diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MaintainRuleMoldListOutput.cs b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MaintainRuleMoldListOutput.cs new file mode 100644 index 00000000..4c5669bd --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MaintainRuleMoldListOutput.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.EquipMgr.Entities.Dto +{ + /// + /// 保养规则关联模具列表输出参数 + /// + public class MaintainRuleMoldListOutput + { + /// + /// 模具Id + /// + public string mold_id { get; set; } + /// + /// 模具编码 + /// + public string mold_code { get; set; } + /// + /// 模具名称 + /// + public string mold_name { get; set; } + } +} diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/MoldMaintenance.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/MoldMaintenance.cs index 187a4940..f34d8433 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Entity/MoldMaintenance.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/MoldMaintenance.cs @@ -8,7 +8,7 @@ namespace Tnb.EquipMgr.Entities /// ///模具保养 /// - [SugarTable("tool_mold_maintenance")] + [SugarTable("tool_mold_maintain_item")] public partial class MoldMaintenance { /// diff --git a/EquipMgr/Tnb.EquipMgr/BaseMoldMaintainService.cs b/EquipMgr/Tnb.EquipMgr/BaseMoldMaintainService.cs index 8fc11254..4b73b973 100644 --- a/EquipMgr/Tnb.EquipMgr/BaseMoldMaintainService.cs +++ b/EquipMgr/Tnb.EquipMgr/BaseMoldMaintainService.cs @@ -12,6 +12,7 @@ using Tnb.Common.Contracts; using Tnb.EquipMgr.Entities.Dto; using Tnb.EquipMgr.Entities; using Tnb.EquipMgr.Utils; +using Mapster; namespace Tnb.EquipMgr { @@ -22,13 +23,21 @@ namespace Tnb.EquipMgr { _db = db; } - - protected async Task Relevance(TSrc input,string masterTableName, string name, Expression> deleleExp) where TDest : BaseEntity, new() + /// + /// 关联 + /// + /// 输入参数类型 + /// 目标数据库表类型 + /// 输入参数 + /// 主表属性名称 + /// 次表属性名称 + /// 删除条件 + /// + /// + protected async Task Relevance(TSrc input, string mColumnName, string name, Expression> deleleExp) where TDest : BaseEntity, new() where TSrc : BaseMoldMaintainInput { - await _db.Deleteable().Where(deleleExp).ExecuteCommandAsync(); - //var itemGroupId = nameof(ToolMoldMaintainGroupRelation.item_group_id); if (input == null) throw new ArgumentNullException(nameof(input)); var entities = new List(); if (input.ids?.Count > 0) @@ -38,10 +47,10 @@ namespace Tnb.EquipMgr var pk = id; TDest entity = new(); entity.id = SnowflakeIdHelper.NextId(); - if (!PropertySet.ValueFactories.TryGetValue(masterTableName, out Action? setGroupIdAction)) + if (!PropertySet.ValueFactories.TryGetValue(mColumnName, out Action? setGroupIdAction)) { - setGroupIdAction = PropertySet.CreateSetPropertyValueAction(masterTableName); - PropertySet.ValueFactories.Add(masterTableName, setGroupIdAction); + setGroupIdAction = PropertySet.CreateSetPropertyValueAction(mColumnName); + PropertySet.ValueFactories.Add(mColumnName, setGroupIdAction); } setGroupIdAction(entity, input.item_group_id); if (!PropertySet.ValueFactories.TryGetValue(name, out Action? setAction)) @@ -56,5 +65,24 @@ namespace Tnb.EquipMgr var row = await _db.Insertable(entities).ExecuteCommandAsync(); if (row < 1) throw Oops.Oh(ErrorCode.COM1000); } + + + protected async Task GetListByMasterId(string masterId, + Expression> masterFilterExp, + Expression> masterSelector, + Expression> relactionFilterExp) + { + var config = new TypeAdapterConfig(); + config.ForType(); + var list = new List(); + var itemIds = await _db.Queryable().Where(masterFilterExp).Select(masterSelector).ToListAsync(); + if (itemIds?.Count > 0) + { + var items = await _db.Queryable().Where(relactionFilterExp).ToListAsync(); + list = items.Adapt>(); + } + return list; + } + } } diff --git a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs index 57133460..e8719ebb 100644 --- a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs +++ b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs @@ -26,10 +26,29 @@ namespace Tnb.EquipMgr public class ToolMoldMaintainRuleService : BaseMoldMaintainService, IToolMoldMaintainRuleService, IDynamicApiController, ITransient { private readonly ISqlSugarClient _db; - public ToolMoldMaintainRuleService(ISqlSugarRepository repository, IUserManager userManager) : base(repository.AsSugarClient()) + public ToolMoldMaintainRuleService(ISqlSugarRepository repository) : base(repository.AsSugarClient()) { _db = repository.AsSugarClient(); } + /// + /// 根据规则Id获取匹配的模具列表 + /// + /// 规则Id + /// + [HttpGet] + public async Task GetListById([FromRoute] string ruleId) + { + var result = new List(); + var list = await _db.Queryable().Where(it => it.rule_id == ruleId).ToListAsync(); + if (list?.Count > 0) + { + var ids = list.Select(it => it.mold_id).ToList(); + result = await _db.Queryable().Where(it => ids.Contains(it.id)) + .Select(it => new MaintainRuleMoldListOutput { mold_id = it.id }, true).ToListAsync(); + } + return result; + } + /// /// 关联模具 /// @@ -39,6 +58,16 @@ namespace Tnb.EquipMgr [HttpPost] public async Task RelevanceMold(RelevanceMoldInput input) => await Relevance(input, nameof(ToolMoldMaintainRuleRelation.rule_id), nameof(ToolMoldMaintainRuleRelation.mold_id), it => it.rule_id == input.rule_id); - + /// + /// 删除模具信息 + /// + /// + /// + [HttpPost] + public async Task DeleteMoldRelevance(RelevanceMoldInput input) + { + var row = await _db.Deleteable().Where(it => it.rule_id == input.rule_id && input.ids.Contains(it.mold_id)).ExecuteCommandAsync(); + if (row < 1) throw Oops.Oh(ErrorCode.COM1002); + } } }