package com.yh.saas.plugin.news.controller;

import com.yh.saas.plugin.news.entity.ExchangeRate;
import com.yh.saas.plugin.news.entity.view.ExchangeRateView;
import com.yh.saas.plugin.news.service.IExchangeRateService;
import com.yh.saas.common.support.plugin.PluginFeature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

    /**
     * <p>
     * 记录汇率库信息 前端控制器
     * </p>
     *
     * @author zhaojz
     * @since 2019-11-26
     */
    @PluginFeature(id = "newsExchangeRate", name = "汇率库")
    @RestController
    @RequestMapping("/newsExchangeRate")
    public class NewsExchangeRateController {

        @Autowired
        private IExchangeRateService exchangeRateService;

        /**
         * 根据币种和年月查询汇率
         *
         * @param currencyKey
         * @param yearMonth
         * @return
         */
        @GetMapping("/query/getExchangeRate")
        public Double getExchangeRate(@RequestParam String currencyKey, @RequestParam String yearMonth) {
            return exchangeRateService.getExchangeRate(currencyKey, yearMonth);
        }

        /**
         * 查询汇率信息
         *
         * @param example
         * @return
         */
        @PluginFeature(id = "FinanceExchangeRate-View", name = "查看")
        @GetMapping("/query/getListByCondition")
        public List<ExchangeRate> getListByCondition(ExchangeRate example) {
            return exchangeRateService.getListByCondition(example);
        }

        /**
         * 保存汇率信息
         *
         * @param rateViewList
         */
        @PluginFeature(id = "FinanceExchangeRate-Manage", name = "设定")
        @PostMapping("/api/saveRate")
        public void saveRate(@RequestBody List<ExchangeRateView> rateViewList) {
            exchangeRateService.saveRate(rateViewList);
        }
}
