diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Dto/BaseInput.cs b/EquipMgr/Tnb.EquipMgr.Entities/Dto/BaseInput.cs new file mode 100644 index 00000000..b826fe23 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Dto/BaseInput.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.EquipMgr.Entities.Dto +{ + public class BaseInput + { + public string item_group_id { get; set; } + public List ids { get; set; } + } +} diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldListOutput.cs b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldListOutput.cs index d385c1bc..72a9bc91 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldListOutput.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldListOutput.cs @@ -8,7 +8,7 @@ namespace Tnb.EquipMgr.Entities.Dto { public class RelevanceMoldListOutput { - + public string mold_id { get; set; } /// /// Desc:模具编号 /// Default:NULL::character varying diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainGroupItemRelationInput.cs b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainGroupItemRelationInput.cs index 98b11fef..4e796a9e 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainGroupItemRelationInput.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainGroupItemRelationInput.cs @@ -9,15 +9,7 @@ namespace Tnb.EquipMgr.Entities.Dto /// /// 关联保养组与模具输入参数 /// - public class MoldMaintainGroupItemRelationInput + public class MoldMaintainGroupItemRelationInput :BaseInput { - /// - /// 项目组Id - /// - public string item_group_id { get; set; } - /// - /// 模具Id - /// - public string mold_id { get; set; } } } diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainItemInput.cs b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainItemInput.cs index 75205ae8..7802dba7 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainItemInput.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainItemInput.cs @@ -9,16 +9,8 @@ namespace Tnb.EquipMgr.Entities.Dto /// /// 模具保养项输入参数 /// - public class MoldMaintainGroupItemInput + public class MoldMaintainGroupItemInput : BaseInput { - /// - /// 项目组Id - /// - public string item_group_id { get; set; } - /// - /// 保养项Id - /// - public string item_id { get; set; } - + } } diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainItemListOutput.cs b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainItemListOutput.cs index 93eefae1..c45b8ad4 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainItemListOutput.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainItemListOutput.cs @@ -11,6 +11,10 @@ namespace Tnb.EquipMgr.Entities.Dto /// public class MoldMaintainItemListOutput { + /// + /// 检查项Id + /// + public string item_id { get; set; } /// /// 项目名称 /// diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Mapper/Mapper.cs b/EquipMgr/Tnb.EquipMgr.Entities/Mapper/Mapper.cs index 47984fa8..3b575108 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Mapper/Mapper.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Mapper/Mapper.cs @@ -8,6 +8,10 @@ namespace Tnb.EquipMgr.Entities.Mapper { public void Register(TypeAdapterConfig config) { + config.ForType() + .Map(dest => dest.item_id, src => src.id); + config.ForType() + .Map(dest => dest.mold_id, src => src.id); } } } \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainGroupService.cs b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainGroupService.cs index 6c481337..52c7d969 100644 --- a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainGroupService.cs +++ b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainGroupService.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; +using System.Reflection; using System.Text; using System.Threading.Tasks; using Aspose.Cells.Drawing; @@ -12,6 +14,9 @@ using JNPF.DynamicApiController; using JNPF.FriendlyException; using Mapster; using Microsoft.AspNetCore.Mvc; +using NPOI.SS.Formula.Functions; +using Qiniu.Util; +using Spire.Pdf.Widget; using SqlSugar; using Tnb.Common.Contracts; using Tnb.EquipMgr.Entities; @@ -82,7 +87,7 @@ namespace Tnb.EquipMgr /// [HttpPost] public async Task RelevanceMaintianGroupAndItem(MoldMaintainGroupItemInput input) => - await Relevance(input); + await Relevance(input, nameof(ToolMoldMaintainGroupItem.item_id), it => it.item_group_id == input.item_group_id); /// /// 关联项目组与模具 @@ -91,20 +96,64 @@ namespace Tnb.EquipMgr /// [HttpPost] public async Task RelevanceMaintianGroupAndMold(MoldMaintainGroupItemRelationInput input) => - await Relevance(input); + await Relevance(input, nameof(ToolMoldMaintainGroupRelation.mold_id), it => it.item_group_id == input.item_group_id); #endregion - private async Task Relevance(TSrc input) where TDest : BaseEntity, new() + private async Task Relevance(TSrc input, string name, Expression> deleleExp) where TDest : BaseEntity, new() + where TSrc : BaseInput { + + await _db.Deleteable().Where(deleleExp).ExecuteCommandAsync(); + var itemGroupId = nameof(ToolMoldMaintainGroupRelation.item_group_id); if (input == null) throw new ArgumentNullException(nameof(input)); - var entity = input.Adapt(); - entity.id = SnowflakeIdHelper.NextId(); - var row = await _db.Insertable(entity).ExecuteCommandAsync(); + var entities = new List(); + if (input.ids?.Count > 0) + { + foreach (var id in input.ids) + { + var pk = id; + TDest entity = new(); + entity.id = SnowflakeIdHelper.NextId(); + if (!PropertySet.ValueFactories.TryGetValue(itemGroupId, out Action setGroupIdAction)) + { + setGroupIdAction = PropertySet.CreateSetPropertyValueAction(itemGroupId); + PropertySet.ValueFactories.Add(itemGroupId, setGroupIdAction); + } + setGroupIdAction(entity, input.item_group_id); + if (!PropertySet.ValueFactories.TryGetValue(name, out Action setAction)) + { + setAction = PropertySet.CreateSetPropertyValueAction(name); + PropertySet.ValueFactories.Add(name, setAction); + } + setAction(entity, pk); + entities.Add(entity); + } + } + var row = await _db.Insertable(entities).ExecuteCommandAsync(); if (row < 1) throw Oops.Oh(ErrorCode.COM1000); } } + + public class PropertySet + { + public static Dictionary> ValueFactories = new Dictionary>(StringComparer.OrdinalIgnoreCase); + + public static Action CreateSetPropertyValueAction(string propertyName) + { + var property = typeof(T).GetProperty(propertyName); + var target = Expression.Parameter(typeof(object)); + var propertyValue = Expression.Parameter(typeof(object)); + var castTarget = Expression.Convert(target, typeof(T)); + var castPropertyValue = Expression.Convert(propertyValue, property.PropertyType); + var setPropertyValue = Expression.Call(castTarget, property.GetSetMethod(), castPropertyValue); + return Expression.Lambda>(setPropertyValue, target, propertyValue).Compile(); + } + + } + + }