feat:自查自评检查导入实现

hangao
wangxy 4 days ago
parent 99153f8321
commit f0fe9c5808

@ -3,6 +3,11 @@ package com.ruoyi.web.controller.manager;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.text.CharSequenceUtil; 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.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.system.domain.check.TdCheckReport; 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.ISysDictDataService;
import com.ruoyi.system.service.check.TdCheckReportService; import com.ruoyi.system.service.check.TdCheckReportService;
import com.ruoyi.system.service.check.TdCheckTypeService; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*; import java.util.*;
/** /**
@ -28,6 +39,7 @@ import java.util.*;
* @description * @description
*/ */
@Component @Component
@Slf4j
public class CheckReportManager { public class CheckReportManager {
@ -43,6 +55,10 @@ public class CheckReportManager {
@Resource
private SysAreaManager sysAreaManager;
public List<TdCheckReport> selectTdCheckReportList(CheckReportDTO tdCheckReport) { public List<TdCheckReport> selectTdCheckReportList(CheckReportDTO tdCheckReport) {
return checkReportService.selectTdCheckReportList(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);
}
}
}
} }

@ -11,12 +11,15 @@ import com.ruoyi.system.domain.check.dto.CheckReportDTO;
import com.ruoyi.system.domain.check.dto.TdCheckReportDTO; import com.ruoyi.system.domain.check.dto.TdCheckReportDTO;
import com.ruoyi.web.controller.manager.CheckReportManager; import com.ruoyi.web.controller.manager.CheckReportManager;
import com.ruoyi.web.controller.manager.SysAreaManager; import com.ruoyi.web.controller.manager.SysAreaManager;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
@ -76,6 +79,19 @@ public class CheckReportController extends BaseController {
return util.exportExcel(tdCheckReports, "检查报告管理数据"); return util.exportExcel(tdCheckReports, "检查报告管理数据");
} }
/**
*
* @param checkId
* @param response
* @throws IOException
*/
@RequiresPermissions("system:check:exportDetail")
@Log(title = "检查报告", businessType = BusinessType.EXPORT)
@GetMapping("/exportDetail")
public void exportDetail(@RequestParam String checkId, HttpServletResponse response) throws IOException {
checkReportManager.exportDetail(checkId, response);
}
/** /**
* *
*/ */

@ -80,6 +80,7 @@
var detailFlag = [[${@permission.hasPermi('system:check:detail')}]] var detailFlag = [[${@permission.hasPermi('system:check:detail')}]]
var selfCheckFlag = [[${@permission.hasPermi('system:check:selfcheck')}]]; var selfCheckFlag = [[${@permission.hasPermi('system:check:selfcheck')}]];
var removeFlag = [[${@permission.hasPermi('system:check:remove')}]]; var removeFlag = [[${@permission.hasPermi('system:check:remove')}]];
var exportDetailFlag = [[${@permission.hasPermi('system:check:exportDetail')}]];
var checkStateDatas = [[${@dict.getType('sys_check_state')}]]; var checkStateDatas = [[${@dict.getType('sys_check_state')}]];
var prefix = ctx + "system/checkReport"; var prefix = ctx + "system/checkReport";
let datas = [] let datas = []
@ -169,6 +170,7 @@
align: 'center', align: 'center',
formatter: function(value, row, index) { formatter: function(value, row, index) {
var actions = []; var actions = [];
actions.push('<a class="btn btn-info btn-xs ' + exportDetailFlag + '" href="javascript:void(0)" onclick="exportDetail(\'' + row.checkId + '\')"><i class="fa fa-download"></i>导出</a> ');
actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.checkId + '\')"><i class="fa fa-edit"></i>详情</a> '); actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.checkId + '\')"><i class="fa fa-edit"></i>详情</a> ');
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.checkId + '\')"><i class="fa fa-edit"></i>编辑</a> '); actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.checkId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.checkId + '\')"><i class="fa fa-remove"></i>删除</a>'); actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.checkId + '\')"><i class="fa fa-remove"></i>删除</a>');
@ -243,6 +245,58 @@
// function openEdit(id){ // function openEdit(id){
// $.modal.openTab("修改" + table.options.modalName, prefix + '/edit' + '/' + id); // $.modal.openTab("修改" + table.options.modalName, prefix + '/edit' + '/' + id);
// } // }
/**
* 导出明细
*/
function exportDetail(checkId) {
// 显示加载中提示
$.modal.loading("正在生成导出文件,请稍候...");
// 创建iframe
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = prefix + '/exportDetail?checkId=' + checkId;
// 记录开始时间
var startTime = new Date().getTime();
// 定时检查iframe状态
var checkInterval = setInterval(function() {
try {
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
// 如果iframe内容加载完成
if (iframeDoc.readyState === 'complete') {
clearInterval(checkInterval);
$.modal.closeLoading();
// 检查是否是错误响应
var responseText = iframeDoc.body.textContent || iframeDoc.body.innerText;
if (responseText && responseText.startsWith('{"code":500')) {
var result = JSON.parse(responseText);
$.modal.alertError(result.msg);
}
// 移除iframe
setTimeout(function() {
document.body.removeChild(iframe);
}, 100);
}
// 超时处理10秒超时
if (new Date().getTime() - startTime > 10000) {
clearInterval(checkInterval);
$.modal.closeLoading();
document.body.removeChild(iframe);
$.modal.alertError("导出超时,请重试");
}
} catch(e) {
// 跨域异常通常表示文件下载成功
clearInterval(checkInterval);
$.modal.closeLoading();
setTimeout(function() {
document.body.removeChild(iframe);
}, 100);
}
}, 200);
document.body.appendChild(iframe);
}
</script> </script>
</body> </body>
</html> </html>

Loading…
Cancel
Save