Browse Source

用户管理

Linsk 3 months ago
parent
commit
b4c47756c8
37 changed files with 1056 additions and 9 deletions
  1. 13 0
      BLL/Dto/AuthDto/QueryAuthDto.cs
  2. 19 0
      BLL/Dto/AuthDto/QueryAuthResultDto.cs
  3. 20 0
      BLL/Dto/AuthDto/UpdateAuthDto.cs
  4. 13 0
      BLL/Dto/BaseDto.cs
  5. 31 0
      BLL/Dto/DataDto/AddDataDto.cs
  6. 14 0
      BLL/Dto/DataDto/QueryDataDto.cs
  7. 31 0
      BLL/Dto/DataDto/QueryDataResultDto.cs
  8. 40 0
      BLL/Dto/RecipeDto/AddRecipeDto.cs
  9. 12 0
      BLL/Dto/RecipeDto/DelRecipeDto.cs
  10. 12 0
      BLL/Dto/RecipeDto/GetRecipeByIdDto.cs
  11. 13 0
      BLL/Dto/RecipeDto/QueryRecipeDto.cs
  12. 40 0
      BLL/Dto/RecipeDto/QueryRecipeResultDto.cs
  13. 40 0
      BLL/Dto/RecipeDto/UpdateRecipeDto.cs
  14. 13 0
      BLL/Dto/UserDto/QueryUserAuthDto.cs
  15. 15 0
      BLL/Dto/UserDto/QueryUserDto.cs
  16. 15 0
      BLL/Dto/UserDto/UserAddDto.cs
  17. 12 0
      BLL/Dto/UserDto/UserDeleteDto.cs
  18. 13 0
      BLL/Dto/UserDto/UserExistDto.cs
  19. 14 0
      BLL/Dto/UserDto/UserLoginDto.cs
  20. 15 0
      BLL/Dto/UserDto/UserUpdateDto.cs
  21. 43 0
      BLL/Manager/AuthManager.cs
  22. 45 0
      BLL/Manager/DataManager.cs
  23. 89 0
      BLL/Manager/RecipeManager.cs
  24. 213 0
      BLL/Manager/UserManager.cs
  25. 14 0
      DAL/Services/AuthService.cs
  26. 0 0
      DAL/Services/BaseService.cs
  27. 14 0
      DAL/Services/DataService.cs
  28. 14 0
      DAL/Services/RecipeService.cs
  29. 32 0
      DAL/Services/UserService.cs
  30. 21 0
      Helper/BaseResult.cs
  31. 6 0
      Helper/SystemEnums.cs
  32. 6 0
      Scada/Extensions/UIExtension.cs
  33. 1 0
      Scada/Page/PageTotalEquipmentControl.cs
  34. 8 0
      Scada/Page/PageUserManage.Designer.cs
  35. 149 3
      Scada/Page/PageUserManage.cs
  36. 5 5
      Scada/Program.cs
  37. 1 1
      Scada/appsettings.json

+ 13 - 0
BLL/Dto/AuthDto/QueryAuthDto.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto.AuthDto
+{
+    public class QueryAuthDto : BaseDto
+    {
+        public string Role { get; set; }
+    }
+}

+ 19 - 0
BLL/Dto/AuthDto/QueryAuthResultDto.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto.AuthDto
+{
+    public class QueryAuthResultDto : BaseDto
+    {
+        public bool ControlModule { get; set; }
+        public bool MonitorModule { get; set; }
+        public bool RecipeModule { get; set; }
+        public bool LogModule { get; set; }
+        public bool ReportModule { get; set; }
+        public bool ChartModule { get; set; }
+        public bool ParamModule { get; set; }
+    }
+}

+ 20 - 0
BLL/Dto/AuthDto/UpdateAuthDto.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto.AuthDto
+{
+    public class UpdateAuthDto : BaseDto
+    {
+        public string Role { get; set; }
+        public bool ControlModule { get; set; }
+        public bool MonitorModule { get; set; }
+        public bool RecipeModule { get; set; }
+        public bool LogModule { get; set; }
+        public bool ReportModule { get; set; }
+        public bool ChartModule { get; set; }
+        public bool ParamModule { get; set; }
+    }
+}

+ 13 - 0
BLL/Dto/BaseDto.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL
+{
+    public class BaseDto
+    {
+        public int Id { get; set; }
+    }
+}

+ 31 - 0
BLL/Dto/DataDto/AddDataDto.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto.DataDto
+{
+    public class AddDataDto : BaseDto
+    {
+        public DateTime InsertTime { get; set; }
+        public string 脱脂喷淋泵压力值 { get; set; }
+
+        public string 脱脂pH值 { get; set; }
+        public string 陶化pH值 { get; set; }
+
+        public string 粗洗喷淋泵压力值 { get; set; }
+
+        public string 陶化喷淋泵压力值 { get; set; }
+
+        public string 精洗喷淋泵压力值 { get; set; }
+
+        public string 水分炉测量温度 { get; set; }
+
+        public string 固化炉测量温度 { get; set; }
+
+        public string 厂内温度 { get; set; }
+
+        public string 厂内湿度 { get; set; }
+    }
+}

