diff --git a/IRaCIS.Core.Application/Service/Common/DTO/FrontAuditConfigViewModel.cs b/IRaCIS.Core.Application/Service/Common/DTO/FrontAuditConfigViewModel.cs index 3a5c89b2e..65960e3ad 100644 --- a/IRaCIS.Core.Application/Service/Common/DTO/FrontAuditConfigViewModel.cs +++ b/IRaCIS.Core.Application/Service/Common/DTO/FrontAuditConfigViewModel.cs @@ -199,6 +199,19 @@ namespace IRaCIS.Core.Application.ViewModel public string DateType { get; set; }=string.Empty; + /// + /// 字典Code + /// + + public string DictionaryCode { get; set; } = string.Empty; + + /// + /// 字典Type + /// + + public string DictionaryType { get; set; } = string.Empty; + + } diff --git a/IRaCIS.Core.Application/Service/Common/FrontAuditConfigService.cs b/IRaCIS.Core.Application/Service/Common/FrontAuditConfigService.cs index e7e942a92..0f901b0b6 100644 --- a/IRaCIS.Core.Application/Service/Common/FrontAuditConfigService.cs +++ b/IRaCIS.Core.Application/Service/Common/FrontAuditConfigService.cs @@ -146,7 +146,6 @@ namespace IRaCIS.Core.Application.Service from leftObjectTypeIdtemp in ObjectTypeIdtemp.DefaultIfEmpty() select new FrontAuditConfigView() { - IsShowParent = data.IsShowParent, ChildrenTypeId = data.ChildrenTypeId, Code = data.Code, @@ -190,6 +189,8 @@ namespace IRaCIS.Core.Application.Service ChildDataValue=data.ChildDataValue, IsSpecialType=data.IsSpecialType, DateType=data.DataType, + DictionaryCode=data.DictionaryCode, + DictionaryType=data.DictionaryType, }; query = query diff --git a/IRaCIS.Core.Application/Service/Inspection/InspectionService.cs b/IRaCIS.Core.Application/Service/Inspection/InspectionService.cs index af9cac4a1..8bbb32ed6 100644 --- a/IRaCIS.Core.Application/Service/Inspection/InspectionService.cs +++ b/IRaCIS.Core.Application/Service/Inspection/InspectionService.cs @@ -402,101 +402,102 @@ namespace IRaCIS.Core.Application.Service.Inspection public async Task SetEnum(DataInspectionAddDTO Data) { + Data.JsonDetail= await _dataInspectionRepository.SetEnum(Data.Identification, Data.JsonDetail); #region 枚举 - try - { - var JsonData = JsonConvert.DeserializeObject>(Data.JsonDetail); - foreach (var item in Data.EnumList) - { - if (!JsonData.ContainsKey(item.Key)) - { - continue; - } - var value = JsonData[item.Key]; - if (value.GetType() == typeof(JArray)) - { - JArray arrays = (JArray)value; - if (item.Type.ToLower() == "id".ToLower()) - { - List guids = new List(); - arrays.ForEach(x => - { - guids.Add(Guid.Parse(x.ToString())); - }); - JsonData[item.Key] = string.Join(',', await _repository.GetQueryable().Where(x => guids.Contains(x.Id)).Select(x => x.ValueCN).ToListAsync()); - } - else if (item.Type.ToLower() == "ChildGroup".ToLower()) - { - List guids = new List(); - arrays.ForEach(x => - { - guids.Add(x.ToString()); - }); - JsonData[item.Key] = string.Join(',', await - _repository.GetQueryable().Where(x => x.Code == item.Code).GroupJoin( - _repository.GetQueryable().Where(x => guids.Contains(x.ChildGroup)), a => a.Id, b => b.ParentId, (a, b) => new - { - parent = b - }).SelectMany(a => a.parent, (m, n) => new - { - value = n.ValueCN - }).Select(x => x.value).ToListAsync() - ); - } - else - { - List guids =new List(); - arrays.ForEach(x => - { - guids.Add(x.ToString()); - }); - JsonData[item.Key] = string.Join(',', await - _repository.GetQueryable().Where(x => x.Code == item.Code).GroupJoin( - _repository.GetQueryable().Where(x=>guids.Contains(x.Code)), a => a.Id, b => b.ParentId, (a, b) => new - { - parent = b - }).SelectMany(a => a.parent, (m, n) => new - { - value = n.ValueCN - }).Select(x => x.value).ToListAsync() - ); - } - } - else - { - if (item.Type.ToLower() == "id".ToLower()) - { - Guid guid = Guid.Parse(value.ToString()); - JsonData[item.Key] = await _repository.GetQueryable().Where(x => guid == x.Id).Select(x => x.ValueCN).FirstOrDefaultAsync(); - } - else if (item.Type.ToLower() == "ChildGroup".ToLower()) - { - JsonData[item.Key] = await _repository.GetQueryable().Where(x => x.Code == item.Code).Join(_repository.GetQueryable().Where(x => x.ChildGroup == value.ToString()), a => a.Id, b => b.ParentId, (a, b) => new - { - value = b.ValueCN - }).Select(x => x.value).FirstOrDefaultAsync(); - } - else - { - JsonData[item.Key] = await _repository.GetQueryable().Where(x=>x.Code==item.Code).Join(_repository.GetQueryable().Where(x=>x.Code== value.ToString()), a => a.Id, b => b.ParentId, (a, b) => new - { - value=b.ValueCN - }).Select(x=>x.value).FirstOrDefaultAsync(); + //try + //{ + // var JsonData = JsonConvert.DeserializeObject>(Data.JsonDetail); + // foreach (var item in Data.EnumList) + // { + // if (!JsonData.ContainsKey(item.Key)) + // { + // continue; + // } + // var value = JsonData[item.Key]; + // if (value.GetType() == typeof(JArray)) + // { + // JArray arrays = (JArray)value; + // if (item.Type.ToLower() == "id".ToLower()) + // { + // List guids = new List(); + // arrays.ForEach(x => + // { + // guids.Add(Guid.Parse(x.ToString())); + // }); + // JsonData[item.Key] = string.Join(',', await _repository.GetQueryable().Where(x => guids.Contains(x.Id)).Select(x => x.ValueCN).ToListAsync()); + // } + // else if (item.Type.ToLower() == "ChildGroup".ToLower()) + // { + // List guids = new List(); + // arrays.ForEach(x => + // { + // guids.Add(x.ToString()); + // }); + // JsonData[item.Key] = string.Join(',', await + // _repository.GetQueryable().Where(x => x.Code == item.Code).GroupJoin( + // _repository.GetQueryable().Where(x => guids.Contains(x.ChildGroup)), a => a.Id, b => b.ParentId, (a, b) => new + // { + // parent = b + // }).SelectMany(a => a.parent, (m, n) => new + // { + // value = n.ValueCN + // }).Select(x => x.value).ToListAsync() + // ); + // } + // else + // { + // List guids =new List(); + // arrays.ForEach(x => + // { + // guids.Add(x.ToString()); + // }); + // JsonData[item.Key] = string.Join(',', await + // _repository.GetQueryable().Where(x => x.Code == item.Code).GroupJoin( + // _repository.GetQueryable().Where(x=>guids.Contains(x.Code)), a => a.Id, b => b.ParentId, (a, b) => new + // { + // parent = b + // }).SelectMany(a => a.parent, (m, n) => new + // { + // value = n.ValueCN + // }).Select(x => x.value).ToListAsync() + // ); + // } + // } + // else + // { + // if (item.Type.ToLower() == "id".ToLower()) + // { + // Guid guid = Guid.Parse(value.ToString()); + // JsonData[item.Key] = await _repository.GetQueryable().Where(x => guid == x.Id).Select(x => x.ValueCN).FirstOrDefaultAsync(); + // } + // else if (item.Type.ToLower() == "ChildGroup".ToLower()) + // { + // JsonData[item.Key] = await _repository.GetQueryable().Where(x => x.Code == item.Code).Join(_repository.GetQueryable().Where(x => x.ChildGroup == value.ToString()), a => a.Id, b => b.ParentId, (a, b) => new + // { + // value = b.ValueCN + // }).Select(x => x.value).FirstOrDefaultAsync(); + // } + // else + // { + // JsonData[item.Key] = await _repository.GetQueryable().Where(x=>x.Code==item.Code).Join(_repository.GetQueryable().Where(x=>x.Code== value.ToString()), a => a.Id, b => b.ParentId, (a, b) => new + // { + // value=b.ValueCN + // }).Select(x=>x.value).FirstOrDefaultAsync(); - } - } - } + // } + // } + // } - IsoDateTimeConverter timeFormat = new IsoDateTimeConverter(); - timeFormat.DateTimeFormat = "yyyy-MM-dd"; - Data.JsonDetail = JsonConvert.SerializeObject(JsonData, Newtonsoft.Json.Formatting.Indented, timeFormat); - } - catch (Exception) - { + + // Data.JsonDetail = JsonConvert.SerializeObject(JsonData); + + //} + //catch (Exception) + //{ - throw new BusinessValidationFailedException("Json 对象枚举异常"); - } + // throw new BusinessValidationFailedException("Json 对象枚举异常"); + //} diff --git a/IRaCIS.Core.Application/Service/Inspection/Interface/IInspectionService.cs b/IRaCIS.Core.Application/Service/Inspection/Interface/IInspectionService.cs index b425acea0..80cb3b595 100644 --- a/IRaCIS.Core.Application/Service/Inspection/Interface/IInspectionService.cs +++ b/IRaCIS.Core.Application/Service/Inspection/Interface/IInspectionService.cs @@ -22,7 +22,7 @@ namespace IRaCIS.Core.Application.Service.Inspection.Interface Task Enforcement(dynamic OptCommand, DataInspectionAddDTO AuditInfo, SignDTO SignInfo, dynamic fun, IResponseOutput? response = null); - Task SetEnum(DataInspectionAddDTO Data); + //Task SetEnum(DataInspectionAddDTO Data); Task AddInspectionRecordAsync(DataInspectionAddDTO addDto, Guid? signId = null); diff --git a/IRaCIS.Core.Domain/Common/FrontAuditConfig.cs b/IRaCIS.Core.Domain/Common/FrontAuditConfig.cs index a016024d9..5443a38d7 100644 --- a/IRaCIS.Core.Domain/Common/FrontAuditConfig.cs +++ b/IRaCIS.Core.Domain/Common/FrontAuditConfig.cs @@ -180,6 +180,18 @@ namespace IRaCIS.Core.Domain.Models public string DateType { get; set; } + /// + /// 字典Code + /// + + public string DictionaryCode { get; set; } + + /// + /// 字典Type + /// + + public string DictionaryType { get; set; } + } diff --git a/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs index 797dc9ad7..13b0595db 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs @@ -39,6 +39,15 @@ namespace IRaCIS.Core.Infra.EFCore /// /// Task SetDataInspectionDateType(DataInspection Data); + + /// + /// 处理枚举 + /// + /// 标识 + /// json对象 + /// + + Task SetEnum(string Identification, string json); } diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 758252f35..591243212 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -18,6 +18,7 @@ using IRaCIS.Core.Infrastructure.Extention; using Microsoft.Data.SqlClient; using Newtonsoft.Json; using IRaCIS.Core.Infra.EFCore.Dto; +using Newtonsoft.Json.Linq; namespace IRaCIS.Core.Infra.EFCore { @@ -466,6 +467,121 @@ namespace IRaCIS.Core.Infra.EFCore #region 稽查 + /// + /// 获取枚举 + /// + /// 标识 + /// Json对象 + /// + /// + public async Task SetEnum(string Identification, string json) + { + var list =await (from u in _dbContext.FrontAuditConfig.Where(x=>x.Identification== Identification) + join p in _dbContext.FrontAuditConfig.Where(x=>x.DictionaryCode!=null&& x.DictionaryCode != string.Empty&&x.DictionaryType != null&&x.DictionaryType != string.Empty) on u.Id equals p.ParentId + select new + { + Key= p.Code, + Code= p.DictionaryCode, + Type= p.DictionaryType + }).ToListAsync(); + + try + { + var JsonData = JsonConvert.DeserializeObject>(json); + foreach (var item in list) + { + if (!JsonData.ContainsKey(item.Key)) + { + continue; + } + var value = JsonData[item.Key]; + if (value.GetType() == typeof(JArray)) + { + JArray arrays = (JArray)value; + if (item.Type.ToLower() == "id".ToLower()) + { + List guids = new List(); + arrays.ForEach(x => + { + guids.Add(Guid.Parse(x.ToString())); + }); + JsonData[item.Key] = string.Join(',', await _dbContext.Dictionary.Where(x => guids.Contains(x.Id)).Select(x => x.ValueCN).ToListAsync()); + } + else if (item.Type.ToLower() == "ChildGroup".ToLower()) + { + List guids = new List(); + arrays.ForEach(x => + { + guids.Add(x.ToString()); + }); + JsonData[item.Key] = string.Join(',', await + _dbContext.Dictionary.Where(x => x.Code == item.Code).GroupJoin( + _dbContext.Dictionary.Where(x => guids.Contains(x.ChildGroup)), a => a.Id, b => b.ParentId, (a, b) => new + { + parent = b + }).SelectMany(a => a.parent, (m, n) => new + { + value = n.ValueCN + }).Select(x => x.value).ToListAsync() + ); + } + else + { + List guids = new List(); + arrays.ForEach(x => + { + guids.Add(x.ToString()); + }); + JsonData[item.Key] = string.Join(',', await + _dbContext.Dictionary.Where(x => x.Code == item.Code).GroupJoin( + _dbContext.Dictionary.Where(x => guids.Contains(x.Code)), a => a.Id, b => b.ParentId, (a, b) => new + { + parent = b + }).SelectMany(a => a.parent, (m, n) => new + { + value = n.ValueCN + }).Select(x => x.value).ToListAsync() + ); + } + } + else + { + if (item.Type.ToLower() == "id".ToLower()) + { + Guid guid = Guid.Parse(value.ToString()); + JsonData[item.Key] = await _dbContext.Dictionary.Where(x => guid == x.Id).Select(x => x.ValueCN).FirstOrDefaultAsync(); + } + else if (item.Type.ToLower() == "ChildGroup".ToLower()) + { + JsonData[item.Key] = await _dbContext.Dictionary.Where(x => x.Code == item.Code).Join(_dbContext.Dictionary.Where(x => x.ChildGroup == value.ToString()), a => a.Id, b => b.ParentId, (a, b) => new + { + value = b.ValueCN + }).Select(x => x.value).FirstOrDefaultAsync(); + } + else + { + JsonData[item.Key] = await _dbContext.Dictionary.Where(x => x.Code == item.Code).Join(_dbContext.Dictionary.Where(x => x.Code == value.ToString()), a => a.Id, b => b.ParentId, (a, b) => new + { + value = b.ValueCN + }).Select(x => x.value).FirstOrDefaultAsync(); + + } + } + } + + + + return JsonConvert.SerializeObject(JsonData); + + } + catch (Exception) + { + + throw new BusinessValidationFailedException("Json 对象枚举异常"); + } + + + } private async Task AddInspectionAsync(TEntity entity) { @@ -519,28 +635,11 @@ namespace IRaCIS.Core.Infra.EFCore } add.CreateUserId = _userInfo.Id; add.IP = _userInfo.IP; - var JsonData = JsonConvert.DeserializeObject>(add.JsonDetail); - - foreach (var item in JsonData.Keys) - { - if (JsonData[item] == null) - { - continue; - } - if (JsonData[item].ToString().ToLower() == "true".ToLower()) - { - JsonData[item] = "是"; - } - else if (JsonData[item].ToString().ToLower() == "false".ToLower()) - { - JsonData[item] = "否"; - } - } if (add.CreateTime == default(DateTime)) { add.CreateTime = DateTime.Now; } - add.JsonDetail = JsonConvert.SerializeObject(JsonData); + add.JsonDetail = await SetEnum(add.Identification, add.JsonDetail); await SetDataInspectionDateType(add); }