处理枚举

Uat_Study
he 2022-04-24 11:41:29 +08:00
parent 9741b7a438
commit 37da8bd3e9
7 changed files with 245 additions and 110 deletions

View File

@ -199,6 +199,19 @@ namespace IRaCIS.Core.Application.ViewModel
public string DateType { get; set; }=string.Empty; public string DateType { get; set; }=string.Empty;
/// <summary>
/// 字典Code
/// </summary>
public string DictionaryCode { get; set; } = string.Empty;
/// <summary>
/// 字典Type
/// </summary>
public string DictionaryType { get; set; } = string.Empty;
} }

View File

@ -146,7 +146,6 @@ namespace IRaCIS.Core.Application.Service
from leftObjectTypeIdtemp in ObjectTypeIdtemp.DefaultIfEmpty() from leftObjectTypeIdtemp in ObjectTypeIdtemp.DefaultIfEmpty()
select new FrontAuditConfigView() select new FrontAuditConfigView()
{ {
IsShowParent = data.IsShowParent, IsShowParent = data.IsShowParent,
ChildrenTypeId = data.ChildrenTypeId, ChildrenTypeId = data.ChildrenTypeId,
Code = data.Code, Code = data.Code,
@ -190,6 +189,8 @@ namespace IRaCIS.Core.Application.Service
ChildDataValue=data.ChildDataValue, ChildDataValue=data.ChildDataValue,
IsSpecialType=data.IsSpecialType, IsSpecialType=data.IsSpecialType,
DateType=data.DataType, DateType=data.DataType,
DictionaryCode=data.DictionaryCode,
DictionaryType=data.DictionaryType,
}; };
query = query query = query

View File

