using AutoMapper; using DMS.Core.Models; using DMS.Infrastructure.Interfaces; using DMS.Infrastructure.Entities; using System.Diagnostics; using DMS.Infrastructure.Data; namespace DMS.Infrastructure.Repositories; public class VarTableRepository : BaseRepository { public VarTableRepository(IMapper mapper, ITransaction transaction) : base(mapper, transaction) { } /// /// 添加变量表 /// /// /// 变量表的ID public async Task AddAsync(VariableTable varTable) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); var addVarTabel = await Db.Insertable(_mapper.Map(varTable)) .ExecuteReturnEntityAsync(); stopwatch.Stop(); //NlogHelper.Info($"添加变量表 '{varTable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms"); return _mapper.Map(addVarTabel); } /// /// 编辑变量表 /// /// /// public async Task UpdateAsync(VariableTable variableTable) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); var result = await Db.Updateable(_mapper.Map(variableTable)) .ExecuteCommandAsync(); stopwatch.Stop(); //NlogHelper.Info($"编辑变量表 '{variableTable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms"); return result; } /// /// 删除变量表 /// /// /// public async Task DeleteAsync(VariableTable varTable) { if (varTable == null ) return 0; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // 转换对象 var res= await Db.Deleteable(_mapper.Map(varTable)) .ExecuteCommandAsync(); stopwatch.Stop(); //NlogHelper.Info($"删除变量表 '{varTable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms"); return res; } /// /// 删除变量表支持事务 /// /// /// public async Task DeleteAsync(IEnumerable deviceVariableTables) { if (deviceVariableTables == null || deviceVariableTables.Count() == 0) return; // 转换对象 var dbList = deviceVariableTables.Select(v => _mapper.Map(v)) .ToList(); await Db.Deleteable(dbList) .ExecuteCommandAsync(); } }