1、数据库操作,生成实体类,清除表数据默认linkid改为单例模式
2、MOM 基础数据-工艺管理-工艺路线模版,左侧树代码调整
This commit is contained in:
@@ -1,14 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using JNPF.Common.Security;
|
|
||||||
|
|
||||||
namespace Tnb.BasicData.Entitys.Dto
|
|
||||||
{
|
|
||||||
public class BasicDataTreeOutput : TreeModel
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using JNPF.Common.Security;
|
||||||
|
|
||||||
|
namespace Tnb.BasicData.Entitys.Dto.ProcessManage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 工艺路线模版左侧树输出参数
|
||||||
|
/// </summary>
|
||||||
|
public class RouteLineTreeOutput : TreeModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 工艺路线类型
|
||||||
|
/// </summary>
|
||||||
|
public string RouteType { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 工艺路线类型名称
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 工艺路线名称
|
||||||
|
/// </summary>
|
||||||
|
public string RouteName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 工艺路线代码
|
||||||
|
/// </summary>
|
||||||
|
public string RouteCode { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 工艺路线版本
|
||||||
|
/// </summary>
|
||||||
|
public string Version { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using JNPF.Systems.Entitys.System;
|
using JNPF.Systems.Entitys.System;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using Tnb.BasicData.Entitys.Dto.ProcessManage;
|
||||||
|
using Tnb.BasicData.Entitys.Entity;
|
||||||
|
|
||||||
namespace Tnb.BasicData.Entitys.Mapper
|
namespace Tnb.BasicData.Entitys.Mapper
|
||||||
{
|
{
|
||||||
@@ -8,12 +10,7 @@ namespace Tnb.BasicData.Entitys.Mapper
|
|||||||
{
|
{
|
||||||
public void Register(TypeAdapterConfig config)
|
public void Register(TypeAdapterConfig config)
|
||||||
{
|
{
|
||||||
config.ForType<ConnectionStringsOptions, ConnectionConfig>()
|
config.ForType<BasRoute, RouteLineTreeOutput>();
|
||||||
.Map(dest => dest.ConnectionString, src => src.DefaultConnection)
|
|
||||||
.AfterMapping((src, dest) =>
|
|
||||||
{
|
|
||||||
dest.ConnectionString = string.Format(src.DefaultConnection, src.Host, src.Port, src.DBName, src.UserName, src.Password);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
104
Tnb.BasicData/ProcessManageService.cs
Normal file
104
Tnb.BasicData/ProcessManageService.cs
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
using System.CodeDom;
|
||||||
|
using Aop.Api.Domain;
|
||||||
|
using Aop.Api.Request;
|
||||||
|
using Aspose.Cells;
|
||||||
|
using JNPF.Common.Core.Manager;
|
||||||
|
using JNPF.Common.Security;
|
||||||
|
using JNPF.DependencyInjection;
|
||||||
|
using JNPF.DynamicApiController;
|
||||||
|
using JNPF.Systems.Entitys.System;
|
||||||
|
using JNPF.Systems.Interfaces.System;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using NPOI.SS.Formula.Functions;
|
||||||
|
using Spire.Presentation;
|
||||||
|
using SqlSugar;
|
||||||
|
using Tnb.BasicData.Entitys.Dto.ProcessManage;
|
||||||
|
using Tnb.BasicData.Entitys.Entity;
|
||||||
|
using Tnb.BasicData.Entitys.Model;
|
||||||
|
|
||||||
|
namespace Tnb.BasicData
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// MOM基础数据-工艺管理
|
||||||
|
/// </summary>
|
||||||
|
[ApiDescriptionSettings(Tag = "BasicData", Name = "ProcessManage", Order = 700)]
|
||||||
|
[Route("api/basic/[controller]")]
|
||||||
|
public class ProcessManageService : IDynamicApiController, ITransient
|
||||||
|
{
|
||||||
|
private readonly ISqlSugarRepository<BasRoute> _repository;
|
||||||
|
private readonly DataBaseManager _dbManager;
|
||||||
|
private readonly IDictionaryDataService _dictionaryDataService;
|
||||||
|
|
||||||
|
public ProcessManageService(
|
||||||
|
IDictionaryDataService dictionaryDataService,
|
||||||
|
ISqlSugarRepository<BasRoute> repository,
|
||||||
|
DataBaseManager dbManager)
|
||||||
|
{
|
||||||
|
_dictionaryDataService = dictionaryDataService;
|
||||||
|
_repository = repository;
|
||||||
|
_dbManager = dbManager;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 获取工艺路线树形结构
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>工艺路线模版树形结构</returns>
|
||||||
|
[HttpGet("route-tree")]
|
||||||
|
public async Task<dynamic> GetRouteTreeList()
|
||||||
|
{
|
||||||
|
var result = new List<RouteLineTreeOutput>();
|
||||||
|
var dictaryDataList = await _dictionaryDataService.GetList("24950639717653");
|
||||||
|
var dictaryData = dictaryDataList.ToDictionary(x => x.EnCode, x => x.FullName);
|
||||||
|
SqlSugarScope sugarClient = null!;
|
||||||
|
var momDbLink = await _repository.AsSugarClient().Queryable<DbLinkEntity>().FirstAsync(x => x.FullName == "tnb_mom");
|
||||||
|
if (momDbLink != null)
|
||||||
|
{
|
||||||
|
sugarClient = _dbManager.ChangeDataBase(momDbLink);
|
||||||
|
}
|
||||||
|
var list = await sugarClient.Queryable<BasRoute>().ToListAsync();
|
||||||
|
if (list?.Count > 0)
|
||||||
|
{
|
||||||
|
var routeGroups = list.GroupBy(g => g.RouteType);
|
||||||
|
var dic1 = routeGroups.ToDictionary(x => $"{x.Key}", x => Tuple.Create(new RouteLineTreeOutput
|
||||||
|
{
|
||||||
|
id = SnowflakeIdHelper.NextId(),
|
||||||
|
RouteType = x.Key,
|
||||||
|
Name = dictaryData.ContainsKey(x.Key) ? dictaryData[x.Key] : string.Empty
|
||||||
|
}, x.GroupBy(g => new { g.RouteName, g.RouteCode })));
|
||||||
|
result.AddRange(dic1.Values.Select(t => t.Item1));
|
||||||
|
foreach (var routeGroup in routeGroups)
|
||||||
|
{
|
||||||
|
if (dic1.ContainsKey(routeGroup.Key))
|
||||||
|
{
|
||||||
|
var nodes = new List<RouteLineTreeOutput>();
|
||||||
|
foreach (var item in dic1[routeGroup.Key].Item2)
|
||||||
|
{
|
||||||
|
var node = new RouteLineTreeOutput();
|
||||||
|
node.id = SnowflakeIdHelper.NextId();
|
||||||
|
node.parentId = dic1[routeGroup.Key].Item1.id;
|
||||||
|
node.Name = $"{item.Key.RouteName}|{item.Key.RouteCode}";
|
||||||
|
node.RouteName = item.Key.RouteName;
|
||||||
|
node.RouteCode = item.Key.RouteCode;
|
||||||
|
nodes.Add(node);
|
||||||
|
}
|
||||||
|
result.AddRange(nodes);
|
||||||
|
var dic2 = nodes.ToDictionary(x => x.Name, x => x.id);
|
||||||
|
foreach (var item in dic1[routeGroup.Key].Item2)
|
||||||
|
{
|
||||||
|
if (dic2.ContainsKey($"{item.Key.RouteName}|{item.Key.RouteCode}"))
|
||||||
|
{
|
||||||
|
result.AddRange(item.Select(x => new RouteLineTreeOutput
|
||||||
|
{
|
||||||
|
id = SnowflakeIdHelper.NextId(),
|
||||||
|
parentId = dic2[$"{item.Key.RouteName}|{item.Key.RouteCode}"],
|
||||||
|
Version = x.Version,
|
||||||
|
})) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new { list = result.ToTree() };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
using System.CodeDom;
|
|
||||||
using Aspose.Cells;
|
|
||||||
using JNPF.Common.Core.Manager;
|
|
||||||
using JNPF.DependencyInjection;
|
|
||||||
using JNPF.DynamicApiController;
|
|
||||||
using JNPF.Systems.Entitys.System;
|
|
||||||
using JNPF.Systems.Interfaces.System;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Spire.Presentation;
|
|
||||||
using SqlSugar;
|
|
||||||
using Tnb.BasicData.Entitys.Entity;
|
|
||||||
using Tnb.BasicData.Entitys.Model;
|
|
||||||
|
|
||||||
namespace Tnb.BasicData
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// MOM基础数据服务
|
|
||||||
/// </summary>
|
|
||||||
[ApiDescriptionSettings(Tag = "BasicData", Name = "RouteLineTemplate", Order = 700)]
|
|
||||||
[Route("api/Route/[controller]")]
|
|
||||||
public class RouteTreeService : IDynamicApiController, ITransient
|
|
||||||
{
|
|
||||||
private readonly ISqlSugarRepository<BasRoute> _repository;
|
|
||||||
private readonly DataBaseManager _dbManager;
|
|
||||||
private readonly IDictionaryDataService _dictionaryDataService;
|
|
||||||
|
|
||||||
public RouteTreeService(
|
|
||||||
IDictionaryDataService dictionaryDataService,
|
|
||||||
ISqlSugarRepository<BasRoute> repository,
|
|
||||||
DataBaseManager dbManager)
|
|
||||||
{
|
|
||||||
_dictionaryDataService = dictionaryDataService;
|
|
||||||
_repository = repository;
|
|
||||||
_dbManager = dbManager;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 返回工艺路线树形结构
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>工艺路线模版树形结构</returns>
|
|
||||||
[AllowAnonymous]
|
|
||||||
[HttpGet("route-tree")]
|
|
||||||
public async Task<List<RouteTree>> GetRouteTreeList()
|
|
||||||
{
|
|
||||||
var dictaryDataList = await _dictionaryDataService.GetList("24950639717653");
|
|
||||||
var dictaryData = dictaryDataList.ToDictionary(x => x.EnCode, x => x.FullName);
|
|
||||||
SqlSugarScope sugarClient = null!;
|
|
||||||
var result = new List<RouteTree>();
|
|
||||||
var momDbLink = await _repository.AsSugarClient().Queryable<DbLinkEntity>().FirstAsync(x => x.FullName == "tnb_mom");
|
|
||||||
if (momDbLink != null)
|
|
||||||
{
|
|
||||||
sugarClient = _dbManager.ChangeDataBase(momDbLink);
|
|
||||||
}
|
|
||||||
|
|
||||||
var list = await sugarClient.Queryable<BasRoute>().ToListAsync();
|
|
||||||
if (list?.Count > 0)
|
|
||||||
{
|
|
||||||
var routeGroups = list.GroupBy(g => g.RouteType);
|
|
||||||
foreach (var routeGroup in routeGroups)
|
|
||||||
{
|
|
||||||
var routeTree = new RouteTree();
|
|
||||||
routeTree.RouteType = dictaryData.ContainsKey(routeGroup.Key) ? dictaryData[routeGroup.Key] : "";
|
|
||||||
var routeNameGroup = routeGroup.GroupBy(g => new { g.RouteName, g.RouteCode });
|
|
||||||
|
|
||||||
routeTree.RouteName = routeNameGroup.Select(x => new RouteName
|
|
||||||
{
|
|
||||||
Tag = $"{x.Key.RouteName}|{x.Key.RouteCode}",
|
|
||||||
RouteVersion = x.Select(t => t.Version).ToList(),
|
|
||||||
}).ToList();
|
|
||||||
result.Add(routeTree);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -332,21 +332,20 @@ public class DataBaseService : IDynamicApiController, ITransient
|
|||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("{linkId}/clean-data")]
|
[HttpPost("{linkId}/clean-data")]
|
||||||
|
[AllowAnonymous]
|
||||||
public async Task<dynamic> CleanTableData(string linkId, DatabaseTableDataCleanInput input)
|
public async Task<dynamic> CleanTableData(string linkId, DatabaseTableDataCleanInput input)
|
||||||
{
|
{
|
||||||
SqlSugarScope sugarClient = null!;
|
SqlSugarScope? sugarClient = null!;
|
||||||
if (linkId == "0")
|
if (linkId == "0")
|
||||||
{
|
{
|
||||||
ConnectionStringsOptions options = App.GetConfig<ConnectionStringsOptions>("ConnectionStrings", true);
|
sugarClient = _repository.AsSugarClient() as SqlSugarScope;
|
||||||
var connCfg = options.Adapt<ConnectionConfig>();
|
|
||||||
sugarClient = new SqlSugarScope(connCfg);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var link = await _dbLinkService.GetInfo(linkId);
|
var link = await _dbLinkService.GetInfo(linkId);
|
||||||
sugarClient = _dataBaseManager.ChangeDataBase(link);
|
sugarClient = _dataBaseManager.ChangeDataBase(link);
|
||||||
}
|
}
|
||||||
return await sugarClient.Deleteable<object>().AS(input.TableName).ExecuteCommandAsync();
|
return await sugarClient!.Deleteable<object>().AS(input.TableName).ExecuteCommandAsync();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 生成代码
|
/// 生成代码
|
||||||
@@ -375,9 +374,7 @@ public class DataBaseService : IDynamicApiController, ITransient
|
|||||||
SqlSugarScope sugarClient = null!;
|
SqlSugarScope sugarClient = null!;
|
||||||
if (linkId == "0") //默认时,使用当前默认数据库配置
|
if (linkId == "0") //默认时,使用当前默认数据库配置
|
||||||
{
|
{
|
||||||
ConnectionStringsOptions options = App.GetConfig<ConnectionStringsOptions>("ConnectionStrings", true);
|
sugarClient = _repository.AsSugarClient() as SqlSugarScope;
|
||||||
var connCfg = options.Adapt<ConnectionConfig>();
|
|
||||||
sugarClient = new SqlSugarScope(connCfg);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -400,7 +397,7 @@ public class DataBaseService : IDynamicApiController, ITransient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var item in sugarClient.DbMaintenance.GetTableInfoList().Where(t => t.Name == input.TableName))
|
foreach (var item in sugarClient!.DbMaintenance.GetTableInfoList().Where(t => t.Name == input.TableName))
|
||||||
{
|
{
|
||||||
string entityName = CustomFormatName(item.Name);/*实体名首字母大写*/
|
string entityName = CustomFormatName(item.Name);/*实体名首字母大写*/
|
||||||
sugarClient.MappingTables.Add(entityName, item.Name);
|
sugarClient.MappingTables.Add(entityName, item.Name);
|
||||||
@@ -410,13 +407,6 @@ public class DataBaseService : IDynamicApiController, ITransient
|
|||||||
sugarClient.MappingColumns.Add(colName /*类的属性首字母大写*/, col.DbColumnName, entityName);
|
sugarClient.MappingColumns.Add(colName /*类的属性首字母大写*/, col.DbColumnName, entityName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var newFileName = "";
|
|
||||||
var pos = input.TableName.IndexOf("_", StringComparison.Ordinal);
|
|
||||||
var first = input.TableName.AsSpan().Slice(0, pos).ToString().ToUpperCase();
|
|
||||||
var second = input.TableName.AsSpan().Slice(pos + 1).ToString().ToUpperCase();
|
|
||||||
newFileName = $"{first}{second}";
|
|
||||||
|
|
||||||
sugarClient.DbFirst.Where(input.TableName)
|
sugarClient.DbFirst.Where(input.TableName)
|
||||||
.FormatFileName(CustomFormatName)
|
.FormatFileName(CustomFormatName)
|
||||||
.IsCreateAttribute()
|
.IsCreateAttribute()
|
||||||
|
|||||||
Reference in New Issue
Block a user