From 8d341db9d2d5699d527c88c935f0c4ce255a57a4 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期二, 10 十二月 2024 16:38:12 +0800
Subject: [PATCH] 代码提交

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs |   92 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 88 insertions(+), 4 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..ff749a1 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,7 @@
 using WIDESEA_Model.Models;
 using WIDESEA_Model.Models.System;
 using WIDESEA_SystemRepository;
+using WIDESEA_Core.Helper;
 
 namespace WIDESEA_SystemService
 {
@@ -35,6 +36,89 @@
             _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();
+            }
+
+            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();
+
+            return WebResponseContent.Instance.OK();
+        }
+
         public List<RoleNodes> GetAllChildren(int roleId)
         {
             if (roleId <= 0) return new List<RoleNodes>() { };
@@ -45,7 +129,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 +194,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 +240,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,
@@ -243,7 +327,7 @@
 
                 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