using Newtonsoft.Json; 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.BaseRepository; using WIDESEA_Core.BaseServices; 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, ISys_DictionaryService { private readonly IUnitOfWorkManage _unitOfWorkManage; public Sys_DictionaryService(ISys_DictionaryRepository BaseDal, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal) { _unitOfWorkManage = unitOfWorkManage; } public List GetVueDictionary(string[] dicNos) { if (dicNos == null || dicNos.Count() == 0) return new List(); var dicConfig = BaseDal.GetDictionaries(dicNos, false).Select(s => new { 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)) { return data; } return BaseDal.QueryObjectDataBySql(dbSql, null); } List vueDictionaryDTOs = dicConfig.Select(item => new VueDictionaryDTO { DicNo = item.dicNo, Config = item.config, Data = GetSourceData(item.dicNo, item.dbSql, item.list) }).ToList(); try { List dicList = dicNos.ToList(); string str = AppSettings.Configuration["dics"]; if (!string.IsNullOrEmpty(str)) { List cusDics = new List(); List 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); } } } } catch { } return vueDictionaryDTOs; } private VueDictionaryDTO GetVueDictionary(string key) { VueDictionaryDTO result = null; try { switch (key) { case "inboundState": { List data = new List(); Type type = typeof(InboundStatusEmun); List enums = Enum.GetValues(typeof(InboundStatusEmun)).Cast().ToList(); int index = 0; foreach (var item in enums) { FieldInfo? fieldInfo = typeof(InboundStatusEmun).GetField(((InboundStatusEmun)item).ToString()); DescriptionAttribute? description = fieldInfo.GetCustomAttribute(); 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 data = new List(); { Type type = typeof(InOrderTypeEnum); List enums = Enum.GetValues(typeof(InOrderTypeEnum)).Cast().ToList(); int index = 0; foreach (var item in enums) { FieldInfo? fieldInfo = typeof(InOrderTypeEnum).GetField(((InOrderTypeEnum)item).ToString()); DescriptionAttribute? description = fieldInfo.GetCustomAttribute(); 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 data = new List(); { Type type = typeof(OutOrderTypeEnum); List enums = Enum.GetValues(typeof(OutOrderTypeEnum)).Cast().ToList(); int index = 0; foreach (var item in enums) { FieldInfo? fieldInfo = typeof(OutOrderTypeEnum).GetField(((OutOrderTypeEnum)item).ToString()); DescriptionAttribute? description = fieldInfo.GetCustomAttribute(); 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 data = new List(); { Type type = typeof(CreateType); List enums = Enum.GetValues(typeof(CreateType)).Cast().ToList(); int index = 0; foreach (var item in enums) { FieldInfo? fieldInfo = typeof(CreateType).GetField(((CreateType)item).ToString()); DescriptionAttribute? description = fieldInfo.GetCustomAttribute(); 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; } } } }