删掉记录审计信息

Uat_Study
hang 2022-04-21 13:48:22 +08:00
parent 674f69cb69
commit b0fa708271
6 changed files with 31 additions and 30 deletions

View File

@ -24,7 +24,7 @@ namespace IRaCIS.Core.API
options.UseProjectables(); options.UseProjectables();
options.AddInterceptors(new AuditingInterceptor(configuration.GetSection("ConnectionStrings:RemoteNew").Value)); //options.AddInterceptors(new AuditingInterceptor(configuration.GetSection("ConnectionStrings:RemoteNew").Value));
}); });
} }

View File

@ -10,6 +10,7 @@ using IRaCIS.Core.Infra.EFCore;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Application.Contracts;
using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Domain.Share;
using MassTransit;
using Panda.DynamicWebApi.Attributes; using Panda.DynamicWebApi.Attributes;
namespace IRaCIS.Core.Application.Services namespace IRaCIS.Core.Application.Services
@ -406,6 +407,7 @@ namespace IRaCIS.Core.Application.Services
return ResponseOutput.NotOk("同类型已存在该文件名"); return ResponseOutput.NotOk("同类型已存在该文件名");
} }
//entity.Id = NewId.NextGuid();
await _repository.AddAsync(entity, true); await _repository.AddAsync(entity, true);
return ResponseOutput.Ok(entity.Id.ToString()); return ResponseOutput.Ok(entity.Id.ToString());
} }

View File

@ -152,7 +152,7 @@ namespace IRaCIS.Application.Services
//var test = _trialRepository.Where(t => t.CreateTime.Year == DateTime.Now.Year + 1).Select(t => t.Code).DefaultIfEmpty(1).ToList(); //var test = _trialRepository.Where(t => t.CreateTime.Year == DateTime.Now.Year + 1).Select(t => t.Code).DefaultIfEmpty(1).ToList();
var trial = _mapper.Map<Trial>(trialAddModel); var trial = _mapper.Map<Trial>(trialAddModel);
trial.Id = NewId.NextGuid(); //trial.Id = NewId.NextGuid();
var yearStr = DateTime.Now.Year.ToString(); var yearStr = DateTime.Now.Year.ToString();
trial.Code = currentYearMaxCodeNext; trial.Code = currentYearMaxCodeNext;

View File

@ -155,7 +155,7 @@ namespace IRaCIS.Application.Services
svItem.SiteId = subject.SiteId; svItem.SiteId = subject.SiteId;
svItem.SubjectId = subject.SubjectId; svItem.SubjectId = subject.SubjectId;
svItem.Id = Guid.NewGuid(); svItem.Id = NewId.NextGuid();
//设置了末次访视,那么加访视计划的时候,设置为不可用 //设置了末次访视,那么加访视计划的时候,设置为不可用
if (subjectSVS.Any(t => t.SubjectId == svItem.SubjectId && t.IsFinalVisit)) if (subjectSVS.Any(t => t.SubjectId == svItem.SubjectId && t.IsFinalVisit))
@ -174,9 +174,10 @@ namespace IRaCIS.Application.Services
visitPlanItem.BlindName = "B" + ((int)visitPlanItem.VisitNum * 10).ToString("D3"); visitPlanItem.BlindName = "B" + ((int)visitPlanItem.VisitNum * 10).ToString("D3");
//var result = await _visitStageRepository.AddAsync(visitPlanItem);
var result = await _repository.AddAsync(visitPlanItem); var result = await _repository.AddAsync(visitPlanItem);
visitPlan.Id = result.Id;
//更新项目访视计划状态为未确认 //更新项目访视计划状态为未确认
await _trialRepository.BatchUpdateAsync(u => u.Id == visitPlan.TrialId, t => new Trial() { VisitPlanConfirmed = false }); await _trialRepository.BatchUpdateAsync(u => u.Id == visitPlan.TrialId, t => new Trial() { VisitPlanConfirmed = false });

View File

@ -1,32 +1,20 @@
using System; using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using MassTransit;
namespace IRaCIS.Core.Domain.Models namespace IRaCIS.Core.Domain.Models
{ {
public abstract class Entity : IEntity<Guid> public abstract class Entity : IEntity<Guid>
{ {
[Key] [Key]
[Required] [Required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] [DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get ; set ; } public Guid Id { get; set; }
} }
public interface IEntity<TKey> public interface IEntity<TKey>
{ {
/// <summary>
/// 编号
/// </summary>
abstract TKey Id { get; set; } abstract TKey Id { get; set; }
} }
//public class Entity<TKey> : IEntity
//{
//}
} }

