package com.dsk.search.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.alibaba.fastjson2.JSONObject;
import com.dsk.biz.utils.ExcelUtils;
import com.dsk.common.constant.Constants;
import com.dsk.common.core.domain.AjaxResult;
import com.dsk.common.core.domain.R;
import com.dsk.common.utils.StringUtils;
import com.dsk.common.utils.poi.ExcelUtil;
import com.dsk.component.UploadComponent;
import com.dsk.jsk.domain.bo.ComposeQueryDto;
import com.dsk.jsk.domain.vo.ImportantProjectExportVo;
import com.dsk.jsk.domain.vo.JskCombineBidProjectExportVo;
import com.dsk.search.service.BusinessOpportunityRadarService;
import com.dsk.system.domain.vo.SysOssVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.util.List;


/**
 * 商机雷达 查询接口
 * @author Administrator
 *
 */
@RequestMapping("/radar")
@RestController
public class BusinessOpportunityRadarController {


    @Resource
    private BusinessOpportunityRadarService opportunityRadarService;
    @Autowired
    private UploadComponent uploadComponent;

    /*
     * 公招标讯
     */
    @RequestMapping("/jskBidPage")
    public AjaxResult jskBidPage(@RequestBody JSONObject object) {
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (PageQueryLimit.pageLimit(compose.getPage())){
            return AjaxResult.error("翻页已达到上限");
        }
        return opportunityRadarService.jskBidPage(object);
    }

    /*
     * 土地交易
     */
    @RequestMapping("/landMarketPage")
    public AjaxResult landMarketPage(@RequestBody JSONObject object) {
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (PageQueryLimit.pageLimit(compose.getPage())){
            return AjaxResult.error("翻页已达到上限");
        }
        return opportunityRadarService.landMarketPage(object);
    }

    /*
     * 拟建项目
     */
    @RequestMapping("/establishmentPage")
    public AjaxResult establishmentPage(@RequestBody JSONObject object) {
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (PageQueryLimit.pageLimit(compose.getPage())){
            return AjaxResult.error("翻页已达到上限");
        }
        return opportunityRadarService.establishmentPage(object);
    }

    /*
     * 开标记录
     */
    @RequestMapping("/jskBidTenderPage")
    public AjaxResult jskBidTenderPage(@RequestBody JSONObject object) {
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (PageQueryLimit.pageLimit(compose.getPage())){
            return AjaxResult.error("翻页已达到上限");
        }
        return opportunityRadarService.jskBidTenderPage(object);
    }


    /*
     * 标讯pro
     */
    @RequestMapping("/jskBidNewsPage")
    public AjaxResult jskBidNewsPage(@RequestBody JSONObject object) {
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (PageQueryLimit.pageLimit(compose.getPage())){
            return AjaxResult.error("翻页已达到上限");
        }
        return opportunityRadarService.jskBidNewsPage(object);
    }

    /*
     * 标讯pro   商机项目关联查询
     */
    @RequestMapping("/jskBidNewsPage/findByName")
    public AjaxResult findByName(@RequestBody JSONObject object) {
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (PageQueryLimit.pageLimit(compose.getPage())){
            return AjaxResult.error("翻页已达到上限");
        }
        return opportunityRadarService.findByName(object);
    }


    /*
     * 专项债查询
     */
    @RequestMapping("/bondProjectPage")
    public AjaxResult bondProjectPage(@RequestBody JSONObject object) {
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (PageQueryLimit.pageLimit(compose.getPage())){
            return AjaxResult.error("翻页已达到上限");
        }
        return opportunityRadarService.bondProjectPage(object);
    }

    /*
     * 投标计划查询
     */
    @RequestMapping("/jskBidPlanPage")
    public AjaxResult jskBidPlanPage(@RequestBody JSONObject object) {
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (PageQueryLimit.pageLimit(compose.getPage())){
            return AjaxResult.error("翻页已达到上限");
        }
        return opportunityRadarService.jskBidPlanPage(object);
    }

    /*
     * 投标计划查询
     */
    @RequestMapping("/jskBidPlan/getCapitalSourceSelect")
    public AjaxResult getCapitalSourceSelect() {
        return opportunityRadarService.getCapitalSourceSelect();
    }

    /*
     * 推荐关键词
     */
    @RequestMapping("/keywordList")
    public AjaxResult keywordList() {
        return opportunityRadarService.keywordList();
    }

    /*
     * 招标来源网站
     */
    @RequestMapping("/bidSourceList")
    public AjaxResult bidSourceList(@RequestBody JSONObject object) {
        return opportunityRadarService.bidSourceList(object);
    }

    /*
     * 重点项目清单
     */
    @RequestMapping("/importantPage")
    public AjaxResult importantPage(@RequestBody JSONObject object) {
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (PageQueryLimit.pageLimit(compose.getPage())){
            return AjaxResult.error("翻页已达到上限");
        }
        return opportunityRadarService.importantPage(object);
    }

    /*
     * 重点项目清单关联查询
     */
    @RequestMapping("/importantSelect")
    public AjaxResult importantSelect(@RequestBody JSONObject object) {
        return opportunityRadarService.importantSelect(object);
    }
    /*
     * 重点项目清单筛选条件
     */
    @RequestMapping("/importantCondition")
    public AjaxResult importantCondition() {
        return opportunityRadarService.importantCondition();
    }

    /**
     * 导出重点项目清单
     */
    @RequestMapping("/export/important")
    @SaCheckPermission("radar:export:important")
    public R<SysOssVo> exportBid(@RequestBody JSONObject object, HttpServletResponse response) {
        List<ImportantProjectExportVo> list = opportunityRadarService.exportImportant(object);
        String title = "重点项目导出明细";
        ExcelUtils<ImportantProjectExportVo> util = new ExcelUtils<>(ImportantProjectExportVo.class);
        ByteArrayOutputStream ba = util.exportExcel(list, "重点项目", title, true);
        return uploadComponent.upload(title, ba, Constants.SUFFIX_XLSX, Constants.CONTENT_TYPE_XLSX);
    }


    /*
     * 公招市场
     */
    @RequestMapping("/bxproPage")
    public AjaxResult bxproPage(@RequestBody JSONObject object) {
        return opportunityRadarService.bxproPage(object);
    }
}
