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

hangao
wangxy 3 days ago
parent f0fe9c5808
commit 1d75677baf

@ -147,11 +147,8 @@ public class CheckReportManager {
List<TdCheckTypeDTO> tdCheckTypeDtoS = Convert.toList(TdCheckTypeDTO.class, list); List<TdCheckTypeDTO> tdCheckTypeDtoS = Convert.toList(TdCheckTypeDTO.class, list);
tdCheckReportDto.setCheckTypeDTOS(tdCheckTypeDtoS); tdCheckReportDto.setCheckTypeDTOS(tdCheckTypeDtoS);
} }
ServletOutputStream out = response.getOutputStream();
try { 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 // 4. 使用Hutool导出Excel
ExcelWriter writer = ExcelUtil.getWriter(true); ExcelWriter writer = ExcelUtil.getWriter(true);
// 1. 先写入主表数据 // 1. 先写入主表数据
@ -182,9 +179,12 @@ public class CheckReportManager {
writer.write(tdCheckReportDto.getCheckTypeDTOS(), true); writer.write(tdCheckReportDto.getCheckTypeDTOS(), true);
// 4. 可选:调整列宽自动适应 // 4. 可选:调整列宽自动适应
writer.autoSizeColumnAll(); writer.autoSizeColumnAll();
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);
// 5. 输出到浏览器 // 5. 输出到浏览器
writer.flush(response.getOutputStream(), true); writer.flush(out, true);
writer.close();
} catch (Exception e) { } catch (Exception e) {
log.error("文件下载失败:{}", e.getMessage(), e); log.error("文件下载失败:{}", e.getMessage(), e);
try { try {

@ -108,7 +108,8 @@
<th:block th:include="include :: element-js" /> <th:block th:include="include :: element-js" />
<th:block th:include="include :: echarts-js" /> <th:block th:include="include :: echarts-js" />
<script th:inline="javascript"> <script th:inline="javascript">
var detailFlag = [[${@permission.hasPermi('system:check:detail')}]] var detailFlag = [[${@permission.hasPermi('system:check:detail')}]];
var exportDetailFlag = [[${@permission.hasPermi('system:check:exportDetail')}]];
var prefix = ctx + "system/checknum"; var prefix = ctx + "system/checknum";
var app = new Vue({ var app = new Vue({
el: '#app', el: '#app',
@ -308,6 +309,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> ');
return actions.join(''); return actions.join('');
} }
@ -315,6 +317,57 @@
}; };
$.table.init(options); $.table.init(options);
}); });
/**
* 导出明细
*/
function exportDetail(checkId) {
// 显示加载中提示
$.modal.loading("正在生成导出文件,请稍候...");
// 创建iframe
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = prefixTable + '/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