From d12e05d737845e5afae35b7c561de88bae8bc850 Mon Sep 17 00:00:00 2001 From: "DEVICE8\\12494" Date: Wed, 24 May 2023 23:31:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=94=9F=E4=BA=A7bom?= =?UTF-8?q?=E6=8B=86=E5=88=86=E5=AD=90=E5=B7=A5=E5=8D=95=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/SubBomListOutput.cs | 21 ++ BasicData/Tnb.BasicData/BasMbomService.cs | 59 +++-- .../IToolMoldsService.cs | 3 +- .../Tnb.EquipMgr.Interfaces.csproj | 1 + .../ToolMoldMaintainRuleService.cs | 1 + .../ToolMoldMaintainRunService.cs | 2 +- EquipMgr/Tnb.EquipMgr/ToolMoldsService.cs | 5 +- .../Dto/DictionaryTreeOutput.cs | 16 ++ .../Dto/PrdManage/GenSubMoCrInput.cs | 4 +- .../Dto/PrdManage/PrdMotreeOutput.cs | 35 +-- .../Entity/PrdMoTaskDefect.cs | 4 + .../Tnb.ProductionMgr/PrdMoTaskService.cs | 206 +++++++++++++----- .../Extension/DictionaryExtensions.cs | 31 ++- .../Extension/LambdaExpressionExtensions.cs | 23 ++ common/Tnb.Common/Security/TreeHelper.cs | 2 + visualdev/Tnb.VisualDev/RunService.cs | 21 +- 16 files changed, 336 insertions(+), 98 deletions(-) create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Dto/DictionaryTreeOutput.cs diff --git a/BasicData/Tnb.BasicData.Entities/Dto/SubBomListOutput.cs b/BasicData/Tnb.BasicData.Entities/Dto/SubBomListOutput.cs index a666855d..f85c64e7 100644 --- a/BasicData/Tnb.BasicData.Entities/Dto/SubBomListOutput.cs +++ b/BasicData/Tnb.BasicData.Entities/Dto/SubBomListOutput.cs @@ -35,5 +35,26 @@ namespace Tnb.BasicData.Entities.Dto /// 数量 /// public string num { get; set;} + /// + /// 单位id + /// + public string unit_id { get; set; } + /// + /// bomid + /// + public string bom_id { get; set; } + /// + /// 工序id + /// + public string process_id { get; set; } + /// + /// bom版本 + /// + public string version { get; set; } + + /// + /// 工艺路线名称 + /// + public string route_name { get; set; } } } diff --git a/BasicData/Tnb.BasicData/BasMbomService.cs b/BasicData/Tnb.BasicData/BasMbomService.cs index 62ec0678..ef2621e8 100644 --- a/BasicData/Tnb.BasicData/BasMbomService.cs +++ b/BasicData/Tnb.BasicData/BasMbomService.cs @@ -133,35 +133,51 @@ namespace Tnb.BasicData /// /// 根据bomid获取对应的子bom列表 /// - /// + /// bomId /// + /// + /// + /// returns: + ///
{ + ///
version:bom版本 + ///
unit_id:单位id + ///
route_name:工艺路线名称 + ///
process_id:工序id + ///
material_id:物料id + ///
material_code:物料编码 + ///
material_name:物料名称 + ///
material_category_code:类别code + ///
output_qty:输出参数 + ///
} + ///
[HttpGet] public async Task GetSubMoListByBomId([FromRoute] string bomId) { + if (string.IsNullOrEmpty(bomId)) throw new ArgumentException($"parameter {nameof(bomId)} not be null or empty"); - var result = await _db.Queryable().LeftJoin((a, b) => a.route_id == b.route_id) - .LeftJoin((a, b, c) => b.process_id == c.id) - .LeftJoin((a, b, c, d) => c.id == d.process_id) - .LeftJoin((a, b, c, d, e) => d.material_id == e.id) - .LeftJoin((a, b, c, d, e, f) => e.category_id == f.id) - .Where((a, b, c, d, e, f) => a.id == bomId) - .Select((a, b, c, d, e, f) => new SubBomListOutput - { - material_id = e.id, - material_code = e.code, - material_name = e.name, - material_category_code = f.category_code, - num = d.num - }) - .Mapper(it => it.output_qty = it.num.ParseToInt()) - .Distinct() - .ToListAsync(); + var result = await _db.Queryable() + .LeftJoin((a, b) => a.route_id == b.id) + .LeftJoin((a, b, c) => b.id == c.route_id) + .LeftJoin((a, b, c, d) => c.process_id == d.process_id) + .LeftJoin((a, b, c, d, e) => e.mbom_id == a.id && e.mbom_process_id == d.id) + .Where((a, b, c, d, e) => a.id == bomId && a.material_id != e.material_id && !string.IsNullOrEmpty(e.material_id)) + .Select((a, b, c, d, e) => new SubBomListOutput + { + version = a.version, + unit_id = a.unit_id, + route_name = b.name, + process_id = c.process_id, + material_id = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.id), + material_code = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.code), + material_name = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.name), + material_category_code = "", + num = e.num, + }) + .Mapper(it => it.output_qty = it.num.ParseToInt()) + .ToListAsync(); return result; } - - - /// /// 根据物料id获取生产bom /// @@ -182,6 +198,7 @@ namespace Tnb.BasicData [HttpGet] public async Task GetMBomListByMaterialId([FromRoute] string materialId) { + return await _db.Queryable() .LeftJoin((a, b) => a.material_id == b.id) .LeftJoin((a, b, c) => a.route_id == c.id) diff --git a/EquipMgr/Tnb.EquipMgr.Interfaces/IToolMoldsService.cs b/EquipMgr/Tnb.EquipMgr.Interfaces/IToolMoldsService.cs index 83bd40e9..e1e1f8d9 100644 --- a/EquipMgr/Tnb.EquipMgr.Interfaces/IToolMoldsService.cs +++ b/EquipMgr/Tnb.EquipMgr.Interfaces/IToolMoldsService.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Tnb.EquipMgr.Entities; using Tnb.EquipMgr.Entities.Dto; +using Tnb.ProductionMgr.Entities.Dto; namespace Tnb.EquipMgr.Interfaces { @@ -16,7 +17,7 @@ namespace Tnb.EquipMgr.Interfaces /// /// /// - public Task> GetEquipmentLists(ToolMoldInput ToolMoldInput); + public Task> GetEquipmentLists(ToolMoldInput ToolMoldInput); /// /// 增加模具设备绑定 /// diff --git a/EquipMgr/Tnb.EquipMgr.Interfaces/Tnb.EquipMgr.Interfaces.csproj b/EquipMgr/Tnb.EquipMgr.Interfaces/Tnb.EquipMgr.Interfaces.csproj index 8bbf5496..510df9dd 100644 --- a/EquipMgr/Tnb.EquipMgr.Interfaces/Tnb.EquipMgr.Interfaces.csproj +++ b/EquipMgr/Tnb.EquipMgr.Interfaces/Tnb.EquipMgr.Interfaces.csproj @@ -8,6 +8,7 @@ + diff --git a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs index 3581442a..54165647 100644 --- a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs +++ b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs @@ -141,6 +141,7 @@ namespace Tnb.EquipMgr await _db.Ado.BeginTranAsync(); var maintainRules = await _db.Queryable().Where(it => input.ruleIds.Contains(it.id)).ToListAsync(); + var ruleMoldRelations = await _db.Queryable().Where(it=>input.ruleIds.Contains(it.rule_id)).ToListAsync(); if (maintainRules?.Count > 0) { List maintainPlans = new(); diff --git a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs index 12db28d5..a172f95c 100644 --- a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs +++ b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs @@ -47,7 +47,7 @@ namespace Tnb.EquipMgr public async Task GetMaintainInfoFromByPlanId([FromRoute] string planId) { dynamic info = new ExpandoObject(); - var planMoldRelation = await _db.Queryable().FirstAsync(it => it.id == planId); + var planMoldRelation = await _db.Queryable().FirstAsync(it => it.maintain_plan_id == planId); if (planMoldRelation != null) { var mold = await _db.Queryable().FirstAsync(it => it.id == planMoldRelation.mold_id); diff --git a/EquipMgr/Tnb.EquipMgr/ToolMoldsService.cs b/EquipMgr/Tnb.EquipMgr/ToolMoldsService.cs index d826c33b..86c41af4 100644 --- a/EquipMgr/Tnb.EquipMgr/ToolMoldsService.cs +++ b/EquipMgr/Tnb.EquipMgr/ToolMoldsService.cs @@ -18,6 +18,7 @@ using SqlSugar; using Tnb.EquipMgr.Entities; using Tnb.EquipMgr.Entities.Dto; using Tnb.EquipMgr.Interfaces; +using Tnb.ProductionMgr.Entities.Dto; namespace Tnb.EquipMgr { /// @@ -67,7 +68,7 @@ namespace Tnb.EquipMgr /// /// [HttpPost] - public async Task> GetEquipmentLists(ToolMoldInput ToolMoldInput) + public async Task> GetEquipmentLists(ToolMoldInput ToolMoldInput) { var db = _repository.AsSugarClient(); var list = await db.Queryable((a, b) => new object[] @@ -75,7 +76,7 @@ namespace Tnb.EquipMgr JoinType.Inner, a.id == b.equipment_id, }) .Where((a, b) => b.mold_id == ToolMoldInput.mold) - .Select((a, b) => new EquipmentListOutput + .Select((a, b) => new Tnb.EquipMgr.Entities.Dto.EquipmentListOutput { id = a.id, eqp_code = a.code, diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/DictionaryTreeOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/DictionaryTreeOutput.cs new file mode 100644 index 00000000..a5aaca03 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/DictionaryTreeOutput.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.ProductionMgr.Entities.Dto +{ + public class DictionaryTreeOutput + { + public string id { get; set; } + public string parentId { get; set; } + public List Child { get; set; } + public bool HasChild { get; set; } + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/GenSubMoCrInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/GenSubMoCrInput.cs index aa6b1f76..049cf59f 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/GenSubMoCrInput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/GenSubMoCrInput.cs @@ -8,12 +8,14 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage { public class GenSubMoCrInput { + public string bom_id { get; set; } + /// /// 父工单id /// public string mo_id { get; set; } /// - /// 子物料ids + /// 工序ids /// public List ids { get; set; } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMotreeOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMotreeOutput.cs index f274fe7c..166af51e 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMotreeOutput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMotreeOutput.cs @@ -7,8 +7,12 @@ using JNPF.Common.Security; namespace Tnb.ProductionMgr.Entities.Dto.PrdManage { - public class PrdMotreeOutput : TreeModel + public class PrdMoTreeOutput : TreeModel { + + //public Dictionary row { get; set; } + + #region 注释代码 public string? org_id { get; set; } /// /// 工单id @@ -25,6 +29,10 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// 物料编号 /// public string? material_code { get; set; } + /// + /// 物料名称 + /// + public string material_name { get; set; } /// /// 工单类型:1-正常工单、2-返工工单、3-试制工单 @@ -39,37 +47,37 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// /// 计划生产数量 /// - public int? plan_qty { get; set; } + public string plan_qty { get; set; } /// /// 已投入数量 /// - public int? input_qty { get; set; } + public string input_qty { get; set; } /// /// 已完工数量 /// - public int? complete_qty { get; set; } + public string complete_qty { get; set; } /// /// 报废数量 /// - public int? scrap_qty { get; set; } + public string scrap_qty { get; set; } /// /// 计划开始时间 /// - public DateTime? plan_start_date { get; set; } + public string plan_start_date { get; set; } /// /// 计划结束时间 /// - public DateTime? plan_end_date { get; set; } + public string plan_end_date { get; set; } /// /// 是否生派工单 /// - public int? is_create_dispatch { get; set; } + public string is_create_dispatch { get; set; } /// @@ -80,7 +88,7 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// /// 是否合并 /// - public int? is_merge { get; set; } + public string is_merge { get; set; } /// /// 组合工单 @@ -100,7 +108,7 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// /// 创建时间 /// - public DateTime? create_time { get; set; } + public string create_time { get; set; } /// /// 修改用户 @@ -110,19 +118,20 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// /// 修改时间 /// - public DateTime? modify_time { get; set; } + public string modify_time { get; set; } /// /// 物料ID /// public string? material_id { get; set; } - + public string? material_id_id { get; set; } /// /// 已排产数量 /// - public int? scheduled_qty { get; set; } + public string scheduled_qty { get; set; } /// /// 父工单id /// public string parent_id { get; set; } + #endregion } } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTaskDefect.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTaskDefect.cs index a298e511..d5d476f6 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTaskDefect.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTaskDefect.cs @@ -48,5 +48,9 @@ public partial class PrdMoTaskDefect : BaseEntity /// 批次 /// public string? batch { get; set; } + /// + /// 报废数量 + /// + public int scrap_qty { get; set; } } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index cbcea7c3..7be62097 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -35,6 +35,11 @@ using Aspose.Cells.Drawing.Texts; using JNPF.Systems.Entitys.Permission; using WebSocketSharp.Frame; using JNPF.Logging; +using System.Dynamic; +using Tnb.EquipMgr.Entities.Dto; +using JNPF.Common.Filter; +using Tnb.BasicData.Entities.Dto; +using NPOI.SS.Formula.Functions; namespace Tnb.ProductionMgr { @@ -45,6 +50,7 @@ namespace Tnb.ProductionMgr public class PrdMoTaskService : IOverideVisualDevService, IPrdMoTaskService, IDynamicApiController, ITransient { private const string ModuleId = "25567924238373"; + private const string MoModuleId = "25018860321301"; private readonly ISqlSugarRepository _repository; private readonly IUserManager _userManager; private readonly IDictionaryDataService _dictionaryDataService; @@ -98,12 +104,12 @@ namespace Tnb.ProductionMgr [HttpGet("{materialId}")] public async Task GetMoldListByItemId(string materialId) { - var result = new List(); + var result = new List(); result = await _db.Queryable() .InnerJoin((a, b) => a.mold_id == b.id) .InnerJoin((a, b, c) => a.material_id == c.id) .Where((a, b, c) => a.material_id == materialId) - .Select((a, b, c) => new MoldListOutput + .Select((a, b, c) => new Tnb.ProductionMgr.Entities.Dto.MoldListOutput { mold_id = a.id, mold_code = b.mold_code, @@ -125,7 +131,7 @@ namespace Tnb.ProductionMgr { var items = await _db.Queryable().InnerJoin((a, b) => a.equipment_id == b.id) .Where((a, b) => a.mold_id == moldId) - .Select((a, b) => new EquipmentListOutput + .Select((a, b) => new Entities.Dto.EquipmentListOutput { eqp_id = b.id, eqp_code = b.code, @@ -255,7 +261,7 @@ namespace Tnb.ProductionMgr material_code = materialCode, material_name = materialName, prd_qty = it.prd_qty, - //scrap_qty = SqlFunc.Subqueryable().Select(x => x.scrap_qty), + scrap_qty = SqlFunc.Subqueryable().Where(pmtd => pmtd.mo_task_id == it.mo_task_id).Select(x => x.scrap_qty), }) .Mapper(it => { @@ -271,7 +277,7 @@ namespace Tnb.ProductionMgr icmo_qty = db.Queryable().First(it => it.mo_task_code == mo_task_code)?.scheduled_qty, reported_work_qty = 0, prd_qty = 0, - //scrap_qty = 0, + scrap_qty = 0, }; return res; } @@ -471,29 +477,74 @@ namespace Tnb.ProductionMgr /// /// [HttpGet] - public async Task GetUnSchedulingList() + public async Task GetUnSchedulingList([FromQuery] VisualDevModelListQueryInput input) { - List trees = new(); - var list = await _db.Queryable().Where(it => string.IsNullOrEmpty(it.parent_id) && it.mo_status == DictConst.ScheduledId).ToListAsync(); - foreach (var item in list) + List trees = new(); + VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(MoModuleId, true); + var data = await _runService.GetListResult(templateEntity, input); + + if (data?.list?.Count > 0) { - var node = item.Adapt(); - node.mo_id = item.id; - node.id = SnowflakeIdHelper.NextId(); - node.parentId = "0"; - var items = await _db.Queryable().Where(it => it.parent_id == item.id).ToListAsync(); - if (items?.Count() > 0) + var parentIdField = nameof(PrdMo.parent_id); + var nodes = data.list.Where(it => it.ContainsKey(parentIdField) && it[parentIdField].IsNullOrEmpty()).ToList(); + foreach (var row in nodes) { - var childNodes = items.Adapt>(); - for (int i = 0; i < items.Count; i++) + var pkName = "material_id_id"; + var dic = row.ToDictionary(x => x.Key, x => x.Value); + + PrdMoTreeOutput node = DictionaryToObject(row); + node.parentId = "0"; + node.mo_id = node.id; + if (dic.ContainsKey(pkName)) { - childNodes[i].mo_id = items[i].id; + var materialId = dic[pkName]?.ToString(); + var material = await _db.Queryable().FirstAsync(it => it.id == materialId); + node.material_id_id = materialId; + node.material_code = material?.code; + node.material_name = material?.name; } - trees.AddRange(childNodes); + + var queryObj = new { parent_id = node.id }; + input.superQueryJson = ""; + input.queryJson = queryObj.ToJsonString(); + var subData = await _runService.GetListResult(templateEntity, input); + if (subData?.list?.Count > 0) + { + var childNodes = new List(); + foreach (var item in subData.list) + { + dic = item.ToDictionary(x => x.Key, x => x.Value); + PrdMoTreeOutput subNode = DictionaryToObject(item); + subNode.parentId = node.id; + subNode.mo_id = subNode.id; + if (dic.ContainsKey(pkName)) + { + var materialId = dic[pkName]?.ToString(); + var material = await _db.Queryable().FirstAsync(it => it.id == materialId); + subNode.material_id_id = materialId; + subNode.material_code = material?.code; + subNode.material_name = material?.name; + } + childNodes.Add(subNode); + } + trees.AddRange(childNodes); + } + trees.Add(node); } - trees.Add(node); } - return trees.ToTree(); + var treeList = trees.ToTree(); + var list = treeList.Skip(input.currentPage - 1).Take(input.pageSize).ToList(); + SqlSugarPagedList pagedList = new() + { + list = treeList, + pagination = new Pagination + { + CurrentPage = input.currentPage, + PageSize = input.pageSize, + Total = treeList.Count + } + }; + return PageResult.SqlSugarPageResult(pagedList); } #endregion @@ -769,7 +820,7 @@ namespace Tnb.ProductionMgr } catch (Exception ex) { - Log.Error("组装包装排产时报错", ex); + JNPF.Logging.Log.Error("组装包装排产时报错", ex); await _db.Ado.RollbackTranAsync(); } return row > 0; @@ -1037,7 +1088,7 @@ namespace Tnb.ProductionMgr defect.defective_item = dItem.defective_item; defect.defective_item_qty = dItem.defective_item_qty; defect.create_id = _userManager.UserId; - + defect.scrap_qty = input.scrap_qty; destDefects.Add(defect); } } @@ -1084,45 +1135,92 @@ namespace Tnb.ProductionMgr if (input.ids is null || input.ids.Count == 0) throw new ArgumentException($"{nameof(input.ids)} not be null or count zero"); var curMo = await _db.Queryable().FirstAsync(it => it.id == input.mo_id); if (curMo == null) throw new ArgumentNullException("创建子工单时的父工单不能为null"); - List subMoList = new(); - var outputMaterials = await _db.Queryable().LeftJoin((a, b) => a.id == b.material_id) - .Where((a, b) => input.ids.Contains(a.id)) - .Select((a, b) => new + + + var outMaterials = await _db.Queryable().InnerJoin((a, b) => a.id == b.mbom_id) + .InnerJoin((a, b, c) => a.id == c.mbom_id && b.id == c.mbom_process_id) + .Where((a, b, c) => a.id == input.bom_id && input.ids.Contains(b.process_id)) + .Select((a, b, c) => new + { + material_id = a.material_id, + num = c.num, + }) + .ToListAsync(); + + if (outMaterials?.Count > 0) + { + var mids = await _db.Queryable().Where(it => it.id == input.mo_id).Select(it => it.material_id).ToListAsync(); + var ids = outMaterials.Select(x => x.material_id).Except(mids).ToList(); + var dicOutMaterialNum = outMaterials.ToDictionary(x => x.material_id, x => x.num.ParseToInt()); + List subMoList = new(); + var outputMaterials = await _db.Queryable().Where(it => ids.Contains(it.id)).ToListAsync(); + foreach (var om in outputMaterials) { - material_id = a.id, - material_code = a.code, - num = b.num, - }) - .ToListAsync(); - foreach (var om in outputMaterials) - { - PrdMo subMo = new(); - subMo.material_id = om.material_id; - subMo.material_code = om.material_code; - subMo.plan_qty = om.num.ParseToInt() * curMo.plan_qty; - subMo.mo_type = curMo.mo_type; - subMo.parent_id = curMo.id; - subMo.plan_start_date = curMo.plan_start_date; - subMo.plan_end_date = curMo.plan_end_date; - subMo.create_id = _userManager.UserId; - subMo.create_time = DateTime.Now; - subMo.mo_status = DictConst.WaitProductId; - subMoList.Add(subMo); + PrdMo subMo = new(); + subMo.material_id = om.id; + subMo.material_code = om.code; + subMo.plan_qty = dicOutMaterialNum.ContainsKey(om.id) ? dicOutMaterialNum[om.id] * curMo.plan_qty : 0; + subMo.mo_type = curMo.mo_type; + subMo.parent_id = curMo.id; + subMo.plan_start_date = curMo.plan_start_date; + subMo.plan_end_date = curMo.plan_end_date; + subMo.create_id = _userManager.UserId; + subMo.create_time = DateTime.Now; + subMo.mo_status = DictConst.WaitProductId; + subMoList.Add(subMo); + } + //生成子工单编码 + for (int i = 0; i < subMoList.Count; i++) + { + var num = (i + 1).ToString().PadLeft(2, '0'); + subMoList[i].mo_code = $"{curMo.mo_code}-{num}"; + } + var row = await _db.Insertable(subMoList).ExecuteCommandAsync(); + if (row < 1) throw Oops.Oh(ErrorCode.COM1000); } - //生成子工单编码 - for (int i = 0; i < subMoList.Count; i++) - { - var num = (i + 1).ToString().PadLeft(2, '0'); - subMoList[i].mo_code = $"{subMoList[i].mo_code}-{num}"; - } - var row = await _db.Insertable(subMoList).ExecuteCommandAsync(); - if (row < 1) throw Oops.Oh(ErrorCode.COM1000); + } #endregion + private static dynamic DictionaryToObject(IDictionary dictionary) + { + var expandoObj = new ExpandoObject(); + var expandoObjCollection = (ICollection>)expandoObj; + + foreach (var keyValuePair in dictionary) + { + expandoObjCollection.Add(keyValuePair); + } + dynamic eoDynamic = expandoObj; + return eoDynamic; + } + + private static Dictionary dicProperties = new Dictionary(StringComparer.OrdinalIgnoreCase); + private static T DictionaryToObject(IDictionary dictionary) where T : class, new() + { + var name = typeof(T).Name; + T instance = new(); + if (!dicProperties.TryGetValue(name, out string[] properies)) + { + properies = instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Select(p => p.Name).ToArray(); + dicProperties[name] = properies; + } + //var properies = instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Select(p => p.Name).ToArray(); + foreach (var pn in properies) + { + if (dictionary.ContainsKey(pn)) + { + instance.PropertySetValue(pn, dictionary[pn]); + } + } + return instance; + } + + + private async Task GetList(VisualDevModelListQueryInput input) { diff --git a/common/Tnb.Common/Extension/DictionaryExtensions.cs b/common/Tnb.Common/Extension/DictionaryExtensions.cs index 962810bf..750a273e 100644 --- a/common/Tnb.Common/Extension/DictionaryExtensions.cs +++ b/common/Tnb.Common/Extension/DictionaryExtensions.cs @@ -1,4 +1,5 @@ -using JNPF.DependencyInjection; +using System.Reflection; +using JNPF.DependencyInjection; namespace JNPF.Common.Extension; @@ -8,6 +9,7 @@ namespace JNPF.Common.Extension; [SuppressSniffer] public static class DictionaryExtensions { + /// /// 从字典中获取值,不存在则返回字典类型的默认值. /// @@ -55,4 +57,31 @@ public static class DictionaryExtensions } } } + + private static Dictionary dicProperties = new Dictionary(StringComparer.OrdinalIgnoreCase); + /// + /// 字典转换成指定类型实例 + /// added by ly on 20230524 + /// + /// 转换的目标类型 + /// 被转换的字典 + /// 转换后的目标类型对象实例 + public static T ToObject(this Dictionary dictionary) where T : class, new() + { + var name = typeof(T).Name; + T instance = new(); + if (!dicProperties.TryGetValue(name, out string[] properies)) + { + properies = instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Select(p => p.Name).ToArray(); + dicProperties[name] = properies; + } + foreach (var pn in properies) + { + if (dictionary.ContainsKey(pn)) + { + instance.PropertySetValue(pn, dictionary[pn]); + } + } + return instance; + } } \ No newline at end of file diff --git a/common/Tnb.Common/Extension/LambdaExpressionExtensions.cs b/common/Tnb.Common/Extension/LambdaExpressionExtensions.cs index 1c1dc7b7..c4c0ddd9 100644 --- a/common/Tnb.Common/Extension/LambdaExpressionExtensions.cs +++ b/common/Tnb.Common/Extension/LambdaExpressionExtensions.cs @@ -18,11 +18,22 @@ namespace JNPF.Common.Extension } setAction(instance, value); } + + public static void PropertySetValue(this T instance, string propertyName, object value) + { + if (!PropertySet.ValueFactories2.TryGetValue(propertyName, out Action setAction)) + { + setAction = PropertySet.CreateSetPropertyValueAction2(propertyName); + PropertySet.ValueFactories2.Add(propertyName, setAction); + } + setAction(instance, value); + } } public class PropertySet { public static Dictionary> ValueFactories = new Dictionary>(StringComparer.OrdinalIgnoreCase); + public static Dictionary> ValueFactories2 = new Dictionary>(StringComparer.OrdinalIgnoreCase); public static Action CreateSetPropertyValueAction(string propertyName) { @@ -35,5 +46,17 @@ namespace JNPF.Common.Extension return Expression.Lambda>(setPropertyValue, target, propertyValue).Compile(); } + public static Action CreateSetPropertyValueAction2(string propertyName) + { + var property = typeof(T).GetProperty(propertyName); + var target = Expression.Parameter(typeof(T)); + var propExp = Expression.Property(target, propertyName); + var propertyValue = Expression.Parameter(typeof(object)); + var castPropertyValue = Expression.Convert(propertyValue, property!.PropertyType); + var assignExp = Expression.Assign(propExp, castPropertyValue); + + return Expression.Lambda>(assignExp, new[] { target,propertyValue }).Compile(); + } + } } diff --git a/common/Tnb.Common/Security/TreeHelper.cs b/common/Tnb.Common/Security/TreeHelper.cs index aecc76ff..cf50f9ee 100644 --- a/common/Tnb.Common/Security/TreeHelper.cs +++ b/common/Tnb.Common/Security/TreeHelper.cs @@ -43,6 +43,8 @@ public static class TreeHelper return resData; } + + #region 私有成员 /// diff --git a/visualdev/Tnb.VisualDev/RunService.cs b/visualdev/Tnb.VisualDev/RunService.cs index 4f35cd27..f794dc03 100644 --- a/visualdev/Tnb.VisualDev/RunService.cs +++ b/visualdev/Tnb.VisualDev/RunService.cs @@ -3023,7 +3023,11 @@ public class RunService : IRunService, ITransient { if (item.Value.IsNullOrEmpty()) continue; var itemValue = item.Value.ToString().Contains("[") ? item.Value.ToJsonString() : item.Value.ToString(); - + JArray jarr = null; + if (itemValue!.Contains("[")) + { + jarr = JArray.Parse(itemValue); + } if (model.searchType == 1) { conModels.Add(new ConditionalCollections() @@ -3041,9 +3045,17 @@ public class RunService : IRunService, ITransient } else { - conModels.Add(new ConditionalCollections() + if (jarr?.Children() != null && jarr?.Children().ToList().Count > 1) { - ConditionalList = new List>() + var values = string.Join(",", jarr.ToList().Select(t => t.Value())); + conModels.Add(new ConditionalModel { FieldName = item.Key, ConditionalType = ConditionalType.In, FieldValue = values }); + + } + else + { + conModels.Add(new ConditionalCollections() + { + ConditionalList = new List>() { new KeyValuePair(WhereType.And, new ConditionalModel { @@ -3052,7 +3064,8 @@ public class RunService : IRunService, ITransient FieldValue = itemValue }) } - }); + }); + } } }