using Autofac.Core; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyModel; using Newtonsoft.Json; using System.Reflection; using WIDESEA_Core.BaseController; using WIDESEA_Core.Helper; using WIDESEA_ISystemServices; using WIDESEA_Model.Models; using System.IO; using WIDESEA_DTO.System; using System.ComponentModel; using System.Collections.Generic; using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; using WIDESEA_Core.Caches; using WIDESEA_Core.Enums; namespace WIDESEA_WCSServer.Controllers.System { [Route("api/Sys_Dictionary")] [ApiController] public class Sys_DictionaryController : ApiBaseController { 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 vueDictionaryDTOs = Service.GetVueDictionary(dicNos); try { List cacheDicNos = new List(); foreach (string n in dicNos) { if (vueDictionaryDTOs.Where(x => x.DicNo == n).Count() > 0) { continue; } string str = _cacheService.Get(n); if (!string.IsNullOrEmpty(str)) { VueDictionaryDTO? vueDictionary = JsonConvert.DeserializeObject(str); if (vueDictionary != null) { vueDictionaryDTOs.Add(vueDictionary); cacheDicNos.Add(n); } } } List dicList = dicNos.ToList(); if (dicNos.Where(x => !cacheDicNos.Contains(x)).Count() > 0) { 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) { if (vueDictionaryDTOs.Where(x => x.DicNo == item).Count() > 0) { continue; } VueDictionaryDTO vueDictionaryDTO = GetVueDictionary(item.Trim()); if (vueDictionaryDTO != null) { vueDictionaryDTOs.Add(vueDictionaryDTO); if (!_cacheService.Exists(item) && vueDictionaryDTO.SaveCache) { _cacheService.Add(item, vueDictionaryDTO.Serialize()); } } } } } } catch { } return Json(vueDictionaryDTOs); } private VueDictionaryDTO? GetVueDictionary(string key) { VueDictionaryDTO? result = null; try { switch (key) { } return result; } catch (Exception ex) { return null; } } } }