+ 14 - 0
BLL/Dto/DataDto/QueryDataDto.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto.DataDto
+{
+    public class QueryDataDto : BaseDto
+    {
+        public DateTime StartTime { get; set; }
+        public DateTime EndTime { get; set; }
+    }
+}

+ 31 - 0
BLL/Dto/DataDto/QueryDataResultDto.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto.DataDto
+{
+    public class QueryDataResultDto : BaseDto
+    {
+        public DateTime InsertTime { get; set; }
+        public string 脱脂喷淋泵压力值 { get; set; }
+
+        public string 脱脂pH值 { get; set; }
+        public string 陶化pH值 { get; set; }
+
+        public string 粗洗喷淋泵压力值 { get; set; }
+
+        public string 陶化喷淋泵压力值 { get; set; }
+
+        public string 精洗喷淋泵压力值 { get; set; }
+
+        public string 水分炉测量温度 { get; set; }
+
+        public string 固化炉测量温度 { get; set; }
+
+        public string 厂内温度 { get; set; }
+
+        public string 厂内湿度 { get; set; }
+    }
+}

+ 40 - 0
BLL/Dto/RecipeDto/AddRecipeDto.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto.RecipeDto
+{
+    public class AddRecipeDto : BaseDto
+    {
+        public string 产品类型 { get; set; } = string.Empty;
+        public string 脱脂设定压力上限值 { get; set; } = string.Empty;
+
+        public string 脱脂设定压力下限值 { get; set; } = string.Empty;
+
+        public string 粗洗喷淋泵过载上限值 { get; set; } = string.Empty;
+
+        public string 粗洗液位下限值 { get; set; } = string.Empty;
+
+        public string 陶化喷淋泵过载上限值 { get; set; } = string.Empty;
+
+        public string 精洗喷淋泵过载上限值 { get; set; } = string.Empty;
+
+        public string 精洗液位下限值 { get; set; } = string.Empty;
+
+        public string 水分炉温度上限值 { get; set; } = string.Empty;
+
+        public string 水分炉温度下限值 { get; set; } = string.Empty;
+
+        public string 冷却室离心风机过载上限值 { get; set; } = string.Empty;
+
+        public string 固化炉温度上限值 { get; set; } = string.Empty;
+
+        public string 固化炉温度下限值 { get; set; } = string.Empty;
+
+        public string 输送机设定速度 { get; set; } = string.Empty;
+
+        public string 输送机设定频率 { get; set; } = string.Empty;
+    }
+}

+ 12 - 0
BLL/Dto/RecipeDto/DelRecipeDto.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto.RecipeDto
+{
+    public class DelRecipeDto
+    {
+    }
+}

+ 12 - 0
BLL/Dto/RecipeDto/GetRecipeByIdDto.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto.RecipeDto
+{
+    public class GetRecipeByIdDto:BaseDto
+    {
+    }
+}

+ 13 - 0
BLL/Dto/RecipeDto/QueryRecipeDto.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto.RecipeDto
+{
+    public class QueryRecipeDto : BaseDto
+    {
+        public string 产品类型 { get; set; } = string.Empty;
+    }
+}

+ 40 - 0
BLL/Dto/RecipeDto/QueryRecipeResultDto.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto.RecipeDto
+{
+    public class QueryRecipeResultDto : BaseDto
+    {
+        public string 产品类型 { get; set; } = string.Empty;
+        public string 脱脂设定压力上限值 { get; set; } = string.Empty;
+
+        public string 脱脂设定压力下限值 { get; set; } = string.Empty;
+
+        public string 粗洗喷淋泵过载上限值 { get; set; } = string.Empty;
+
+        public string 粗洗液位下限值 { get; set; } = string.Empty;
+
+        public string 陶化喷淋泵过载上限值 { get; set; } = string.Empty;
+
+        public string 精洗喷淋泵过载上限值 { get; set; } = string.Empty;
+
+        public string 精洗液位下限值 { get; set; } = string.Empty;
+
+        public string 水分炉温度上限值 { get; set; } = string.Empty;
+
+        public string 水分炉温度下限值 { get; set; } = string.Empty;
+
+        public string 冷却室离心风机过载上限值 { get; set; } = string.Empty;
+
+        public string 固化炉温度上限值 { get; set; } = string.Empty;
+
+        public string 固化炉温度下限值 { get; set; } = string.Empty;
+
+        public string 输送机设定速度 { get; set; } = string.Empty;
+
+        public string 输送机设定频率 { get; set; } = string.Empty;
+    }
+}

