package com.simuwang.manage.api.fund;

import com.simuwang.base.common.page.TableDataInfo;
import com.simuwang.base.pojo.vo.FundInformationVO;
import com.simuwang.base.pojo.vo.FundReportFrequencyVO;
import com.simuwang.manage.api.base.BaseController;
import com.simuwang.manage.service.FundInformationService;
import com.simuwang.manage.service.FundReportFrequencyService;
import com.smppw.common.pojo.ResultVo;
import com.smppw.common.pojo.enums.status.ResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * FileName: FundInformationController
 * Author:   chenjianhua
 * Date:     2024/9/6 15:01
 * Description: ${DESCRIPTION}
 */
@RestController
@RequestMapping("/fund")
public class FundInformationController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(FundInformationController.class);


    @Autowired
    private FundInformationService fundInformationService;

    @Autowired
    private FundReportFrequencyService fundReportFrequencyService;
    /**
     * 搜索输入框查询
     * @param keyword
     * @return
     */
    @RequestMapping("search-info")
    public TableDataInfo searchFundInfo(@RequestParam(value = "keyword",required = false)String keyword){
        List<Map<String,String>> result = fundInformationService.searchFundInfo(keyword);
        return getDataTable(result);
    }

    /**
     * @param fundShortName
     * @param companyShortName
     * @param navFrequency
     * @param assetFrequency
     * @return
     */
    @RequestMapping("search-list")
    public List<FundInformationVO> searchFundInfoList(
              @RequestParam(value = "fundId",required = false)String fundId,
              @RequestParam(value = "fundShortName",required = false)String fundShortName,
              @RequestParam(value = "companyShortName",required = false)String companyShortName,
              @RequestParam(value = "navFrequency",required = false)Integer navFrequency,
              @RequestParam(value = "assetFrequency",required = false)Integer assetFrequency,
              @RequestParam(value = "startDate",required = false)Integer startDate,
              @RequestParam(value = "endDate",required = false)Integer endDate){
        List<FundInformationVO> result = fundInformationService.searchFundInfoList(fundId,fundShortName,companyShortName,navFrequency,assetFrequency,startDate,endDate);
        return result;
    }

    @PostMapping("/save-frequency")
    public ResultVo saveFundReportFrequency(@RequestBody FundReportFrequencyVO fundReportFrequency){
        ResultVo vo = new ResultVo(ResultCode.SAVE_SUCCESS);
        try{
            fundReportFrequencyService.saveFundReportFrequency(fundReportFrequency);
        }catch (Exception e){
            vo = new ResultVo(ResultCode.SAVE_FAILED);
            logger.error(e.getMessage(),e);
        }
        return vo;
    }

}
