完成新建设备的单元 测试包括,添加变量表,和添加菜单
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
using AutoMapper;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
using System.Threading.Tasks;
|
||||
using DMS.Core.Interfaces.Repositories;
|
||||
|
||||
namespace DMS.Infrastructure.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 通用服务基类,封装了常见的增、删、改操作。
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">业务逻辑模型类型。</typeparam>
|
||||
/// <typeparam name="TEntity">数据库实体类型。</typeparam>
|
||||
/// <typeparam name="TRepository">与实体对应的仓储类型。</typeparam>
|
||||
public abstract class BaseService<TModel, TRepository>
|
||||
where TModel : class, new()
|
||||
where TRepository : IBaseRepository<TModel>
|
||||
{
|
||||
protected readonly TRepository ServerRepository;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化 BaseService 的新实例。
|
||||
/// </summary>
|
||||
/// <param name="mapper">AutoMapper 实例,用于对象映射。</param>
|
||||
/// <param name="serverRepository">仓储实例,用于数据访问。</param>
|
||||
protected BaseService( TRepository serverRepository)
|
||||
{
|
||||
ServerRepository = serverRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步添加一个新的业务模型对象。
|
||||
/// </summary>
|
||||
/// <param name="model">要添加的业务模型对象。</param>
|
||||
/// <returns>返回添加后的数据库实体。</returns>
|
||||
public virtual async Task<TModel> AddAsync(TModel model)
|
||||
{
|
||||
return await ServerRepository.AddAsync(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步更新一个现有的业务模型对象。
|
||||
/// </summary>
|
||||
/// <param name="model">要更新的业务模型对象。</param>
|
||||
/// <returns>返回受影响的行数。</returns>
|
||||
public virtual async Task<int> UpdateAsync(TModel model)
|
||||
{
|
||||
return await ServerRepository.UpdateAsync(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步删除一个业务模型对象。
|
||||
/// </summary>
|
||||
/// <param name="model">要删除的业务模型对象。</param>
|
||||
/// <returns>返回受影响的行数。</returns>
|
||||
public virtual async Task<int> DeleteAsync(TModel model)
|
||||
{
|
||||
return await ServerRepository.DeleteAsync(model);
|
||||
}
|
||||
|
||||
public virtual async Task<List<TModel>> GetAllAsync()
|
||||
{
|
||||
return await ServerRepository.GetAllAsync();
|
||||
}
|
||||
|
||||
public virtual async Task<TModel> GetByIdAsync(int id)
|
||||
{
|
||||
return await ServerRepository.GetByIdAsync(id);
|
||||
}
|
||||
public virtual async Task<List<TModel>> TakeAsync(int number)
|
||||
{
|
||||
return await ServerRepository.TakeAsync(number);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
using DMS.Core.Interfaces;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Configurations;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using SqlSugar;
|
||||
|
||||
namespace DMS.Infrastructure.Services;
|
||||
|
||||
|
||||
|
||||
public class DatabaseService : IDatabaseService
|
||||
{
|
||||
private readonly SqlSugarDbContext _dbContext;
|
||||
private readonly SqlSugarClient _db;
|
||||
|
||||
public DatabaseService(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 ;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using AutoMapper;
|
||||
using DMS.Core.Helper;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Concurrent;
|
||||
using DMS.Core.Interfaces;
|
||||
using DMS.Core.Interfaces.Repositories;
|
||||
|
||||
namespace DMS.Infrastructure.Services
|
||||
{
|
||||
public class DeviceService : BaseService<Device, DeviceRepository>
|
||||
{
|
||||
private readonly IDeviceRepository _deviceRepository;
|
||||
|
||||
public DeviceService(DeviceRepository repository) : base(repository)
|
||||
{
|
||||
_deviceRepository = repository;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using AutoMapper;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
|
||||
namespace DMS.Infrastructure.Services
|
||||
{
|
||||
public class MenuService : BaseService<MenuBean, MenuRepository>
|
||||
{
|
||||
public MenuService(MenuRepository repository) : base(repository)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using AutoMapper;
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Core.Helper;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DMS.Infrastructure.Services
|
||||
{
|
||||
public class MqttService:BaseService<MqttServer, MqttServerRepository>
|
||||
{
|
||||
public MqttService( MqttServerRepository serverRepository) : base( serverRepository)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using AutoMapper;
|
||||
using DMS.Core.Helper;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
|
||||
namespace DMS.Infrastructure.Services
|
||||
{
|
||||
public class VariableService : BaseService<Variable, VariableRepository>
|
||||
{
|
||||
|
||||
public VariableService(VariableRepository repository) : base(repository)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using AutoMapper;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
|
||||
namespace DMS.Infrastructure.Services;
|
||||
|
||||
public class VariableTableService : BaseService<VariableTable, VariableTableRepository>
|
||||
{
|
||||
public VariableTableService(VariableTableRepository repository) : base(repository)
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user