+ 40 - 0
BLL/Dto/RecipeDto/UpdateRecipeDto.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto.RecipeDto
+{
+    public class UpdateRecipeDto : BaseDto
+    {
+        public string 产品类型 { get; set; } = string.Empty;
+        public string 脱脂设定压力上限值 { get; set; } = string.Empty;
+
+        public string 脱脂设定压力下限值 { get; set; } = string.Empty;
+
+        public string 粗洗喷淋泵过载上限值 { get; set; } = string.Empty;
+
+        public string 粗洗液位下限值 { get; set; } = string.Empty;
+
+        public string 陶化喷淋泵过载上限值 { get; set; } = string.Empty;
+
+        public string 精洗喷淋泵过载上限值 { get; set; } = string.Empty;
+
+        public string 精洗液位下限值 { get; set; } = string.Empty;
+
+        public string 水分炉温度上限值 { get; set; } = string.Empty;
+
+        public string 水分炉温度下限值 { get; set; } = string.Empty;
+
+        public string 冷却室离心风机过载上限值 { get; set; } = string.Empty;
+
+        public string 固化炉温度上限值 { get; set; } = string.Empty;
+
+        public string 固化炉温度下限值 { get; set; } = string.Empty;
+
+        public string 输送机设定速度 { get; set; } = string.Empty;
+
+        public string 输送机设定频率 { get; set; } = string.Empty;
+    }
+}

+ 13 - 0
BLL/Dto/UserDto/QueryUserAuthDto.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto
+{
+    public class QueryUserAuthDto
+    {
+        public string UserName { get; set; }
+    }
+}

+ 15 - 0
BLL/Dto/UserDto/QueryUserDto.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto
+{
+    public class QueryUserDto : BaseDto
+    {
+        public string UserName { get; set; }
+        public string UserPassword { get; set; }
+        public string Role { get; set; }
+    }
+}

+ 15 - 0
BLL/Dto/UserDto/UserAddDto.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL
+{
+    public class UserAddDto:BaseDto
+    {
+        public string UserName { get; set; }
+        public string UserPassword { get; set; }
+        public string Role { get; set; }
+    }
+}

+ 12 - 0
BLL/Dto/UserDto/UserDeleteDto.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto
+{
+    public class UserDeleteDto:BaseDto
+    {
+    }
+}

+ 13 - 0
BLL/Dto/UserDto/UserExistDto.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL
+{
+    public class UserExistDto
+    {
+        public string UserName { get; set; }
+    }
+}

+ 14 - 0
BLL/Dto/UserDto/UserLoginDto.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL
+{
+    public class UserLoginDto
+    {
+        public string UserName { get; set; }
+        public string UserPassword { get; set; }
+    }
+}

+ 15 - 0
BLL/Dto/UserDto/UserUpdateDto.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto
+{
+    public class UserUpdateDto:BaseDto
+    {
+        public string UserName { get; set; }
+        public string UserPassword { get; set; }
+        public string Role { get; set; }
+    }
+}

+ 43 - 0
BLL/Manager/AuthManager.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BLL.Dto.AuthDto;
+using DAL.Services;
+using Helper;
+using Mapster;
+using Model;
+
+namespace BLL.Manager
+{
+    public class AuthManager
+    {
+        private readonly AuthService _authService;
+        public AuthManager(AuthService authService)
+        {
+            _authService = authService;
+        }
+
+        public async Task<BaseResult> UpdateAuthAsync(UpdateAuthDto request)
+        {
+            var entity = request.Adapt<AuthEntity>();
+
+            var res = await _authService.UpdateAsync(entity);
+
+            if (res)
+            {
+                return new BaseResult() { Result = SystemEnums.Result.Success };
+            }
+            return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "更新权限失败" };
+        }
+
+        public async Task<BaseResult<QueryAuthResultDto>> GetAuthAsync(QueryAuthDto request)
+        {
+            var res = await _authService.GetByOneAsync(c => c.Role == request.Role);
+
+            return new BaseResult<QueryAuthResultDto>() { Result = SystemEnums.Result.Success, Data = new List<QueryAuthResultDto>() { res.Adapt<QueryAuthResultDto>() } };
+
+        }
+    }
+}

+ 45 - 0
BLL/Manager/DataManager.cs

