101 lines
3.4 KiB
C#
101 lines
3.4 KiB
C#
using IRaCIS.Core.Application.Contracts.Dicom.DTO;
|
|
using IRaCIS.Application.Contracts;
|
|
using IRaCIS.Core.Domain.Share;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using IRaCIS.Core.Application.Auth;
|
|
|
|
namespace IRaCIS.Core.Application.Services
|
|
{
|
|
[AllowAnonymous, ApiExplorerSettings(GroupName = "Image")]
|
|
public class ImageShareService : BaseService, IImageShareService
|
|
{
|
|
|
|
private readonly IRepository<ImageShare> _imageShareRepository;
|
|
private readonly IRepository<DicomStudy> _studyRepository;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly ITokenService _tokenService;
|
|
|
|
public ImageShareService(IRepository<ImageShare> imageShareRepository, IRepository<DicomStudy> studyRepository, IConfiguration configuration, ITokenService tokenService)
|
|
{
|
|
|
|
_imageShareRepository = imageShareRepository;
|
|
_studyRepository = studyRepository;
|
|
_configuration = configuration;
|
|
_tokenService = tokenService;
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IResponseOutput> CreateImageShare(ImageShareCommand imageShareCommand)
|
|
{
|
|
|
|
var imageShare = _mapper.Map<ImageShare>(imageShareCommand);
|
|
|
|
var addEntity = await _imageShareRepository.AddAsync(imageShare);
|
|
|
|
|
|
//验证码 4位
|
|
int verificationPassWord = new Random().Next(1000, 10000);
|
|
|
|
addEntity.Password = verificationPassWord.ToString();
|
|
|
|
//配置文件读取过期时间
|
|
|
|
var days = AppSettings.ImageShareExpireDays;
|
|
|
|
|
|
addEntity.ExpireTime = DateTime.Now.AddDays(days);
|
|
|
|
var success = await _imageShareRepository.SaveChangesAsync();
|
|
|
|
return ResponseOutput.Result(success, new { ResourceId = imageShare.Id, Password = verificationPassWord.ToString() });
|
|
|
|
|
|
}
|
|
|
|
[HttpGet, Route("{resourceId:guid}/{password}")]
|
|
public async Task<IResponseOutput> VerifyShareImage(Guid resourceId, string password)
|
|
{
|
|
var pWord = password.Trim();
|
|
var imageShare = await _imageShareRepository.FirstOrDefaultAsync(t => t.Id == resourceId);
|
|
|
|
if (imageShare == null)
|
|
{
|
|
return ResponseOutput.NotOk("资源不存在。");
|
|
}
|
|
|
|
if (pWord != imageShare.Password.Trim())
|
|
{
|
|
return ResponseOutput.NotOk("分享密码错误。");
|
|
}
|
|
|
|
if (DateTime.Now > imageShare.ExpireTime)
|
|
{
|
|
return ResponseOutput.NotOk("资源分享过期。");
|
|
}
|
|
|
|
var resource = new ResourceInfo()
|
|
{
|
|
VisitTaskId = imageShare.VisitTaskId,
|
|
RouteUrl=imageShare.RouteUrl,
|
|
Token = _tokenService.GetToken(IRaCISClaims.Create(new UserBasicInfo()
|
|
{
|
|
Id = Guid.Empty,
|
|
IsReviewer = false,
|
|
IsAdmin = false,
|
|
RealName = "Share001",
|
|
UserName = "Share001",
|
|
Sex = 0,
|
|
//UserType = "ShareType",
|
|
UserTypeEnum = UserTypeEnum.ShareImage,
|
|
Code = "ShareCode001",
|
|
}))
|
|
};
|
|
|
|
|
|
return ResponseOutput.Ok(resource);
|
|
|
|
}
|
|
}
|
|
} |