修改一版
parent
2f2a81e4cc
commit
ae1137d2af
|
@ -84,6 +84,53 @@
|
|||
<param name="dto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.FrontAuditConfigService.SetInspectionEnumValueData(IRaCIS.Core.Infra.EFCore.Common.Dto.SetInspectionEnumValueDto)">
|
||||
<summary>
|
||||
翻译稽查数据
|
||||
</summary>
|
||||
<param name="dto">传入Dto</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.FrontAuditConfigService.SetDataInspectionDateType(System.Collections.Generic.List{System.String},System.String)">
|
||||
<summary>
|
||||
格式化日期和时间
|
||||
</summary>
|
||||
<param name="Data">稽查数据</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.FrontAuditConfigService.GetInspectionEnumValue(System.Collections.Generic.List{System.String},System.String)">
|
||||
<summary>
|
||||
获取外键表数据
|
||||
</summary>
|
||||
<param name="Table">表名称</param>
|
||||
<param name="ForeignKeyValue">外键value</param>
|
||||
<param name="ForeignKeyText">要查询的外键值</param>
|
||||
<param name="value">传入的纸</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.FrontAuditConfigService.SetEnum(System.Guid,System.Collections.Generic.List{System.String},System.String)">
|
||||
<summary>
|
||||
获取枚举
|
||||
</summary>
|
||||
<param name="Identification">标识</param>
|
||||
<param name="json">Json对象</param>
|
||||
<returns></returns>
|
||||
<exception cref="!:BusinessValidationFailedException"></exception>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.FrontAuditConfigService.SetDataInspectionDateType(IRaCIS.Core.Domain.Models.DataInspection)">
|
||||
<summary>
|
||||
格式化日期和时间
|
||||
</summary>
|
||||
<param name="Data">稽查数据</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.FrontAuditConfigService.IsNullOrEmpty(System.Object)">
|
||||
<summary>
|
||||
IsNullOrEmpty
|
||||
</summary>
|
||||
<param name="value"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.FrontAuditConfigService.GetChildrenItem(IRaCIS.Core.Application.ViewModel.GetChildrenItem)">
|
||||
<summary>
|
||||
获取子数据
|
||||
|
@ -764,7 +811,7 @@
|
|||
文件路径
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IRaCIS.Core.Application.Contracts.DTO.GetConsistencyCheckFileDto.RelativePaths">
|
||||
<member name="P:IRaCIS.Core.Application.Contracts.DTO.GetConsistencyCheckFileDto.RelativePath">
|
||||
<summary>
|
||||
相对路径
|
||||
</summary>
|
||||
|
|
|
@ -11,6 +11,10 @@ using IRaCIS.Core.Application.ViewModel;
|
|||
using Castle.Core.Internal;
|
||||
using MassTransit;
|
||||
using IRaCIS.Core.Infra.EFCore.Common.Dto;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
|
||||
namespace IRaCIS.Core.Application.Service
|
||||
{
|
||||
|
@ -25,17 +29,23 @@ namespace IRaCIS.Core.Application.Service
|
|||
private readonly IRepository<FrontAuditConfig> _frontAuditConfigRepository;
|
||||
private readonly IRepository<QCChallengeDialog> _qCChallengeDialogRepository;
|
||||
private readonly IRepository<QCChallenge> _qCChallengeRepository;
|
||||
private readonly IRepository<Dictionary> _dictionaryRepository;
|
||||
private readonly IRepository<Trial> _trialRepository;
|
||||
private readonly IRepository<CheckChallengeDialog> _checkChallengeDialogRepository;
|
||||
|
||||
public FrontAuditConfigService(IRepository<FrontAuditConfig> frontAuditConfigRepository,
|
||||
IRepository<QCChallengeDialog> qCChallengeDialogRepository,
|
||||
IRepository<QCChallenge> qCChallengeRepository,
|
||||
IRepository<Dictionary> dictionaryRepository,
|
||||
IRepository<Trial> trialRepository,
|
||||
IRepository<CheckChallengeDialog> checkChallengeDialogRepository
|
||||
)
|
||||
{
|
||||
_frontAuditConfigRepository = frontAuditConfigRepository;
|
||||
this._qCChallengeDialogRepository = qCChallengeDialogRepository;
|
||||
this._qCChallengeRepository = qCChallengeRepository;
|
||||
this._dictionaryRepository = dictionaryRepository;
|
||||
this._trialRepository = trialRepository;
|
||||
this._checkChallengeDialogRepository = checkChallengeDialogRepository;
|
||||
}
|
||||
|
||||
|
@ -171,9 +181,375 @@ namespace IRaCIS.Core.Application.Service
|
|||
[HttpPost]
|
||||
public async Task<List<string>> SetInspectionEnumValue(SetInspectionEnumValueDto dto)
|
||||
{
|
||||
return await _frontAuditConfigRepository.SetInspectionEnumValue(dto);
|
||||
return await SetInspectionEnumValueData(dto);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 翻译稽查数据
|
||||
/// </summary>
|
||||
/// <param name="dto">传入Dto</param>
|
||||
/// <returns></returns>
|
||||
private async Task<List<string>> SetInspectionEnumValueData(SetInspectionEnumValueDto dto)
|
||||
{
|
||||
var listIdentification = dto.Items.Select(x => x.Identification).ToList();
|
||||
foreach (var item in dto.Items)
|
||||
{
|
||||
if (item.Identification == string.Empty || item.Json == string.Empty)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
item.Json = await GetInspectionEnumValue(listIdentification, item.Json);
|
||||
item.Json = await SetEnum(dto.TrialId, listIdentification, item.Json);
|
||||
item.Json = await SetDataInspectionDateType(listIdentification, item.Json);
|
||||
}
|
||||
return dto.Items.Select(x => x.Json).ToList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 格式化日期和时间
|
||||
/// </summary>
|
||||
/// <param name="Data">稽查数据</param>
|
||||
/// <returns></returns>
|
||||
private async Task<string> SetDataInspectionDateType(List<string> identification, string json)
|
||||
{
|
||||
var list = await (from parent in _frontAuditConfigRepository.AsQueryable().Where(x => identification.Contains(x.Identification))
|
||||
join child in _frontAuditConfigRepository.AsQueryable().Where(x => x.EnumType == "Date" && x.IsEnable.HasValue && x.IsEnable.Value) on parent.Id equals child.ParentId
|
||||
select new DateDto()
|
||||
{
|
||||
Code = child.Code,
|
||||
DateType = child.DateType,
|
||||
}).ToListAsync();
|
||||
|
||||
list = list.GroupBy(x => new { x.Code }, (key, lst) => new DateDto()
|
||||
{
|
||||
Code = key.Code,
|
||||
DateType = lst.Max(x => x.DateType),
|
||||
}).ToList();
|
||||
|
||||
var JsonData = JsonConvert.DeserializeObject<IDictionary<string, object>>(json);
|
||||
|
||||
if (JsonData == null)
|
||||
{
|
||||
return json;
|
||||
}
|
||||
|
||||
foreach (var item in JsonData.Keys)
|
||||
{
|
||||
var datefirst = list.FirstOrDefault(x => x.Code.ToLower() == item.ToLower());
|
||||
if (datefirst != null && !IsNullOrEmpty(JsonData[item]))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (datefirst.DateType == "Date")
|
||||
{
|
||||
JsonData[item] = DateTime.Parse(JsonData[item].ToString()).ToString("yyyy-MM-dd");
|
||||
}
|
||||
|
||||
if (datefirst.DateType == "DateTime")
|
||||
{
|
||||
JsonData[item] = DateTime.Parse(JsonData[item].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return JsonConvert.SerializeObject(JsonData);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取外键表数据
|
||||
/// </summary>
|
||||
/// <param name="Table">表名称</param>
|
||||
/// <param name="ForeignKeyValue">外键value</param>
|
||||
/// <param name="ForeignKeyText">要查询的外键值</param>
|
||||
/// <param name="value">传入的纸</param>
|
||||
/// <returns></returns>
|
||||
private async Task<string> GetInspectionEnumValue(List<string> identification, string json)
|
||||
{
|
||||
var list = await (from u in _frontAuditConfigRepository.Where(x => identification.Contains(x.Identification))
|
||||
join p in _frontAuditConfigRepository.Where(x => x.EnumType == "Foreign" && x.IsEnable.HasValue && x.IsEnable.Value) on u.Id equals p.ParentId
|
||||
select new
|
||||
{
|
||||
Key = p.Code,
|
||||
ForeignKeyValue = p.ForeignKeyValue,
|
||||
ForeignKeyText = p.ForeignKeyText,
|
||||
ForeignKeyTable = p.ForeignKeyTable
|
||||
}).ToListAsync();
|
||||
|
||||
list = list.GroupBy(x => new { x.Key }, (key, lst) => new
|
||||
{
|
||||
Key = key.Key,
|
||||
ForeignKeyValue = lst.Max(x => x.ForeignKeyValue),
|
||||
ForeignKeyText = lst.Max(x => x.ForeignKeyText),
|
||||
ForeignKeyTable = lst.Max(x => x.ForeignKeyTable),
|
||||
|
||||
}).ToList();
|
||||
|
||||
|
||||
|
||||
var JsonDataValue = JsonConvert.DeserializeObject<IDictionary<string, object>>(json);
|
||||
foreach (var item in list)
|
||||
{
|
||||
if (!JsonDataValue.ContainsKey(item.Key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string Table = item.ForeignKeyTable;
|
||||
string ForeignKeyValue = item.ForeignKeyValue;
|
||||
string ForeignKeyText = item.ForeignKeyText;
|
||||
if (JsonDataValue[item.Key] != null)
|
||||
{
|
||||
string value = JsonDataValue[item.Key].ToString();
|
||||
string para = string.Empty;
|
||||
string sql = string.Empty;
|
||||
var JsonData = JsonConvert.DeserializeObject<IDictionary<string, object>>(JsonConvert.SerializeObject(new { item = value }));
|
||||
if (JsonData["item"].GetType() == typeof(JArray))
|
||||
{
|
||||
foreach (var v in JsonData["item"] as JArray)
|
||||
{
|
||||
para += para == string.Empty ? $"'{v.ToString()}'" : $",'{v.ToString()}'";
|
||||
}
|
||||
sql = $"select {ForeignKeyText} Text from {Table} where {ForeignKeyValue} in (@para)";
|
||||
}
|
||||
else
|
||||
{
|
||||
para = $"{JsonData["item"].ToString()}";
|
||||
sql = $"select {ForeignKeyText} Text from {Table} where {ForeignKeyValue} = @para";
|
||||
}
|
||||
SqlParameter[] paravalue = new SqlParameter[] {
|
||||
new SqlParameter("@para",para)
|
||||
};
|
||||
JsonDataValue[item.Key] = string.Join(",", _frontAuditConfigRepository._dbContext.Database.SqlQuery<ForeignKey>(sql, paravalue).Select(x => x.Text).ToList());
|
||||
}
|
||||
|
||||
}
|
||||
return JsonConvert.SerializeObject(JsonDataValue);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取枚举
|
||||
/// </summary>
|
||||
/// <param name="Identification">标识</param>
|
||||
/// <param name="json">Json对象</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="BusinessValidationFailedException"></exception>
|
||||
private async Task<string> SetEnum(Guid trilaid, List<string> identification, string json)
|
||||
{
|
||||
if (json == null || json == "null")
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var list = await (from u in _frontAuditConfigRepository.Where(x => identification.Contains(x.Identification))
|
||||
join p in _frontAuditConfigRepository.Where(x => x.Code != "AuditState" && x.EnumType == "Dictionary" && x.IsEnable.HasValue && x.IsEnable.Value) on u.Id equals p.ParentId
|
||||
select new
|
||||
{
|
||||
Key = p.Code,
|
||||
Code = p.DictionaryCode,
|
||||
Type = p.DictionaryType
|
||||
}).ToListAsync();
|
||||
|
||||
// 添加单双审
|
||||
var trialtype = await _trialRepository.AsQueryable().Where(x => x.Id == trilaid).Select(x => x.QCProcessEnum).FirstOrDefaultAsync();
|
||||
|
||||
list.Add(new
|
||||
{
|
||||
|
||||
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 JsonData = JsonConvert.DeserializeObject<IDictionary<string, object>>(json);
|
||||
foreach (var item in list)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (!JsonData.ContainsKey(item.Key) || JsonData[item.Key] == null)
|
||||
{
|
||||
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 _dictionaryRepository.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
|
||||
_dictionaryRepository.Where(x => x.Code == item.Code).GroupJoin(
|
||||
_dictionaryRepository.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
|
||||
_dictionaryRepository.Where(x => x.Code == item.Code).GroupJoin(
|
||||
_dictionaryRepository.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 _dictionaryRepository.Where(x => guid == x.Id).Select(x => x.ValueCN).FirstOrDefaultAsync();
|
||||
}
|
||||
else if (item.Type.ToLower() == "ChildGroup".ToLower())
|
||||
{
|
||||
JsonData[item.Key] = await _dictionaryRepository.Where(x => x.Code == item.Code).Join(_dictionaryRepository.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 _dictionaryRepository.Where(x => x.Code == item.Code).Join(_dictionaryRepository.Where(x => x.Code == value.ToString()), a => a.Id, b => b.ParentId, (a, b) => new
|
||||
{
|
||||
value = b.ValueCN
|
||||
}).Select(x => x.value).FirstOrDefaultAsync();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return JsonConvert.SerializeObject(JsonData);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 格式化日期和时间
|
||||
/// </summary>
|
||||
/// <param name="Data">稽查数据</param>
|
||||
/// <returns></returns>
|
||||
private async Task<DataInspection> SetDataInspectionDateType(DataInspection Data)
|
||||
{
|
||||
var list = await (from parent in _frontAuditConfigRepository.AsQueryable().Where(x => x.Identification == Data.Identification)
|
||||
join child in _frontAuditConfigRepository.AsQueryable().Where(x => x.EnumType == "Date") on parent.Id equals child.ParentId
|
||||
select new DateDto()
|
||||
{
|
||||
Code = child.Code,
|
||||
DateType = child.DateType,
|
||||
}).ToListAsync();
|
||||
|
||||
var JsonData = JsonConvert.DeserializeObject<IDictionary<string, object>>(Data.JsonDetail);
|
||||
|
||||
foreach (var item in JsonData.Keys)
|
||||
{
|
||||
var datefirst = list.FirstOrDefault(x => x.Code.ToLower() == item.ToLower());
|
||||
if (datefirst != null && !IsNullOrEmpty(JsonData[item]))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (datefirst.DateType == "Date")
|
||||
{
|
||||
JsonData[item] = DateTime.Parse(JsonData[item].ToString()).ToString("yyyy-MM-dd");
|
||||
}
|
||||
|
||||
if (datefirst.DateType == "DateTime")
|
||||
{
|
||||
JsonData[item] = DateTime.Parse(JsonData[item].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Data.JsonDetail = JsonConvert.SerializeObject(JsonData);
|
||||
|
||||
return Data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// IsNullOrEmpty
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
private bool IsNullOrEmpty(object value)
|
||||
{
|
||||
if (value == null || value.ToString() == string.Empty)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取子数据
|
||||
/// </summary>
|
||||
|
|
|
@ -22,26 +22,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
{
|
||||
IRaCISDBContext _dbContext { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取中心啥的名称
|
||||
/// </summary>
|
||||
/// <param name="Data"></param>
|
||||
/// <returns></returns>
|
||||
Task SetInspectionNameValue(DataInspection Data);
|
||||
|
||||
/// <summary>
|
||||
/// 格式化日期和时间
|
||||
/// </summary>
|
||||
/// <param name="Data"></param>
|
||||
/// <returns></returns>
|
||||
Task<DataInspection> SetDataInspectionDateType(DataInspection Data);
|
||||
|
||||
/// <summary>
|
||||
/// 翻译稽查数据
|
||||
/// </summary>
|
||||
/// <param name="dto">传入Dto</param>
|
||||
/// <returns></returns>
|
||||
Task<List<string>> SetInspectionEnumValue(SetInspectionEnumValueDto dto);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -575,480 +575,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
#region 稽查
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 翻译稽查数据
|
||||
/// </summary>
|
||||
/// <param name="dto">传入Dto</param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<string>> SetInspectionEnumValue(SetInspectionEnumValueDto dto)
|
||||
{
|
||||
var listIdentification = dto.Items.Select(x => x.Identification).ToList() ;
|
||||
foreach (var item in dto.Items)
|
||||
{
|
||||
if (item.Identification == string.Empty || item.Json == string.Empty)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
item.Json = await GetInspectionEnumValue(listIdentification, item.Json);
|
||||
item.Json = await SetEnum(dto.TrialId, listIdentification, item.Json);
|
||||
item.Json = await SetDataInspectionDateType(listIdentification, item.Json);
|
||||
}
|
||||
return dto.Items.Select(x => x.Json).ToList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 格式化日期和时间
|
||||
/// </summary>
|
||||
/// <param name="Data">稽查数据</param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> SetDataInspectionDateType(List<string> identification, string json)
|
||||
{
|
||||
var list = await (from parent in _dbContext.FrontAuditConfig.AsQueryable().Where(x => identification.Contains(x.Identification))
|
||||
join child in _dbContext.FrontAuditConfig.AsQueryable().Where(x => x.EnumType == "Date" && x.IsEnable.HasValue && x.IsEnable.Value) on parent.Id equals child.ParentId
|
||||
select new DateDto()
|
||||
{
|
||||
Code = child.Code,
|
||||
DateType = child.DateType,
|
||||
}).ToListAsync();
|
||||
|
||||
list = list.GroupBy(x => new { x.Code }, (key, lst) => new DateDto()
|
||||
{
|
||||
Code = key.Code,
|
||||
DateType = lst.Max(x => x.DateType),
|
||||
}).ToList();
|
||||
|
||||
var JsonData = JsonConvert.DeserializeObject<IDictionary<string, object>>(json);
|
||||
|
||||
if (JsonData == null)
|
||||
{
|
||||
return json;
|
||||
}
|
||||
|
||||
foreach (var item in JsonData.Keys)
|
||||
{
|
||||
var datefirst = list.FirstOrDefault(x => x.Code.ToLower() == item.ToLower());
|
||||
if (datefirst != null && !IsNullOrEmpty(JsonData[item]))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (datefirst.DateType == "Date")
|
||||
{
|
||||
JsonData[item] = DateTime.Parse(JsonData[item].ToString()).ToString("yyyy-MM-dd");
|
||||
}
|
||||
|
||||
if (datefirst.DateType == "DateTime")
|
||||
{
|
||||
JsonData[item] = DateTime.Parse(JsonData[item].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return JsonConvert.SerializeObject(JsonData);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取外键表数据
|
||||
/// </summary>
|
||||
/// <param name="Table">表名称</param>
|
||||
/// <param name="ForeignKeyValue">外键value</param>
|
||||
/// <param name="ForeignKeyText">要查询的外键值</param>
|
||||
/// <param name="value">传入的纸</param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> GetInspectionEnumValue(List<string> identification, string json)
|
||||
{
|
||||
var list = await (from u in _dbContext.FrontAuditConfig.Where(x => identification.Contains(x.Identification))
|
||||
join p in _dbContext.FrontAuditConfig.Where(x => x.EnumType == "Foreign" && x.IsEnable.HasValue && x.IsEnable.Value) on u.Id equals p.ParentId
|
||||
select new
|
||||
{
|
||||
Key = p.Code,
|
||||
ForeignKeyValue = p.ForeignKeyValue,
|
||||
ForeignKeyText = p.ForeignKeyText,
|
||||
ForeignKeyTable = p.ForeignKeyTable
|
||||
}).ToListAsync();
|
||||
|
||||
list= list.GroupBy(x => new { x.Key }, (key, lst) => new
|
||||
{
|
||||
Key=key.Key,
|
||||
ForeignKeyValue=lst.Max(x=>x.ForeignKeyValue),
|
||||
ForeignKeyText = lst.Max(x => x.ForeignKeyText),
|
||||
ForeignKeyTable = lst.Max(x => x.ForeignKeyTable),
|
||||
|
||||
}).ToList();
|
||||
|
||||
|
||||
|
||||
var JsonDataValue = JsonConvert.DeserializeObject<IDictionary<string, object>>(json);
|
||||
foreach (var item in list)
|
||||
{
|
||||
if (!JsonDataValue.ContainsKey(item.Key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string Table = item.ForeignKeyTable;
|
||||
string ForeignKeyValue = item.ForeignKeyValue;
|
||||
string ForeignKeyText = item.ForeignKeyText;
|
||||
if (JsonDataValue[item.Key] != null)
|
||||
{
|
||||
string value = JsonDataValue[item.Key].ToString();
|
||||
string para = string.Empty;
|
||||
string sql = string.Empty;
|
||||
var JsonData = JsonConvert.DeserializeObject<IDictionary<string, object>>(JsonConvert.SerializeObject(new { item = value }));
|
||||
if (JsonData["item"].GetType() == typeof(JArray))
|
||||
{
|
||||
foreach (var v in JsonData["item"] as JArray)
|
||||
{
|
||||
para += para == string.Empty ? $"'{v.ToString()}'" : $",'{v.ToString()}'";
|
||||
}
|
||||
sql = $"select {ForeignKeyText} Text from {Table} where {ForeignKeyValue} in (@para)";
|
||||
}
|
||||
else
|
||||
{
|
||||
para = $"{JsonData["item"].ToString()}";
|
||||
sql = $"select {ForeignKeyText} Text from {Table} where {ForeignKeyValue} = @para";
|
||||
}
|
||||
SqlParameter[] paravalue = new SqlParameter[] {
|
||||
new SqlParameter("@para",para)
|
||||
};
|
||||
JsonDataValue[item.Key] = string.Join(",", _dbContext.Database.SqlQuery<ForeignKey>(sql, paravalue).Select(x => x.Text).ToList());
|
||||
}
|
||||
|
||||
}
|
||||
return JsonConvert.SerializeObject(JsonDataValue);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取枚举
|
||||
/// </summary>
|
||||
/// <param name="Identification">标识</param>
|
||||
/// <param name="json">Json对象</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="BusinessValidationFailedException"></exception>
|
||||
public async Task<string> SetEnum(Guid trilaid, List<string> identification, string json)
|
||||
{
|
||||
if (json == null||json=="null")
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var list = await (from u in _dbContext.FrontAuditConfig.Where(x => identification.Contains(x.Identification))
|
||||
join p in _dbContext.FrontAuditConfig.Where(x => x.Code != "AuditState" && x.EnumType == "Dictionary"&&x.IsEnable.HasValue&& x.IsEnable.Value) on u.Id equals p.ParentId
|
||||
select new
|
||||
{
|
||||
Key = p.Code,
|
||||
Code = p.DictionaryCode,
|
||||
Type = p.DictionaryType
|
||||
}).ToListAsync();
|
||||
|
||||
// 添加单双审
|
||||
var trialtype = await _dbContext.Trial.AsQueryable().Where(x => x.Id == trilaid).Select(x => x.QCProcessEnum).FirstOrDefaultAsync();
|
||||
|
||||
list.Add(new
|
||||
{
|
||||
|
||||
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 JsonData = JsonConvert.DeserializeObject<IDictionary<string, object>>(json);
|
||||
foreach (var item in list)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (!JsonData.ContainsKey(item.Key) || JsonData[item.Key]==null)
|
||||
{
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return JsonConvert.SerializeObject(JsonData);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 格式化日期和时间
|
||||
/// </summary>
|
||||
/// <param name="Data">稽查数据</param>
|
||||
/// <returns></returns>
|
||||
public async Task<DataInspection> SetDataInspectionDateType(DataInspection Data)
|
||||
{
|
||||
var list = await (from parent in _dbContext.FrontAuditConfig.AsQueryable().Where(x => x.Identification == Data.Identification)
|
||||
join child in _dbContext.FrontAuditConfig.AsQueryable().Where(x => x.EnumType == "Date") on parent.Id equals child.ParentId
|
||||
select new DateDto()
|
||||
{
|
||||
Code = child.Code,
|
||||
DateType = child.DateType,
|
||||
}).ToListAsync();
|
||||
|
||||
var JsonData = JsonConvert.DeserializeObject<IDictionary<string, object>>(Data.JsonDetail);
|
||||
|
||||
foreach (var item in JsonData.Keys)
|
||||
{
|
||||
var datefirst = list.FirstOrDefault(x => x.Code.ToLower() == item.ToLower());
|
||||
if (datefirst != null && !IsNullOrEmpty(JsonData[item]))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (datefirst.DateType == "Date")
|
||||
{
|
||||
JsonData[item] = DateTime.Parse(JsonData[item].ToString()).ToString("yyyy-MM-dd");
|
||||
}
|
||||
|
||||
if (datefirst.DateType == "DateTime")
|
||||
{
|
||||
JsonData[item] = DateTime.Parse(JsonData[item].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Data.JsonDetail = JsonConvert.SerializeObject(JsonData);
|
||||
|
||||
return Data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// IsNullOrEmpty
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
private bool IsNullOrEmpty(object value)
|
||||
{
|
||||
if (value == null || value.ToString() == string.Empty)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置项目以及名称
|
||||
/// </summary>
|
||||
/// <param name="Data"></param>
|
||||
/// <returns></returns>
|
||||
public async Task SetInspectionNameValue(DataInspection Data)
|
||||
{
|
||||
#region 项目名称
|
||||
|
||||
var trialdata = await _dbContext.Trial.Select(x => new { x.Id, x.ResearchProgramNo, x.ExperimentName, }).FirstOrDefaultAsync(x => x.Id == Data.TrialId);
|
||||
if (IsNullOrEmpty(Data.ResearchProgramNo))
|
||||
{
|
||||
|
||||
Data.ResearchProgramNo = trialdata?.ResearchProgramNo;
|
||||
}
|
||||
|
||||
if (IsNullOrEmpty(Data.TrialName))
|
||||
{
|
||||
Data.TrialName = trialdata?.ExperimentName;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 测试中心名称
|
||||
|
||||
|
||||
Data.SiteCode = (await _dbContext.TrialSite.IgnoreQueryFilters().FirstOrDefaultAsync(x => x.TrialId == Data.TrialId && x.SiteId == Data.SiteId))?.TrialSiteCode;
|
||||
|
||||
|
||||
|
||||
if (IsNullOrEmpty(Data.SiteName) && Data.SiteId != null)
|
||||
{
|
||||
var sitedata = await _dbContext.Site.Where(x => x.Id == Data.SiteId).Select(x => new { x.SiteName }).FirstOrDefaultAsync();
|
||||
Data.SiteName = sitedata?.SiteName;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 受试者
|
||||
|
||||
|
||||
if (IsNullOrEmpty(Data.SubjectCode) && Data.SubjectId != null)
|
||||
{
|
||||
|
||||
Data.SubjectCode = (await _dbContext.Subject.Where(x => x.Id == Data.SubjectId).Select(x => new { x.Code }).FirstOrDefaultAsync())?.Code;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 访视
|
||||
if (IsNullOrEmpty(Data.SubjectVisitName))
|
||||
{
|
||||
Data.SubjectVisitName = (await _dbContext.SubjectVisit.Where(x => x.Id == Data.SubjectVisitId).Select(x => new { x.VisitName }).FirstOrDefaultAsync())?.VisitName;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 创建者
|
||||
|
||||
if (IsNullOrEmpty(Data.CreateUserName))
|
||||
{
|
||||
Data.CreateUserName = _userInfo.RealName;
|
||||
}
|
||||
|
||||
if (IsNullOrEmpty(Data.RoleName))
|
||||
{
|
||||
Data.RoleName = _userInfo.UserTypeShortName;
|
||||
}
|
||||
|
||||
//if (IsNullOrEmpty(Data.CreateUserName) || IsNullOrEmpty(Data.RoleName))
|
||||
//{
|
||||
// var userdata = await _dbContext.Users.AsQueryable().Where(x => x.Id == Data.CreateUserId).GroupJoin(_dbContext.UserType.AsQueryable(), a => a.UserTypeId, b => b.Id, (a, b) => new
|
||||
// {
|
||||
// UserName = a.FirstName + a.LastName,
|
||||
// Role = b
|
||||
// }).SelectMany(a => a.Role, (m, n) => new
|
||||
// {
|
||||
// UserName = m.UserName,
|
||||
// RoleName = n.UserTypeShortName
|
||||
// }).FirstOrDefaultAsync();
|
||||
|
||||
// if (userdata != null)
|
||||
// {
|
||||
// if (IsNullOrEmpty(Data.CreateUserName))
|
||||
// {
|
||||
// Data.CreateUserName = userdata?.UserName;
|
||||
// }
|
||||
|
||||
|
||||
// if (IsNullOrEmpty(Data.RoleName))
|
||||
// {
|
||||
// Data.RoleName = userdata?.RoleName;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region 取操作类型
|
||||
try
|
||||
{
|
||||
var from = await _dbContext.FrontAuditConfig.FirstOrDefaultAsync(x => x.Identification == Data.Identification);
|
||||
Data.ObjectType = from.ObjectTypeId;
|
||||
Data.OptType = from.OptTypeId;
|
||||
Data.ChildrenType = from.ChildrenTypeId;
|
||||
Data.ModuleType = from.ModuleTypeId;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
throw new BusinessValidationFailedException("操作标识异常");
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue