using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Mvc;
|
using Newtonsoft.Json;
|
using Quartz;
|
using System.ComponentModel;
|
using System.Reflection;
|
using WIDESEA_Common.CommonEnum;
|
using WIDESEA_Common.LocationEnum;
|
using WIDESEA_Common.MaterielEnum;
|
using WIDESEA_Common.StockEnum;
|
using WIDESEA_Common.TaskEnum;
|
using WIDESEA_Core.BaseController;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.Caches;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_DTO.System;
|
using WIDESEA_ISystemService;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_WMSServer.Controllers
|
{
|
/// <summary>
|
/// 字典
|
/// </summary>
|
[Route("api/Sys_Dictionary")]
|
[ApiController]
|
public class Sys_DictionaryController : ApiBaseController<ISys_DictionaryService, Sys_Dictionary>
|
{
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly ICacheService _cacheService;
|
|
public Sys_DictionaryController(ISys_DictionaryService service, IHttpContextAccessor httpContextAccessor, ICacheService cacheService) : base(service)
|
{
|
_httpContextAccessor = httpContextAccessor;
|
_cacheService = cacheService;
|
}
|
|
[HttpPost, Route("GetVueDictionary"), AllowAnonymous]
|
public IActionResult GetVueDictionary([FromBody] string[] dicNos)
|
{
|
List<VueDictionaryDTO> vueDictionaryDTOs = Service.GetVueDictionary(dicNos);
|
try
|
{
|
List<string> selectDicNos = vueDictionaryDTOs.Select(x => x.DicNo).ToList();
|
List<string> cacheDicNos = new List<string>();
|
foreach (string n in dicNos.Where(x => !selectDicNos.Contains(x)))
|
{
|
string? str = _cacheService.Get(n);
|
if (!string.IsNullOrEmpty(str))
|
{
|
VueDictionaryDTO? vueDictionary = JsonConvert.DeserializeObject<VueDictionaryDTO>(str);
|
|
if (vueDictionary != null)
|
{
|
vueDictionaryDTOs.Add(vueDictionary);
|
cacheDicNos.Add(n);
|
}
|
}
|
}
|
List<string> dicList = dicNos.ToList();
|
List<string> otherDicNos = dicNos.Where(x => !cacheDicNos.Contains(x) && !selectDicNos.Contains(x)).ToList();
|
if (otherDicNos.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 otherDicNos)
|
{
|
if (dics.Contains(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 Json(vueDictionaryDTOs);
|
}
|
|
private VueDictionaryDTO? GetVueDictionary(string key)
|
{
|
VueDictionaryDTO? result = null;
|
try
|
{
|
switch (key)
|
{
|
case "jobAssembly":
|
{
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = new List<object>() { new { key = "WIDESEAWCS_Tasks", value = "WIDESEAWCS_Tasks" } } };
|
|
}
|
break;
|
case "jobClassName":
|
{
|
Type type = typeof(IJob);
|
var basePath = AppContext.BaseDirectory;
|
string path = Path.Combine(basePath, $"WIDESEAWCS_Tasks");
|
Assembly assembly = Assembly.LoadFrom(path);
|
List<Type> types = assembly.GetTypes().Where(x => type.IsAssignableFrom(x) && !x.IsAbstract && !x.IsInterface).ToList();
|
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = types.Select(x => new { key = x.Name, value = x.Name }) };
|
}
|
break;
|
case "taskState":
|
{
|
List<object> data = new List<object>();
|
|
#region TaskInStatusEnum
|
{
|
Type type = typeof(TaskInStatusEnum);
|
List<int> enums = Enum.GetValues(typeof(TaskInStatusEnum)).Cast<int>().ToList();
|
int index = 0;
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(TaskInStatusEnum).GetField(((TaskInStatusEnum)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++;
|
}
|
}
|
#endregion
|
|
#region TaskOutStatusEnum
|
{
|
Type type = typeof(TaskOutStatusEnum);
|
List<int> enums = Enum.GetValues(typeof(TaskOutStatusEnum)).Cast<int>().ToList();
|
int index = 0;
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(TaskOutStatusEnum).GetField(((TaskOutStatusEnum)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++;
|
}
|
}
|
#endregion
|
|
#region TaskRelocationStatusEnum
|
{
|
Type type = typeof(TaskRelocationStatusEnum);
|
List<int> enums = Enum.GetValues(typeof(TaskRelocationStatusEnum)).Cast<int>().ToList();
|
int index = 0;
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(TaskRelocationStatusEnum).GetField(((TaskRelocationStatusEnum)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++;
|
}
|
}
|
#endregion
|
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "taskInStatus":
|
{
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(TaskInStatusEnum)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(TaskInStatusEnum).GetField(((TaskInStatusEnum)item).ToString());
|
DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
|
data.Add(new { key = item.ToString(), value = description != null ? description.Description : item.ToString() });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "taskOutStatus":
|
{
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(TaskOutStatusEnum)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(TaskOutStatusEnum).GetField(((TaskOutStatusEnum)item).ToString());
|
DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
|
data.Add(new { key = item.ToString(), value = description != null ? description.Description : item.ToString() });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "taskRelocationStatus":
|
{
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(TaskRelocationStatusEnum)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(TaskRelocationStatusEnum).GetField(((TaskRelocationStatusEnum)item).ToString());
|
DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
|
data.Add(new { key = item.ToString(), value = description != null ? description.Description : item.ToString() });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "taskInboundType":
|
{
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(TaskInboundTypeEnum)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(TaskInboundTypeEnum).GetField(((TaskInboundTypeEnum)item).ToString());
|
DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
|
data.Add(new { key = item.ToString(), value = description != null ? description.Description : item.ToString() });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "taskOutboundType":
|
{
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(TaskOutboundTypeEnum)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(TaskOutboundTypeEnum).GetField(((TaskOutboundTypeEnum)item).ToString());
|
DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
|
data.Add(new { key = item.ToString(), value = description != null ? description.Description : item.ToString() });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "taskRelocationType":
|
{
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(TaskRelocationTypeEnum)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(TaskRelocationTypeEnum).GetField(((TaskRelocationTypeEnum)item).ToString());
|
DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
|
data.Add(new { key = item.ToString(), value = description != null ? description.Description : item.ToString() });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "taskTypeGroup":
|
{
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(TaskTypeGroup)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(TaskTypeGroup).GetField(((TaskTypeGroup)item).ToString());
|
DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
|
data.Add(new { key = item.ToString(), value = description != null ? description.Description : ((TaskTypeGroup)item).ToString() });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "taskTypeEnum":
|
{
|
// 合并入库/出库/移库任务类型
|
List<object> data = new List<object>();
|
foreach (var item in Enum.GetValues(typeof(TaskInboundTypeEnum)).Cast<int>())
|
{
|
var field = typeof(TaskInboundTypeEnum).GetField(((TaskInboundTypeEnum)item).ToString());
|
var desc = field?.GetCustomAttribute<DescriptionAttribute>()?.Description ?? item.ToString();
|
data.Add(new { key = item.ToString(), value = desc });
|
}
|
foreach (var item in Enum.GetValues(typeof(TaskOutboundTypeEnum)).Cast<int>())
|
{
|
var field = typeof(TaskOutboundTypeEnum).GetField(((TaskOutboundTypeEnum)item).ToString());
|
var desc = field?.GetCustomAttribute<DescriptionAttribute>()?.Description ?? item.ToString();
|
data.Add(new { key = item.ToString(), value = desc });
|
}
|
foreach (var item in Enum.GetValues(typeof(TaskRelocationTypeEnum)).Cast<int>())
|
{
|
var field = typeof(TaskRelocationTypeEnum).GetField(((TaskRelocationTypeEnum)item).ToString());
|
var desc = field?.GetCustomAttribute<DescriptionAttribute>()?.Description ?? item.ToString();
|
data.Add(new { key = item.ToString(), value = desc });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "taskStatusEnum":
|
{
|
// 合并入库/出库/移库任务状态
|
List<object> data = new List<object>();
|
foreach (var item in Enum.GetValues(typeof(TaskInStatusEnum)).Cast<int>())
|
{
|
var field = typeof(TaskInStatusEnum).GetField(((TaskInStatusEnum)item).ToString());
|
var desc = field?.GetCustomAttribute<DescriptionAttribute>()?.Description ?? item.ToString();
|
data.Add(new { key = item.ToString(), value = desc });
|
}
|
foreach (var item in Enum.GetValues(typeof(TaskOutStatusEnum)).Cast<int>())
|
{
|
var field = typeof(TaskOutStatusEnum).GetField(((TaskOutStatusEnum)item).ToString());
|
var desc = field?.GetCustomAttribute<DescriptionAttribute>()?.Description ?? item.ToString();
|
data.Add(new { key = item.ToString(), value = desc });
|
}
|
foreach (var item in Enum.GetValues(typeof(TaskRelocationStatusEnum)).Cast<int>())
|
{
|
var field = typeof(TaskRelocationStatusEnum).GetField(((TaskRelocationStatusEnum)item).ToString());
|
var desc = field?.GetCustomAttribute<DescriptionAttribute>()?.Description ?? item.ToString();
|
data.Add(new { key = item.ToString(), value = desc });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "stockChangeTypeEnum":
|
{
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(StockChangeTypeEnum)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(StockChangeTypeEnum).GetField(((StockChangeTypeEnum)item).ToString());
|
DescriptionAttribute? description = fieldInfo?.GetCustomAttribute<DescriptionAttribute>();
|
data.Add(new { key = item.ToString(), value = description != null ? description.Description : item.ToString() });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "stockStatusEmun":
|
{
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(StockStatusEmun)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(StockStatusEmun).GetField(((StockStatusEmun)item).ToString());
|
DescriptionAttribute? description = fieldInfo?.GetCustomAttribute<DescriptionAttribute>();
|
data.Add(new { key = item.ToString(), value = description != null ? description.Description : item.ToString() });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "yesno":
|
{
|
// 使用真实的是否枚举
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(WhetherEnum)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(WhetherEnum).GetField(((WhetherEnum)item).ToString());
|
DescriptionAttribute? description = fieldInfo?.GetCustomAttribute<DescriptionAttribute>();
|
string displayName = description?.Description ?? ((WhetherEnum)item).ToString();
|
// 根据枚举值提供中文名称
|
switch ((WhetherEnum)item)
|
{
|
case WhetherEnum.True:
|
displayName = "是";
|
break;
|
case WhetherEnum.False:
|
displayName = "否";
|
break;
|
}
|
data.Add(new { key = item.ToString(), value = displayName });
|
}
|
// 为兼容性,同时支持 true/false 字符串
|
data.Add(new { key = "true", value = "是" });
|
data.Add(new { key = "false", value = "否" });
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "InventoryMaterialType":
|
{
|
// 使用真实的物料类型枚举
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(MaterielTypeEnum)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(MaterielTypeEnum).GetField(((MaterielTypeEnum)item).ToString());
|
DescriptionAttribute? description = fieldInfo?.GetCustomAttribute<DescriptionAttribute>();
|
string displayName = description?.Description ?? ((MaterielTypeEnum)item).ToString();
|
// 根据枚举值提供中文名称
|
switch ((MaterielTypeEnum)item)
|
{
|
case MaterielTypeEnum.FinishProduct:
|
displayName = "成品";
|
break;
|
case MaterielTypeEnum.HalfProduct:
|
displayName = "半成品";
|
break;
|
case MaterielTypeEnum.RawMateriel:
|
displayName = "原材料";
|
break;
|
case MaterielTypeEnum.SpareParts:
|
displayName = "备件";
|
break;
|
}
|
data.Add(new { key = item.ToString(), value = displayName });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "MaterielSourceType":
|
{
|
// 物料来源类型枚举
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(MaterielSourceTypeEnum)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(MaterielSourceTypeEnum).GetField(((MaterielSourceTypeEnum)item).ToString());
|
DescriptionAttribute? description = fieldInfo?.GetCustomAttribute<DescriptionAttribute>();
|
string displayName = description?.Description ?? ((MaterielSourceTypeEnum)item).ToString();
|
// 根据枚举值提供中文名称
|
switch ((MaterielSourceTypeEnum)item)
|
{
|
case MaterielSourceTypeEnum.PurchasePart:
|
displayName = "采购件";
|
break;
|
case MaterielSourceTypeEnum.SelfMadePart:
|
displayName = "自制件";
|
break;
|
case MaterielSourceTypeEnum.PurchaseAndSelf:
|
displayName = "采购&自制件";
|
break;
|
}
|
data.Add(new { key = item.ToString(), value = displayName });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "InventoryMaterialStatus":
|
{
|
// 物料状态字典 - 根据业务需求定义
|
List<object> data = new List<object>
|
{
|
new { key = "1", value = "正常" },
|
new { key = "2", value = "待检" },
|
new { key = "3", value = "合格" },
|
new { key = "4", value = "不合格" },
|
new { key = "5", value = "冻结" },
|
new { key = "6", value = "报废" },
|
new { key = "7", value = "过期" },
|
new { key = "8", value = "损坏" }
|
};
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "locationStatusEnum":
|
{
|
// 货位状态枚举
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(LocationStatusEnum)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(LocationStatusEnum).GetField(((LocationStatusEnum)item).ToString());
|
DescriptionAttribute? description = fieldInfo?.GetCustomAttribute<DescriptionAttribute>();
|
data.Add(new { key = item.ToString(), value = description != null ? description.Description : item.ToString() });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "locationTypeEnum":
|
{
|
// 货位类型枚举
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(LocationTypeEnum)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(LocationTypeEnum).GetField(((LocationTypeEnum)item).ToString());
|
DescriptionAttribute? description = fieldInfo?.GetCustomAttribute<DescriptionAttribute>();
|
data.Add(new { key = item.ToString(), value = description != null ? description.Description : item.ToString() });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
case "enableStatusEnum":
|
{
|
// 货位禁用状态枚举
|
List<object> data = new List<object>();
|
List<int> enums = Enum.GetValues(typeof(EnableStatusEnum)).Cast<int>().ToList();
|
foreach (var item in enums)
|
{
|
FieldInfo? fieldInfo = typeof(EnableStatusEnum).GetField(((EnableStatusEnum)item).ToString());
|
DescriptionAttribute? description = fieldInfo?.GetCustomAttribute<DescriptionAttribute>();
|
data.Add(new { key = item.ToString(), value = description != null ? description.Description : item.ToString() });
|
}
|
result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
|
}
|
break;
|
}
|
return result;
|
}
|
catch (Exception ex)
|
{
|
return null;
|
}
|
}
|
}
|
}
|