diff --git a/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs b/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs index 7f5e6a24f..95c9d5a24 100644 --- a/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs +++ b/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs @@ -16,6 +16,7 @@ using Newtonsoft.Json.Linq; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Domain.Share.Management; using System.Text.Json.Nodes; +using IRaCIS.Application.Contracts; namespace IRaCIS.Core.Application.Service { @@ -235,7 +236,7 @@ namespace IRaCIS.Core.Application.Service - var listIdentification = auditDatas.Select(x => x.Identification).ToList(); + var listIdentification = auditDatas.Select(x => x.Identification).Distinct().ToList(); foreach (var item in auditDatas) { Dictionary jsonDict = JsonConvert.DeserializeObject>(item.JsonStr); @@ -703,12 +704,16 @@ namespace IRaCIS.Core.Application.Service { return null; } + + + //DictionaryCode='' and EnumType='Dictionary' 是审核状态 var list = await (from u in _frontAuditConfigRepository.Where(x => identificationList.Contains(x.Identification)) - join p in _frontAuditConfigRepository.Where(x => x.DictionaryCode!=null &&x.DictionaryCode!=string.Empty && x.EnumType == "Dictionary" && x.IsEnable) on u.Id equals p.ParentId + join p in _frontAuditConfigRepository.Where(x => (x.DictionaryCode!=string.Empty && x.EnumType == "Dictionary" )||(x.DataType=="Table") && x.IsEnable) on u.Id equals p.ParentId select new { //前端展示类型 - //DataType=p.DataType, + DataType=p.DataType, + TableConfigJsonStr= p.TableConfigJsonStr, Key = p.Code, Code = p.DictionaryCode, Type = p.DictionaryType @@ -721,22 +726,14 @@ namespace IRaCIS.Core.Application.Service { list.Add(new { - //DataType="", + DataType = string.Empty, + TableConfigJsonStr = string.Empty, Key = "AuditState", Code = trialtype == TrialQCProcess.SingleAudit ? "AuditStatePE" : "AuditStateRC", Type = "Code", - }); + }); ; } - - - - list = list.GroupBy(x => new { x.Key }, (key, lst) => new - { - Key = key.Key, - Code = lst.Max(x => x.Code), - Type = lst.Max(x => x.Type), - }).ToList(); var jsonDataDic = JsonConvert.DeserializeObject>(jsonStr); foreach (var item in list) @@ -749,11 +746,51 @@ namespace IRaCIS.Core.Application.Service continue; } var value = jsonDataDic[item.Key]; + + //翻译的是数组 if (value.GetType() == typeof(JArray)) { JArray arrays = (JArray)value; + if (item.DataType == "Table") + { + var tableConfigList= JsonConvert.DeserializeObject>(item.TableConfigJsonStr) ?? new List(); + + + + var translateInfoList = tableConfigList.Where(t => t.IsNeedTransalate).Select(t => new { t.ColumnValue, t.TranslateDictionaryName }).Distinct().ToList(); + + var dictionaryNameList = translateInfoList.Select(t => t.TranslateDictionaryName).Distinct().ToList(); + + + var searchList = await _dictionaryRepository.Where(t => dictionaryNameList.Contains(t.Parent.Code) && t.ParentId != null && t.IsEnable).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); + + //翻译的字典数据 + var translateDataList= searchList.GroupBy(t => t.ParentCode).ToDictionary(g => g.Key, g => g.OrderBy(t => t.ShowOrder).ToList()); + + List jsonList = new List(); + foreach (JToken arraysItem in arrays) + { + var jsonObject = JObject.Parse(arraysItem.ToString()); + + foreach (var translateInfo in translateInfoList) + { + //Json 解析后 true 变为了True + jsonObject[translateInfo.ColumnValue] = translateDataList[translateInfo.TranslateDictionaryName].Where(t => t.Code.ToLower() == jsonObject[translateInfo.ColumnValue].ToString().ToLower()).Select(t => t.ValueCN).FirstOrDefault(); + } + + jsonList.Add(jsonObject); + + } + + jsonDataDic[item.Key] = JToken.FromObject(jsonList); + + break; + + } + + if (item.Type.ToLower() == FrontAudit.Id.GetDescription().ToLower()) { List guids = new List(); @@ -835,12 +872,15 @@ namespace IRaCIS.Core.Application.Service ); } } + + //翻译的是单个字段 else { + //通过字典项的Guid 翻译 if (item.Type.ToLower() == FrontAudit.Id.GetDescription().ToLower()) { Guid guid = Guid.Parse(value.ToString()); - jsonDataDic[item.Key] = await _dictionaryRepository.Where(x => guid == x.Id).Select(x => x.ValueCN).FirstOrDefaultAsync(); + jsonDataDic[item.Key] = await _dictionaryRepository.Where(x => x.Id== guid ).Select(x => x.ValueCN).FirstOrDefaultAsync(); } else if (item.Type.ToLower() == FrontAudit.ChildGroup.GetDescription().ToLower()) { @@ -849,6 +889,7 @@ namespace IRaCIS.Core.Application.Service value = b.ValueCN }).Select(x => x.value).FirstOrDefaultAsync(); } + //通过字典项的code 翻译 枚举或者 bool else { jsonDataDic[item.Key] = await _dictionaryRepository.Where(x => x.Code == item.Code).Join(_dictionaryRepository.Where(x => x.Code == value.ToString()), a => a.Id, b => b.ParentId, (a, b) => new