package com.jxy.marketall.controller;

import com.jxy.common.core.utils.StringUtils;
import com.jxy.common.core.web.Result.AjaxResult;
import com.jxy.common.security.annotation.RequiresLogin;
import com.jxy.marketall.mapper.BiAnMapper2;
import com.jxy.marketall.service.MacroEconomyService;
import com.jxy.marketall.service.NDAQService;
import com.jxy.marketall.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 统一请求接口
 * @Date 2022/5/27 9:54
 * @Author 杜懿
 */
@RestController
@RequestMapping("/market")
@Api(tags = "宏观经济接口")
public class MarketController {

    @Autowired
    private NDAQService ndaqService;

    @Autowired
    private BiAnMapper2 biAnMapper2;

    @Autowired
    private MacroEconomyService macroEconomyService;


    @GetMapping("/NDAQohlc")
    @ApiOperation(value = "纳斯达克 IXIC：ohlc数据",response = List.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "start", value = "开始时间", dataType = "string", paramType = "query", required = false),
            @ApiImplicitParam(name = "end", value = "结束时间", dataType = "string", paramType = "query", required = false)})
    public AjaxResult NDAQohlc(QueryVo vo){

        return  ndaqService.findOHLCByTime(vo);

    }

    @GetMapping("/NDAQma")
    @ApiOperation(value = "纳斯达克 IXIC：ma数据",response = List.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "start", value = "开始时间", dataType = "string", paramType = "query", required = false),
            @ApiImplicitParam(name = "end", value = "结束时间", dataType = "string", paramType = "query", required = false)})
    public AjaxResult NDAQma(QueryVo vo){

        return  ndaqService.findMaByTime(vo);

    }

    @GetMapping("/NDAQBTCPrice")
    @ApiOperation(value = "NDAQ、BTC对比K线 以NDAQ时间线为主",response = List.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "start", value = "开始时间", dataType = "string", paramType = "query", required = false),
            @ApiImplicitParam(name = "end", value = "结束时间", dataType = "string", paramType = "query", required = false)})
    //@RequiresLogin
    public AjaxResult NBPriceByNDAQTime(QueryVo vo){

        return  ndaqService.getNBPriceByNDAQTime(vo);

    }

    @GetMapping("/BTCNDAQPrice")
    @ApiOperation(value = "NDAQ、BTC对比K线 以BTC币价时间线为主",response = List.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "start", value = "开始时间", dataType = "string", paramType = "query", required = false),
            @ApiImplicitParam(name = "end", value = "结束时间", dataType = "string", paramType = "query", required = false)})
    //@RequiresLogin
    public AjaxResult NBPriceByBTCTime(QueryVo vo){

        return  ndaqService.getNBPriceByBTCTime(vo);

    }

    @PostMapping("/USTreasuriesYields")
    @ApiOperation(value = "国债收益率(美国) 条件查询",response = List.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "timeInterval", value = "时间间隔 单位分钟min、小时h、天d、月M，严格区分大小写", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "start", value = "开始时间  可以只传开始时间，表示查询大于这个时间的值", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "end", value = "结束时间 可以只传开始时间，表示查询大于这个时间的值", dataType = "string", paramType = "query")})
    //@RequiresLogin
    public AjaxResult USTreasuriesYields(@RequestBody() TreasuriesYieldsVo vo){

        return  macroEconomyService.getTreasuriesYields(vo);
    }

    @PostMapping("/MoneyStockMeasures")
    @ApiOperation(value = "货币供应量 条件查询",response = List.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ifAdjusted", value = "是否季节性调整", dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "start", value = "开始时间  可以只传开始时间，表示查询大于这个时间的值", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "end", value = "结束时间 可以只传开始时间，表示查询大于这个时间的值", dataType = "string", paramType = "query")})
    //@RequiresLogin
    public AjaxResult MoneyStockMeasures(@RequestBody() MoneyStockMeasuresVo vo){

        return  macroEconomyService.getMoneyStockMeasures(vo);
    }

    @PostMapping("/loan/psi")
    @ApiOperation(value = "私营部门贷款",response = List.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "start", value = "开始时间  可以只传开始时间，表示查询大于这个时间的值", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "end", value = "结束时间 可以只传开始时间，表示查询大于这个时间的值", dataType = "string", paramType = "query")})
    //@RequiresLogin
    public AjaxResult LoanPSI(@RequestBody(required = false) QueryVo vo){
        if(StringUtils.isNull(vo)){
            vo = new QueryVo();
        }
        return  macroEconomyService.getPSI(vo);
    }

    @PostMapping("/loan/gdp")
    @ApiOperation(value = "私人债务占GDP比重 条件查询",response = List.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "start", value = "开始时间  可以只传开始时间，表示查询大于这个时间的值", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "end", value = "结束时间 可以只传开始时间，表示查询大于这个时间的值", dataType = "string", paramType = "query")})
    //@RequiresLogin
    public AjaxResult LoanFDHBPIGDP(@RequestBody(required = false) QueryVo vo){

        if(StringUtils.isNull(vo)){
            vo = new QueryVo();
        }
        return  macroEconomyService.getGDPPrivateInvestor(vo);
    }

    @PostMapping("/wei")
    @ApiOperation(value = "每周经济指数",response = List.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "start", value = "开始时间  可以只传开始时间，表示查询大于这个时间的值", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "end", value = "结束时间 可以只传开始时间， 表示查询大于这个时间的值", dataType = "string", paramType = "query")})
    //@RequiresLogin
    public AjaxResult WEI(@RequestBody(required = false) QueryVo vo){
        if(StringUtils.isNull(vo)){
            vo = new QueryVo();
        }
        return  macroEconomyService.getWEI(vo);
    }

    @PostMapping("/exchangeRate")
    @ApiOperation(value = "最新外汇信息",response = List.class)
    //@RequiresLogin
    public AjaxResult exchangeRate(){
        return  macroEconomyService.getNewExchangeRate();
    }

    @PostMapping("/exchangeRate/list")
    @ApiOperation(value = "外汇信息历史数据",response = List.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "symbol", value = "具体数据", dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "start", value = "开始时间  可以只传开始时间，表示查询大于这个时间的值", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "end", value = "结束时间 可以只传开始时间，表示查询大于这个时间的值", dataType = "string", paramType = "query")})
    //@RequiresLogin
    public AjaxResult exchangeRateList(@RequestBody() BiAnVo vo){

        return  macroEconomyService.getExchangeRateList(vo);
    }

    @PostMapping("/GDP")
    @ApiOperation(value = "最新国内生产总值",response = List.class)
    //@RequiresLogin
    public AjaxResult gdp(){
        return  macroEconomyService.getNewGDP();
    }

    @PostMapping("/GDP/list")
    @ApiOperation(value = "国内生产总值历史数据",response = List.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "symbol", value = "具体数据", dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "start", value = "开始时间  可以只传开始时间，表示查询大于这个时间的值", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "end", value = "结束时间 可以只传开始时间，表示查询大于这个时间的值", dataType = "string", paramType = "query")})
    //@RequiresLogin
    public AjaxResult gdpList(@RequestBody() BiAnVo vo){
        return  macroEconomyService.getGDPList(vo);
    }
}
