Suject稽查bug trigger 两次事务
parent
d4fdf74198
commit
4388dbd547
|
@ -140,18 +140,21 @@ namespace IRaCIS.Core.Application.Service.Inspection
|
||||||
};
|
};
|
||||||
|
|
||||||
query = query.WhereIf(dto.SiteId != null, x => x.SiteId == dto.SiteId)
|
query = query.WhereIf(dto.SiteId != null, x => x.SiteId == dto.SiteId)
|
||||||
.WhereIf(dto.RelationDeadlineTime != null, x => x.CreateTime <= dto.RelationDeadlineTime.Value.AddSeconds(1))
|
//.WhereIf(dto.RelationDeadlineTime != null, x => x.CreateTime <= dto.RelationDeadlineTime.Value.AddSeconds(1))
|
||||||
.WhereIf(dto.TrialId != null, t => (t.TrialId == dto.TrialId) || (t.CreateTime >= trialData.CreateTime && t.CreateTime <= trialData.TrialFinishTime))
|
.WhereIf(dto.TrialId != null, t => (t.TrialId == dto.TrialId) || (t.CreateTime >= trialData.CreateTime && t.CreateTime <= trialData.TrialFinishTime))
|
||||||
.WhereIf(dto.BatchId != null && dto.ObjectRelationParentId == null && dto.GeneralId == null, x => x.BatchId == dto.BatchId)
|
.WhereIf(dto.BatchId != null && dto.ObjectRelationParentId == null && dto.GeneralId == null, x => x.BatchId == dto.BatchId)
|
||||||
.WhereIf(dto.BatchId != null && dto.GeneralId != null && dto.ObjectRelationParentId == null, x => x.BatchId == dto.BatchId || x.GeneralId == dto.GeneralId || x.ObjectRelationParentId== dto.GeneralId)
|
.WhereIf(dto.BatchId != null && dto.GeneralId != null && dto.ObjectRelationParentId == null, x => x.BatchId == dto.BatchId ||
|
||||||
//父稽查 查看关联子记录 x.ObjectRelationParentId== dto.GeneralId
|
((x.GeneralId == dto.GeneralId || x.ObjectRelationParentId == dto.GeneralId) && x.CreateTime <= dto.RelationDeadlineTime.Value.AddSeconds(1)))
|
||||||
.WhereIf(dto.ObjectRelationParentId != null && dto.BatchId != null && dto.GeneralId != null,
|
.WhereIf(dto.ObjectRelationParentId != null && dto.BatchId != null && dto.GeneralId != null,
|
||||||
x => x.GeneralId == dto.ObjectRelationParentId || //子稽查 查询父记录
|
x =>
|
||||||
x.GeneralId == dto.GeneralId || //同一对象
|
|
||||||
x.BatchId == dto.BatchId || //同一事务批次
|
x.BatchId == dto.BatchId || //同一事务批次
|
||||||
x.ObjectRelationParentId == dto.GeneralId || //父稽查 查询子记录
|
x.ObjectRelationParentId == dto.ObjectRelationParentId || //不同对象 但是同一层级 适用于子对象
|
||||||
x.ObjectRelationParentId == dto.ObjectRelationParentId //不同对象 但是同一层级
|
|
||||||
)
|
|
||||||
|
( ( x.GeneralId == dto.ObjectRelationParentId || //子稽查 查询父记录
|
||||||
|
x.GeneralId == dto.GeneralId || //同一对象
|
||||||
|
x.ObjectRelationParentId == dto.GeneralId //父稽查 查询子记录
|
||||||
|
)&& x.CreateTime <= dto.RelationDeadlineTime.Value.AddSeconds(1)))
|
||||||
.WhereIf(!dto.SubjectInfo.IsNullOrEmpty(), x => x.SubjectCode.Contains(dto.SubjectInfo))
|
.WhereIf(!dto.SubjectInfo.IsNullOrEmpty(), x => x.SubjectCode.Contains(dto.SubjectInfo))
|
||||||
//.WhereIf(dto.VisitPlanInfo != null&& dto.VisitPlanInfo!=(decimal) 1.11, x => x.VisitNum == dto.VisitPlanInfo)
|
//.WhereIf(dto.VisitPlanInfo != null&& dto.VisitPlanInfo!=(decimal) 1.11, x => x.VisitNum == dto.VisitPlanInfo)
|
||||||
//.WhereIf(dto.VisitPlanInfo != (decimal)1.11,x=>x.InPlan!=null&& x.InPlan==false)
|
//.WhereIf(dto.VisitPlanInfo != (decimal)1.11,x=>x.InPlan!=null&& x.InPlan==false)
|
||||||
|
|
|
@ -65,7 +65,7 @@ namespace IRaCIS.Application.Services
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
await _repository.SaveChangesAsync();
|
await _subjectRepository.SaveChangesAsync();
|
||||||
|
|
||||||
return ResponseOutput.Ok(mapedSubject.Id.ToString());
|
return ResponseOutput.Ok(mapedSubject.Id.ToString());
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace IRaCIS.Core.Application.Triggers
|
||||||
|
|
||||||
|
|
||||||
await _subjectVisitRepository.AddRangeAsync(svList);
|
await _subjectVisitRepository.AddRangeAsync(svList);
|
||||||
|
await _subjectVisitRepository.SaveChangesAsync();
|
||||||
|
|
||||||
#region 在f访视计划确认的时候处理 给subject添加访视计划
|
#region 在f访视计划确认的时候处理 给subject添加访视计划
|
||||||
////已添加受试者 都不存在该新增的计划名称 那么该项目所有受试者都增加一个访视记录
|
////已添加受试者 都不存在该新增的计划名称 那么该项目所有受试者都增加一个访视记录
|
||||||
|
|
|
@ -411,6 +411,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
||||||
|
|
||||||
await InsertInspection<Subject>(entity, type, x => new InspectionConvertDTO()
|
await InsertInspection<Subject>(entity, type, x => new InspectionConvertDTO()
|
||||||
{
|
{
|
||||||
|
GeneralId=x.Id,
|
||||||
SubjectId = x.Id,
|
SubjectId = x.Id,
|
||||||
SubjectCode = x.Code,
|
SubjectCode = x.Code,
|
||||||
}, new
|
}, new
|
||||||
|
@ -543,13 +544,14 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
||||||
var subjectCode = entity.Subject?.Code;
|
var subjectCode = entity.Subject?.Code;
|
||||||
await InsertInspection<SubjectVisit>(item.Entity as SubjectVisit, type, x => new InspectionConvertDTO()
|
await InsertInspection<SubjectVisit>(item.Entity as SubjectVisit, type, x => new InspectionConvertDTO()
|
||||||
{
|
{
|
||||||
|
GeneralId=x.Id,
|
||||||
SubjectCode = subjectCode,
|
SubjectCode = subjectCode,
|
||||||
SubjectId = x.SubjectId,
|
SubjectId = x.SubjectId,
|
||||||
SubjectVisitId = x.Id,
|
SubjectVisitId = x.Id,
|
||||||
SubjectVisitName = x.VisitName,
|
SubjectVisitName = x.VisitName,
|
||||||
BlindName = x.BlindName,
|
BlindName = x.BlindName,
|
||||||
Reason = reason,
|
Reason = reason,
|
||||||
}, null, item.OriginalValues);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 既往手术史
|
// 既往手术史
|
||||||
|
@ -907,6 +909,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
||||||
await InsertInspection<ReadModule>(item.Entity as ReadModule, type, x => new InspectionConvertDTO()
|
await InsertInspection<ReadModule>(item.Entity as ReadModule, type, x => new InspectionConvertDTO()
|
||||||
{
|
{
|
||||||
GeneralId = x.Id,
|
GeneralId = x.Id,
|
||||||
|
ObjectRelationParentId = entity.ReadingPeriodSetId,
|
||||||
SubjectVisitId = x.SubjectVisitId,
|
SubjectVisitId = x.SubjectVisitId,
|
||||||
IsDistinctionInterface = false,
|
IsDistinctionInterface = false,
|
||||||
}, new
|
}, new
|
||||||
|
@ -969,7 +972,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
||||||
/// <param name="expression">表达式</param>
|
/// <param name="expression">表达式</param>
|
||||||
/// <param name="otherItem">其他对象</param>
|
/// <param name="otherItem">其他对象</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task InsertInspection<T>(T entityObj, string type, Expression<Func<T, InspectionConvertDTO>> expression = null, object otherItem = null, object originaldata = null) where T : class
|
public async Task InsertInspection<T>(T entityObj, string type, Expression<Func<T, InspectionConvertDTO>> expression = null, object otherItem = null, object originaldata = null) where T : Entity
|
||||||
{
|
{
|
||||||
|
|
||||||
InspectionConvertDTO inspection = new InspectionConvertDTO();
|
InspectionConvertDTO inspection = new InspectionConvertDTO();
|
||||||
|
@ -981,6 +984,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
||||||
inspection = f(entityObj);
|
inspection = f(entityObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//避免重复赋值
|
||||||
|
inspection.GeneralId = entityObj.Id;
|
||||||
|
|
||||||
inspection.Identification = await GetInspectionRecordIdentificationAsync(entityObj, type, inspection.IsDistinctionInterface);
|
inspection.Identification = await GetInspectionRecordIdentificationAsync(entityObj, type, inspection.IsDistinctionInterface);
|
||||||
|
|
||||||
|
@ -1028,7 +1033,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
||||||
|
|
||||||
inspection.BatchId = _userInfo.BatchId.Value;
|
inspection.BatchId = _userInfo.BatchId.Value;
|
||||||
|
|
||||||
await _dbContext.DataInspection.AddAsync(inspection);
|
await _dbContext.DataInspection.AddAsync(inspection );
|
||||||
|
|
||||||
|
|
||||||
//await AddInspectionRecordAsync( entityObj, inspection, otherItem);
|
//await AddInspectionRecordAsync( entityObj, inspection, otherItem);
|
||||||
|
|
|
@ -463,8 +463,14 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var entities = ChangeTracker.Entries().Where(u => (u.State == EntityState.Modified || u.State == EntityState.Deleted || u.State == EntityState.Added)).Where(x => x.Entity.GetType() != typeof(DataInspection)).ToList();
|
//触发器里面提交事务 业务方法里面提交事务 会记录两次
|
||||||
|
var inspectionGeneralIdList = ChangeTracker.Entries().Where(t => typeof(DataInspection).IsAssignableFrom(t.Entity.GetType())).Select(t => ((DataInspection)t.Entity).GeneralId).ToList();
|
||||||
|
|
||||||
|
var entities = ChangeTracker.Entries().Where(u => (u.State == EntityState.Modified || u.State == EntityState.Deleted || u.State == EntityState.Added))
|
||||||
|
.Where(t => ! typeof(DataInspection).IsAssignableFrom(t.Entity.GetType()) && !inspectionGeneralIdList.Contains(((Entity) t.Entity).Id ))
|
||||||
|
.ToList();
|
||||||
AuditingData auditingData = new AuditingData(this, _userInfo);
|
AuditingData auditingData = new AuditingData(this, _userInfo);
|
||||||
|
|
||||||
await auditingData.IncomingEntitys(entities);
|
await auditingData.IncomingEntitys(entities);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
|
|
@ -394,6 +394,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
|
|
||||||
public async Task<bool> SaveChangesAsync(CancellationToken cancellationToken = default)
|
public async Task<bool> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
|
||||||
return await _dbContext.SaveChangesAsync(cancellationToken) > 0;
|
return await _dbContext.SaveChangesAsync(cancellationToken) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue