基本修改完毕开始进行单元测试
This commit is contained in:
@@ -10,16 +10,16 @@ namespace DMS.Infrastructure.Repositories;
|
||||
/// <summary>
|
||||
/// VariableData仓储类,用于操作DbVariableData实体
|
||||
/// </summary>
|
||||
public class VarDataRepository : BaseRepository<DbVariable, Variable>
|
||||
public class VarDataRepository : BaseRepository<DbVariable>
|
||||
{
|
||||
public VarDataRepository(IMapper mapper, ITransaction transaction)
|
||||
: base(mapper, transaction)
|
||||
public VarDataRepository(SqlSugarDbContext dbContext)
|
||||
: base(dbContext)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override async Task<List<Variable>> GetAllAsync()
|
||||
public override async Task<List<DbVariable>> GetAllAsync()
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
@@ -29,11 +29,10 @@ public class VarDataRepository : BaseRepository<DbVariable, Variable>
|
||||
.ToListAsync();
|
||||
stopwatch.Stop();
|
||||
//NlogHelper.Info($"获取所有VariableData耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result.Select(d => _mapper.Map<Variable>(d))
|
||||
.ToList();
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<Variable>> GetByVariableTableIdAsync(int varTableId)
|
||||
public async Task<List<DbVariable>> GetByVariableTableIdAsync(int varTableId)
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
@@ -42,21 +41,21 @@ public class VarDataRepository : BaseRepository<DbVariable, Variable>
|
||||
.ToListAsync();
|
||||
stopwatch.Stop();
|
||||
//NlogHelper.Info($"获取变量表的所有变量{result.Count()}个耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result.Select(d => _mapper.Map<Variable>(d))
|
||||
.ToList();
|
||||
return result;
|
||||
}
|
||||
|
||||
public override async Task<int> AddAsync(Variable variable)
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var dbVarData = await Db.Insertable(_mapper.Map<DbVariable>(variable))
|
||||
.ExecuteReturnEntityAsync();
|
||||
stopwatch.Stop();
|
||||
//NlogHelper.Info($"新增VariableData '{variable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return dbVarData.Id;
|
||||
}
|
||||
//public override async Task<DbVariable> AddAsync(DbVariable entity)
|
||||
//{
|
||||
// Stopwatch stopwatch = new Stopwatch();
|
||||
// stopwatch.Start();
|
||||
// var dbVarData = await Db.Insertable(entity)
|
||||
// .ExecuteReturnEntityAsync();
|
||||
// stopwatch.Stop();
|
||||
// //NlogHelper.Info($"新增VariableData '{entity.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
// return dbVarData.Id;
|
||||
//}
|
||||
|
||||
/*
|
||||
public async Task<int> AddAsync(IEnumerable<Variable> variableDatas)
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
@@ -75,19 +74,21 @@ public class VarDataRepository : BaseRepository<DbVariable, Variable>
|
||||
//NlogHelper.Info($"新增VariableData '{variableDatas.Count()}'个, 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return res;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public override async Task<int> UpdateAsync(Variable variable)
|
||||
public override async Task<int> UpdateAsync(DbVariable entity)
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await Db.Updateable<DbVariable>(_mapper.Map<DbVariable>(variable))
|
||||
var result = await Db.Updateable(entity)
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
//NlogHelper.Info($"更新VariableData '{variable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
//NlogHelper.Info($"更新VariableData '{entity.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
public async Task<int> UpdateAsync(List<Variable> variableDatas)
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
@@ -101,19 +102,21 @@ public class VarDataRepository : BaseRepository<DbVariable, Variable>
|
||||
//NlogHelper.Info($"更新VariableData {variableDatas.Count()}个 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
public override async Task<int> DeleteAsync(Variable variable)
|
||||
public override async Task<int> DeleteAsync(DbVariable entity)
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await Db.Deleteable<DbVariable>()
|
||||
.Where(d => d.Id == variable.Id)
|
||||
.Where(d => d.Id == entity.Id)
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
//NlogHelper.Info($"删除VariableData: '{variable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
//NlogHelper.Info($"删除VariableData: '{entity.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
public async Task<int> DeleteAsync(IEnumerable<Variable> variableDatas)
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
@@ -128,12 +131,14 @@ public class VarDataRepository : BaseRepository<DbVariable, Variable>
|
||||
//NlogHelper.Info($"删除VariableData: '{variableDatas.Count()}'个 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
// public VarDataRepository(IMapper mapper)
|
||||
// {
|
||||
// _mapper = mapper;
|
||||
// }
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// 为变量添加MQTT服务器关联,并指定别名。
|
||||
/// </summary>
|
||||
@@ -156,7 +161,7 @@ public class VarDataRepository : BaseRepository<DbVariable, Variable>
|
||||
.ToListAsync();
|
||||
|
||||
var existingAliasesDict = existingAliases
|
||||
.ToDictionary(a => (a.VariableId, a.MqttId), a => a);
|
||||
.ToDictionary(a => (a.VariableId, a.Mqtt.Id), a => a);
|
||||
|
||||
var toInsert = new List<DbVariableMqtt>();
|
||||
var toUpdate = new List<DbVariableMqtt>();
|
||||
@@ -214,4 +219,5 @@ public class VarDataRepository : BaseRepository<DbVariable, Variable>
|
||||
throw;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user