using 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;
|
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>();
|
|
List<string> cacheDicNos = new List<string>();
|
#region 查询数据库下拉框数据
|
if (dicNos.Where(x => !cacheDicNos.Contains(x)).Count() > 0)
|
{
|
var selectDics = BaseDal.GetDictionaries(dicNos.Where(x => !cacheDicNos.Contains(x)), _sys_RoleService.GetAllChildren(App.User.RoleId));
|
|
foreach (var item in selectDics)
|
{
|
if (!_cacheService.Exists(item.DicNo))
|
{
|
vueDictionaryDTOs.Add(item);
|
_cacheService.Add(item.DicNo, item.Serialize());
|
}
|
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());
|
}
|
}
|
}
|
}
|
#endregion
|
|
|
|
foreach (string n in dicNos)
|
{
|
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);
|
}
|
}
|
}
|
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)
|
{
|
if (dicList.Contains(item))
|
cusDics.Add(item);
|
dicList.Remove(item);
|
}
|
|
foreach (var item in cusDics)
|
{
|
VueDictionaryDTO vueDictionaryDTO = GetVueDictionary(item.Trim());
|
if (vueDictionaryDTO != null)
|
{
|
if (!_cacheService.Exists(item))
|
{
|
vueDictionaryDTOs.Add(vueDictionaryDTO);
|
_cacheService.Add(item, vueDictionaryDTO.Serialize());
|
}
|
}
|
}
|
}
|
}
|
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, value = description.Description });
|
}
|
else
|
{
|
data.Add(new { key = item, value = item.ToString() });
|
}
|
index++;
|
}
|
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
}
|
return result;
|
}
|
catch (Exception ex)
|
{
|
return null;
|
}
|
}
|
}
|
}
|