临时提交

This commit is contained in:
2025-07-19 09:25:01 +08:00
parent e1a89e7c70
commit 01fe2e14ef
52 changed files with 499 additions and 370 deletions

View File

@@ -5,7 +5,7 @@ using System.Runtime.CompilerServices;
using System.Threading;
using NLog;
namespace DMS.Helper;
namespace DMS.Core.Helper;
/// <summary>
/// NLog 日志帮助类,提供简化的日志记录方法,并自动捕获调用者信息。

View File

@@ -0,0 +1,10 @@
using System.Threading.Tasks;
namespace DMS.Core.Interfaces
{
public interface IDatabaseService
{
void InitializeDataBase();
Task InitializeMenu();
}
}

View File

@@ -0,0 +1,18 @@
using System.Threading.Tasks;
namespace DMS.Core.Interfaces
{
public interface IDbContext
{
// Define common database operations here, e.g.,
// Task<TEntity> GetByIdAsync<TEntity>(int id) where TEntity : class;
// Task AddAsync<TEntity>(TEntity entity) where TEntity : class;
// Task UpdateAsync<TEntity>(TEntity entity) where TEntity : class;
// Task DeleteAsync<TEntity>(TEntity entity) where TEntity : class;
// SqlSugarClient GetClient(); // This should NOT be here if you want to hide SqlSugar
// For now, we'll just keep it empty or add methods as needed.
// The primary goal is to abstract away SqlSugarClient.
// The IUnitOfWork already handles transactions.
}
}

View File

@@ -0,0 +1,18 @@
using DMS.Core.Models;
using DMS.Core.Enums;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace DMS.Core.Interfaces
{
public interface IDeviceRepository
{
Task<int> UpdateAsync(Device device);
Task<List<Device>> GetAllAsync();
Task<Device> GetByIdAsync(int id);
Task<int> DeleteAsync(Device device, List<MenuBean> menus);
Task AddAsync(Device device);
}
}

View File

@@ -0,0 +1,23 @@
using DMS.Core.Models;
using DMS.Core.Enums;
using SqlSugar;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace DMS.Core.Interfaces
{
public interface IMenuRepository
{
Task<int> DeleteAsync(MenuBean menu);
Task<int> DeleteAsync(MenuBean menu, SqlSugarClient db);
Task<List<MenuBean>> GetMenuTreesAsync();
Task<int> AddAsync(MenuBean menu);
Task<int> AddAsync(MenuBean menu, SqlSugarClient db);
Task<int> AddVarTableMenuAsync(Device dbDevice, int parentMenuId, SqlSugarClient db);
Task<int> AddAsync(Device device, SqlSugarClient db);
Task<int> UpdateAsync(MenuBean menu);
Task<MenuBean?> GetMenuByDataIdAsync(int dataId, MenuType menuType);
Task<MenuBean> GetMainMenuByNameAsync(string name);
}
}

View File

@@ -0,0 +1,15 @@
using DMS.Core.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace DMS.Core.Interfaces
{
public interface IMqttRepository
{
Task<Mqtt> GetByIdAsync(int id);
Task<List<Mqtt>> GetAllAsync();
Task<int> AddAsync(Mqtt mqtt);
Task<int> UpdateAsync(Mqtt mqtt);
Task<int> DeleteAsync(Mqtt mqtt);
}
}

View File

@@ -0,0 +1,11 @@
using System.Threading.Tasks;
namespace DMS.Core.Interfaces
{
public interface IUnitOfWork
{
Task BeginTranAsync();
Task CommitTranAsync();
Task RollbackTranAsync();
}
}

View File

@@ -0,0 +1,15 @@
using DMS.Core.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace DMS.Core.Interfaces
{
public interface IUserRepository
{
Task<User> GetByIdAsync(int id);
Task<List<User>> GetAllAsync();
Task<int> AddAsync(User user);
Task<int> UpdateAsync(User user);
Task<int> DeleteAsync(int id);
}
}

View File

@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using DMS.Core.Models;
using SqlSugar;
namespace DMS.Core.Interfaces
{
public interface IVarDataRepository
{
Task<Variable> GetByIdAsync(int id);
Task<Variable> GetByIdAsync(int id, SqlSugarClient db);
Task<List<Variable>> GetAllAsync();
Task<List<Variable>> GetAllAsync(SqlSugarClient db);
Task<List<Variable>> GetByVariableTableIdAsync(int varTableId);
Task<List<Variable>> GetByVariableTableIdAsync(int varTableId, SqlSugarClient db);
Task<Variable> AddAsync(Variable variable);
Task<Variable> AddAsync(Variable variable, SqlSugarClient db);
Task<int> AddAsync(IEnumerable<Variable> variableDatas);
Task<int> AddAsync(IEnumerable<Variable> variableDatas, SqlSugarClient db);
Task<int> UpdateAsync(Variable variable);
Task<int> UpdateAsync(Variable variable, SqlSugarClient db);
Task<int> UpdateAsync(List<Variable> variableDatas);
Task<int> UpdateAsync(List<Variable> variableDatas, SqlSugarClient db);
Task<int> DeleteAsync(Variable variable);
Task<int> DeleteAsync(Variable variable, SqlSugarClient db);
Task<int> DeleteAsync(IEnumerable<Variable> variableDatas);
Task<int> AddMqttToVariablesAsync(IEnumerable<VariableMqtt> variableMqttList);
}
}

