From c020f31a67fc5aa5644511bddff075f7ecc85234 Mon Sep 17 00:00:00 2001 From: qinchulong <qinchulong@hnkhzn.com> Date: 星期二, 27 五月 2025 15:35:27 +0800 Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/HuaYiZhongHeng/ZhongHeLiTiKu --- 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_DictionaryService.cs | 592 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 592 insertions(+), 0 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" new file mode 100644 index 0000000..9743d4b --- /dev/null +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_DictionaryService.cs" @@ -0,0 +1,592 @@ +锘縰sing Newtonsoft.Json; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +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; +using WIDESEA_DTO.System; +using WIDESEA_ISystemRepository; +using WIDESEA_ISystemService; +using WIDESEA_Model.Models; + +namespace WIDESEA_SystemService +{ + public class Sys_DictionaryService : ServiceBase<Sys_Dictionary, ISys_DictionaryRepository>, ISys_DictionaryService + { + private readonly IUnitOfWorkManage _unitOfWorkManage; + private readonly ICacheService _cacheService; + + public Sys_DictionaryService(ISys_DictionaryRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, ICacheService cacheService) : base(BaseDal) + { + _unitOfWorkManage = unitOfWorkManage; + _cacheService = cacheService; + } + + 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>(); + + List<string> cacheDicNos = new List<string>(); + foreach (string n in dicNos) + { + string str = _cacheService.Get(n); + if (!string.IsNullOrEmpty(str)) + { + VueDictionaryDTO? vueDictionary = JsonConvert.DeserializeObject<VueDictionaryDTO>(str); + + if (vueDictionary != null) + { + vueDictionaryDTOs.Add(vueDictionary); + cacheDicNos.Add(n); + } + } + } + if (dicNos.Where(x => !cacheDicNos.Contains(x)).Count() > 0) + { + List<VueDictionaryDTO> selectDics = BaseDal.GetDictionaries(dicNos.Where(x => !cacheDicNos.Contains(x))).Select(s => new VueDictionaryDTO + { + DicNo = s.DicNo, + Config = s.Config, + //dbSql = s.Sql, + Data = s.DicList.OrderByDescending(o => o.OrderNo).Select(list => new { key = list.DicValue, value = list.DicName }) + }).ToList(); + + foreach (var item in selectDics) + { + if (!_cacheService.Exists(item.DicNo)) + { + _cacheService.Add(item.DicNo, item.Serialize()); + } + } + vueDictionaryDTOs.AddRange(selectDics); + } + + //object GetSourceData(string dicNo, string dbSql, object data) + //{ + // if (string.IsNullOrEmpty(dbSql)) + // { + // return data; + // } + // return BaseDal.QueryObjectDataBySql(dbSql, null); + //} + //List<VueDictionaryDTO> vueDictionaryDTOs = dicConfig.Select(item => new VueDictionaryDTO + //{ + // DicNo = item.dicNo, + // Config = item.config, + // Data = GetSourceData(item.dicNo, item.dbSql, item.list) + //}).ToList(); + + try + { + List<string> dicList = dicNos.ToList(); + if (dicNos.Where(x => !cacheDicNos.Contains(x)).Count() > 0) + { + string str = AppSettings.Configuration["dics"]; + if (!string.IsNullOrEmpty(str)) + { + List<string> cusDics = new List<string>(); + + List<string> dics = str.Split(",").ToList(); + + foreach (var item in dics) + { + dicList.Remove(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()); + } + } + } + } + } + } + catch + { + + } + return vueDictionaryDTOs; + } + + private VueDictionaryDTO GetVueDictionary(string key) + { + VueDictionaryDTO result = null; + try + { + switch (key) + { + case "inboundState": + { + List<object> data = new List<object>(); + 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(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) + { + 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 "inOrderType": + { + List<object> data = new List<object>(); + + { + Type type = typeof(InOrderTypeEnum); + List<int> enums = Enum.GetValues(typeof(InOrderTypeEnum)).Cast<int>().ToList(); + int index = 0; + foreach (var item in enums) + { + FieldInfo? fieldInfo = typeof(InOrderTypeEnum).GetField(((InOrderTypeEnum)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 "outOrderType": + { + List<object> data = new List<object>(); + + { + Type type = typeof(OutOrderTypeEnum); + List<int> enums = Enum.GetValues(typeof(OutOrderTypeEnum)).Cast<int>().ToList(); + int index = 0; + foreach (var item in enums) + { + FieldInfo? fieldInfo = typeof(OutOrderTypeEnum).GetField(((OutOrderTypeEnum)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 "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>(); + + { + Type type = typeof(CreateType); + List<int> enums = Enum.GetValues(typeof(CreateType)).Cast<int>().ToList(); + int index = 0; + foreach (var item in enums) + { + FieldInfo? fieldInfo = typeof(CreateType).GetField(((CreateType)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 "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(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; + } + catch (Exception ex) + { + return null; + } + } + } +} -- Gitblit v1.9.3