package com.ruoyi.oa.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.oa.service.IExchangeRateService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;

@RestController
@Validated
@RequiredArgsConstructor
@RequestMapping("/oa/exchangeRate")
public class OaExchangeRateController extends BaseController {
    private final IExchangeRateService oaExchangeRateService;

    /**
     * 获取指定日期的美元兑人民币汇率
     */
    @GetMapping("/usd2cny")
    public BigDecimal getUsd2CnyRate(@RequestParam(required = false) Date date) {
        if (date == null) {
            date = new Date();
        }
        return oaExchangeRateService.getUsdExchangeRate(date);
    }
}