View File

@@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using DMS.Core.Models;
namespace DMS.Core.Interfaces
{
public interface IVarTableRepository
{
Task<VariableTable> AddAsync(VariableTable varTable);
Task<VariableTable> AddAsync(VariableTable variableTable, SqlSugarClient db);
Task<int> UpdateAsync(VariableTable variableTable);
Task<int> UpdateAsync(VariableTable variableTable, SqlSugarClient db);
Task<int> DeleteAsync(VariableTable variableTable);
Task<int> DeleteAsync(VariableTable varTable, SqlSugarClient db);
}
}

View File

@@ -0,0 +1,18 @@
using DMS.Core.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace DMS.Core.Interfaces
{
public interface IVariableMqttAliasRepository
{
Task<VariableMqtt?> GetAliasByVariableAndMqtt(int variableDataId, int mqttId);
Task<VariableMqtt?> GetAliasByVariableAndMqtt(int variableDataId, int mqttId, SqlSugarClient db);
Task<int> AddManyAsync(IEnumerable<VariableMqtt> entities);
Task<int> AddManyAsync(IEnumerable<VariableMqtt> entities, SqlSugarClient db);
Task<int> UpdateAliasAsync(int variableDataId, int mqttId, string newAlias);
Task<int> UpdateAliasAsync(int variableDataId, int mqttId, string newAlias, SqlSugarClient db);
Task<int> DeleteAsync(int variableDataId, int mqttId);
}
}

View File

@@ -3,7 +3,7 @@ using System.Collections.ObjectModel;
using DMS.Core.Enums;
namespace DMS.Models;
namespace DMS.Core.Models;
/// <summary>
/// 表示设备信息。
@@ -13,7 +13,7 @@ public partial class Device
/// <summary>
/// 设备的描述信息。
/// </summary>
private string description;
public string Description { get; set; }
/// <summary>
/// 设备的类型。
@@ -23,53 +23,53 @@ public partial class Device
/// <summary>
/// 设备的唯一标识符。
/// </summary>
private int id;
public int Id { get; set; }
/// <summary>
/// 设备的IP地址。
/// </summary>
private string ip;
public string Ip { get; set; }
/// <summary>
/// 表示设备是否处于活动状态。
/// </summary>
private bool isActive = true;
public bool IsActive { get; set; } = true;
/// <summary>
/// 表示是否添加默认变量表。
/// </summary>
private bool isAddDefVarTable = true;
public bool IsAddDefVarTable { get; set; } = true;
/// <summary>
/// 表示设备是否正在运行。
/// </summary>
private bool isRuning;
public bool IsRuning { get; set; }
/// <summary>
/// 设备的名称。
/// </summary>
private string name;
public string Name { get; set; }
/// <summary>
/// 设备的端口号。
/// </summary>
private int prot;
public int Prot { get; set; }
/// <summary>
/// PLC的CPU类型。
/// </summary>
//private CpuType cpuType;
//public CpuType cpuType;
/// <summary>
/// PLC的机架号。
/// </summary>
private short rack;
public short Rack { get; set; }
/// <summary>
/// PLC的槽号。
/// </summary>
private short slot;
public short Slot { get; set; }
/// <summary>
/// 设备的通信协议类型。
@@ -79,7 +79,7 @@ public partial class Device
/// <summary>
/// OPC UA Endpoint URL。
/// </summary>
private string? opcUaEndpointUrl;
public string OpcUaEndpointUrl { get; set; }=String.Empty;
/// <summary>
/// 设备关联的变量表列表。

View File

@@ -1,6 +1,6 @@
using DMS.Core.Enums;
namespace DMS.Models;
namespace DMS.Core.Models;
/// <summary>
/// 表示菜单项。

View File

@@ -1,6 +1,6 @@
using DMS.Core.Enums;
namespace DMS.Models;
namespace DMS.Core.Models;
/// <summary>
/// 表示MQTT配置信息。

View File

@@ -1,6 +1,6 @@
using DMS.Core.Enums;
namespace DMS.Models;
namespace DMS.Core.Models;
/// <summary>
/// 表示通知信息。

