using IRaCIS.Api.Filter;
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.Pay
{
///
/// Financial 支撑信息---汇率
///
[Route("exchangeRate")]
[ApiController, Authorize, ApiExplorerSettings(GroupName = "Financial")]
public class ExchangeRateController : ControllerBase
{
private readonly IExchangeRateService _exchangeRateService;
private readonly ICalculateService _calculateService;
private readonly IPaymentAdjustmentService _costAdjustmentService;
public ExchangeRateController(IExchangeRateService exchangeRateService,
ICalculateService calculateService,
IPaymentAdjustmentService costAdjustmentService)
{
_exchangeRateService = exchangeRateService;
_calculateService = calculateService;
_costAdjustmentService = costAdjustmentService;
}
///
/// 添加或更新汇率(会触发没有对锁定的费用计算)
///
[LogFilter]
[HttpPost, Route("addOrUpdateExchangeRate")]
public IResponseOutput AddOrUpdateExchangeRate(ExchangeRateCommand addOrUpdateModel)
{
var result = _exchangeRateService.AddOrUpdateExchangeRate(addOrUpdateModel);
var calcList = _calculateService.GetNeedCalculateReviewerList(Guid.Empty, addOrUpdateModel.YearMonth);
foreach (var item in calcList)
{
if (item != null)
{
_calculateService.CalculateMonthlyPayment(new CalculateDoctorAndMonthDTO()
{
NeedCalculateReviewers = new List()
{
item.DoctorId
},
CalculateMonth = DateTime.Parse(item.YearMonth)
}, User.FindFirst("id").Value);
}
}
_costAdjustmentService.CalculateCNY(addOrUpdateModel.YearMonth,addOrUpdateModel.Rate);
return result;
}
///
/// 分页获取汇率列表
///
[HttpPost, Route("getRateList")]
public IResponseOutput> GetAwardPriceList(ExchangeRateQueryDTO queryParam)
{
return ResponseOutput.Ok(_exchangeRateService.GetExchangeRateList(queryParam));
}
///
/// 根据记录Id,删除汇率记录
///
/// 汇率记录Id
[HttpDelete, Route("deleteExchangeRate/{id:guid}")]
public IResponseOutput DeleteExchangeRate(Guid id)
{
return _exchangeRateService.DeleteExchangeRate(id);
}
}
}