114 lines
3.3 KiB
C#
114 lines
3.3 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using AutoMapper;
|
|
using IRaCIS.Core.Application.Contracts;
|
|
using IRaCIS.Core.Domain.Models;
|
|
using IRaCIS.Core.Domain.Share;
|
|
using IRaCIS.Core.Infra.EFCore;
|
|
using IRaCIS.Core.Infrastructure.Extention;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace IRaCIS.Core.API.Controllers
|
|
{
|
|
|
|
[ApiController, ApiExplorerSettings(GroupName = "Reviewer")]
|
|
public class InspectionController : ControllerBase
|
|
{
|
|
private readonly IRepository _repository;
|
|
private readonly IMapper _mapper;
|
|
private readonly IUserInfo _userInfo;
|
|
|
|
public InspectionController(IRepository repository, IMapper mapper, IUserInfo userInfo)
|
|
{
|
|
_repository = repository;
|
|
_mapper = mapper;
|
|
_userInfo = userInfo;
|
|
}
|
|
|
|
[HttpPost, Route("trialDocument/userConfirm")]
|
|
public async Task<IResponseOutput> UserConfirm(TrialDocumentConfirmDTO opt, [FromServices] ITrialDocumentService _trialDocumentService)
|
|
{
|
|
var verifyResult = await VerifySignatureAsync(opt.SignInfo);
|
|
|
|
if (verifyResult.IsSuccess == false)
|
|
{
|
|
return verifyResult;
|
|
}
|
|
|
|
var bResult = await _trialDocumentService.UserConfirm(opt.OptCommand);
|
|
|
|
if (bResult.IsSuccess == false)
|
|
{
|
|
return bResult;
|
|
}
|
|
|
|
//SiteId SubjectId SubjectVisitId TrialId 最开始没有 需要特殊处理
|
|
//表冗余字段 前端只传递一次的话 后台模型就需要单独处理
|
|
|
|
|
|
if (opt.AuditInfo.IsSign)
|
|
{
|
|
var signId = await AddSignRecordAsync(opt.SignInfo);
|
|
|
|
await AddInspectionRecordAsync(opt.AuditInfo, signId);
|
|
}
|
|
else
|
|
{
|
|
await AddInspectionRecordAsync(opt.AuditInfo, null);
|
|
}
|
|
|
|
return bResult;
|
|
}
|
|
|
|
|
|
|
|
/// <summary> 验证用户签名信息 </summary> ///
|
|
private 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> ///
|
|
private 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> ///
|
|
private async Task AddInspectionRecordAsync(DataInspectionAddDTO addDto, Guid? signId)
|
|
{
|
|
|
|
var add = await _repository.AddAsync(_mapper.Map<DataInspection>(addDto));
|
|
|
|
add.SignId = signId;
|
|
add.IP = _userInfo.IP;
|
|
|
|
var success = await _repository.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|