@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BLL.Dto.DataDto;
+using DAL.Services;
+using Helper;
+using HZY.Framework.DependencyInjection;
+using Mapster;
+using Model;
+using SqlSugar;
+
+namespace BLL.Manager
+{
+    public class DataManager:IScopedSelfDependency
+    {
+        private readonly DataService _dataService;
+        public DataManager(DataService dataService)
+        {
+            _dataService = dataService;
+        }
+
+        public async Task<BaseResult> AddDataAsync(AddDataDto request)
+        {
+            var entity = request.Adapt<DataEntity>();
+            var res = await _dataService.InsertAsync(entity);
+
+            if (res > 0)
+            {
+                return new BaseResult() { Result = SystemEnums.Result.Success };
+            }
+
+            return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "添加数据失败" };
+        }
+
+        public async Task<BaseResult<QueryDataResultDto>> GetDataListByTimeAsync(QueryDataDto request)
+        {
+            var res = await _dataService.GetListAsync(c => SqlFunc.Between(c.InsertTime, request.StartTime, request.EndTime));
+
+            return new BaseResult<QueryDataResultDto>() { Result = SystemEnums.Result.Success, Data = res.Adapt<List<QueryDataResultDto>>() };
+
+        }
+    }
+}

+ 89 - 0
BLL/Manager/RecipeManager.cs

@@ -0,0 +1,89 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BLL.Dto.RecipeDto;
+using DAL.Services;
+using Helper;
+using HZY.Framework.DependencyInjection;
+using Mapster;
+using Model;
+
+namespace BLL.Manager
+{
+    internal class RecipeManager:IScopedSelfDependency
+    {
+        private readonly RecipeService _recipeService;
+        public RecipeManager(RecipeService recipeService)
+        {
+            _recipeService = recipeService;
+        }
+
+        public async Task<BaseResult> AddRecipeAsync(AddRecipeDto request)
+        {
+
+            var isExist = await _recipeService.ExistAsync(e => e.产品类型 == request.产品类型);
+            if (isExist)
+            {
+                return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "产品类型已存在" };
+
+            }
+
+            var entity = request.Adapt<RecipeEntity>();
+            var res = await _recipeService.InsertAsync(entity);
+            if (res > 0)
+            {
+                return new BaseResult() { Result = SystemEnums.Result.Success };
+            }
+            return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "添加失败" };
+        }
+
+
+        public async Task<BaseResult> UpdateRecipeAsync(UpdateRecipeDto request)
+        {
+            var isExsit = await _recipeService.ExistAsync(c => c.产品类型 == request.产品类型 && c.Id != request.Id);
+            if (isExsit)
+            {
+                return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "修改的产品类型已存在" };
+            }
+            var entity = request.Adapt<RecipeEntity>();
+            var res = await _recipeService.UpdateAsync(entity);
+            if (res)
+            {
+                return new BaseResult() { Result = SystemEnums.Result.Success };
+            }
+            return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "更新失败" };
+        }
+        public async Task<BaseResult> DeleteRecipeAsync(DelRecipeDto request)
+        {
+            var entity = request.Adapt<RecipeEntity>();
+            var res = await _recipeService.DeleteAsync(entity);
+            if (res)
+            {
+                return new BaseResult() { Result = SystemEnums.Result.Success };
+            }
+            return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "删除失败" };
+        }
+
+        public async Task<BaseResult<QueryRecipeResultDto>> GetRecipeListAsync()
+        {
+
+            var res = await _recipeService.GetListAsync(c => true);
+
+            var dtos = res.Adapt<List<QueryRecipeResultDto>>();
+
+            return new BaseResult<QueryRecipeResultDto>() { Result = SystemEnums.Result.Success, Data = dtos };
+        }
+
+        public async Task<BaseResult<QueryRecipeResultDto>> GetRecipeAsyncById(GetRecipeByIdDto request)
+        {
+            var res = await _recipeService.GetByOneAsync(c => c.Id == request.Id);
+
+            var dtos = res.Adapt<QueryRecipeResultDto>();
+
+            return new BaseResult<QueryRecipeResultDto>() { Result = SystemEnums.Result.Success, Data = new List<QueryRecipeResultDto>() { dtos } };
+        }
+
+    }
+}

+ 213 - 0
BLL/Manager/UserManager.cs

