diff --git a/DMS.Core/DMS.Core.csproj b/DMS.Core/DMS.Core.csproj
index f3eb51a..647d814 100644
--- a/DMS.Core/DMS.Core.csproj
+++ b/DMS.Core/DMS.Core.csproj
@@ -12,10 +12,6 @@
-
-
-
-
Always
@@ -31,4 +27,8 @@
+
+
+
+
diff --git a/DMS.Core/Interfaces/IUnitOfWork.cs b/DMS.Core/Interfaces/IUnitOfWork.cs
deleted file mode 100644
index f05ebfb..0000000
--- a/DMS.Core/Interfaces/IUnitOfWork.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using System.Threading.Tasks;
-
-namespace DMS.Core.Interfaces
-{
- public interface IUnitOfWork
- {
- Task BeginTranAsync();
- Task CommitTranAsync();
- Task RollbackTranAsync();
- }
-}
\ No newline at end of file
diff --git a/DMS.Infrastructure/Class1.cs b/DMS.Infrastructure/Class1.cs
deleted file mode 100644
index f43bb86..0000000
--- a/DMS.Infrastructure/Class1.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace DMS.Infrastructure
-{
- public class Class1
- {
-
- }
-}
diff --git a/DMS.Infrastructure/Data/SqlSugarDbContext.cs b/DMS.Infrastructure/Data/SqlSugarDbContext.cs
index 25a0d68..0de098a 100644
--- a/DMS.Infrastructure/Data/SqlSugarDbContext.cs
+++ b/DMS.Infrastructure/Data/SqlSugarDbContext.cs
@@ -1,12 +1,12 @@
using DMS.Config;
-using DMS.Core.Interfaces;
+using DMS.Infrastructure.Interfaces;
using SqlSugar;
using System;
using System.Threading.Tasks;
namespace DMS.Infrastructure.Data;
-public class SqlSugarDbContext : IUnitOfWork
+public class SqlSugarDbContext : ITransaction
{
private readonly SqlSugarClient _db;
@@ -24,10 +24,6 @@ public class SqlSugarDbContext : IUnitOfWork
});
}
- public SqlSugarClient GetSqlSugarClient()
- {
- return _db;
- }
public async Task BeginTranAsync()
{
@@ -39,8 +35,15 @@ public class SqlSugarDbContext : IUnitOfWork
await _db.CommitTranAsync();
}
+
+
public async Task RollbackTranAsync()
{
await _db.RollbackTranAsync();
}
+
+ public SqlSugarClient GetInstance()
+ {
+ return _db;
+ }
}
\ No newline at end of file
diff --git a/DMS.Core/Interfaces/IDatabaseService.cs b/DMS.Infrastructure/Interfaces/IDatabaseService.cs
similarity index 78%
rename from DMS.Core/Interfaces/IDatabaseService.cs
rename to DMS.Infrastructure/Interfaces/IDatabaseService.cs
index 477df1f..6f29b47 100644
--- a/DMS.Core/Interfaces/IDatabaseService.cs
+++ b/DMS.Infrastructure/Interfaces/IDatabaseService.cs
@@ -1,6 +1,6 @@
using System.Threading.Tasks;
-namespace DMS.Core.Interfaces
+namespace DMS.Infrastructure.Interfaces
{
public interface IDatabaseService
{
diff --git a/DMS.Core/Interfaces/IDbContext.cs b/DMS.Infrastructure/Interfaces/IDbContext.cs
similarity index 66%
rename from DMS.Core/Interfaces/IDbContext.cs
rename to DMS.Infrastructure/Interfaces/IDbContext.cs
index 485e41f..3447bb9 100644
--- a/DMS.Core/Interfaces/IDbContext.cs
+++ b/DMS.Infrastructure/Interfaces/IDbContext.cs
@@ -1,6 +1,6 @@
using System.Threading.Tasks;
-namespace DMS.Core.Interfaces
+namespace DMS.Infrastructure.Interfaces
{
public interface IDbContext
{
@@ -9,10 +9,10 @@ namespace DMS.Core.Interfaces
// Task AddAsync(TEntity entity) where TEntity : class;
// Task UpdateAsync(TEntity entity) where TEntity : class;
// Task DeleteAsync(TEntity entity) where TEntity : class;
- // SqlSugarClient GetClient(); // This should NOT be here if you want to hide SqlSugar
+ // ITransaction 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.
+ // The primary goal is to abstract away ITransaction.
+ // The ITransaction already handles transactions.
}
}
\ No newline at end of file
diff --git a/DMS.Core/Interfaces/IDeviceRepository.cs b/DMS.Infrastructure/Interfaces/IDeviceRepository.cs
similarity index 91%
rename from DMS.Core/Interfaces/IDeviceRepository.cs
rename to DMS.Infrastructure/Interfaces/IDeviceRepository.cs
index c9fe099..eee16e6 100644
--- a/DMS.Core/Interfaces/IDeviceRepository.cs
+++ b/DMS.Infrastructure/Interfaces/IDeviceRepository.cs
@@ -3,7 +3,7 @@ using DMS.Core.Enums;
using System.Collections.Generic;
using System.Threading.Tasks;
-namespace DMS.Core.Interfaces
+namespace DMS.Infrastructure.Interfaces
{
public interface IDeviceRepository
{
diff --git a/DMS.Core/Interfaces/IMenuRepository.cs b/DMS.Infrastructure/Interfaces/IMenuRepository.cs
similarity index 67%
rename from DMS.Core/Interfaces/IMenuRepository.cs
rename to DMS.Infrastructure/Interfaces/IMenuRepository.cs
index 26436c4..93a8f36 100644
--- a/DMS.Core/Interfaces/IMenuRepository.cs
+++ b/DMS.Infrastructure/Interfaces/IMenuRepository.cs
@@ -1,20 +1,19 @@
using DMS.Core.Models;
using DMS.Core.Enums;
-using SqlSugar;
using System.Collections.Generic;
using System.Threading.Tasks;
-namespace DMS.Core.Interfaces
+namespace DMS.Infrastructure.Interfaces
{
public interface IMenuRepository
{
Task DeleteAsync(MenuBean menu);
- Task DeleteAsync(MenuBean menu, SqlSugarClient db);
+ Task DeleteAsync(MenuBean menu, ITransaction db);
Task> GetMenuTreesAsync();
Task AddAsync(MenuBean menu);
- Task AddAsync(MenuBean menu, SqlSugarClient db);
- Task AddVarTableMenuAsync(Device dbDevice, int parentMenuId, SqlSugarClient db);
- Task AddAsync(Device device, SqlSugarClient db);
+ Task AddAsync(MenuBean menu, ITransaction db);
+ Task AddVarTableMenuAsync(Device dbDevice, int parentMenuId, ITransaction db);
+ Task AddAsync(Device device, ITransaction db);
Task UpdateAsync(MenuBean menu);
Task GetMenuByDataIdAsync(int dataId, MenuType menuType);
diff --git a/DMS.Core/Interfaces/IMqttRepository.cs b/DMS.Infrastructure/Interfaces/IMqttRepository.cs
similarity index 89%
rename from DMS.Core/Interfaces/IMqttRepository.cs
rename to DMS.Infrastructure/Interfaces/IMqttRepository.cs
index b7d3ed0..43f2c0e 100644
--- a/DMS.Core/Interfaces/IMqttRepository.cs
+++ b/DMS.Infrastructure/Interfaces/IMqttRepository.cs
@@ -2,7 +2,7 @@ using DMS.Core.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
-namespace DMS.Core.Interfaces
+namespace DMS.Infrastructure.Interfaces
{
public interface IMqttRepository
{
diff --git a/DMS.Infrastructure/Interfaces/ITransaction.cs b/DMS.Infrastructure/Interfaces/ITransaction.cs
new file mode 100644
index 0000000..d05a91c
--- /dev/null
+++ b/DMS.Infrastructure/Interfaces/ITransaction.cs
@@ -0,0 +1,17 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DMS.Infrastructure.Interfaces
+{
+ public interface ITransaction
+ {
+ Task BeginTranAsync();
+ Task CommitTranAsync();
+ SqlSugarClient GetInstance();
+ Task RollbackTranAsync();
+ }
+}
diff --git a/DMS.Core/Interfaces/IUserRepository.cs b/DMS.Infrastructure/Interfaces/IUserRepository.cs
similarity index 89%
rename from DMS.Core/Interfaces/IUserRepository.cs
rename to DMS.Infrastructure/Interfaces/IUserRepository.cs
index b3e5dea..e39dd16 100644
--- a/DMS.Core/Interfaces/IUserRepository.cs
+++ b/DMS.Infrastructure/Interfaces/IUserRepository.cs
@@ -2,7 +2,7 @@ using DMS.Core.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
-namespace DMS.Core.Interfaces
+namespace DMS.Infrastructure.Interfaces
{
public interface IUserRepository
{
diff --git a/DMS.Core/Interfaces/IVarDataRepository.cs b/DMS.Infrastructure/Interfaces/IVarDataRepository.cs
similarity index 63%
rename from DMS.Core/Interfaces/IVarDataRepository.cs
rename to DMS.Infrastructure/Interfaces/IVarDataRepository.cs
index cae0eab..585732e 100644
--- a/DMS.Core/Interfaces/IVarDataRepository.cs
+++ b/DMS.Infrastructure/Interfaces/IVarDataRepository.cs
@@ -1,28 +1,27 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using DMS.Core.Models;
-using SqlSugar;
-namespace DMS.Core.Interfaces
+namespace DMS.Infrastructure.Interfaces
{
public interface IVarDataRepository
{
Task GetByIdAsync(int id);
- Task GetByIdAsync(int id, SqlSugarClient db);
+ Task GetByIdAsync(int id, ITransaction db);
Task> GetAllAsync();
- Task> GetAllAsync(SqlSugarClient db);
+ Task> GetAllAsync(ITransaction db);
Task> GetByVariableTableIdAsync(int varTableId);
- Task> GetByVariableTableIdAsync(int varTableId, SqlSugarClient db);
+ Task> GetByVariableTableIdAsync(int varTableId, ITransaction db);
Task AddAsync(Variable variable);
- Task AddAsync(Variable variable, SqlSugarClient db);
+ Task AddAsync(Variable variable, ITransaction db);
Task AddAsync(IEnumerable variableDatas);
- Task AddAsync(IEnumerable variableDatas, SqlSugarClient db);
+ Task AddAsync(IEnumerable variableDatas, ITransaction db);
Task UpdateAsync(Variable variable);
- Task UpdateAsync(Variable variable, SqlSugarClient db);
+ Task UpdateAsync(Variable variable, ITransaction db);
Task UpdateAsync(List variableDatas);
- Task UpdateAsync(List variableDatas, SqlSugarClient db);
+ Task UpdateAsync(List variableDatas, ITransaction db);
Task DeleteAsync(Variable variable);
- Task DeleteAsync(Variable variable, SqlSugarClient db);
+ Task DeleteAsync(Variable variable, ITransaction db);
Task DeleteAsync(IEnumerable variableDatas);
Task AddMqttToVariablesAsync(IEnumerable variableMqttList);
diff --git a/DMS.Core/Interfaces/IVarTableRepository.cs b/DMS.Infrastructure/Interfaces/IVarTableRepository.cs
similarity index 65%
rename from DMS.Core/Interfaces/IVarTableRepository.cs
rename to DMS.Infrastructure/Interfaces/IVarTableRepository.cs
index 063afe0..f0fe545 100644
--- a/DMS.Core/Interfaces/IVarTableRepository.cs
+++ b/DMS.Infrastructure/Interfaces/IVarTableRepository.cs
@@ -2,16 +2,16 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using DMS.Core.Models;
-namespace DMS.Core.Interfaces
+namespace DMS.Infrastructure.Interfaces
{
public interface IVarTableRepository
{
Task AddAsync(VariableTable varTable);
- Task AddAsync(VariableTable variableTable, SqlSugarClient db);
+ Task AddAsync(VariableTable variableTable, ITransaction db);
Task UpdateAsync(VariableTable variableTable);
- Task UpdateAsync(VariableTable variableTable, SqlSugarClient db);
+ Task UpdateAsync(VariableTable variableTable, ITransaction db);
Task DeleteAsync(VariableTable variableTable);
- Task DeleteAsync(VariableTable varTable, SqlSugarClient db);
+ Task DeleteAsync(VariableTable varTable, ITransaction db);
}
}
\ No newline at end of file
diff --git a/DMS.Core/Interfaces/IVariableMqttAliasRepository.cs b/DMS.Infrastructure/Interfaces/IVariableMqttAliasRepository.cs
similarity index 82%
rename from DMS.Core/Interfaces/IVariableMqttAliasRepository.cs
rename to DMS.Infrastructure/Interfaces/IVariableMqttAliasRepository.cs
index 868ffcf..c972b23 100644
--- a/DMS.Core/Interfaces/IVariableMqttAliasRepository.cs
+++ b/DMS.Infrastructure/Interfaces/IVariableMqttAliasRepository.cs
@@ -2,16 +2,16 @@ using DMS.Core.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
-namespace DMS.Core.Interfaces
+namespace DMS.Infrastructure.Interfaces
{
public interface IVariableMqttAliasRepository
{
Task GetAliasByVariableAndMqtt(int variableDataId, int mqttId);
- Task GetAliasByVariableAndMqtt(int variableDataId, int mqttId, SqlSugarClient db);
+ Task GetAliasByVariableAndMqtt(int variableDataId, int mqttId, ITransaction db);
Task AddManyAsync(IEnumerable entities);
- Task AddManyAsync(IEnumerable entities, SqlSugarClient db);
+ Task AddManyAsync(IEnumerable entities, ITransaction db);
Task UpdateAliasAsync(int variableDataId, int mqttId, string newAlias);
- Task UpdateAliasAsync(int variableDataId, int mqttId, string newAlias, SqlSugarClient db);
+ Task UpdateAliasAsync(int variableDataId, int mqttId, string newAlias, ITransaction db);
Task DeleteAsync(int variableDataId, int mqttId);
}
diff --git a/DMS.Infrastructure/Repositories/BaseRepository.cs b/DMS.Infrastructure/Repositories/BaseRepository.cs
new file mode 100644
index 0000000..b047ba7
--- /dev/null
+++ b/DMS.Infrastructure/Repositories/BaseRepository.cs
@@ -0,0 +1,88 @@
+using AutoMapper;
+using DMS.Core.Helper;
+using DMS.Infrastructure.Interfaces;
+using DMS.Infrastructure.Data;
+using SqlSugar;
+using System.Diagnostics;
+using System.Linq.Expressions;
+
+namespace DMS.Infrastructure.Repositories;
+
+public abstract class BaseRepository
+ where TEntity : class, new()
+ where TModel : class, new()
+{
+ protected readonly IMapper _mapper;
+ private readonly SqlSugarDbContext dbContext;
+
+ protected SqlSugarClient Db => dbContext.GetInstance();
+
+ protected BaseRepository(IMapper mapper, ITransaction transaction)
+ {
+ _mapper = mapper;
+ this.dbContext = dbContext;
+ }
+
+ public virtual async Task AddAsync(TModel model)
+ {
+ Stopwatch stopwatch = new Stopwatch();
+ stopwatch.Start();
+ var entity = _mapper.Map(model);
+ var result = await Db.Insertable(entity).ExecuteCommandAsync();
+ stopwatch.Stop();
+ NlogHelper.Info($"Add {typeof(TModel).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
+ return result;
+ }
+
+ public virtual async Task UpdateAsync(TModel model)
+ {
+ Stopwatch stopwatch = new Stopwatch();
+ stopwatch.Start();
+ var entity = _mapper.Map(model);
+ var result = await Db.Updateable(entity).ExecuteCommandAsync();
+ stopwatch.Stop();
+ NlogHelper.Info($"Update {typeof(TModel).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
+ return result;
+ }
+
+ public virtual async Task DeleteAsync(TModel model)
+ {
+ Stopwatch stopwatch = new Stopwatch();
+ stopwatch.Start();
+ var entity = _mapper.Map(model);
+ var result = await Db.Deleteable(entity).ExecuteCommandAsync();
+ stopwatch.Stop();
+ NlogHelper.Info($"Delete {typeof(TModel).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
+ return result;
+ }
+
+ public virtual async Task> GetAllAsync()
+ {
+ Stopwatch stopwatch = new Stopwatch();
+ stopwatch.Start();
+ var entities = await Db.Queryable().ToListAsync();
+ stopwatch.Stop();
+ NlogHelper.Info($"GetAll {typeof(TModel).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
+ return _mapper.Map>(entities);
+ }
+
+ public virtual async Task GetByIdAsync(int id)
+ {
+ Stopwatch stopwatch = new Stopwatch();
+ stopwatch.Start();
+ var entity = await Db.Queryable().In(id).FirstAsync();
+ stopwatch.Stop();
+ NlogHelper.Info($"GetById {typeof(TModel).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
+ return _mapper.Map(entity);
+ }
+
+ public virtual async Task GetByConditionAsync(Expression> expression)
+ {
+ Stopwatch stopwatch = new Stopwatch();
+ stopwatch.Start();
+ var entity = await Db.Queryable().FirstAsync(expression);
+ stopwatch.Stop();
+ NlogHelper.Info($"GetByCondition {typeof(TModel).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
+ return _mapper.Map(entity);
+ }
+}
diff --git a/DMS.Infrastructure/Repositories/DeviceRepository.cs b/DMS.Infrastructure/Repositories/DeviceRepository.cs
index fe7a264..26248b8 100644
--- a/DMS.Infrastructure/Repositories/DeviceRepository.cs
+++ b/DMS.Infrastructure/Repositories/DeviceRepository.cs
@@ -6,141 +6,76 @@ using DMS.Core.Helper;
using DMS.Core.Models;
using DMS.Infrastructure.Data;
using SqlSugar;
+using DMS.Infrastructure.Interfaces;
namespace DMS.Infrastructure.Repositories;
-public class DeviceRepository : IDeviceRepository
+public class DeviceRepository : BaseRepository, IDeviceRepository
{
- private readonly IMapper _mapper;
private readonly IMenuRepository _menuRepository;
private readonly IVarTableRepository _varTableRepository;
- private readonly IUnitOfWork _unitOfWork;
- public DeviceRepository(IMapper mapper, IMenuRepository menuRepository, IVarTableRepository varTableRepository, IUnitOfWork unitOfWork)
+ public DeviceRepository(IMapper mapper, IMenuRepository menuRepository, IVarTableRepository varTableRepository, ITransaction transaction)
+ : base(mapper, transaction)
{
- _mapper = mapper;
_menuRepository = menuRepository;
_varTableRepository = varTableRepository;
- _unitOfWork = unitOfWork;
- }
-
-
-
- ///
- /// 编辑设备信息。
- ///
- /// 要编辑的设备对象。
- /// 受影响的行数。
- public async Task UpdateAsync(Device device)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- var db = _unitOfWork.GetInstance();
- var result = await db.Updateable(_mapper.Map(device))
- .ExecuteCommandAsync();
- stopwatch.Stop();
- NlogHelper.Info($"编辑设备 '{device.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
}
-
- ///
- /// 获取设备列表
- ///
- ///
- public async Task> GetAllAsync()
- {
- using (var db = DbContext.GetInstance())
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- var dlist = await db.Queryable()
- .Includes(d => d.VariableTables, dv => dv.Device)
- .Includes(d => d.VariableTables, dvd => dvd.Variables, data => data.VariableTable)
- .Includes(d => d.VariableTables, vt => vt.Variables, v => v.VariableMqtts)
- .ToListAsync();
-
-
- stopwatch.Stop();
- NlogHelper.Info($"加载设备列表总耗时:{stopwatch.ElapsedMilliseconds}ms");
- var devices = _mapper.Map>(dlist);
- return devices;
- }
- }
-
- ///
- /// 根据ID获取设备信息。
- ///
- /// 设备ID。
- /// 对应的DbDevice对象。
- public async Task GetByIdAsync(int id)
+ public override async Task> GetAllAsync()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using (var db = DbContext.GetInstance())
- {
- var result = await db.Queryable()
- .FirstAsync(p => p.Id == id);
- stopwatch.Stop();
- NlogHelper.Info($"根据ID '{id}' 获取设备耗时:{stopwatch.ElapsedMilliseconds}ms");
- return _mapper.Map(result);
- }
+ var dlist = await Db.Queryable()
+ .Includes(d => d.VariableTables, dv => dv.Device)
+ .Includes(d => d.VariableTables, dvd => dvd.Variables, data => data.VariableTable)
+ .Includes(d => d.VariableTables, vt => vt.Variables, v => v.VariableMqtts)
+ .ToListAsync();
+
+ stopwatch.Stop();
+ NlogHelper.Info($"加载设备列表总耗时:{stopwatch.ElapsedMilliseconds}ms");
+ var devices = _mapper.Map>(dlist);
+ return devices;
}
+
- ///
- /// 删除设备。
- ///
- /// 要删除的设备ID。
- /// 受影响的行数。
public async Task DeleteAsync(Device device, List menus)
{
- var db = _unitOfWork.GetInstance();
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- var result = await db.Deleteable(new DbDevice { Id = device.Id })
+ var result = await Db.Deleteable(new DbDevice { Id = device.Id })
.ExecuteCommandAsync();
// 删除变量表
- await _varTableRepository.DeleteAsync(device.VariableTables);
+ //await _varTableRepository.DeleteAsync(device.VariableTables);
stopwatch.Stop();
NlogHelper.Info($"删除设备:{device.Name},耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
-
-
-
-
- ///
- /// 添加设备
- ///
- ///
public async Task AddAsync(Device device)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- var db = _unitOfWork.GetInstance();
//查询设备的名字是否存在
- var exist = await db.Queryable()
+ var exist = await Db.Queryable()
.Where(d => d.Name == device.Name)
.FirstAsync();
if (exist != null)
throw new InvalidOperationException("设备名称已经存在。");
// 2. 将设备添加到数据库
- var addDevice = await db.Insertable(_mapper.Map(device))
+ var addDevice = await Db.Insertable(_mapper.Map(device))
.ExecuteReturnEntityAsync();
// 4. 为新设备添加菜单
- var addDeviceMenuId = await _menuRepository.AddAsync(addDevice);
+ //var addDeviceMenuId = await _menuRepository.AddAsync(addDevice);
stopwatch.Stop();
NlogHelper.Info($"添加设备 '{device.Name}' 及相关菜单耗时:{stopwatch.ElapsedMilliseconds}ms");
}
-
-
}
\ No newline at end of file
diff --git a/DMS.Infrastructure/Repositories/MenuRepository.cs b/DMS.Infrastructure/Repositories/MenuRepository.cs
index d53854d..82bee23 100644
--- a/DMS.Infrastructure/Repositories/MenuRepository.cs
+++ b/DMS.Infrastructure/Repositories/MenuRepository.cs
@@ -6,22 +6,20 @@ using DMS.Core.Enums;
using DMS.Core.Helper;
using DMS.Core.Models;
using DMS.Infrastructure.Data;
+using DMS.Infrastructure.Interfaces;
namespace DMS.Infrastructure.Repositories;
-public class MenuRepository : IMenuRepository
+public class MenuRepository : BaseRepository
{
- private readonly IMapper _mapper;
-
- public MenuRepository(IMapper mapper)
+ public MenuRepository(IMapper mapper, ITransaction transaction)
+ : base(mapper, transaction)
{
- _mapper = mapper;
}
public async Task DeleteAsync(MenuBean menu)
{
- using var db = DbContext.GetInstance();
- return await DeleteAsync(menu, db);
+ return await DeleteAsync(menu, Db);
}
public async Task DeleteAsync(MenuBean menu, SqlSugarClient db)
@@ -42,18 +40,15 @@ public class MenuRepository : IMenuRepository
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using (var db = DbContext.GetInstance())
- {
- List menuTree = new();
- var dbMenuTree = await db.Queryable()
- .ToTreeAsync(dm => dm.Items, dm => dm.ParentId, 0);
+ List menuTree = new();
+ var dbMenuTree = await Db.Queryable()
+ .ToTreeAsync(dm => dm.Items, dm => dm.ParentId, 0);
- foreach (var dbMenu in dbMenuTree)
- menuTree.Add(_mapper.Map(dbMenu));
- stopwatch.Stop();
- NlogHelper.Info($"获取菜单树耗时:{stopwatch.ElapsedMilliseconds}ms");
- return menuTree;
- }
+ foreach (var dbMenu in dbMenuTree)
+ menuTree.Add(_mapper.Map(dbMenu));
+ stopwatch.Stop();
+ NlogHelper.Info($"获取菜单树耗时:{stopwatch.ElapsedMilliseconds}ms");
+ return menuTree;
}
@@ -61,8 +56,7 @@ public class MenuRepository : IMenuRepository
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using var db = DbContext.GetInstance();
- var result = await AddAsync(menu, db);
+ var result = await AddAsync(menu, Db);
stopwatch.Stop();
NlogHelper.Info($"添加菜单 '{menu.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
@@ -148,13 +142,10 @@ public class MenuRepository : IMenuRepository
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using (var db = DbContext.GetInstance())
- {
- var result = await UpdateAsync(menu, db);
- stopwatch.Stop();
- NlogHelper.Info($"编辑菜单 '{menu.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
+ var result = await UpdateAsync(menu, Db);
+ stopwatch.Stop();
+ NlogHelper.Info($"编辑菜单 '{menu.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
+ return result;
}
///
@@ -177,20 +168,16 @@ public class MenuRepository : IMenuRepository
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using (var db = DbContext.GetInstance())
- {
- var result = await db.Queryable()
- .FirstAsync(m => m.DataId == dataId && m.Type == menuType);
- stopwatch.Stop();
- NlogHelper.Info($"根据DataId '{dataId}' 和 MenuType '{menuType}' 获取菜单耗时:{stopwatch.ElapsedMilliseconds}ms");
- return _mapper.Map(result);
- }
+ var result = await Db.Queryable()
+ .FirstAsync(m => m.DataId == dataId && m.Type == menuType);
+ stopwatch.Stop();
+ NlogHelper.Info($"根据DataId '{dataId}' 和 MenuType '{menuType}' 获取菜单耗时:{stopwatch.ElapsedMilliseconds}ms");
+ return _mapper.Map(result);
}
public async Task GetMainMenuByNameAsync(string name)
{
- using var db = DbContext.GetInstance();
- var dbMenu= await db.Queryable().FirstAsync(m => m.Name == name && m.Type == MenuType.MainMenu);
+ var dbMenu= await Db.Queryable().FirstAsync(m => m.Name == name && m.Type == MenuType.MainMenu);
return _mapper.Map(dbMenu);
}
}
\ No newline at end of file
diff --git a/DMS.Infrastructure/Repositories/MqttRepository.cs b/DMS.Infrastructure/Repositories/MqttRepository.cs
index eb4cf9e..310f48a 100644
--- a/DMS.Infrastructure/Repositories/MqttRepository.cs
+++ b/DMS.Infrastructure/Repositories/MqttRepository.cs
@@ -5,21 +5,21 @@ using DMS.Core.Enums;
using DMS.Core.Helper;
using DMS.Core.Models;
using DMS.Infrastructure.Data;
+using DMS.Infrastructure.Interfaces;
namespace DMS.Infrastructure.Repositories;
///
/// Mqtt仓储类,用于操作DbMqtt实体
///
-public class MqttRepository : IMqttRepository
+public class MqttRepository : BaseRepository
{
private readonly MenuRepository _menuRepository;
- private readonly IMapper _mapper;
- public MqttRepository(MenuRepository menuRepository, IMapper mapper)
+ public MqttRepository(MenuRepository menuRepository, IMapper mapper, ITransaction transaction)
+ : base(mapper, transaction)
{
_menuRepository = menuRepository;
- _mapper = mapper;
}
///
@@ -31,15 +31,12 @@ public class MqttRepository : IMqttRepository
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using (var _db = DbContext.GetInstance())
- {
- var result = await _db.Queryable()
- .In(id)
- .SingleAsync();
- stopwatch.Stop();
- NlogHelper.Info($"根据ID '{id}' 获取Mqtt配置耗时:{stopwatch.ElapsedMilliseconds}ms");
- return _mapper.Map(result);
- }
+ var result = await Db.Queryable()
+ .In(id)
+ .SingleAsync();
+ stopwatch.Stop();
+ NlogHelper.Info($"根据ID '{id}' 获取Mqtt配置耗时:{stopwatch.ElapsedMilliseconds}ms");
+ return _mapper.Map(result);
}
///
@@ -50,17 +47,14 @@ public class MqttRepository : IMqttRepository
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using (var _db = DbContext.GetInstance())
- {
- var result = await _db.Queryable()
- .Includes(m => m.VariableMqtts, vm => vm.Variable)
- .Includes(m => m.VariableMqtts, vm => vm.Mqtt)
- .ToListAsync();
- stopwatch.Stop();
- NlogHelper.Info($"获取所有Mqtt配置耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result.Select(m => _mapper.Map(m))
- .ToList();
- }
+ var result = await Db.Queryable()
+ .Includes(m => m.VariableMqtts, vm => vm.Variable)
+ .Includes(m => m.VariableMqtts, vm => vm.Mqtt)
+ .ToListAsync();
+ stopwatch.Stop();
+ NlogHelper.Info($"获取所有Mqtt配置耗时:{stopwatch.ElapsedMilliseconds}ms");
+ return result.Select(m => _mapper.Map(m))
+ .ToList();
}
///
@@ -72,11 +66,10 @@ public class MqttRepository : IMqttRepository
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using var db = DbContext.GetInstance();
- await db.BeginTranAsync();
+ await Db.BeginTranAsync();
try
{
- var result = await db.Insertable(_mapper.Map(mqtt))
+ var result = await Db.Insertable(_mapper.Map(mqtt))
.ExecuteReturnIdentityAsync();
var mqttMenu = await _menuRepository.GetMainMenuByNameAsync("Mqtt服务器");
// AddAsync menu entry
@@ -88,15 +81,15 @@ public class MqttRepository : IMqttRepository
DataId = result,
ParentId = mqttMenu.Id,
};
- await _menuRepository.AddAsync(menu, db);
- await db.CommitTranAsync();
+ await _menuRepository.AddAsync(menu, Db);
+ await Db.CommitTranAsync();
stopwatch.Stop();
NlogHelper.Info($"新增Mqtt配置 '{mqtt.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
catch (Exception ex)
{
- await db.RollbackTranAsync();
+ await Db.RollbackTranAsync();
NlogHelper.Error($"添加MQTT配置 {{mqtt.Name}} 失败", ex);
throw;
}
@@ -111,32 +104,29 @@ public class MqttRepository : IMqttRepository
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using (var db = DbContext.GetInstance())
+ await Db.BeginTranAsync();
+ try
{
- await db.BeginTranAsync();
- try
+ var result = await Db.Updateable(_mapper.Map(mqtt))
+ .ExecuteCommandAsync();
+ // Update menu entry
+ var menu = await _menuRepository.GetMenuByDataIdAsync(mqtt.Id, MenuType.MqttMenu);
+ if (menu != null)
{
- var result = await db.Updateable(_mapper.Map(mqtt))
- .ExecuteCommandAsync();
- // Update menu entry
- var menu = await _menuRepository.GetMenuByDataIdAsync(mqtt.Id, MenuType.MqttMenu);
- if (menu != null)
- {
- menu.Name = mqtt.Name;
- await _menuRepository.UpdateAsync(menu, db);
- }
+ menu.Name = mqtt.Name;
+ await _menuRepository.UpdateAsync(menu, Db);
+ }
- await db.CommitTranAsync();
- stopwatch.Stop();
- NlogHelper.Info($"更新Mqtt配置 '{mqtt.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
- catch (Exception ex)
- {
- await db.RollbackTranAsync();
- NlogHelper.Error($"更新MQTT配置 {{mqtt.Name}} 失败", ex);
- throw;
- }
+ await Db.CommitTranAsync();
+ stopwatch.Stop();
+ NlogHelper.Info($"更新Mqtt配置 '{mqtt.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
+ return result;
+ }
+ catch (Exception ex)
+ {
+ await Db.RollbackTranAsync();
+ NlogHelper.Error($"更新MQTT配置 {{mqtt.Name}} 失败", ex);
+ throw;
}
}
@@ -149,32 +139,29 @@ public class MqttRepository : IMqttRepository
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using (var db = DbContext.GetInstance())
+ await Db.BeginTranAsync();
+ try
{
- await db.BeginTranAsync();
- try
+ var result = await Db.Deleteable()
+ .In(mqtt.Id)
+ .ExecuteCommandAsync();
+ // DeleteAsync menu entry
+ var menu = await _menuRepository.GetMenuByDataIdAsync(mqtt.Id, MenuType.MqttMenu);
+ if (menu != null)
{
- var result = await db.Deleteable()
- .In(mqtt.Id)
- .ExecuteCommandAsync();
- // DeleteAsync menu entry
- var menu = await _menuRepository.GetMenuByDataIdAsync(mqtt.Id, MenuType.MqttMenu);
- if (menu != null)
- {
- await _menuRepository.DeleteAsync(menu, db);
- }
+ await _menuRepository.DeleteAsync(menu, Db);
+ }
- await db.CommitTranAsync();
- stopwatch.Stop();
- NlogHelper.Info($"删除Mqtt配置ID '{mqtt.Id}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
- catch (Exception ex)
- {
- await db.RollbackTranAsync();
- NlogHelper.Error($"删除MQTT配置 {{mqtt.Name}} 失败", ex);
- throw;
- }
+ await Db.CommitTranAsync();
+ stopwatch.Stop();
+ NlogHelper.Info($"删除Mqtt配置ID '{mqtt.Id}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
+ return result;
+ }
+ catch (Exception ex)
+ {
+ await Db.RollbackTranAsync();
+ NlogHelper.Error($"删除MQTT配置 {{mqtt.Name}} 失败", ex);
+ throw;
}
}
}
\ No newline at end of file
diff --git a/DMS.Infrastructure/Repositories/UserRepository.cs b/DMS.Infrastructure/Repositories/UserRepository.cs
index 3eb4faa..441c2a9 100644
--- a/DMS.Infrastructure/Repositories/UserRepository.cs
+++ b/DMS.Infrastructure/Repositories/UserRepository.cs
@@ -1,8 +1,7 @@
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Threading.Tasks;
+using AutoMapper;
+using DMS.Core.Models;
+using DMS.Infrastructure.Interfaces;
using DMS.Infrastructure.Entities;
-using DMS.Core.Helper;
using DMS.Infrastructure.Data;
namespace DMS.Infrastructure.Repositories;
@@ -10,95 +9,10 @@ namespace DMS.Infrastructure.Repositories;
///
/// 用户仓储类,用于操作DbUser实体
///
-public class UserRepository : IUserRepository
+public class UserRepository : BaseRepository
{
-
- ///
- /// 根据ID获取用户
- ///
- /// 主键ID
- ///
- public async Task GetByIdAsync(int id)
+ public UserRepository(IMapper mapper, ITransaction transaction)
+ : base(mapper, transaction)
{
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- using (var _db = DbContext.GetInstance())
- {
- var result = await _db.Queryable().In(id).SingleAsync();
- stopwatch.Stop();
- NlogHelper.Info($"根据ID '{id}' 获取用户耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
- }
-
- ///
- /// 获取所有用户
- ///
- ///
- public async Task> GetAllAsync()
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- using (var _db = DbContext.GetInstance())
- {
- var result = await _db.Queryable().ToListAsync();
- stopwatch.Stop();
- NlogHelper.Info($"获取所有用户耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
- }
-
- ///
- /// 新增用户
- ///
- /// 用户实体
- ///
- public async Task AddAsync(DbUser user)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- using (var _db = DbContext.GetInstance())
- {
- var result = await _db.Insertable(user).ExecuteReturnIdentityAsync();
- stopwatch.Stop();
- NlogHelper.Info($"新增用户 '{user.Id}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
- }
-
- ///
- /// 更新用户
- ///
- /// 用户实体
- ///
- public async Task UpdateAsync(DbUser user)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- using (var _db = DbContext.GetInstance())
- {
- var result = await _db.Updateable(user).ExecuteCommandAsync();
- stopwatch.Stop();
- NlogHelper.Info($"更新用户 '{user.Id}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
- }
-
- ///
- /// 根据ID删除用户
- ///
- /// 主键ID
- ///
- public async Task DeleteAsync(int id)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- using (var _db = DbContext.GetInstance())
- {
- var result = await _db.Deleteable().In(id).ExecuteCommandAsync();
- stopwatch.Stop();
- NlogHelper.Info($"删除用户ID '{id}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
}
}
\ No newline at end of file
diff --git a/DMS.Infrastructure/Repositories/VarDataRepository.cs b/DMS.Infrastructure/Repositories/VarDataRepository.cs
index ba8f8ed..1aaa223 100644
--- a/DMS.Infrastructure/Repositories/VarDataRepository.cs
+++ b/DMS.Infrastructure/Repositories/VarDataRepository.cs
@@ -1,12 +1,8 @@
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Threading.Tasks;
-using SqlSugar;
using AutoMapper;
-using Dm.util;
-using DMS.Infrastructure.Entities;
-using DMS.Core.Helper;
using DMS.Core.Models;
+using DMS.Infrastructure.Interfaces;
+using System.Diagnostics;
+using DMS.Infrastructure.Entities;
using DMS.Infrastructure.Data;
namespace DMS.Infrastructure.Repositories;
@@ -14,169 +10,54 @@ namespace DMS.Infrastructure.Repositories;
///
/// VariableData仓储类,用于操作DbVariableData实体
///
-public class VarDataRepository : IVarDataRepository
+public class VarDataRepository : BaseRepository
{
- private readonly IMapper _mapper;
-
- public VarDataRepository(IMapper mapper)
+ public VarDataRepository(IMapper mapper, ITransaction transaction)
+ : base(mapper, transaction)
{
- _mapper = mapper;
}
- ///
- /// 根据ID获取VariableData
- ///
- /// 主键ID
- ///
- public async Task GetByIdAsync(int id)
+
+
+ public override async Task> GetAllAsync()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using (var db = DbContext.GetInstance())
- {
- var result = await GetByIdAsync(id, db);
- stopwatch.Stop();
- NlogHelper.Info($"根据ID '{id}' 获取VariableData耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
- }
-
- ///
- /// 根据ID获取VariableData
- ///
- /// 主键ID
- /// SqlSugarClient实例
- ///
- public async Task GetByIdAsync(int id, SqlSugarClient db)
- {
- return await db.Queryable()
- .In(id)
- .SingleAsync();
- }
-
- ///
- /// 获取所有VariableData
- ///
- ///
- public async Task> GetAllAsync()
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- using (var db = DbContext.GetInstance())
- {
- var result = await GetAllAsync(db);
- stopwatch.Stop();
- NlogHelper.Info($"获取所有VariableData耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
- }
-
- ///
- /// 获取所有VariableData
- ///
- /// SqlSugarClient实例
- ///
- public async Task> GetAllAsync(SqlSugarClient db)
- {
- var result = await db.Queryable()
+ var result = await Db.Queryable()
.Includes(d => d.VariableTable)
.Includes(d => d.VariableTable.Device)
.ToListAsync();
+ stopwatch.Stop();
+ //NlogHelper.Info($"获取所有VariableData耗时:{stopwatch.ElapsedMilliseconds}ms");
return result.Select(d => _mapper.Map(d))
.ToList();
}
- ///
- /// 获取所有VariableData
- ///
- ///
public async Task> GetByVariableTableIdAsync(int varTableId)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using (var db = DbContext.GetInstance())
- {
- var result = await GetByVariableTableIdAsync(varTableId, db);
- stopwatch.Stop();
- NlogHelper.Info($"获取变量表的所有变量{result.Count()}个耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
- }
-
- ///
- /// 获取所有VariableData
- ///
- /// SqlSugarClient实例
- ///
- public async Task> GetByVariableTableIdAsync(int varTableId, SqlSugarClient db)
- {
- var result = await db.Queryable()
+ var result = await Db.Queryable()
.Where(d => d.VariableTableId == varTableId)
.ToListAsync();
+ stopwatch.Stop();
+ //NlogHelper.Info($"获取变量表的所有变量{result.Count()}个耗时:{stopwatch.ElapsedMilliseconds}ms");
return result.Select(d => _mapper.Map(d))
.ToList();
}
- ///
- /// 新增VariableData
- ///
- /// VariableData实体
- ///
- public async Task AddAsync(Variable variable)
+ public override async Task AddAsync(Variable variable)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using (var db = DbContext.GetInstance())
- {
- var varData = await AddAsync(variable, db);
- stopwatch.Stop();
- NlogHelper.Info($"新增VariableData '{variable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return varData;
- }
- }
-
-
- ///
- /// 新增VariableData
- ///
- /// VariableData实体
- ///
- public async Task AddAsync(Variable variable, SqlSugarClient db)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- var dbVarData = await db.Insertable(_mapper.Map(variable))
+ var dbVarData = await Db.Insertable(_mapper.Map(variable))
.ExecuteReturnEntityAsync();
stopwatch.Stop();
- NlogHelper.Info($"新增VariableData '{variable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return _mapper.Map(dbVarData);
+ //NlogHelper.Info($"新增VariableData '{variable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
+ return dbVarData.Id;
}
- ///
- /// 新增VariableData
- ///
- /// VariableData实体
- ///
public async Task AddAsync(IEnumerable variableDatas)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- using (var db = DbContext.GetInstance())
- {
- var varData = await AddAsync(variableDatas, db);
- stopwatch.Stop();
- NlogHelper.Info($"新增VariableData '{variableDatas.Count()}'个, 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return varData;
- }
- }
-
-
- ///
- /// 新增VariableData
- ///
- /// VariableData实体
- ///
- public async Task AddAsync(IEnumerable variableDatas, SqlSugarClient db)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -185,138 +66,66 @@ public class VarDataRepository : IVarDataRepository
var dbList = variableDatas.Select(vb => _mapper.Map(vb))
.ToList();
stopwatch2.Stop();
- NlogHelper.Info($"复制 Variable'{variableDatas.Count()}'个, 耗时:{stopwatch2.ElapsedMilliseconds}ms");
+ //NlogHelper.Info($"复制 Variable'{variableDatas.Count()}'个, 耗时:{stopwatch2.ElapsedMilliseconds}ms");
- var res = await db.Insertable(dbList)
+ var res = await Db.Insertable(dbList)
.ExecuteCommandAsync();
stopwatch.Stop();
- NlogHelper.Info($"新增VariableData '{variableDatas.Count()}'个, 耗时:{stopwatch.ElapsedMilliseconds}ms");
+ //NlogHelper.Info($"新增VariableData '{variableDatas.Count()}'个, 耗时:{stopwatch.ElapsedMilliseconds}ms");
return res;
}
- ///
- /// 更新VariableData
- ///
- /// VariableData实体
- ///
- public async Task UpdateAsync(Variable variable)
+ public override async Task UpdateAsync(Variable variable)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using (var db = DbContext.GetInstance())
- {
- var result = await UpdateAsync(variable, db);
- stopwatch.Stop();
- NlogHelper.Info($"更新VariableData '{variable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
- }
-
- ///
- /// 更新VariableData
- ///
- /// VariableData实体
- /// SqlSugarClient实例
- ///
- public async Task UpdateAsync(Variable variable, SqlSugarClient db)
- {
- var result = await db.Updateable(_mapper.Map(variable))
+ var result = await Db.Updateable(_mapper.Map(variable))
.ExecuteCommandAsync();
+ stopwatch.Stop();
+ //NlogHelper.Info($"更新VariableData '{variable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
- ///
- /// 更新VariableData
- ///
- /// VariableData实体
- ///
public async Task UpdateAsync(List variableDatas)
- {
- using var _db = DbContext.GetInstance();
- return await UpdateAsync(variableDatas, _db);
- }
-
- ///
- /// 更新VariableData
- ///
- /// VariableData实体
- ///
- public async Task UpdateAsync(List variableDatas, SqlSugarClient db)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var dbVarDatas = variableDatas.Select(vd => _mapper.Map(vd));
- var result = await db.Updateable(dbVarDatas.ToList())
+ var result = await Db.Updateable(dbVarDatas.ToList())
.ExecuteCommandAsync();
stopwatch.Stop();
- NlogHelper.Info($"更新VariableData {variableDatas.Count()}个 耗时:{stopwatch.ElapsedMilliseconds}ms");
+ //NlogHelper.Info($"更新VariableData {variableDatas.Count()}个 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
- ///
- /// 删除VariableData
- ///
- /// 主键ID
- ///
- public async Task DeleteAsync(Variable variable)
+ public override async Task DeleteAsync(Variable variable)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using var db = DbContext.GetInstance();
- var result = await DeleteAsync(variable, db);
- stopwatch.Stop();
- NlogHelper.Info($"删除VariableData: '{variable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
-
- ///
- /// 根据ID删除VariableData
- ///
- /// 主键ID
- /// SqlSugarClient实例
- ///
- public async Task DeleteAsync(Variable variable, SqlSugarClient db)
- {
- var result = await db.Deleteable()
+ var result = await Db.Deleteable()
.Where(d => d.Id == variable.Id)
.ExecuteCommandAsync();
+ stopwatch.Stop();
+ //NlogHelper.Info($"删除VariableData: '{variable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
- ///
- /// 删除VariableData
- ///
- /// 主键ID
- ///
public async Task DeleteAsync(IEnumerable variableDatas)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using var db = DbContext.GetInstance();
- var result = await DeleteAsync(variableDatas, db);
-
- stopwatch.Stop();
- NlogHelper.Info($"删除VariableData: '{variableDatas.Count()}'个 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
-
- ///
- /// 删除VariableData
- ///
- /// 主键ID
- /// SqlSugarClient实例
- ///
- public async Task DeleteAsync(IEnumerable variableDatas, SqlSugarClient db)
- {
var dbList = variableDatas.Select(vd => _mapper.Map(vd))
.ToList();
- var result = await db.Deleteable(dbList)
+ var result = await Db.Deleteable(dbList)
.ExecuteCommandAsync();
+
+ stopwatch.Stop();
+ //NlogHelper.Info($"删除VariableData: '{variableDatas.Count()}'个 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
@@ -333,8 +142,7 @@ public class VarDataRepository : IVarDataRepository
/// 成功添加或更新关联的数量。
public async Task AddMqttToVariablesAsync(IEnumerable variableMqttList)
{
- using var db = DbContext.GetInstance();
- await db.BeginTranAsync();
+ await Db.BeginTranAsync();
try
{
@@ -343,7 +151,7 @@ public class VarDataRepository : IVarDataRepository
var mqttIds = variableMqttList.Select(vm => vm.Mqtt.Id).Distinct().ToList();
// 1. 一次性查询所有相关的现有别名
- var existingAliases = await db.Queryable()
+ var existingAliases = await Db.Queryable()
.Where(it => variableIds.Contains(it.VariableId) && mqttIds.Contains(it.MqttId))
.ToListAsync();
@@ -383,25 +191,25 @@ public class VarDataRepository : IVarDataRepository
// 2. 批量更新
if (toUpdate.Any())
{
- var updateResult = await db.Updateable(toUpdate).ExecuteCommandAsync();
+ var updateResult = await Db.Updateable(toUpdate).ExecuteCommandAsync();
affectedCount += updateResult;
}
// 3. 批量插入
if (toInsert.Any())
{
- var insertResult = await db.Insertable(toInsert).ExecuteCommandAsync();
+ var insertResult = await Db.Insertable(toInsert).ExecuteCommandAsync();
affectedCount += insertResult;
}
- await db.CommitTranAsync();
- NlogHelper.Info($"成功为 {variableMqttList.Count()} 个变量请求添加/更新了MQTT服务器关联,实际影响 {affectedCount} 个。");
+ await Db.CommitTranAsync();
+ //NlogHelper.Info($"成功为 {variableMqttList.Count()} 个变量请求添加/更新了MQTT服务器关联,实际影响 {affectedCount} 个。");
return affectedCount;
}
catch (Exception ex)
{
- await db.RollbackTranAsync();
- NlogHelper.Error($"为变量添加MQTT服务器关联时发生错误: {ex.Message}", ex);
+ await Db.RollbackTranAsync();
+ //NlogHelper.Error($"为变量添加MQTT服务器关联时发生错误: {ex.Message}", ex);
// 根据需要,可以向上层抛出异常
throw;
}
diff --git a/DMS.Infrastructure/Repositories/VarTableRepository.cs b/DMS.Infrastructure/Repositories/VarTableRepository.cs
index 31eef8c..10ad2fa 100644
--- a/DMS.Infrastructure/Repositories/VarTableRepository.cs
+++ b/DMS.Infrastructure/Repositories/VarTableRepository.cs
@@ -1,20 +1,17 @@
-using SqlSugar;
-using System.Diagnostics;
using AutoMapper;
-using DMS.Infrastructure.Entities;
-using DMS.Core.Helper;
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 : IVarTableRepository
+public class VarTableRepository : BaseRepository
{
- private readonly IMapper _mapper;
-
- public VarTableRepository(IMapper mapper)
+ public VarTableRepository(IMapper mapper, ITransaction transaction)
+ : base(mapper, transaction)
{
- _mapper = mapper;
}
///
@@ -26,32 +23,11 @@ public class VarTableRepository : IVarTableRepository
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using (var db = DbContext.GetInstance())
- {
- var addVarTable = await AddAsync(varTable, db);
-
- stopwatch.Stop();
- NlogHelper.Info($"添加变量表 '{varTable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return addVarTable;
- }
- }
-
-
- ///
- /// 添加变量表支持事务
- ///
- ///
- ///
- ///
- public async Task AddAsync(VariableTable variableTable, SqlSugarClient db)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
-
- var addVarTabel = await db.Insertable(_mapper.Map(variableTable))
+ var addVarTabel = await Db.Insertable(_mapper.Map(varTable))
.ExecuteReturnEntityAsync();
+
stopwatch.Stop();
- NlogHelper.Info($"添加设备 '{addVarTabel.Name}' 的默认变量表耗时:{stopwatch.ElapsedMilliseconds}ms");
+ //NlogHelper.Info($"添加变量表 '{varTable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return _mapper.Map(addVarTabel);
}
@@ -64,26 +40,10 @@ public class VarTableRepository : IVarTableRepository
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using var db = DbContext.GetInstance();
- var result = await UpdateAsync(variableTable, db);
- stopwatch.Stop();
- NlogHelper.Info($"编辑变量表 '{variableTable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
-
- ///
- /// 编辑变量表,支持事务
- ///
- ///
- ///
- public async Task UpdateAsync(VariableTable variableTable, SqlSugarClient db)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- var result = await db.Updateable(_mapper.Map(variableTable))
+ var result = await Db.Updateable(_mapper.Map(variableTable))
.ExecuteCommandAsync();
stopwatch.Stop();
- NlogHelper.Info($"编辑变量表 '{variableTable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
+ //NlogHelper.Info($"编辑变量表 '{variableTable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
@@ -92,35 +52,17 @@ public class VarTableRepository : IVarTableRepository
///
///
///
- public async Task DeleteAsync(VariableTable variableTable)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- using (var db = DbContext.GetInstance())
- {
- var result = await DeleteAsync(variableTable, db);
- stopwatch.Stop();
- NlogHelper.Info($"删除变量表 '{variableTable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
- }
-
- ///
- /// 删除变量表支持事务
- ///
- ///
- ///
- public async Task DeleteAsync(VariableTable varTable, SqlSugarClient db)
+ 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))
+ var res= await Db.Deleteable(_mapper.Map(varTable))
.ExecuteCommandAsync();
stopwatch.Stop();
- NlogHelper.Info($"删除变量表 '{varTable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
+ //NlogHelper.Info($"删除变量表 '{varTable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return res;
}
@@ -129,14 +71,14 @@ public class VarTableRepository : IVarTableRepository
///
///
///
- public async Task DeleteAsync(IEnumerable deviceVariableTables, SqlSugarClient db)
+ 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)
+ await Db.Deleteable(dbList)
.ExecuteCommandAsync();
}
diff --git a/DMS.Infrastructure/Repositories/VariableMqttAliasRepository.cs b/DMS.Infrastructure/Repositories/VariableMqttAliasRepository.cs
index 004f235..3ca4ad6 100644
--- a/DMS.Infrastructure/Repositories/VariableMqttAliasRepository.cs
+++ b/DMS.Infrastructure/Repositories/VariableMqttAliasRepository.cs
@@ -1,124 +1,18 @@
-using SqlSugar;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using DMS.Infrastructure.Data;
+using AutoMapper;
+using DMS.Core.Models;
+using DMS.Infrastructure.Interfaces;
using DMS.Infrastructure.Entities;
+using DMS.Infrastructure.Data;
namespace DMS.Infrastructure.Repositories;
///
/// 变量与MQTT服务器别名关联的数据仓库。
///
-public class VariableMqttAliasRepository : IVariableMqttAliasRepository
+public class VariableMqttAliasRepository : BaseRepository
{
- ///
- /// 根据变量ID和MQTT服务器ID获取别名。
- ///
- /// 变量数据ID。
- /// MQTT服务器ID。
- /// DbVariableMqtt实体,如果不存在则为null。
- public async Task GetAliasByVariableAndMqtt(int variableDataId, int mqttId)
+ public VariableMqttAliasRepository(IMapper mapper, ITransaction transaction)
+ : base(mapper, transaction)
{
- using (var db = DbContext.GetInstance())
- {
- return await GetAliasByVariableAndMqtt(variableDataId, mqttId, db);
- }
- }
-
- ///
- /// 根据变量ID和MQTT服务器ID获取别名。
- ///
- /// 变量数据ID。
- /// MQTT服务器ID。
- /// SqlSugarClient实例。
- /// DbVariableMqtt实体,如果不存在则为null。
- public async Task GetAliasByVariableAndMqtt(int variableDataId, int mqttId, SqlSugarClient db)
- {
- return await db.Queryable()
- .Where(it => it.VariableId == variableDataId && it.MqttId == mqttId)
- .FirstAsync();
- }
-
- ///
- /// 批量添加变量与MQTT服务器的关联。
- ///
- /// 要添加的DbVariableMqtt实体列表。
- /// 成功添加的数量。
- public async Task AddManyAsync(IEnumerable entities)
- {
- using (var db = DbContext.GetInstance())
- {
- return await AddManyAsync(entities, db);
- }
- }
-
- ///
- /// 批量添加变量与MQTT服务器的关联。
- ///
- /// 要添加的DbVariableMqtt实体列表。
- /// SqlSugarClient实例。
- /// 成功添加的数量。
- public async Task AddManyAsync(IEnumerable entities, SqlSugarClient db)
- {
- return await db.Insertable(entities).ExecuteCommandAsync();
- }
-
- ///
- /// 更新变量与MQTT服务器的别名。
- ///
- /// 变量数据ID。
- /// MQTT服务器ID。
- /// 新的别名。
- /// 受影响的行数。
- public async Task UpdateAliasAsync(int variableDataId, int mqttId, string newAlias)
- {
- using (var db = DbContext.GetInstance())
- {
- return await UpdateAliasAsync(variableDataId, mqttId, newAlias, db);
- }
- }
-
- ///
- /// 更新变量与MQTT服务器的别名。
- ///
- /// 变量数据ID。
- /// MQTT服务器ID。
- /// 新的别名。
- /// SqlSugarClient实例。
- /// 受影响的行数。
- public async Task UpdateAliasAsync(int variableDataId, int mqttId, string newAlias, SqlSugarClient db)
- {
- return await db.Updateable()
- .SetColumns(it => it.MqttAlias == newAlias)
- .Where(it => it.VariableId == variableDataId && it.MqttId == mqttId)
- .ExecuteCommandAsync();
- }
-
- ///
- /// 删除变量与MQTT服务器的关联。
- ///
- /// 变量数据ID。
- /// MQTT服务器ID。
- /// 受影响的行数。
- public async Task DeleteAsync(int variableDataId, int mqttId)
- {
- using (var db = DbContext.GetInstance())
- {
- return await DeleteAsync(variableDataId, mqttId, db);
- }
- }
-
- ///
- /// 删除变量与MQTT服务器的关联。
- ///
- /// 变量数据ID。
- /// MQTT服务器ID。
- /// SqlSugarClient实例。
- /// 受影响的行数。
- public async Task DeleteAsync(int variableDataId, int mqttId, SqlSugarClient db)
- {
- return await db.Deleteable()
- .Where(it => it.VariableId == variableDataId && it.MqttId == mqttId)
- .ExecuteCommandAsync();
}
}
diff --git a/DMS.Infrastructure/Services/DatabaseInitializerService.cs b/DMS.Infrastructure/Services/DatabaseInitializerService.cs
index cc25179..a8fffe9 100644
--- a/DMS.Infrastructure/Services/DatabaseInitializerService.cs
+++ b/DMS.Infrastructure/Services/DatabaseInitializerService.cs
@@ -8,13 +8,13 @@ using System.Threading.Tasks;
namespace DMS.Infrastructure.Services
{
- public class DatabaseInitializerService : DMS.Core.Interfaces.IDatabaseService
+ public class DatabaseInitializerService : DMS.Infrastructure.Interfaces.IDatabaseService
{
private readonly SqlSugarClient _db;
public DatabaseInitializerService(SqlSugarDbContext dbContext)
{
- _db = dbContext.GetSqlSugarClient();
+ _db = dbContext.GetInstance();
}
public void InitializeDataBase()
diff --git a/DMS.WPF/App.xaml.cs b/DMS.WPF/App.xaml.cs
index 3363c11..1b0269a 100644
--- a/DMS.WPF/App.xaml.cs
+++ b/DMS.WPF/App.xaml.cs
@@ -5,8 +5,8 @@ using DMS.Core.Enums;
using DMS.Helper;
using DMS.Services;
using DMS.Services.Processors;
-using DMS.ViewModels;
-using DMS.Views;
+using DMS.WPF.ViewModels;
+using DMS.WPF.Views;
using iNKORE.UI.WPF.Modern.Common.IconKeys;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@@ -19,7 +19,7 @@ using DMS.Infrastructure.Data;
using DMS.WPF.Helper;
using DMS.WPF.Services;
using DMS.WPF.Services.Processors;
-using DMS.WPF.ViewModels.DMS.ViewModels;
+using DMS.WPF.ViewModels.DMS.WPF.ViewModels;
using SqlSugar;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
@@ -112,8 +112,8 @@ public partial class App : System.Windows.Application
// SqlSugarDbContext now internally creates SqlSugarClient using ConnectionSettings
services.AddScoped();
- // Register IUnitOfWork (abstract interface for transaction management)
- services.AddScoped();
+ // Register ITransaction (abstract interface for transaction management)
+ services.AddScoped();
// Register IDatabaseService (abstract interface for database initialization)
services.AddSingleton();
diff --git a/DMS.WPF/Helper/DataServicesHelper.cs b/DMS.WPF/Helper/DataServicesHelper.cs
index 9eca085..7ceeaf0 100644
--- a/DMS.WPF/Helper/DataServicesHelper.cs
+++ b/DMS.WPF/Helper/DataServicesHelper.cs
@@ -1,7 +1,7 @@
using DMS.Core.Enums;
-using DMS.Models;
-using DMS.ViewModels;
+using DMS.WPF.Models;
+using DMS.WPF.ViewModels;
using DMS.WPF.Models;
using DMS.WPF.ViewModels;
using Microsoft.Extensions.DependencyInjection;
diff --git a/DMS.WPF/Helper/ExcelHelper.cs b/DMS.WPF/Helper/ExcelHelper.cs
index a6d0bd7..efebd2a 100644
--- a/DMS.WPF/Helper/ExcelHelper.cs
+++ b/DMS.WPF/Helper/ExcelHelper.cs
@@ -6,7 +6,7 @@ using System.IO;
using System.Linq;
using System.Reflection;
using DMS.Core.Enums;
-using DMS.Models;
+using DMS.WPF.Models;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
diff --git a/DMS.WPF/Helper/MenuHelper.cs b/DMS.WPF/Helper/MenuHelper.cs
index c52c4f9..53e6021 100644
--- a/DMS.WPF/Helper/MenuHelper.cs
+++ b/DMS.WPF/Helper/MenuHelper.cs
@@ -1,4 +1,4 @@
-using DMS.Models;
+using DMS.WPF.Models;
namespace DMS.Helper;
diff --git a/DMS.WPF/Message/NavgatorMessage.cs b/DMS.WPF/Message/NavgatorMessage.cs
index dff4b1b..06f2462 100644
--- a/DMS.WPF/Message/NavgatorMessage.cs
+++ b/DMS.WPF/Message/NavgatorMessage.cs
@@ -1,5 +1,5 @@
using CommunityToolkit.Mvvm.Messaging.Messages;
-using DMS.ViewModels;
+using DMS.WPF.ViewModels;
namespace DMS.Message;
diff --git a/DMS.WPF/Models/MenuBean.cs b/DMS.WPF/Models/MenuBean.cs
index 10c5596..5df2cef 100644
--- a/DMS.WPF/Models/MenuBean.cs
+++ b/DMS.WPF/Models/MenuBean.cs
@@ -1,8 +1,8 @@
using CommunityToolkit.Mvvm.ComponentModel;
using DMS.Core.Enums;
-using DMS.ViewModels;
+using DMS.WPF.ViewModels;
-namespace DMS.Models;
+namespace DMS.WPF.Models;
///
/// 表示菜单项。
diff --git a/DMS.WPF/Models/Notification.cs b/DMS.WPF/Models/Notification.cs
index 4c8b7e3..a42e60b 100644
--- a/DMS.WPF/Models/Notification.cs
+++ b/DMS.WPF/Models/Notification.cs
@@ -1,6 +1,6 @@
using DMS.Core.Enums;
-namespace DMS.Models;
+namespace DMS.WPF.Models;
///
/// 表示通知信息。
diff --git a/DMS.WPF/Models/OpcUaNode.cs b/DMS.WPF/Models/OpcUaNode.cs
index c4605b8..889b67e 100644
--- a/DMS.WPF/Models/OpcUaNode.cs
+++ b/DMS.WPF/Models/OpcUaNode.cs
@@ -2,7 +2,7 @@ using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using Opc.Ua;
-namespace DMS.Models;
+namespace DMS.WPF.Models;
///
/// 表示OPC UA节点,用于构建节点树。
diff --git a/DMS.WPF/Models/User.cs b/DMS.WPF/Models/User.cs
index 2b26fe4..e18bb4e 100644
--- a/DMS.WPF/Models/User.cs
+++ b/DMS.WPF/Models/User.cs
@@ -1,4 +1,4 @@
-namespace DMS.Models;
+namespace DMS.WPF.Models;
public class User
{
diff --git a/DMS.WPF/Models/VariableContext.cs b/DMS.WPF/Models/VariableContext.cs
index f023cc5..628c9ff 100644
--- a/DMS.WPF/Models/VariableContext.cs
+++ b/DMS.WPF/Models/VariableContext.cs
@@ -1,4 +1,4 @@
-using DMS.Models;
+using DMS.WPF.Models;
namespace DMS.Models
{
diff --git a/DMS.WPF/Models/VariableMqtt.cs b/DMS.WPF/Models/VariableMqtt.cs
index 226bc99..cb84c35 100644
--- a/DMS.WPF/Models/VariableMqtt.cs
+++ b/DMS.WPF/Models/VariableMqtt.cs
@@ -1,9 +1,10 @@
using System;
using CommunityToolkit.Mvvm.ComponentModel;
using DMS.Core.Enums;
-using DMS.Data.Entities;
-namespace DMS.Models;
+using DMS.WPF.Models;
+
+namespace DMS.WPF.Models;
///
/// 表示变量数据与MQTT服务器之间的关联模型,包含MQTT别名。
diff --git a/DMS.WPF/Models/VariableTable.cs b/DMS.WPF/Models/VariableTable.cs
index 6fe1c08..22c09df 100644
--- a/DMS.WPF/Models/VariableTable.cs
+++ b/DMS.WPF/Models/VariableTable.cs
@@ -3,7 +3,7 @@ using System.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;
using DMS.Core.Enums;
-namespace DMS.Models;
+namespace DMS.WPF.Models;
///
/// 表示变量表信息。
diff --git a/DMS.WPF/Services/DataProcessingService.cs b/DMS.WPF/Services/DataProcessingService.cs
index 41d097f..c1a583a 100644
--- a/DMS.WPF/Services/DataProcessingService.cs
+++ b/DMS.WPF/Services/DataProcessingService.cs
@@ -4,7 +4,7 @@ using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using DMS.Helper;
-using DMS.Models;
+using DMS.WPF.Models;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
diff --git a/DMS.WPF/Services/IDataProcessingService.cs b/DMS.WPF/Services/IDataProcessingService.cs
index a57ffe5..e611f42 100644
--- a/DMS.WPF/Services/IDataProcessingService.cs
+++ b/DMS.WPF/Services/IDataProcessingService.cs
@@ -1,5 +1,5 @@
using System.Threading.Tasks;
-using DMS.Models;
+using DMS.WPF.Models;
namespace DMS.Services;
diff --git a/DMS.WPF/Services/IDialogService.cs b/DMS.WPF/Services/IDialogService.cs
index 3938406..3e2b0bb 100644
--- a/DMS.WPF/Services/IDialogService.cs
+++ b/DMS.WPF/Services/IDialogService.cs
@@ -1,5 +1,5 @@
using DMS.Core.Enums;
-using DMS.Models;
+using DMS.WPF.Models;
using iNKORE.UI.WPF.Modern.Controls;
namespace DMS.Services;
diff --git a/DMS.WPF/Services/INotificationService.cs b/DMS.WPF/Services/INotificationService.cs
index 7933909..56bace5 100644
--- a/DMS.WPF/Services/INotificationService.cs
+++ b/DMS.WPF/Services/INotificationService.cs
@@ -1,5 +1,5 @@
using DMS.Core.Enums;
-using DMS.Models;
+using DMS.WPF.Models;
namespace DMS.Services;
diff --git a/DMS.WPF/Services/IVariableProcessor.cs b/DMS.WPF/Services/IVariableProcessor.cs
index c8aa8bf..4e31c26 100644
--- a/DMS.WPF/Services/IVariableProcessor.cs
+++ b/DMS.WPF/Services/IVariableProcessor.cs
@@ -1,5 +1,5 @@
using System.Threading.Tasks;
-using DMS.Models;
+using DMS.WPF.Models;
namespace DMS.Services;
diff --git a/DMS.WPF/Services/MqttBackgroundService.cs b/DMS.WPF/Services/MqttBackgroundService.cs
index 5a999f2..bc1a4cc 100644
--- a/DMS.WPF/Services/MqttBackgroundService.cs
+++ b/DMS.WPF/Services/MqttBackgroundService.cs
@@ -3,7 +3,7 @@ using System.Text;
using System.Threading.Channels;
using DMS.Data.Repositories;
using DMS.Helper;
-using DMS.Models;
+using DMS.WPF.Models;
using Microsoft.Extensions.Hosting;
using MQTTnet;
using MQTTnet.Client;
diff --git a/DMS.WPF/Services/NavgatorServices.cs b/DMS.WPF/Services/NavgatorServices.cs
index 2665bc4..ff9fe88 100644
--- a/DMS.WPF/Services/NavgatorServices.cs
+++ b/DMS.WPF/Services/NavgatorServices.cs
@@ -2,7 +2,7 @@
using CommunityToolkit.Mvvm.Messaging;
using DMS.Helper;
using DMS.Message;
-using DMS.ViewModels;
+using DMS.WPF.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using DMS.Core.Enums;
diff --git a/DMS.WPF/Services/OpcUaBackgroundService.cs b/DMS.WPF/Services/OpcUaBackgroundService.cs
index d6d172a..e861434 100644
--- a/DMS.WPF/Services/OpcUaBackgroundService.cs
+++ b/DMS.WPF/Services/OpcUaBackgroundService.cs
@@ -1,7 +1,7 @@
using System.Collections.Concurrent;
using DMS.Core.Enums;
using DMS.Helper;
-using DMS.Models;
+using DMS.WPF.Models;
using Microsoft.Extensions.Hosting;
using Opc.Ua;
using Opc.Ua.Client;
diff --git a/DMS.WPF/Services/Processors/CheckValueChangedProcessor.cs b/DMS.WPF/Services/Processors/CheckValueChangedProcessor.cs
index fdfc35f..ded0cf4 100644
--- a/DMS.WPF/Services/Processors/CheckValueChangedProcessor.cs
+++ b/DMS.WPF/Services/Processors/CheckValueChangedProcessor.cs
@@ -1,5 +1,5 @@
using DMS.Helper;
-using DMS.Models;
+using DMS.WPF.Models;
namespace DMS.Services.Processors;
diff --git a/DMS.WPF/Services/Processors/LoggingProcessor.cs b/DMS.WPF/Services/Processors/LoggingProcessor.cs
index 00ad152..a9ac817 100644
--- a/DMS.WPF/Services/Processors/LoggingProcessor.cs
+++ b/DMS.WPF/Services/Processors/LoggingProcessor.cs
@@ -1,5 +1,5 @@
using System.Threading.Tasks;
-using DMS.Models;
+using DMS.WPF.Models;
using Microsoft.Extensions.Logging;
using DMS.Helper;
diff --git a/DMS.WPF/Services/Processors/MqttPublishProcessor.cs b/DMS.WPF/Services/Processors/MqttPublishProcessor.cs
index 9844a07..e3ebd74 100644
--- a/DMS.WPF/Services/Processors/MqttPublishProcessor.cs
+++ b/DMS.WPF/Services/Processors/MqttPublishProcessor.cs
@@ -1,5 +1,5 @@
using System.Threading.Tasks;
-using DMS.Models;
+using DMS.WPF.Models;
namespace DMS.Services.Processors
{
diff --git a/DMS.WPF/Services/Processors/UpdateDbVariableProcessor.cs b/DMS.WPF/Services/Processors/UpdateDbVariableProcessor.cs
index 8095bcd..ae2db60 100644
--- a/DMS.WPF/Services/Processors/UpdateDbVariableProcessor.cs
+++ b/DMS.WPF/Services/Processors/UpdateDbVariableProcessor.cs
@@ -1,6 +1,6 @@
using System.Threading.Tasks;
using DMS.Helper;
-using DMS.Models;
+using DMS.WPF.Models;
namespace DMS.Services.Processors
{
diff --git a/DMS.WPF/Services/S7BackgroundService.cs b/DMS.WPF/Services/S7BackgroundService.cs
index 14232aa..533fcf9 100644
--- a/DMS.WPF/Services/S7BackgroundService.cs
+++ b/DMS.WPF/Services/S7BackgroundService.cs
@@ -1,7 +1,7 @@
using System.Collections.Concurrent;
using DMS.Core.Enums;
using DMS.Helper;
-using DMS.Models;
+using DMS.WPF.Models;
using Microsoft.Extensions.Hosting;
using S7.Net;
using S7.Net.Types;
diff --git a/DMS.WPF/ViewModels/DataTransformViewModel.cs b/DMS.WPF/ViewModels/DataTransformViewModel.cs
index b3bfb6b..4bc2b42 100644
--- a/DMS.WPF/ViewModels/DataTransformViewModel.cs
+++ b/DMS.WPF/ViewModels/DataTransformViewModel.cs
@@ -1,4 +1,4 @@
-namespace DMS.ViewModels;
+namespace DMS.WPF.ViewModels;
public class DataTransformViewModel : ViewModelBase
{
diff --git a/DMS.WPF/ViewModels/DeviceDetailViewModel.cs b/DMS.WPF/ViewModels/DeviceDetailViewModel.cs
index 03f57e5..f946e9b 100644
--- a/DMS.WPF/ViewModels/DeviceDetailViewModel.cs
+++ b/DMS.WPF/ViewModels/DeviceDetailViewModel.cs
@@ -7,10 +7,10 @@ using DMS.Core.Helper;
using DMS.Infrastructure.Data;
using DMS.Infrastructure.Repositories;
-namespace DMS.WPF.ViewModels;
using Microsoft.Extensions.DependencyInjection;
+using DMS.Services;
-namespace DMS.ViewModels;
+namespace DMS.WPF.ViewModels;
public partial class DeviceDetailViewModel : ViewModelBase
{
@@ -67,7 +67,7 @@ public partial class DeviceDetailViewModel : ViewModelBase
var parentMenu = DataServicesHelper.FindMenusForDevice(CurrentDevice, _dataServices.MenuTrees);
if (parentMenu == null)
{
- NotificationHelper.ShowError("无法找到当前设备的父级菜单,无法添加变量表菜单。");
+ //NotificationHelper.ShowError("无法找到当前设备的父级菜单,无法添加变量表菜单。");
return;
}
@@ -94,12 +94,12 @@ public partial class DeviceDetailViewModel : ViewModelBase
// 8. Update UI
CurrentDevice?.VariableTables?.Add(addedVarTable);
MessageHelper.SendLoadMessage(Enums.LoadTypes.Menu); // Refresh the main navigation menu
- NotificationHelper.ShowSuccess($"变量表 {addedVarTable.Name} 添加成功。");
+ //NotificationHelper.ShowSuccess($"变量表 {addedVarTable.Name} 添加成功。");
}
catch (Exception ex)
{
await db.RollbackTranAsync();
- NotificationHelper.ShowError($"添加变量表时发生错误: {ex.Message}", ex);
+ //NotificationHelper.ShowError($"添加变量表时发生错误: {ex.Message}", ex);
}
}
@@ -108,7 +108,7 @@ public partial class DeviceDetailViewModel : ViewModelBase
{
if (SelectedVariableTable == null)
{
- NotificationHelper.ShowInfo("请选择要编辑的变量表。");
+ //NotificationHelper.ShowInfo("请选择要编辑的变量表。");
return;
}
@@ -138,19 +138,19 @@ public partial class DeviceDetailViewModel : ViewModelBase
}
await db.CommitTranAsync();
- NotificationHelper.ShowSuccess($"变量表 {SelectedVariableTable.Name} 编辑成功。");
+ //NotificationHelper.ShowSuccess($"变量表 {SelectedVariableTable.Name} 编辑成功。");
MessageHelper.SendLoadMessage(Enums.LoadTypes.Menu); // Refresh the main navigation menu
}
else
{
await db.RollbackTranAsync();
- NotificationHelper.ShowError($"变量表 {SelectedVariableTable.Name} 编辑失败。");
+ //NotificationHelper.ShowError($"变量表 {SelectedVariableTable.Name} 编辑失败。");
}
}
catch (Exception ex)
{
await db.RollbackTranAsync();
- NotificationHelper.ShowError($"编辑变量表时发生错误: {ex.Message}", ex);
+ //NotificationHelper.ShowError($"编辑变量表时发生错误: {ex.Message}", ex);
}
}
@@ -159,7 +159,7 @@ public partial class DeviceDetailViewModel : ViewModelBase
{
if (SelectedVariableTable == null)
{
- NotificationHelper.ShowInfo("请选择要删除的变量表。");
+ //NotificationHelper.ShowInfo("请选择要删除的变量表。");
return;
}
@@ -196,19 +196,19 @@ public partial class DeviceDetailViewModel : ViewModelBase
await db.CommitTranAsync();
var delVarTableName = SelectedVariableTable.Name;
CurrentDevice?.VariableTables?.Remove(SelectedVariableTable);
- NotificationHelper.ShowSuccess($"变量表 {delVarTableName} 删除成功。");
+ //NotificationHelper.ShowSuccess($"变量表 {delVarTableName} 删除成功。");
MessageHelper.SendLoadMessage(Enums.LoadTypes.Menu); // Refresh the main navigation menu
}
else
{
await db.RollbackTranAsync();
- NotificationHelper.ShowError($"变量表 {SelectedVariableTable.Name} 删除失败。");
+ //NotificationHelper.ShowError($"变量表 {SelectedVariableTable.Name} 删除失败。");
}
}
catch (Exception ex)
{
await db.RollbackTranAsync();
- NotificationHelper.ShowError($"删除变量表时发生错误: {ex.Message}", ex);
+ //NotificationHelper.ShowError($"删除变量表时发生错误: {ex.Message}", ex);
}
}
@@ -217,7 +217,7 @@ public partial class DeviceDetailViewModel : ViewModelBase
private async Task EditDevice()
{
// Implement device editing logic, similar to AddDeviceCommand but for existing device
- NotificationHelper.ShowInfo("编辑设备功能待实现。");
+ //NotificationHelper.ShowInfo("编辑设备功能待实现。");
await Task.CompletedTask;
}
@@ -225,7 +225,7 @@ public partial class DeviceDetailViewModel : ViewModelBase
private async Task DeleteDevice()
{
// Implement device deletion logic
- NotificationHelper.ShowInfo("删除设备功能待实现。");
+ //NotificationHelper.ShowInfo("删除设备功能待实现。");
await Task.CompletedTask;
}
diff --git a/DMS.WPF/ViewModels/DevicesViewModel.cs b/DMS.WPF/ViewModels/DevicesViewModel.cs
index 90dcf1c..a404985 100644
--- a/DMS.WPF/ViewModels/DevicesViewModel.cs
+++ b/DMS.WPF/ViewModels/DevicesViewModel.cs
@@ -4,13 +4,16 @@ using CommunityToolkit.Mvvm.Input;
using DMS.Data.Repositories;
using DMS.Core.Enums;
using DMS.Helper;
-using DMS.Models;
+using DMS.WPF.Models;
using DMS.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using DMS.Data;
+using DMS.WPF.Services;
+using DMS.Infrastructure.Repositories;
+using DMS.WPF.Models;
-namespace DMS.ViewModels;
+namespace DMS.WPF.ViewModels;
///
/// 设备管理视图模型,负责设备的增删改查操作。
diff --git a/DMS.WPF/ViewModels/Dialogs/ConfrimDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/ConfrimDialogViewModel.cs
index ac4760f..41e3a74 100644
--- a/DMS.WPF/ViewModels/Dialogs/ConfrimDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/ConfrimDialogViewModel.cs
@@ -1,6 +1,6 @@
using CommunityToolkit.Mvvm.ComponentModel;
-namespace DMS.ViewModels.Dialogs;
+namespace DMS.WPF.ViewModels.Dialogs;
public partial class ConfrimDialogViewModel : ObservableObject
{
diff --git a/DMS.WPF/ViewModels/Dialogs/ImportExcelDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/ImportExcelDialogViewModel.cs
index 2e23fb5..2496709 100644
--- a/DMS.WPF/ViewModels/Dialogs/ImportExcelDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/ImportExcelDialogViewModel.cs
@@ -1,9 +1,10 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using DMS.Helper;
-using DMS.Models;
+using DMS.WPF.Models;
+using DMS.WPF.Models;
-namespace DMS.ViewModels.Dialogs;
+namespace DMS.WPF.ViewModels.Dialogs;
public partial class ImportExcelDialogViewModel : ObservableObject
{
diff --git a/DMS.WPF/ViewModels/Dialogs/ImportResultDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/ImportResultDialogViewModel.cs
index 2490e21..083c18e 100644
--- a/DMS.WPF/ViewModels/Dialogs/ImportResultDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/ImportResultDialogViewModel.cs
@@ -1,9 +1,9 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
-using DMS.Models;
+using DMS.WPF.Models;
-namespace DMS.ViewModels.Dialogs;
+namespace DMS.WPF.ViewModels.Dialogs;
///
/// ImportResultDialogViewModel 是用于显示变量导入结果的视图模型。
diff --git a/DMS.WPF/ViewModels/Dialogs/IsActiveDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/IsActiveDialogViewModel.cs
index a3a2401..ef91229 100644
--- a/DMS.WPF/ViewModels/Dialogs/IsActiveDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/IsActiveDialogViewModel.cs
@@ -2,7 +2,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using DMS.Core.Enums;
-namespace DMS.ViewModels.Dialogs;
+namespace DMS.WPF.ViewModels.Dialogs;
public partial class IsActiveDialogViewModel : ObservableObject
{
diff --git a/DMS.WPF/ViewModels/Dialogs/MqttAliasBatchEditDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/MqttAliasBatchEditDialogViewModel.cs
index 0439e69..e751a04 100644
--- a/DMS.WPF/ViewModels/Dialogs/MqttAliasBatchEditDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/MqttAliasBatchEditDialogViewModel.cs
@@ -3,9 +3,10 @@ using CommunityToolkit.Mvvm.Input;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Linq;
-using DMS.Models;
+using DMS.WPF.Models;
+using DMS.WPF.Models;
-namespace DMS.ViewModels.Dialogs;
+namespace DMS.WPF.ViewModels.Dialogs;
public partial class MqttAliasBatchEditDialogViewModel : ObservableObject
{
diff --git a/DMS.WPF/ViewModels/Dialogs/MqttAliasDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/MqttAliasDialogViewModel.cs
index f048d8d..e641367 100644
--- a/DMS.WPF/ViewModels/Dialogs/MqttAliasDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/MqttAliasDialogViewModel.cs
@@ -1,7 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
-namespace DMS.ViewModels.Dialogs;
+namespace DMS.WPF.ViewModels.Dialogs;
public partial class MqttAliasDialogViewModel : ObservableObject
{
diff --git a/DMS.WPF/ViewModels/Dialogs/MqttDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/MqttDialogViewModel.cs
index ca772b0..d4d1eb4 100644
--- a/DMS.WPF/ViewModels/Dialogs/MqttDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/MqttDialogViewModel.cs
@@ -1,8 +1,9 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
-using DMS.Models;
+using DMS.WPF.Models;
+using DMS.WPF.Models;
-namespace DMS.ViewModels.Dialogs;
+namespace DMS.WPF.ViewModels.Dialogs;
public partial class MqttDialogViewModel : ObservableObject
{
diff --git a/DMS.WPF/ViewModels/Dialogs/MqttSelectionDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/MqttSelectionDialogViewModel.cs
index 1ca9d1a..7ca9367 100644
--- a/DMS.WPF/ViewModels/Dialogs/MqttSelectionDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/MqttSelectionDialogViewModel.cs
@@ -2,10 +2,12 @@ using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using DMS.Data.Repositories;
using System.Threading.Tasks;
-using DMS.Models;
+using DMS.WPF.Models;
using DMS.Services;
+using DMS.WPF.Services;
+using DMS.WPF.Models;
-namespace DMS.ViewModels.Dialogs;
+namespace DMS.WPF.ViewModels.Dialogs;
public partial class MqttSelectionDialogViewModel : ObservableObject
{
diff --git a/DMS.WPF/ViewModels/Dialogs/OpcUaImportDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/OpcUaImportDialogViewModel.cs
index b3a857b..dc46e9e 100644
--- a/DMS.WPF/ViewModels/Dialogs/OpcUaImportDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/OpcUaImportDialogViewModel.cs
@@ -5,12 +5,13 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using DMS.Core.Enums;
using DMS.Helper;
-using DMS.Models;
+using DMS.WPF.Models;
+using DMS.WPF.Models;
using Opc.Ua;
using Opc.Ua.Client;
using Opc.Ua.Configuration;
-namespace DMS.ViewModels.Dialogs;
+namespace DMS.WPF.ViewModels.Dialogs;
public partial class OpcUaImportDialogViewModel : ObservableObject
{
diff --git a/DMS.WPF/ViewModels/Dialogs/OpcUaUpdateTypeDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/OpcUaUpdateTypeDialogViewModel.cs
index 2d23daf..03cbee6 100644
--- a/DMS.WPF/ViewModels/Dialogs/OpcUaUpdateTypeDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/OpcUaUpdateTypeDialogViewModel.cs
@@ -1,7 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using DMS.Core.Enums;
-namespace DMS.ViewModels.Dialogs
+namespace DMS.WPF.ViewModels.Dialogs
{
public partial class OpcUaUpdateTypeDialogViewModel : ObservableObject
{
diff --git a/DMS.WPF/ViewModels/Dialogs/PollLevelDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/PollLevelDialogViewModel.cs
index bd1825a..327793c 100644
--- a/DMS.WPF/ViewModels/Dialogs/PollLevelDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/PollLevelDialogViewModel.cs
@@ -4,7 +4,7 @@ using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using DMS.Core.Enums;
-namespace DMS.ViewModels.Dialogs
+namespace DMS.WPF.ViewModels.Dialogs
{
public partial class PollLevelDialogViewModel : ObservableObject
{
diff --git a/DMS.WPF/ViewModels/Dialogs/ProcessingDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/ProcessingDialogViewModel.cs
index d6d0bf7..aef7020 100644
--- a/DMS.WPF/ViewModels/Dialogs/ProcessingDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/ProcessingDialogViewModel.cs
@@ -1,6 +1,6 @@
using CommunityToolkit.Mvvm.ComponentModel;
-namespace DMS.ViewModels.Dialogs;
+namespace DMS.WPF.ViewModels.Dialogs;
public partial class ProcessingDialogViewModel : ObservableObject
{
diff --git a/DMS.WPF/ViewModels/Dialogs/VarDataDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/VarDataDialogViewModel.cs
index 874feb1..ac7f4af 100644
--- a/DMS.WPF/ViewModels/Dialogs/VarDataDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/VarDataDialogViewModel.cs
@@ -1,7 +1,8 @@
using CommunityToolkit.Mvvm.ComponentModel;
-using DMS.Models;
+using DMS.WPF.Models;
+using DMS.WPF.Models;
-namespace DMS.ViewModels.Dialogs;
+namespace DMS.WPF.ViewModels.Dialogs;
public partial class VarDataDialogViewModel : ObservableObject
{
diff --git a/DMS.WPF/ViewModels/Dialogs/VarTableDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/VarTableDialogViewModel.cs
index 4c32695..cb0af4e 100644
--- a/DMS.WPF/ViewModels/Dialogs/VarTableDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/VarTableDialogViewModel.cs
@@ -1,7 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
-using DMS.Models;
+using DMS.WPF.Models;
-namespace DMS.ViewModels.Dialogs;
+namespace DMS.WPF.ViewModels.Dialogs;
public partial class VarTableDialogViewModel:ObservableObject
{
diff --git a/DMS.WPF/ViewModels/HomeViewModel.cs b/DMS.WPF/ViewModels/HomeViewModel.cs
index b9ddf31..505d0d6 100644
--- a/DMS.WPF/ViewModels/HomeViewModel.cs
+++ b/DMS.WPF/ViewModels/HomeViewModel.cs
@@ -1,4 +1,4 @@
-namespace DMS.ViewModels;
+namespace DMS.WPF.ViewModels;
public class HomeViewModel : ViewModelBase
{
diff --git a/DMS.WPF/ViewModels/MainViewModel.cs b/DMS.WPF/ViewModels/MainViewModel.cs
index 3084612..4cac95b 100644
--- a/DMS.WPF/ViewModels/MainViewModel.cs
+++ b/DMS.WPF/ViewModels/MainViewModel.cs
@@ -17,7 +17,7 @@ using Microsoft.Extensions.Logging;
// AddAsync this using directive
// AddAsync this using directive
-namespace DMS.ViewModels;
+namespace DMS.WPF.ViewModels;
///
/// 主视图模型,负责应用程序的主导航和数据管理。
diff --git a/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs b/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs
index 78ee2af..f960b73 100644
--- a/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs
+++ b/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
using System.Collections.Generic;
using DMS.Data.Repositories;
using DMS.Helper;
-using DMS.Models;
+using DMS.WPF.Models;
using DMS.Services;
namespace DMS.ViewModels
diff --git a/DMS.WPF/ViewModels/MqttsViewModel.cs b/DMS.WPF/ViewModels/MqttsViewModel.cs
index b5203c0..b69cb94 100644
--- a/DMS.WPF/ViewModels/MqttsViewModel.cs
+++ b/DMS.WPF/ViewModels/MqttsViewModel.cs
@@ -4,13 +4,13 @@ using CommunityToolkit.Mvvm.Input;
using DMS.Data.Repositories;
using DMS.Core.Enums;
using DMS.Helper;
-using DMS.Models;
+using DMS.WPF.Models;
using DMS.Services;
using Microsoft.Extensions.Logging;
using DMS.Data;
-using DMS.Views;
+using DMS.WPF.Views;
-namespace DMS.ViewModels;
+namespace DMS.WPF.ViewModels;
public partial class MqttsViewModel : ViewModelBase
{
diff --git a/DMS.WPF/ViewModels/SettingViewModel.cs b/DMS.WPF/ViewModels/SettingViewModel.cs
index 41b8cd2..a6a9c16 100644
--- a/DMS.WPF/ViewModels/SettingViewModel.cs
+++ b/DMS.WPF/ViewModels/SettingViewModel.cs
@@ -9,7 +9,7 @@ using DMS.Data;
using DMS.Helper;
using DMS.Services;
-namespace DMS.ViewModels;
+namespace DMS.WPF.ViewModels;
public partial class SettingViewModel : ViewModelBase
{
diff --git a/DMS.WPF/ViewModels/VariableTableViewModel.cs b/DMS.WPF/ViewModels/VariableTableViewModel.cs
index b566637..658bc2c 100644
--- a/DMS.WPF/ViewModels/VariableTableViewModel.cs
+++ b/DMS.WPF/ViewModels/VariableTableViewModel.cs
@@ -8,14 +8,14 @@ using CommunityToolkit.Mvvm.Input;
using DMS.Data.Repositories;
using DMS.Core.Enums;
using DMS.Helper;
-using DMS.Models;
+using DMS.WPF.Models;
using DMS.Services;
using iNKORE.UI.WPF.Modern.Controls;
using Newtonsoft.Json;
using DMS.Extensions;
using SqlSugar;
-namespace DMS.ViewModels;
+namespace DMS.WPF.ViewModels;
///
/// VariableTableViewModel 是用于管理和显示变量表数据的视图模型。
diff --git a/DMS.WPF/ViewModels/ViewModelBase.cs b/DMS.WPF/ViewModels/ViewModelBase.cs
index 55b2648..f512c5f 100644
--- a/DMS.WPF/ViewModels/ViewModelBase.cs
+++ b/DMS.WPF/ViewModels/ViewModelBase.cs
@@ -1,6 +1,6 @@
using CommunityToolkit.Mvvm.ComponentModel;
-namespace DMS.ViewModels;
+namespace DMS.WPF.ViewModels;
public abstract class ViewModelBase : ObservableObject
{
diff --git a/DMS.WPF/Views/DataTransformView.xaml b/DMS.WPF/Views/DataTransformView.xaml
index 2e424e2..b26d950 100644
--- a/DMS.WPF/Views/DataTransformView.xaml
+++ b/DMS.WPF/Views/DataTransformView.xaml
@@ -1,4 +1,4 @@
-