diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 85575ef0d..b4e7d958e 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -84,6 +84,53 @@ + + + 翻译稽查数据 + + 传入Dto + + + + + 格式化日期和时间 + + 稽查数据 + + + + + 获取外键表数据 + + 表名称 + 外键value + 要查询的外键值 + 传入的纸 + + + + + 获取枚举 + + 标识 + Json对象 + + + + + + 格式化日期和时间 + + 稽查数据 + + + + + IsNullOrEmpty + + + + 获取子数据 @@ -764,7 +811,7 @@ 文件路径 - + 相对路径 diff --git a/IRaCIS.Core.Application/Service/Common/FrontAuditConfigService.cs b/IRaCIS.Core.Application/Service/Common/FrontAuditConfigService.cs index 66cf2123f..c95e6ff52 100644 --- a/IRaCIS.Core.Application/Service/Common/FrontAuditConfigService.cs +++ b/IRaCIS.Core.Application/Service/Common/FrontAuditConfigService.cs @@ -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 _frontAuditConfigRepository; private readonly IRepository _qCChallengeDialogRepository; private readonly IRepository _qCChallengeRepository; + private readonly IRepository _dictionaryRepository; + private readonly IRepository _trialRepository; private readonly IRepository _checkChallengeDialogRepository; public FrontAuditConfigService(IRepository frontAuditConfigRepository, IRepository qCChallengeDialogRepository, IRepository qCChallengeRepository, + IRepository dictionaryRepository, + IRepository trialRepository, IRepository 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> SetInspectionEnumValue(SetInspectionEnumValueDto dto) { - return await _frontAuditConfigRepository.SetInspectionEnumValue(dto); + return await SetInspectionEnumValueData(dto); } + + + /// + /// 翻译稽查数据 + /// + /// 传入Dto + /// + private async Task> 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(); + } + + + + + + /// + /// 格式化日期和时间 + /// + /// 稽查数据 + /// + private async Task SetDataInspectionDateType(List 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>(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); + + + } + + /// + /// 获取外键表数据 + /// + /// 表名称 + /// 外键value + /// 要查询的外键值 + /// 传入的纸 + /// + private async Task GetInspectionEnumValue(List 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>(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>(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(sql, paravalue).Select(x => x.Text).ToList()); + } + + } + return JsonConvert.SerializeObject(JsonDataValue); + + } + + + /// + /// 获取枚举 + /// + /// 标识 + /// Json对象 + /// + /// + private async Task SetEnum(Guid trilaid, List 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>(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 guids = new List(); + 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 guids = new List(); + 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 guids = new List(); + 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); + + + + + } + + + + + /// + /// 格式化日期和时间 + /// + /// 稽查数据 + /// + private async Task 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>(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; + } + + /// + /// IsNullOrEmpty + /// + /// + /// + private bool IsNullOrEmpty(object value) + { + if (value == null || value.ToString() == string.Empty) + { + return true; + } + else + { + return false; + } + } + + + /// /// 获取子数据 /// diff --git a/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs index c2fa439e4..3163070f3 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs @@ -22,26 +22,7 @@ namespace IRaCIS.Core.Infra.EFCore { IRaCISDBContext _dbContext { get; set; } - /// - /// 获取中心啥的名称 - /// - /// - /// - Task SetInspectionNameValue(DataInspection Data); - /// - /// 格式化日期和时间 - /// - /// - /// - Task SetDataInspectionDateType(DataInspection Data); - - /// - /// 翻译稽查数据 - /// - /// 传入Dto - /// - Task> SetInspectionEnumValue(SetInspectionEnumValueDto dto); } diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 2e2346165..d776b7c21 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -575,480 +575,7 @@ namespace IRaCIS.Core.Infra.EFCore #region 稽查 - /// - /// 翻译稽查数据 - /// - /// 传入Dto - /// - public async Task> 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(); - } - - - - - - /// - /// 格式化日期和时间 - /// - /// 稽查数据 - /// - public async Task SetDataInspectionDateType(List 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>(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); - - - } - - /// - /// 获取外键表数据 - /// - /// 表名称 - /// 外键value - /// 要查询的外键值 - /// 传入的纸 - /// - public async Task GetInspectionEnumValue(List 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>(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>(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(sql, paravalue).Select(x => x.Text).ToList()); - } - - } - return JsonConvert.SerializeObject(JsonDataValue); - - } - - - /// - /// 获取枚举 - /// - /// 标识 - /// Json对象 - /// - /// - public async Task SetEnum(Guid trilaid, List 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>(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 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(); - - } - } - } - catch (Exception) - { - - - } - } - - - - return JsonConvert.SerializeObject(JsonData); - - - - - } - - - - - /// - /// 格式化日期和时间 - /// - /// 稽查数据 - /// - public async Task 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>(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; - } - - /// - /// IsNullOrEmpty - /// - /// - /// - private bool IsNullOrEmpty(object value) - { - if (value == null || value.ToString() == string.Empty) - { - return true; - } - else - { - return false; - } - } - - /// - /// 设置项目以及名称 - /// - /// - /// - 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 - - } +