From 695571c6009ecbc12e7d4a4fb147df7967a1260e Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期一, 07 七月 2025 20:21:19 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/MeiRuiAn/HuaiAn
---
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs | 201 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 195 insertions(+), 6 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs"
index 030a5ea..3a58e39 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs"
@@ -15,6 +15,8 @@
using WIDESEA_Model.Models;
using WIDESEA_Model.Models.System;
using WIDESEA_SystemRepository;
+using WIDESEA_Core.Helper;
+using WIDESEA_Core.HostedService;
namespace WIDESEA_SystemService
{
@@ -35,6 +37,98 @@
_RoleAuthRepository = roleAuthRepository;
}
+ public override WebResponseContent AddData(SaveModel saveModel)
+ {
+ string authorityScope = saveModel.MainData["authorityScope"].ToString() ?? "";
+ Sys_Role role = saveModel.MainData.DicToModel<Sys_Role>();
+ if (BaseDal.QueryFirst(x => x.RoleName == role.RoleName) != null)
+ {
+ return WebResponseContent.Instance.Error($"瑙掕壊鍚嶉噸澶�");
+ }
+ List<Dt_Warehouse> warehouses = BaseDal.Db.Queryable<Dt_Warehouse>().Where(x => true).ToList();
+ List<Sys_RoleDataPermission> roleDataPermissions = new List<Sys_RoleDataPermission>();
+ if (!string.IsNullOrEmpty(authorityScope))
+ {
+ string[] scopes = authorityScope.Split(',');
+ foreach (string scope in scopes)
+ {
+ Dt_Warehouse? warehouse = warehouses.FirstOrDefault(x => x.WarehouseId == Convert.ToInt32(scope));
+ if (warehouse != null)
+ {
+ roleDataPermissions.Add(new Sys_RoleDataPermission
+ {
+ WarehouseId = warehouse.WarehouseId,
+ WarehouseName = warehouse.WarehouseName,
+ RoleName = role.RoleName
+ });
+ }
+ }
+ }
+
+ int roleId = BaseDal.AddData(role);
+ if (roleDataPermissions.Count > 0)
+ {
+ roleDataPermissions.ForEach(x => { x.RoleId = roleId; });
+ BaseDal.Db.Insertable(roleDataPermissions).ExecuteCommand();
+ }
+
+ PermissionDataHostService.UserRoles = PermissionDataHostService.GetUserRoles(Db);
+
+ return WebResponseContent.Instance.OK();
+ }
+
+ public override WebResponseContent UpdateData(SaveModel saveModel)
+ {
+ string authorityScope = saveModel.MainData["authorityScope"].ToString() ?? "";
+ Sys_Role role = saveModel.MainData.DicToModel<Sys_Role>();
+ if (BaseDal.QueryFirst(x => x.RoleId == role.RoleId) == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒拌鏁版嵁");
+ }
+ List<Dt_Warehouse> warehouses = BaseDal.Db.Queryable<Dt_Warehouse>().Where(x => true).ToList();
+
+ List<Sys_RoleDataPermission> oldDatas = BaseDal.Db.Queryable<Sys_RoleDataPermission>().Where(x => x.RoleId == role.RoleId).ToList();
+ List<Sys_RoleDataPermission> roleDataPermissions = new List<Sys_RoleDataPermission>();
+ if (!string.IsNullOrEmpty(authorityScope))
+ {
+ string[] scopes = authorityScope.Split(',');
+ foreach (string scope in scopes)
+ {
+ Sys_RoleDataPermission? oldData = oldDatas.FirstOrDefault(x => x.WarehouseId == Convert.ToInt32(scope));
+ if (oldData == null)
+ {
+ Dt_Warehouse? warehouse = warehouses.FirstOrDefault(x => x.WarehouseId == Convert.ToInt32(scope));
+ if (warehouse != null)
+ {
+ roleDataPermissions.Add(new Sys_RoleDataPermission
+ {
+ WarehouseId = warehouse.WarehouseId,
+ WarehouseName = warehouse.WarehouseName,
+ RoleName = role.RoleName
+ });
+ }
+ }
+ else
+ {
+ oldDatas.Remove(oldData);
+ }
+ }
+ }
+
+ roleDataPermissions.ForEach(x => { x.RoleId = role.RoleId; });
+ BaseDal.Db.Insertable(roleDataPermissions).ExecuteCommand();
+ BaseDal.Db.Deleteable(oldDatas).ExecuteCommand();
+
+ PermissionDataHostService.UserRoles = PermissionDataHostService.GetUserRoles(Db);
+
+ return WebResponseContent.Instance.OK();
+ }
+
+ public List<int> GetAllChildrenRoleId(int roleId)
+ {
+ return GetAllChildren(roleId).Select(x => x.Id).ToList();
+ }
+
public List<RoleNodes> GetAllChildren(int roleId)
{
if (roleId <= 0) return new List<RoleNodes>() { };
@@ -45,7 +139,7 @@
return list;
}
- public List<RoleNodes> GetAllRoleId()
+ public List<RoleNodes> GetAllRoleId()
{
List<RoleNodes> roles = BaseDal.QueryData().Select(s => new RoleNodes() { Id = s.RoleId, ParentId = s.ParentId, RoleName = s.RoleName }).ToList();
@@ -110,7 +204,7 @@
//鑾峰彇鐢ㄦ埛鏉冮檺
List<Permissions> permissions = _MenuRepository.GetPermissions(roleId);
//鏉冮檺鐢ㄦ埛鏉冮檺鏌ヨ鎵�鏈夌殑鑿滃崟淇℃伅
- List<MenuDTO> menus = _MenuService.GetUserMenuList(roleId);
+ List<MenuDTO> menus = _MenuService.GetUserMenuList(roleId);
//鑾峰彇褰撳墠鐢ㄦ埛鏉冮檺濡�:(Add,Search)瀵瑰簲鐨勬樉绀烘枃鏈俊鎭:Add锛氭坊鍔狅紝Search:鏌ヨ
var data = menus.Select(x => new
{
@@ -156,7 +250,7 @@
List<MenuDTO> menus = _MenuService.GetUserMenuListPDA(roleId);
//鑾峰彇褰撳墠鐢ㄦ埛鏉冮檺濡�:(Add,Search)瀵瑰簲鐨勬樉绀烘枃鏈俊鎭:Add锛氭坊鍔狅紝Search:鏌ヨ
- var data = menus.Where(x => x.MenuType==1).Select(x => new
+ var data = menus.Where(x => x.MenuType == 1).Select(x => new
{
Id = x.MenuId,
Pid = x.ParentId,
@@ -184,9 +278,11 @@
//褰撳墠鐢ㄦ埛鐨勬潈闄�
List<Permissions> permissions = _MenuRepository.GetPermissions(App.User.RoleId);
+ List<int> menuIds = _MenuRepository.QueryData(x => x.MenuId, x => x.MenuType == 1);
+
List<int> originalMeunIds = new List<int>();
//琚垎閰嶈鑹茬殑鏉冮檺
- List<Sys_RoleAuth> roleAuths = _RoleAuthRepository.QueryData(x => x.RoleId == roleId);
+ List<Sys_RoleAuth> roleAuths = _RoleAuthRepository.QueryData(x => x.RoleId == roleId && menuIds.Contains(x.MenuId));
List<Sys_RoleAuth> updateAuths = new List<Sys_RoleAuth>();
foreach (UserPermissionDTO x in userPermissions)
{
@@ -239,11 +335,104 @@
x.AuthValue = "";
});
//灏嗗彇娑堢殑鏉冮檺璁剧疆涓�""
- _RoleAuthRepository.UpdateData(delAuths);
+ _RoleAuthRepository.DeleteData(delAuths);
int addCount = updateAuths.Where(x => x.AuthId <= 0).Count();
int updateCount = updateAuths.Where(x => x.AuthId > 0).Count();
-
+
+ string _version = DateTime.Now.ToString("yyyyMMddHHMMssfff");
+
+
+ content.OK($"淇濆瓨鎴愬姛锛氭柊澧炲姞閰嶈彍鍗曟潈闄恵addCount}鏉�,鏇存柊鑿滃崟{updateCount}鏉�,鍒犻櫎鏉冮檺{delAuths.Count}鏉�");
+ }
+ catch (Exception ex)
+ {
+ message = "寮傚父淇℃伅锛�" + ex.Message + ex.StackTrace + ",";
+ }
+
+ return content;
+ }
+
+ /// <summary>
+ /// 淇濆瓨瑙掕壊鏉冮檺
+ /// </summary>
+ /// <param name="userPermissions"></param>
+ /// <param name="roleId"></param>
+ /// <returns></returns>
+ public WebResponseContent SavePermissionPDA(List<UserPermissionDTO> userPermissions, int roleId)
+ {
+ WebResponseContent content = new WebResponseContent();
+ string message = "";
+ try
+ {
+ if (!GetAllChildren(App.User.RoleId).Exists(x => x.Id == roleId))
+ return WebResponseContent.Instance.Error("娌℃湁鏉冮檺淇敼姝よ鑹茬殑鏉冮檺淇℃伅");
+ //褰撳墠鐢ㄦ埛鐨勬潈闄�
+ List<Permissions> permissions = _MenuRepository.GetPermissions(App.User.RoleId);
+
+ List<int> originalMeunIds = new List<int>();
+
+ List<int> menuIds = _MenuRepository.QueryData(x => x.MenuId, x => x.MenuType == 1);
+
+ //琚垎閰嶈鑹茬殑鏉冮檺
+ List<Sys_RoleAuth> roleAuths = _RoleAuthRepository.QueryData(x => x.RoleId == roleId && menuIds.Contains(x.MenuId));
+ List<Sys_RoleAuth> updateAuths = new List<Sys_RoleAuth>();
+ foreach (UserPermissionDTO x in userPermissions)
+ {
+ Permissions per = permissions.FirstOrDefault(p => p.MenuId == x.Id);
+ //涓嶈兘鍒嗛厤瓒呰繃褰撳墠鐢ㄦ埛鐨勬潈闄�
+ if (per == null) continue;
+ //per.UserAuthArr.Contains(a.Value)鏍¢獙鏉冮檺鑼冨洿
+ string[] arr = x.Actions == null || x.Actions.Count == 0
+ ? new string[0]
+ : x.Actions.Where(a => per.UserAuthArr.Contains(a.Value))
+ .Select(s => s.Value).ToArray();
+
+ //濡傛灉褰撳墠鏉冮檺娌℃湁鍒嗛厤杩囷紝璁剧疆Auth_Id榛樿涓�0锛岃〃绀烘柊澧炵殑鏉冮檺
+ var auth = roleAuths.Where(r => r.MenuId == x.Id).Select(s => new { s.AuthId, s.AuthValue, s.MenuId }).FirstOrDefault();
+ string newAuthValue = string.Join(",", arr);
+ //鏉冮檺娌℃湁鍙戠敓鍙樺寲鍒欎笉澶勭悊
+ if (auth == null || auth.AuthValue != newAuthValue)
+ {
+ updateAuths.Add(new Sys_RoleAuth()
+ {
+ RoleId = roleId,
+ MenuId = x.Id,
+ AuthValue = string.Join(",", arr),
+ AuthId = auth == null ? 0 : auth.AuthId,
+ ModifyDate = DateTime.Now,
+ Modifier = App.User.UserName,
+ CreateDate = DateTime.Now,
+ Creater = App.User.UserName
+ });
+ }
+ else
+ {
+ originalMeunIds.Add(auth.MenuId);
+ }
+
+ }
+ //鏇存柊鏉冮檺
+ _RoleAuthRepository.UpdateData(updateAuths);
+ //鏂板鐨勬潈闄�
+ _RoleAuthRepository.AddData(updateAuths);
+
+ //鑾峰彇鏉冮檺鍙栨秷鐨勬潈闄�
+ int[] authIds = roleAuths.Where(x => userPermissions.Select(u => u.Id)
+ .ToList().Contains(x.MenuId) || originalMeunIds.Contains(x.MenuId))
+ .Select(s => s.AuthId)
+ .ToArray();
+ List<Sys_RoleAuth> delAuths = roleAuths.Where(x => x.AuthValue != "" && !authIds.Contains(x.AuthId)).ToList();
+ delAuths.ForEach(x =>
+ {
+ x.AuthValue = "";
+ });
+ //灏嗗彇娑堢殑鏉冮檺璁剧疆涓�""
+ _RoleAuthRepository.DeleteData(delAuths);
+
+ int addCount = updateAuths.Where(x => x.AuthId <= 0).Count();
+ int updateCount = updateAuths.Where(x => x.AuthId > 0).Count();
+
string _version = DateTime.Now.ToString("yyyyMMddHHMMssfff");
--
Gitblit v1.9.3