package com.dsk.search.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.alibaba.fastjson2.JSONObject;
import com.dsk.common.core.domain.AjaxResult;
import com.dsk.common.utils.StringUtils;
import com.dsk.jsk.domain.EnterpriseUipSearchBody;
import com.dsk.jsk.domain.JskCombineSearchDto;
import com.dsk.jsk.domain.bo.ComposeQueryDto;
import com.dsk.jsk.domain.bo.UrbanInvestmentPlatformDto;
import com.dsk.search.service.ExportService;
import com.dsk.system.service.ISysUserFileRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
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.validation.Valid;

/**
 * @author lc
 * @date 2023/11/14 14:15
 */
@RestController
@RequestMapping("/export")
public class ExportController {

    @Autowired
    private ISysUserFileRecordService sysUserFileRecordService;
    @Resource
    private ExportService exportService;

    /**
     * 导出回调接口
     * @param object
     * @return
     */
    @PostMapping(value = "/backUrl")
    public AjaxResult exportBack(@RequestBody JSONObject object) {
        return sysUserFileRecordService.exportBack(object);
    }

    /*
     * 企业基本信息表导出
     */
    @PostMapping("/enterprise/info")
    public void enterpriseInfoExport(@RequestBody JSONObject object) {
        ComposeQueryDto compose = com.alibaba.fastjson2.JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (StringUtils.isEmpty(compose.getExportExeclName())){
            object.put("exportExeclName","企业基本信息导出");
        }
        exportService.enterpriseInfoExport(object);
    }

    /*
     * 企业资质表导出
     */
    @PostMapping("/aptitude")
    public void enterpriseAptitudeExport(@RequestBody JSONObject object) {
        ComposeQueryDto compose = com.alibaba.fastjson2.JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (StringUtils.isEmpty(compose.getExportExeclName())){
            object.put("exportExeclName","企业资质信息导出");
        }
        exportService.enterpriseAptitudeExport(object);
    }

    /*
     * 重点项目清单导出
     */
    @RequestMapping("/important")
    public void exportImportant(@RequestBody JSONObject object) {
        ComposeQueryDto compose = com.alibaba.fastjson2.JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (StringUtils.isEmpty(compose.getExportExeclName())){
            object.put("exportExeclName","重点项目导出");
        }
        exportService.importantExport(object);
    }

    /**
     * 集团成员列表导出
     */
    @PostMapping("/combine/memberList")
    public void memberListExportPre(@RequestBody JskCombineSearchDto dto) throws Exception {
        exportService.memberListExport(dto);
    }

    //集团中标业绩导出
    @PostMapping("/combine/win/bid")
    @SaCheckPermission("combine:info:export:win:bid")
    public void exportWinBid(@RequestBody JskCombineSearchDto dto) {
        exportService.exportWinBid(dto);
    }

    //集团招标业绩导出
    @PostMapping("/combine/bid")
    @SaCheckPermission("combine:info:export:win:bid")
    public void exportBid(@RequestBody JskCombineSearchDto dto) {
        exportService.exportBid(dto);
    }

    //查城投平台导出
    @PostMapping(value = "/uipSerach")
    public void uipSerachExport(@RequestBody @Valid EnterpriseUipSearchBody vo) throws Exception {
        exportService.uipSerachExport(vo);
    }

    //市场经济  城投平台导出
    @PostMapping("/urbanInvestmentPlatform")
    public void export(@RequestBody UrbanInvestmentPlatformDto dto) {
        exportService.export(dto);
    }
}
