using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; using JNPF.Common.Enums; using JNPF.Common.Security; using JNPF.FriendlyException; using SqlSugar; using Tnb.Common.Contracts; using Tnb.EquipMgr.Entities.Dto; using Tnb.EquipMgr.Entities; using Tnb.EquipMgr.Utils; namespace Tnb.EquipMgr { public class BaseMoldMaintainService { private readonly ISqlSugarClient _db; public BaseMoldMaintainService(ISqlSugarClient db) { _db = db; } protected async Task Relevance(TSrc input,string masterTableName, 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) { foreach (var id in input.ids) { var pk = id; TDest entity = new(); entity.id = SnowflakeIdHelper.NextId(); if (!PropertySet.ValueFactories.TryGetValue(masterTableName, out Action? setGroupIdAction)) { setGroupIdAction = PropertySet.CreateSetPropertyValueAction(masterTableName); PropertySet.ValueFactories.Add(masterTableName, 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); } } }