@@ -0,0 +1,213 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BLL.Dto;
+using DAL;
+using Helper;
+using HZY.Framework.DependencyInjection;
+using Mapster;
+using Model;
+using SqlSugar;
+
+namespace BLL
+{
+    public class UserManager : IScopedSelfDependency
+    {
+        private readonly UserService _userService;
+
+        public UserManager(UserService userService)
+        {
+            _userService = userService;
+        }
+
+        public async Task<BaseResult<UserEntity>> LoginAsync(UserLoginDto request)
+        {
+            if (request == null || string.IsNullOrEmpty(request.UserName) || string.IsNullOrEmpty(request.UserPassword))
+            {
+                return new BaseResult<UserEntity>
+                {
+                    Result = SystemEnums.Result.Fail,
+                    Msg = "用户名或密码不能为空"
+                };
+            }
+
+            var entity = request.Adapt<UserEntity>();
+            var result = await _userService.LoginAsync(entity);
+
+            if (result.Result == SystemEnums.Result.Fail)
+            {
+                return new BaseResult<UserEntity>
+                {
+                    Result = SystemEnums.Result.Fail,
+                    Msg = result.Msg
+                };
+            }
+            return result;
+        }
+
+        public async Task<BaseResult<UserEntity>> IsUserExistAsync(UserExistDto request)
+        {
+            var entity = request.Adapt<UserEntity>();
+            var result = await _userService.ExistAsync(u => u.UserName == entity.UserName);
+
+            if (!result)
+            {
+                return new BaseResult<UserEntity>
+                {
+                    Result = SystemEnums.Result.Fail,
+                    Msg = $"{entity.UserName}不存在"
+                };
+            }
+            return new BaseResult<UserEntity>
+            {
+                Result = SystemEnums.Result.Success,
+                Msg = $"{entity.UserName}已存在"
+            };
+        }
+
+        public async Task<BaseResult<UserEntity>> AddUserAsync(UserAddDto request)
+        {
+            if (request == null || string.IsNullOrEmpty(request.UserName) || string.IsNullOrEmpty(request.UserPassword))
+            {
+                return new BaseResult<UserEntity>
+                {
+                    Result = SystemEnums.Result.Fail,
+                    Msg = "用户名或密码不能为空"
+                };
+            }
+
+            var isExist = await IsUserExistAsync(new UserExistDto { UserName = request.UserName });
+            if (isExist.Result==SystemEnums.Result.Success)
+            {
+                return new BaseResult<UserEntity>
+                {
+                    Result = SystemEnums.Result.Fail,
+                    Msg = $"{request.UserName}已存在"
+                };
+            }
+
+            var entity = request.Adapt<UserEntity>();
+            var result = await _userService.InsertAsync(entity);
+            if (result <= 0)
+            {
+                return new BaseResult<UserEntity>
+                {
+                    Result = SystemEnums.Result.Fail,
+                    Msg = $"添加{entity.UserName}失败"
+                };
+            }
+            return new BaseResult<UserEntity>
+            {
+                Result = SystemEnums.Result.Success,
+                Msg = $"添加{entity.UserName}成功",
+                Data = new List<UserEntity> { entity }
+            };
+        }
+
+        public async Task<BaseResult<UserEntity>> UpdateUserAsync(UserUpdateDto request)
+        {
+            var isExist = await _userService.ExistAsync(u => u.UserName == request.UserName&&u.Id!=request.Id);
+            if (isExist)
+            {
+                return new BaseResult<UserEntity>
+                {
+                    Result = SystemEnums.Result.Fail,
+                    Msg = $"{request.UserName}已存在"
+                };
+            }
+            
+            if (request == null || string.IsNullOrEmpty(request .UserName) || string.IsNullOrEmpty(request.UserPassword))
+            {
+                return new BaseResult<UserEntity>
+                {
+                    Result = SystemEnums.Result.Fail,
+                    Msg = "用户名或密码不能为空"
+                };
+            }
+            var entity = request.Adapt<UserEntity>();
+            var result = await _userService.UpdateAsync(entity);
+            if (!result)
+            {
+                return new BaseResult<UserEntity>
+                {
+                    Result = SystemEnums.Result.Fail,
+                    Msg = $"更新{entity.UserName}失败"
+                };
+            }
+            return new BaseResult<UserEntity>
+            {
+                Result = SystemEnums.Result.Success,
+                Msg = $"更新{entity.UserName}成功",
+                Data = new List<UserEntity> { entity }
+            };
+        }
+
+        public async Task<BaseResult<UserEntity>> DeleteUserAsync(UserDeleteDto request)
+        {
+            if (request == null )
+            {
+                return new BaseResult<UserEntity>
+                {
+                    Result = SystemEnums.Result.Fail,
+                    Msg = "用户不能为空"
+                };
+            }
+            var entity = request.Adapt<UserEntity>();
+            var result = await _userService.DeleteAsync(entity);
+            if (!result)
+            {
+                return new BaseResult<UserEntity>
+                {
+                    Result = SystemEnums.Result.Fail,
+                    Msg = $"删除{entity.UserName}失败"
+                };
+            }
+            return new BaseResult<UserEntity>
+            {
+                Result = SystemEnums.Result.Success,
+                Msg = $"删除{entity.UserName}成功",
+                Data = new List<UserEntity> { entity }
+            };
+        }
+
+        public async Task<BaseResult<UserEntity>> GetUserListAsync()
+        {
+            var result = new BaseResult<UserEntity>();
+            var users = await _userService.GetListAsync(u => true);
+            if (users == null || !users.Any())
+            {
+                result.Result = SystemEnums.Result.Fail;
+                result.Msg = "没有用户信息";
+            }
+            else
+            {
+                result.Result = SystemEnums.Result.Success;
+                result.Data = users;
+            }
+            return result;
+        }
+
+        public async Task<BaseResult<UserEntity>> GetUserAuthAsync(QueryUserAuthDto request)
+        {
+            var isExist = await IsUserExistAsync(new UserExistDto { UserName = request.UserName });
+            if(isExist.Result == SystemEnums.Result.Fail)
+            {
+                return new BaseResult<UserEntity>
+                {
+                    Result = SystemEnums.Result.Fail,
+                    Msg = "用户不存在"
+                };
+            }
+            var result = await _userService.GetByOneAsync(u => u.UserName == request.UserName);
+
+            return new BaseResult<UserEntity>
+            {
+                Result = SystemEnums.Result.Success,
+                Msg = "用户存在",
+                Data = new List<UserEntity> { result }
+            };
+        }
+    }
+}

