|
|
|
@ -3,6 +3,11 @@ package com.ruoyi.web.controller.manager;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
|
|
|
import cn.hutool.core.text.StrPool;
|
|
|
|
|
import cn.hutool.http.HttpStatus;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelWriter;
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysDictData;
|
|
|
|
|
import com.ruoyi.common.utils.ShiroUtils;
|
|
|
|
|
import com.ruoyi.system.domain.check.TdCheckReport;
|
|
|
|
@ -11,11 +16,17 @@ import com.ruoyi.system.domain.check.dto.*;
|
|
|
|
|
import com.ruoyi.system.service.ISysDictDataService;
|
|
|
|
|
import com.ruoyi.system.service.check.TdCheckReportService;
|
|
|
|
|
import com.ruoyi.system.service.check.TdCheckTypeService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.poi.util.IOUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -28,6 +39,7 @@ import java.util.*;
|
|
|
|
|
* @description 检查报告
|
|
|
|
|
*/
|
|
|
|
|
@Component
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class CheckReportManager {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -43,6 +55,10 @@ public class CheckReportManager {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private SysAreaManager sysAreaManager;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<TdCheckReport> selectTdCheckReportList(CheckReportDTO tdCheckReport) {
|
|
|
|
|
return checkReportService.selectTdCheckReportList(tdCheckReport);
|
|
|
|
|
}
|
|
|
|
@ -121,4 +137,65 @@ public class CheckReportManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void exportDetail(String id, HttpServletResponse response) throws IOException {
|
|
|
|
|
TdCheckReport tdCheckReport = checkReportService.getById(id);
|
|
|
|
|
TdCheckReportDTO tdCheckReportDto = Convert.convert(TdCheckReportDTO.class, tdCheckReport);
|
|
|
|
|
tdCheckReportDto.setFramework(sysAreaManager.getAreaName(tdCheckReportDto.getFramework()));
|
|
|
|
|
tdCheckReportDto.setArea(sysAreaManager.getAreaName(tdCheckReportDto.getArea()));
|
|
|
|
|
List<TdCheckType> list = checkTypeService.lambdaQuery().eq(TdCheckType::getCheckId, tdCheckReport.getCheckId()).list();
|
|
|
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
|
|
|
List<TdCheckTypeDTO> tdCheckTypeDtoS = Convert.toList(TdCheckTypeDTO.class, list);
|
|
|
|
|
tdCheckReportDto.setCheckTypeDTOS(tdCheckTypeDtoS);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
String fileName = URLEncoder.encode(tdCheckReport.getCheckId() + ".xlsx", "UTF-8");
|
|
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
|
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName);
|
|
|
|
|
// 4. 使用Hutool导出Excel
|
|
|
|
|
ExcelWriter writer = ExcelUtil.getWriter(true);
|
|
|
|
|
// 1. 先写入主表数据
|
|
|
|
|
writer.renameSheet("自查信息");
|
|
|
|
|
writer.addHeaderAlias("adduser", "检查人员");
|
|
|
|
|
writer.addHeaderAlias("depart", "检查单位");
|
|
|
|
|
writer.addHeaderAlias("checkStartTime", "检查开始时间");
|
|
|
|
|
writer.addHeaderAlias("checkEndTime", "检查结束时间");
|
|
|
|
|
writer.addHeaderAlias("framework", "所属市州");
|
|
|
|
|
writer.addHeaderAlias("area", "所属区县");
|
|
|
|
|
writer.addHeaderAlias("totalScore", "实有项目总分");
|
|
|
|
|
writer.addHeaderAlias("percentageScore", "得分占比");
|
|
|
|
|
// 只导出有别名的字段
|
|
|
|
|
writer.setOnlyAlias(true);
|
|
|
|
|
// 2.2 写入主表数据(只有一条记录)
|
|
|
|
|
writer.write(CollUtil.newArrayList(tdCheckReportDto), true);
|
|
|
|
|
// 3. 写入子表信息(多条记录)
|
|
|
|
|
writer.setSheet("自查类信息");
|
|
|
|
|
// 3.1 设置子表表头
|
|
|
|
|
writer.addHeaderAlias("checkItems", "自查项");
|
|
|
|
|
writer.addHeaderAlias("typeContent", "自查内容");
|
|
|
|
|
writer.addHeaderAlias("score", "分值");
|
|
|
|
|
writer.addHeaderAlias("realScore", "得分");
|
|
|
|
|
writer.addHeaderAlias("deductionCriteria", "扣分标准");
|
|
|
|
|
// 只导出有别名的字段
|
|
|
|
|
writer.setOnlyAlias(true);
|
|
|
|
|
// 3.2 写入子表数据
|
|
|
|
|
writer.write(tdCheckReportDto.getCheckTypeDTOS(), true);
|
|
|
|
|
// 4. 可选:调整列宽自动适应
|
|
|
|
|
writer.autoSizeColumnAll();
|
|
|
|
|
// 5. 输出到浏览器
|
|
|
|
|
writer.flush(response.getOutputStream(), true);
|
|
|
|
|
writer.close();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("文件下载失败:{}", e.getMessage(), e);
|
|
|
|
|
try {
|
|
|
|
|
response.setContentType("application/json");
|
|
|
|
|
response.getWriter().print("{\"code\":500,\"msg\":\"导出失败:" + e.getMessage() + "\"}");
|
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
log.error("返回错误信息失败", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|