test
This commit is contained in:
@@ -0,0 +1,206 @@
|
||||
using IRaCIS.Application.Contracts;
|
||||
using IRaCIS.Core.Application.Contracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IRaCIS.Core.Application.Service.Inspection.DTO
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
public class DataInspectionAddDTO
|
||||
{
|
||||
|
||||
public Guid? TrialId { get; set; }
|
||||
public Guid? SiteId { get; set; }
|
||||
public Guid? SubjectId { get; set; }
|
||||
public Guid? SubjectVisitId { get; set; }
|
||||
public string ModuleType { get; set; } = string.Empty;
|
||||
public string OptType { get; set; } = string.Empty;
|
||||
|
||||
|
||||
|
||||
public string BlindName { get; set; } = string.Empty;
|
||||
public string Reason { get; set; } = string.Empty;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 子类
|
||||
/// </summary>
|
||||
public int ChildrenType { get; set; }
|
||||
public bool IsSign { get; set; }
|
||||
public string JsonDetail { get; set; } = string.Empty;
|
||||
|
||||
|
||||
|
||||
|
||||
////需要单独处理
|
||||
//public string IP { get; set; }
|
||||
|
||||
//public Guid? SignId { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
public interface IInspectionDTO
|
||||
{
|
||||
public DataInspectionAddDTO AuditInfo { get; set; }
|
||||
}
|
||||
|
||||
public interface ISignDTO
|
||||
{
|
||||
public SignDTO SignInfo { get; set; }
|
||||
|
||||
}
|
||||
|
||||
#region Setting
|
||||
/// <summary>
|
||||
/// 配置 基础逻辑信息
|
||||
/// </summary>
|
||||
public class InsBasicTrialConfig : InspectionBase, IInspectionDTO, ISignDTO
|
||||
{
|
||||
public BasicTrialConfig OptCommand { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置流程
|
||||
/// </summary>
|
||||
public class InsTrialProcessConfig : InspectionBase, IInspectionDTO, ISignDTO
|
||||
{
|
||||
public TrialProcessConfig OptCommand { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置加急信息
|
||||
/// </summary>
|
||||
public class InsTrialUrgentConfig : InspectionBase, IInspectionDTO, ISignDTO
|
||||
{
|
||||
public TrialUrgentConfig OptCommand { get; set; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 受试者
|
||||
public class InsSubjectCommand : InspectionBase, IInspectionDTO, ISignDTO
|
||||
{
|
||||
public SubjectCommand OptCommand { get; set; }
|
||||
}
|
||||
|
||||
public class InsUpdateSubjectStatus : InspectionBase, IInspectionDTO, ISignDTO
|
||||
{
|
||||
public SubjectStatusChangeCommand OptCommand { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class InsDeleteSubjectDto : InspectionBase, IInspectionDTO, ISignDTO
|
||||
{
|
||||
public DeleteSubjectDto OptCommand { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class DeleteSubjectDto
|
||||
{
|
||||
public Guid SubjectId { get; set; }
|
||||
|
||||
public Guid TrialId { get; set; }
|
||||
|
||||
public Guid SiteId { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 用户 签名某个文档 Dto
|
||||
/// </summary>
|
||||
public class TrialDocumentConfirmDTO : InspectionBase, IInspectionDTO, ISignDTO
|
||||
{
|
||||
|
||||
public UserConfirmCommand OptCommand { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class GetDataInspectionOutDto : DataInspection
|
||||
{
|
||||
public string ExperimentName { get; set; } = string.Empty;
|
||||
|
||||
public string SiteName { get; set; } = string.Empty;
|
||||
|
||||
public string FirstName { get; set; } = string.Empty;
|
||||
|
||||
public string LastName { get; set; } = string.Empty;
|
||||
|
||||
public string VisitName { get; set; } = string.Empty;
|
||||
|
||||
public string ParentJson { get; set; } = string.Empty;
|
||||
|
||||
public string CreateUser { get; set; } = string.Empty;
|
||||
public string UserFirstName { get; set; } = string.Empty;
|
||||
public string UserLastName { get; set; } = string.Empty;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class GetDataInspectionDto : PageInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 功能模块
|
||||
/// </summary>
|
||||
public string ModuleType { get; set; } = string.Empty;
|
||||
/// <summary>
|
||||
/// 盲态访视名
|
||||
/// </summary>
|
||||
public string BlindName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 项目iD
|
||||
/// </summary>
|
||||
public Guid? TrialId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 中心
|
||||
/// </summary>
|
||||
public Guid? SiteId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 受试者
|
||||
/// </summary>
|
||||
public Guid? SubjectId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 访视
|
||||
/// </summary>
|
||||
public Guid? SubjectVisitId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 操作类型
|
||||
/// </summary>
|
||||
public string OptType { get; set; } = string.Empty;
|
||||
/// <summary>
|
||||
/// 子类
|
||||
/// </summary>
|
||||
public int? ChildrenType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改原因
|
||||
/// </summary>
|
||||
|
||||
public string Reason { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 是否有签名
|
||||
/// </summary>
|
||||
public bool? IsSign { get; set; }
|
||||
}
|
||||
|
||||
public class InspectionBase
|
||||
{
|
||||
public DataInspectionAddDTO AuditInfo { get; set; }
|
||||
|
||||
public SignDTO SignInfo { get; set; } = new SignDTO();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
using Castle.Core.Internal;
|
||||
using IRaCIS.Core.Application.Contracts;
|
||||
using IRaCIS.Core.Application.Service.Inspection.DTO;
|
||||
using IRaCIS.Core.Application.Service.Inspection.Interface;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using Panda.DynamicWebApi.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IRaCIS.Core.Application.Service.Inspection
|
||||
{
|
||||
[NonDynamicWebApi]
|
||||
public class InspectionService : BaseService, IInspectionService
|
||||
{
|
||||
public InspectionService()
|
||||
{
|
||||
|
||||
}
|
||||
public async Task<PageOutput<GetDataInspectionOutDto>> GetInspectionData(GetDataInspectionDto dto)
|
||||
{
|
||||
//_repository.GetQueryable.GetQueryable < DataInspection >
|
||||
|
||||
#region 逻辑代码
|
||||
var query = from data in _repository.GetQueryable<DataInspection>()
|
||||
join trial in _repository.GetQueryable<Trial>() on data.TrialId equals trial.Id into trialtemp
|
||||
from leftrial in trialtemp.DefaultIfEmpty()
|
||||
join site in _repository.GetQueryable<Site>() on data.SiteId equals site.Id into sitetemp
|
||||
from leftsite in sitetemp.DefaultIfEmpty()
|
||||
join subject in _repository.GetQueryable<Subject>() on data.SubjectId equals subject.Id into subtemp
|
||||
from leftsubject in subtemp.DefaultIfEmpty()
|
||||
join subjectVisit in _repository.GetQueryable<SubjectVisit>() on data.SubjectVisitId equals subjectVisit.Id into subjectVisittemp
|
||||
from leftsubjectVisit in subjectVisittemp.DefaultIfEmpty()
|
||||
join parent in _repository.GetQueryable<DataInspection>() on data.ParentId equals parent.Id into parenttemp
|
||||
from leftparent in parenttemp.DefaultIfEmpty()
|
||||
join user in _repository.GetQueryable<User>() on data.CreateUserId equals user.Id into usertemp
|
||||
from leftuser in usertemp.DefaultIfEmpty()
|
||||
|
||||
select new GetDataInspectionOutDto()
|
||||
{
|
||||
CreateTime = data.CreateTime,
|
||||
CreateUserId = data.CreateUserId,
|
||||
ModuleType = data.ModuleType,
|
||||
BlindName = data.BlindName,
|
||||
TrialId = data.TrialId,
|
||||
SiteId = data.SiteId,
|
||||
SubjectId = data.SubjectId,
|
||||
SubjectVisitId = data.SubjectVisitId,
|
||||
OptType = data.OptType,
|
||||
IP = data.IP,
|
||||
Reason = data.Reason,
|
||||
IsSign = data.IsSign,
|
||||
SignId = data.SignId,
|
||||
ParentId = data.ParentId,
|
||||
ChildrenType = data.ChildrenType,
|
||||
JsonDetail = data.JsonDetail,
|
||||
SiteName = leftsite.SiteName,
|
||||
ExperimentName = leftrial.ExperimentName,
|
||||
FirstName = leftsubject.FirstName,
|
||||
LastName = leftsubject.LastName,
|
||||
Id = data.Id,
|
||||
ParentJson = leftparent.JsonDetail,
|
||||
VisitName = leftsubjectVisit.VisitName,
|
||||
CreateUser = leftuser.UserName,
|
||||
UserFirstName = leftuser.FirstName,
|
||||
UserLastName = leftuser.LastName,
|
||||
};
|
||||
|
||||
query = query.WhereIf(!dto.BlindName.IsNullOrEmpty(), x => x.BlindName == dto.BlindName)
|
||||
.WhereIf(dto.IsSign != null, x => x.IsSign == dto.IsSign)
|
||||
.WhereIf(dto.ChildrenType != null, x => x.ChildrenType == dto.ChildrenType)
|
||||
.WhereIf(!dto.ModuleType.IsNullOrEmpty(), x => x.ModuleType == dto.ModuleType)
|
||||
.WhereIf(!dto.OptType.IsNullOrEmpty(), x => x.OptType == dto.OptType)
|
||||
.WhereIf(!dto.Reason.IsNullOrEmpty(), x => x.Reason == dto.Reason)
|
||||
.WhereIf(dto.TrialId != null, x => x.TrialId == dto.TrialId)
|
||||
.WhereIf(dto.SubjectId != null, x => x.SubjectId == dto.SubjectId)
|
||||
.WhereIf(dto.SubjectVisitId != null, x => x.SubjectVisitId == dto.SubjectVisitId)
|
||||
.WhereIf(dto.SiteId != null, x => x.SiteId == dto.SiteId);
|
||||
#endregion
|
||||
|
||||
#region 测试
|
||||
//var query = from data in _repository.GetQueryable<DataInspection>()
|
||||
|
||||
// join parent in _repository.GetQueryable<DataInspection>() on data.ParentId equals parent.Id into parenttemp
|
||||
// from leftparent in parenttemp.DefaultIfEmpty()
|
||||
// join subjectVisit in _repository.GetQueryable<SubjectVisit>() on data.SubjectVisitId equals subjectVisit.Id into subjectVisittemp
|
||||
|
||||
// from leftsubjectVisit in subjectVisittemp.DefaultIfEmpty()
|
||||
// select new GetDataInspectionOutDto()
|
||||
// {
|
||||
// CreateTime = data.CreateTime,
|
||||
// CreateUserId = data.CreateUserId,
|
||||
// ModuleType = data.ModuleType,
|
||||
// BlindName = data.BlindName,
|
||||
// TrialId = data.TrialId,
|
||||
// SiteId = data.SiteId,
|
||||
// SubjectId = data.SubjectId,
|
||||
// SubjectVisitId = data.SubjectVisitId,
|
||||
// OptType = data.OptType,
|
||||
// IP = data.IP,
|
||||
// Reason = data.Reason,
|
||||
// IsSign = data.IsSign,
|
||||
// SignId = data.SignId,
|
||||
// ParentId = data.ParentId,
|
||||
// ChildrenType = data.ChildrenType,
|
||||
// JsonDetail = data.JsonDetail,
|
||||
// VisitName = leftsubjectVisit.VisitName,
|
||||
// Id = data.Id,
|
||||
// ParentJson = leftparent.JsonDetail,
|
||||
|
||||
// };
|
||||
#endregion
|
||||
|
||||
|
||||
dto.Asc = false;
|
||||
return await query.ToPagedListAsync(dto.PageIndex, dto.PageSize, "CreateTime", dto.Asc);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 通用逻辑封装
|
||||
/// </summary>
|
||||
/// <param name="OptCommand">方法参数</param>
|
||||
/// <param name="AuditInfo">添加稽查</param>
|
||||
/// <param name="SignInfo">用户签名</param>
|
||||
/// <param name="fun">委托</param>
|
||||
/// <returns></returns>
|
||||
public async Task<dynamic> Enforcement(dynamic OptCommand, DataInspectionAddDTO AuditInfo, SignDTO SignInfo, dynamic fun, IResponseOutput response=null)
|
||||
{
|
||||
Guid? signId = null;
|
||||
MapData(OptCommand, AuditInfo);
|
||||
if (AuditInfo.IsSign)
|
||||
{
|
||||
// 验证用户签名信息
|
||||
var verifyResult = await VerifySignatureAsync(SignInfo);
|
||||
signId = await AddSignRecordAsync(SignInfo);
|
||||
if (verifyResult.IsSuccess == false)
|
||||
{
|
||||
return verifyResult;
|
||||
}
|
||||
await AddSignRecordAsync(SignInfo);
|
||||
}
|
||||
|
||||
IResponseOutput bResult;
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
bResult = response;
|
||||
}
|
||||
else
|
||||
{
|
||||
bResult = await fun(OptCommand);
|
||||
}
|
||||
|
||||
// 用户 签名某个文档
|
||||
|
||||
|
||||
if (bResult.IsSuccess == false)
|
||||
{
|
||||
return bResult;
|
||||
}
|
||||
|
||||
// 判断是否需要前面
|
||||
|
||||
await AddInspectionRecordAsync(AuditInfo, signId);
|
||||
|
||||
if (bResult.IsSuccess == false)
|
||||
{
|
||||
return bResult;
|
||||
}
|
||||
return bResult;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 映射 SiteId SubjectId SubjectVisitId TrialId 最开始没有 需要特殊处理
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="mapData"></param>
|
||||
public void MapData(dynamic data, dynamic mapData)
|
||||
{
|
||||
List<string> column = new List<string>() { "TrialId", "SiteId", "SubjectId", "SubjectVisitId" };
|
||||
foreach (var item in column)
|
||||
{
|
||||
try
|
||||
{
|
||||
var value = data.GetType().GetProperty(item).GetValue(data);
|
||||
mapData.GetType().GetProperty(item).SetValue(mapData, value);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> 验证用户签名信息 </summary> ///
|
||||
public async Task<IResponseOutput> VerifySignatureAsync(SignDTO signDTO)
|
||||
{
|
||||
var user = await _repository.FirstOrDefaultAsync<User>(u => u.UserName == signDTO.UserName && u.Password == signDTO.PassWord);
|
||||
if (user == null)
|
||||
{
|
||||
return ResponseOutput.NotOk("password error");
|
||||
}
|
||||
else if (user.Status == UserStateEnum.Disable)
|
||||
{
|
||||
return ResponseOutput.NotOk("The user has been disabled!");
|
||||
}
|
||||
return ResponseOutput.Ok();
|
||||
|
||||
}
|
||||
|
||||
/// <summary> 添加签名记录 </summary> ///
|
||||
public async Task<Guid> AddSignRecordAsync(SignDTO signDTO)
|
||||
{
|
||||
var add = await _repository.AddAsync(_mapper.Map<TrialSign>(signDTO));
|
||||
|
||||
var success = await _repository.SaveChangesAsync();
|
||||
|
||||
return add.Id;
|
||||
|
||||
}
|
||||
|
||||
/// <summary> 添加稽查记录( 有的会签名,有的不会签名) </summary> ///
|
||||
public async Task<IResponseOutput> AddInspectionRecordAsync(DataInspectionAddDTO addDto, Guid? signId)
|
||||
{
|
||||
var add = _mapper.Map<DataInspection>(addDto);
|
||||
Guid? parentId = null;
|
||||
parentId = (await _repository.GetQueryable<DataInspection>().Where(x => x.TrialId == add.TrialId && x.SubjectVisitId == add.SubjectVisitId && x.SubjectId == add.SubjectId && x.SiteId == x.SiteId).OrderByDescending(x => x.CreateTime).FirstOrDefaultAsync())?.Id;
|
||||
add.ParentId = parentId;
|
||||
add.CreateTime = DateTime.Now;
|
||||
add.CreateUserId = _userInfo.Id;
|
||||
add.SignId = signId;
|
||||
add.IP = _userInfo.IP;
|
||||
await _repository.AddAsync(add);
|
||||
var success = await _repository.SaveChangesAsync();
|
||||
return ResponseOutput.Ok(success);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using IRaCIS.Core.Application.Contracts;
|
||||
using IRaCIS.Core.Application.Service.Inspection.DTO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IRaCIS.Core.Application.Service.Inspection.Interface
|
||||
{
|
||||
public interface IInspectionService
|
||||
{
|
||||
|
||||
Task<PageOutput<GetDataInspectionOutDto>> GetInspectionData(GetDataInspectionDto dto);
|
||||
|
||||
void MapData(dynamic data, dynamic mapData);
|
||||
|
||||
Task<IResponseOutput> VerifySignatureAsync(SignDTO signDTO);
|
||||
|
||||
Task<Guid> AddSignRecordAsync(SignDTO signDTO);
|
||||
|
||||
Task<dynamic> Enforcement(dynamic OptCommand, DataInspectionAddDTO AuditInfo, SignDTO SignInfo, dynamic fun, IResponseOutput response = null);
|
||||
|
||||
Task<IResponseOutput> AddInspectionRecordAsync(DataInspectionAddDTO addDto, Guid? signId);
|
||||
}
|
||||
}
|
||||
@@ -1,75 +1,27 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using IRaCIS.Application.Contracts;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace IRaCIS.Core.Application.Contracts;
|
||||
|
||||
public class SignDTO
|
||||
{
|
||||
public string UserName { get; set; } = String.Empty;
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
|
||||
public string PassWord { get; set; } = String.Empty;
|
||||
public string PassWord { get; set; } = string.Empty;
|
||||
|
||||
public string SignText { get; set; } = String.Empty;
|
||||
public string SignText { get; set; } = string.Empty;
|
||||
|
||||
|
||||
|
||||
[NotDefault]
|
||||
public Guid TrialId { get; set; }
|
||||
|
||||
[NotDefault]
|
||||
public Guid SignCodeId { get; set; }
|
||||
public Guid? TrialId { get; set; }
|
||||
|
||||
[NotDefault]
|
||||
public string SignCode { get; set; } = String.Empty;
|
||||
public Guid? SignCodeId { get; set; }
|
||||
|
||||
|
||||
public string SignCode { get; set; } = string.Empty;
|
||||
|
||||
public Guid? SubjectVisitId { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class DataInspectionAddDTO
|
||||
{
|
||||
|
||||
public Guid TrialId { get; set; }
|
||||
public Guid SiteId { get; set; }
|
||||
public Guid SubjectId { get; set; }
|
||||
public Guid SubjectVisitId { get; set; }
|
||||
public int ModuleEnum { get; set; }
|
||||
public int OptEnum { get; set; }
|
||||
|
||||
|
||||
|
||||
public string BlindName { get; set; } = string.Empty;
|
||||
public string Reason { get; set; } = string.Empty;
|
||||
public bool IsSign { get; set; }
|
||||
public string JsonDetail { get; set; } = string.Empty;
|
||||
|
||||
|
||||
|
||||
|
||||
////需要单独处理
|
||||
//public string IP { get; set; }
|
||||
|
||||
//public Guid? SignId { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
public interface IInspectionDTO
|
||||
{
|
||||
public DataInspectionAddDTO AuditInfo { get; set; }
|
||||
}
|
||||
|
||||
public interface ISignDTO
|
||||
{
|
||||
public SignDTO SignInfo { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class TrialDocumentConfirmDTO : IInspectionDTO, ISignDTO
|
||||
{
|
||||
public UserConfirmCommand OptCommand { get; set; }
|
||||
|
||||
public DataInspectionAddDTO AuditInfo { get; set; }
|
||||
|
||||
public SignDTO SignInfo { get; set; }
|
||||
}
|
||||
@@ -7,6 +7,8 @@ namespace IRaCIS.Application.Interfaces
|
||||
{
|
||||
Task<IResponseOutput> AddOrUpdateSubject([FromBody] SubjectCommand subjectCommand);
|
||||
Task<IResponseOutput> DeleteSubject(Guid id);
|
||||
|
||||
Task<IResponseOutput> UpdateSubjectStatus(SubjectStatusChangeCommand subjectStatusChangeCommand);
|
||||
Task<IResponseOutput<PageOutput<SubjectQueryView>, TrialSubjectConfig>> GetSubjectList(SubjectQueryParam param);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user