+ 14 - 0
DAL/Services/AuthService.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using HZY.Framework.DependencyInjection;
+using Model;
+
+namespace DAL.Services
+{
+    public class AuthService : BaseService<AuthEntity>, IScopedSelfDependency
+    {
+    }
+}

+ 0 - 0
DAL/BaseService.cs → DAL/Services/BaseService.cs


+ 14 - 0
DAL/Services/DataService.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using HZY.Framework.DependencyInjection;
+using Model;
+
+namespace DAL.Services
+{
+    public class DataService : BaseService<DataEntity>, IScopedSelfDependency
+    {
+    }
+}

+ 14 - 0
DAL/Services/RecipeService.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using HZY.Framework.DependencyInjection;
+using Model;
+
+namespace DAL.Services
+{
+    public class RecipeService : BaseService<RecipeEntity>, IScopedSelfDependency
+    {
+    }
+}

+ 32 - 0
DAL/Services/UserService.cs

@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Helper;
+using HZY.Framework.DependencyInjection;
+using Model;
+
+namespace DAL
+{
+    public class UserService:BaseService<UserEntity>,IScopedSelfDependency
+    {
+        public async Task<BaseResult<UserEntity>> LoginAsync(UserEntity userEntity)
+        {
+            var result = new BaseResult<UserEntity>();
+            var user = await DB.SqlSugarClient.Queryable<UserEntity>()
+                .Where(u => u.UserName == userEntity.UserName && u.UserPassword == userEntity.UserPassword)
+                .FirstAsync();
+            if (user == null)
+            {
+                result.Result = SystemEnums.Result.Fail;
+                result.Msg = "用户名或密码错误";
+            }
+            else
+            {
+                result.Data = new List<UserEntity> { user };
+            }
+            return result;
+        }
+    }
+}

+ 21 - 0
Helper/BaseResult.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Helper
+{
+    public class BaseResult
+    {
+        public SystemEnums.Result Result { get; set; } = SystemEnums.Result.Success;
+
+        public string Msg { get; set; } = string.Empty;
+
+    }
+
+    public class BaseResult<T>:BaseResult
+    {
+        public List<T> Data { get; set; }
+    }
+}

+ 6 - 0
Helper/SystemEnums.cs

@@ -25,5 +25,11 @@ namespace Helper
             操作员,
             访客
         }
+
+        public enum Result
+        {
+            Fail,
+            Success,
+        }
     }
 }

+ 6 - 0
Scada/Extensions/UIExtension.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using Sunny.UI;
+using LogLevel = Microsoft.Extensions.Logging.LogLevel;
 
 namespace Scada
 {
@@ -11,4 +12,9 @@ namespace Scada
     {
         public static Action<UIStyleManager>? SetStyleManager;
     }
+
+    public static class LogExtension
+    {
+        public static Action<string, LogLevel> ShowMessage;
+    }
 }

+ 1 - 0
Scada/Page/PageTotalEquipmentControl.cs

@@ -22,6 +22,7 @@ namespace Scada.Page
         {
             _logger = logger;
             InitializeComponent();
+            LogExtension.ShowMessage = ShowLog;
         }
 
         private void btn_Start_Common_Click(object sender, EventArgs e)

+ 8 - 0
Scada/Page/PageUserManage.Designer.cs

@@ -163,6 +163,7 @@
             btn_AddUser.TabIndex = 8;
             btn_AddUser.Text = "添加用户";
             btn_AddUser.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_AddUser.Click += btn_AddUser_Click;
             // 
             // btn_Update
             // 
@@ -175,6 +176,7 @@
             btn_Update.TabIndex = 9;
             btn_Update.Text = "修改用户";
             btn_Update.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_Update.Click += btn_Update_Click;
             // 
             // btn_Delete
             // 
