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<Sys_Dictionary, ISys_DictionaryRepository>, ISys_DictionaryService
|
{
|
private readonly IUnitOfWorkManage _unitOfWorkManage;
|
public Sys_DictionaryService(ISys_DictionaryRepository BaseDal, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
|
{
|
_unitOfWorkManage = unitOfWorkManage;
|
}
|
|
public ISys_DictionaryRepository Repository => BaseDal;
|
|
public List<VueDictionaryDTO> GetVueDictionary(string[] dicNos)
|
{
|
if (dicNos == null || dicNos.Count() == 0) return new List<VueDictionaryDTO>();
|
|
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<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))
|
{
|
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);
|
}
|
}
|
}
|
}
|
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(InboundStatusEmun);
|
List<int> enums = Enum.GetValues(typeof(InboundStatusEmun)).Cast<int>().ToList();
|
int index = 0;
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(InboundStatusEmun).GetField(((InboundStatusEmun)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 "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;
|
}
|
return result;
|
}
|
catch (Exception ex)
|
{
|
return null;
|
}
|
}
|
}
|
}
|