处理枚举
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user