@@ -187,6 +189,7 @@
             btn_Delete.TabIndex = 10;
             btn_Delete.Text = "删除用户";
             btn_Delete.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_Delete.Click += btn_Delete_Click;
             // 
             // dgv_User
             // 
@@ -237,9 +240,11 @@
             dgv_User.Size = new Size(663, 489);
             dgv_User.StripeOddColor = Color.FromArgb(235, 243, 255);
             dgv_User.TabIndex = 11;
+            dgv_User.SelectIndexChange += dgv_User_SelectIndexChange;
             // 
             // Id
             // 
+            Id.DataPropertyName = "Id";
             Id.HeaderText = "Id";
             Id.MinimumWidth = 6;
             Id.Name = "Id";
@@ -248,6 +253,7 @@
             // 
             // UserName
             // 
+            UserName.DataPropertyName = "UserName";
             UserName.HeaderText = "用户名";
             UserName.MinimumWidth = 6;
             UserName.Name = "UserName";
@@ -256,6 +262,7 @@
             // 
             // UserPassword
             // 
+            UserPassword.DataPropertyName = "UserPassword";
             UserPassword.HeaderText = "密码";
             UserPassword.MinimumWidth = 6;
             UserPassword.Name = "UserPassword";
@@ -264,6 +271,7 @@
             // 
             // Role
             // 
+            Role.DataPropertyName = "Role";
             Role.HeaderText = "角色";
             Role.MinimumWidth = 6;
             Role.Name = "Role";

+ 149 - 3
Scada/Page/PageUserManage.cs

@@ -7,6 +7,9 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
+using BLL;
+using BLL.Dto;
+using Helper;
 using HZY.Framework.DependencyInjection;
 using Sunny.UI;
 
@@ -14,19 +17,162 @@ namespace Scada.Page
 {
     public partial class PageUserManage : UIPage, ISingletonSelfDependency
     {
-        public PageUserManage()
+        private readonly UserManager _userManager;
+        public PageUserManage(UserManager userManager)
         {
             InitializeComponent();
+            _userManager = userManager;
+
+            this.cb_Auth.Items.AddRange(Enum.GetNames(typeof(SystemEnums.UserRole)));
+            this.cb_Auth.SelectedIndex = -1; // 默认不选择
+            dgv_User.AutoGenerateColumns = false;
+
+            this.Load += PageUserManage_Load;
         }
 
-        private void PageUserManage_Load(object sender, EventArgs e)
+        private async void PageUserManage_Load(object sender, EventArgs e)
         {
-
+            await LoadData();
         }
 
         private void PageUserManage_Initialize(object sender, EventArgs e)
         {
 
         }
+
+        private bool VaildInput()
+        {
+            if (this.txt_UserName.Text.IsNullOrEmpty())
+            {
+                UIMessageTip.ShowWarning("用户名不能为空!");
+                return false;
+            }
+            if (this.txt_Password.Text.IsNullOrEmpty())
+            {
+                UIMessageTip.ShowWarning("密码不能为空!");
+                return false;
+            }
+            if (this.txt_EnterPassword.Text.IsNullOrEmpty())
+            {
+                UIMessageTip.ShowWarning("确认密码不能为空!");
+                return false;
+            }
+            if (this.txt_Password.Text != this.txt_EnterPassword.Text)
+            {
+                UIMessageTip.ShowWarning("两次密码输入不一致!");
+                return false;
+            }
+            if (this.cb_Auth.SelectedIndex == -1)
+            {
+                UIMessageTip.ShowWarning("请选择用户权限!");
+                return false;
+            }
+            return true;
+        }
+
+        private async void btn_AddUser_Click(object sender, EventArgs e)
+        {
+            if (!VaildInput())
+            {
+                return;
+            }
+
+            UserAddDto userAddDto = new UserAddDto()
+            {
+                UserName = this.txt_UserName.Text.Trim(),
+                UserPassword = this.txt_Password.Text.Trim(),
+                Role = this.cb_Auth.SelectedItem.ToString() // 修复类型转换问题
+            };
+
+            var result = await _userManager.AddUserAsync(userAddDto);
+            if (result.Result == SystemEnums.Result.Success)
+            {
+                UIMessageTip.ShowOk("添加成功");
+                LogExtension.ShowMessage("添加用户成功", Microsoft.Extensions.Logging.LogLevel.Information);
+
+                await LoadData();
+            }
+            else
+            {
+                UIMessageTip.ShowOk("添加失败");
+                LogExtension.ShowMessage("添加用户失败", Microsoft.Extensions.Logging.LogLevel.Information);
+            }
+        }
+
+        private async Task LoadData()
+        {
+
+            var res = await _userManager.GetUserListAsync();
+            if (res.Result == SystemEnums.Result.Success)
+            {
+                this.dgv_User.DataSource = res.Data;
+                this.dgv_User.Refresh();
+            }
+        }
+
+        private void dgv_User_SelectIndexChange(object sender, int index)
+        {
+            var rows = this.dgv_User.Rows[index];
+            this.txt_UserName.Text = rows.Cells["UserName"].Value.ToString();
+            this.txt_Password.Text = rows.Cells["UserPassword"].Value.ToString();
+            this.txt_EnterPassword.Text = rows.Cells["UserPassword"].Value.ToString(); // 确认密码与密码一致
+            this.cb_Auth.SelectedItem = rows.Cells["Role"].Value.ToString(); // 修复类型转换问题
+        }
+
+        private async void btn_Update_Click(object sender, EventArgs e)
+        {
+            if (!VaildInput())
+            {
+                return;
+            }
+
+            UserUpdateDto userUpdateDto = new UserUpdateDto()
+            {
+                Id = int.Parse(this.dgv_User.CurrentRow.Cells["Id"].Value.ToString()),
+                UserName = this.txt_UserName.Text.Trim(),
+                UserPassword = this.txt_Password.Text.Trim(),
+                Role = this.cb_Auth.SelectedItem.ToString() // 修复类型转换问题
+            };
+
+            var result = await _userManager.UpdateUserAsync(userUpdateDto);
+            if (result.Result == SystemEnums.Result.Success)
+            {
+                UIMessageTip.ShowOk("更新成功");
+                LogExtension.ShowMessage("更新用户成功", Microsoft.Extensions.Logging.LogLevel.Information);
+                await LoadData();
+            }
+            else
+            {
+                UIMessageTip.ShowError("更新失败");
+                LogExtension.ShowMessage("更新用户失败", Microsoft.Extensions.Logging.LogLevel.Information);
+            }
+        }
+
+        private async void btn_Delete_Click(object sender, EventArgs e)
+        {
+            if(this.dgv_User.CurrentRow == null)
+            {
+                UIMessageTip.ShowWarning("请选择要删除的用户");
+                return;
+            }
+
+            UserDeleteDto userDeleteDto = new UserDeleteDto()
+            {
+                Id = int.Parse(this.dgv_User.CurrentRow.Cells["Id"].Value.ToString())
+            };
+
+            var result = await _userManager.DeleteUserAsync(userDeleteDto);
+            if(result.Result==SystemEnums.Result.Success)
+            {
+                UIMessageTip.ShowOk("删除成功");
+                LogExtension.ShowMessage("删除用户成功", Microsoft.Extensions.Logging.LogLevel.Information);
+                await LoadData();
+            }
+            else
+            {
+                UIMessageTip.ShowError("删除失败");
+                LogExtension.ShowMessage("删除用户失败", Microsoft.Extensions.Logging.LogLevel.Information);
+            }
+        }
     }
 }

