重新组织目录

This commit is contained in:
2023-04-21 09:26:04 +08:00
parent 41580fe1fb
commit bddd6ac805
33 changed files with 76 additions and 75 deletions

View File

@@ -0,0 +1,96 @@
using JNPF.Common.Core.Manager;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Systems.Entitys.System;
using JNPF.Systems.Interfaces.System;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Tnb.BasicData.Entitys;
using Tnb.BasicData.Entitys.Entity;
using Tnb.BasicData.Entitys.Dto;
namespace Tnb.BasicData
{
/// <summary>
/// 物料清单
/// </summary>
[ApiDescriptionSettings(Tag = "BasicData", Name = "ParentMaterial", Order = 701)]
[Route("api/basic/[controller]")]
public class ParentMaterialService : IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository<BasMaterial> _repository;
private readonly DataBaseManager _dbManager;
private readonly IDictionaryDataService _dictionaryDataService;
public ParentMaterialService(
ISqlSugarRepository<BasMaterial> repository,DataBaseManager dbManager,IDictionaryDataService dictionaryDataService)
{
_repository = repository;
_dbManager = dbManager;
_dictionaryDataService = dictionaryDataService;
}
/// <summary>
/// 获取物料清单树.
/// </summary>
/// <param name="input">获取物料清单树.</param>
/// <returns></returns>
[HttpPost("[action]")]
public async Task<dynamic> GetTree(ParentMaterialTreeQueryInput queryInput)
{
var db = _repository.AsSugarClient();
var dic = await _dictionaryDataService.GetDicByKey(DicTypeKey.MeasurementUnit);
var momDbLink = await _repository.AsSugarClient().Queryable<DbLinkEntity>().FirstAsync(x => x.FullName == DbName.TNBMON);
if (momDbLink != null)
{
db = _dbManager.ChangeDataBase(momDbLink);
}
if (string.IsNullOrEmpty(queryInput.materialId))
{
var data = await db.Queryable<BasParentMaterialItems>()
.LeftJoin<BasParentMaterial>((a,b)=>a.ParentMaterialId==b.Id)
.LeftJoin<BasMaterial>((a,b,c)=>a.MaterialId==c.Id)
.Where((a,b,c)=>a.ParentMaterialId==queryInput.parentMaterialId)
.Select((a,b,c)=>new ParentMaterialTreeOutput
{
material_id = c.MaterialName,
material_id_extras = c.Extras,
material_id_id=c.Id,
material_id_minpacking = c.Minpacking,
material_id_remark = c.Remark,
material_id_unitid = c.Unitid,
hasChildren = SqlFunc.Subqueryable<BasParentMaterial>().Where(x=>x.MaterialId==a.MaterialId).Any(),
}).Mapper(it =>
{
it.material_id_unitid = dic[it.material_id_unitid].ToString();
}).ToListAsync();
return data;
}
else
{
var data = await db.Queryable<BasParentMaterialItems>()
.LeftJoin<BasParentMaterial>((a,b)=>a.ParentMaterialId==b.Id)
.LeftJoin<BasMaterial>((a,b,c)=>a.MaterialId==c.Id)
.Where((a,b,c)=>b.MaterialId==queryInput.materialId && a.ParentMaterialId==b.Id)
.Select((a,b,c)=>new ParentMaterialTreeOutput
{
material_id = c.MaterialName,
material_id_extras = c.Extras,
material_id_id=c.Id,
material_id_minpacking = c.Minpacking,
material_id_remark = c.Remark,
material_id_unitid = c.Unitid,
hasChildren = SqlFunc.Subqueryable<BasParentMaterial>().Where(x=>x.MaterialId==a.MaterialId).Any(),
}).Mapper(it =>
{
it.material_id_unitid = dic[it.material_id_unitid].ToString();
}).ToListAsync();
return data;
}
}
}
}

View File

@@ -0,0 +1,142 @@
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 JNPF.VisualDev;
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 : IOverideVisualDevService, IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository<BasRoute> _repository;
private readonly DataBaseManager _dbManager;
private readonly IDictionaryDataService _dictionaryDataService;
private readonly string _dictionaryTypeId;
public ProcessManageService(
IDictionaryDataService dictionaryDataService,
ISqlSugarRepository<BasRoute> repository,
DataBaseManager dbManager)
{
_dictionaryDataService = dictionaryDataService;
_repository = repository;
_dbManager = dbManager;
_dictionaryTypeId = "24950639717653";
}
public OverideVisualDevFunc OverideFuncs => new OverideVisualDevFunc();
/// <summary>
/// 获取工艺路线树形结构
/// </summary>
/// <returns>工艺路线模版树形结构</returns>
/// <remarks>
///<br/> [{
///<br/> "RouteType": 工艺路线类型,
///<br/> "Name": 工艺路线类型名称,
///<br/> "RouteName": 工艺路线名称,
///<br/> "RouteCode": 工艺路线代码,
///<br/> "Version": 工艺路线版本,
///<br/> "id": "25325800913429",
///<br/> "parentId": null,
///<br/> "hasChildren": true,
///<br/> "children": [{
///<br/> "RouteType": 工艺路线类型,
///<br/> "Name": 工艺路线名称|工艺路线版本,
///<br/> "RouteName": "显示器集成",
///<br/> "RouteCode": 工艺路线代码,
///<br/> "Version": 工艺路线版本,
///<br/> "id": 当前节点Id不用可以忽略,
///<br/> "parentId": "父节点Id,不用可以忽略",
///<br/> "hasChildren": 是否包含子节点,true/false,
///<br/> "children": [{
///<br/> "Version": 工艺路线版本,
///<br/> }
///<br/> ],
///<br/> "num": 子节点数量,不用可以忽略,
///<br/> "isLeaf": 是否页节点,不用可以忽略 true/false
///<br/> }
///<br/> ]
///<br/>}
///<br/>]
/// </remarks>
[HttpGet("route-tree")]
public async Task<dynamic> GetRouteTreeList()
{
var result = new List<RouteLineTreeOutput>();
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<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}"],
Name = x.Version,
Version = x.Version,
}));
}
}
}
}
}
return new { list = result.ToTree() };
}
}
}

View File

@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(SolutionDir)\common.props" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" />
<ProjectReference Include="..\Tnb.BasicData.Interfaces\Tnb.BasicData.Interfaces.csproj" />
</ItemGroup>
</Project>