修改仓储
parent
2b84cdd5a6
commit
cf08b85811
|
@ -224,39 +224,46 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
}
|
||||
|
||||
|
||||
/// <summary>EF跟踪方式 先查询出来,再更新部分字段 稽查的时候需要完整的实体信息</summary>
|
||||
public async Task<bool> UpdatePartialAsync(TEntity entity, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, CancellationToken cancellationToken = default)
|
||||
|
||||
|
||||
|
||||
/// <summary>EF跟踪方式 外层先有查询好的完成实体,再更新部分字段 稽查的时候需要完整的实体信息</summary>
|
||||
public async Task<bool> UpdatePartialAsync(TEntity waitModifyEntity, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entityEntry = _dbContext.Entry(entity);
|
||||
|
||||
|
||||
var entityEntry = _dbContext.Entry(waitModifyEntity);
|
||||
entityEntry.State = EntityState.Detached;
|
||||
|
||||
|
||||
List<PropertyInfo> list = ((MemberInitExpression)updateFactory.Body).Bindings.Select(mb => mb.Member.Name)
|
||||
.Select(propName => typeof(TEntity).GetProperty(propName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)).ToList();
|
||||
|
||||
Func<TEntity, TEntity> func = updateFactory.Compile();
|
||||
|
||||
TEntity applyObj = func(entity);
|
||||
|
||||
foreach (PropertyInfo prop in list)
|
||||
{
|
||||
object value = prop.GetValue((object)applyObj);
|
||||
prop.SetValue((object)entity, value);
|
||||
|
||||
_dbContext.Entry(entity).Property(prop.Name).IsModified = true;
|
||||
}
|
||||
ModifyPartialFiled(waitModifyEntity, updateFactory);
|
||||
|
||||
return await SaveChangesAsync(autoSave);
|
||||
|
||||
}
|
||||
|
||||
public async Task UpdatePartialSearchFirstAsync(Expression<Func<TEntity, bool>> updateFilter,
|
||||
Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (updateFilter == null)
|
||||
{
|
||||
throw new ArgumentException("更新过滤条件不允许为空", nameof(updateFilter));
|
||||
}
|
||||
|
||||
var searchEntityList = await _dbSet.AsNoTracking().Where(updateFilter).ToListAsync();
|
||||
|
||||
foreach (var needUpdateEntity in searchEntityList)
|
||||
{
|
||||
await UpdatePartialAsync(needUpdateEntity, updateFactory, autoSave);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>EF跟踪方式 先查询出来,再更新部分字段 稽查的时候需要完整的实体信息</summary>
|
||||
public async Task<TEntity> UpdatePartialSearchFirstAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
//不跟踪 查询出来的实体就是Detached
|
||||
var searchEntity = await _dbSet.AsNoTracking().FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
if (searchEntity == null)
|
||||
|
@ -266,35 +273,39 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
}
|
||||
|
||||
|
||||
List<PropertyInfo> list = ((MemberInitExpression)updateFactory.Body).Bindings.Select(mb => mb.Member.Name)
|
||||
.Select(propName => typeof(TEntity).GetProperty(propName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)).ToList();
|
||||
|
||||
Func<TEntity, TEntity> func = updateFactory.Compile();
|
||||
|
||||
TEntity applyObj = func(searchEntity);
|
||||
|
||||
foreach (PropertyInfo prop in list)
|
||||
{
|
||||
object value = prop.GetValue((object)applyObj);
|
||||
prop.SetValue((object)searchEntity, value);
|
||||
|
||||
_dbContext.Entry(searchEntity).Property(prop.Name).IsModified = true;
|
||||
}
|
||||
|
||||
|
||||
ModifyPartialFiled(searchEntity, updateFactory);
|
||||
|
||||
|
||||
await SaveChangesAsync(autoSave);
|
||||
|
||||
return searchEntity;
|
||||
}
|
||||
|
||||
|
||||
private void ModifyPartialFiled(TEntity waitModifyEntity, Expression<Func<TEntity, TEntity>> updateFactory)
|
||||
{
|
||||
List<PropertyInfo> list = ((MemberInitExpression)updateFactory.Body).Bindings.Select(mb => mb.Member.Name)
|
||||
.Select(propName => typeof(TEntity).GetProperty(propName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)).ToList();
|
||||
|
||||
Func<TEntity, TEntity> func = updateFactory.Compile();
|
||||
|
||||
TEntity applyObj = func(waitModifyEntity);
|
||||
|
||||
foreach (PropertyInfo prop in list)
|
||||
{
|
||||
object value = prop.GetValue(applyObj);
|
||||
prop.SetValue(waitModifyEntity, value);
|
||||
|
||||
_dbContext.Entry(waitModifyEntity).Property(prop.Name).IsModified = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>EF跟踪方式 删除</summary>
|
||||
public async Task<bool> DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
_dbSet.Remove(entity);
|
||||
|
||||
|
||||
|
||||
|
||||
if (autoSave)
|
||||
|
@ -537,17 +548,17 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
/// <exception cref="BusinessValidationFailedException"></exception>
|
||||
public async Task<string> SetEnum(Guid trilaid, 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.Code== "AuditState"||(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();
|
||||
var list = await (from u in _dbContext.FrontAuditConfig.Where(x => x.Identification == Identification)
|
||||
join p in _dbContext.FrontAuditConfig.Where(x => x.Code == "AuditState" || (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();
|
||||
|
||||
// 添加单双审
|
||||
var trialtype = await _dbContext.Trial.AsQueryable().Where(x => x.Id == trilaid).Select(x => x.QCProcessEnum).FirstOrDefaultAsync();
|
||||
var trialtype = await _dbContext.Trial.AsQueryable().Where(x => x.Id == trilaid).Select(x => x.QCProcessEnum).FirstOrDefaultAsync();
|
||||
|
||||
list.Add(new
|
||||
{
|
||||
|
@ -709,7 +720,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
else if (typeof(TEntity) == typeof(DicomStudy))
|
||||
{
|
||||
DicomStudy data = entity as DicomStudy;
|
||||
await UpdateSubjectVisit(data.SubjectVisitId, SubmitStateEnum.ToSubmit,"上传Dicom影像");
|
||||
await UpdateSubjectVisit(data.SubjectVisitId, SubmitStateEnum.ToSubmit, "上传Dicom影像");
|
||||
}
|
||||
// 非Dicom影像
|
||||
else if (typeof(TEntity) == typeof(NoneDicomStudy))
|
||||
|
@ -719,7 +730,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
}
|
||||
|
||||
// 修改访视状态记录稽查
|
||||
async Task UpdateSubjectVisit(Guid subvisitVisit, SubmitStateEnum submit,string reason)
|
||||
async Task UpdateSubjectVisit(Guid subvisitVisit, SubmitStateEnum submit, string reason)
|
||||
{
|
||||
var subjectvisit = await _dbContext.SubjectVisit.AsNoTracking().AsQueryable().Where(x => x.Id == subvisitVisit).FirstOrDefaultAsync();
|
||||
if (subjectvisit.SubmitState != submit)
|
||||
|
@ -730,13 +741,13 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
List<DataInspection> inspections = new List<DataInspection>();
|
||||
inspections.Add(new DataInspection()
|
||||
{
|
||||
Identification= "Edit|Visit|Status|Visit-Image Upload|Add Image",
|
||||
TrialId= subjectvisit.TrialId,
|
||||
SiteId=subjectvisit.SiteId,
|
||||
SubjectId=subjectvisit.SubjectId,
|
||||
SubjectVisitId=subjectvisit.Id,
|
||||
Reason= reason,
|
||||
JsonDetail= subjectvisit.ToJcJson(),
|
||||
Identification = "Edit|Visit|Status|Visit-Image Upload|Add Image",
|
||||
TrialId = subjectvisit.TrialId,
|
||||
SiteId = subjectvisit.SiteId,
|
||||
SubjectId = subjectvisit.SubjectId,
|
||||
SubjectVisitId = subjectvisit.Id,
|
||||
Reason = reason,
|
||||
JsonDetail = subjectvisit.ToJcJson(),
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -774,7 +785,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
{
|
||||
add.CreateTime = DateTime.Now;
|
||||
}
|
||||
add.JsonDetail = await SetEnum(add.TrialId,add.Identification, add.JsonDetail);
|
||||
add.JsonDetail = await SetEnum(add.TrialId, add.Identification, add.JsonDetail);
|
||||
await SetDataInspectionDateType(add);
|
||||
}
|
||||
|
||||
|
@ -782,7 +793,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// IsNullOrEmpty
|
||||
|
|
Loading…
Reference in New Issue