+ 5 - 5
Scada/Program.cs

@@ -1,4 +1,5 @@
 using System.Reflection;
+using BLL;
 using DAL;
 using HZY.Framework.DependencyInjection;
 using Microsoft.Extensions.Configuration;
@@ -19,8 +20,6 @@ namespace Scada
         [STAThread]
         static void Main()
         {
-            
-
             var services = new ServiceCollection();
             ConfigureServices(services);
             ApplicationConfiguration.Initialize();
@@ -32,8 +31,8 @@ namespace Scada
 
             var db = serviceProvider.GetRequiredService<ISqlSugarClient>();
 
-            db.CodeFirst.SetStringDefaultLength(200)
-.InitTables(typeof(AuthEntity),typeof(DataEntity), typeof(RecipeEntity), typeof(UserEntity));
+//            db.CodeFirst.SetStringDefaultLength(200)
+//.InitTables(typeof(AuthEntity),typeof(DataEntity), typeof(RecipeEntity), typeof(UserEntity));
 
             Application.Run(frmMain);
         }
@@ -42,7 +41,8 @@ namespace Scada
         {
             services.AddDependencyInjection(options =>
             {
-                options.Assemblies = new[] { typeof(Program).Assembly };
+                options.Assemblies = new[] { typeof(Program).Assembly,typeof(BaseDto).Assembly,typeof(DB).Assembly };
+               
             });
 
             IConfigurationBuilder cfgBuilder = new ConfigurationBuilder()

+ 1 - 1
Scada/appsettings.json

@@ -2,7 +2,7 @@
   "DbContexts": {
     "DbType": "SqlServer",
     "SqlServer": {
-      "ConnectionString": "Server=.;Database=scada;User ID=sa;Password=123456;Encrypt=True;TrustServerCertificate=True;"
+      "ConnectionString": "Server=.;Database=scada;User ID=sa;Password=pecton;Encrypt=True;TrustServerCertificate=True;"
     }
   },
     //相对路径  可以省略前面的东西