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 { /// /// MOM基础数据服务 /// [ApiDescriptionSettings(Tag = "BasicData", Name = "RouteLineTemplate", Order = 700)] [Route("api/Route/[controller]")] public class RouteTreeService : IDynamicApiController, ITransient { private readonly ISqlSugarRepository _repository; private readonly DataBaseManager _dbManager; private readonly IDictionaryDataService _dictionaryDataService; public RouteTreeService( IDictionaryDataService dictionaryDataService, ISqlSugarRepository repository, DataBaseManager dbManager) { _dictionaryDataService = dictionaryDataService; _repository = repository; _dbManager = dbManager; } /// /// 返回工艺路线树形结构 /// /// 工艺路线模版树形结构 [AllowAnonymous] [HttpGet("route-tree")] public async Task> GetRouteTreeList() { var dictaryDataList = await _dictionaryDataService.GetList("24950639717653"); var dictaryData = dictaryDataList.ToDictionary(x => x.EnCode, x => x.FullName); SqlSugarScope sugarClient = null!; var result = new List(); 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); 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; } } }