From 4cbb37e1b51b2ca86c420de43d8761ebb6069f1b Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Fri, 15 Apr 2022 09:35:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E5=85=B8bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Common/DTO/DictionaryModel.cs | 2 +- .../Service/Common/DictionaryService.cs | 36 ++++++++++--------- .../Context/IRaCISDBContext.cs | 12 +++---- .../EntityConfigration/DoctorConfigration.cs | 12 +++++++ 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs b/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs index 6f5bab8d..454bbddb 100644 --- a/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs +++ b/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs @@ -42,7 +42,7 @@ namespace IRaCIS.Application.Contracts //有父亲 就有值 - public Guid ParentId { get; set; } + public Guid? ParentId { get; set; } public bool IsEnable { get; set; } diff --git a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs index 7ca8b2ea..2b1eb8c7 100644 --- a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs +++ b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs @@ -59,26 +59,25 @@ namespace IRaCIS.Application.Services [HttpPost] public async Task AddOrUpdateBasicDic(AddOrEditBasicDic addOrEditBasic) { - if (addOrEditBasic.Id == null) - { - var entity = await _dicRepository.InsertDictionaryAsync(addOrEditBasic); + //if (addOrEditBasic.Id == null) + //{ + // var entity = await _dicRepository.InsertDictionaryAsync(addOrEditBasic); - await _dicRepository.UpdateFromQueryAsync(t => t.ParentId == Guid.Empty, - u => new Dictionary() { ParentId = null }); + // await _dicRepository.UpdateFromQueryAsync(t => t.ParentId == Guid.Empty, + // u => new Dictionary() { ParentId = null }); - return ResponseOutput.Ok(entity.Id.ToString()); - } - else - { - var entity = await _dicRepository.InsertOrUpdateAsync(addOrEditBasic, true); - await _dicRepository.UpdateFromQueryAsync(t => t.ParentId == Guid.Empty, - u => new Dictionary() { ParentId = null }); + // return ResponseOutput.Ok(entity.Id.ToString()); + //} + //else + //{ + // var entity = await _dicRepository.InsertOrUpdateAsync(addOrEditBasic, true); - return ResponseOutput.Ok(entity.Id.ToString()); - } - //var entity = await _dicRepository.InsertOrUpdateAsync(addOrEditBasic, true); - //return ResponseOutput.Ok(entity.Id.ToString()); + // return ResponseOutput.Ok(entity.Id.ToString()); + //} + var entity = await _dicRepository.InsertOrUpdateAsync(addOrEditBasic, true); + + return ResponseOutput.Ok(entity.Id.ToString()); } @@ -100,6 +99,11 @@ namespace IRaCIS.Application.Services [HttpDelete("{id:guid}")] public async Task DeleteDictionary(Guid id) { + if ( await _dicRepository.AnyAsync(t => t.ParentId == id)) + { + return ResponseOutput.NotOk("有子项数据,不允许直接删除!"); + } + if ((await _doctorDictionaryRepository.AnyAsync(t => t.DictionaryId == id)) || (await _doctorRepository.AnyAsync(t => t.SpecialityId == id || t.PositionId == id || t.DepartmentId == id || t.RankId == id)) diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index bd3f7270..75eba7b8 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -10,6 +10,7 @@ using Microsoft.EntityFrameworkCore.ChangeTracking; using System.Reflection; using IRaCIS.Core.Domain.Share; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; using UserTypeGroup = IRaCIS.Core.Domain.Models.UserTypeGroup; namespace IRaCIS.Core.Infra.EFCore @@ -68,11 +69,7 @@ namespace IRaCIS.Core.Infra.EFCore protected override void OnModelCreating(ModelBuilder modelBuilder) { - //modelBuilder.Entity().HasMany(s => s.TrialSiteUserSurveyList).WithOne(sv => sv.TrialSiteSurvey); - //modelBuilder.Entity().HasMany(s => s.TrialSiteEquipmentSurveyList).WithOne(sv => sv.TrialSiteSurvey); - //modelBuilder.Entity().Ignore(t => t.MappedValue); - //modelBuilder.Entity().Property(t => t.MappedValue).HasComputedColumnSql(_userInfo.IsEn_Us? "[Value]":"[ValueCN]"); - //modelBuilder.Entity()// .HasQueryFilter(t => t.IsDeleted == false); + if (_userInfo.IsEn_Us) { @@ -84,8 +81,9 @@ namespace IRaCIS.Core.Infra.EFCore } - modelBuilder.Entity().Property(t => t.FullName) .HasComputedColumnSql("[LastName] + ' / ' + [FirstName]",false); - modelBuilder.Entity().Ignore(t => t.FullName); + + //modelBuilder.Entity().Property(t => t.FullName) .HasComputedColumnSql("[LastName] + ' / ' + [FirstName]",false); + //modelBuilder.Entity().Ignore(t => t.FullName); //遍历实体模型手动配置 diff --git a/IRaCIS.Core.Infra.EFCore/EntityConfigration/DoctorConfigration.cs b/IRaCIS.Core.Infra.EFCore/EntityConfigration/DoctorConfigration.cs index 06fb8b96..ddef1e98 100644 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/DoctorConfigration.cs +++ b/IRaCIS.Core.Infra.EFCore/EntityConfigration/DoctorConfigration.cs @@ -1,5 +1,6 @@ using IRaCIS.Core.Domain.Models; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Builders; @@ -22,4 +23,15 @@ namespace IRaCIS.Core.Infra.EFCore.EntityConfigration .HasForeignKey(dd => dd.DictionaryId); } } + + public class DictionaryConfigration : IEntityTypeConfiguration + { + + + public void Configure(EntityTypeBuilder builder) + { + builder.Property(e => e.MappedValue).Metadata.SetBeforeSaveBehavior(PropertySaveBehavior.Ignore); + + } + } }