diff --git a/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkplanController.cs b/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkplanController.cs index 43cf33bb..5303198d 100644 --- a/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkplanController.cs +++ b/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkplanController.cs @@ -118,12 +118,47 @@ namespace ZR.Admin.WebApi.Controllers.MES.pro [HttpPost("addworkorder")] public IActionResult AddWorkorder([FromBody] ProWorkorder proWorkorder) { + // TODO 获取工单对象 + // TODO 增加插入时间,插入人员:ToCreate + // TODO 根据工单对象里的计划ID,查询生产计划的数量,判断工单数和要小于等于计划数:能插入,正常返回,0或1;大于,2 + int data = 0; if (proWorkorder != null) { - proWorkorder.ToCreate(HttpContext); - data = proWorkplanService.AddWorkorder(proWorkorder); - + string workPlanId = proWorkorder.FkProPlanId; + string workorderId = proWorkorder.Id; + + if (!string.IsNullOrEmpty(workPlanId) && !string.IsNullOrEmpty(workorderId)) + { + // 查询生产计划对象 + List lstWorkplan = proWorkplanService.GetProWorkplanById(workPlanId); + + // 查询所有生产工单 + List lstWorkorder = proWorkplanService.GetWorkorderList(workorderId); + + // 计算所有工单的数量和,生产计划的数量:比较 + if(lstWorkplan!=null && lstWorkplan.Count==1) + { + int countWorkplan = int.Parse(lstWorkplan[0].ActualplanNumber.Trim()); + int countWorkorder = 0; + foreach (ProWorkorder item in lstWorkorder) + { + countWorkorder += item.Actualnumber.GetValueOrDefault(); + } + countWorkorder += proWorkorder.Actualnumber.GetValueOrDefault(); + + // 计划数>0 计划数要大于等于当前工单总数 + if(countWorkplan > 0 && (countWorkplan>= countWorkorder)) + { + proWorkorder.ToCreate(HttpContext); + data = proWorkplanService.AddWorkorder(proWorkorder); + } + else + { + data = 2; + } + } + } } return ToResponse(new ApiResult(200, "success", data)); @@ -137,9 +172,23 @@ namespace ZR.Admin.WebApi.Controllers.MES.pro [HttpPost("updateworkplan")] public IActionResult UpdateWorkorder([FromBody] ProWorkorder proWorkorder) { + // TODO 判断更新的数量是否超过计划数 + int data = 0; if (proWorkorder != null) { + + string workPlanId = proWorkorder.FkProPlanId; + if (!string.IsNullOrEmpty(workPlanId)) + { + // 查询生产计划对象 + + // 查询所有生产工单 + + // 计算所有工单的数量和,生产计划的数量:比较 + + } + proWorkorder.ToUpdate(HttpContext); data = proWorkplanService.UpdateWorkorder(proWorkorder); diff --git a/ZR.Service/mes/pro/IService/IProWorkplanService.cs b/ZR.Service/mes/pro/IService/IProWorkplanService.cs index 27723f6c..c0c1d27c 100644 --- a/ZR.Service/mes/pro/IService/IProWorkplanService.cs +++ b/ZR.Service/mes/pro/IService/IProWorkplanService.cs @@ -14,6 +14,8 @@ namespace ZR.Service.mes.pro.IService public (List,int) GetAllData(int pageNum, int pageSize, int year, int week, string partNumber, string color); + public List GetProWorkplanById(string id); + public int AddWorkPlan(ProWorkplan proWorkplan); public int UpdateWorkPlan(ProWorkplan proWorkplan); diff --git a/ZR.Service/mes/pro/ProWorkplanService.cs b/ZR.Service/mes/pro/ProWorkplanService.cs index a767886b..dea10e53 100644 --- a/ZR.Service/mes/pro/ProWorkplanService.cs +++ b/ZR.Service/mes/pro/ProWorkplanService.cs @@ -32,6 +32,10 @@ namespace ZR.Service.mes.pro return (proWorkplanList, totalCount); } + public List GetProWorkplanById(string id) + { + return Context.Queryable().Where(it => it.Id == id).ToList(); + } public int AddWorkPlan(ProWorkplan proWorkplan) { @@ -70,5 +74,7 @@ namespace ZR.Service.mes.pro { return Context.Deleteable().In(id).ExecuteCommand(); } + + } }