From 9d5108e68378de1b51ca133636cf5d7912f8d794 Mon Sep 17 00:00:00 2001 From: he <10978375@qq.com> Date: Mon, 25 Apr 2022 14:16:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=93=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Visit/VisitPlanService.cs | 1 + IRaCIS.Core.Domain/Common/JsonConvert.cs | 2 +- .../Repository/ICommandRepository.cs | 4 ++-- .../Repository/Repository.cs | 17 +++++++---------- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Visit/VisitPlanService.cs b/IRaCIS.Core.Application/Service/Visit/VisitPlanService.cs index 8ebd6e3a6..da9df6202 100644 --- a/IRaCIS.Core.Application/Service/Visit/VisitPlanService.cs +++ b/IRaCIS.Core.Application/Service/Visit/VisitPlanService.cs @@ -566,6 +566,7 @@ namespace IRaCIS.Application.Services }); await _inspectionService.AddListInspectionRecordAsync(datas); await _repository.AddAsync(stat); + //await _subjectVisitRepository.AddRangeAsync() await _repository.AddRangeAsync(subjectVisits); await _repository.SaveChangesAsync(); return ResponseOutput.Ok(); diff --git a/IRaCIS.Core.Domain/Common/JsonConvert.cs b/IRaCIS.Core.Domain/Common/JsonConvert.cs index d6d77c826..81a9a6345 100644 --- a/IRaCIS.Core.Domain/Common/JsonConvert.cs +++ b/IRaCIS.Core.Domain/Common/JsonConvert.cs @@ -10,7 +10,7 @@ namespace IRaCIS.Core.Domain.Common public static class JJsonConvert { /// - /// 将对象序列化成Json字符串 + /// 将对象序列化成稽查需要的Json字符串 /// /// 需要序列化的对象 /// diff --git a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs index 339b8c31b..c4f700149 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs @@ -53,9 +53,9 @@ namespace IRaCIS.Core.Infra.EFCore Task CountAsync(Expression> whereLambda = null, bool ignoreQueryFilters = false); - ValueTask AddAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); + ValueTask AddAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default,bool isSaveAudit=false); - Task> AddRangeAsync(IEnumerable entities); + Task> AddRangeAsync(IEnumerable entities, bool isSaveAudit = false); //Task AddRangeAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default); // 不建议使用,使用跟踪,然后save 部分字段更新,此种方式是更新所有字段 diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 9154b68a7..00a798172 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -19,6 +19,7 @@ using Microsoft.Data.SqlClient; using Newtonsoft.Json; using IRaCIS.Core.Infra.EFCore.Dto; using Newtonsoft.Json.Linq; +using IRaCIS.Core.Domain.Common; namespace IRaCIS.Core.Infra.EFCore { @@ -42,28 +43,24 @@ namespace IRaCIS.Core.Infra.EFCore } - #region 异步 EF 跟踪 添加 - - - - public async Task> AddRangeAsync(IEnumerable entities) + public async Task> AddRangeAsync(IEnumerable entities,bool isSaveAudit=false) { foreach (var addEntity in entities) { - await AddAsync(addEntity); + await AddAsync(addEntity, isSaveAudit); } return entities; } /// EF跟踪方式 添加 - public async ValueTask AddAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) + public async ValueTask AddAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default,bool isSaveAudit=false) { await _dbSet.AddAsync(entity).ConfigureAwait(false); - await AddInspectionAsync(entity); + await AddInspectionAsync(entity, isSaveAudit); if (autoSave) { @@ -583,7 +580,7 @@ namespace IRaCIS.Core.Infra.EFCore } - private async Task AddInspectionAsync(TEntity entity) + private async Task AddInspectionAsync(TEntity entity,bool isSaveAudit=false) { List datas = new List(); @@ -602,7 +599,7 @@ namespace IRaCIS.Core.Infra.EFCore IsSign = false, CreateTime = createtime, Identification = "Init|Subject|Status|Subject", - JsonDetail = JsonConvert.SerializeObject(entity) + JsonDetail = entity.ToJcJson() }); } await AddListInspectionRecordAsync(datas);