using IRaCIS.Application.Interfaces;
using IRaCIS.Application.ViewModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using IRaCIS.Core.Application.Contracts.RequestAndResponse;
namespace IRaCIS.Api.Controllers
{
///
/// Financial 支撑信息---项目费用
///
[Route("trialPaymentPrice")]
[ApiController, Authorize, ApiExplorerSettings(GroupName = "Financial")]
public class TrialPaymentPriceController : ControllerBase
{
private readonly ITrialPaymentPriceService _trialPaymentPriceService;
private readonly ICalculateService _calculateService;
private readonly ITrialService _trialService;
public TrialPaymentPriceController(ITrialPaymentPriceService trialPaymentPriceService,
ICalculateService calculateService,
ITrialService trialService)
{
_trialPaymentPriceService = trialPaymentPriceService;
_calculateService = calculateService;
_trialService = trialService;
}
///
/// 保存(替换)项目支付价格信息(会触发没有被锁定的费用计算)[AUTH]
///
[HttpPost, Route("addOrUpdateTrialPaymentPrice")]
public IResponseOutput AddOrUpdateTrialPaymentPrice(TrialPaymentPriceCommand addOrUpdateModel)
{
var userId = Guid.Parse(User.FindFirst("id").Value);
var result = _trialPaymentPriceService.AddOrUpdateTrialPaymentPrice(addOrUpdateModel, userId);
var needCalReviewerIds = _trialService.GetTrialEnrollmentReviewerIds(addOrUpdateModel.TrialId);
var calcList = _calculateService.GetNeedCalculateReviewerList(Guid.Empty, string.Empty);
foreach (var item in calcList)
{
if (item != null && needCalReviewerIds.Contains(item.DoctorId))
{
_calculateService.CalculateMonthlyPayment(new CalculateDoctorAndMonthDTO()
{
NeedCalculateReviewers = new List()
{
item.DoctorId
},
CalculateMonth = DateTime.Parse(item.YearMonth)
}, User.FindFirst("id").Value);
}
}
return result;
}
///
/// 更新项目SOW 协议 [AUTH]
///
///
///
[HttpPost, Route("uploadTrialSOW")]
public IResponseOutput UploadTrialSOW(TrialSOWPathDTO trialSowPath)
{
var userId = Guid.Parse(User.FindFirst("id").Value);
return _trialPaymentPriceService.UploadTrialSOW(userId, trialSowPath);
}
///
///删除项目SOW [AUTH]
///
///
///
[HttpPost, Route("deleteTrialSOW")]
public IResponseOutput DeleteTrialSOW(DeleteSowPathDTO trialSowPath)
{
var userId = Guid.Parse(User.FindFirst("id").Value);
return _trialPaymentPriceService.DeleteTrialSOW(userId, trialSowPath);
}
///
/// 获取项目支付价格信息列表
///
[HttpPost, Route("getTrialPaymentPriceList")]
public IResponseOutput> GetTrialPaymentPriceList(TrialPaymentPriceQueryDTO queryParam)
{
return ResponseOutput.Ok(_trialPaymentPriceService.GetTrialPaymentPriceList(queryParam)) ;
}
}
}