JudgmentController.java 2.16 KB
package cn.com.glsx.admin.modules.controller;

import cn.com.glsx.admin.common.constants.Constants;
import cn.com.glsx.admin.modules.model.export.JudgmentExport;
import cn.com.glsx.admin.modules.model.param.JudgmentSearch;
import cn.com.glsx.admin.modules.service.JudgmentService;
import cn.com.glsx.admin.modules.utils.FdfsUtils;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.web.R;
import com.glsx.plat.office.excel.EasyExcelUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.ByteArrayOutputStream;
import java.util.List;

/**
 * 大数据研判 controller
 *
 * @author yll
 */
@Slf4j
@RestController
@RequestMapping(value = "/judgment")
@Api(value = "大数据研判报表", tags = {"大数据研判报表"})
public class JudgmentController {

    @Autowired
    private JudgmentService judgmentService;

    @GetMapping("/search")
    @ApiOperation(value = "查询大数据研判列表")
    public R findJudgmentList(JudgmentSearch judgmentSearch) {
        PageInfo pageInfo = judgmentService.findJudgmentList(judgmentSearch);
        return R.ok().putPageData(pageInfo);
    }

    @GetMapping("/export")
    @ApiOperation(value = "导出大数据研判报表")
    public R<String> exportJudgmentList(JudgmentSearch judgmentSearch) {
        String fileName = FdfsUtils.getFileName("大数据研判报表");
        List<JudgmentExport> judgmentList = judgmentService.exportJudgmentList(judgmentSearch);
        // 将文件写入内存流 然后上传到文件服务器 返回文件服务器的地址给前端 前端执行下载
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        EasyExcelUtils.writeExcel(outputStream, judgmentList, fileName, JudgmentExport.class);
        String fileUrl = FdfsUtils.uploadFile(outputStream.toByteArray(), Constants.XLSX_FILE_EXTENSION);
        return R.ok().data(fileUrl);
    }
}