diff --git a/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkplanController.cs b/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkplanController.cs index 2e2c217f..049325ba 100644 --- a/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkplanController.cs +++ b/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkplanController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.IdentityModel.Tokens; using ZR.Admin.WebApi.Extensions; using ZR.Model.mes.md; using ZR.Model.mes.pro; @@ -182,34 +183,59 @@ namespace ZR.Admin.WebApi.Controllers.MES.pro if (!string.IsNullOrEmpty(workPlanId) && !string.IsNullOrEmpty(workorderId)) { - // 查询生产计划对象 - List lstWorkplan = proWorkplanService.GetProWorkplanById(workPlanId); + string isArrange = "0"; - // 查询所有生产工单 - List lstWorkorder = proWorkplanService.GetWorkorderList(workorderId); + // 查询所有生产工单,根据生产计划ID + List lstWorkorder = proWorkplanService.GetWorkorderList(workPlanId); - // 计算所有工单的数量和,生产计划的数量:比较 - if (lstWorkplan != null && lstWorkplan.Count == 1) + // 找到要更新的工单,要判断当前工单状态 + ProWorkorder currentWorkorder = null; + foreach (ProWorkorder item in lstWorkorder) { - int countWorkplan = int.Parse(lstWorkplan[0].ActualplanNumber.Trim()); - int countWorkorder = 0; - foreach (ProWorkorder item in lstWorkorder) + if(item.Id.Equals(workorderId) && !string.IsNullOrEmpty(item.Isarrange)) { - countWorkorder += item.Actualnumber.GetValueOrDefault(); - } - countWorkorder += proWorkorder.Actualnumber.GetValueOrDefault(); - - // 计划数>0 计划数要大于等于当前工单总数 - if (countWorkplan > 0 && (countWorkplan >= countWorkorder)) - { - proWorkorder.ToUpdate(HttpContext); - data = proWorkplanService.UpdateWorkorder(proWorkorder); - } - else - { - data = 2; + isArrange = item.Isarrange; + currentWorkorder = item; + break; } } + + // 状态为未排产状态,才能更新 + if ("0".Equals(isArrange)) + { + // 查询生产计划对象 + List lstWorkplan = proWorkplanService.GetProWorkplanById(workPlanId); + + // 计算所有工单的数量和,生产计划的数量:比较 + 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(); + } + if(currentWorkorder!=null) countWorkorder -= currentWorkorder.Actualnumber.GetValueOrDefault(); // 减去当前工单的数值 + + // 再加上要更新的值 + countWorkorder += proWorkorder.Actualnumber.GetValueOrDefault(); + + // 计划数>0 计划数要大于等于当前工单总数 + if (countWorkplan > 0 && (countWorkplan >= countWorkorder)) + { + proWorkorder.ToUpdate(HttpContext); + data = proWorkplanService.UpdateWorkorder(proWorkorder); + } + else + { + data = 2; + } + } + } + else data = 3; + } } diff --git a/ZR.Service/mes/pro/IService/IProWorkplanService.cs b/ZR.Service/mes/pro/IService/IProWorkplanService.cs index c0c1d27c..d0565dbc 100644 --- a/ZR.Service/mes/pro/IService/IProWorkplanService.cs +++ b/ZR.Service/mes/pro/IService/IProWorkplanService.cs @@ -14,6 +14,11 @@ namespace ZR.Service.mes.pro.IService public (List,int) GetAllData(int pageNum, int pageSize, int year, int week, string partNumber, string color); + /// + /// 根据计划ID,获取对象 + /// + /// + /// public List GetProWorkplanById(string id); public int AddWorkPlan(ProWorkplan proWorkplan); @@ -22,6 +27,11 @@ namespace ZR.Service.mes.pro.IService public int DeleteWorkPlan(string id); + /// + /// 根据生产计划ID,获取工单列表 + /// + /// + /// public List GetWorkorderList(string id); public int AddWorkorder(ProWorkorder proWorkorder); diff --git a/ZR.Service/mes/pro/ProWorkplanService.cs b/ZR.Service/mes/pro/ProWorkplanService.cs index 7cd723ad..c9842456 100644 --- a/ZR.Service/mes/pro/ProWorkplanService.cs +++ b/ZR.Service/mes/pro/ProWorkplanService.cs @@ -32,6 +32,7 @@ namespace ZR.Service.mes.pro return (proWorkplanList, totalCount); } + public List GetProWorkplanById(string id) { return Context.Queryable().Where(it => it.Id == id).ToList();