@ -402,101 +402,102 @@ namespace IRaCIS.Core.Application.Service.Inspection
public async Task SetEnum(DataInspectionAddDTO Data) public async Task SetEnum(DataInspectionAddDTO Data)
{ {
Data.JsonDetail= await _dataInspectionRepository.SetEnum(Data.Identification, Data.JsonDetail);
#region 枚举 #region 枚举
try //try
{ //{
var JsonData = JsonConvert.DeserializeObject<IDictionary<string, object>>(Data.JsonDetail); // var JsonData = JsonConvert.DeserializeObject<IDictionary<string, object>>(Data.JsonDetail);
foreach (var item in Data.EnumList) // foreach (var item in Data.EnumList)
{ // {
if (!JsonData.ContainsKey(item.Key)) // if (!JsonData.ContainsKey(item.Key))
{ // {
continue; // continue;
} // }
var value = JsonData[item.Key]; // var value = JsonData[item.Key];
if (value.GetType() == typeof(JArray)) // if (value.GetType() == typeof(JArray))
{ // {
JArray arrays = (JArray)value; // JArray arrays = (JArray)value;
if (item.Type.ToLower() == "id".ToLower()) // if (item.Type.ToLower() == "id".ToLower())
{ // {
List<Guid> guids = new List<Guid>(); // List<Guid> guids = new List<Guid>();
arrays.ForEach(x => // arrays.ForEach(x =>
{ // {
guids.Add(Guid.Parse(x.ToString())); // guids.Add(Guid.Parse(x.ToString()));
}); // });
JsonData[item.Key] = string.Join(',', await _repository.GetQueryable<Dictionary>().Where(x => guids.Contains(x.Id)).Select(x => x.ValueCN).ToListAsync()); // JsonData[item.Key] = string.Join(',', await _repository.GetQueryable<Dictionary>().Where(x => guids.Contains(x.Id)).Select(x => x.ValueCN).ToListAsync());
} // }
else if (item.Type.ToLower() == "ChildGroup".ToLower()) // else if (item.Type.ToLower() == "ChildGroup".ToLower())
{ // {
List<string> guids = new List<string>(); // List<string> guids = new List<string>();
arrays.ForEach(x => // arrays.ForEach(x =>
{ // {
guids.Add(x.ToString()); // guids.Add(x.ToString());
}); // });
JsonData[item.Key] = string.Join(',', await // JsonData[item.Key] = string.Join(',', await
_repository.GetQueryable<Dictionary>().Where(x => x.Code == item.Code).GroupJoin( // _repository.GetQueryable<Dictionary>().Where(x => x.Code == item.Code).GroupJoin(
_repository.GetQueryable<Dictionary>().Where(x => guids.Contains(x.ChildGroup)), a => a.Id, b => b.ParentId, (a, b) => new // _repository.GetQueryable<Dictionary>().Where(x => guids.Contains(x.ChildGroup)), a => a.Id, b => b.ParentId, (a, b) => new
{ // {
parent = b // parent = b
}).SelectMany(a => a.parent, (m, n) => new // }).SelectMany(a => a.parent, (m, n) => new
{ // {
value = n.ValueCN // value = n.ValueCN
}).Select(x => x.value).ToListAsync() // }).Select(x => x.value).ToListAsync()
); // );
} // }
else // else
{ // {
List<string> guids =new List<string>(); // List<string> guids =new List<string>();
arrays.ForEach(x => // arrays.ForEach(x =>
{ // {
guids.Add(x.ToString()); // guids.Add(x.ToString());
}); // });
JsonData[item.Key] = string.Join(',', await // JsonData[item.Key] = string.Join(',', await
_repository.GetQueryable<Dictionary>().Where(x => x.Code == item.Code).GroupJoin( // _repository.GetQueryable<Dictionary>().Where(x => x.Code == item.Code).GroupJoin(
_repository.GetQueryable<Dictionary>().Where(x=>guids.Contains(x.Code)), a => a.Id, b => b.ParentId, (a, b) => new // _repository.GetQueryable<Dictionary>().Where(x=>guids.Contains(x.Code)), a => a.Id, b => b.ParentId, (a, b) => new
{ // {
parent = b // parent = b
}).SelectMany(a => a.parent, (m, n) => new // }).SelectMany(a => a.parent, (m, n) => new
{ // {
value = n.ValueCN // value = n.ValueCN
}).Select(x => x.value).ToListAsync() // }).Select(x => x.value).ToListAsync()
); // );
} // }
} // }
else // else
{ // {
if (item.Type.ToLower() == "id".ToLower()) // if (item.Type.ToLower() == "id".ToLower())
{ // {
Guid guid = Guid.Parse(value.ToString()); // Guid guid = Guid.Parse(value.ToString());
JsonData[item.Key] = await _repository.GetQueryable<Dictionary>().Where(x => guid == x.Id).Select(x => x.ValueCN).FirstOrDefaultAsync(); // JsonData[item.Key] = await _repository.GetQueryable<Dictionary>().Where(x => guid == x.Id).Select(x => x.ValueCN).FirstOrDefaultAsync();
} // }
else if (item.Type.ToLower() == "ChildGroup".ToLower()) // else if (item.Type.ToLower() == "ChildGroup".ToLower())
{ // {
JsonData[item.Key] = await _repository.GetQueryable<Dictionary>().Where(x => x.Code == item.Code).Join(_repository.GetQueryable<Dictionary>().Where(x => x.ChildGroup == value.ToString()), a => a.Id, b => b.ParentId, (a, b) => new // JsonData[item.Key] = await _repository.GetQueryable<Dictionary>().Where(x => x.Code == item.Code).Join(_repository.GetQueryable<Dictionary>().Where(x => x.ChildGroup == value.ToString()), a => a.Id, b => b.ParentId, (a, b) => new
{ // {
value = b.ValueCN // value = b.ValueCN
}).Select(x => x.value).FirstOrDefaultAsync(); // }).Select(x => x.value).FirstOrDefaultAsync();
} // }
else // else
{ // {
JsonData[item.Key] = await _repository.GetQueryable<Dictionary>().Where(x=>x.Code==item.Code).Join(_repository.GetQueryable<Dictionary>().Where(x=>x.Code== value.ToString()), a => a.Id, b => b.ParentId, (a, b) => new // JsonData[item.Key] = await _repository.GetQueryable<Dictionary>().Where(x=>x.Code==item.Code).Join(_repository.GetQueryable<Dictionary>().Where(x=>x.Code== value.ToString()), a => a.Id, b => b.ParentId, (a, b) => new
{ // {
value=b.ValueCN // value=b.ValueCN
}).Select(x=>x.value).FirstOrDefaultAsync(); // }).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 对象枚举异常");
} //}

View File

@ -22,7 +22,7 @@ namespace IRaCIS.Core.Application.Service.Inspection.Interface
Task<dynamic> Enforcement(dynamic OptCommand, DataInspectionAddDTO AuditInfo, SignDTO SignInfo, dynamic fun, IResponseOutput? response = null); Task<dynamic> Enforcement(dynamic OptCommand, DataInspectionAddDTO AuditInfo, SignDTO SignInfo, dynamic fun, IResponseOutput? response = null);
Task SetEnum(DataInspectionAddDTO Data); //Task SetEnum(DataInspectionAddDTO Data);
Task<IResponseOutput> AddInspectionRecordAsync(DataInspectionAddDTO addDto, Guid? signId = null); Task<IResponseOutput> AddInspectionRecordAsync(DataInspectionAddDTO addDto, Guid? signId = null);

View File

@ -180,6 +180,18 @@ namespace IRaCIS.Core.Domain.Models
public string DateType { get; set; } public string DateType { get; set; }
/// <summary>
/// 字典Code
/// </summary>
public string DictionaryCode { get; set; }
/// <summary>
/// 字典Type
/// </summary>
public string DictionaryType { get; set; }
} }

View File

@ -39,6 +39,15 @@ namespace IRaCIS.Core.Infra.EFCore
/// <param name="Data"></param> /// <param name="Data"></param>
/// <returns></returns> /// <returns></returns>
Task<DataInspection> SetDataInspectionDateType(DataInspection Data); Task<DataInspection> SetDataInspectionDateType(DataInspection Data);
/// <summary>
/// 处理枚举
/// </summary>
/// <param name="Identification">标识</param>
/// <param name="json">json对象</param>
/// <returns></returns>
Task<string> SetEnum(string Identification, string json);
} }

View File

@ -18,6 +18,7 @@ using IRaCIS.Core.Infrastructure.Extention;
using Microsoft.Data.SqlClient; using Microsoft.Data.SqlClient;
using Newtonsoft.Json; using Newtonsoft.Json;
using IRaCIS.Core.Infra.EFCore.Dto; using IRaCIS.Core.Infra.EFCore.Dto;
using Newtonsoft.Json.Linq;
namespace IRaCIS.Core.Infra.EFCore namespace IRaCIS.Core.Infra.EFCore
{ {
@ -466,6 +467,121 @@ namespace IRaCIS.Core.Infra.EFCore
#region 稽查 #region 稽查
/// <summary>
/// 获取枚举
/// </summary>
/// <param name="Identification">标识</param>
/// <param name="json">Json对象</param>
/// <returns></returns>
/// <exception cref="BusinessValidationFailedException"></exception>
public async Task<string> 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<IDictionary<string, object>>(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<Guid> guids = new List<Guid>();
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<string> guids = new List<string>();
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<string> guids = new List<string>();
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) private async Task AddInspectionAsync(TEntity entity)
{ {
@ -519,28 +635,11 @@ namespace IRaCIS.Core.Infra.EFCore
} }
add.CreateUserId = _userInfo.Id; add.CreateUserId = _userInfo.Id;
add.IP = _userInfo.IP; add.IP = _userInfo.IP;
var JsonData = JsonConvert.DeserializeObject<IDictionary<string, object>>(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)) if (add.CreateTime == default(DateTime))
{ {
add.CreateTime = DateTime.Now; add.CreateTime = DateTime.Now;
} }
add.JsonDetail = JsonConvert.SerializeObject(JsonData); add.JsonDetail = await SetEnum(add.Identification, add.JsonDetail);
await SetDataInspectionDateType(add); await SetDataInspectionDateType(add);
} }