处理枚举

This commit is contained in:
he
2022-04-24 11:41:29 +08:00
parent 9741b7a438
commit 37da8bd3e9
7 changed files with 245 additions and 110 deletions
@@ -199,6 +199,19 @@ namespace IRaCIS.Core.Application.ViewModel
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;
}
@@ -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
@@ -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<IDictionary<string, object>>(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<Guid> guids = new List<Guid>();
arrays.ForEach(x =>
{
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());
}
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
_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
{
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
_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
{
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<Dictionary>().Where(x => guid == x.Id).Select(x => x.ValueCN).FirstOrDefaultAsync();
}
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
{
value = b.ValueCN
}).Select(x => x.value).FirstOrDefaultAsync();
}
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
{
value=b.ValueCN
}).Select(x=>x.value).FirstOrDefaultAsync();
//try
//{
// var JsonData = JsonConvert.DeserializeObject<IDictionary<string, object>>(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<Guid> guids = new List<Guid>();
// arrays.ForEach(x =>
// {
// 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());
// }
// 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
// _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
// {
// 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
// _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
// {
// 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<Dictionary>().Where(x => guid == x.Id).Select(x => x.ValueCN).FirstOrDefaultAsync();
// }
// 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
// {
// value = b.ValueCN
// }).Select(x => x.value).FirstOrDefaultAsync();
// }
// 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
// {
// 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 对象枚举异常");
//}
@@ -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 SetEnum(DataInspectionAddDTO Data);
//Task SetEnum(DataInspectionAddDTO Data);
Task<IResponseOutput> AddInspectionRecordAsync(DataInspectionAddDTO addDto, Guid? signId = null);