View File

@ -13,6 +13,7 @@ using IRaCIS.Core.Domain.Share;
using MassTransit; using MassTransit;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.ValueGeneration;
using UserTypeGroup = IRaCIS.Core.Domain.Models.UserTypeGroup; using UserTypeGroup = IRaCIS.Core.Domain.Models.UserTypeGroup;
namespace IRaCIS.Core.Infra.EFCore namespace IRaCIS.Core.Infra.EFCore
@ -67,7 +68,10 @@ namespace IRaCIS.Core.Infra.EFCore
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
//modelBuilder.Entity<User>().Property(t => t.FullName) .HasDefaultValueSql("[LastName] + ' / ' + [FirstName]");
//code first must migration dbfirst must config in db
modelBuilder.Entity<StudyMonitor>().Property(e => e.TotalMillisecondsInterval).HasComputedColumnSql("datediff(MS,UploadStartTime,UploadFinishedTime)");
if (_userInfo.IsEn_Us) if (_userInfo.IsEn_Us)
{ {
@ -79,9 +83,6 @@ namespace IRaCIS.Core.Infra.EFCore
} }
//modelBuilder.Entity<User>().Property(t => t.FullName) .HasDefaultValueSql("[LastName] + ' / ' + [FirstName]");
//遍历实体模型手动配置 //遍历实体模型手动配置
var typesToRegister = Assembly.GetExecutingAssembly().GetTypes().Where(q => q.GetInterface(typeof(IEntityTypeConfiguration<>).FullName) != null); var typesToRegister = Assembly.GetExecutingAssembly().GetTypes().Where(q => q.GetInterface(typeof(IEntityTypeConfiguration<>).FullName) != null);
foreach (var type in typesToRegister) foreach (var type in typesToRegister)
@ -92,17 +93,19 @@ namespace IRaCIS.Core.Infra.EFCore
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
//code first must migration dbfirst must config in db
modelBuilder.Entity<StudyMonitor>().Property(e => e.TotalMillisecondsInterval).HasComputedColumnSql("datediff(MS,UploadStartTime,UploadFinishedTime)");
// 软删除配置
foreach (var entityType in modelBuilder.Model.GetEntityTypes()) foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{ {
// 软删除配置
if (typeof(ISoftDelete).IsAssignableFrom(entityType.ClrType)) if (typeof(ISoftDelete).IsAssignableFrom(entityType.ClrType))
{ {
entityType.AddSoftDeleteQueryFilter(); entityType.AddSoftDeleteQueryFilter();
} }
if (typeof(Entity).IsAssignableFrom(entityType.ClrType))
{
modelBuilder.Entity(entityType.ClrType).Property<Guid>("Id").HasValueGenerator<MySequentialGuidValueGenerator>();
}
} }
} }
@ -310,8 +313,6 @@ namespace IRaCIS.Core.Infra.EFCore
public virtual DbSet<CommonDocument> CommonDocument { get; set; } public virtual DbSet<CommonDocument> CommonDocument { get; set; }
public override int SaveChanges() public override int SaveChanges()
{ {
UpdateAuditInfo(); UpdateAuditInfo();
@ -361,7 +362,7 @@ namespace IRaCIS.Core.Infra.EFCore
//添加的时候,更新审计字段也赋值 //添加的时候,更新审计字段也赋值
case EntityState.Added: case EntityState.Added:
//// 仓储添加时 就有id了 ////// 仓储添加时 就有id了
//if (t.Entity is Entity entity && entity.Id == Guid.Empty) //if (t.Entity is Entity entity && entity.Id == Guid.Empty)
//{ //{
// entity.Id = NewId.NextGuid(); // entity.Id = NewId.NextGuid();
@ -453,4 +454,13 @@ namespace IRaCIS.Core.Infra.EFCore
#endregion #endregion
} }
public class MySequentialGuidValueGenerator : ValueGenerator<Guid>
{
public override Guid Next(EntityEntry entry)
{
return NewId.NextGuid();
}
public override bool GeneratesTemporaryValues => false;
}
} }