Bläddra i källkod

部门管理调整好了

lcl 9 månader sedan
förälder
incheckning
a530c25f5b

+ 4 - 4
Common/JwtUtil.cs

@@ -153,10 +153,10 @@ namespace Util
         {
             var claims = new List<Claim>()
                 {
-                    new(ClaimTypes.PrimarySid, user.UserId.ToString()),
-                    new(ClaimTypes.NameIdentifier, user.UserId.ToString()),
-                    new(ClaimTypes.Name, user.Username),
-                    new(ClaimTypes.GroupSid, user.DeptId.ToString()),
+                    new(ClaimTypes.PrimarySid, user.userId.ToString()),
+                    new(ClaimTypes.NameIdentifier, user.userId.ToString()),
+                    new(ClaimTypes.Name, user.username),
+                    new(ClaimTypes.GroupSid, user.deptId.ToString()),
                     new(ClaimTypes.UserData, JsonConvert.SerializeObject(user))
                 };
 

+ 4 - 4
Controllers/Base/HomeController.cs

@@ -36,8 +36,8 @@ namespace Controllers
         {
             TokenModel loginUser = new(new TokenModel()
             {
-                Username = parm.AdminName,
-                UserId = 1
+                username = parm.AdminName,
+                userId = 1
             }, new List<Roles>());
             List<string> permissions = permissionService.List();
             CacheService.SetUserPerms(GlobalConstant.UserPermKEY + "1", permissions);
@@ -49,8 +49,8 @@ namespace Controllers
         {
             TokenModel loginUser = new(new TokenModel()
             {
-                Username = parm.AdminName,
-                UserId = 1
+                username = parm.AdminName,
+                userId = 1
             }, new List<Roles>());
             List<string> permissions = permissionService.List();
             CacheService.SetUserPerms(GlobalConstant.UserPermKEY + "1", permissions);

+ 23 - 23
Controllers/Base/SysDeptController.cs

@@ -8,8 +8,10 @@ using Infrastructure;
 using Microsoft.AspNetCore.Mvc;
 using Middleware;
 using Model;
+using Model.Base;
 using Services;
 using System.Collections;
+using Util;
 
 namespace Controllers
 {
@@ -75,7 +77,7 @@ namespace Controllers
         /// </summary>
         /// <param name="dept"></param>
         /// <returns></returns>
-        [HttpGet("treeselect")]
+        [HttpGet("/v1/skb/sysServer/dept/tree")]
         public IActionResult TreeSelect(SysDeptQueryDto dept)
         {
             var depts = DeptService.GetSysDepts(dept);
@@ -109,7 +111,7 @@ namespace Controllers
         [ActionPermissionFilter(Permission = "system:dept:query")]
         public IActionResult GetInfo(long deptId)
         {
-            var info = DeptService.GetFirst(f => f.DeptId == deptId);
+            var info = DeptService.GetFirst(f => f.deptId == deptId);
             return SUCCESS(info);
         }
 
@@ -118,17 +120,18 @@ namespace Controllers
         /// </summary>
         /// <param name="dept"></param>
         /// <returns></returns>
-        [HttpPost]
-        [Log(Title = "部门管理", BusinessType = BusinessType.INSERT)]
-        [ActionPermissionFilter(Permission = "system:dept:add")]
+        [HttpPost("/v1/skb/sysServer/dept/add")]
         public IActionResult Add([FromBody] SysDept dept)
         {
             if (UserConstants.NOT_UNIQUE.Equals(DeptService.CheckDeptNameUnique(dept)))
             {
-                return ToResponse(ResultCode.CUSTOM_ERROR, $"新增部门{dept.Name}失败,部门名称已存在");
+                return ToResponse(ResultCode.CUSTOM_ERROR, $"新增部门{dept.name}失败,部门名称已存在");
             }
-            dept.CreateBy = HttpContext.GetName();
-            return ToResponse(DeptService.InsertDept(dept));
+            TokenModel loginUser = JwtUtil.GetLoginUser(HttpContext);
+            dept.CreateBy = loginUser.username;
+            dept.UpdateBy = loginUser.username;
+            dept.DelFlag = "0";
+            return SUCCESS(DeptService.InsertDept(dept));
         }
 
         /// <summary>
@@ -136,42 +139,39 @@ namespace Controllers
         /// </summary>
         /// <param name="dept"></param>
         /// <returns></returns>
-        [HttpPut]
-        [Log(Title = "部门管理", BusinessType = BusinessType.UPDATE)]
-        [ActionPermissionFilter(Permission = "system:dept:update")]
+        [HttpPut("/v1/skb/sysServer/dept/update")]
         public IActionResult Update([FromBody] SysDept dept)
         {
             if (UserConstants.NOT_UNIQUE.Equals(DeptService.CheckDeptNameUnique(dept)))
             {
-                return ToResponse(ResultCode.CUSTOM_ERROR, $"修改部门{dept.Name}失败,部门名称已存在");
+                return ToResponse(ResultCode.CUSTOM_ERROR, $"修改部门{dept.name}失败,部门名称已存在");
             }
-            else if (dept.ParentId.Equals(dept.DeptId))
+            else if (dept.parentId.Equals(dept.deptId))
             {
-                return ToResponse(ResultCode.CUSTOM_ERROR, $"修改部门{dept.Name}失败,上级部门不能是自己");
+                return ToResponse(ResultCode.CUSTOM_ERROR, $"修改部门{dept.name}失败,上级部门不能是自己");
             }
-            dept.UpdateBy = HttpContext.GetName();
-            return ToResponse(DeptService.UpdateDept(dept));
+            TokenModel loginUser = JwtUtil.GetLoginUser(HttpContext);
+            dept.UpdateBy = loginUser.username;
+            return SUCCESS(DeptService.UpdateDept(dept));
         }
 
         /// <summary>
         /// 删除部门
         /// </summary>
         /// <returns></returns>
-        [HttpDelete("{deptId}")]
-        [ActionPermissionFilter(Permission = "system:dept:remove")]
-        [Log(Title = "部门管理", BusinessType = BusinessType.DELETE)]
-        public IActionResult Remove(long deptId)
+        [HttpDelete("/v1/skb/sysServer/dept/removeById/{id}")]
+        public IActionResult Remove(int id)
         {
-            if (DeptService.Queryable().Count(it => it.ParentId == deptId && it.DelFlag == "0") > 0)
+            if (DeptService.Queryable().Count(it => it.parentId == id && it.DelFlag == "0") > 0)
             {
                 return ToResponse(ResultCode.CUSTOM_ERROR, $"存在下级部门,不允许删除");
             }
-            if (UserService.Queryable().Count(it => it.deptId == deptId && it.DelFlag == "0") > 0)
+            if (UserService.Queryable().Count(it => it.deptId == id && it.DelFlag == "0") > 0)
             {
                 return ToResponse(ResultCode.CUSTOM_ERROR, $"部门存在用户,不允许删除");
             }
 
-            return SUCCESS(DeptService.Delete(deptId));
+            return SUCCESS(DeptService.Delete(id));
         }
     }
 }

+ 10 - 4
Controllers/Base/SysUserController.cs

@@ -98,10 +98,11 @@ namespace Controllers
 
             user.RoleIds = parm.role;
             user.PostIds = parm.post;
-            user.password = Function.MD532(Function.CheckNull(user.password));
+            user.salt = Function.get_Random(6);
+            user.password = Function.MD532(Function.CheckNull(user.password) + user.salt);
             TokenModel loginUser = JwtUtil.GetLoginUser(HttpContext);
-            user.CreateBy = loginUser.Username;
-            user.UpdateBy = loginUser.Username;
+            user.CreateBy = loginUser.username;
+            user.UpdateBy = loginUser.username;
             user.LockFlag = "0";
             user.DelFlag = "0";
 
@@ -121,8 +122,13 @@ namespace Controllers
 
             user.RoleIds = parm.role;
             user.PostIds = parm.post;
+            if(!string.IsNullOrEmpty(parm.password))
+            {
+                user.salt = Function.get_Random(6);
+                user.password = Function.MD532(Function.CheckNull(user.password) + user.salt);
+            }
             TokenModel loginUser = JwtUtil.GetLoginUser(HttpContext);
-            user.UpdateBy = loginUser.Username;
+            user.UpdateBy = loginUser.username;
 
             int upResult = UserService.UpdateUser(user);
 

+ 1 - 1
Extensions/HttpContextExtension.cs

@@ -76,7 +76,7 @@ namespace Extensions
         public static long GetUId(this HttpContext context)
         {
             TokenModel loginUser = JwtUtil.GetLoginUser(context);
-            return loginUser.UserId;
+            return loginUser.userId;
             // var uid = context.User.FindFirstValue(ClaimTypes.PrimarySid);
             // return !string.IsNullOrEmpty(uid) ? long.Parse(uid) : 0;
         }

+ 3 - 3
Filters/ActionPermissionFilter.cs

@@ -43,9 +43,9 @@ namespace Middleware
         {
             TokenModel info = JwtUtil.GetLoginUser(context.HttpContext);
 
-            if (info != null && info?.UserId > 0)
+            if (info != null && info?.userId > 0)
             {
-                long userId = info.UserId;
+                long userId = info.userId;
                 List<string> perms = CacheService.GetUserPerms(GlobalConstant.UserPermKEY + userId);
                 List<string> rolePerms = info.RoleIds;
 
@@ -76,7 +76,7 @@ namespace Middleware
                 var url = context.HttpContext.Request.Path;
                 if (!HasPermi && !Permission.Equals("common"))
                 {
-                    logger.Info($"用户{info.Username}没有权限访问{url},当前权限[{Permission}]");
+                    logger.Info($"用户{info.username}没有权限访问{url},当前权限[{Permission}]");
                     JsonResult result = new(new ApiResult((int)ResultCode.FORBIDDEN, $"你当前没有权限访问,请联系管理员", url))
                     {
                         ContentType = "application/json",

+ 1 - 0
Filters/GlobalActionMonitor.cs

@@ -86,6 +86,7 @@ namespace Middleware
                                             string ParameterType = propertyInfos[i].GetMethod.ReturnParameter.ParameterType.Name;
                                             if (ParameterType == "Int32")
                                             {
+                                                if(value == null || value == "") value = "0";
                                                 value = Convert.ToInt32(value);
                                             }
                                             else if (ParameterType == "Int64[]")

+ 2 - 2
Filters/VerifyAttribute.cs

@@ -50,7 +50,7 @@ namespace Filters
 
                 //Console.WriteLine($"jwt到期剩余:{ts.TotalMinutes}分,{ts.TotalSeconds}秒");
 
-                var CK = "token_" + loginUser.UserId;
+                var CK = "token_" + loginUser.userId;
                 if (!CacheHelper.Exists(CK) && ts.TotalMinutes < 5)
                 {
                     var newToken = JwtUtil.GenerateJwtToken(JwtUtil.AddClaims(loginUser));
@@ -61,7 +61,7 @@ namespace Filters
                     {
                         context.HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "X-Refresh-Token");
                     }
-                    logger.Info($"刷新token,userName={loginUser.Username},token={newToken}");
+                    logger.Info($"刷新token,userName={loginUser.username},token={newToken}");
                     context.HttpContext.Response.Headers.Add("X-Refresh-Token", newToken);
                 }
             }

+ 8 - 8
Model/Base/SysDept.cs

@@ -10,36 +10,36 @@ namespace Model
         /// <summary>
         /// 部门ID
         /// </summary>
-        [SugarColumn(ColumnDescription = "部门ID", ColumnName = "dept_id")]
-        public long DeptId { get; set; }
+        [SugarColumn(ColumnDescription = "部门ID", IsPrimaryKey = true, IsIdentity = true, ColumnName = "dept_id")]
+        public long deptId { get; set; }
 
 
         /// <summary>
         /// 部门名称
         /// </summary>
         [SugarColumn(ColumnDescription = "部门名称", Length = 50, ColumnName = "name")]
-        public string Name { get; set; }
+        public string? name { get; set; }
 
 
         /// <summary>
         /// 排序
         /// </summary>
         [SugarColumn(ColumnDescription = "排序", ColumnName = "sort_order")]
-        public int SortOrder { get; set; }
+        public int sortOrder { get; set; }
 
 
         /// <summary>
         /// 创建人
         /// </summary>
         [SugarColumn(ColumnDescription = "创建人", Length = 64, ColumnName = "create_by")]
-        public string CreateBy { get; set; }
+        public string? CreateBy { get; set; }
 
 
         /// <summary>
         /// 修改人
         /// </summary>
         [SugarColumn(ColumnDescription = "修改人", Length = 64, ColumnName = "update_by")]
-        public string UpdateBy { get; set; }
+        public string? UpdateBy { get; set; }
 
 
         /// <summary>
@@ -60,14 +60,14 @@ namespace Model
         /// 删除标志
         /// </summary>
         [SugarColumn(ColumnDescription = "删除标志", Length = 1, ColumnName = "del_flag")]
-        public string DelFlag { get; set; }
+        public string? DelFlag { get; set; }
 
 
         /// <summary>
         /// 父级部门ID
         /// </summary>
         [SugarColumn(ColumnDescription = "父级部门ID", ColumnName = "parent_id")]
-        public long ParentId { get; set; }
+        public long parentId { get; set; }
 
 
         /// <summary>

+ 6 - 6
Model/Base/TokenModel.cs

@@ -2,9 +2,9 @@
 {
     public class TokenModel
     {
-        public long UserId { get; set; }
-        public long DeptId { get; set; }
-        public string Username { get; set; }
+        public long userId { get; set; }
+        public long deptId { get; set; }
+        public string username { get; set; }
         /// <summary>
         /// 角色集合
         /// </summary>
@@ -27,9 +27,9 @@
 
         public TokenModel(TokenModel info, List<Roles> roles)
         {
-            UserId = info.UserId;
-            Username = info.Username;
-            DeptId = info.DeptId;
+            userId = info.userId;
+            username = info.username;
+            deptId = info.deptId;
             Roles = roles;
             RoleIds = roles.Select(f => f.RoleKey).ToList();
         }

+ 12 - 12
Model/Dto/Base/SysDeptDto.cs

@@ -5,29 +5,29 @@ namespace Dto
 {
     public class SysDeptQueryDto : PagerInfo
     {
-        public int? DelFlag { get; set; }
-        public string DeptName { get; set; }
+        public int? delFlag { get; set; }
+        public string? deptName { get; set; }
     }
     public class SysDeptDto : SysBase
     {
-        public long DeptId { get; set; }
+        public long deptId { get; set; }
 
-        public long ParentId { get; set; }
+        public long parentId { get; set; }
 
-        public string Ancestors { get; set; }
+        public string? ancestors { get; set; }
 
-        public string DeptName { get; set; }
+        public string? deptName { get; set; }
 
-        public int OrderNum { get; set; }
+        public int orderNum { get; set; }
 
-        public string Leader { get; set; }
+        public string? leader { get; set; }
 
-        public string Phone { get; set; }
+        public string? phone { get; set; }
 
-        public string Email { get; set; }
+        public string? email { get; set; }
 
-        public int Status { get; set; }
+        public int status { get; set; }
 
-        public int DelFlag { get; set; }
+        public int delFlag { get; set; }
     }
 }

+ 1 - 0
Model/Dto/Base/SysUserDto.cs

@@ -5,6 +5,7 @@
         public long userId { get; set; }
         public string? username { get; set; }
         public string? nickname { get; set; }
+        public string? name { get; set; }
         public string? email { get; set; }
         public string? remark { get; set; }
         public string? phone { get; set; }

+ 2 - 2
Model/Vo/Base/TreeSelectVo.cs

@@ -56,8 +56,8 @@ namespace Vo
 
         public TreeSelectVo(SysDept dept)
         {
-            Id = dept.DeptId;
-            Name = dept.Name;
+            Id = dept.deptId;
+            Name = dept.name;
 
             List<TreeSelectVo> child = new List<TreeSelectVo>();
             foreach (var item in dept.children)

+ 25 - 23
Services/Base/SysDeptService.cs

@@ -29,7 +29,7 @@ namespace Services
         {
             var predicate = Expressionable.Create<SysDept>();
             predicate = predicate.And(it => it.DelFlag == "0");
-            predicate = predicate.AndIF(dept.DeptName.IfNotEmpty(), it => it.Name.Contains(dept.DeptName));
+            predicate = predicate.AndIF(dept.deptName.IfNotEmpty(), it => it.name.Contains(dept.deptName));
 
             var response = GetList(predicate.ToExpression());
 
@@ -43,9 +43,9 @@ namespace Services
         /// <returns></returns>
         public string CheckDeptNameUnique(SysDept dept)
         {
-            long deptId = dept.DeptId == 0 ? -1L : dept.DeptId;
-            SysDept info = GetFirst(it => it.Name == dept.Name && it.ParentId == dept.ParentId);
-            if (info != null && info.DeptId != deptId)
+            long deptId = dept.deptId == 0 ? -1L : dept.deptId;
+            SysDept info = GetFirst(it => it.name == dept.name && it.parentId == dept.parentId);
+            if (info != null && info.deptId != deptId)
             {
                 return UserConstants.NOT_UNIQUE;
             }
@@ -59,19 +59,20 @@ namespace Services
         /// <returns></returns>
         public int InsertDept(SysDept dept)
         {
-            // SysDept info = GetFirst(it => it.DeptId == dept.ParentId);
-            // //如果父节点不为正常状态,则不允许新增子节点
-            // if (info != null && UserConstants.DEPT_NORMAL != info?.Status)
+            // SysDept info = GetFirst(it => it.deptId == dept.parentId);
+            //如果父节点不为正常状态,则不允许新增子节点
+            // if (info != null && UserConstants.DEPT_NORMAL != info?.status)
             // {
             //     throw new CustomException("部门停用,不允许新增");
             // }
-            // dept.Ancestors = "";
+            // dept.ancestors = "";
             // if (info != null)
             // {
-            //     dept.Ancestors = info.Ancestors + "," + dept.ParentId;
+            //     dept.ancestors = info.ancestors + "," + dept.parentId;
             // }
-            // return Add(dept);
-            return 0;
+            dept.CreateTime = DateTime.Now;
+            dept.UpdateTime = DateTime.Now;
+            return Add(dept);
         }
 
         /// <summary>
@@ -81,14 +82,15 @@ namespace Services
         /// <returns></returns>
         public int UpdateDept(SysDept dept)
         {
-            // SysDept newParentDept = GetFirst(it => it.DeptId == dept.ParentId);
-            // SysDept oldDept = GetFirst(m => m.DeptId == dept.DeptId);
+            dept.UpdateTime = DateTime.Now;
+            // SysDept newParentDept = GetFirst(it => it.deptId == dept.parentId);
+            // SysDept oldDept = GetFirst(m => m.deptId == dept.deptId);
             // if (newParentDept != null && oldDept != null)
             // {
-            //     string newAncestors = newParentDept.Ancestors + "," + newParentDept.DeptId;
-            //     string oldAncestors = oldDept.Ancestors;
-            //     dept.Ancestors = newAncestors;
-            //     UpdateDeptChildren(dept.DeptId, newAncestors, oldAncestors);
+            //     string newAncestors = newParentDept.ancestors + "," + newParentDept.deptId;
+            //     string oldAncestors = oldDept.ancestors;
+            //     dept.ancestors = newAncestors;
+            //     UpdateDeptChildren(dept.deptId, newAncestors, oldAncestors);
             // }
             // int result = Context.Updateable(dept).ExecuteCommand();
             // if (UserConstants.DEPT_NORMAL.Equals(dept.Status) && dept.Ancestors.IfNotEmpty()
@@ -97,8 +99,8 @@ namespace Services
             //     // 如果该部门是启用状态,则启用该部门的所有上级部门
             //     UpdateParentDeptStatusNormal(dept);
             // }
-            // return result;
-            return 0;
+            int result = Update(dept, true);
+            return result;
         }
 
         /// <summary>
@@ -122,7 +124,7 @@ namespace Services
         /// <param name="oldAncestors">旧的父ID集合</param>
         public void UpdateDeptChildren(long deptId, string newAncestors, string oldAncestors)
         {
-            // List<SysDept> children = GetChildrenDepts(GetSysDepts(new SysDeptQueryDto()), deptId);
+            List<SysDept> children = GetChildrenDepts(GetSysDepts(new SysDeptQueryDto()), deptId);
 
             // foreach (var child in children)
             // {
@@ -161,11 +163,11 @@ namespace Services
         public List<SysDept> BuildDeptTree(List<SysDept> depts)
         {
             List<SysDept> returnList = new List<SysDept>();
-            List<long> tempList = depts.Select(f => f.DeptId).ToList();
+            List<long> tempList = depts.Select(f => f.deptId).ToList();
             foreach (var dept in depts)
             {
                 // 如果是顶级节点, 遍历该父节点的所有子节点
-                if (!tempList.Contains(dept.ParentId))
+                if (!tempList.Contains(dept.parentId))
                 {
                     RecursionFn(depts, dept);
                     returnList.Add(dept);
@@ -221,7 +223,7 @@ namespace Services
         /// <returns></returns>
         private List<SysDept> GetChildList(List<SysDept> list, SysDept dept)
         {
-            return list.Where(p => p.ParentId == dept.DeptId).ToList();
+            return list.Where(p => p.parentId == dept.deptId).ToList();
         }
 
         #region 角色部门

+ 2 - 2
Services/Base/SysLoginService.cs

@@ -68,8 +68,8 @@ namespace Services
             OAuthVo info = new ();
             info.access_token = JwtUtil.GenerateJwtToken(JwtUtil.AddClaims(loginUser));
             info.refresh_token = Guid.NewGuid().ToString();
-            info.user_id = loginUser.UserId;
-            info.username = loginUser.Username;
+            info.user_id = loginUser.userId;
+            info.username = loginUser.username;
             
             JwtSettings jwtSettings = new();
             AppSettings.Bind("JwtSettings", jwtSettings);