From 2bdad959bc30a7c24bf08ca81fb52fff63e79f52 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期一, 17 二月 2025 21:05:49 +0800
Subject: [PATCH] 优化条码打印功能

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemRepository/Sys_DictionaryRepository.cs |  112 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 94 insertions(+), 18 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemRepository/Sys_DictionaryRepository.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemRepository/Sys_DictionaryRepository.cs"
index f90799d..963a540 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemRepository/Sys_DictionaryRepository.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemRepository/Sys_DictionaryRepository.cs"
@@ -1,13 +1,20 @@
 锘縰sing Microsoft.AspNetCore.DataProtection.KeyManagement;
+using Microsoft.AspNetCore.Routing;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
 using SqlSugar;
 using System;
+using System.Collections;
 using System.Collections.Generic;
+using System.Data;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.BaseRepository;
+using WIDESEAWCS_DTO.System;
 using WIDESEAWCS_ISystemRepository;
 using WIDESEAWCS_Model.Models;
+using WIDESEAWCS_Model.Models.System;
 
 namespace WIDESEAWCS_SystemRepository
 {
@@ -16,47 +23,114 @@
         public Sys_DictionaryRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage)
         {
         }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="dicNos"></param>
-        /// <param name="executeSql">鏄惁鎵ц鑷畾涔塻ql</param>
-        /// <returns></returns>
-        public IEnumerable<Sys_Dictionary> GetDictionaries(IEnumerable<string> dicNos, bool executeSql = true)
+        public IEnumerable<VueDictionaryDTO> GetDictionaries(IEnumerable<string> dicNos, List<RoleNodes> roleNodes, bool executeSql = true)
         {
             List<Sys_Dictionary> Dictionaries = GetAllDictionary();
+            List<VueDictionaryDTO> DictionaryDTO = new List<VueDictionaryDTO>();
+
 
             foreach (var item in Dictionaries.Where(x => dicNos.Contains(x.DicNo)))
             {
+                VueDictionaryDTO dictionaryDTO = new VueDictionaryDTO();
+                dictionaryDTO.DicNo = item.DicNo;
+                dictionaryDTO.Config = item.Config;
+                dictionaryDTO.Data = item.DicList.OrderByDescending(o => o.OrderNo).Select(list => new { key = list.DicValue, value = list.DicName });
                 if (executeSql)
                 {
                     //  2020.05.01澧炲姞鏍规嵁鐢ㄦ埛淇℃伅鍔犺浇瀛楀吀鏁版嵁婧恠ql
                     string sql = item.DBSql;
                     if (!string.IsNullOrEmpty(sql))
                     {
-                        item.DicList = Query(sql);
+                        dictionaryDTO.Data = item.DicNo == "tree_roles" ? 
+                            QueryRole(GetCustomDBSql(item.DicNo, sql, roleNodes)).OrderBy(x => x.id).Select(list => new { id = list.id, parentId = list.parentId, key = list.DicValue, value = list.DicName }) : Query(GetCustomDBSql(item.DicNo, sql, roleNodes)).OrderByDescending(o => o.OrderNo).Select(list => new { key = list.DicValue, value = list.DicName });
                     }
                 }
+                DictionaryDTO.Add(dictionaryDTO);
             }
-
-            return Dictionaries;
+            return DictionaryDTO;
         }
-
-        List<Sys_DictionaryList> Query(string sql)
+        List<SourceKeyVaule> QueryRole(string sql)
         {
             try
             {
-                return base.QueryDynamicDataBySql(sql, null).Select(s => new Sys_DictionaryList()
+                return base.QueryDynamicDataBySql(sql, null).Select(s => new SourceKeyVaule()
                 {
-                    DicName = s.Value,
-                    DicValue = s.Key.ToString()
+                    id = s.id,
+                    parentId = s.parentId,
+                    DicName = s.value,
+                    DicValue = s.key
                 }).ToList();
             }
             catch (Exception ex)
             {
                 throw ex;
             }
+        }
+        List<Sys_DictionaryList> Query(string sql)
+        {
+            try
+            {
+                return base.QueryDynamicDataBySql(sql, null).Select(s => new Sys_DictionaryList()
+                {
+                    DicName = s.value,
+                    DicValue = s.key.ToString()
+                }).ToList();
+            }
+            catch (Exception ex)
+            {
+                throw ex;
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇鑷畾涔夋暟鎹簮sql
+        /// </summary>
+        /// <param name="dicNo"></param>
+        /// <param name="originalSql"></param>
+        /// <returns></returns>
+        public static string GetCustomDBSql(string dicNo, string originalSql, List<RoleNodes> roleNodes)
+        {
+            switch (dicNo)
+            {
+                case "roles":
+                //2020.05.24澧炲姞缁戝畾table琛ㄦ椂锛岃幏鍙栨墍鏈夌殑瑙掕壊鍒楄〃
+                //娉ㄦ剰锛屽鏋滄槸2020.05.24涔嬪墠鑾峰彇鐨勬暟鎹簱鑴氭湰
+                //璇峰湪鑿滃崟銆愪笅鎷夋缁戝畾璁剧疆銆戞坊鍔犱竴涓瓧鍏哥紪鍙枫�恡_roles銆�,闄や簡瀛楀吀缂栧彿锛屽叾浠栧唴瀹归殢渚垮~鍐�
+                case "t_roles":
+                case "tree_roles":
+                    originalSql = GetRolesSql(originalSql, roleNodes);
+                    break;
+                default:
+                    break;
+            }
+            return originalSql;
+        }
+
+        /// <summary>
+        /// 鑾峰彇瑙e喅鐨勬暟鎹簮锛屽彧鑳界湅鍒拌嚜宸变笌涓嬬骇鎵�鏈夎鑹�
+        /// </summary>
+        /// <param name="context"></param>
+        /// <param name="originalSql"></param>
+        /// <returns></returns>
+        public static string GetRolesSql(string originalSql, List<RoleNodes> roleNodes)
+        {
+            if (App.User.IsSuperAdmin)
+            {
+                return originalSql;
+            }
+
+            var RoleNodes = roleNodes.Where(x => x.Id == App.User.RoleId)
+                   .Select(s => new RoleNodes()
+                   {
+                       Id = s.Id,
+                       ParentId = 0,//灏嗚嚜宸辩殑瑙掕壊浣滀负root鑺傜偣
+                       RoleName = s.RoleName
+                   }).ToList();
+            List<int> roleIds = roleNodes.Select(x => x.Id).ToList();
+            //roleIds.Add(App.User.RoleId);
+
+            return originalSql = $@"SELECT RoleId as 'key',RoleId AS id,ParentId AS parentId,RoleName as 'value' FROM Sys_Role 
+                      WHERE Enable=1  and RoleId in ({string.Join(',', roleIds)})";
         }
 
         private List<Sys_Dictionary> GetAllDictionary()
@@ -69,7 +143,9 @@
 
     public class SourceKeyVaule
     {
-        public object Key { get; set; }
-        public string Value { get; set; }
+        public int id { get; set; }
+        public int parentId { get; set; }
+        public string DicName { get; set; }
+        public int DicValue { get; set; }
     }
 }

--
Gitblit v1.9.3