diff --git a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs index c413b9b4..25e27e82 100644 --- a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs +++ b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs @@ -72,8 +72,11 @@ public static class DictConst /// 工单状态-强制接单 /// public const string MoCloseId = "25501969636645"; - - + /// + /// 工单状态-code + /// + public const string MoTaskStatusCode = "OrderStatus"; + /// /// 工单状态 已下发字典Id /// diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoStatisticsInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoStatisticsInput.cs new file mode 100644 index 00000000..45254ca1 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoStatisticsInput.cs @@ -0,0 +1,16 @@ +namespace Tnb.ProductionMgr.Entities.Dto.PrdManage +{ + public class PrdMoStatisticsInput + { + public string mo_status { get; set; } + /// + /// 页码. + /// + public int currentPage { get; set; } + + /// + /// 页容量. + /// + public int pageSize { get; set; } + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoStatisticsOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoStatisticsOutput.cs new file mode 100644 index 00000000..e867dd4c --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoStatisticsOutput.cs @@ -0,0 +1,29 @@ +namespace Tnb.ProductionMgr.Entities.Dto.PrdManage +{ + public class PrdMoStatisticsOutput + { + public string id { get; set; } + public string mo_code { get; set; } + public string mo_status { get; set; } + public string material_name { get; set; } + public string material_code { get; set; } + public decimal? plan_qty { get; set; } + public decimal? scheduled_qty { get; set; } + public decimal? tobe_scheduled_qty { get; set; } + public decimal? reported_work_qty { get; set; } + public decimal? complete_rate { get; set; } + public List children { get; set; } = new List(); + } + + public class PrdMoStatisticsDetailOutput + { + public string id { get; set; } + public string mo_task_code { get; set; } + public string mo_task_status { get; set; } + public string estimated_start_date { get; set; } + public string estimated_end_date { get; set; } + public decimal? scheduled_qty { get; set; } + public decimal? reported_work_qty { get; set; } + public decimal? scrap_qty { get; set; } + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs index 9c7ca149..425a792d 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs @@ -362,7 +362,52 @@ namespace Tnb.ProductionMgr .ExecuteCommandHasChangeAsync(); } - + /// + /// 工单统计 + /// + /// + /// + [HttpPost] + public async Task GetPrdMoStatistics(PrdMoStatisticsInput input) + { + var result = await _db.Queryable() + .LeftJoin((a, b) => a.mo_status == b.Id) + .LeftJoin((a, b, c) => a.material_id == c.id) + .WhereIF(!string.IsNullOrEmpty(input.mo_status), (a, b) => b.EnCode == input.mo_status) + // .OrderByDescending((a,b,c)=>a.reported_work_qty==null?0:a.reported_work_qty*100/a.plan_qty) + .Select((a, b, c) => new PrdMoStatisticsOutput + { + id = a.id, + mo_code = a.mo_code, + mo_status = b.FullName, + material_code = c.code, + material_name = c.name, + plan_qty = a.plan_qty, + scheduled_qty = a.scheduled_qty, + tobe_scheduled_qty = a.plan_qty - a.scheduled_qty, + reported_work_qty = a.reported_work_qty, + complete_rate = a.reported_work_qty==null?0:SqlFunc.ToDecimal(a.reported_work_qty*100)/SqlFunc.ToDecimal(a.plan_qty), + children = SqlFunc.Subqueryable() + .LeftJoin((x,y)=>x.mo_task_code==y.EnCode && y.DictionaryTypeId==DictConst.PrdTaskStatusTypeId) + .Where(x=>x.mo_id==a.id) + .OrderByDesc((x,y)=>x.create_time) + .ToList((x,y)=>new PrdMoStatisticsDetailOutput() + { + id = x.id, + mo_task_code = x.mo_task_code, + mo_task_status = y.FullName, + estimated_start_date = x.estimated_start_date==null ? "" : x.estimated_start_date.Value.ToString("yyyy-MM-dd HH:mm:ss"), + estimated_end_date = x.estimated_end_date==null ? "" : x.estimated_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss"), + scheduled_qty = x.scheduled_qty, + reported_work_qty = x.reported_work_qty, + scrap_qty = x.scrap_qty, + }), + }) + .MergeTable().OrderByDescending(a=>a.complete_rate) + .ToPagedListAsync(input.currentPage, input.pageSize); + + return PageResult.SqlSugarPageResult(result); + } #endregion diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index 87d405c5..ece210a1 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -670,6 +670,9 @@ namespace Tnb.ProductionMgr if (input.schedule_type.Value == 1) //注塑、基础排产 { var mo = await db.Queryable().FirstAsync(it => it.id == input.mo_id); + BasMbomProcess basMbomProcess = null; + if(!string.IsNullOrEmpty(input.bom_id)) + basMbomProcess = await db.Queryable().FirstAsync(x => x.mbom_id == input.bom_id); var moTask = input.Adapt(); moTask.id = SnowflakeIdHelper.NextId(); moTask.create_id = _userManager.UserId; @@ -677,6 +680,7 @@ namespace Tnb.ProductionMgr moTask.mo_task_status = DictConst.ToBeScheduledEncode; moTask.scheduled_qty = input.scheduled_qty; moTask.unit_id = mo.unit_id; + moTask.mbom_process_id = basMbomProcess?.id ?? ""; if (!string.IsNullOrEmpty(input.eqp_id)) { @@ -2335,6 +2339,26 @@ namespace Tnb.ProductionMgr return result.IsSuccess ? "排产成功" : result.ErrorMessage; } + /// + /// 获取工单各个状态数量 + /// + /// + [HttpPost] + public async Task GetMoTaskStatusNum() + { + return await _db.Queryable(). + LeftJoin((a,b)=>a.Id==b.DictionaryTypeId) + .LeftJoin((a,b,c)=>b.Id==c.mo_status) + .Where((a,b,c)=>a.EnCode==DictConst.MoTaskStatusCode) + .GroupBy((a,b,c)=>new { mo_status_code = b.EnCode,mo_status_name = b.FullName}) + .Select((a,b,c) => new + { + mo_status_code = b.EnCode, + mo_status_name = b.FullName, + count = SqlFunc.AggregateCount(c.mo_status) + }).ToListAsync(); + } + }