diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialPreparationPlanOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialPreparationPlanOutput.cs new file mode 100644 index 00000000..f8c367bd --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MaterialPreparationPlanOutput.cs @@ -0,0 +1,30 @@ +namespace Tnb.ProductionMgr.Entities.Dto.PrdManage +{ + public class MaterialPreparationPlanOutput + { + public string mo_task_id { get; set; } + public string mo_task_code { get; set; } + public string material_id { get; set; } + public string material_code { get; set; } + public int? num { get; set; } + public List children { get; set; } = new List(); + } + + public class MaterialPreparationPlanDOutput + { + public int? rate_num { get; set; } + public string mo_task_id { get; set; } + public string mo_task_code { get; set; } + public string parent_id { get; set; } + public string material_id { get; set; } + public string material_code { get; set; } + public List children { get; set; } = new List(); + } + + public class MaterialPreparationPlanDDOutput + { + public string material_id { get; set; } + public string material_code { get; set; } + public decimal? num { get; set; } + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMoTaskService.cs index 16eca732..29f0b0aa 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMoTaskService.cs @@ -19,5 +19,12 @@ namespace Tnb.ProductionMgr.Interfaces /// /// Task> GetListByEqpId(string eqpId); + + /// + /// 获取备料计划 + /// + /// + Task GetMaterialPreparationPlan(); + } } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index e04856d5..7f2dea96 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -2121,7 +2121,7 @@ namespace Tnb.ProductionMgr return await _db.Queryable().Where(it => it.eqp_id == eqpId && it.mo_task_status == DictConst.InProgressEnCode).ToListAsync(); } - + /// /// 计算预计结束日期 /// @@ -2607,6 +2607,70 @@ namespace Tnb.ProductionMgr count = SqlFunc.AggregateCount(c.mo_status) }).ToListAsync(); } + + + /// + /// 获取备料计划 + /// + /// + public async Task GetMaterialPreparationPlan() + { + string now = DateTime.Now.ToString("yyyy-MM-dd"); + var childrenList = await _db.Queryable() + .LeftJoin((a, b) => a.id == b.parent_id) + .LeftJoin((a, b, c) => b.material_id == c.id) + .Where((a, b) => a.schedule_type == 2 && string.IsNullOrEmpty(a.parent_id) && a.estimated_start_date.Value.ToString("yyyy-MM-dd") == now) + .Select((a, b, c) => new MaterialPreparationPlanDOutput + { + mo_task_id = b.id, + mo_task_code = b.mo_task_code, + rate_num = SqlFunc.Subqueryable().Where(o => o.id == a.bom_id) + .OrderByDesc(o => o.create_time).Select(o => o.num), + parent_id = b.parent_id, + material_id = b.material_id, + material_code = c.code, + children = SqlFunc.Subqueryable() + .LeftJoin((x, y) => x.material_id == y.id) + .Where((x, y) => x.mbom_process_id == b.mbom_process_id) + .ToList((x, y) => new MaterialPreparationPlanDDOutput() + { + material_id = x.material_id, + material_code = y.code, + num = x.num + }) + + }).ToListAsync(); + + var prdMoTaskList = await _db.Queryable() + .LeftJoin((a, b) => a.material_id == b.id) + .Where(a => a.schedule_type == 2 && string.IsNullOrEmpty(a.parent_id) && a.estimated_start_date.Value.ToString("yyyy-MM-dd") == now) + .Select((a,b)=>new MaterialPreparationPlanOutput() + { + mo_task_id = a.id, + mo_task_code = a.mo_task_code, + material_id = b.id, + material_code = b.code, + num = a.scheduled_qty, + }) + .ToListAsync(); + + foreach (var item in prdMoTaskList) + { + item.children = childrenList.Where(x => x.parent_id == item.mo_task_id).ToList(); + foreach (var itemChild in item.children) + { + foreach (var itemChildChild in itemChild.children) + { + if (itemChildChild.num > 0 && itemChild.rate_num != null && itemChild.rate_num>0) + { + itemChildChild.num = item.num * itemChildChild.num / itemChild.rate_num; + } + } + } + } + + return prdMoTaskList; + } }