齐套接口返回成功后再操作数据库,生产工单列表优化,提报完工数不能大于任务单数 完成后修改状态
This commit is contained in:
@@ -1313,6 +1313,13 @@ namespace Tnb.ProductionMgr
|
||||
var report = await db.Queryable<PrdReport>().FirstAsync(it => it.mo_task_id == input.mo_task_id);
|
||||
var prdMoTask = await db.Queryable<PrdMoTask>().SingleAsync(x => x.id == input.mo_task_id);
|
||||
|
||||
|
||||
bool flag = (prdMoTask.reported_work_qty ?? 0) + (prdMoTask.scrap_qty ?? 0) + input.reported_qty == prdMoTask.scheduled_qty;
|
||||
if ((prdMoTask.reported_work_qty ?? 0) + (prdMoTask.scrap_qty ?? 0) + input.reported_qty > prdMoTask.scheduled_qty)
|
||||
{
|
||||
throw Oops.Bah("已完成数量不能大于任务单数量");
|
||||
}
|
||||
|
||||
report = input.Adapt<PrdReport>();
|
||||
report.id = SnowflakeIdHelper.NextId();
|
||||
report.reported_qty = input.reported_qty;
|
||||
@@ -1346,6 +1353,7 @@ namespace Tnb.ProductionMgr
|
||||
await db.Updateable<PrdMoTask>()
|
||||
// .SetColumns(x => x.complete_qty == x.complete_qty + input.reported_qty)
|
||||
.SetColumns(x => x.reported_work_qty == input.reported_qty)
|
||||
.SetColumnsIF(flag,x=>x.mo_task_status==DictConst.ComplatedEnCode)
|
||||
.Where(x => x.id == input.mo_task_id).ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
@@ -1353,6 +1361,7 @@ namespace Tnb.ProductionMgr
|
||||
await db.Updateable<PrdMoTask>()
|
||||
// .SetColumns(x => x.complete_qty == x.complete_qty + input.reported_qty)
|
||||
.SetColumns(x => x.reported_work_qty == x.reported_work_qty + input.reported_qty)
|
||||
.SetColumnsIF(flag,x=>x.mo_task_status==DictConst.ComplatedEnCode)
|
||||
.Where(x => x.id == input.mo_task_id).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
@@ -1366,11 +1375,13 @@ namespace Tnb.ProductionMgr
|
||||
{
|
||||
await db.Updateable<PrdMoTask>()
|
||||
.SetColumns(x => x.last_process_complete_qty == input.reported_qty)
|
||||
.SetColumnsIF(flag,x=>x.mo_task_status==DictConst.ComplatedEnCode)
|
||||
.Where(x => x.id == prdMoTask.parent_id).ExecuteCommandAsync();
|
||||
}else if (parentMoTask?.last_process_complete_qty != null)
|
||||
{
|
||||
await db.Updateable<PrdMoTask>()
|
||||
.SetColumns(x => x.last_process_complete_qty == x.last_process_complete_qty + input.reported_qty)
|
||||
.SetColumnsIF(flag,x=>x.mo_task_status==DictConst.ComplatedEnCode)
|
||||
.Where(x => x.id == prdMoTask.parent_id).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
@@ -1386,81 +1397,81 @@ namespace Tnb.ProductionMgr
|
||||
|
||||
|
||||
//扣除生产投料 按最先投入的依次扣除
|
||||
List<PrdFeedingD> prdFeedingDs = await db.Queryable<PrdFeedingH>()
|
||||
.LeftJoin<PrdFeedingD>((a,b)=>a.id==b.feeding_id)
|
||||
.Where((a,b) => a.workline_id == prdMoTask.workline_id && (b.status=="0" || b.status=="1"))
|
||||
.OrderBy((a,b) => b.create_time)
|
||||
.Select((a,b)=>b)
|
||||
.ToListAsync();
|
||||
|
||||
if (prdFeedingDs != null && prdFeedingDs.Count>0)
|
||||
{
|
||||
|
||||
BasMbom basMbom = await db.Queryable<BasMbom>().SingleAsync(x => x.id == prdMoTask.bom_id);
|
||||
List<BasMbomInput> basMbomInputs = await db.Queryable<BasMbomInput>().Where(x =>
|
||||
x.mbom_id == prdMoTask.bom_id && x.mbom_process_id == prdMoTask.mbom_process_id).ToListAsync();
|
||||
|
||||
foreach (var item in basMbomInputs)
|
||||
{
|
||||
var details = prdFeedingDs.Where(x => x.material_id == item.material_id).OrderBy(x=>x.create_time).ToList();
|
||||
if (details?.Count>0)
|
||||
{
|
||||
decimal deductNum = input.reported_qty * item.num / basMbom.num;
|
||||
decimal? notUseNum = details.Sum(x => x.num - x.use_num);
|
||||
if (notUseNum > deductNum)
|
||||
{
|
||||
|
||||
foreach (var detail in details)
|
||||
{
|
||||
|
||||
if (deductNum - (detail.num - detail.use_num) < 0)
|
||||
{
|
||||
await db.Updateable<PrdFeedingD>().SetColumns(x => x.use_num == x.use_num+deductNum)
|
||||
.SetColumns(x=>x.status=="1")
|
||||
.Where(x => x.id == detail.id).ExecuteCommandAsync();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
await db.Updateable<PrdFeedingD>().SetColumns(x => x.use_num == x.num)
|
||||
.SetColumns(x=>x.status=="2")
|
||||
.Where(x => x.id == detail.id).ExecuteCommandAsync();
|
||||
|
||||
}
|
||||
|
||||
deductNum = deductNum - (detail.num - detail.use_num);
|
||||
|
||||
if (deductNum <= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (deductNum > 0)
|
||||
{
|
||||
throw new Exception("投入物料不足");
|
||||
}
|
||||
}
|
||||
else if(notUseNum == deductNum)
|
||||
{
|
||||
foreach (var detail in details)
|
||||
{
|
||||
await db.Updateable<PrdFeedingD>().SetColumns(x => x.use_num == x.num)
|
||||
.SetColumns(x=>x.status=="2")
|
||||
.Where(x => x.id == detail.id).ExecuteCommandAsync();
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("投入物料不足");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//throw new Exception("无投入物料");
|
||||
}
|
||||
}
|
||||
}
|
||||
// List<PrdFeedingD> prdFeedingDs = await db.Queryable<PrdFeedingH>()
|
||||
// .LeftJoin<PrdFeedingD>((a,b)=>a.id==b.feeding_id)
|
||||
// .Where((a,b) => a.workline_id == prdMoTask.workline_id && (b.status=="0" || b.status=="1"))
|
||||
// .OrderBy((a,b) => b.create_time)
|
||||
// .Select((a,b)=>b)
|
||||
// .ToListAsync();
|
||||
//
|
||||
// if (prdFeedingDs != null && prdFeedingDs.Count>0)
|
||||
// {
|
||||
//
|
||||
// BasMbom basMbom = await db.Queryable<BasMbom>().SingleAsync(x => x.id == prdMoTask.bom_id);
|
||||
// List<BasMbomInput> basMbomInputs = await db.Queryable<BasMbomInput>().Where(x =>
|
||||
// x.mbom_id == prdMoTask.bom_id && x.mbom_process_id == prdMoTask.mbom_process_id).ToListAsync();
|
||||
//
|
||||
// foreach (var item in basMbomInputs)
|
||||
// {
|
||||
// var details = prdFeedingDs.Where(x => x.material_id == item.material_id).OrderBy(x=>x.create_time).ToList();
|
||||
// if (details?.Count>0)
|
||||
// {
|
||||
// decimal deductNum = input.reported_qty * item.num / basMbom.num;
|
||||
// decimal? notUseNum = details.Sum(x => x.num - x.use_num);
|
||||
// if (notUseNum > deductNum)
|
||||
// {
|
||||
//
|
||||
// foreach (var detail in details)
|
||||
// {
|
||||
//
|
||||
// if (deductNum - (detail.num - detail.use_num) < 0)
|
||||
// {
|
||||
// await db.Updateable<PrdFeedingD>().SetColumns(x => x.use_num == x.use_num+deductNum)
|
||||
// .SetColumns(x=>x.status=="1")
|
||||
// .Where(x => x.id == detail.id).ExecuteCommandAsync();
|
||||
//
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// await db.Updateable<PrdFeedingD>().SetColumns(x => x.use_num == x.num)
|
||||
// .SetColumns(x=>x.status=="2")
|
||||
// .Where(x => x.id == detail.id).ExecuteCommandAsync();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// deductNum = deductNum - (detail.num - detail.use_num);
|
||||
//
|
||||
// if (deductNum <= 0)
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// if (deductNum > 0)
|
||||
// {
|
||||
// throw new Exception("投入物料不足");
|
||||
// }
|
||||
// }
|
||||
// else if(notUseNum == deductNum)
|
||||
// {
|
||||
// foreach (var detail in details)
|
||||
// {
|
||||
// await db.Updateable<PrdFeedingD>().SetColumns(x => x.use_num == x.num)
|
||||
// .SetColumns(x=>x.status=="2")
|
||||
// .Where(x => x.id == detail.id).ExecuteCommandAsync();
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new Exception("投入物料不足");
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new Exception("无投入物料");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user