From a89c018c3afa43a529f9eb54725bc92ed2b996e8 Mon Sep 17 00:00:00 2001 From: hutongqing <hutongqing@hnkhzn.com> Date: 星期二, 24 九月 2024 15:04:45 +0800 Subject: [PATCH] 1 --- 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_DictionaryService.cs | 405 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 368 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..eabf102 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,114 @@ 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; + + 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>(); - var dicConfig = BaseDal.GetDictionaries(dicNos, false).Select(s => new + List<string> cacheDicNos = new List<string>(); + foreach (string n in dicNos) { - 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(); - - object GetSourceData(string dicNo, string dbSql, object data) - { - if (string.IsNullOrEmpty(dbSql)) + string str = _cacheService.Get(n); + if (!string.IsNullOrEmpty(str)) { - return data; + VueDictionaryDTO? vueDictionary = JsonConvert.DeserializeObject<VueDictionaryDTO>(str); + + if (vueDictionary != null) + { + vueDictionaryDTOs.Add(vueDictionary); + cacheDicNos.Add(n); + } } - return BaseDal.QueryObjectDataBySql(dbSql, null); } - List<VueDictionaryDTO> vueDictionaryDTOs = dicConfig.Select(item => new VueDictionaryDTO + if (dicNos.Where(x => !cacheDicNos.Contains(x)).Count() > 0) { - DicNo = item.dicNo, - Config = item.config, - Data = GetSourceData(item.dicNo, item.dbSql, item.list) - }).ToList(); + 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(); - - string str = AppSettings.Configuration["dics"]; - if (!string.IsNullOrEmpty(str)) + if (dicNos.Where(x => !cacheDicNos.Contains(x)).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 dics) { - vueDictionaryDTOs.Add(vueDictionaryDTO); + 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()); + } + } } } } @@ -99,12 +153,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 +252,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 +306,232 @@ 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; } return result; } -- Gitblit v1.9.3