WebForCRMController.java 7.49 KB
package com.lhcredit.project.webbusiness.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.lhcredit.common.utils.OssUtils;
import com.lhcredit.common.utils.ServletUtils;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.framework.aspectj.lang.annotation.CheckToken;
import com.lhcredit.framework.aspectj.lang.annotation.Log;
import com.lhcredit.framework.aspectj.lang.annotation.ReportCount;
import com.lhcredit.framework.aspectj.lang.enums.BusinessType;
import com.lhcredit.framework.aspectj.lang.enums.OperatorType;
import com.lhcredit.framework.web.controller.BaseController;
import com.lhcredit.framework.web.domain.AjaxResult;
import com.lhcredit.framework.web.page.TableDataInfo;
import com.lhcredit.project.business.bCreditReport.domain.BCreditReport;
import com.lhcredit.project.business.bCreditReport.mapper.BCreditReportMapper;
import com.lhcredit.project.business.bCreditReport.service.BCreditReportServiceImpl;
import com.lhcredit.project.business.bCreditReport.service.IBCreditReportService;
import com.lhcredit.project.business.bReportTable.domain.BReportTable;
import com.lhcredit.project.business.bReportTable.service.IBReportTableService;
import com.lhcredit.project.business.frontUser.domain.FrontUserMon;
import com.lhcredit.project.business.reportFinanceData.domain.ReportFinanceData;
import com.lhcredit.project.business.reportFinanceData.service.IReportFinanceDataService;
import com.lhcredit.project.business.reportMake.ReportMakeService;
import com.lhcredit.project.system.dict.domain.DictData;
import com.lhcredit.project.system.dict.service.DictDataServiceImpl;
import com.lhcredit.project.system.dict.service.IDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.compress.utils.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;


/**
 * 信用管家 对 crm接口
 *
 * @author lhcredit
 * @date 2024-06-03
 */
@RestController
@RequestMapping("/api-V2.0/forCrm")
public class WebForCRMController extends BaseController {

    @Autowired
    private IDictDataService dictDataService;

    @Autowired
    private BCreditReportServiceImpl bCreditReportService;

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

    /**
     * crm系统查询 字典信息
     * @param dictData
     * @return
     */
    @PostMapping("/getDictData")
    public JSONObject getDictData(DictData dictData){
        dictData.setStatus("0");
        List<DictData> list = dictDataService.selectDictDataList(dictData);
        JSONObject result = new JSONObject();
        result.put("data", list);
        result.put("code", 200);
        result.put("msg", "success");
//        result.setData(list);
//        result.setCode(200);
//        result.setMsg("操作成功");
        return result;
    }

    /**
     * crm查询信用报告
     * @param bCreditReport
     * @return
     */
    @PostMapping("/getBcreditReportList")
    public TableDataInfo getBcreditReportList(@RequestBody BCreditReport bCreditReport){
        startPage(bCreditReport.getPageNum(), bCreditReport.getPageSize());
        List<BCreditReport> list = bCreditReportService.getBcreditReportListForCrm(bCreditReport);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(200);
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
    }

    /**
     * crm 查询信用报告excel导出
     * @param bCreditReport
     */
    @PostMapping("/exportBCreditReport")
    public AjaxResult exportBCreditReport(@RequestBody BCreditReport bCreditReport) {
        List<BCreditReport> list = bCreditReportService.getBcreditReportListForCrm(bCreditReport);
        return AjaxResult.success(list);
//        ExcelUtil<BCreditReport> excelUtil = new ExcelUtil<>(BCreditReport.class );
//        return excelUtil.exportExcel(list,"信用报告");
        /*Collection<BCreditReport> bCreditReports = CollUtil.newArrayList(list);
        ExcelWriter writer = ExcelUtil.getWriter();
        writer.write(bCreditReports,true);
        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        response.setHeader("Content-Disposition","attachment;filename=Bcredits.xls");

        ServletOutputStream outputStream = null;
        try {
            outputStream = response.getOutputStream();
            writer.flush(outputStream,true);
        } catch (IOException e) {
            logger.error(e.getMessage());
            throw new RuntimeException("信用报告导出到crm异常");
        } finally {
            writer.close();
            IoUtil.close(outputStream);
        }*/
    }

    /**
     * 根据合同查询 每个合同id下的报告数量
     * @param param
     * @return
     */
    @PostMapping("/getReportCountByContractIds")
    public AjaxResult getReportCountByContractIds(@RequestBody String param) {
        JSONObject paramObj = JSONObject.parseObject(param);
        String contractIdStr = paramObj.getString("contractIds");
        List<BCreditReport> reportCountByContractIds;
        //无合同id  则查询所有
        if (StringUtils.isBlank(contractIdStr)) {
            reportCountByContractIds = bCreditReportService.getBCreditReportCountByContractIds(new ArrayList<>());
            return AjaxResult.success(reportCountByContractIds);
        }
        //拆分合同id  并按照合同id查询 报告数量
        String[] ids = contractIdStr.split(",");
        List<Long> contractIds = Lists.newArrayList();
        for (String id : ids) {
            contractIds.add(Long.parseLong(id));
        }
        reportCountByContractIds = bCreditReportService.getBCreditReportCountByContractIds(contractIds);
        return AjaxResult.success(reportCountByContractIds);
    }

    /**
     * 查询 报告列表中的 报告类型 并返回
     * @return
     */
    @GetMapping("/getBCreditReportType/{contractId}")
    public JSONObject getBCreditReportType(@PathVariable("contractId") Long contractId){
        JSONObject object = new JSONObject();
        if(contractId == null){
            object.put("code", 300);
            object.put("msg", "合同id不能为空");
            return object;
        }
        List<DictData> reportTypes = bCreditReportService.getRrportType(contractId);

        object.put("code", 200);
        object.put("msg", "success");
        object.put("data", reportTypes);
        return object;
    }


    public static void main(String[] args) {
        LocalDate now = LocalDate.now();
        System.out.println(now.toString());
        Integer i = new Integer(2000);
        int a= 2000;
        System.out.println(i.equals(a));
    }
}