模具保养运行,代码优化
This commit is contained in:
@@ -135,7 +135,6 @@ namespace Tnb.EquipMgr
|
||||
item_name = e.name,
|
||||
})
|
||||
.ToListAsync();
|
||||
//items.ForEach(it => it.status = 0);
|
||||
var checkItems = await _db.Queryable<ToolMoldMaintainItemRecord>().Where(it => it.plan_id == input.plan_id && it.mold_id == input.mold_id).Select(it => new
|
||||
{
|
||||
plan_id = it.plan_id,
|
||||
@@ -143,16 +142,15 @@ namespace Tnb.EquipMgr
|
||||
item_group_id = it.item_group_id,
|
||||
mold_id = it.mold_id,
|
||||
}).ToListAsync();
|
||||
var dicCheckItems = checkItems.GroupBy(g => $"{g.plan_id}{g.mold_id}{g.item_group_id}{g.item_id}").ToDictionary(x => x.Key, x => x.FirstOrDefault());
|
||||
if (items?.Count > 0 && checkItems?.Count > 0)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
foreach (var checkItem in checkItems)
|
||||
var key = $"{item.plan_id}{item.mold_id}{item.item_group_id}{item.item_id}";
|
||||
if (dicCheckItems.ContainsKey(key) && dicCheckItems[key] != null)
|
||||
{
|
||||
if (item.plan_id == checkItem.plan_id && item.mold_id == checkItem.mold_id && item.item_group_id == checkItem.item_group_id && item.item_id == checkItem.item_id)
|
||||
{
|
||||
item.status = 1;
|
||||
}
|
||||
item.status = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,33 +267,49 @@ namespace Tnb.EquipMgr
|
||||
[HttpPost]
|
||||
public async Task MaintainFinish(MoldMaintainRunUpInput input)
|
||||
{
|
||||
if (input == null) throw new ArgumentNullException("input");
|
||||
var grpIds = await _db.Queryable<ToolMoldMaintainGroupRelation>()
|
||||
.LeftJoin<ToolMolds>((a, b) => a.mold_id == b.id)
|
||||
.Where(a => a.mold_id == input.mold_id)
|
||||
.Select((a, b) => a.item_group_id)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
var itemIds = await _db.Queryable<ToolMoldMaintainGroupItem>().Where(it => grpIds.Contains(it.item_group_id)).Select(it => it.item_id).ToListAsync();
|
||||
if (itemIds?.Count > 0)
|
||||
var items = await _db.Queryable<ToolMoldMaintainPlanRelation>()
|
||||
.InnerJoin<ToolMoldMaintainGroupRelation>((a, b) => a.mold_id == b.mold_id)
|
||||
.InnerJoin<ToolMoldMaintainGroupItem>((a, b, c) => b.item_group_id == c.item_group_id)
|
||||
.InnerJoin<ToolMoldMaintainGroup>((a, b, c, d) => c.item_group_id == d.id)
|
||||
.InnerJoin<ToolMoldMaintainItem>((a, b, c, d, e) => c.item_id == e.id)
|
||||
.Where((a) => a.maintain_plan_id == input.plan_id && a.mold_id == input.mold_id)
|
||||
.Select((a, b, c, d, e) => new CheckItemOutput
|
||||
{
|
||||
plan_id = a.maintain_plan_id,
|
||||
mold_id = a.mold_id,
|
||||
item_group_id = d.id,
|
||||
item_group_name = d.name,
|
||||
item_id = e.id,
|
||||
item_name = e.name,
|
||||
})
|
||||
.ToListAsync();
|
||||
var checkItems = await _db.Queryable<ToolMoldMaintainItemRecord>().Where(it => it.plan_id == input.plan_id && it.mold_id == input.mold_id).Select(it => new
|
||||
{
|
||||
var items = await _db.Queryable<ToolMoldMaintainItemRecord>().Where(it => it.mold_id == input.mold_id && it.status == 1).ToListAsync();
|
||||
if (items?.Count < itemIds.Count)
|
||||
plan_id = it.plan_id,
|
||||
item_id = it.item_id,
|
||||
item_group_id = it.item_group_id,
|
||||
mold_id = it.mold_id,
|
||||
}).ToListAsync();
|
||||
var dicCheckItems = checkItems.GroupBy(g => $"{g.plan_id}{g.mold_id}{g.item_group_id}{g.item_id}").ToDictionary(x => x.Key, x => x.FirstOrDefault());
|
||||
var maintainedItems = items.Where(it => dicCheckItems.ContainsKey($"{it.plan_id}{it.mold_id}{it.item_group_id}{it.item_id}") && dicCheckItems[$"{it.plan_id}{it.mold_id}{it.item_group_id}{it.item_id}"] != null).ToList();
|
||||
if ((items?.Count > 0 && maintainedItems?.Count > 0 )|| (maintainedItems == null || maintainedItems.Count < 1))
|
||||
{
|
||||
if (maintainedItems.Count < items.Count || (maintainedItems == null || maintainedItems.Count < 1))
|
||||
{
|
||||
throw new AppFriendlyException("当前模具有未完成的保养项目", 500);
|
||||
}
|
||||
var row = await _db.Updateable<ToolMolds>().SetColumns(it => new ToolMolds { mold_status = MoldUseStatus.MOLD_USE_STATUS_ZK_ID }).Where(it => it.id == input.mold_id).ExecuteCommandAsync();
|
||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
|
||||
var allMoldStatus = await _db.Queryable<ToolMoldMaintainPlanRelation>().InnerJoin<ToolMolds>((a, b) => a.mold_id == b.id)
|
||||
.Where((a, b) => a.maintain_plan_id == input.plan_id)
|
||||
.Select((a, b) => b.mold_status)
|
||||
.ToListAsync();
|
||||
if (allMoldStatus?.Count > 0 && allMoldStatus.All(x => x == MoldUseStatus.MOLD_USE_STATUS_ZK_ID))
|
||||
{
|
||||
row = await _db.Updateable<ToolMoldMaintainPlan>().SetColumns(it => new ToolMoldMaintainPlan { status = MoldPlanMaintainStatus.MOLDPLAN_MAINTAIN_STATUS_COMPLETED_CODE }).Where(it => it.id == input.plan_id).ExecuteCommandAsync();
|
||||
}
|
||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
|
||||
}
|
||||
var row = await _db.Updateable<ToolMolds>().SetColumns(it => new ToolMolds { mold_status = MoldUseStatus.MOLD_USE_STATUS_ZK_ID }).Where(it => it.id == input.mold_id).ExecuteCommandAsync();
|
||||
var allMoldStatus = await _db.Queryable<ToolMoldMaintainPlanRelation>().InnerJoin<ToolMolds>((a, b) => a.mold_id == b.id)
|
||||
.Where((a, b) => a.maintain_plan_id == input.plan_id)
|
||||
.Select((a, b) => b.mold_status)
|
||||
.ToListAsync();
|
||||
if (allMoldStatus?.Count > 0 && allMoldStatus.All(x => x == MoldUseStatus.MOLD_USE_STATUS_ZK_ID))
|
||||
{
|
||||
row = await _db.Updateable<ToolMoldMaintainPlan>().SetColumns(it => new ToolMoldMaintainPlan { status = MoldPlanMaintainStatus.MOLDPLAN_MAINTAIN_STATUS_COMPLETED_CODE }).Where(it => it.id == input.plan_id).ExecuteCommandAsync();
|
||||
}
|
||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user