From 00720e9fbf531548b5ddeecd69a8e845e4f55015 Mon Sep 17 00:00:00 2001 From: pangwenpeng <17302161021@163.com> Date: Tue, 28 May 2024 08:13:15 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E6=9A=82=E5=AD=98=EF=BC=8C=E6=AF=8F?= =?UTF-8?q?=E6=97=A5=E6=8B=89=E5=8E=BB=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langguanApi/Controllers/UserController.cs | 5 ++ .../Model/Dto/SystemConfiguration/UserDto.cs | 57 +++++++++++++++++++ langguanApi/Model/Entity/UserEntity.cs | 32 +++++++++++ 3 files changed, 94 insertions(+) create mode 100644 langguanApi/Model/Dto/SystemConfiguration/UserDto.cs diff --git a/langguanApi/Controllers/UserController.cs b/langguanApi/Controllers/UserController.cs index 7085b2d..2ea1c88 100644 --- a/langguanApi/Controllers/UserController.cs +++ b/langguanApi/Controllers/UserController.cs @@ -76,5 +76,10 @@ namespace langguanApi.Controllers await _userService.UpdateUser(input); return Ok(new ApiResult() { code = 0 }); } + + #region 用户管理相关接口 + + + #endregion } } diff --git a/langguanApi/Model/Dto/SystemConfiguration/UserDto.cs b/langguanApi/Model/Dto/SystemConfiguration/UserDto.cs new file mode 100644 index 0000000..152ab6a --- /dev/null +++ b/langguanApi/Model/Dto/SystemConfiguration/UserDto.cs @@ -0,0 +1,57 @@ +namespace langguanApi.Model.Dto.SystemConfiguration +{ + /// + /// 用于用户管理的Dto + /// + public class UserDto + { + /// + /// 用户名 + /// + public string Username { get; set; } + /// + /// 角色id + /// + public int roleId { get; set; } + /// + /// 邮箱 + /// + public string Email { get; set; } + /// + /// 学历 + /// + public string Education { get; set; } + /// + /// 手机号 + /// + public int Tel { get; set; } + /// + /// 性别 0表示男 1表示女 + /// + public byte Sex { get; set; } + /// + /// 毕业院校 + /// + public string University { get; set; } + /// + /// 出生日期 + /// + public string Brithday { get; set; } + /// + /// 籍贯 + /// + public string Native { get; set; } + /// + /// 居住地 + /// + public string Address { get; set; } + /// + /// 是否管理员 0否 1是 + /// + public byte IsAdmin { get; set; } + /// + /// 是否删除 0否 1是 + /// + public byte IsDel { get; set; } + } +} diff --git a/langguanApi/Model/Entity/UserEntity.cs b/langguanApi/Model/Entity/UserEntity.cs index 350b96a..8225ad8 100644 --- a/langguanApi/Model/Entity/UserEntity.cs +++ b/langguanApi/Model/Entity/UserEntity.cs @@ -21,5 +21,37 @@ /// 邮箱 /// public string Email { get; set; } + /// + /// 学历 + /// + public string Education { get; set; } + /// + /// 手机号 + /// + public int Tel { get; set; } + /// + /// 性别 0表示男 1表示女 + /// + public byte Sex { get; set; } + /// + /// 毕业院校 + /// + public string University { get; set; } + /// + /// 出生日期 + /// + public string Brithday { get; set; } + /// + /// 籍贯 + /// + public string Native { get; set; } + /// + /// 居住地 + /// + public string Address { get; set; } + /// + /// 是否管理员 0否 1是 + /// + public byte IsAdmin { get; set; } } } From 3c257f11c1ac06e282c1686db9b399fbf9083677 Mon Sep 17 00:00:00 2001 From: pangwenpeng <17302161021@163.com> Date: Tue, 28 May 2024 18:33:30 +0800 Subject: [PATCH 02/13] =?UTF-8?q?=E4=BA=BA=E5=91=98=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7=E5=92=8C=E4=BA=BA=E5=91=98?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=EF=BC=8C=E8=BE=85=E5=8A=A9?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=9F=A5=E8=AF=A2=E5=92=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=88=E5=90=8E=E9=9D=A2=E4=BC=9A=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=EF=BC=89=EF=BC=8C=E8=BE=85=E8=A7=92=E8=89=B2=E8=89=B2?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=92=8C=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=88=E5=90=8E=E9=9D=A2=E4=BC=9A=E4=BF=AE=E6=94=B9=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langguanApi/Controllers/MeauController.cs | 43 +++++ langguanApi/Controllers/RoleController.cs | 31 ++++ langguanApi/Controllers/UserController.cs | 25 +++ .../Model/Dto/SystemConfiguration/UserDto.cs | 57 ------- .../Dto/SystemConfigurationDto/MeauDto.cs | 30 ++++ .../Dto/SystemConfigurationDto/RoleDto.cs | 25 +++ .../Dto/SystemConfigurationDto/UserDto.cs | 148 ++++++++++++++++ langguanApi/Model/Entity/UserEntity.cs | 20 ++- langguanApi/Model/ReqPaing.cs | 3 +- .../Model/SystemConfigurationEntity/Meau.cs | 32 ++++ .../SystemConfigurationEntity/UserRole.cs | 25 +++ langguanApi/Service/MeauService.cs | 73 ++++++++ langguanApi/Service/RoleService.cs | 63 +++++++ langguanApi/Service/UserService.cs | 158 +++++++++++++++++- 14 files changed, 670 insertions(+), 63 deletions(-) create mode 100644 langguanApi/Controllers/MeauController.cs create mode 100644 langguanApi/Controllers/RoleController.cs delete mode 100644 langguanApi/Model/Dto/SystemConfiguration/UserDto.cs create mode 100644 langguanApi/Model/Dto/SystemConfigurationDto/MeauDto.cs create mode 100644 langguanApi/Model/Dto/SystemConfigurationDto/RoleDto.cs create mode 100644 langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs create mode 100644 langguanApi/Model/SystemConfigurationEntity/Meau.cs create mode 100644 langguanApi/Model/SystemConfigurationEntity/UserRole.cs create mode 100644 langguanApi/Service/MeauService.cs create mode 100644 langguanApi/Service/RoleService.cs diff --git a/langguanApi/Controllers/MeauController.cs b/langguanApi/Controllers/MeauController.cs new file mode 100644 index 0000000..39d5710 --- /dev/null +++ b/langguanApi/Controllers/MeauController.cs @@ -0,0 +1,43 @@ +using langguanApi.Model; +using langguanApi.Model.Dto.SystemConfigurationDto; +using langguanApi.Service; +using Microsoft.AspNetCore.Mvc; + +namespace langguanApi.Controllers +{ + /// + /// 菜单控制器 + /// + [Route("api/[controller]")] + [ApiController] + public class MeauController : ControllerBase + { + private MeauService _meuaService; + public MeauController(MeauService meauService) + { + _meuaService = meauService; + } + /// + /// 获取菜单列表 + /// + /// + /// + [HttpGet("GetMenuList")] + public async Task GetMenuList([FromQuery] reqpage input) + { + var result = await _meuaService.GetMeauList(input); + return Ok(result); + } + /// + /// 新增菜单 + /// + /// + /// + [HttpPost("AddMeau")] + public async Task AddMeau([FromBody] MeauDto input) + { + var result = await _meuaService.AddMeau(input); + return Ok(result); + } + } +} diff --git a/langguanApi/Controllers/RoleController.cs b/langguanApi/Controllers/RoleController.cs new file mode 100644 index 0000000..8feda65 --- /dev/null +++ b/langguanApi/Controllers/RoleController.cs @@ -0,0 +1,31 @@ +using langguanApi.Model.Dto.SystemConfigurationDto; +using langguanApi.Service; +using Microsoft.AspNetCore.Mvc; + +namespace langguanApi.Controllers +{ + /// + /// 角色 + /// + [Route("api/[controller]")] + [ApiController] + public class RoleController : ControllerBase + { + private RoleService _roleService; + public RoleController(RoleService roleService) + { + _roleService = roleService; + } + /// + ///新增角色 + /// + /// + /// + [HttpPost("AddRole")] + public async Task AddRole([FromBody] RoleDto input) + { + var result = await _roleService.AddRole(input); + return Ok(result); + } + } +} diff --git a/langguanApi/Controllers/UserController.cs b/langguanApi/Controllers/UserController.cs index 2ea1c88..e771242 100644 --- a/langguanApi/Controllers/UserController.cs +++ b/langguanApi/Controllers/UserController.cs @@ -1,5 +1,6 @@ using langguanApi.Model; using langguanApi.Model.Dto; +using langguanApi.Model.Dto.SystemConfigurationDto; using langguanApi.Service; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -79,6 +80,30 @@ namespace langguanApi.Controllers #region 用户管理相关接口 + /// + ///新增用户 + /// + /// + /// + [HttpPost("AddUser")] + public async Task AddUser([FromBody] UserDto input) + { + var result = await _userService.AddUser(input); + return Ok(result); + } + //获取用户列表 + /// + /// 获取用户列表 + /// + /// + /// + [HttpGet("GetUserList")] + public async Task GetUserList([FromQuery] UserQueryDto input) + { + var result = await _userService.GetUserList(input); + return Ok(result); + } + #endregion } diff --git a/langguanApi/Model/Dto/SystemConfiguration/UserDto.cs b/langguanApi/Model/Dto/SystemConfiguration/UserDto.cs deleted file mode 100644 index 152ab6a..0000000 --- a/langguanApi/Model/Dto/SystemConfiguration/UserDto.cs +++ /dev/null @@ -1,57 +0,0 @@ -namespace langguanApi.Model.Dto.SystemConfiguration -{ - /// - /// 用于用户管理的Dto - /// - public class UserDto - { - /// - /// 用户名 - /// - public string Username { get; set; } - /// - /// 角色id - /// - public int roleId { get; set; } - /// - /// 邮箱 - /// - public string Email { get; set; } - /// - /// 学历 - /// - public string Education { get; set; } - /// - /// 手机号 - /// - public int Tel { get; set; } - /// - /// 性别 0表示男 1表示女 - /// - public byte Sex { get; set; } - /// - /// 毕业院校 - /// - public string University { get; set; } - /// - /// 出生日期 - /// - public string Brithday { get; set; } - /// - /// 籍贯 - /// - public string Native { get; set; } - /// - /// 居住地 - /// - public string Address { get; set; } - /// - /// 是否管理员 0否 1是 - /// - public byte IsAdmin { get; set; } - /// - /// 是否删除 0否 1是 - /// - public byte IsDel { get; set; } - } -} diff --git a/langguanApi/Model/Dto/SystemConfigurationDto/MeauDto.cs b/langguanApi/Model/Dto/SystemConfigurationDto/MeauDto.cs new file mode 100644 index 0000000..1f950d0 --- /dev/null +++ b/langguanApi/Model/Dto/SystemConfigurationDto/MeauDto.cs @@ -0,0 +1,30 @@ +namespace langguanApi.Model.Dto.SystemConfigurationDto +{ + public class MeauDto + { + /// + /// 父菜单ID 默认首页为1级,有组织为2级,无组织为2级,下面的子菜单为3级 + /// + public string ParentId { get; set; } + /// + /// 菜单编码 + /// + public string MenuCode { get; set; } + /// + /// 菜单名称 + /// + public string MenuName { get; set; } + /// + /// 可空,菜单跳转路径 + /// + public string Url { get; set; } + /// + /// 排序 + /// + public int Sort { get; set; } + /// + /// 是否激活 + /// + public bool IsActive { get; set; } + } +} diff --git a/langguanApi/Model/Dto/SystemConfigurationDto/RoleDto.cs b/langguanApi/Model/Dto/SystemConfigurationDto/RoleDto.cs new file mode 100644 index 0000000..ba7dd96 --- /dev/null +++ b/langguanApi/Model/Dto/SystemConfigurationDto/RoleDto.cs @@ -0,0 +1,25 @@ +namespace langguanApi.Model.Dto.SystemConfigurationDto +{ + /// + /// 角色DTO + /// + public class RoleDto + { + /// + /// 角色名称 + /// + public string RoleName { get; set; } + /// + /// 多个菜单用,隔开 + /// + public string Meaus { get; set; } + /// + /// 是否管理员 + /// + public bool IsAdmin { get; set; } + /// + /// 角色描述 + /// + public string Description { get; set; } + } +} diff --git a/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs b/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs new file mode 100644 index 0000000..8e9e631 --- /dev/null +++ b/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs @@ -0,0 +1,148 @@ +using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Bson; + +namespace langguanApi.Model.Dto.SystemConfigurationDto +{ + /// + /// 用于用户管理的Dto + /// + public class UserDto + { + /// + ///用户ID + /// + [BsonId] + [BsonRepresentation(BsonType.ObjectId)] + public string Id { get; set; } + /// + /// 用户名 + /// + public string Username { get; set; } + /// + /// 角色id + /// + public string roleId { get; set; } + /// + /// 邮箱 + /// + public string Email { get; set; } + /// + /// 学历 + /// + public string Education { get; set; } + /// + /// 手机号 + /// + public string Tel { get; set; } + /// + /// 性别 0表示男 1表示女 + /// + public byte Sex { get; set; } + /// + /// 毕业院校 + /// + public string University { get; set; } + /// + /// 出生日期 + /// + public string BrithdayDateTime { get; set; } + public DateTime? Brithday { get; set; } + + /// + /// 入职日期 + /// + public string HiredateDateTime { get; set; } = DateTime.Now.ToString(); + public DateTime? Hiredate { get; set; } + /// + /// 籍贯 + /// + public string Native { get; set; } + /// + /// 居住地 + /// + public string Address { get; set; } + /// + /// 是否管理员 0否 1是 + /// + public byte IsAdmin { get; set; } + /// + /// 是否删除 0否 1是 + /// + public byte IsDel { get; set; } + //是否启用 0表示未启用 1表示启用 + public byte IsEnable { get; set; } + } + /// + ///根据用户条件查询 + /// + public class UserQueryDto + { + /// + /// 用户名 + /// + public string Username { get; set; } = ""; + /// + /// 手机号 + /// + public string Tel { get; set; } = ""; + //入职开始时间 + public string HiredateStart { get; set; } = ""; + //入职结束时间 + public string HiredateEnd { get; set; } = ""; + } + + /// + /// 用户列表展示 + /// + public class UserListDto + { + /// + /// 用户名 + /// + public string Username { get; set; } + /// + /// 学历 + /// + public string Education { get; set; } + /// + /// 邮箱 + /// + public string Email { get; set; } + /// + /// 角色名称 + /// + public string roleName{ get; set; } + /// + /// 性别 + /// + public string Sex { get; set; } + /// + /// 毕业院校 + /// + public string University { get; set; } + /// + /// 联系方式 + /// + public string Tel { get; set; } + /// + /// 出生日期 + /// + public string Brithday { get; set; } + /// + /// 籍贯 + /// + public string Native { get; set; } + /// + /// 居住地 + /// + public string Address { get; set; } + /// + /// 入职日期 + /// + public string Hiredate { get; set; } + /// + /// 是否管理员 0否 1是 + /// + public string IsAdmin { get; set; } + } +} diff --git a/langguanApi/Model/Entity/UserEntity.cs b/langguanApi/Model/Entity/UserEntity.cs index 8225ad8..4eb8056 100644 --- a/langguanApi/Model/Entity/UserEntity.cs +++ b/langguanApi/Model/Entity/UserEntity.cs @@ -1,4 +1,7 @@ -namespace langguanApi.Model.Entity +using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Bson; + +namespace langguanApi.Model.Entity { /// /// 用户实体 @@ -16,7 +19,8 @@ /// /// 角色id /// - public int roleId { get; set; } + [BsonRepresentation(BsonType.ObjectId)] + public string roleId { get; set; } /// /// 邮箱 /// @@ -28,7 +32,7 @@ /// /// 手机号 /// - public int Tel { get; set; } + public string Tel { get; set; } /// /// 性别 0表示男 1表示女 /// @@ -40,7 +44,7 @@ /// /// 出生日期 /// - public string Brithday { get; set; } + public DateTime? Brithday { get; set; } /// /// 籍贯 /// @@ -50,8 +54,16 @@ /// public string Address { get; set; } /// + /// 入职日期 + /// + public DateTime? Hiredate { get; set; } + /// /// 是否管理员 0否 1是 /// public byte IsAdmin { get; set; } + /// + /// 是否启用 0禁用 1启用 + /// + public byte IsEnable { get; set; } } } diff --git a/langguanApi/Model/ReqPaing.cs b/langguanApi/Model/ReqPaing.cs index 40d145a..d662f43 100644 --- a/langguanApi/Model/ReqPaing.cs +++ b/langguanApi/Model/ReqPaing.cs @@ -1,4 +1,5 @@ -namespace langguanApi.Model + +namespace langguanApi.Model { public class ReqPaing { diff --git a/langguanApi/Model/SystemConfigurationEntity/Meau.cs b/langguanApi/Model/SystemConfigurationEntity/Meau.cs new file mode 100644 index 0000000..192ba51 --- /dev/null +++ b/langguanApi/Model/SystemConfigurationEntity/Meau.cs @@ -0,0 +1,32 @@ +namespace langguanApi.Model.SystemConfigurationEntity +{ + //菜单实体类 + public class Meau : BaseModel + { + /// + /// 父菜单ID 默认首页为1级,有组织为2级,无组织为2级,下面的子菜单为3级 + /// + public string ParentId { get; set; } + /// + /// 菜单编码 + /// + public string MenuCode { get; set; } + /// + /// 菜单名称 + /// + public string MenuName { get; set; } + /// + /// 可空,菜单跳转路径 + /// + public string Url { get; set; } + /// + /// 排序 + /// + public int Sort { get; set; } + /// + /// 是否激活 + /// + public bool IsActive { get; set; } + + } +} diff --git a/langguanApi/Model/SystemConfigurationEntity/UserRole.cs b/langguanApi/Model/SystemConfigurationEntity/UserRole.cs new file mode 100644 index 0000000..dc186be --- /dev/null +++ b/langguanApi/Model/SystemConfigurationEntity/UserRole.cs @@ -0,0 +1,25 @@ +namespace langguanApi.Model.SystemConfigurationEntity +{ + /// + /// 角色实体类 + /// + public class UserRole : BaseModel + { + /// + /// 角色名称 + /// + public string RoleName { get; set; } + /// + /// 多个菜单用,隔开 + /// + public string Meaus { get; set; } + /// + /// 是否管理员 + /// + public bool IsAdmin { get; set; } + /// + /// 角色描述 + /// + public string Description { get; set; } + } +} diff --git a/langguanApi/Service/MeauService.cs b/langguanApi/Service/MeauService.cs new file mode 100644 index 0000000..eed9241 --- /dev/null +++ b/langguanApi/Service/MeauService.cs @@ -0,0 +1,73 @@ +using langguanApi.Extensions.AutoDI; +using langguanApi.Model; +using langguanApi.Model.Dto.SystemConfigurationDto; +using langguanApi.Model.SystemConfigurationEntity; +using Mapster; +using System.Linq.Expressions; + +namespace langguanApi.Service +{ + /// + /// 菜单服务 + /// + [ServiceInjection(InjectionType.Transient)] + public class MeauService : BaseService + { + public MeauService(IConfiguration config) : base(config, nameof(Meau)) + { + } + + /// + /// 获取菜单列表 + /// + /// + /// + public async Task GetMeauList(reqpage input) + { + Expression> exp = filter =>filter.IsDelete == false; + if (!string.IsNullOrEmpty(input.key)) + { + exp=filter => filter.MenuName.Contains(input.key); + } + return await base.GetPager(new ReqPaing() + { + pageSize = input.pageSize, + current = input.current + }, exp); + } + + + /// + /// 新加 + /// + /// + /// + public async Task AddMeau(MeauDto input) + { + if (await Exist(input)) + { + return new ApiResult { code = 1, msg = $"{input.MenuName}的菜单已存在" }; + } + var entity = input.Adapt(); + if (entity != null) + { + await base.CreateAsync(entity); + return new ApiResult { code = 0, msg = "" }; + } + return new ApiResult { code = 1, msg = "菜单添加失败" }; ; + } + /// + /// 是否存在 + /// + /// + /// + public async Task Exist(MeauDto input) + { + var entity = input.Adapt(); + Expression> exp = filter => filter.MenuName == entity.MenuName; + return await base.Exist(exp); + } + + + } +} diff --git a/langguanApi/Service/RoleService.cs b/langguanApi/Service/RoleService.cs new file mode 100644 index 0000000..d1d8a70 --- /dev/null +++ b/langguanApi/Service/RoleService.cs @@ -0,0 +1,63 @@ +using langguanApi.Extensions.AutoDI; +using langguanApi.Model.Dto.SystemConfigurationDto; +using langguanApi.Model; +using langguanApi.Model.Entity; +using langguanApi.Model.SystemConfigurationEntity; +using StackExchange.Redis; +using Mapster; +using System.Linq.Expressions; + +namespace langguanApi.Service +{ + [ServiceInjection(InjectionType.Transient)] + public class RoleService : BaseService + { + public RoleService(IConfiguration config) : base(config, nameof(Role)) + { + } + /// + /// 用户是否存在 + /// + /// + /// + public async Task Exist(RoleDto input) + { + var entity = input.Adapt(); + Expression> exp = filter => filter.RoleName == entity.RoleName; + return await base.Exist(exp); + } + + /// + /// 新加角色 + /// + /// + /// + public async Task AddRole(RoleDto input) + { + if (await Exist(input)) + { + return new ApiResult { code = 1, msg = $"{input.RoleName}的角色已存在" }; + } + var entity = input.Adapt(); + if (entity != null) + { + await base.CreateAsync(entity); + return new ApiResult { code = 0, msg = "" }; + } + return new ApiResult { code = 1, msg = "菜单添加失败" }; ; + } + /// + /// 根据Id,获取多个校色信息 + /// + /// + /// + public async Task> GetRoleListByIds(IEnumerable ids) + { + Expression> exp = filter => ids.Contains(filter.Id) && filter.IsDelete == false; + var list = (await base.GetListWithExp(exp)).ToList(); + return list; + } + + + } +} diff --git a/langguanApi/Service/UserService.cs b/langguanApi/Service/UserService.cs index e4468a8..2f72644 100644 --- a/langguanApi/Service/UserService.cs +++ b/langguanApi/Service/UserService.cs @@ -2,8 +2,13 @@ using langguanApi.Extensions.AutoDI; using langguanApi.Model; using langguanApi.Model.Dto; +using langguanApi.Model.Dto.SystemConfigurationDto; using langguanApi.Model.Entity; using Mapster; +using Microsoft.AspNetCore.Mvc.Filters; +using MongoDB.Bson.IO; +using MongoDB.Driver.Linq; +using Org.BouncyCastle.Asn1.Ocsp; using System.Linq.Expressions; namespace langguanApi.Service @@ -11,8 +16,12 @@ namespace langguanApi.Service [ServiceInjection(InjectionType.Transient)] public class UserService : BaseService { - public UserService(IConfiguration config) : base(config, nameof(UserEntity).Replace("Entity", "")) + private ILogger _logger; + private RoleService _roleService; + public UserService(IConfiguration config, ILogger logger, RoleService roleService) : base(config, nameof(UserEntity).Replace("Entity", "")) { + _logger = logger; + _roleService = roleService; } /// /// 登录 @@ -86,5 +95,152 @@ namespace langguanApi.Service { await base.RemoveAsync(id); } + + #region 用户管理 + /// + /// 用户是否存在 + /// + /// + /// + public async Task Exist(UserDto input) + { + var entity = input.Adapt(); + Expression> exp = filter => filter.Id == entity.Id; + return await base.Exist(exp); + } + /// + ///新增用户 + /// + /// 新增用户dto + /// + public async Task AddUser(UserDto input) + { + try + { + #region 校验参数 + if (string.IsNullOrEmpty(input.Username)) + { + return new ApiResult { code = 1, msg = "用户名非空" }; + } + if (string.IsNullOrEmpty(input.Tel)) + { + return new ApiResult { code = 1, msg = "手机号非空" }; + } + if (string.IsNullOrEmpty(input.Email)) + { + return new ApiResult { code = 1, msg = "邮箱非空" }; + } + if (string.IsNullOrEmpty(input.roleId)) + { + return new ApiResult { code = 1, msg = "角色不能为空" }; + } + #endregion + #region 组织数据 + + if (!string.IsNullOrEmpty(input.BrithdayDateTime)) + { + input.Brithday = Convert.ToDateTime(input.BrithdayDateTime); + } + if (!string.IsNullOrEmpty(input.HiredateDateTime)) + { + input.Hiredate = Convert.ToDateTime(input.HiredateDateTime); + } + input.IsEnable = 1; + var entity = input.Adapt(); + #endregion + #region 保存数据 + if (entity != null && string.IsNullOrEmpty(entity.Id)) + { + await base.CreateAsync(entity); + } + + #endregion + } + catch (Exception ex) + { + _logger.LogError($"新增用户出现异常,请求参数:user:{Newtonsoft.Json.JsonConvert.SerializeObject(input)}," + + $"请求接口:'api/User/AddUser'," + + $"异常信息:{ex.Message}," + + $"异常位置:{ex.StackTrace}" + ); + return new ApiResult { code = 1, msg = "保存用户信息失败" }; + } + finally + { + _logger.LogInformation($"新增用户参数:user:{Newtonsoft.Json.JsonConvert.SerializeObject(input)}"); + } + return new ApiResult { code = 0, msg = "保存用户信息成功" }; + } + /// + /// + /// + /// + /// + public async Task GetUserList(UserQueryDto input) + { + try + { + #region 组织查询条件 + Expression> exp = filter => filter.IsDelete == false; + if (!string.IsNullOrEmpty(input.Username)) + { + exp = filter => filter.Username.Contains(input.Username); + } + if (!string.IsNullOrEmpty(input.Tel)) + { + exp = filter => filter.Tel.Contains(input.Tel); + } + if (!string.IsNullOrEmpty(input.HiredateStart)) + { + exp = filter => filter.Hiredate.Value >= DateTime.Parse(input.HiredateStart); + } + if (!string.IsNullOrEmpty(input.HiredateEnd)) + { + exp = filter => filter.Hiredate.Value <= DateTime.Parse(input.HiredateEnd); + } + #endregion + + #region 获取数据 + var result = await base.GetListWithExp(exp);//获取人员信息 + var roleList = await _roleService.GetRoleListByIds(result.Select(s => s.roleId).ToList()); + #endregion + #region 组装返回数据 + List list = new List(); + foreach (var item in result) + { + list.Add(new UserListDto + { + Username = item.Username, + Education = item.Education, + Tel = item.Tel, + Email = item.Email, + roleName = roleList.FirstOrDefault(s => s.Id == item.roleId)?.RoleName, + Sex = item.Sex == 0 ? "男" : "女", + Address = item.Address, + IsAdmin = item.IsAdmin == 0 ? "否" : "是", + Native = item.Native, + University = item.University, + Hiredate = item.Hiredate.HasValue == true ? item.Hiredate.Value.ToString("yyyy-MM-dd") : "", + Brithday = item.Brithday.HasValue == true ? item.Brithday.Value.ToString("yyyy-MM-dd") : "", + }); + } + #endregion + return new ApiResult { code = 0, data = list }; + } + catch (Exception ex) + { + _logger.LogError($"获取用户列表出现异常,请求参数:userQuery:{Newtonsoft.Json.JsonConvert.SerializeObject(input)}," + + $"请求接口:'api/User/GetUserList'," + + $"异常信息:{ex.Message}," + + $"异常位置:{ex.StackTrace}" + ); + return new ApiResult { code = 1, msg = "获取用户列表失败" }; + } + finally + { + _logger.LogInformation($"获取用户列表参数:userQuery:{Newtonsoft.Json.JsonConvert.SerializeObject(input)}"); + } + } + #endregion } } From 0f9ab916fa53d31fe8988beadc150081a461cecf Mon Sep 17 00:00:00 2001 From: pangwenpeng <17302161021@163.com> Date: Wed, 29 May 2024 09:47:00 +0800 Subject: [PATCH 03/13] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langguanApi/Service/RoleService.cs | 14 ++++++++------ langguanApi/Service/UserService.cs | 21 --------------------- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/langguanApi/Service/RoleService.cs b/langguanApi/Service/RoleService.cs index b305d67..fbb7924 100644 --- a/langguanApi/Service/RoleService.cs +++ b/langguanApi/Service/RoleService.cs @@ -4,7 +4,6 @@ using langguanApi.Model.Dto.SystemConfigurationDto; using langguanApi.Model; using langguanApi.Model.Entity; using langguanApi.Model.SystemConfigurationEntity; -using StackExchange.Redis; using Mapster; using NPOI.SS.Formula.Functions; using System.Linq.Expressions; @@ -14,6 +13,9 @@ using System.Collections.Generic; namespace langguanApi.Service { + /// + /// 校色服务 + /// [ServiceInjection(InjectionType.Transient)] public class RoleService : BaseService { @@ -105,8 +107,8 @@ namespace langguanApi.Service /// public async Task Exist(RoleDto input) { - var entity = input.Adapt(); - Expression> exp = filter => filter.RoleName == entity.RoleName; + var entity = input.Adapt(); + Expression> exp = filter => filter.RoleName == entity.RoleName; return await base.Exist(exp); } /// @@ -120,7 +122,7 @@ namespace langguanApi.Service { return new ApiResult { code = 1, msg = $"{input.RoleName}的角色已存在" }; } - var entity = input.Adapt(); + var entity = input.Adapt(); if (entity != null) { await base.CreateAsync(entity); @@ -133,9 +135,9 @@ namespace langguanApi.Service /// /// /// - public async Task> GetRoleListByIds(IEnumerable ids) + public async Task> GetRoleListByIds(IEnumerable ids) { - Expression> exp = filter => ids.Contains(filter.Id) && filter.IsDelete == false; + Expression> exp = filter => ids.Contains(filter.Id) && filter.IsDelete == false; var list = (await base.GetListWithExp(exp)).ToList(); return list; } diff --git a/langguanApi/Service/UserService.cs b/langguanApi/Service/UserService.cs index 2f72644..c13a2c5 100644 --- a/langguanApi/Service/UserService.cs +++ b/langguanApi/Service/UserService.cs @@ -186,18 +186,6 @@ namespace langguanApi.Service { exp = filter => filter.Username.Contains(input.Username); } - if (!string.IsNullOrEmpty(input.Tel)) - { - exp = filter => filter.Tel.Contains(input.Tel); - } - if (!string.IsNullOrEmpty(input.HiredateStart)) - { - exp = filter => filter.Hiredate.Value >= DateTime.Parse(input.HiredateStart); - } - if (!string.IsNullOrEmpty(input.HiredateEnd)) - { - exp = filter => filter.Hiredate.Value <= DateTime.Parse(input.HiredateEnd); - } #endregion #region 获取数据 @@ -211,17 +199,8 @@ namespace langguanApi.Service list.Add(new UserListDto { Username = item.Username, - Education = item.Education, - Tel = item.Tel, Email = item.Email, roleName = roleList.FirstOrDefault(s => s.Id == item.roleId)?.RoleName, - Sex = item.Sex == 0 ? "男" : "女", - Address = item.Address, - IsAdmin = item.IsAdmin == 0 ? "否" : "是", - Native = item.Native, - University = item.University, - Hiredate = item.Hiredate.HasValue == true ? item.Hiredate.Value.ToString("yyyy-MM-dd") : "", - Brithday = item.Brithday.HasValue == true ? item.Brithday.Value.ToString("yyyy-MM-dd") : "", }); } #endregion From d4ac85c5257637612c3332750058f43527acdb64 Mon Sep 17 00:00:00 2001 From: pangwenpeng <17302161021@163.com> Date: Wed, 29 May 2024 10:57:37 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langguanApi/Model/Entity/UserEntity.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/langguanApi/Model/Entity/UserEntity.cs b/langguanApi/Model/Entity/UserEntity.cs index 7b681f7..799dc71 100644 --- a/langguanApi/Model/Entity/UserEntity.cs +++ b/langguanApi/Model/Entity/UserEntity.cs @@ -28,6 +28,9 @@ namespace langguanApi.Model.Entity /// 手机号 /// public string Phone { get; set; } + + //是否管理员 0表示不是管理员 1表示管理员 + public byte IsAdmin { get; set; } } /// /// 添加用户DTO From ef5cce1ce88f395bacab3408e582408ef588da89 Mon Sep 17 00:00:00 2001 From: pangwenpeng <17302161021@163.com> Date: Wed, 29 May 2024 17:22:41 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E4=BA=BA=E5=91=98=E7=AE=A1=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E6=96=B0=E5=A2=9E=EF=BC=8C=E6=9F=A5=E8=AF=A2=E5=88=97?= =?UTF-8?q?=E8=A1=A8=EF=BC=8C=E6=9F=A5=E8=AF=A2=E5=8D=95=E4=B8=AA=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=88=A0=E9=99=A4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langguanApi/Common/StringHelper.cs | 53 +++++ langguanApi/Controllers/UserController.cs | 60 +++-- .../Dto/SystemConfigurationDto/UserDto.cs | 91 ++------ langguanApi/Model/Entity/UserEntity.cs | 2 +- langguanApi/Service/RoleService.cs | 13 ++ langguanApi/Service/UserService.cs | 214 +++++++++++++++--- 6 files changed, 311 insertions(+), 122 deletions(-) diff --git a/langguanApi/Common/StringHelper.cs b/langguanApi/Common/StringHelper.cs index f3f3e0c..0cc0d3b 100644 --- a/langguanApi/Common/StringHelper.cs +++ b/langguanApi/Common/StringHelper.cs @@ -28,5 +28,58 @@ namespace langguanApi.Common } return pwd; } + + /// + /// 加密 + /// + /// 需要加密的字符串 + /// 加密后的字符串 + //[OperationContract] + public static string Encrypt(string strSource) + { + //把字符串放到byte数组中 + byte[] bytIn = System.Text.Encoding.Default.GetBytes(strSource); + //建立加密对象的密钥和偏移量 + byte[] iv = { 102, 16, 93, 156, 78, 4, 218, 32 };//定义偏移量 + byte[] key = { 55, 103, 246, 79, 36, 99, 167, 3 };//定义密钥 + //实例DES加密类 + DESCryptoServiceProvider mobjCryptoService = new DESCryptoServiceProvider(); + mobjCryptoService.Key = iv; + mobjCryptoService.IV = key; + ICryptoTransform encrypto = mobjCryptoService.CreateEncryptor(); + //实例MemoryStream流加密密文件 + System.IO.MemoryStream ms = new System.IO.MemoryStream(); + CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write); + cs.Write(bytIn, 0, bytIn.Length); + cs.FlushFinalBlock(); + + string strOut = System.Convert.ToBase64String(ms.ToArray()); + return strOut; + + } + /// + /// 解密 + /// + /// 需要解密的字符串 + /// 解密后的字符串 + //[OperationContract] + public static string Decrypt(string Source) + { + if (Source == null) return string.Empty; + //将解密字符串转换成字节数组 + byte[] bytIn = System.Convert.FromBase64String(Source); + //给出解密的密钥和偏移量,密钥和偏移量必须与加密时的密钥和偏移量相同 + byte[] iv = { 102, 16, 93, 156, 78, 4, 218, 32 };//定义偏移量 + byte[] key = { 55, 103, 246, 79, 36, 99, 167, 3 };//定义密钥 + DESCryptoServiceProvider mobjCryptoService = new DESCryptoServiceProvider(); + mobjCryptoService.Key = iv; + mobjCryptoService.IV = key; + //实例流进行解密 + System.IO.MemoryStream ms = new System.IO.MemoryStream(bytIn, 0, bytIn.Length); + ICryptoTransform encrypto = mobjCryptoService.CreateDecryptor(); + CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Read); + StreamReader strd = new StreamReader(cs, Encoding.Default); + return strd.ReadToEnd(); + } } } diff --git a/langguanApi/Controllers/UserController.cs b/langguanApi/Controllers/UserController.cs index e771242..5dc9ba2 100644 --- a/langguanApi/Controllers/UserController.cs +++ b/langguanApi/Controllers/UserController.cs @@ -56,30 +56,8 @@ namespace langguanApi.Controllers var result = await _userService.GetPage(input); return Ok(result); } - ///删除用户 - /// - /// - /// - [HttpDelete("Delete")] - public async Task Delete(string id) - { - await _userService.DeleteUser(id); - return Ok(new ApiResult() { code = 0 }); - } - /// - /// 修改用户信息 - /// - /// - /// - [HttpPut("Update")] - public async Task Update([FromBody] UserUpdate input) - { - await _userService.UpdateUser(input); - return Ok(new ApiResult() { code = 0 }); - } #region 用户管理相关接口 - /// ///新增用户 /// @@ -103,8 +81,42 @@ namespace langguanApi.Controllers var result = await _userService.GetUserList(input); return Ok(result); } - - + //根据用户Id获取用户信息 + /// + /// 根据用户Id获取用户信息 + /// + /// + /// + [HttpGet("GetUserById")] + public async Task GetUserById(string userId) + { + var result = await _userService.GetUserById(userId); + return Ok(result); + } + //修改用户信息 + /// + /// 修改用户信息 + /// + /// + /// + [HttpPost("UpdateUser")] + public async Task UpdateUser([FromBody] UserDto input) + { + var result = await _userService.UpdateUser(input); + return Ok(result); + } + //删除用户 + /// + /// 删除用户 + /// + /// + /// + [HttpPost("DeleteUser")] + public async Task DeleteUser(string userId) + { + var result = await _userService.DeleteUser(userId); + return Ok(result); + } #endregion } } diff --git a/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs b/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs index 8e9e631..a938ad1 100644 --- a/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs +++ b/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs @@ -27,41 +27,10 @@ namespace langguanApi.Model.Dto.SystemConfigurationDto /// public string Email { get; set; } /// - /// 学历 - /// - public string Education { get; set; } - /// /// 手机号 /// public string Tel { get; set; } /// - /// 性别 0表示男 1表示女 - /// - public byte Sex { get; set; } - /// - /// 毕业院校 - /// - public string University { get; set; } - /// - /// 出生日期 - /// - public string BrithdayDateTime { get; set; } - public DateTime? Brithday { get; set; } - - /// - /// 入职日期 - /// - public string HiredateDateTime { get; set; } = DateTime.Now.ToString(); - public DateTime? Hiredate { get; set; } - /// - /// 籍贯 - /// - public string Native { get; set; } - /// - /// 居住地 - /// - public string Address { get; set; } - /// /// 是否管理员 0否 1是 /// public byte IsAdmin { get; set; } @@ -69,8 +38,10 @@ namespace langguanApi.Model.Dto.SystemConfigurationDto /// 是否删除 0否 1是 /// public byte IsDel { get; set; } - //是否启用 0表示未启用 1表示启用 - public byte IsEnable { get; set; } + /// + /// 密码 md5加密 + /// + public string Password { get; set; } } /// ///根据用户条件查询 @@ -85,64 +56,50 @@ namespace langguanApi.Model.Dto.SystemConfigurationDto /// 手机号 /// public string Tel { get; set; } = ""; - //入职开始时间 - public string HiredateStart { get; set; } = ""; - //入职结束时间 - public string HiredateEnd { get; set; } = ""; + /// + /// 当前条数 + /// + public int PageSize { get; set; } = 10; + /// + /// 当前页数 + /// + public int PageIndex { get; set; } = 1; } /// /// 用户列表展示 /// - public class UserListDto + public class UserDetailDto { + /// + /// 用户ID,方便查看详情操作 + /// + public string UserId { get; set; } /// /// 用户名 /// public string Username { get; set; } /// - /// 学历 - /// - public string Education { get; set; } - /// /// 邮箱 /// public string Email { get; set; } /// + /// 角色id + /// + public string RoleId { get; set; } + /// /// 角色名称 /// - public string roleName{ get; set; } - /// - /// 性别 - /// - public string Sex { get; set; } - /// - /// 毕业院校 - /// - public string University { get; set; } + public string RoleName{ get; set; } /// /// 联系方式 /// public string Tel { get; set; } /// - /// 出生日期 - /// - public string Brithday { get; set; } - /// - /// 籍贯 - /// - public string Native { get; set; } - /// - /// 居住地 - /// - public string Address { get; set; } - /// - /// 入职日期 - /// - public string Hiredate { get; set; } - /// /// 是否管理员 0否 1是 /// public string IsAdmin { get; set; } } + + } diff --git a/langguanApi/Model/Entity/UserEntity.cs b/langguanApi/Model/Entity/UserEntity.cs index 799dc71..d79a11f 100644 --- a/langguanApi/Model/Entity/UserEntity.cs +++ b/langguanApi/Model/Entity/UserEntity.cs @@ -19,7 +19,7 @@ namespace langguanApi.Model.Entity /// /// 角色id /// - public string roleId { get; set; } + public string RoleId { get; set; } /// /// 邮箱 /// diff --git a/langguanApi/Service/RoleService.cs b/langguanApi/Service/RoleService.cs index fbb7924..7f62785 100644 --- a/langguanApi/Service/RoleService.cs +++ b/langguanApi/Service/RoleService.cs @@ -141,5 +141,18 @@ namespace langguanApi.Service var list = (await base.GetListWithExp(exp)).ToList(); return list; } + + #region 用户管理角色相关 + /// + /// 根据id获取角色信息 + /// + /// + /// + public async Task GetRoleById(string roleId) + { + return await base.GetAsync(roleId); + } + #endregion + } } diff --git a/langguanApi/Service/UserService.cs b/langguanApi/Service/UserService.cs index c13a2c5..a34892c 100644 --- a/langguanApi/Service/UserService.cs +++ b/langguanApi/Service/UserService.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc.Filters; using MongoDB.Bson.IO; using MongoDB.Driver.Linq; using Org.BouncyCastle.Asn1.Ocsp; +using System.Collections.Generic; using System.Linq.Expressions; namespace langguanApi.Service @@ -83,18 +84,6 @@ namespace langguanApi.Service current = input.current }, exp); } - ///更新用户信息 - public async Task UpdateUser(UserUpdate user) - { - var entity = user.Adapt(); - entity.Password = StringHelper.MD5Encrypt32(user.Password); - await base.UpdateAsync(user.Id, entity); - } - ///删除用户 - public async Task DeleteUser(string id) - { - await base.RemoveAsync(id); - } #region 用户管理 /// @@ -136,24 +125,18 @@ namespace langguanApi.Service } #endregion #region 组织数据 - - if (!string.IsNullOrEmpty(input.BrithdayDateTime)) - { - input.Brithday = Convert.ToDateTime(input.BrithdayDateTime); - } - if (!string.IsNullOrEmpty(input.HiredateDateTime)) - { - input.Hiredate = Convert.ToDateTime(input.HiredateDateTime); - } - input.IsEnable = 1; var entity = input.Adapt(); + entity.Phone = input.Tel; + if (!string.IsNullOrEmpty(input.Password)) + { + entity.Password = StringHelper.MD5Encrypt32(input.Password); + } #endregion #region 保存数据 if (entity != null && string.IsNullOrEmpty(entity.Id)) { await base.CreateAsync(entity); } - #endregion } catch (Exception ex) @@ -172,12 +155,13 @@ namespace langguanApi.Service return new ApiResult { code = 0, msg = "保存用户信息成功" }; } /// - /// + /// 获取用户列表 /// /// /// public async Task GetUserList(UserQueryDto input) { + List list = new List(); try { #region 组织查询条件 @@ -186,25 +170,40 @@ namespace langguanApi.Service { exp = filter => filter.Username.Contains(input.Username); } + if (!string.IsNullOrEmpty(input.Tel)) + { + exp = filter => filter.Phone.Contains(input.Tel); + } #endregion - #region 获取数据 var result = await base.GetListWithExp(exp);//获取人员信息 - var roleList = await _roleService.GetRoleListByIds(result.Select(s => s.roleId).ToList()); + if (result.Count() > 0) + { + result = result.Skip((input.PageIndex - 1) * input.PageSize).Take(input.PageSize); + } + else + { + return new ApiResult { code = 0, data = null, msg = "没有用户信息" }; + } + var roleList = await _roleService.GetRoleListByIds(result.Select(s => s.RoleId).ToList());//根据角色Id获取角色信息 #endregion + //md5解密 + //var password = StringHelper.MD5Decrypt32(item.Password); #region 组装返回数据 - List list = new List(); foreach (var item in result) { - list.Add(new UserListDto + list.Add(new UserDetailDto { + UserId = item.Id, Username = item.Username, Email = item.Email, - roleName = roleList.FirstOrDefault(s => s.Id == item.roleId)?.RoleName, + RoleId = item.RoleId, + RoleName = roleList.FirstOrDefault(s => s.Id == item.RoleId)?.RoleName, + IsAdmin = item.IsAdmin == 0 ? "男" : "女", + Tel = item.Phone, }); } #endregion - return new ApiResult { code = 0, data = list }; } catch (Exception ex) { @@ -219,6 +218,161 @@ namespace langguanApi.Service { _logger.LogInformation($"获取用户列表参数:userQuery:{Newtonsoft.Json.JsonConvert.SerializeObject(input)}"); } + return new ApiResult { code = 0, data = list }; + } + + /// + /// 根据用户Id获取用户信息 + /// + /// + /// + public async Task GetUserById(string userId) + { + UserDetailDto userDetail = null; + try + { + #region 校验数据 + if (string.IsNullOrEmpty(userId)) + { + return new ApiResult { code = 1, msg = "获取用户信息失败,userId非空" }; + } + #endregion + #region 获取数据 + var user = await base.GetAsync(userId);//根据userId获取用户信息 + if (user == null) + { + return new ApiResult { code = 1, msg = "用户不存在" }; + } + var role = await _roleService.GetRoleById(user.RoleId);//根据角色Id获取角色信息 + if (role == null) + { + return new ApiResult { code = 1, msg = "角色不存在" }; + } + #endregion + #region 组织需要展示的数据 + userDetail = new UserDetailDto + { + UserId = user.Id, + Username = user.Username, + Email = user.Email, + RoleId = user.RoleId, + RoleName = role.RoleName, + IsAdmin = user.IsAdmin == 0 ? "男" : "女", + Tel = user.Phone + }; + #endregion + } + catch (Exception ex) + { + _logger.LogError($"获取用户信息出现异常,请求参数:userId:{userId}," + + $"请求接口:'api/User/GetUserById'," + + $"异常信息:{ex.Message}," + + $"异常位置:{ex.StackTrace}" + ); + return new ApiResult { code = 1, msg = "获取用户信息失败" }; + } + finally + { + _logger.LogInformation($"获取用户信息参数:userId:{userId}"); + } + return new ApiResult { code = 0, data = userDetail }; + } + + + //更新用户信息方法 + public async Task UpdateUser(UserDto input) + { + try + { + #region 校验参数 + if (string.IsNullOrEmpty(input.Id)) + { + return new ApiResult { code = 1, msg = "用户Id不能为空" }; + } + if (string.IsNullOrEmpty(input.Username)) + { + return new ApiResult { code = 1, msg = "用户名不能为空" }; + } + if (string.IsNullOrEmpty(input.Tel)) + { + return new ApiResult { code = 1, msg = "手机号不能为空" }; + } + if (string.IsNullOrEmpty(input.Email)) + { + return new ApiResult { code = 1, msg = "邮箱不能为空" }; + } + if (string.IsNullOrEmpty(input.roleId)) + { + return new ApiResult { code = 1, msg = "角色不能为空" }; + } + #endregion + #region 组织数据 + var userEntity = input.Adapt(); + userEntity.Phone = input.Tel; + if (!string.IsNullOrEmpty(input.Password)) + { + userEntity.Password = StringHelper.MD5Encrypt32(input.Password); + } + #endregion + #region 更新数据 + await base.UpdateAsync(input.Id, userEntity);//更新用户信息 + #endregion + } + catch (Exception ex) + { + _logger.LogError($"更新用户信息出现异常,请求参数:user:{Newtonsoft.Json.JsonConvert.SerializeObject(input)}," + + $"请求接口:'api/User/UpdateUser'," + + $"异常信息:{ex.Message}," + + $"异常位置:{ex.StackTrace}" + ); + return new ApiResult { code = 1, msg = "更新用户信息失败" }; + } + finally + { + _logger.LogInformation($"更新用户信息参数:user:{Newtonsoft.Json.JsonConvert.SerializeObject(input)}"); + } + return new ApiResult { code = 0, msg = "更新用户信息成功" }; + } + + /// + /// 作废用户的方法 + /// + /// + /// + public async Task DeleteUser(string userId) + { + try + { + #region 校验数据 + if (string.IsNullOrEmpty(userId)) + { + return new ApiResult { code = 1, msg = "用户Id不能为空" }; + } + #endregion + #region 更新数据 + var user = await base.GetAsync(userId);//根据userId获取用户信息 + if (user == null) + { + return new ApiResult { code = 1, msg = "用户不存在" }; + } + user.IsDelete = true; + await base.UpdateAsync(userId, user);//更新用户信息 + #endregion + } + catch (Exception ex) + { + _logger.LogError($"删除用户信息出现异常,请求参数:userId:{userId}," + + $"请求接口:'api/User/DeleteUser'," + + $"异常信息:{ex.Message}," + + $"异常位置:{ex.StackTrace}" + ); + return new ApiResult { code = 1, msg = "删除用户信息失败" }; + } + finally + { + _logger.LogInformation($"删除用户信息参数:userId:{userId}"); + } + return new ApiResult { code = 0, msg = "删除用户信息成功" }; } #endregion } From 7fd0048b29b61f70bc3ec6e7ed25d2e305004a9a Mon Sep 17 00:00:00 2001 From: pangwenpeng <17302161021@163.com> Date: Wed, 29 May 2024 17:32:21 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=9A=84=E4=B8=8D=E8=A6=81=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langguanApi/Controllers/MeauController.cs | 24 +------- langguanApi/Controllers/RoleController.cs | 12 +--- .../Model/SystemConfigurationEntity/Meau.cs | 32 ----------- .../SystemConfigurationEntity/UserRole.cs | 25 --------- langguanApi/Service/MeauService.cs | 56 +------------------ langguanApi/Service/RoleService.cs | 44 ++------------- 6 files changed, 12 insertions(+), 181 deletions(-) delete mode 100644 langguanApi/Model/SystemConfigurationEntity/Meau.cs delete mode 100644 langguanApi/Model/SystemConfigurationEntity/UserRole.cs diff --git a/langguanApi/Controllers/MeauController.cs b/langguanApi/Controllers/MeauController.cs index 39d5710..327413c 100644 --- a/langguanApi/Controllers/MeauController.cs +++ b/langguanApi/Controllers/MeauController.cs @@ -17,27 +17,7 @@ namespace langguanApi.Controllers { _meuaService = meauService; } - /// - /// 获取菜单列表 - /// - /// - /// - [HttpGet("GetMenuList")] - public async Task GetMenuList([FromQuery] reqpage input) - { - var result = await _meuaService.GetMeauList(input); - return Ok(result); - } - /// - /// 新增菜单 - /// - /// - /// - [HttpPost("AddMeau")] - public async Task AddMeau([FromBody] MeauDto input) - { - var result = await _meuaService.AddMeau(input); - return Ok(result); - } + + } } diff --git a/langguanApi/Controllers/RoleController.cs b/langguanApi/Controllers/RoleController.cs index 2ee96d6..59874aa 100644 --- a/langguanApi/Controllers/RoleController.cs +++ b/langguanApi/Controllers/RoleController.cs @@ -90,16 +90,6 @@ namespace langguanApi.Controllers Select(s => new { s.Id, s.RoleName }) }); } - /// - ///新增角色 - /// - /// - /// - [HttpPost("AddRole")] - public async Task AddRole([FromBody] RoleDto input) - { - var result = await _roleService.AddRole(input); - return Ok(result); - } + } } diff --git a/langguanApi/Model/SystemConfigurationEntity/Meau.cs b/langguanApi/Model/SystemConfigurationEntity/Meau.cs deleted file mode 100644 index 192ba51..0000000 --- a/langguanApi/Model/SystemConfigurationEntity/Meau.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace langguanApi.Model.SystemConfigurationEntity -{ - //菜单实体类 - public class Meau : BaseModel - { - /// - /// 父菜单ID 默认首页为1级,有组织为2级,无组织为2级,下面的子菜单为3级 - /// - public string ParentId { get; set; } - /// - /// 菜单编码 - /// - public string MenuCode { get; set; } - /// - /// 菜单名称 - /// - public string MenuName { get; set; } - /// - /// 可空,菜单跳转路径 - /// - public string Url { get; set; } - /// - /// 排序 - /// - public int Sort { get; set; } - /// - /// 是否激活 - /// - public bool IsActive { get; set; } - - } -} diff --git a/langguanApi/Model/SystemConfigurationEntity/UserRole.cs b/langguanApi/Model/SystemConfigurationEntity/UserRole.cs deleted file mode 100644 index dc186be..0000000 --- a/langguanApi/Model/SystemConfigurationEntity/UserRole.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace langguanApi.Model.SystemConfigurationEntity -{ - /// - /// 角色实体类 - /// - public class UserRole : BaseModel - { - /// - /// 角色名称 - /// - public string RoleName { get; set; } - /// - /// 多个菜单用,隔开 - /// - public string Meaus { get; set; } - /// - /// 是否管理员 - /// - public bool IsAdmin { get; set; } - /// - /// 角色描述 - /// - public string Description { get; set; } - } -} diff --git a/langguanApi/Service/MeauService.cs b/langguanApi/Service/MeauService.cs index eed9241..9309988 100644 --- a/langguanApi/Service/MeauService.cs +++ b/langguanApi/Service/MeauService.cs @@ -1,7 +1,7 @@ using langguanApi.Extensions.AutoDI; using langguanApi.Model; using langguanApi.Model.Dto.SystemConfigurationDto; -using langguanApi.Model.SystemConfigurationEntity; +using langguanApi.Model.Entity; using Mapster; using System.Linq.Expressions; @@ -11,62 +11,12 @@ namespace langguanApi.Service /// 菜单服务 /// [ServiceInjection(InjectionType.Transient)] - public class MeauService : BaseService + public class MeauService : BaseService { - public MeauService(IConfiguration config) : base(config, nameof(Meau)) + public MeauService(IConfiguration config) : base(config, nameof(Menu)) { } - /// - /// 获取菜单列表 - /// - /// - /// - public async Task GetMeauList(reqpage input) - { - Expression> exp = filter =>filter.IsDelete == false; - if (!string.IsNullOrEmpty(input.key)) - { - exp=filter => filter.MenuName.Contains(input.key); - } - return await base.GetPager(new ReqPaing() - { - pageSize = input.pageSize, - current = input.current - }, exp); - } - - - /// - /// 新加 - /// - /// - /// - public async Task AddMeau(MeauDto input) - { - if (await Exist(input)) - { - return new ApiResult { code = 1, msg = $"{input.MenuName}的菜单已存在" }; - } - var entity = input.Adapt(); - if (entity != null) - { - await base.CreateAsync(entity); - return new ApiResult { code = 0, msg = "" }; - } - return new ApiResult { code = 1, msg = "菜单添加失败" }; ; - } - /// - /// 是否存在 - /// - /// - /// - public async Task Exist(MeauDto input) - { - var entity = input.Adapt(); - Expression> exp = filter => filter.MenuName == entity.MenuName; - return await base.Exist(exp); - } } diff --git a/langguanApi/Service/RoleService.cs b/langguanApi/Service/RoleService.cs index 7f62785..d29dac5 100644 --- a/langguanApi/Service/RoleService.cs +++ b/langguanApi/Service/RoleService.cs @@ -3,7 +3,6 @@ using langguanApi.Extensions.AutoDI; using langguanApi.Model.Dto.SystemConfigurationDto; using langguanApi.Model; using langguanApi.Model.Entity; -using langguanApi.Model.SystemConfigurationEntity; using Mapster; using NPOI.SS.Formula.Functions; using System.Linq.Expressions; @@ -14,7 +13,7 @@ using System.Collections.Generic; namespace langguanApi.Service { /// - /// 校色服务 + /// 角色服务 /// [ServiceInjection(InjectionType.Transient)] public class RoleService : BaseService @@ -100,35 +99,15 @@ namespace langguanApi.Service }, exp); } + #region 用户管理角色相关 /// - /// 用户是否存在 + /// 根据id获取角色信息 /// - /// + /// /// - public async Task Exist(RoleDto input) + public async Task GetRoleById(string roleId) { - var entity = input.Adapt(); - Expression> exp = filter => filter.RoleName == entity.RoleName; - return await base.Exist(exp); - } - /// - /// 新加角色 - /// - /// - /// - public async Task AddRole(RoleDto input) - { - if (await Exist(input)) - { - return new ApiResult { code = 1, msg = $"{input.RoleName}的角色已存在" }; - } - var entity = input.Adapt(); - if (entity != null) - { - await base.CreateAsync(entity); - return new ApiResult { code = 0, msg = "" }; - } - return new ApiResult { code = 1, msg = "菜单添加失败" }; ; + return await base.GetAsync(roleId); } /// /// 根据Id,获取多个校色信息 @@ -141,17 +120,6 @@ namespace langguanApi.Service var list = (await base.GetListWithExp(exp)).ToList(); return list; } - - #region 用户管理角色相关 - /// - /// 根据id获取角色信息 - /// - /// - /// - public async Task GetRoleById(string roleId) - { - return await base.GetAsync(roleId); - } #endregion } From 7b283ab0caac8e4bebb8a51e0ebcb6a720d8b95b Mon Sep 17 00:00:00 2001 From: pangwenpeng <17302161021@163.com> Date: Thu, 30 May 2024 09:36:01 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E5=AF=B9=E6=AF=94=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=B2=A1=E7=94=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langguanApi/Controllers/MeauController.cs | 23 -------------- langguanApi/Controllers/RoleController.cs | 2 -- .../Dto/SystemConfigurationDto/MeauDto.cs | 30 ------------------- .../Dto/SystemConfigurationDto/RoleDto.cs | 25 ---------------- langguanApi/Model/Entity/UserEntity.cs | 2 -- langguanApi/Service/MeauService.cs | 23 -------------- langguanApi/Service/UserService.cs | 2 -- 7 files changed, 107 deletions(-) delete mode 100644 langguanApi/Controllers/MeauController.cs delete mode 100644 langguanApi/Model/Dto/SystemConfigurationDto/MeauDto.cs delete mode 100644 langguanApi/Model/Dto/SystemConfigurationDto/RoleDto.cs delete mode 100644 langguanApi/Service/MeauService.cs diff --git a/langguanApi/Controllers/MeauController.cs b/langguanApi/Controllers/MeauController.cs deleted file mode 100644 index 327413c..0000000 --- a/langguanApi/Controllers/MeauController.cs +++ /dev/null @@ -1,23 +0,0 @@ -using langguanApi.Model; -using langguanApi.Model.Dto.SystemConfigurationDto; -using langguanApi.Service; -using Microsoft.AspNetCore.Mvc; - -namespace langguanApi.Controllers -{ - /// - /// 菜单控制器 - /// - [Route("api/[controller]")] - [ApiController] - public class MeauController : ControllerBase - { - private MeauService _meuaService; - public MeauController(MeauService meauService) - { - _meuaService = meauService; - } - - - } -} diff --git a/langguanApi/Controllers/RoleController.cs b/langguanApi/Controllers/RoleController.cs index 1e3201c..2fdc7e1 100644 --- a/langguanApi/Controllers/RoleController.cs +++ b/langguanApi/Controllers/RoleController.cs @@ -1,10 +1,8 @@ using langguanApi.Model; using langguanApi.Model.Entity; -using langguanApi.Model.Dto.SystemConfigurationDto; using langguanApi.Service; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using System.Threading.Tasks; namespace langguanApi.Controllers { diff --git a/langguanApi/Model/Dto/SystemConfigurationDto/MeauDto.cs b/langguanApi/Model/Dto/SystemConfigurationDto/MeauDto.cs deleted file mode 100644 index 1f950d0..0000000 --- a/langguanApi/Model/Dto/SystemConfigurationDto/MeauDto.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace langguanApi.Model.Dto.SystemConfigurationDto -{ - public class MeauDto - { - /// - /// 父菜单ID 默认首页为1级,有组织为2级,无组织为2级,下面的子菜单为3级 - /// - public string ParentId { get; set; } - /// - /// 菜单编码 - /// - public string MenuCode { get; set; } - /// - /// 菜单名称 - /// - public string MenuName { get; set; } - /// - /// 可空,菜单跳转路径 - /// - public string Url { get; set; } - /// - /// 排序 - /// - public int Sort { get; set; } - /// - /// 是否激活 - /// - public bool IsActive { get; set; } - } -} diff --git a/langguanApi/Model/Dto/SystemConfigurationDto/RoleDto.cs b/langguanApi/Model/Dto/SystemConfigurationDto/RoleDto.cs deleted file mode 100644 index ba7dd96..0000000 --- a/langguanApi/Model/Dto/SystemConfigurationDto/RoleDto.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace langguanApi.Model.Dto.SystemConfigurationDto -{ - /// - /// 角色DTO - /// - public class RoleDto - { - /// - /// 角色名称 - /// - public string RoleName { get; set; } - /// - /// 多个菜单用,隔开 - /// - public string Meaus { get; set; } - /// - /// 是否管理员 - /// - public bool IsAdmin { get; set; } - /// - /// 角色描述 - /// - public string Description { get; set; } - } -} diff --git a/langguanApi/Model/Entity/UserEntity.cs b/langguanApi/Model/Entity/UserEntity.cs index d79a11f..68d5bb1 100644 --- a/langguanApi/Model/Entity/UserEntity.cs +++ b/langguanApi/Model/Entity/UserEntity.cs @@ -29,8 +29,6 @@ namespace langguanApi.Model.Entity /// public string Phone { get; set; } - //是否管理员 0表示不是管理员 1表示管理员 - public byte IsAdmin { get; set; } } /// /// 添加用户DTO diff --git a/langguanApi/Service/MeauService.cs b/langguanApi/Service/MeauService.cs deleted file mode 100644 index 9309988..0000000 --- a/langguanApi/Service/MeauService.cs +++ /dev/null @@ -1,23 +0,0 @@ -using langguanApi.Extensions.AutoDI; -using langguanApi.Model; -using langguanApi.Model.Dto.SystemConfigurationDto; -using langguanApi.Model.Entity; -using Mapster; -using System.Linq.Expressions; - -namespace langguanApi.Service -{ - /// - /// 菜单服务 - /// - [ServiceInjection(InjectionType.Transient)] - public class MeauService : BaseService - { - public MeauService(IConfiguration config) : base(config, nameof(Menu)) - { - } - - - - } -} diff --git a/langguanApi/Service/UserService.cs b/langguanApi/Service/UserService.cs index aefb0c5..fb143a5 100644 --- a/langguanApi/Service/UserService.cs +++ b/langguanApi/Service/UserService.cs @@ -203,7 +203,6 @@ namespace langguanApi.Service Email = item.Email, RoleId = item.RoleId, RoleName = roleList.FirstOrDefault(s => s.Id == item.RoleId)?.RoleName, - IsAdmin = item.IsAdmin == 0 ? "男" : "女", Tel = item.Phone, }); } @@ -261,7 +260,6 @@ namespace langguanApi.Service Email = user.Email, RoleId = user.RoleId, RoleName = role.RoleName, - IsAdmin = user.IsAdmin == 0 ? "男" : "女", Tel = user.Phone }; #endregion From c07646784f60b3bedd8b377c494bfe5c9633d095 Mon Sep 17 00:00:00 2001 From: pangwenpeng <17302161021@163.com> Date: Thu, 30 May 2024 09:40:16 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs b/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs index a938ad1..c39d113 100644 --- a/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs +++ b/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs @@ -31,10 +31,6 @@ namespace langguanApi.Model.Dto.SystemConfigurationDto /// public string Tel { get; set; } /// - /// 是否管理员 0否 1是 - /// - public byte IsAdmin { get; set; } - /// /// 是否删除 0否 1是 /// public byte IsDel { get; set; } From 835831c6f7836fb151966a924246c24e5718690f Mon Sep 17 00:00:00 2001 From: pangwenpeng <17302161021@163.com> Date: Thu, 30 May 2024 10:49:05 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E8=A7=92=E8=89=B2ID=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs | 2 +- langguanApi/Service/UserService.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs b/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs index c39d113..b836ffd 100644 --- a/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs +++ b/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs @@ -21,7 +21,7 @@ namespace langguanApi.Model.Dto.SystemConfigurationDto /// /// 角色id /// - public string roleId { get; set; } + public string RoleId { get; set; } /// /// 邮箱 /// diff --git a/langguanApi/Service/UserService.cs b/langguanApi/Service/UserService.cs index fb143a5..a535afa 100644 --- a/langguanApi/Service/UserService.cs +++ b/langguanApi/Service/UserService.cs @@ -123,7 +123,7 @@ namespace langguanApi.Service { return new ApiResult { code = 1, msg = "邮箱非空" }; } - if (string.IsNullOrEmpty(input.roleId)) + if (string.IsNullOrEmpty(input.RoleId)) { return new ApiResult { code = 1, msg = "角色不能为空" }; } @@ -303,7 +303,7 @@ namespace langguanApi.Service { return new ApiResult { code = 1, msg = "邮箱不能为空" }; } - if (string.IsNullOrEmpty(input.roleId)) + if (string.IsNullOrEmpty(input.RoleId)) { return new ApiResult { code = 1, msg = "角色不能为空" }; } From c41592194269a817b251706cd3a6e7b1c58ecd8a Mon Sep 17 00:00:00 2001 From: pangwenpeng <17302161021@163.com> Date: Thu, 30 May 2024 10:58:27 +0800 Subject: [PATCH 10/13] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E5=8E=9F=E6=9D=A5?= =?UTF-8?q?=E6=A0=B7=E5=AD=90=EF=BC=8C=E5=8E=BB=E6=8E=89=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langguanApi/Controllers/RoleController.cs | 1 - langguanApi/Model/Entity/UserEntity.cs | 40 ----------------------- langguanApi/Model/ReqPaing.cs | 3 +- 3 files changed, 1 insertion(+), 43 deletions(-) diff --git a/langguanApi/Controllers/RoleController.cs b/langguanApi/Controllers/RoleController.cs index 2fdc7e1..49fbede 100644 --- a/langguanApi/Controllers/RoleController.cs +++ b/langguanApi/Controllers/RoleController.cs @@ -90,6 +90,5 @@ namespace langguanApi.Controllers Select(s => new { s.Id, s.RoleName }) }); } - } } diff --git a/langguanApi/Model/Entity/UserEntity.cs b/langguanApi/Model/Entity/UserEntity.cs index 68d5bb1..5077f18 100644 --- a/langguanApi/Model/Entity/UserEntity.cs +++ b/langguanApi/Model/Entity/UserEntity.cs @@ -51,46 +51,6 @@ namespace langguanApi.Model.Entity /// 邮箱 /// public string Email { get; set; } - /// - /// 学历 - /// - public string Education { get; set; } - /// - /// 手机号 - /// - public string Tel { get; set; } - /// - /// 性别 0表示男 1表示女 - /// - public byte Sex { get; set; } - /// - /// 毕业院校 - /// - public string University { get; set; } - /// - /// 出生日期 - /// - public DateTime? Brithday { get; set; } - /// - /// 籍贯 - /// - public string Native { get; set; } - /// - /// 居住地 - /// - public string Address { get; set; } - /// - /// 入职日期 - /// - public DateTime? Hiredate { get; set; } - /// - /// 是否管理员 0否 1是 - /// - public byte IsAdmin { get; set; } - /// - /// 是否启用 0禁用 1启用 - /// - public byte IsEnable { get; set; } } /// /// 更新用户DTO diff --git a/langguanApi/Model/ReqPaing.cs b/langguanApi/Model/ReqPaing.cs index d662f43..40d145a 100644 --- a/langguanApi/Model/ReqPaing.cs +++ b/langguanApi/Model/ReqPaing.cs @@ -1,5 +1,4 @@ - -namespace langguanApi.Model +namespace langguanApi.Model { public class ReqPaing { From c584c03da2fdb719fed70255addd6b54fbd7f284 Mon Sep 17 00:00:00 2001 From: pangwenpeng <17302161021@163.com> Date: Thu, 30 May 2024 15:54:59 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Model/Dto/SystemConfigurationDto/UserDto.cs | 12 ++---------- langguanApi/Service/UserService.cs | 12 +++--------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs b/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs index b836ffd..e532a7e 100644 --- a/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs +++ b/langguanApi/Model/Dto/SystemConfigurationDto/UserDto.cs @@ -45,13 +45,9 @@ namespace langguanApi.Model.Dto.SystemConfigurationDto public class UserQueryDto { /// - /// 用户名 + /// 关键字查询,可根据userName,Tel,Email /// - public string Username { get; set; } = ""; - /// - /// 手机号 - /// - public string Tel { get; set; } = ""; + public string key { get; set; } = ""; /// /// 当前条数 /// @@ -91,10 +87,6 @@ namespace langguanApi.Model.Dto.SystemConfigurationDto /// 联系方式 /// public string Tel { get; set; } - /// - /// 是否管理员 0否 1是 - /// - public string IsAdmin { get; set; } } diff --git a/langguanApi/Service/UserService.cs b/langguanApi/Service/UserService.cs index a535afa..8d5ca4e 100644 --- a/langguanApi/Service/UserService.cs +++ b/langguanApi/Service/UserService.cs @@ -170,13 +170,9 @@ namespace langguanApi.Service { #region 组织查询条件 Expression> exp = filter => filter.IsDelete == false; - if (!string.IsNullOrEmpty(input.Username)) + if (!string.IsNullOrEmpty(input.key)) { - exp = filter => filter.Username.Contains(input.Username); - } - if (!string.IsNullOrEmpty(input.Tel)) - { - exp = filter => filter.Phone.Contains(input.Tel); + exp = filter => filter.Username.Contains(input.key)|| filter.Phone.Contains(input.key)|| filter.Email.Contains(input.key); } #endregion #region 获取数据 @@ -191,8 +187,6 @@ namespace langguanApi.Service } var roleList = await _roleService.GetRoleListByIds(result.Select(s => s.RoleId).ToList());//根据角色Id获取角色信息 #endregion - //md5解密 - //var password = StringHelper.MD5Decrypt32(item.Password); #region 组装返回数据 foreach (var item in result) { @@ -221,7 +215,7 @@ namespace langguanApi.Service { _logger.LogInformation($"获取用户列表参数:userQuery:{Newtonsoft.Json.JsonConvert.SerializeObject(input)}"); } - return new ApiResult { code = 0, data = list }; + return new ApiResult { code = 0, data = list,msg="获取信息成功" }; } /// From 8721251475ec686a0f5d6c080a5722c0def691a1 Mon Sep 17 00:00:00 2001 From: pangwenpeng <17302161021@163.com> Date: Thu, 30 May 2024 17:51:36 +0800 Subject: [PATCH 12/13] =?UTF-8?q?=E8=A7=92=E8=89=B2=E5=8A=A0=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=92=8C=E5=88=97=E8=A1=A8=E5=8A=A0=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langguanApi/Service/MenuService.cs | 118 ++++++++++++++++++++++------- 1 file changed, 91 insertions(+), 27 deletions(-) diff --git a/langguanApi/Service/MenuService.cs b/langguanApi/Service/MenuService.cs index adfd2f4..0a3fe7f 100644 --- a/langguanApi/Service/MenuService.cs +++ b/langguanApi/Service/MenuService.cs @@ -11,19 +11,43 @@ namespace langguanApi.Service [ServiceInjection(InjectionType.Transient)] public class MenuService : BaseService { - public MenuService(IConfiguration config) : base(config, nameof(Menu)) + private ILogger _logger; + public MenuService(IConfiguration config, ILogger logger) : base(config, nameof(Menu)) { + _logger = logger; } public async Task> GetMenusByParentId(string parentId) { Expression> exp = filter => filter.IsDelete == false && filter.ParentId == parentId; return (await base.GetListWithExp(exp)).OrderBy(x => x.Sort).ToList(); } + /// + /// 新增菜单 + /// + /// 菜单实体 + /// public async Task AddMenu(AddMenuDto menu) { - var entity = menu.Adapt(); - await base.CreateAsync(entity); - return new ApiResult(); + try + { + var entity = menu.Adapt(); + await base.CreateAsync(entity); + } + catch (Exception ex) + { + + _logger.LogError($"新增菜单出现异常,请求参数:{Newtonsoft.Json.JsonConvert.SerializeObject(menu)}," + + $"请求接口:'api/Menu/AddMenu'," + + $"异常信息:{ex.Message}," + + $"异常位置:{ex.StackTrace}" + ); + return new ApiResult { code = 1, msg = "保存菜单失败", data = false }; + } + finally + { + _logger.LogInformation($"新增菜单参数:menu:{Newtonsoft.Json.JsonConvert.SerializeObject(menu)}"); + } + return new ApiResult { code = 0, msg = "保存菜单信息成功", data = true }; } public async Task UpdateMenu(UpdateMenuDto menu) { @@ -38,32 +62,67 @@ namespace langguanApi.Service /// public async Task Pager(reqpage input) { - Expression> exp = filter => filter.IsDelete == false; - if (!string.IsNullOrEmpty(input.key)) - { - exp = exp.And(filter => filter.Name.Contains(input.key)); - } List dto = new List(); - var MenuList = await GetChildList(null); - foreach (var item in MenuList) + try { - dto.Add(new MenuTreeDto() + var MenuList = await GetChildList("0");//获取跟节点 + if (MenuList.Any()) { - Id = item.Id, - Name = item.Name, - Sort = item.Sort, - ParentId = item.ParentId, - ParentName = item.ParentName, - Children = await GetChildList(item.Id) - }); + foreach (var item in MenuList) + { + dto.Add(new MenuTreeDto() + { + Id = item.Id, + Name = item.Name, + Sort = item.Sort, + ParentId = item.ParentId, + ParentName = item.ParentName, + Children = await GetChildList(item.Id) + }); + } + //筛选数据 + if (!string.IsNullOrEmpty(input.key)) + { + if (dto.Exists(p => p.Name == input.key) || + dto.Exists(p => p.Children.Exists(c => c.Name == input.key)) || + dto.Exists(p => p.ParentName == input.key)) + { + if (dto.Exists(p => p.Name == input.key)) + { + dto = dto.Where(p => p.Name == input.key).ToList(); + } + else if (dto.Exists(p => p.Children.Exists(c => c.Name == input.key))) + { + dto = dto.SelectMany(p => p.Children).Where(p => p.Name == input.key).ToList(); + } + else + { + dto = dto.SelectMany(p => p.Children).Where(p => p.ParentName == input.key).ToList(); + } + return new ApiResult() { code = 0, data = dto, msg = "获取菜单列表" }; + } + else + { + return new ApiResult() { code = 0, data = null, msg = "获取菜单列表不存在" }; + } + } + } } - return new ApiResult() { data = dto }; + catch (Exception ex) + { - //return await base.GetPager(new ReqPaing() - //{ - // pageSize = input.pageSize, - // current = input.current - //}, exp); + _logger.LogError($"获取菜单列表出现异常,请求参数:{Newtonsoft.Json.JsonConvert.SerializeObject(input)}," + + $"请求接口:'api/Menu/Pager'," + + $"异常信息:{ex.Message}," + + $"异常位置:{ex.StackTrace}" + ); + return new ApiResult { code = 1, msg = "获取菜单列表失败", data = false }; + } + finally + { + _logger.LogInformation($"获取菜单列表参数:menu:{Newtonsoft.Json.JsonConvert.SerializeObject(input)}"); + } + return new ApiResult() { code = 0, data = dto, msg = "获取菜单列表" }; } /// /// 递归获取子菜单列表 @@ -73,13 +132,18 @@ namespace langguanApi.Service public async Task> GetChildList(string parentId) { Expression> exp = filter => filter.IsDelete == false && filter.ParentId == parentId; + Expression> expDataSource = filter => filter.IsDelete; var list = (await GetListWithExp(exp)) - .OrderByDescending(x => x.Sort) + .OrderBy(x => x.Sort) .ToList().Adapt>(); + var DataSourceList = (await GetAsync()) + .OrderBy(x => x.Sort) + .ToList();//拿到所有数据源,筛选结果 foreach (var item in list) { item.Children = await GetChildList(item.Id); - item.ParentName = (await base.GetAsync(item.ParentId))?.Name; + item.ParentName = DataSourceList.FirstOrDefault(p => p.Id == item.ParentId)?.Name; + item.ParentId = DataSourceList.FirstOrDefault(p => p.Id == item.ParentId)?.Id; } return list; } From aab080cf194a416f10a60c1ce20c8cea21ebd2df Mon Sep 17 00:00:00 2001 From: pangwenpeng <17302161021@163.com> Date: Thu, 30 May 2024 18:06:01 +0800 Subject: [PATCH 13/13] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BD=9C=E5=BA=9F?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langguanApi/Controllers/MenuController.cs | 10 ++-- langguanApi/Service/MenuService.cs | 68 +++++++++++++++++++++-- 2 files changed, 69 insertions(+), 9 deletions(-) diff --git a/langguanApi/Controllers/MenuController.cs b/langguanApi/Controllers/MenuController.cs index 49cff20..6627b6d 100644 --- a/langguanApi/Controllers/MenuController.cs +++ b/langguanApi/Controllers/MenuController.cs @@ -57,13 +57,13 @@ namespace langguanApi.Controllers /// /// 删除菜单 /// - /// + /// /// - [HttpDelete("remove")] - public async Task Remove(IEnumerable ids) + [HttpDelete("DeleteMenu")] + public async Task DeleteMenu(string id) { - await _menuService.BatchRemoveAsync(ids); - return Ok(new ApiResult()); + var result = await _menuService.DeleteMenu(id); + return Ok(result); } } } diff --git a/langguanApi/Service/MenuService.cs b/langguanApi/Service/MenuService.cs index 0a3fe7f..6da7469 100644 --- a/langguanApi/Service/MenuService.cs +++ b/langguanApi/Service/MenuService.cs @@ -49,11 +49,37 @@ namespace langguanApi.Service } return new ApiResult { code = 0, msg = "保存菜单信息成功", data = true }; } + /// + /// 更改菜单 + /// + /// 菜单实体类 + /// public async Task UpdateMenu(UpdateMenuDto menu) { - var entity = menu.Adapt(); - await base.UpdateAsync(entity.Id, entity); - return new ApiResult(); + try + { + if (string.IsNullOrEmpty(menu.Id)) + { + return new ApiResult() { code = 0, data = false, msg = "更新菜单失败,Id不能为空" }; + } + var entity = menu.Adapt(); + await base.UpdateAsync(entity.Id, entity); + } + catch (Exception ex) + { + + _logger.LogError($"修改菜单出现异常,请求参数:{Newtonsoft.Json.JsonConvert.SerializeObject(menu)}," + + $"请求接口:'api/Menu/UpdateMenu'," + + $"异常信息:{ex.Message}," + + $"异常位置:{ex.StackTrace}" + ); + return new ApiResult { code = 1, msg = "保存菜单失败", data = false }; + } + finally + { + _logger.LogInformation($"修改菜单参数:menu:{Newtonsoft.Json.JsonConvert.SerializeObject(menu)}"); + } + return new ApiResult() { code = 0, data = true, msg = "更新菜单成功" }; } /// /// 获取菜单树 @@ -83,7 +109,7 @@ namespace langguanApi.Service //筛选数据 if (!string.IsNullOrEmpty(input.key)) { - if (dto.Exists(p => p.Name == input.key) || + if (dto.Exists(p => p.Name == input.key) || dto.Exists(p => p.Children.Exists(c => c.Name == input.key)) || dto.Exists(p => p.ParentName == input.key)) { @@ -147,5 +173,39 @@ namespace langguanApi.Service } return list; } + + /// + /// 作废菜单 + /// + /// 当前菜单id + /// + public async Task DeleteMenu(string id) + { + try + { + var entity = await base.GetAsync(id); + if (entity == null) + { + return new ApiResult() { code = 0, data = false, msg = "删除菜单失败,Id不存在" }; + } + entity.IsDelete = true; + await base.UpdateAsync(id, entity); + } + catch (Exception ex) + { + + _logger.LogError($"删除菜单出现异常,请求参数:{Newtonsoft.Json.JsonConvert.SerializeObject(id)}," + + $"请求接口:'api/Menu/DeleteMenu'," + + $"异常信息:{ex.Message}," + + $"异常位置:{ex.StackTrace}" + ); + return new ApiResult { code = 1, msg = "删除菜单失败", data = false }; + } + finally + { + _logger.LogInformation($"删除菜单参数:menuId:{id}"); + } + return new ApiResult() { code = 0, data = true, msg = "删除菜单成功" }; + } } }