载具更换代码优化
This commit is contained in:
@@ -83,57 +83,7 @@ namespace Tnb.EquipMgr
|
||||
[HttpPost]
|
||||
public async Task RelevanceMaintianGroupAndItem(MoldMaintainGroupItemInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
if (input.ids == null || input.ids.Count == 0) throw new ArgumentException($"parameter {nameof(input.ids)} not be null or count not be zero");
|
||||
await Relevance<MoldMaintainGroupItemInput, ToolMoldMaintainGroupItem>(input, nameof(ToolMoldMaintainGroupItem.item_group_id), nameof(ToolMoldMaintainGroupItem.item_id), it => it.item_group_id == input.id);
|
||||
List<ToolMoldMaintainItemRecord> itemRecords = new();
|
||||
var grpIds = await _db.Queryable<ToolMoldMaintainGroupItem>().Where(it => input.ids.Contains(it.item_id)).Select(it => it.item_group_id).Distinct().ToListAsync();
|
||||
if (grpIds?.Count > 0)
|
||||
{
|
||||
var grps = await _db.Queryable<ToolMoldMaintainGroup>().Where(it => grpIds.Contains(it.id)).ToListAsync();
|
||||
foreach (var grp in grps)
|
||||
{
|
||||
var molds = await _db.Queryable<ToolMoldMaintainGroupRelation>().Where(it => it.item_group_id == grp.id).ToListAsync();
|
||||
if (molds?.Count > 0)
|
||||
{
|
||||
foreach (var mold in molds)
|
||||
{
|
||||
var dbItIds = await _db.Queryable<ToolMoldMaintainItemRecord>().Where(it => it.mold_id == mold.id && it.item_group_id == grp.id && input.ids.Contains(it.id)).Select(it => it.item_id).ToListAsync();
|
||||
input.ids = input.ids.Except(dbItIds).ToList();
|
||||
if (input.ids?.Count > 0)
|
||||
{
|
||||
var items = await _db.Queryable<ToolMoldMaintainItem>().Where(it => input.ids.Contains(it.id)).ToListAsync();
|
||||
if (items?.Count > 0)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
ToolMoldMaintainItemRecord record = new();
|
||||
record.mold_id = mold.id;
|
||||
record.item_group_id = grp.id;
|
||||
record.item_group_name = grp.name;
|
||||
record.item_id = item.id;
|
||||
record.item_name = item.name;
|
||||
record.status = 0;
|
||||
itemRecords.Add(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
await _db.Insertable(itemRecords).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
throw;
|
||||
}
|
||||
await Relevance<MoldMaintainGroupItemInput, ToolMoldMaintainGroupItem>(input, nameof(ToolMoldMaintainGroupItem.item_group_id), nameof(ToolMoldMaintainGroupItem.item_id), it => it.item_group_id == input.id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -145,41 +95,6 @@ namespace Tnb.EquipMgr
|
||||
public async Task RelevanceMaintianGroupAndMold(MoldMaintainGroupItemRelationInput input)
|
||||
{
|
||||
await Relevance<MoldMaintainGroupItemRelationInput, ToolMoldMaintainGroupRelation>(input, nameof(ToolMoldMaintainGroupRelation.item_group_id), nameof(ToolMoldMaintainGroupRelation.mold_id), it => it.item_group_id == input.id);
|
||||
List<ToolMoldMaintainItemRecord> itemRecords = new();
|
||||
foreach (var moldId in input.ids)
|
||||
{
|
||||
var grpIds = await _db.Queryable<ToolMoldMaintainGroupRelation>().Where(it => it.mold_id == moldId).Select(it => it.item_group_id).Distinct().ToListAsync();
|
||||
if (grpIds?.Count > 0)
|
||||
{
|
||||
var grps = await _db.Queryable<ToolMoldMaintainGroup>().Where(it => grpIds.Contains(it.id)).ToListAsync();
|
||||
foreach (var grp in grps)
|
||||
{
|
||||
var itemIds = await _db.Queryable<ToolMoldMaintainGroupItem>().Where(it => it.item_group_id == grp.id).Select(it => it.item_id).ToListAsync();
|
||||
if (itemIds?.Count > 0)
|
||||
{
|
||||
var dbItemIds = await _db.Queryable<ToolMoldMaintainItemRecord>().Where(it => it.mold_id == moldId && it.item_group_id == grp.id && itemIds.Contains(it.item_id)).Select(it => it.item_id).ToListAsync();
|
||||
itemIds = itemIds.Except(dbItemIds).ToList();
|
||||
if (itemIds?.Count > 0)
|
||||
{
|
||||
var items = await _db.Queryable<ToolMoldMaintainItem>().Where(it => itemIds.Contains(it.id)).ToListAsync();
|
||||
foreach (var item in items)
|
||||
{
|
||||
ToolMoldMaintainItemRecord record = new();
|
||||
record.mold_id = moldId;
|
||||
record.item_group_id = grp.id;
|
||||
record.item_group_name = grp.name;
|
||||
record.item_id = item.id;
|
||||
record.item_name = item.name;
|
||||
record.status = 0;
|
||||
itemRecords.Add(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
await _db.Insertable(itemRecords).ExecuteCommandAsync();
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除项目组与模具检查项信息
|
||||
|
||||
Reference in New Issue
Block a user