bug修复

Uat_Study
hang 2022-04-14 13:57:35 +08:00
parent 872c16f11f
commit a539eaa4b8
9 changed files with 113 additions and 31 deletions

View File

@ -59,10 +59,19 @@ namespace IRaCIS.Application.Services
[HttpPost]
public async Task<IResponseOutput> AddOrUpdateBasicDic(AddOrEditBasicDic addOrEditBasic)
{
if (addOrEditBasic.Id == null)
{
var entity = await _dicRepository.InsertDictionaryAsync(addOrEditBasic);
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);
var entity = await _repository.InsertOrUpdateAsync<Dictionary, AddOrEditBasicDic>(addOrEditBasic, true);
return ResponseOutput.Ok(entity.Id.ToString());
//return ResponseOutput.Ok(entity.Id.ToString());
}

View File

@ -91,17 +91,26 @@ namespace IRaCIS.Core.Application
[HttpPost]
public async Task<PageOutput<TrialSiteSurveyStat>> GetSiteSurveyApprovalList(TrialSiteSurveyStatQuery query)
{
if (_userInfo.IsAdmin)
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager ||
_userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM ||
_userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM ||
_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM)
{
return new PageOutput<TrialSiteSurveyStat>(query.PageIndex, query.PageSize, 0, new List<TrialSiteSurveyStat>());
return await _trialRepository
.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.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 })
.OrderByDescending(t => t.ApprovalRequiredCount).ToPagedListAsync(query.PageIndex, query.PageSize, query.SortField, query.Asc);
}
return await _trialRepository
.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.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 })
.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
{
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)
.ProjectTo<DocSignStat>(_mapper.ConfigurationProvider, new { userTypeEnumInt = _userInfo.UserTypeEnumInt, userId = _userInfo.Id, userTypeId = _userInfo.UserTypeId })
.OrderByDescending(t => t.WaitSignCount)

View File

@ -56,7 +56,7 @@ namespace IRaCIS.Application.Services
[HttpGet("{trialId:guid}")]
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);
var list = await query.ToListAsync();
var trial = await _repository.FirstOrDefaultAsync<Trial>(t => t.Id == trialId).IfNullThrowException();

View File

@ -7,12 +7,12 @@ using System.ComponentModel.DataAnnotations;
namespace IRaCIS.Application.Services
{
[ ApiExplorerSettings(GroupName = "Institution")]
[ApiExplorerSettings(GroupName = "Institution")]
public class TestService : BaseService
{
private readonly IRepository<Dictionary> _dicRepository;
public TestService(IRepository<Dictionary> dicRepository)
public TestService(IRepository<Dictionary> dicRepository)
{
_dicRepository = dicRepository;
}
@ -21,13 +21,14 @@ namespace IRaCIS.Application.Services
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;
var a = 123;
var b = _localizer["test{0}", "测试"];
return _localizer["test{0}","测试"];
return _localizer["test{0}", "测试"];
}
}

View File

@ -58,8 +58,7 @@ namespace IRaCIS.Core.Domain.Models
public string KeyName { get; set; } = string.Empty;
//²âÊÔ
[NotMapped]
[NotMapped]
public string MappedValue { get; set; }

View File

@ -68,8 +68,7 @@ namespace IRaCIS.Core.Domain.Models
public bool IsFirstAdd { get; set; } = true;
[NotMapped]
public string FullName { get; set; }
}
}

View File

@ -74,16 +74,19 @@ namespace IRaCIS.Core.Infra.EFCore
//modelBuilder.Entity<Dictionary>().Property(t => t.MappedValue).HasComputedColumnSql(_userInfo.IsEn_Us? "[Value]":"[ValueCN]");
//modelBuilder.Entity<TrialSiteSurvey>()// .HasQueryFilter(t => t.IsDeleted == false);
if (_userInfo.IsEn_Us)
{
modelBuilder.Entity<Dictionary>().Property(t => t.MappedValue).HasColumnName( "Value" );
modelBuilder.Entity<Dictionary>().Property(t => t.MappedValue).HasColumnName("Value");
}
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);
foreach (var type in typesToRegister)

View File

@ -11,7 +11,7 @@ namespace IRaCIS.Core.Infra.EFCore
{
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);
}

View File

@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using AutoMapper;
@ -11,6 +14,8 @@ using Microsoft.EntityFrameworkCore.ChangeTracking;
using AutoMapper.QueryableExtensions;
using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Infrastructure.Extention;
using Microsoft.Data.SqlClient;
using Z.EntityFramework.Plus;
namespace IRaCIS.Core.Infra.EFCore
{
@ -20,7 +25,7 @@ namespace IRaCIS.Core.Infra.EFCore
public IMapper _mapper { 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)
@ -35,7 +40,64 @@ namespace IRaCIS.Core.Infra.EFCore
#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)
{
@ -127,7 +189,7 @@ namespace IRaCIS.Core.Infra.EFCore
{
query = query.IgnoreQueryFilters();
}
if (exp == null)
if (exp == null)
return await query.FirstOrDefaultAsync().ConfigureAwait(false);
return await query.FirstOrDefaultAsync(exp).ConfigureAwait(false);
}
@ -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();
@ -312,7 +374,7 @@ namespace IRaCIS.Core.Infra.EFCore
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;