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 { /// /// MOM基础数据-工艺管理 /// [ApiDescriptionSettings(Tag = "BasicData", Name = "ProcessManage", Order = 700)] [Route("api/basic/[controller]")] public class ProcessManageService : IDynamicApiController, ITransient { private readonly ISqlSugarRepository _repository; private readonly DataBaseManager _dbManager; private readonly IDictionaryDataService _dictionaryDataService; private readonly string _dictionaryTypeId; public ProcessManageService( IDictionaryDataService dictionaryDataService, ISqlSugarRepository repository, DataBaseManager dbManager) { _dictionaryDataService = dictionaryDataService; _repository = repository; _dbManager = dbManager; _dictionaryTypeId = "24950639717653"; } /// /// 获取工艺路线树形结构 /// /// 工艺路线模版树形结构 /// ///
[{ ///
"RouteType": 工艺路线类型, ///
"Name": 工艺路线类型名称, ///
"RouteName": 工艺路线名称, ///
"RouteCode": 工艺路线代码, ///
"Version": 工艺路线版本, ///
"id": "25325800913429", ///
"parentId": null, ///
"hasChildren": true, ///
"children": [{ ///
"RouteType": 工艺路线类型, ///
"Name": 工艺路线名称|工艺路线版本, ///
"RouteName": "显示器集成", ///
"RouteCode": 工艺路线代码, ///
"Version": 工艺路线版本, ///
"id": 当前节点Id,不用可以忽略, ///
"parentId": "父节点Id,不用可以忽略", ///
"hasChildren": 是否包含子节点,true/false, ///
"children": [{ ///
"Version": 工艺路线版本, ///
} ///
], ///
"num": 子节点数量,不用可以忽略, ///
"isLeaf": 是否页节点,不用可以忽略 true/false ///
} ///
] ///
} ///
] ///
[HttpGet("route-tree")] public async Task GetRouteTreeList() { var result = new List(); var dictaryDataList = await _dictionaryDataService.GetList(_dictionaryTypeId); var dictaryData = dictaryDataList.ToDictionary(x => x.EnCode, x => x.FullName); SqlSugarScope sugarClient = null!; var momDbLink = await _repository.AsSugarClient().Queryable().FirstAsync(x => x.FullName == "tnb_mom"); if (momDbLink != null) { sugarClient = _dbManager.ChangeDataBase(momDbLink); } var list = await sugarClient.Queryable().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(); 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}"], Name = x.Version, Version = x.Version, })); } } } } } return new { list = result.ToTree() }; } } }