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.search.util.ObjectUtils;
import com.dsk.system.service.ISysUserFileRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
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;
import java.util.Arrays;

/**
 * @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 AjaxResult enterpriseInfoExport(@RequestBody JSONObject object) {
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (null==compose.getAptitudeQueryDto()
                || !ObjectUtils.hasValueThroughObj(compose.getAptitudeQueryDto(), null, Arrays.asList("and", "or", "yes", "no", "level", "qualification", "new", "only"))) {
            return AjaxResult.warn("导出筛选条件为空！");
        }
        if (StringUtils.isEmpty(compose.getExportExeclName())){
            object.put("exportExeclName","企业基本信息导出");
        }
        object.put("exportTemplateName","http://123.60.218.188:9099/company/");
        object.put("exportStartRow",3);
        return exportService.enterpriseInfoExport(object);
    }

    /*
     * 企业资质表导出
     */
    @PostMapping("/aptitude")
    public AjaxResult enterpriseAptitudeExport(@RequestBody JSONObject object) {
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (null==compose.getAptitudeQueryDto()
                || !ObjectUtils.hasValueThroughObj(compose.getAptitudeQueryDto(), null, Arrays.asList("and", "or", "yes", "no", "level", "qualification", "new", "only"))) {
            return AjaxResult.warn("导出筛选条件为空！");
        }
        if (StringUtils.isEmpty(compose.getExportExeclName())){
            object.put("exportExeclName","企业资质信息导出");
        }
        object.put("exportTemplateName","http://123.60.218.188:9099/company/");
        object.put("exportStartRow",3);
        return exportService.enterpriseAptitudeExport(object);
    }

    /*
     * 重点项目清单导出
     */
    @RequestMapping("/important")
    public AjaxResult exportImportant(@RequestBody JSONObject object) {
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (null==compose.getImportantProjectDto()
                || !ObjectUtils.hasValueThroughObj(compose.getImportantProjectDto(), null, Arrays.asList("and", "or", "yes", "no", "level", "qualification", "new", "only"))) {
            return AjaxResult.warn("导出筛选条件为空！");
        }
        if (StringUtils.isEmpty(compose.getExportExeclName())){
            object.put("exportExeclName","重点项目导出");
        }
        return exportService.importantExport(object);
    }

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

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

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

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

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

    //集团土地交易导出
    @PostMapping("/combine/landMarket")
    public AjaxResult exportCombineLandMarket(@RequestBody JSONObject object) {
        return exportService.exportCombineLandMarket(object);
    }

    //集团招标计划导出
    @PostMapping("/combine/bidPlan")
    public AjaxResult exportCombineBidPlan(@RequestBody JSONObject object) {
        return exportService.exportCombineBidPlan(object);
    }

    //集团拟建项目导出
    @PostMapping("/combine/establishment")
    public AjaxResult exportCombineEstablishment(@RequestBody JSONObject object) {
        return exportService.exportCombineEstablishment(object);
    }
}