View File

@@ -1,6 +1,6 @@
using System.Collections.ObjectModel;
namespace DMS.Models;
namespace DMS.Core.Models;
/// <summary>
/// 表示OPC UA节点用于构建节点树。

View File

@@ -1,4 +1,4 @@
namespace DMS.Models;
namespace DMS.Core.Models;
public class User
{

View File

@@ -1,6 +1,6 @@
using DMS.Core.Enums;
namespace DMS.Models;
namespace DMS.Core.Models;
/// <summary>
/// 表示变量数据信息。
@@ -15,7 +15,7 @@ public partial class Variable
/// <summary>
/// 变量名称。
/// </summary>
private string name;
public string Name { get; set; }
/// <summary>
/// 节点ID用于标识变量在设备或系统中的唯一路径。
@@ -41,7 +41,7 @@ public partial class Variable
/// <summary>
/// 变量描述。
/// </summary>
private string description = String.Empty;
public string Description { get; set; } = String.Empty;
/// <summary>
/// 协议类型例如Modbus、OPC UA等。
@@ -61,22 +61,22 @@ public partial class Variable
/// <summary>
/// 变量当前原始数据值。
/// </summary>
private string dataValue = String.Empty;
public string DataValue { get; set; } = String.Empty;
/// <summary>
/// 变量经过转换或格式化后的显示值。
/// </summary>
private string displayValue = String.Empty;
public string DisplayValue { get; set; } = String.Empty;
/// <summary>
/// 指示变量是否处于激活状态。
/// </summary>
public bool isActive;
public bool IsActive { get; set; }
/// <summary>
/// 指示变量是否被选中
/// </summary>
public bool isSelect;
public bool IsSelect { get; set; }
/// <summary>
/// 指示是否需要保存变量数据。
@@ -91,12 +91,12 @@ public partial class Variable
/// <summary>
/// 轮询级别例如1秒、5秒等。
/// </summary>
private PollLevelType pollLevelType = PollLevelType.ThirtySeconds;
public PollLevelType PollLevelType { get; set; } = PollLevelType.ThirtySeconds;
/// <summary>
/// OPC UA更新类型例如轮询或订阅。
/// </summary>
private OpcUaUpdateType opcUaUpdateType = OpcUaUpdateType.OpcUaPoll;
public OpcUaUpdateType OpcUaUpdateType { get; set; } = OpcUaUpdateType.OpcUaPoll;
/// <summary>
/// 最后一次轮询时间。
@@ -111,7 +111,7 @@ public partial class Variable
/// <summary>
/// 指示变量是否已被修改了。
/// </summary>
private bool isModified;
public bool IsModified { get; set; }
/// <summary>
/// 报警的最大值阈值。
@@ -126,7 +126,7 @@ public partial class Variable
/// <summary>
/// 数据转换规则或表达式。
/// </summary>
private string converstion = String.Empty;
public string Converstion { get; set; } = String.Empty;
/// <summary>
/// 数据保存的范围或阈值。
@@ -136,13 +136,13 @@ public partial class Variable
/// <summary>
/// 变量数据创建时间。
/// </summary>
private DateTime createTime;
public DateTime CreateTime { get; set; }
/// <summary>
/// 变量数据最后更新时间。
/// </summary>
private DateTime updateTime = DateTime.Now;
public DateTime UpdateTime { get; set; } = DateTime.Now;
/// <summary>
/// 最后更新变量数据的用户。

View File

@@ -1,6 +1,6 @@
using DMS.Models;
using DMS.Core.Models;
namespace DMS.Models
namespace DMS.Core.Models
{
public class VariableContext
{

View File

@@ -1,7 +1,7 @@
using System;
using DMS.Core.Enums;
namespace DMS.Models;
namespace DMS.Core.Models;
/// <summary>
/// 表示变量数据与MQTT服务器之间的关联模型包含MQTT别名。

View File

@@ -2,7 +2,7 @@
using System.ComponentModel;
using DMS.Core.Enums;
namespace DMS.Models;
namespace DMS.Core.Models;
/// <summary>
/// 表示变量表信息。
@@ -22,7 +22,7 @@ public partial class VariableTable
/// <summary>
/// 变量表描述。
/// </summary>
private string description;
public string Description { get; set; }
/// <summary>
/// 变量表中包含的数据变量列表。
@@ -37,12 +37,12 @@ public partial class VariableTable
/// <summary>
/// 表示变量表是否处于活动状态。
/// </summary>
private bool isActive;
public bool IsActive { get; set; }
/// <summary>
/// 变量表名称。
/// </summary>
private string name;
public string Name { get; set; }
/// <summary>
/// 变量表使用的协议类型。