模具保养执行业务代码调整

This commit is contained in:
DEVICE8\12494
2023-05-31 10:34:59 +08:00
parent ea3a325ecb
commit 600cd6d900
8 changed files with 314 additions and 93 deletions

View File

@@ -19,6 +19,8 @@ using JNPF.Common.Contracts;
using Tnb.EquipMgr.Entities;
using Tnb.EquipMgr.Entities.Dto;
using Tnb.EquipMgr.Interfaces;
using Senparc.Weixin.MP.AdvancedAPIs.GroupMessage;
using Aop.Api.Domain;
namespace Tnb.EquipMgr
{
@@ -79,8 +81,60 @@ namespace Tnb.EquipMgr
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task RelevanceMaintianGroupAndItem(MoldMaintainGroupItemInput input) =>
await Relevance<MoldMaintainGroupItemInput, ToolMoldMaintainGroupItem>(input, nameof(ToolMoldMaintainGroupItem.item_group_id), nameof(ToolMoldMaintainGroupItem.item_id), it => it.item_group_id == input.id);
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;
}
}
/// <summary>
/// 关联项目组与模具
@@ -88,8 +142,45 @@ namespace Tnb.EquipMgr
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task RelevanceMaintianGroupAndMold(MoldMaintainGroupItemRelationInput input) =>
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>
/// 删除项目组与模具检查项信息
/// </summary>
@@ -98,14 +189,15 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task Delete(MoldMaintainDelInput input)
{
if (input.table_name == "item")
{
await Delete<ToolMoldMaintainGroupItem>(it => it.item_group_id == input.id && input.ids.Contains(it.item_id));
await Delete<ToolMoldMaintainItemRecord>(it => it.item_group_id == input.id && input.ids.Contains(it.item_id));
}
else
{
await Delete<ToolMoldMaintainGroupRelation>(it => it.item_group_id == input.id && input.ids.Contains(it.mold_id));
await Delete<ToolMoldMaintainItemRecord>(it => it.item_group_id == input.id && input.ids.Contains(it.mold_id));
}
}