更新工单逻辑

This commit is contained in:
xiaowei.song
2023-11-16 09:28:10 +08:00
parent 09cc50304a
commit 1c6119e17f
3 changed files with 59 additions and 22 deletions

View File

@@ -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<ProWorkplan> lstWorkplan = proWorkplanService.GetProWorkplanById(workPlanId);
string isArrange = "0";
// 查询所有生产工单
List<ProWorkorder> lstWorkorder = proWorkplanService.GetWorkorderList(workorderId);
// 查询所有生产工单根据生产计划ID
List<ProWorkorder> 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<ProWorkplan> 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;
}
}