载具更换代码优化

This commit is contained in:
DEVICE8\12494
2023-06-02 08:39:27 +08:00
parent 38a62de63a
commit 73445f813e
22 changed files with 496 additions and 207 deletions

View File

@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.EquipMgr.Entities.Dto
{
public class CheckItemOutput
{
/// <summary>
/// 计划ID
/// </summary>
public string plan_id { get; set; }
/// <summary>
/// 模具ID
/// </summary>
public string mold_id { get; set; }
/// <summary>
/// 保养组id
/// </summary>
public string item_group_id { get; set; }
/// <summary>
/// 保养组名称
/// </summary>
public string item_group_name { get; set; }
/// <summary>
/// 保养项id
/// </summary>
public string item_id { get; set; }
/// <summary>
/// 保养项名称
/// </summary>
public string item_name { get; set; }
/// <summary>
/// 保养项,保养状态
/// </summary>
public int status { get; set; } = 0;
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.EquipMgr.Entities.Dto
{
/// <summary>
/// 根据模具ID、计划ID获取保养组及项目信息
/// </summary>
public class CheckItemQueryinput
{
/// <summary>
/// 计划ID
/// </summary>
public string plan_id { get; set; }
/// <summary>
/// 模具ID
/// </summary>
public string mold_id { get; set; }
}
}

View File

@@ -16,16 +16,26 @@ namespace Tnb.EquipMgr.Entities.Dto
/// </summary>
public string plan_id { get; set; }
/// <summary>
/// 保养项Ids
/// 模具id
/// </summary>
public List<string>itemIds { get; set; }
public string mold_id { get; set; }
/// <summary>
/// 保养项状态 0未完成 1已完成
/// </summary>
public int? status { get; set; }
/// <summary>
/// 模具id
/// 保养项Ids
/// </summary>
public string mold_id { get; set; }
public List<MaintainItemInfo> items { get; set; }
}
public class MaintainItemInfo
{
public string item_group_id { get; set; }
public string item_id { get; set; }
}
}

View File

@@ -42,5 +42,9 @@ public partial class ToolMoldMaintainItemRecord : BaseEntity<string>
/// 模具ID
/// </summary>
public string mold_id { get; set; }
/// <summary>
/// 保养计划ID
/// </summary>
public string plan_id { get; set; }
}

View File

@@ -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>
/// 删除项目组与模具检查项信息

View File

@@ -94,43 +94,69 @@ namespace Tnb.EquipMgr
return result;
}
/// <summary>
/// 根据模具ID获取保养组及项目信息
/// 根据计划Id、模具ID获取保养组及项目信息
/// </summary>
/// <param name="moldId">模具ID</param>
/// <returns></returns>
/// <param name="input">
/// 参数:
/// <br/>{
/// <br/> plan_id:计划Id
/// <br/> mold_id:模具Id
/// <br/>}
/// </param>
/// <remarks>
/// returns:
/// <br/>{
/// <br/> plan_id:计划ID
/// <br/> mold_id:模具ID
/// <br/> item_group_id:保养组ID
/// <br/> item_group_name:保养组名称
/// <br/> item_id:保养项ID
/// <br/> item_name:保养项名称
/// <br/>}
/// </remarks>
/// <exception cref="ArgumentNullException"></exception>
[HttpGet]
public async Task<dynamic> GetCheckItemAndGrpByMoldId([FromRoute] string moldId)
public async Task<dynamic> GetCheckItemAndGrpByMoldId([FromQuery] CheckItemQueryinput input)
{
if (moldId.IsNullOrEmpty()) throw new ArgumentException($"parameter {nameof(moldId)} not be null or empty");
{
var checkItems = await _db.Queryable<ToolMoldMaintainItemRecord>().Where(it => it.mold_id == moldId).Select(it => new
if (input == null) throw new ArgumentNullException(nameof(input));
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
{
item_group_id = it.item_group_id,
item_group_name = it.item_group_name,
item_id = it.item_id,
item_name = it.item_name,
status = it.status,
}).ToListAsync();
//var checkItems = await _db.Queryable<ToolMoldMaintainGroupRelation, ToolMoldMaintainGroup, ToolMoldMaintainGroupItem, ToolMoldMaintainItem>((a, b, c, d) => new JoinQueryInfos
// (
// JoinType.Inner, a.item_group_id == b.id,
// JoinType.Inner, b.id == c.item_group_id,
// JoinType.Inner, c.item_id == d.id
// ))
// .Where(a => a.mold_id == moldId)
// .Select((a, b, c, d) => new
// {
// item_group_id = b.id,
// item_group_name = b.name,
// item_id = d.id,
// item_name = d.name,
// status = d.status,
// }).ToListAsync();
return checkItems;
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();
//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,
item_id = it.item_id,
item_group_id = it.item_group_id,
mold_id = it.mold_id,
}).ToListAsync();
if (items?.Count > 0 && checkItems?.Count > 0)
{
foreach (var item in items)
{
foreach (var checkItem in checkItems)
{
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;
}
}
}
}
return Enumerable.Empty<dynamic>();
return items;
}
@@ -220,8 +246,18 @@ namespace Tnb.EquipMgr
public async Task MaintainItemFinish(MoldMaintainRunUpInput input)
{
if (input == null) throw new ArgumentNullException("input");
if (input.itemIds == null || input.itemIds.Count == 0) throw new ArgumentException($"parameter {nameof(input.itemIds)} not be null or empty");
var row = await _db.Updateable<ToolMoldMaintainItemRecord>().SetColumns(it => new ToolMoldMaintainItemRecord { status = 1 }).Where(it => input.itemIds.Contains(it.id)).ExecuteCommandAsync();
if (input.items == null || input.items.Count == 0) throw new ArgumentException($"parameter {nameof(input.items)} not be null or empty");
List<ToolMoldMaintainItemRecord> records = new();
foreach (var item in input.items)
{
ToolMoldMaintainItemRecord record = new();
record.plan_id = input.plan_id;
record.mold_id = input.mold_id;
record.item_group_id = item.item_group_id;
record.item_id = item.item_id;
records.Add(record);
}
var row = await _db.Insertable(records).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
}