完成新建设备的单元 测试包括,添加变量表,和添加菜单
This commit is contained in:
@@ -18,28 +18,28 @@ public class DeviceRepository : BaseRepository<DbDevice>, IDeviceRepository
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<List<Device>> GetAllAsync()
|
||||
public async Task<List<Core.Models.Device>> GetAllAsync()
|
||||
{
|
||||
var dbList = await base.GetAllAsync();
|
||||
return _mapper.Map<List<Device>>(dbList);
|
||||
return _mapper.Map<List<Core.Models.Device>>(dbList);
|
||||
}
|
||||
|
||||
public async Task<Device> GetByIdAsync(int id)
|
||||
public async Task<Core.Models.Device> GetByIdAsync(int id)
|
||||
{
|
||||
var dbDevice = await base.GetByIdAsync(id);
|
||||
return _mapper.Map<Device>(dbDevice);
|
||||
return _mapper.Map<Core.Models.Device>(dbDevice);
|
||||
}
|
||||
|
||||
public async Task<Device> AddAsync(Device model)
|
||||
public async Task<Core.Models.Device> AddAsync(Core.Models.Device model)
|
||||
{
|
||||
var dbDevice = await base.AddAsync(_mapper.Map<DbDevice>(model));
|
||||
return _mapper.Map(dbDevice, model);
|
||||
}
|
||||
|
||||
public async Task<int> UpdateAsync(Device model) => await base.UpdateAsync(_mapper.Map<DbDevice>(model));
|
||||
public async Task<int> UpdateAsync(Core.Models.Device model) => await base.UpdateAsync(_mapper.Map<DbDevice>(model));
|
||||
|
||||
|
||||
public async Task<int> DeleteAsync(Device model) => await base.DeleteAsync(_mapper.Map<DbDevice>(model));
|
||||
public async Task<int> DeleteAsync(Core.Models.Device model) => await base.DeleteAsync(_mapper.Map<DbDevice>(model));
|
||||
|
||||
public async Task<int> DeleteAsync(int id)
|
||||
{
|
||||
@@ -52,10 +52,10 @@ public class DeviceRepository : BaseRepository<DbDevice>, IDeviceRepository
|
||||
return result;
|
||||
}
|
||||
|
||||
public new async Task<List<Device>> TakeAsync(int number)
|
||||
public new async Task<List<Core.Models.Device>> TakeAsync(int number)
|
||||
{
|
||||
var dbList = await base.TakeAsync(number);
|
||||
return _mapper.Map<List<Device>>(dbList);
|
||||
return _mapper.Map<List<Core.Models.Device>>(dbList);
|
||||
|
||||
}
|
||||
}
|
||||
82
DMS.Infrastructure/Repositories/InitializeRepository.cs
Normal file
82
DMS.Infrastructure/Repositories/InitializeRepository.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using DMS.Core.Interfaces.Repositories;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Configurations;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using SqlSugar;
|
||||
|
||||
namespace DMS.Infrastructure.Repositories;
|
||||
|
||||
public class InitializeRepository : IInitializeRepository
|
||||
{
|
||||
private readonly SqlSugarDbContext _dbContext;
|
||||
private readonly SqlSugarClient _db;
|
||||
|
||||
public InitializeRepository(SqlSugarDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_db = _dbContext.GetInstance();
|
||||
}
|
||||
|
||||
public void InitializeTables()
|
||||
{
|
||||
_db.DbMaintenance.CreateDatabase();
|
||||
_db.CodeFirst.InitTables<DbNlog>();
|
||||
_db.CodeFirst.InitTables<DbDevice>();
|
||||
_db.CodeFirst.InitTables<DbVariableTable>();
|
||||
_db.CodeFirst.InitTables<DbVariable>();
|
||||
_db.CodeFirst.InitTables<DbVariableHistory>();
|
||||
_db.CodeFirst.InitTables<DbUser>();
|
||||
_db.CodeFirst.InitTables<DbMqttServer>();
|
||||
_db.CodeFirst.InitTables<DbVariableMqttAlias>();
|
||||
_db.CodeFirst.InitTables<DbMenu>();
|
||||
}
|
||||
|
||||
public void InitializeTableIndex()
|
||||
{
|
||||
_db.DbMaintenance.CreateIndex(nameof(DbDevice),new []
|
||||
{
|
||||
nameof(DbDevice.Name),
|
||||
nameof(DbDevice.OpcUaServerUrl),
|
||||
},true);
|
||||
|
||||
_db.DbMaintenance.CreateIndex(nameof(DbVariable),new []
|
||||
{
|
||||
nameof(DbVariable.OpcUaNodeId)
|
||||
},true);
|
||||
_db.DbMaintenance.CreateIndex(nameof(DbMqttServer),new []
|
||||
{
|
||||
nameof(DbMqttServer.ServerName)
|
||||
},true);
|
||||
}
|
||||
|
||||
public bool IsAnyTable(string tableName)
|
||||
{
|
||||
return _db.DbMaintenance.IsAnyTable(tableName, false);
|
||||
}
|
||||
|
||||
public bool IsAnyIndex(string indexName)
|
||||
{
|
||||
return _db.DbMaintenance.IsAnyIndex(indexName);
|
||||
}
|
||||
|
||||
public void InitializeMenus()
|
||||
{
|
||||
var settings = AppSettings.Load();
|
||||
if (settings.Menus.Any())
|
||||
{
|
||||
return ;
|
||||
}
|
||||
|
||||
settings.Menus.Add(new MenuBean() { Id=1, Header = "主页", Icon = "Home", ParentId = 0 });
|
||||
settings.Menus.Add(new MenuBean() { Id = 2, Header = "设备", Icon = "Devices3", ParentId = 0 });
|
||||
settings.Menus.Add(new MenuBean() { Id = 3, Header = "数据转换", Icon = "ChromeSwitch", ParentId = 0 });
|
||||
settings.Menus.Add(new MenuBean() { Id = 4, Header = "Mqtt服务器", Icon = "Cloud", ParentId = 0 });
|
||||
settings.Menus.Add(new MenuBean() { Id = 5, Header = "设置", Icon = "Settings", ParentId = 0 });
|
||||
settings.Menus.Add(new MenuBean() { Id = 6, Header = "关于", Icon = "Info", ParentId = 0 });
|
||||
|
||||
settings.Save();
|
||||
|
||||
return ;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ public class RepositoryManager : IRepositoryManager
|
||||
_dbContext = dbContext;
|
||||
_db = dbContext.GetInstance();
|
||||
|
||||
InitializeRepository=new InitializeRepository(dbContext);
|
||||
Devices = new DeviceRepository(mapper, dbContext);
|
||||
VariableTables = new VariableTableRepository(mapper, dbContext);
|
||||
Variables = new VariableRepository(mapper, dbContext);
|
||||
@@ -41,6 +42,7 @@ public class RepositoryManager : IRepositoryManager
|
||||
public IMenuRepository Menus { get; set; }
|
||||
public IVariableHistoryRepository VariableHistories { get; set; }
|
||||
public IUserRepository Users { get; set; }
|
||||
public IInitializeRepository InitializeRepository { get; set; }
|
||||
public async Task BeginTranAsync() => await _db.BeginTranAsync();
|
||||
|
||||
public async Task CommitAsync() => await _db.CommitTranAsync();
|
||||
|
||||
Reference in New Issue
Block a user