From 4f39dcc195f28fa275fc2d065fbf1bf6a46c21b7 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 17 六月 2025 00:41:18 +0800
Subject: [PATCH] 优化出入库逻辑

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_DictionaryService.cs |  464 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 427 insertions(+), 37 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_DictionaryService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_DictionaryService.cs"
index 7ee22e0..9b01901 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_DictionaryService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_DictionaryService.cs"
@@ -1,4 +1,5 @@
 锘縰sing Newtonsoft.Json;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Information;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -6,8 +7,10 @@
 using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Core;
 using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.BaseServices;
+using WIDESEA_Core.Caches;
 using WIDESEA_Core.DB;
 using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
@@ -21,63 +24,105 @@
     public class Sys_DictionaryService : ServiceBase<Sys_Dictionary, ISys_DictionaryRepository>, ISys_DictionaryService
     {
         private readonly IUnitOfWorkManage _unitOfWorkManage;
-        public Sys_DictionaryService(ISys_DictionaryRepository BaseDal, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
+        private readonly ICacheService _cacheService;
+        private readonly ISys_RoleService _sys_RoleService;
+
+        public Sys_DictionaryService(ISys_DictionaryRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, ICacheService cacheService, ISys_RoleService sys_RoleService) : base(BaseDal)
         {
             _unitOfWorkManage = unitOfWorkManage;
+            _cacheService = cacheService;
+            _sys_RoleService = sys_RoleService;
         }
 
         public ISys_DictionaryRepository Repository => BaseDal;
 
+        public override WebResponseContent AddData(SaveModel saveModel)
+        {
+            Sys_Dictionary dictionary = saveModel.MainData.DicToModel<Sys_Dictionary>();
+            _cacheService.Remove(dictionary.DicNo);
+            return base.AddData(saveModel);
+        }
+
+        public override WebResponseContent UpdateData(SaveModel saveModel)
+        {
+            Sys_Dictionary dictionary = saveModel.MainData.DicToModel<Sys_Dictionary>();
+            _cacheService.Remove(dictionary.DicNo);
+            return base.UpdateData(saveModel);
+        }
+
         public List<VueDictionaryDTO> GetVueDictionary(string[] dicNos)
         {
             if (dicNos == null || dicNos.Count() == 0) return new List<VueDictionaryDTO>();
+            List<VueDictionaryDTO> vueDictionaryDTOs = new List<VueDictionaryDTO>();
 
-            var dicConfig = BaseDal.GetDictionaries(dicNos, false).Select(s => new
+            List<string> cacheDicNos = new List<string>();
+            #region 鏌ヨ鏁版嵁搴撲笅鎷夋鏁版嵁
+            if (dicNos.Where(x => !cacheDicNos.Contains(x)).Count() > 0)
             {
-                dicNo = s.DicNo,
-                config = s.Config,
-                dbSql = s.DBSql,
-                list = s.DicList.OrderByDescending(o => o.OrderNo).Select(list => new { key = list.DicValue, value = list.DicName })
-            }).ToList();
+                var selectDics = BaseDal.GetDictionaries(dicNos.Where(x => !cacheDicNos.Contains(x)), _sys_RoleService.GetAllChildren(App.User.RoleId));
 
-            object GetSourceData(string dicNo, string dbSql, object data)
-            {
-                if (string.IsNullOrEmpty(dbSql))
+                foreach (var item in selectDics)
                 {
-                    return data;
+                    if (!_cacheService.Exists(item.DicNo))
+                    {
+                        vueDictionaryDTOs.Add(item);
+                    }
+                    else
+                    {
+                        VueDictionaryDTO? vueDictionary = JsonConvert.DeserializeObject<VueDictionaryDTO>(_cacheService.Get(item.DicNo));
+                        if (vueDictionary != null && vueDictionary.Data.ToJson() != item.Data.ToJson())
+                        {
+                            vueDictionaryDTOs.Add(item);
+                            _cacheService.AddOrUpdate(item.DicNo, item.Serialize());
+                        }
+                    }
                 }
-                return BaseDal.QueryObjectDataBySql(dbSql, null);
             }
-            List<VueDictionaryDTO> vueDictionaryDTOs = dicConfig.Select(item => new VueDictionaryDTO
+            #endregion
+            foreach (string n in dicNos)
             {
-                DicNo = item.dicNo,
-                Config = item.config,
-                Data = GetSourceData(item.dicNo, item.dbSql, item.list)
-            }).ToList();
+                string str = _cacheService.Get(n);
+                if (!string.IsNullOrEmpty(str))
+                {
+                    VueDictionaryDTO? vueDictionary = JsonConvert.DeserializeObject<VueDictionaryDTO>(str);
+
+                    if (vueDictionary != null && vueDictionaryDTOs.Where(x => x.DicNo == vueDictionary.DicNo).FirstOrDefault() == null)
+                    {
+                        vueDictionaryDTOs.Add(vueDictionary);
+                        cacheDicNos.Add(n);
+                    }
+                }
+            }
 
             try
             {
-                List<string> dicList = dicNos.ToList();
-
-                string str = AppSettings.Configuration["dics"];
-                if (!string.IsNullOrEmpty(str))
+                List<string> dicList = dicNos.Where(x => !cacheDicNos.Contains(x)).ToList();
+                if (dicList.Count() > 0)
                 {
-                    List<string> cusDics = new List<string>();
-
-                    List<string> dics = str.Split(",").ToList();
-
-                    foreach (var item in dics)
+                    string str = AppSettings.Configuration["dics"];
+                    if (!string.IsNullOrEmpty(str))
                     {
-                        dicList.Remove(item);
-                        cusDics.Add(item);
-                    }
+                        List<string> cusDics = new List<string>();
 
-                    foreach (var item in cusDics)
-                    {
-                        VueDictionaryDTO vueDictionaryDTO = GetVueDictionary(item.Trim());
-                        if (vueDictionaryDTO != null)
+                        List<string> dics = str.Split(",").ToList();
+
+                        foreach (var item in dicList)
                         {
-                            vueDictionaryDTOs.Add(vueDictionaryDTO);
+                            if (dics.Contains(item))
+                                cusDics.Add(item);
+                        }
+
+                        foreach (var item in cusDics)
+                        {
+                            VueDictionaryDTO vueDictionaryDTO = GetVueDictionary(item.Trim());
+                            if (vueDictionaryDTO != null)
+                            {
+                                vueDictionaryDTOs.Add(vueDictionaryDTO);
+                                if (!_cacheService.Exists(item))
+                                {
+                                    _cacheService.Add(item, vueDictionaryDTO.Serialize());
+                                }
+                            }
                         }
                     }
                 }
@@ -99,12 +144,36 @@
                     case "inboundState":
                         {
                             List<object> data = new List<object>();
-                            Type type = typeof(InboundStatusEmun);
-                            List<int> enums = Enum.GetValues(typeof(InboundStatusEmun)).Cast<int>().ToList();
+                            Type type = typeof(InboundStatusEnum);
+                            List<int> enums = Enum.GetValues(typeof(InboundStatusEnum)).Cast<int>().ToList();
                             int index = 0;
                             foreach (var item in enums)
                             {
-                                FieldInfo? fieldInfo = typeof(InboundStatusEmun).GetField(((InboundStatusEmun)item).ToString());
+                                FieldInfo? fieldInfo = typeof(InboundStatusEnum).GetField(((InboundStatusEnum)item).ToString());
+                                DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                                if (description != null)
+                                {
+                                    data.Add(new { key = item.ToString(), value = description.Description });
+                                }
+                                else
+                                {
+                                    data.Add(new { key = item.ToString(), value = item.ToString() });
+                                }
+                                index++;
+                            }
+
+                            result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
+                        }
+                        break;
+                    case "outboundStatusEnum":
+                        {
+                            List<object> data = new List<object>();
+                            Type type = typeof(OutboundStatusEnum);
+                            List<int> enums = Enum.GetValues(typeof(OutboundStatusEnum)).Cast<int>().ToList();
+                            int index = 0;
+                            foreach (var item in enums)
+                            {
+                                FieldInfo? fieldInfo = typeof(OutboundStatusEnum).GetField(((OutboundStatusEnum)item).ToString());
                                 DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
                                 if (description != null)
                                 {
@@ -174,6 +243,33 @@
                             result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
                         }
                         break;
+                    case "orderDetailStatusEnum":
+                        {
+                            List<object> data = new List<object>();
+
+                            {
+                                Type type = typeof(OrderDetailStatusEnum);
+                                List<int> enums = Enum.GetValues(typeof(OrderDetailStatusEnum)).Cast<int>().ToList();
+                                int index = 0;
+                                foreach (var item in enums)
+                                {
+                                    FieldInfo? fieldInfo = typeof(OrderDetailStatusEnum).GetField(((OrderDetailStatusEnum)item).ToString());
+                                    DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                                    if (description != null)
+                                    {
+                                        data.Add(new { key = item.ToString(), value = description.Description });
+                                    }
+                                    else
+                                    {
+                                        data.Add(new { key = item.ToString(), value = item.ToString() });
+                                    }
+                                    index++;
+                                }
+                            }
+
+                            result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
+                        }
+                        break;
                     case "createType":
                         {
                             List<object> data = new List<object>();
@@ -201,6 +297,300 @@
                             result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
                         }
                         break;
+                    case "enableEnum":
+                        {
+                            List<object> data = new List<object>();
+
+                            {
+                                Type type = typeof(EnableEnum);
+                                List<int> enums = Enum.GetValues(typeof(EnableEnum)).Cast<int>().ToList();
+                                int index = 0;
+                                foreach (var item in enums)
+                                {
+                                    FieldInfo? fieldInfo = typeof(EnableEnum).GetField(((EnableEnum)item).ToString());
+                                    DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                                    if (description != null)
+                                    {
+                                        data.Add(new { key = item.ToString(), value = description.Description });
+                                    }
+                                    else
+                                    {
+                                        data.Add(new { key = item.ToString(), value = item.ToString() });
+                                    }
+                                    index++;
+                                }
+                            }
+
+                            result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
+                        }
+                        break;
+                    case "enableStatusEnum":
+                        {
+                            List<object> data = new List<object>();
+
+                            {
+                                Type type = typeof(EnableStatusEnum);
+                                List<int> enums = Enum.GetValues(typeof(EnableStatusEnum)).Cast<int>().ToList();
+                                int index = 0;
+                                foreach (var item in enums)
+                                {
+                                    FieldInfo? fieldInfo = typeof(EnableStatusEnum).GetField(((EnableStatusEnum)item).ToString());
+                                    DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                                    if (description != null)
+                                    {
+                                        data.Add(new { key = item.ToString(), value = description.Description });
+                                    }
+                                    else
+                                    {
+                                        data.Add(new { key = item.ToString(), value = item.ToString() });
+                                    }
+                                    index++;
+                                }
+                            }
+
+                            result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
+                        }
+                        break;
+                    case "locationStatusEnum":
+                        {
+                            List<object> data = new List<object>();
+
+                            {
+                                Type type = typeof(LocationStatusEnum);
+                                List<int> enums = Enum.GetValues(typeof(LocationStatusEnum)).Cast<int>().ToList();
+                                int index = 0;
+                                foreach (var item in enums)
+                                {
+                                    FieldInfo? fieldInfo = typeof(LocationStatusEnum).GetField(((LocationStatusEnum)item).ToString());
+                                    DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                                    if (description != null)
+                                    {
+                                        data.Add(new { key = item.ToString(), value = description.Description });
+                                    }
+                                    else
+                                    {
+                                        data.Add(new { key = item.ToString(), value = item.ToString() });
+                                    }
+                                    index++;
+                                }
+                            }
+
+                            result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
+                        }
+                        break;
+                    case "locationTypeEnum":
+                        {
+                            List<object> data = new List<object>();
+
+                            {
+                                Type type = typeof(LocationTypeEnum);
+                                List<int> enums = Enum.GetValues(typeof(LocationTypeEnum)).Cast<int>().ToList();
+                                int index = 0;
+                                foreach (var item in enums)
+                                {
+                                    FieldInfo? fieldInfo = typeof(LocationTypeEnum).GetField(((LocationTypeEnum)item).ToString());
+                                    DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                                    if (description != null)
+                                    {
+                                        data.Add(new { key = item.ToString(), value = description.Description });
+                                    }
+                                    else
+                                    {
+                                        data.Add(new { key = item.ToString(), value = item.ToString() });
+                                    }
+                                    index++;
+                                }
+                            }
+
+                            result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
+                        }
+                        break;
+                    case "taskTypeEnum":
+                        {
+                            List<object> data = new List<object>();
+
+                            {
+                                Type type = typeof(TaskTypeEnum);
+                                List<int> enums = Enum.GetValues(typeof(TaskTypeEnum)).Cast<int>().ToList();
+                                int index = 0;
+                                foreach (var item in enums)
+                                {
+                                    FieldInfo? fieldInfo = typeof(TaskTypeEnum).GetField(((TaskTypeEnum)item).ToString());
+                                    DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                                    if (description != null)
+                                    {
+                                        data.Add(new { key = item.ToString(), value = description.Description });
+                                    }
+                                    else
+                                    {
+                                        data.Add(new { key = item.ToString(), value = item.ToString() });
+                                    }
+                                    index++;
+                                }
+                            }
+
+                            result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
+                        }
+                        break;
+                    case "taskStatusEnum":
+                        {
+                            List<object> data = new List<object>();
+
+                            {
+                                Type type = typeof(InTaskStatusEnum);
+                                List<int> enums = Enum.GetValues(typeof(InTaskStatusEnum)).Cast<int>().ToList();
+                                int index = 0;
+                                foreach (var item in enums)
+                                {
+                                    FieldInfo? fieldInfo = typeof(InTaskStatusEnum).GetField(((InTaskStatusEnum)item).ToString());
+                                    DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                                    if (description != null)
+                                    {
+                                        data.Add(new { key = item.ToString(), value = description.Description });
+                                    }
+                                    else
+                                    {
+                                        data.Add(new { key = item.ToString(), value = item.ToString() });
+                                    }
+                                    index++;
+                                }
+                            }
+
+                            {
+                                Type type = typeof(OutTaskStatusEnum);
+                                List<int> enums = Enum.GetValues(typeof(OutTaskStatusEnum)).Cast<int>().ToList();
+                                int index = 0;
+                                foreach (var item in enums)
+                                {
+                                    FieldInfo? fieldInfo = typeof(OutTaskStatusEnum).GetField(((OutTaskStatusEnum)item).ToString());
+                                    DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                                    if (description != null)
+                                    {
+                                        data.Add(new { key = item.ToString(), value = description.Description });
+                                    }
+                                    else
+                                    {
+                                        data.Add(new { key = item.ToString(), value = item.ToString() });
+                                    }
+                                    index++;
+                                }
+                            }
+
+                            {
+                                Type type = typeof(RelocationTaskStatusEnum);
+                                List<int> enums = Enum.GetValues(typeof(RelocationTaskStatusEnum)).Cast<int>().ToList();
+                                int index = 0;
+                                foreach (var item in enums)
+                                {
+                                    FieldInfo? fieldInfo = typeof(RelocationTaskStatusEnum).GetField(((RelocationTaskStatusEnum)item).ToString());
+                                    DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                                    if (description != null)
+                                    {
+                                        data.Add(new { key = item.ToString(), value = description.Description });
+                                    }
+                                    else
+                                    {
+                                        data.Add(new { key = item.ToString(), value = item.ToString() });
+                                    }
+                                    index++;
+                                }
+                            }
+
+                            {
+                                Type type = typeof(AGVTaskStatusEnum);
+                                List<int> enums = Enum.GetValues(typeof(AGVTaskStatusEnum)).Cast<int>().ToList();
+                                int index = 0;
+                                foreach (var item in enums)
+                                {
+                                    FieldInfo? fieldInfo = typeof(AGVTaskStatusEnum).GetField(((AGVTaskStatusEnum)item).ToString());
+                                    DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                                    if (description != null)
+                                    {
+                                        data.Add(new { key = item.ToString(), value = description.Description });
+                                    }
+                                    else
+                                    {
+                                        data.Add(new { key = item.ToString(), value = item.ToString() });
+                                    }
+                                    index++;
+                                }
+                            }
+
+                            result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
+                        }
+                        break;
+                    case "stockStatusEmun":
+                        {
+                            List<object> data = new List<object>();
+                            Type type = typeof(StockStatusEmun);
+                            List<int> enums = Enum.GetValues(typeof(StockStatusEmun)).Cast<int>().ToList();
+                            int index = 0;
+                            foreach (var item in enums)
+                            {
+                                FieldInfo? fieldInfo = typeof(StockStatusEmun).GetField(((StockStatusEmun)item).ToString());
+                                DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                                if (description != null)
+                                {
+                                    data.Add(new { key = item.ToString(), value = description.Description });
+                                }
+                                else
+                                {
+                                    data.Add(new { key = item.ToString(), value = item.ToString() });
+                                }
+                                index++;
+                            }
+
+                            result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
+                        }
+                        break;
+                    case "stockChangeType":
+                        {
+                            List<object> data = new List<object>();
+                            Type type = typeof(StockChangeType);
+                            List<int> enums = Enum.GetValues(typeof(StockChangeType)).Cast<int>().ToList();
+                            int index = 0;
+                            foreach (var item in enums)
+                            {
+                                FieldInfo? fieldInfo = typeof(StockChangeType).GetField(((StockChangeType)item).ToString());
+                                DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                                if (description != null)
+                                {
+                                    data.Add(new { key = item.ToString(), value = description.Description });
+                                }
+                                else
+                                {
+                                    data.Add(new { key = item.ToString(), value = item.ToString() });
+                                }
+                                index++;
+                            }
+
+                            result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
+                        }
+                        break;
+                    case "outStockStatus":
+                        {
+                            List<object> data = new List<object>();
+                            Type type = typeof(OutStockStatus);
+                            List<int> enums = Enum.GetValues(typeof(OutStockStatus)).Cast<int>().ToList();
+                            int index = 0;
+                            foreach (var item in enums)
+                            {
+                                FieldInfo? fieldInfo = typeof(OutStockStatus).GetField(((OutStockStatus)item).ToString());
+                                DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                                if (description != null)
+                                {
+                                    data.Add(new { key = item.ToString(), value = description.Description });
+                                }
+                                else
+                                {
+                                    data.Add(new { key = item.ToString(), value = item.ToString() });
+                                }
+                                index++;
+                            }
+
+                            result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
+                        }
+                        break;
                 }
                 return result;
             }

--
Gitblit v1.9.3