bug修复
parent
872c16f11f
commit
a539eaa4b8
|
@ -59,11 +59,20 @@ namespace IRaCIS.Application.Services
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IResponseOutput> AddOrUpdateBasicDic(AddOrEditBasicDic addOrEditBasic)
|
public async Task<IResponseOutput> AddOrUpdateBasicDic(AddOrEditBasicDic addOrEditBasic)
|
||||||
{
|
{
|
||||||
|
if (addOrEditBasic.Id == null)
|
||||||
var entity = await _repository.InsertOrUpdateAsync<Dictionary, AddOrEditBasicDic>(addOrEditBasic, true);
|
{
|
||||||
|
var entity = await _dicRepository.InsertDictionaryAsync(addOrEditBasic);
|
||||||
return ResponseOutput.Ok(entity.Id.ToString());
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -91,17 +91,26 @@ namespace IRaCIS.Core.Application
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<PageOutput<TrialSiteSurveyStat>> GetSiteSurveyApprovalList(TrialSiteSurveyStatQuery query)
|
public async Task<PageOutput<TrialSiteSurveyStat>> GetSiteSurveyApprovalList(TrialSiteSurveyStatQuery query)
|
||||||
{
|
{
|
||||||
if (_userInfo.IsAdmin)
|
|
||||||
{
|
|
||||||
return new PageOutput<TrialSiteSurveyStat>(query.PageIndex, query.PageSize, 0, new List<TrialSiteSurveyStat>());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager ||
|
||||||
|
_userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM ||
|
||||||
|
_userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM ||
|
||||||
|
_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM)
|
||||||
|
{
|
||||||
return await _trialRepository
|
return await _trialRepository
|
||||||
.Where(t => t.TrialUserList.Any(t => t.UserId == _userInfo.Id))
|
.Where(t => t.TrialUserList.Any(t => t.UserId == _userInfo.Id))
|
||||||
.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM,c=> c.TrialSiteSurveyList.Where(t => t.State == TrialSiteSurveyEnum.SPMApproved).Count()>0)
|
.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM, c => c.TrialSiteSurveyList.Where(t => t.State == TrialSiteSurveyEnum.SPMApproved).Count() > 0)
|
||||||
.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM, c => c.TrialSiteSurveyList.Where(t => t.State == TrialSiteSurveyEnum.CRCSubmitted).Count() > 0)
|
.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM, c => c.TrialSiteSurveyList.Where(t => t.State == TrialSiteSurveyEnum.CRCSubmitted).Count() > 0)
|
||||||
.ProjectTo<TrialSiteSurveyStat>(_mapper.ConfigurationProvider, new { userTypeEnumInt = _userInfo.UserTypeEnumInt, userId = _userInfo.Id })
|
.ProjectTo<TrialSiteSurveyStat>(_mapper.ConfigurationProvider, new { userTypeEnumInt = _userInfo.UserTypeEnumInt, userId = _userInfo.Id })
|
||||||
.OrderByDescending(t=>t.ApprovalRequiredCount).ToPagedListAsync(query.PageIndex, query.PageSize, query.SortField, query.Asc);
|
.OrderByDescending(t => t.ApprovalRequiredCount).ToPagedListAsync(query.PageIndex, query.PageSize, query.SortField, query.Asc);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new PageOutput<TrialSiteSurveyStat>(query.PageIndex, query.PageSize, 0, new List<TrialSiteSurveyStat>());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +130,7 @@ namespace IRaCIS.Core.Application
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var trialDocStat = await _trialRepository
|
var trialDocStat = await _trialRepository
|
||||||
.WhereIf(_userInfo.UserTypeEnumInt != (int)UserTypeEnum.SuperAdmin, t => t.TrialUserList.Any(t => t.UserId == _userInfo.Id))
|
.Where(t => t.TrialUserList.Any(t => t.UserId == _userInfo.Id))
|
||||||
.WhereIf(!_userInfo.IsAdmin, c => c.TrialDocumentList.Where(t => t.NeedConfirmedUserTypeList.Any(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId) && !t.TrialDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id)).Count() > 0)
|
.WhereIf(!_userInfo.IsAdmin, c => c.TrialDocumentList.Where(t => t.NeedConfirmedUserTypeList.Any(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId) && !t.TrialDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id)).Count() > 0)
|
||||||
.ProjectTo<DocSignStat>(_mapper.ConfigurationProvider, new { userTypeEnumInt = _userInfo.UserTypeEnumInt, userId = _userInfo.Id, userTypeId = _userInfo.UserTypeId })
|
.ProjectTo<DocSignStat>(_mapper.ConfigurationProvider, new { userTypeEnumInt = _userInfo.UserTypeEnumInt, userId = _userInfo.Id, userTypeId = _userInfo.UserTypeId })
|
||||||
.OrderByDescending(t => t.WaitSignCount)
|
.OrderByDescending(t => t.WaitSignCount)
|
||||||
|
|
|
@ -56,7 +56,7 @@ namespace IRaCIS.Application.Services
|
||||||
[HttpGet("{trialId:guid}")]
|
[HttpGet("{trialId:guid}")]
|
||||||
public async Task<VisitPlanView> GetVisitStageList(Guid trialId)
|
public async Task<VisitPlanView> GetVisitStageList(Guid trialId)
|
||||||
{
|
{
|
||||||
var query = _visitStageRepository.Where(u => u.TrialId == trialId)
|
var query = _visitStageRepository.AsQueryable(true).Where(u => u.TrialId == trialId)
|
||||||
.ProjectTo<VisitStageDTO>(_mapper.ConfigurationProvider).OrderBy(t => t.VisitNum);
|
.ProjectTo<VisitStageDTO>(_mapper.ConfigurationProvider).OrderBy(t => t.VisitNum);
|
||||||
var list = await query.ToListAsync();
|
var list = await query.ToListAsync();
|
||||||
var trial = await _repository.FirstOrDefaultAsync<Trial>(t => t.Id == trialId).IfNullThrowException();
|
var trial = await _repository.FirstOrDefaultAsync<Trial>(t => t.Id == trialId).IfNullThrowException();
|
||||||
|
|
|
@ -7,7 +7,7 @@ using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace IRaCIS.Application.Services
|
namespace IRaCIS.Application.Services
|
||||||
{
|
{
|
||||||
[ ApiExplorerSettings(GroupName = "Institution")]
|
[ApiExplorerSettings(GroupName = "Institution")]
|
||||||
public class TestService : BaseService
|
public class TestService : BaseService
|
||||||
{
|
{
|
||||||
private readonly IRepository<Dictionary> _dicRepository;
|
private readonly IRepository<Dictionary> _dicRepository;
|
||||||
|
@ -21,13 +21,14 @@ namespace IRaCIS.Application.Services
|
||||||
public string Get(testModel testModel)
|
public string Get(testModel testModel)
|
||||||
{
|
{
|
||||||
|
|
||||||
var c = _dicRepository.Where(t=>t.ParentId!=null).Select(t=>t.MappedValue).First();
|
var d = _repository.Where<User>().Select(t => t.FullName).FirstOrDefault();
|
||||||
|
var c = _dicRepository.Where(t => t.ParentId != null).Select(t => t.MappedValue).First();
|
||||||
CultureInfo culture = CultureInfo.CurrentUICulture;
|
CultureInfo culture = CultureInfo.CurrentUICulture;
|
||||||
|
|
||||||
var a = 123;
|
var a = 123;
|
||||||
|
|
||||||
var b = _localizer["test{0}", "测试"];
|
var b = _localizer["test{0}", "测试"];
|
||||||
return _localizer["test{0}","测试"];
|
return _localizer["test{0}", "测试"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,6 @@ namespace IRaCIS.Core.Domain.Models
|
||||||
public string KeyName { get; set; } = string.Empty;
|
public string KeyName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
|
||||||
//イ簗ヤ
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public string MappedValue { get; set; }
|
public string MappedValue { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -68,8 +68,7 @@ namespace IRaCIS.Core.Domain.Models
|
||||||
|
|
||||||
public bool IsFirstAdd { get; set; } = true;
|
public bool IsFirstAdd { get; set; } = true;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public string FullName { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,16 +74,19 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
//modelBuilder.Entity<Dictionary>().Property(t => t.MappedValue).HasComputedColumnSql(_userInfo.IsEn_Us? "[Value]":"[ValueCN]");
|
//modelBuilder.Entity<Dictionary>().Property(t => t.MappedValue).HasComputedColumnSql(_userInfo.IsEn_Us? "[Value]":"[ValueCN]");
|
||||||
//modelBuilder.Entity<TrialSiteSurvey>()// .HasQueryFilter(t => t.IsDeleted == false);
|
//modelBuilder.Entity<TrialSiteSurvey>()// .HasQueryFilter(t => t.IsDeleted == false);
|
||||||
|
|
||||||
|
|
||||||
if (_userInfo.IsEn_Us)
|
if (_userInfo.IsEn_Us)
|
||||||
{
|
{
|
||||||
modelBuilder.Entity<Dictionary>().Property(t => t.MappedValue).HasColumnName( "Value" );
|
modelBuilder.Entity<Dictionary>().Property(t => t.MappedValue).HasColumnName("Value");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
modelBuilder.Entity<Dictionary>().Property(t => t.MappedValue).HasColumnName( "ValueCN");
|
modelBuilder.Entity<Dictionary>().Property(t => t.MappedValue).HasColumnName("ValueCN");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
modelBuilder.Entity<User>().Property(t => t.FullName) .HasComputedColumnSql("[LastName] + ' / ' + [FirstName]",false);
|
||||||
|
modelBuilder.Entity<User>().Ignore(t => t.FullName);
|
||||||
|
|
||||||
//遍历实体模型手动配置
|
//遍历实体模型手动配置
|
||||||
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)
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
{
|
{
|
||||||
public interface ICommandRepository<TEntity>: ICommandRepository<TEntity, Guid> where TEntity : Entity
|
public interface ICommandRepository<TEntity>: ICommandRepository<TEntity, Guid> where TEntity : Entity
|
||||||
{
|
{
|
||||||
|
Task<TEntity> InsertDictionaryAsync<TFrom>(TFrom from, params EntityVerifyExp<TEntity>[] verify);
|
||||||
Task<TEntity> InsertOrUpdateAsync<TFrom>(TFrom from, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify);
|
Task<TEntity> InsertOrUpdateAsync<TFrom>(TFrom from, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
@ -11,6 +14,8 @@ using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||||
using AutoMapper.QueryableExtensions;
|
using AutoMapper.QueryableExtensions;
|
||||||
using IRaCIS.Core.Infrastructure;
|
using IRaCIS.Core.Infrastructure;
|
||||||
using IRaCIS.Core.Infrastructure.Extention;
|
using IRaCIS.Core.Infrastructure.Extention;
|
||||||
|
using Microsoft.Data.SqlClient;
|
||||||
|
using Z.EntityFramework.Plus;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Infra.EFCore
|
namespace IRaCIS.Core.Infra.EFCore
|
||||||
{
|
{
|
||||||
|
@ -20,7 +25,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
public IMapper _mapper { get; set; }
|
public IMapper _mapper { get; set; }
|
||||||
public IRaCISDBContext _dbContext { get; set; }
|
public IRaCISDBContext _dbContext { get; set; }
|
||||||
|
|
||||||
private DbSet<TEntity> _dbSet => _dbContext.Set<TEntity>();
|
public DbSet<TEntity> _dbSet => _dbContext.Set<TEntity>();
|
||||||
|
|
||||||
|
|
||||||
public Repository(IRaCISDBContext dbContext, IMapper mapper)
|
public Repository(IRaCISDBContext dbContext, IMapper mapper)
|
||||||
|
@ -35,7 +40,64 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
|
|
||||||
#region 异步部分
|
#region 异步部分
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 仅仅供字典表插入使用,因为efcore 动态映射列的问题
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TFrom"></typeparam>
|
||||||
|
/// <param name="from"></param>
|
||||||
|
/// <param name="verify"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="BusinessValidationFailedException"></exception>
|
||||||
|
public async Task<TEntity> InsertDictionaryAsync<TFrom>(TFrom from, params EntityVerifyExp<TEntity>[] verify)
|
||||||
|
{
|
||||||
|
var entity = _mapper.Map<TEntity>(from);
|
||||||
|
|
||||||
|
foreach (var verifyItem in verify.Where(t => t.verifyType != VerifyEnum.OnlyUpdate && t.IsVerify))
|
||||||
|
{
|
||||||
|
if (await _dbSet.IgnoreQueryFilters().AnyAsync(verifyItem.VerifyExp).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
throw new BusinessValidationFailedException(verifyItem.VerifyMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof(TEntity) == typeof(Dictionary))
|
||||||
|
{
|
||||||
|
Type type = typeof(TFrom);
|
||||||
|
|
||||||
|
//以下是不要ID这个字段的 比如自增列ID 就不能像上名那样写
|
||||||
|
var properties = type.GetProperties().Where(t=>t.Name!="Id");
|
||||||
|
//.Where(t => !t.GetCustomAttributes().Any(c => c.GetType() == typeof(NotMappedAttribute)))
|
||||||
|
//.Where(t => !t.PropertyType.IsGenericType);
|
||||||
|
|
||||||
|
string[] strSqlNames = properties
|
||||||
|
.Select(p => $"[{p.Name}]").ToArray();
|
||||||
|
|
||||||
|
string strSqlName = string.Join(",", strSqlNames);
|
||||||
|
string[] strSqlValues = properties.Select(P => $"@{P.Name}").ToArray();
|
||||||
|
string strSqlValue = string.Join(",", strSqlValues);
|
||||||
|
|
||||||
|
// strSql得到的 sql语句为insert into testModel ( [ID],[Name],[QQ],[Email] ) values (@ID,@Name,@QQ,@Email)
|
||||||
|
string strSql = $"insert into {nameof(Dictionary)} ( " + strSqlName + " ) values (" + strSqlValue + ")";
|
||||||
|
|
||||||
|
//para Sql是参数
|
||||||
|
SqlParameter[] para = properties
|
||||||
|
.Select(p => new SqlParameter($"@{p.Name}", p.GetValue(from, null))).ToArray();
|
||||||
|
|
||||||
|
|
||||||
|
_dbContext.Database.ExecuteSqlRaw(strSql, para);
|
||||||
|
|
||||||
|
//测试还是有问题 NotMapped 会失效
|
||||||
|
//await quey.BulkInsertAsync(new List<Dictionary>() { entity as Dictionary });
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("仅仅供字典表插入使用,因为efcore 动态映射列的问题");
|
||||||
|
//await _dbSet.BulkInsertAsync(new List<TEntity>() { entity });
|
||||||
|
|
||||||
|
//return entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<TEntity> InsertOrUpdateAsync<TFrom>(TFrom from, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify)
|
public async Task<TEntity> InsertOrUpdateAsync<TFrom>(TFrom from, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify)
|
||||||
{
|
{
|
||||||
|
@ -290,7 +352,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQueryable<TEntity> AsQueryable( bool ignoreQueryFilters = false)
|
public IQueryable<TEntity> AsQueryable(bool ignoreQueryFilters = false)
|
||||||
{
|
{
|
||||||
var query = _dbSet.AsQueryable();
|
var query = _dbSet.AsQueryable();
|
||||||
|
|
||||||
|
@ -312,7 +374,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
return condition ? _dbSet.AsNoTracking().Where(filter) : _dbSet.AsNoTracking();
|
return condition ? _dbSet.AsNoTracking().Where(filter) : _dbSet.AsNoTracking();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> exp = null, bool isTraking = false,bool ignoreQueryFilters = false)
|
public IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> exp = null, bool isTraking = false, bool ignoreQueryFilters = false)
|
||||||
{
|
{
|
||||||
IQueryable<TEntity> query = _dbSet;
|
IQueryable<TEntity> query = _dbSet;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue