添加项目文件。
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
//--------------------------------------------------------------------
|
||||
// 此代码由T4模板自动生成 byzhouhang 20210918
|
||||
// 生成时间 2021-12-23 13:21:04
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||
//--------------------------------------------------------------------
|
||||
namespace IRaCIS.Core.Application.Contracts
|
||||
{
|
||||
/// <summary> TrialSiteEquipmentSurveyView 列表视图模型 </summary>
|
||||
public class TrialSiteEquipmentSurveyView
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid TrialSiteSurveyId { get; set; }
|
||||
public string EquipmentType { get; set; } = string.Empty;
|
||||
public Guid? EquipmentTypeId { get; set; }
|
||||
|
||||
public string Parameters { get; set; } = string.Empty;
|
||||
public string ManufacturerName { get; set; } = string.Empty;
|
||||
public string ScannerType { get; set; } = string.Empty;
|
||||
public string Note { get; set; } = string.Empty;
|
||||
public DateTime CreateTime { get; set; }
|
||||
public Guid CreateUserId { get; set; }
|
||||
public DateTime UpdateTime { get; set; }
|
||||
public Guid UpdateUserId { get; set; }
|
||||
}
|
||||
|
||||
///<summary>TrialSiteEquipmentSurveyQuery 列表查询参数模型</summary>
|
||||
public class TrialSiteEquipmentSurveyQuery
|
||||
{
|
||||
|
||||
public Guid TrialSiteSurveyId { get; set; }
|
||||
|
||||
public string ScannerType { get; set; } = string.Empty;
|
||||
|
||||
/////<summary> Parameters</summary>
|
||||
//public string Parameters { get; set; }
|
||||
|
||||
/////<summary> ManufacturerName</summary>
|
||||
//public string ManufacturerName { get; set; }
|
||||
|
||||
/////<summary> ScannerType</summary>
|
||||
//public string ScannerType { get; set; }
|
||||
|
||||
/////<summary> Note</summary>
|
||||
//public string Note { get; set; }
|
||||
|
||||
}
|
||||
|
||||
///<summary> TrialSiteEquipmentSurveyAddOrEdit 列表查询参数模型</summary>
|
||||
public class TrialSiteEquipmentSurveyAddOrEdit
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
public Guid TrialSiteSurveyId { get; set; }
|
||||
|
||||
public Guid? EquipmentTypeId { get; set; }
|
||||
public string Parameters { get; set; } = string.Empty;
|
||||
public string ManufacturerName { get; set; } = string.Empty;
|
||||
public string ScannerType { get; set; } = string.Empty;
|
||||
public string Note { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
//--------------------------------------------------------------------
|
||||
// 此代码由T4模板自动生成 byzhouhang 20210918
|
||||
// 生成时间 2021-12-23 13:21:04
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
namespace IRaCIS.Core.Application.Contracts
|
||||
{
|
||||
|
||||
public class TrialSurveyInitInfo
|
||||
{
|
||||
public Guid TrialId { get; set; }
|
||||
public string Sponsor { get; set; } = string.Empty;
|
||||
|
||||
//研究方案号
|
||||
public string ResearchProgramNo { get; set; } = string.Empty;
|
||||
|
||||
//实验名称
|
||||
public string ExperimentName { get; set; } = string.Empty;
|
||||
|
||||
public string TrialCode { get; set; } = string.Empty;
|
||||
|
||||
public Guid IndicationTypeId { get; set; }
|
||||
|
||||
public string IndicationType { get; set; } = string.Empty;
|
||||
|
||||
public string TrialSiteSurveyUserRoles { get; set; } = string.Empty;
|
||||
|
||||
public string TrialSiteSurveyEquipmentType { get; set; } = string.Empty;
|
||||
|
||||
public List<TrialSiteForSelect> TrialSiteSelectList { get; set; }=new List<TrialSiteForSelect>();
|
||||
|
||||
}
|
||||
|
||||
public class TrialSiteForSelect
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid TrialId { get; set; }
|
||||
|
||||
public Guid SiteId { get; set; }
|
||||
|
||||
public string TrialSiteCode { get; set; } = string.Empty;
|
||||
|
||||
public string TrialSiteAliasName { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class LoginReturnDTO
|
||||
{
|
||||
public TrialSurveyInitInfo TrialInfo { get; set; } = new TrialSurveyInitInfo();
|
||||
|
||||
public TrialSiteSurveyView TrialSiteSurvey { get; set; } = new TrialSiteSurveyView();
|
||||
|
||||
public List<TrialSiteEquipmentSurveyView> TrialSiteEquipmentSurveyList { get; set; } = new List<TrialSiteEquipmentSurveyView>();
|
||||
|
||||
public List<TrialSiteUserSurveyView> TrialSiteUserSurveyList { get; set; } = new List<TrialSiteUserSurveyView>();
|
||||
}
|
||||
|
||||
|
||||
/// <summary> TrialSiteSurveyView 列表视图模型 </summary>
|
||||
public class TrialSiteSurveyView
|
||||
{
|
||||
|
||||
public string TrialSiteCode { get; set; } = String.Empty;
|
||||
public string TrialSiteAliasName { get; set; } = String.Empty;
|
||||
|
||||
public string SiteName { get; set; } = string.Empty;
|
||||
public bool IsAbandon { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
public Guid TrialId { get; set; }
|
||||
public Guid SiteId { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
public Guid CreateUserId { get; set; }
|
||||
public DateTime UpdateTime { get; set; }
|
||||
public Guid UpdateUserId { get; set; }
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
public string Phone { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public int AverageEngravingCycle { get; set; }
|
||||
public bool IsConfirmImagingTechnologist { get; set; }
|
||||
public string NotConfirmReson { get; set; } = string.Empty;
|
||||
public int EfficacyEvaluatorType { get; set; }
|
||||
public bool IsFollowStudyParameters { get; set; }
|
||||
public string NotFollowReson { get; set; } = string.Empty;
|
||||
//public bool IsLocked { get; set; } = false;
|
||||
public TrialSiteSurveyEnum State { get; set; }
|
||||
}
|
||||
|
||||
///<summary>TrialSiteSurveyQuery 列表查询参数模型</summary>
|
||||
public class TrialSiteSurveyQuery
|
||||
{
|
||||
public Guid TrialId { get; set; }
|
||||
|
||||
public Guid SiteId { get; set; }
|
||||
|
||||
/////<summary> UserName</summary>
|
||||
//public string UserName { get; set; }
|
||||
|
||||
/////<summary> Phone</summary>
|
||||
//public string Phone { get; set; }
|
||||
|
||||
/////<summary> Email</summary>
|
||||
//public string Email { get; set; }
|
||||
|
||||
/////<summary> NotConfirmReson</summary>
|
||||
//public string NotConfirmReson { get; set; }
|
||||
|
||||
/////<summary> NotFollowReson</summary>
|
||||
//public string NotFollowReson { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class SiteSurveySendVerifyCode
|
||||
{
|
||||
public VerifyType verificationType { get; set; }
|
||||
public string EmailOrPhone { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
|
||||
public class LoginDto
|
||||
{
|
||||
public Guid TrialId { get; set; }
|
||||
|
||||
public Guid SiteId { get; set; }
|
||||
|
||||
|
||||
public bool IsUpdate { get; set; }
|
||||
|
||||
|
||||
public string ReplaceUserEmailOrPhone { get; set; } = string.Empty;
|
||||
|
||||
public VerifyType verificationType { get; set; }
|
||||
public string EmailOrPhone { get; set; } = string.Empty;
|
||||
|
||||
public string verificationCode { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
|
||||
///<summary> TrialSiteSurveyAddOrEdit 列表查询参数模型</summary>
|
||||
public class TrialSiteSurveyAddOrEdit
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
public Guid TrialId { get; set; }
|
||||
public Guid SiteId { get; set; }
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
public string Phone { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public int AverageEngravingCycle { get; set; }
|
||||
public bool IsConfirmImagingTechnologist { get; set; }
|
||||
public string NotConfirmReson { get; set; } = string.Empty;
|
||||
public int EfficacyEvaluatorType { get; set; }
|
||||
public bool IsFollowStudyParameters { get; set; }
|
||||
public string NotFollowReson { get; set; } = string.Empty;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class TrialSiteSurvyeSubmitDTO
|
||||
{
|
||||
[NotDefault]
|
||||
public Guid TrialId { get; set; }
|
||||
[NotDefault]
|
||||
public Guid TrialSiteSurveyId { get; set; }
|
||||
|
||||
public string? LoginUrl { get; set; }
|
||||
|
||||
public string? RouteUrl { get; set; }
|
||||
}
|
||||
|
||||
public class TrialSiteSurveyQueryDTO
|
||||
{
|
||||
//public Guid? SiteId { get; set; }
|
||||
|
||||
public string SiteName { get; set; } = String.Empty;
|
||||
public string TrialSiteCode { get; set; } = String.Empty;
|
||||
public string TrialSiteAliasName { get; set; } = String.Empty;
|
||||
}
|
||||
|
||||
public class CopyTrialSiteSurveyDTO
|
||||
{
|
||||
public Guid TrialSiteSurveyId { get; set; }
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
public string Phone { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
//--------------------------------------------------------------------
|
||||
// 此代码由T4模板自动生成 byzhouhang 20210918
|
||||
// 生成时间 2021-12-23 13:21:04
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||
//--------------------------------------------------------------------
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
namespace IRaCIS.Core.Application.Contracts
|
||||
{
|
||||
/// <summary> TrialSiteUserSurveyView 列表视图模型 </summary>
|
||||
public class TrialSiteUserSurveyView: TrialSiteUserSurveyAddOrEdit
|
||||
{
|
||||
public bool IsGenerateSuccess { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
public Guid CreateUserId { get; set; }
|
||||
public DateTime UpdateTime { get; set; }
|
||||
public Guid UpdateUserId { get; set; }
|
||||
|
||||
public string UserType { get; set; } = string.Empty;
|
||||
public TrialSiteSurveyEnum State { get; set; }
|
||||
|
||||
public string TrialRoleName { get; set; }
|
||||
|
||||
public Guid? SystemUserId { get; set; }
|
||||
}
|
||||
|
||||
///<summary>TrialSiteUserSurveyQuery 列表查询参数模型</summary>
|
||||
public class TrialSiteUserSurveyQuery
|
||||
{
|
||||
|
||||
public Guid TrialSiteSurveyId { get; set; }
|
||||
|
||||
/////<summary> UserName</summary>
|
||||
//public string Name { get; set; }
|
||||
|
||||
/////<summary> Phone</summary>
|
||||
//public string Phone { get; set; }
|
||||
|
||||
/////<summary> Email</summary>
|
||||
//public string Email { get; set; }
|
||||
|
||||
}
|
||||
|
||||
///<summary> TrialSiteUserSurveyAddOrEdit 列表查询参数模型</summary>
|
||||
public class TrialSiteUserSurveyAddOrEdit
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
public Guid TrialRoleNameId { get; set; }
|
||||
public Guid TrialSiteSurveyId { get; set; }
|
||||
public Guid? UserTypeId { get; set; }
|
||||
public string FirstName { get; set; } = string.Empty;
|
||||
public string LastName { get; set; } = string.Empty;
|
||||
public string Phone { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public bool IsCorrect { get; set; }
|
||||
public bool IsGenerateAccount { get; set; }
|
||||
|
||||
public string OrganizationName { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
|
||||
public class TrialSiteUserSurveyVerfyResult
|
||||
{
|
||||
public Guid TrialSiteUserSurveyId { get; set; }
|
||||
|
||||
public List<string> ErroMsgList { get; set; } = new List<string>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
//--------------------------------------------------------------------
|
||||
// 此代码由T4模板自动生成 byzhouhang 20210918
|
||||
// 生成时间 2021-12-23 13:20:59
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace IRaCIS.Core.Application.Contracts
|
||||
{
|
||||
public interface ITrialSiteEquipmentSurveyService
|
||||
{
|
||||
Task<IResponseOutput> AddOrUpdateTrialSiteEquipmentSurvey(TrialSiteEquipmentSurveyAddOrEdit addOrEditTrialSiteEquipmentSurvey);
|
||||
Task<IResponseOutput> DeleteTrialSiteEquipmentSurvey(Guid trialSiteEquipmentSurveyId);
|
||||
Task<List<TrialSiteEquipmentSurveyView>> GetTrialSiteEquipmentSurveyList(Guid trialSiteSurveyId, string? scannerType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
//--------------------------------------------------------------------
|
||||
// 此代码由T4模板自动生成 byzhouhang 20210918
|
||||
// 生成时间 2021-12-23 13:20:59
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||
//--------------------------------------------------------------------
|
||||
using IRaCIS.Application.Services;
|
||||
using IRaCIS.Core.Application.Auth;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace IRaCIS.Core.Application.Contracts
|
||||
{
|
||||
public interface ITrialSiteSurveyService
|
||||
{
|
||||
Task<IResponseOutput> AddOrUpdateTrialSiteSurvey(TrialSiteSurveyAddOrEdit addOrEditTrialSiteSurvey);
|
||||
Task<IResponseOutput> DeleteTrialSiteSurvey(Guid trialSiteSurveyId);
|
||||
Task<LoginReturnDTO> GetSiteSurveyInfo(Guid trialSiteSurveyId, Guid trialId);
|
||||
Task<List<TrialSiteSurveyView>> GetTrialSiteSurveyList(Guid trialId, TrialSiteSurveyQueryDTO trialSiteSurveyQueryDTO);
|
||||
Task<TrialSurveyInitInfo> GetTrialSurveyInitInfo(Guid trialId);
|
||||
Task<IResponseOutput> SendVerifyCode(SiteSurveySendVerifyCode userInfo, [FromServices] IMailVerificationService _mailVerificationService);
|
||||
//Task<IResponseOutput> TrialSurveyLock(Guid trialSiteSurveyId, bool isLock);
|
||||
//IResponseOutput TrialSurveySubmmit(Guid trialId, Guid trialSiteSurveyId);
|
||||
Task<IResponseOutput> VerifySendCode(LoginDto userInfo, [FromServices] ITokenService _tokenService);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//--------------------------------------------------------------------
|
||||
// 此代码由T4模板自动生成 byzhouhang 20210918
|
||||
// 生成时间 2021-12-23 13:20:59
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
namespace IRaCIS.Core.Application.Contracts
|
||||
{
|
||||
public interface ITrialSiteUserSurveyService
|
||||
{
|
||||
Task<IResponseOutput> AddOrUpdateTrialSiteUserSurvey(TrialSiteUserSurveyAddOrEdit addOrEditTrialSiteUserSurvey);
|
||||
Task<IResponseOutput> DeleteTrialSiteUserSurvey(Guid trialSiteUserSurveyId);
|
||||
Task<List<TrialSiteUserSurveyView>> GetTrialSiteUserSurveyList(Guid trialSiteSurveyId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Microsoft.AspNetCore.JsonPatch.Operations;
|
||||
using Swashbuckle.AspNetCore.Filters;
|
||||
|
||||
namespace IRaCIS.Core.Application.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// 实测 标注在服务方法上 没用
|
||||
/// </summary>
|
||||
public class JsonPatchUserRequestExample : IExamplesProvider<object>
|
||||
{
|
||||
public Operation[] GetExamples()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
new Operation
|
||||
{
|
||||
op = "replace",
|
||||
path = "/name",
|
||||
value = "Gordon"
|
||||
},
|
||||
new Operation
|
||||
{
|
||||
op = "replace",
|
||||
path = "/surname",
|
||||
value = "Freeman"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
object IExamplesProvider<object>.GetExamples()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
new Operation
|
||||
{
|
||||
op = "replace",
|
||||
path = "/name",
|
||||
value = "Gordon"
|
||||
},
|
||||
new Operation
|
||||
{
|
||||
op = "replace",
|
||||
path = "/surname",
|
||||
value = "Freeman"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
//--------------------------------------------------------------------
|
||||
// 此代码由T4模板自动生成 byzhouhang 20210918
|
||||
// 生成时间 2021-12-23 13:20:59
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using IRaCIS.Core.Application.Filter;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using IRaCIS.Core.Infra.EFCore;
|
||||
|
||||
namespace IRaCIS.Core.Application.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// TrialSiteEquipmentSurveyService
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "Trial")]
|
||||
public class TrialSiteEquipmentSurveyService : BaseService, ITrialSiteEquipmentSurveyService
|
||||
{
|
||||
private readonly IRepository<TrialSiteEquipmentSurvey> _trialSiteEquipmentSurveyRepository;
|
||||
|
||||
public TrialSiteEquipmentSurveyService(IRepository<TrialSiteEquipmentSurvey> trialSiteEquipmentSurveyRepository)
|
||||
{
|
||||
_trialSiteEquipmentSurveyRepository = trialSiteEquipmentSurveyRepository;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("{trialSiteSurveyId:guid}")]
|
||||
public async Task<List<TrialSiteEquipmentSurveyView>> GetTrialSiteEquipmentSurveyList(Guid trialSiteSurveyId, string? scannerType)
|
||||
{
|
||||
var trialSiteEquipmentSurveyQueryable = _trialSiteEquipmentSurveyRepository.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId)
|
||||
.WhereIf(!string.IsNullOrEmpty(scannerType), t => t.ScannerType.Contains(scannerType!))
|
||||
.ProjectTo<TrialSiteEquipmentSurveyView>(_mapper.ConfigurationProvider);
|
||||
|
||||
return await trialSiteEquipmentSurveyQueryable.ToListAsync();
|
||||
}
|
||||
|
||||
[TypeFilter(typeof(TrialResourceFilter))]
|
||||
[HttpPost("{trialId:guid}")]
|
||||
public async Task<IResponseOutput> AddOrUpdateTrialSiteEquipmentSurvey(TrialSiteEquipmentSurveyAddOrEdit addOrEditTrialSiteEquipmentSurvey)
|
||||
{
|
||||
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM)
|
||||
{
|
||||
return ResponseOutput.NotOk("CPM/APM 不允许操作");
|
||||
}
|
||||
|
||||
if (addOrEditTrialSiteEquipmentSurvey.Id != null)
|
||||
{
|
||||
if (await _trialSiteEquipmentSurveyRepository.Where(t => t.Id == addOrEditTrialSiteEquipmentSurvey.Id).AnyAsync(t => t.TrialSiteSurvey.State==TrialSiteSurveyEnum.PMCreatedAndLock))
|
||||
{
|
||||
return ResponseOutput.NotOk("已锁定,不允许操作");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var entity = await _trialSiteEquipmentSurveyRepository.InsertOrUpdateAsync(addOrEditTrialSiteEquipmentSurvey, true);
|
||||
|
||||
return ResponseOutput.Ok(entity.Id.ToString());
|
||||
|
||||
}
|
||||
|
||||
[TypeFilter(typeof(TrialResourceFilter))]
|
||||
[HttpDelete("{trialSiteEquipmentSurveyId:guid}/{trialId:guid}")]
|
||||
public async Task<IResponseOutput> DeleteTrialSiteEquipmentSurvey(Guid trialSiteEquipmentSurveyId)
|
||||
{
|
||||
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM)
|
||||
{
|
||||
return ResponseOutput.NotOk("CPM/APM 不允许操作");
|
||||
}
|
||||
|
||||
if (await _trialSiteEquipmentSurveyRepository.Where(t => t.Id == trialSiteEquipmentSurveyId).AnyAsync(t => t.TrialSiteSurvey.State==TrialSiteSurveyEnum.PMCreatedAndLock))
|
||||
{
|
||||
return ResponseOutput.NotOk("已锁定,不允许操作");
|
||||
}
|
||||
var success = await _trialSiteEquipmentSurveyRepository.DeleteFromQueryAsync(t => t.Id == trialSiteEquipmentSurveyId);
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,691 @@
|
||||
//--------------------------------------------------------------------
|
||||
// 此代码由T4模板自动生成 byzhouhang 20210918
|
||||
// 生成时间 2021-12-23 13:20:59
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||
//--------------------------------------------------------------------
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using System.Text.RegularExpressions;
|
||||
using IRaCIS.Core.Infrastructure;
|
||||
using IRaCIS.Application.Services;
|
||||
using IRaCIS.Core.Application.Auth;
|
||||
using IRaCIS.Application.Contracts;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using IRaCIS.Core.Application.Filter;
|
||||
using IRaCIS.Core.Infra.EFCore;
|
||||
using MailKit.Security;
|
||||
using MimeKit;
|
||||
|
||||
namespace IRaCIS.Core.Application.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// TrialSiteSurveyService
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "Trial")]
|
||||
public class TrialSiteSurveyService : BaseService, ITrialSiteSurveyService
|
||||
{
|
||||
private readonly IRepository<TrialSiteSurvey> _trialSiteSurveyRepository;
|
||||
private readonly IRepository<TrialSiteUserSurvey> _trialSiteUserSurveyRepository;
|
||||
private readonly IRepository<User> _userRepository;
|
||||
|
||||
public TrialSiteSurveyService(IRepository<TrialSiteSurvey> trialSiteSurveyRepository,IRepository<TrialSiteUserSurvey> trialSiteUserSurveyRepository,IRepository<User> userRepository)
|
||||
{
|
||||
_trialSiteSurveyRepository = trialSiteSurveyRepository;
|
||||
_trialSiteUserSurveyRepository = trialSiteUserSurveyRepository;
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
|
||||
private object lockObj { get; set; } = new object();
|
||||
|
||||
/// <summary>
|
||||
/// 发送验证码
|
||||
/// </summary>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="_mailVerificationService"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
public async Task<IResponseOutput> SendVerifyCode(SiteSurveySendVerifyCode userInfo, [FromServices] IMailVerificationService _mailVerificationService)
|
||||
{
|
||||
var verificationType = userInfo.verificationType;
|
||||
//检查手机或者邮箱是否有效
|
||||
if (!Regex.IsMatch(userInfo.EmailOrPhone, @"/^1[34578]\d{9}$/") && !Regex.IsMatch(userInfo.EmailOrPhone, @"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$"))
|
||||
{
|
||||
|
||||
throw new BusinessValidationFailedException(verificationType == VerifyType.Email
|
||||
? "Please input a legal email"
|
||||
: "Please input a legal phone");
|
||||
|
||||
}
|
||||
|
||||
//邮箱
|
||||
if (verificationType == VerifyType.Email)
|
||||
{
|
||||
//验证码 6位
|
||||
int verificationCode = new Random().Next(100000, 1000000);
|
||||
|
||||
await _mailVerificationService.AnolymousSendEmail(userInfo.EmailOrPhone, verificationCode);
|
||||
}
|
||||
//手机短信
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证后 如果数据库该项目不存在该邮箱 那么就插入记录 存在
|
||||
/// </summary>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="_tokenService"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="BusinessValidationFailedException"></exception>
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<IResponseOutput> VerifySendCode(LoginDto userInfo, [FromServices] ITokenService _tokenService)
|
||||
{
|
||||
|
||||
var isReplaceUser = !string.IsNullOrEmpty(userInfo.ReplaceUserEmailOrPhone);
|
||||
|
||||
|
||||
if (userInfo.IsUpdate && isReplaceUser && !await _trialSiteSurveyRepository.AnyAsync(t => (t.Email == userInfo.ReplaceUserEmailOrPhone || t.Phone == userInfo.ReplaceUserEmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId))
|
||||
{
|
||||
return ResponseOutput.NotOk("该项目Site不存在该交接人的调研记录,不允许选择更新");
|
||||
}
|
||||
|
||||
|
||||
if (userInfo.IsUpdate && await _trialSiteSurveyRepository.AnyAsync(t => (t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State != TrialSiteSurveyEnum.PMCreatedAndLock))
|
||||
{
|
||||
return ResponseOutput.NotOk("您的记录未锁定,不允许选择更新,若已经提交,可被驳回后进行操作");
|
||||
}
|
||||
|
||||
|
||||
//自己的记录锁定了 只能更新自己的,不能更新别人的(但是别人能更新自己锁定的)
|
||||
if (userInfo.IsUpdate && userInfo.ReplaceUserEmailOrPhone != userInfo.EmailOrPhone && await _trialSiteSurveyRepository.AnyAsync(t => (t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State == TrialSiteSurveyEnum.PMCreatedAndLock))
|
||||
{
|
||||
//自己的锁了 想更新别人的
|
||||
return ResponseOutput.NotOk("当前Site 您的调研记录已锁定,不允许更新其他人邮箱调研记录");
|
||||
}
|
||||
|
||||
//自己的锁定了 如果有其他未锁定的,也不能更新自己的
|
||||
if (userInfo.IsUpdate && userInfo.ReplaceUserEmailOrPhone == userInfo.EmailOrPhone &&
|
||||
await _trialSiteSurveyRepository.AnyAsync(t => (t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State == TrialSiteSurveyEnum.PMCreatedAndLock)
|
||||
&& await _trialSiteSurveyRepository.AnyAsync(t => (t.Email != userInfo.EmailOrPhone && t.Phone != userInfo.EmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State != TrialSiteSurveyEnum.PMCreatedAndLock))
|
||||
{
|
||||
|
||||
return ResponseOutput.NotOk("当前Site 您的调研记录已锁定,也存在其他未锁定的记录,不允许更新自己的调研记录");
|
||||
}
|
||||
|
||||
|
||||
////存在未锁定的记录,却去更新已锁定的
|
||||
if (userInfo.IsUpdate && userInfo.ReplaceUserEmailOrPhone != userInfo.EmailOrPhone && await _trialSiteSurveyRepository.AnyAsync(t => t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State != TrialSiteSurveyEnum.PMCreatedAndLock)
|
||||
&& await _trialSiteSurveyRepository.AnyAsync(t => (t.Email == userInfo.ReplaceUserEmailOrPhone || t.Phone == userInfo.ReplaceUserEmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State == TrialSiteSurveyEnum.PMCreatedAndLock)
|
||||
&& !await _trialSiteSurveyRepository.AnyAsync(t => (t.Email == userInfo.ReplaceUserEmailOrPhone || t.Phone == userInfo.ReplaceUserEmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State != TrialSiteSurveyEnum.PMCreatedAndLock)
|
||||
)
|
||||
{
|
||||
return ResponseOutput.NotOk("当前Site 存在未锁定的调研记录,不允许更新已锁定邮箱的调研记录");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//var verificationRecord = await _repository
|
||||
// .FirstOrDefaultAsync<VerificationCode>(t => (t.EmailOrPhone == userInfo.EmailOrPhone) && t.Code == userInfo.verificationCode && t.CodeType == userInfo.verificationType);
|
||||
|
||||
////检查数据库是否存在该验证码
|
||||
//if (verificationRecord == null)
|
||||
//{
|
||||
// return ResponseOutput.NotOk("Verification code error");
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// //检查验证码是否失效
|
||||
// if (verificationRecord.ExpirationTime < DateTime.Now)
|
||||
// {
|
||||
// return ResponseOutput.NotOk("The verification code has expired");
|
||||
// }
|
||||
// else //验证码正确 并且 没有超时
|
||||
{
|
||||
TrialSiteSurvey dbEntity = null;
|
||||
|
||||
|
||||
//替换交接人
|
||||
if (isReplaceUser)
|
||||
{
|
||||
//该交接人的记录 是否有未锁定的 有就用未锁定的,没有就用 锁定的最后一条
|
||||
|
||||
var noLockedLastSurvey = await _trialSiteSurveyRepository.Where(t => (t.Email == userInfo.ReplaceUserEmailOrPhone || t.Phone == userInfo.ReplaceUserEmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State == TrialSiteSurveyEnum.PMCreatedAndLock == false, true)
|
||||
.Include(u => u.TrialSiteEquipmentSurveyList).Include(u => u.TrialSiteUserSurveyList).OrderByDescending(t => t.CreateTime).FirstOrDefaultAsync();
|
||||
|
||||
//都是锁定的
|
||||
if (noLockedLastSurvey == null)
|
||||
{
|
||||
|
||||
var latestLock = await _trialSiteSurveyRepository.Where(t => t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId).OrderByDescending(t => t.CreateTime).FirstOrDefaultAsync();
|
||||
|
||||
if (latestLock!.Email != userInfo.ReplaceUserEmailOrPhone)
|
||||
{
|
||||
return ResponseOutput.NotOk($"该邮箱{userInfo.ReplaceUserEmailOrPhone }对应的调查表不是最新锁定的记录,不允许更新!");
|
||||
}
|
||||
|
||||
var lockedLastSurvey = await _trialSiteSurveyRepository.Where(t => (t.Email == userInfo.ReplaceUserEmailOrPhone || t.Phone == userInfo.ReplaceUserEmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State == TrialSiteSurveyEnum.PMCreatedAndLock == true)
|
||||
.Include(u => u.TrialSiteEquipmentSurveyList).Include(u => u.TrialSiteUserSurveyList).OrderByDescending(t => t.CreateTime).FirstOrDefaultAsync().IfNullThrowConvertException();
|
||||
|
||||
//Copy 一份 更换邮箱
|
||||
|
||||
var copy = lockedLastSurvey.Clone();
|
||||
|
||||
copy.State = TrialSiteSurveyEnum.ToSubmit;
|
||||
|
||||
copy.Email = userInfo.EmailOrPhone;
|
||||
|
||||
if (userInfo.ReplaceUserEmailOrPhone != userInfo.EmailOrPhone)
|
||||
{
|
||||
copy.UserName = String.Empty;
|
||||
copy.Phone = String.Empty;
|
||||
}
|
||||
|
||||
|
||||
copy.Id = Guid.Empty;
|
||||
copy.TrialSiteEquipmentSurveyList.ForEach(t => t.Id = Guid.Empty);
|
||||
copy.TrialSiteUserSurveyList.ForEach(t => t.Id = Guid.Empty);
|
||||
|
||||
dbEntity = await _repository.AddAsync(copy);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//有未锁定的 更新下邮箱
|
||||
noLockedLastSurvey.Email = userInfo.EmailOrPhone;
|
||||
noLockedLastSurvey.UserName = String.Empty;
|
||||
noLockedLastSurvey.Phone = String.Empty;
|
||||
|
||||
dbEntity = noLockedLastSurvey;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////邮箱相同的话 就是同一个人进来 copy一份
|
||||
//if (userInfo.EmailOrPhone == userInfo.ReplaceUserEmailOrPhone)
|
||||
//{
|
||||
// dbEntity = await _repository.Where<TrialSiteSurvey>(t => (t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId).Include(u => u.TrialSiteEquipmentSurveyList).Include(u => u.TrialSiteUserSurveyList).FirstOrDefaultAsync().IfNullThrowConvertException();
|
||||
|
||||
// var clone = dbEntity.Clone();
|
||||
// clone.Id = Guid.Empty;
|
||||
// clone.TrialSiteEquipmentSurveyList.ForEach(t => t.Id = Guid.Empty);
|
||||
// clone.TrialSiteUserSurveyList.ForEach(t => t.Id = Guid.Empty);
|
||||
// clone.State = TrialSiteSurveyEnum.ToSubmit;
|
||||
|
||||
// dbEntity = await _repository.AddAsync(clone);
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
var dbEntityList = await _trialSiteSurveyRepository.Where(t => t.TrialId == userInfo.TrialId && t.SiteId == userInfo.SiteId).ToListAsync();
|
||||
|
||||
|
||||
//没有记录 new一份
|
||||
if (dbEntityList.Count == 0)
|
||||
{
|
||||
|
||||
dbEntity = await _repository.AddAsync(_mapper.Map<TrialSiteSurvey>(userInfo));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
|
||||
//该site 下不存在该邮箱的记录
|
||||
if (!dbEntityList.Any(t => t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone))
|
||||
{
|
||||
return ResponseOutput.NotOk("该Site下已经有其他用户已填写的调研表,您不被允许继续填写");
|
||||
}
|
||||
|
||||
|
||||
//有没有该邮箱 未锁定的
|
||||
var nolockEntity = dbEntityList.Where(t => t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone).FirstOrDefault(t => t.State != TrialSiteSurveyEnum.PMCreatedAndLock);
|
||||
|
||||
// 未锁定的 为空
|
||||
if (nolockEntity == null)
|
||||
{
|
||||
//查看最新锁定的
|
||||
dbEntity = dbEntityList.Where(t => t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone).OrderByDescending(t => t.CreateTime).FirstOrDefault(t => t.State == TrialSiteSurveyEnum.PMCreatedAndLock).IfNullThrowException();
|
||||
|
||||
}
|
||||
else //有未锁定的 直接用未锁定的
|
||||
{
|
||||
dbEntity = nolockEntity;
|
||||
}
|
||||
|
||||
}
|
||||
//_mapper.Map(userInfo, dbEntity);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//删除验证码历史记录
|
||||
await _repository.DeleteFromQueryAsync<VerificationCode>(t => t.EmailOrPhone == userInfo.EmailOrPhone && t.Code == userInfo.verificationCode && t.CodeType == userInfo.verificationType);
|
||||
|
||||
await _repository.SaveChangesAsync();
|
||||
|
||||
return ResponseOutput.Ok(new
|
||||
{
|
||||
TrialSiteSurveyId = dbEntity!.Id,
|
||||
Token = _tokenService.GetToken(IRaCISClaims.Create(new UserBasicInfo()
|
||||
{
|
||||
Id = Guid.Empty,
|
||||
IsReviewer = false,
|
||||
IsAdmin = false,
|
||||
RealName = "SiteSurvey",
|
||||
UserName = "SiteSurvey",
|
||||
Sex = 0,
|
||||
//UserType = "ShareType",
|
||||
UserTypeEnum = UserTypeEnum.Undefined,
|
||||
Code = "SiteSurvey",
|
||||
}))
|
||||
});
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 直接查询相关所有数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{trialId:guid}/{trialSiteSurveyId:guid}")]
|
||||
public async Task<LoginReturnDTO> GetSiteSurveyInfo(Guid trialSiteSurveyId, Guid trialId)
|
||||
{
|
||||
var result = await _trialSiteSurveyRepository.Where(t => t.Id == trialSiteSurveyId && t.TrialId == trialId)
|
||||
.ProjectTo<LoginReturnDTO>(_mapper.ConfigurationProvider).FirstOrDefaultAsync().IfNullThrowException();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 实际这里只会是更新 添加在login的时候做了
|
||||
/// </summary>
|
||||
/// <param name="addOrEditTrialSiteSurvey"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IResponseOutput> AddOrUpdateTrialSiteSurvey(TrialSiteSurveyAddOrEdit addOrEditTrialSiteSurvey)
|
||||
{
|
||||
|
||||
if (addOrEditTrialSiteSurvey.Id != null)
|
||||
{
|
||||
if (await _trialSiteSurveyRepository.AnyAsync(t => t.Id == addOrEditTrialSiteSurvey.Id && t.State == TrialSiteSurveyEnum.PMCreatedAndLock))
|
||||
{
|
||||
return ResponseOutput.NotOk("已锁定,不允许操作");
|
||||
}
|
||||
}
|
||||
var entity = await _trialSiteSurveyRepository.InsertOrUpdateAsync(addOrEditTrialSiteSurvey, true);
|
||||
|
||||
return ResponseOutput.Ok(entity.Id.ToString());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除调研表
|
||||
/// </summary>
|
||||
/// <param name="trialSiteSurveyId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{trialSiteSurveyId:guid}/{trialId:guid}")]
|
||||
public async Task<IResponseOutput> DeleteTrialSiteSurvey(Guid trialSiteSurveyId)
|
||||
{
|
||||
|
||||
|
||||
if (await _trialSiteSurveyRepository.AnyAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.PMCreatedAndLock))
|
||||
{
|
||||
return ResponseOutput.NotOk("已锁定,不允许操作");
|
||||
}
|
||||
|
||||
var success = await _trialSiteSurveyRepository.DeleteFromQueryAsync(t => t.Id == trialSiteSurveyId);
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取 项目 某个site的调研记录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("{trialId:guid}")]
|
||||
public async Task<List<TrialSiteSurveyView>> GetTrialSiteSurveyList(Guid trialId, TrialSiteSurveyQueryDTO trialSiteSurveyQueryDTO)
|
||||
{
|
||||
var trialSiteSurveyQueryable = _trialSiteSurveyRepository.Where(t => t.TrialId == trialId).IgnoreQueryFilters()
|
||||
//.WhereIf(trialSiteSurveyQueryDTO.si != null, t => t.SiteId == siteId)
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(trialSiteSurveyQueryDTO.SiteName), t => t.Site.SiteName.Contains(trialSiteSurveyQueryDTO.SiteName))
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(trialSiteSurveyQueryDTO.TrialSiteAliasName), t => t.TrialSite.TrialSiteAliasName.Contains(trialSiteSurveyQueryDTO.TrialSiteAliasName))
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(trialSiteSurveyQueryDTO.TrialSiteCode), t => t.TrialSite.TrialSiteAliasName.Contains(trialSiteSurveyQueryDTO.TrialSiteCode))
|
||||
//.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM, t => t.State >= TrialSiteSurveyEnum.ToSubmit)
|
||||
//.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM, t => t.State >= TrialSiteSurveyEnum.SPMApproved)
|
||||
.ProjectTo<TrialSiteSurveyView>(_mapper.ConfigurationProvider);
|
||||
|
||||
return await trialSiteSurveyQueryable.ToListAsync();
|
||||
}
|
||||
|
||||
//[HttpPut("{trialId:guid}/{isReplaceUser:bool}")]
|
||||
//public async Task<IResponseOutput> CopyTrialSurveyInitInfo(CopyTrialSiteSurveyDTO copyDto, bool isReplaceUser)
|
||||
//{
|
||||
// var survey = await _repository.Where<TrialSiteSurvey>(t => t.Id == copyDto.TrialSiteSurveyId).FirstOrDefaultAsync();
|
||||
|
||||
// if (survey == null) return Null404NotFound(survey);
|
||||
|
||||
// survey.Id = Guid.Empty;
|
||||
// if (isReplaceUser)
|
||||
// {
|
||||
// survey.UserName = copyDto.UserName;
|
||||
// survey.Email = copyDto.Email;
|
||||
// survey.Phone = copyDto.Phone;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
// return ResponseOutput.Ok();
|
||||
//}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始登陆界面 项目基本信息+下拉框数据
|
||||
/// </summary>
|
||||
/// <param name="trialId"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("{trialId:guid}")]
|
||||
public async Task<TrialSurveyInitInfo> GetTrialSurveyInitInfo(Guid trialId)
|
||||
{
|
||||
var info = await _repository.Where<Trial>(t => t.Id == trialId).ProjectTo<TrialSurveyInitInfo>(_mapper.ConfigurationProvider).FirstOrDefaultAsync().IfNullThrowException();
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 驳回
|
||||
/// </summary>
|
||||
/// <param name="trialId"></param>
|
||||
/// <param name="trialSiteSurveyId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{trialId:guid}/{trialSiteSurveyId:guid}")]
|
||||
public async Task<IResponseOutput> SubmissionRejection(Guid trialId, Guid trialSiteSurveyId)
|
||||
{
|
||||
if (await _repository.AnyAsync<TrialSiteSurvey>(t => t.State == TrialSiteSurveyEnum.PMCreatedAndLock && t.Id == trialSiteSurveyId))
|
||||
{
|
||||
return ResponseOutput.NotOk("已锁定,不允许操作");
|
||||
}
|
||||
|
||||
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM)
|
||||
{
|
||||
await _repository.UpdateFromQueryAsync<TrialSiteSurvey>(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.ToSubmit });
|
||||
}
|
||||
else if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM)
|
||||
{
|
||||
var hasSPMOrCPM = await _trialSiteSurveyRepository.AnyAsync(t => t.TrialId == trialId && t.Trial.TrialUserList.Any(u => u.User.UserTypeEnum == UserTypeEnum.SPM || u.User.UserTypeEnum == UserTypeEnum.CPM));
|
||||
|
||||
if (hasSPMOrCPM)
|
||||
{
|
||||
await _trialSiteSurveyRepository.UpdateFromQueryAsync(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.CRCSubmitted });
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
await _trialSiteSurveyRepository.UpdateFromQueryAsync(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.ToSubmit });
|
||||
}
|
||||
}
|
||||
return ResponseOutput.Ok();
|
||||
|
||||
}
|
||||
|
||||
|
||||
[HttpPut("{trialId:guid}/{trialSiteSurveyId:guid}")]
|
||||
public async Task<IResponseOutput> AbandonSiteSurvey(Guid trialSiteSurveyId)
|
||||
{
|
||||
var survey = (await _trialSiteSurveyRepository.FirstOrDefaultAsync(t => t.Id == trialSiteSurveyId)).IfNullThrowConvertException();
|
||||
|
||||
if (survey.State != TrialSiteSurveyEnum.ToSubmit)
|
||||
{
|
||||
return ResponseOutput.NotOk("只允许废除未提交的记录");
|
||||
}
|
||||
|
||||
survey.IsAbandon = true;
|
||||
|
||||
await _repository.SaveChangesAsync();
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 提交 后台自动识别是谁提交
|
||||
/// </summary>
|
||||
/// <param name="siteSurvyeSubmit"></param>
|
||||
/// <returns></returns>
|
||||
//[TypeFilter(typeof(TrialResourceFilter))]
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput> TrialSurveySubmit(TrialSiteSurvyeSubmitDTO siteSurvyeSubmit)
|
||||
{
|
||||
|
||||
var trialId= siteSurvyeSubmit.TrialId;
|
||||
var trialSiteSurveyId = siteSurvyeSubmit.TrialSiteSurveyId;
|
||||
|
||||
if (_userInfo.IsAdmin)
|
||||
{
|
||||
return ResponseOutput.NotOk("不允许Admin操作");
|
||||
}
|
||||
|
||||
|
||||
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.Undefined)
|
||||
{
|
||||
var hasSPMOrCPM = await _trialSiteSurveyRepository.AnyAsync(t => t.TrialId == trialId && t.Trial.TrialUserList.Any(u => u.User.UserTypeEnum == UserTypeEnum.SPM || u.User.UserTypeEnum == UserTypeEnum.CPM));
|
||||
|
||||
if (hasSPMOrCPM)
|
||||
{
|
||||
await _trialSiteSurveyRepository.UpdateFromQueryAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.ToSubmit, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.CRCSubmitted });
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
await _trialSiteSurveyRepository.UpdateFromQueryAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.ToSubmit, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.SPMApproved });
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM)
|
||||
{
|
||||
if (_repository.Where<TrialSiteUserSurvey>(t => t.TrialSiteSurveyId == trialSiteSurveyId && t.IsCorrect == false).Any())
|
||||
{
|
||||
return ResponseOutput.NotOk("人员信息有不正确项,不允许提交");
|
||||
}
|
||||
|
||||
await _trialSiteSurveyRepository.UpdateFromQueryAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.CRCSubmitted, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.SPMApproved });
|
||||
|
||||
}
|
||||
else if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager)
|
||||
{
|
||||
|
||||
var trialSiteSurvey = _trialSiteSurveyRepository.Where(t => t.Id == trialSiteSurveyId).FirstOrDefault();
|
||||
|
||||
if (trialSiteSurvey == null) return Null404NotFound(trialSiteSurvey);
|
||||
|
||||
if (_trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId && t.IsCorrect == false).Any())
|
||||
{
|
||||
return ResponseOutput.NotOk("人员信息有不正确项,不允许提交");
|
||||
}
|
||||
|
||||
//已生成的不管 管的只需要是 生成失败的并且需要生成账号的
|
||||
var needGenerateList = _trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId && t.IsCorrect && t.IsGenerateAccount && t.IsGenerateSuccess == false).ToList();
|
||||
|
||||
|
||||
var trialInfo = await _repository.FirstOrDefaultAsync<Trial>(t => t.Id == trialId);
|
||||
|
||||
foreach (var item in needGenerateList)
|
||||
{
|
||||
|
||||
var messageToSend = new MimeMessage();
|
||||
//发件地址
|
||||
messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com"));
|
||||
//收件地址
|
||||
messageToSend.To.Add(new MailboxAddress(String.Empty, item.Email));
|
||||
//主题
|
||||
messageToSend.Subject = "GRR Site survey (Trial Notice)";
|
||||
|
||||
var builder = new BodyBuilder();
|
||||
|
||||
//找下系统中是否存在该用户类型的 并且邮箱 或者手机的账户
|
||||
var sysUserInfo = await _userRepository.Where(t => t.UserTypeId == item.UserTypeId && t.EMail == item.Email ).Include(t=>t.UserTypeRole).FirstOrDefaultAsync();
|
||||
|
||||
int verificationCode = new Random().Next(100000, 1000000);
|
||||
|
||||
//var baseApiUrl = baseUrl.Remove(baseUrl.IndexOf("#")) + "api";
|
||||
|
||||
|
||||
if (sysUserInfo==null)
|
||||
{
|
||||
|
||||
lock (lockObj)
|
||||
{
|
||||
var saveItem = _mapper.Map<User>(item);
|
||||
|
||||
saveItem.Code = _userRepository.Select(t => t.Code).DefaultIfEmpty().Max() + 1;
|
||||
|
||||
saveItem.UserCode = AppSettings.UserCodePrefix + saveItem.Code.ToString("D4");
|
||||
|
||||
saveItem.UserName = saveItem.UserCode;
|
||||
|
||||
saveItem.UserTypeEnum = _repository.Where<UserType>(t => t.Id == saveItem.UserTypeId).Select(t => t.UserTypeEnum).First();
|
||||
|
||||
saveItem.Password = MD5Helper.Md5(verificationCode.ToString());
|
||||
|
||||
_ = _repository.AddAsync(saveItem).Result;
|
||||
|
||||
_ = _repository.SaveChangesAsync().Result;
|
||||
|
||||
|
||||
sysUserInfo = saveItem;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (sysUserInfo.IsFirstAdd)
|
||||
{
|
||||
await _userRepository.UpdateFromQueryAsync(t => t.Id == sysUserInfo.Id,
|
||||
u => new User() { Password = MD5Helper.Md5(verificationCode.ToString()) });
|
||||
}
|
||||
|
||||
|
||||
builder.HtmlBody = @$"<body style='font-family: 微软雅黑;padding: 0;margin: 0;'>
|
||||
<div style='padding-left: 40px;background: #f6f6f6'>
|
||||
<div style='padding-top: 20px;'>
|
||||
<div style='line-height: 40px;font-size: 18px'>
|
||||
{sysUserInfo.LastName + "/" + sysUserInfo.FirstName}:
|
||||
</div>
|
||||
<div style='line-height: 40px;padding-left: 40px;margin-bottom: 10px;'>
|
||||
您参与的临床试验项目 {trialInfo.ExperimentName} ,独立影像评估相关工作将在网上进行。项目及账号信息为:
|
||||
</div>
|
||||
<div style='border: 1px solid #eee;box-sizing:border-box;width: 80%;background: #fff;padding: 20px;line-height: 40px;font-size: 14px;border-radius: 5px;margin-left: 60px;margin-bottom: 30px;'>
|
||||
<div>
|
||||
项目编号: {trialInfo.TrialCode}
|
||||
</div>
|
||||
<div>
|
||||
试验方案号: {trialInfo.ResearchProgramNo}
|
||||
</div>
|
||||
<div>
|
||||
试验名称: {trialInfo.ExperimentName}
|
||||
</div>
|
||||
<div>
|
||||
用户名: {sysUserInfo.UserName}
|
||||
</div>
|
||||
<div>
|
||||
密码: {(sysUserInfo.IsFirstAdd ? verificationCode.ToString() + "(请在登录后进行修改)" : "***(您已有账号, 若忘记密码, 请通过邮箱找回)")}
|
||||
</div>
|
||||
<div>
|
||||
角色: {sysUserInfo.UserTypeRole.UserTypeShortName}
|
||||
</div>
|
||||
<div>
|
||||
系统登录地址: {siteSurvyeSubmit.LoginUrl} (请确认加入后再登陆)
|
||||
</div>
|
||||
</div>
|
||||
<a href='{siteSurvyeSubmit.RouteUrl + "?Id="+item.Id+ "&IsExternalUser=0"}' style='margin-left:60px;font-size:14px;text-decoration: none;display: inline-block;height: 40px;width: 140px;background: #00D1B2;color:#fff;border-radius: 5px;line-height: 40px;text-align: center;margin-bottom: 100px;'>
|
||||
查看并确认
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>";
|
||||
|
||||
|
||||
messageToSend.Body = builder.ToMessageBody();
|
||||
|
||||
using (var smtp = new MailKit.Net.Smtp.SmtpClient())
|
||||
{
|
||||
|
||||
smtp.ServerCertificateValidationCallback = (s, c, h, e) => true;
|
||||
|
||||
smtp.MessageSent += (sender, args) =>
|
||||
{
|
||||
|
||||
_= _trialSiteUserSurveyRepository.UpdateFromQueryAsync(t => t.Id == item.Id, u => new TrialSiteUserSurvey() { IsGenerateSuccess = true, SystemUserId = sysUserInfo.Id , ExpireTime = DateTime.Now.AddDays(7) }).Result;
|
||||
|
||||
};
|
||||
|
||||
|
||||
await smtp.ConnectAsync("smtp.163.com", 25, SecureSocketOptions.StartTls);
|
||||
|
||||
|
||||
await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH");
|
||||
|
||||
|
||||
await smtp.SendAsync(messageToSend);
|
||||
|
||||
|
||||
await smtp.DisconnectAsync(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
await _trialSiteSurveyRepository.UpdateFromQueryAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.SPMApproved, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.PMCreatedAndLock });
|
||||
|
||||
}
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// 锁定
|
||||
///// </summary>
|
||||
///// <param name="trialSiteSurveyId"></param>
|
||||
///// <param name="isLock"></param>
|
||||
///// <returns></returns>
|
||||
//[TypeFilter(typeof(TrialResourceFilter))]
|
||||
//[HttpPost("{trialSiteSurveyId:guid}/{trialId:guid}/{isLock:bool}")]
|
||||
//public async Task<IResponseOutput> TrialSurveyLock(Guid trialSiteSurveyId, bool isLock)
|
||||
//{
|
||||
// if (await _repository.Where<TrialSiteSurvey>(t => t.Id == trialSiteSurveyId).AnyAsync(t => t.TrialSiteUserSurveyList.Any(k => k.IsGenerateAccount && k.IsGenerateSuccess == false)))
|
||||
// {
|
||||
// ResponseOutput.NotOk("有用户账户没生成,不允许锁定");
|
||||
// }
|
||||
|
||||
// await _repository.UpdateFromQueryAsync<TrialSiteSurvey>(t => t.Id == trialSiteSurveyId, k => new TrialSiteSurvey() { State==TrialSiteSurveyEnum.PMCreatedAndLock });
|
||||
|
||||
// return ResponseOutput.Ok();
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
//--------------------------------------------------------------------
|
||||
// 此代码由T4模板自动生成 byzhouhang 20210918
|
||||
// 生成时间 2021-12-23 13:20:59
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||
//--------------------------------------------------------------------
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using IRaCIS.Core.Application.Filter;
|
||||
using IRaCIS.Core.Infra.EFCore;
|
||||
using IRaCIS.Core.Infrastructure;
|
||||
|
||||
namespace IRaCIS.Core.Application.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// TrialSiteUserSurveyService
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "Trial")]
|
||||
public class TrialSiteUserSurveyService : BaseService, ITrialSiteUserSurveyService
|
||||
{
|
||||
private readonly IRepository<TrialSiteUserSurvey> _trialSiteUserSurveyRepository;
|
||||
|
||||
public TrialSiteUserSurveyService(IRepository<TrialSiteUserSurvey> trialSiteUserSurveyRepository)
|
||||
{
|
||||
_trialSiteUserSurveyRepository = trialSiteUserSurveyRepository;
|
||||
}
|
||||
|
||||
[HttpGet("{trialSiteSurveyId:guid}")]
|
||||
public async Task<List<TrialSiteUserSurveyView>> GetTrialSiteUserSurveyList(Guid trialSiteSurveyId)
|
||||
{
|
||||
|
||||
var trialSiteUserSurveyQueryable = _trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId)
|
||||
//.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM, t => t.TrialSiteSurvey.State >= TrialSiteSurveyEnum.CRCSubmitted)
|
||||
//.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM|| _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM, t => t.TrialSiteSurvey.State >= TrialSiteSurveyEnum.SPMApproved)
|
||||
.ProjectTo<TrialSiteUserSurveyView>(_mapper.ConfigurationProvider);
|
||||
|
||||
return await trialSiteUserSurveyQueryable.ToListAsync();
|
||||
}
|
||||
|
||||
[TypeFilter(typeof(TrialResourceFilter))]
|
||||
[HttpPost("{trialId:guid}")]
|
||||
public async Task<IResponseOutput> AddOrUpdateTrialSiteUserSurvey(TrialSiteUserSurveyAddOrEdit addOrEditTrialSiteUserSurvey)
|
||||
{
|
||||
|
||||
|
||||
if (await _trialSiteUserSurveyRepository.Where(t => t.Id == addOrEditTrialSiteUserSurvey.Id).AnyAsync(t => t.TrialSiteSurvey.State == TrialSiteSurveyEnum.PMCreatedAndLock))
|
||||
{
|
||||
return ResponseOutput.NotOk("已锁定,不允许操作");
|
||||
}
|
||||
|
||||
if (addOrEditTrialSiteUserSurvey.UserTypeId != null && ( _userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM))
|
||||
{
|
||||
var existSysUser = await _repository.FirstOrDefaultAsync<User>(t => t.EMail == addOrEditTrialSiteUserSurvey.Email && t.UserTypeId == addOrEditTrialSiteUserSurvey.UserTypeId);
|
||||
|
||||
|
||||
if (existSysUser != null)
|
||||
{
|
||||
if (existSysUser.LastName != addOrEditTrialSiteUserSurvey.LastName || existSysUser.FirstName != addOrEditTrialSiteUserSurvey.FirstName)
|
||||
{
|
||||
return ResponseOutput.NotOk($"该用户在系统中账户名为:{existSysUser.LastName + " / " + existSysUser.FirstName} ,与填写信息存在不一致项, 现将界面信息修改为与系统一致,可进行保存",
|
||||
new { existSysUser.LastName, existSysUser.FirstName, existSysUser.Phone }, ApiResponseCodeEnum.NeedTips);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var entity = await _trialSiteUserSurveyRepository.InsertOrUpdateAsync(addOrEditTrialSiteUserSurvey, true);
|
||||
|
||||
return ResponseOutput.Ok(entity.Id.ToString());
|
||||
|
||||
}
|
||||
|
||||
[TypeFilter(typeof(TrialResourceFilter))]
|
||||
[HttpDelete("{trialSiteUserSurveyId:guid}/{trialId:guid}")]
|
||||
public async Task<IResponseOutput> DeleteTrialSiteUserSurvey(Guid trialSiteUserSurveyId)
|
||||
{
|
||||
|
||||
|
||||
if (await _trialSiteUserSurveyRepository.Where(t => t.Id == trialSiteUserSurveyId).AnyAsync(t => t.TrialSiteSurvey.State == TrialSiteSurveyEnum.PMCreatedAndLock))
|
||||
{
|
||||
return ResponseOutput.NotOk("已锁定,不允许操作");
|
||||
}
|
||||
|
||||
var success = await _trialSiteUserSurveyRepository.DeleteFromQueryAsync(t => t.Id == trialSiteUserSurveyId);
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using AutoMapper;
|
||||
using IRaCIS.Core.Application.Contracts;
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
|
||||
namespace IRaCIS.Core.Application.AutoMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// 映射配置
|
||||
/// </summary>
|
||||
public partial class SiteSurveyConfig : Profile
|
||||
{
|
||||
public SiteSurveyConfig()
|
||||
{
|
||||
//编辑
|
||||
CreateMap<TrialSiteSurvey, TrialSiteSurveyAddOrEdit>().ReverseMap();
|
||||
|
||||
CreateMap<TrialSiteEquipmentSurveyAddOrEdit, TrialSiteEquipmentSurvey>().ReverseMap();
|
||||
|
||||
CreateMap<TrialSiteUserSurveyAddOrEdit, TrialSiteUserSurvey>().ReverseMap();
|
||||
|
||||
CreateMap<LoginDto, TrialSiteSurvey>().ForMember(d => d.Email, t => t.MapFrom(t => t.EmailOrPhone));
|
||||
|
||||
|
||||
//列表
|
||||
CreateMap<TrialSiteEquipmentSurvey, TrialSiteEquipmentSurveyView>()
|
||||
.ForMember(t=>t.EquipmentType,u=>u.MapFrom(d=>d.EquipmentType.Value));
|
||||
|
||||
|
||||
|
||||
CreateMap<TrialSiteSurvey, TrialSiteSurveyView>()
|
||||
.ForMember(d => d.TrialSiteAliasName, u => u.MapFrom(s => s.TrialSite.TrialSiteAliasName))
|
||||
.ForMember(d => d.SiteName, u => u.MapFrom(s => s.Site.SiteName))
|
||||
.ForMember(d => d.TrialSiteCode, u => u.MapFrom(s => s.TrialSite.TrialSiteCode));
|
||||
|
||||
CreateMap<TrialSiteUserSurvey, TrialSiteUserSurveyView>()
|
||||
.ForMember(t => t.TrialRoleName, u => u.MapFrom(d => d.TrialRoleName.Value))
|
||||
.ForMember(d => d.UserType, u => u.MapFrom(s => s.UserTypeRole.UserTypeShortName));
|
||||
|
||||
|
||||
CreateMap<Trial, TrialSurveyInitInfo>()
|
||||
.ForMember(d => d.Sponsor, u => u.MapFrom(s => s.Sponsor.SponsorName))
|
||||
.ForMember(d => d.IndicationType, u => u.MapFrom(s => s.IndicationType.Value))
|
||||
.ForMember(d => d.TrialSiteSelectList, u => u.MapFrom(s => s.TrialSiteList))
|
||||
.ForMember(d => d.TrialId, u => u.MapFrom(s => s.Id));
|
||||
|
||||
CreateMap<TrialSite, TrialSiteForSelect>();
|
||||
|
||||
CreateMap<TrialSiteSurvey, LoginReturnDTO>()
|
||||
.ForMember(d => d.TrialSiteSurvey, u => u.MapFrom(s => s))
|
||||
.ForMember(d => d.TrialInfo, u => u.MapFrom(s => s.Trial))
|
||||
.ForMember(d => d.TrialSiteUserSurveyList, u => u.MapFrom(s => s.TrialSiteUserSurveyList));
|
||||
|
||||
|
||||
|
||||
|
||||
CreateMap<TrialSiteUserSurvey, User>();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user