|
|
@@ -4,10 +4,7 @@ import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; |
|
|
|
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.tuoheng.admin.constant.SystemConstant; |
|
|
|
import com.tuoheng.admin.conver.InspectionFileConverMapper; |
|
|
|
import com.tuoheng.admin.dto.InspectionFileExportExcelDto; |
|
|
|
import com.tuoheng.admin.entity.Inspection; |
|
|
|
import com.tuoheng.admin.entity.InspectionFile; |
|
|
@@ -18,17 +15,17 @@ import com.tuoheng.admin.mapper.InspectionFileMapper; |
|
|
|
import com.tuoheng.admin.mapper.InspectionMapper; |
|
|
|
import com.tuoheng.admin.utils.CurrentUserUtil; |
|
|
|
import com.tuoheng.admin.utils.DownloadUtil; |
|
|
|
import com.tuoheng.admin.utils.excel.CustomCellWriteHandler; |
|
|
|
import com.tuoheng.admin.utils.excel.CustomCellWriteWidthHandler; |
|
|
|
import com.tuoheng.admin.utils.excel.ImageModifyHandler; |
|
|
|
import com.tuoheng.admin.utils.excel.StyleUtils; |
|
|
|
import com.tuoheng.common.core.config.UploadFileConfig; |
|
|
|
import com.tuoheng.common.core.config.common.CommonConfig; |
|
|
|
import com.tuoheng.common.core.exception.ServiceException; |
|
|
|
import com.tuoheng.common.core.utils.DateUtils; |
|
|
|
import com.tuoheng.common.core.utils.FileUtils; |
|
|
|
import com.tuoheng.common.core.utils.JsonResult; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
@@ -85,7 +82,7 @@ public class ExportInspectionFileByIdListService { |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
String fileName = inspection.getName() + "-疑似问题清单.xlsx"; |
|
|
|
String fileName = inspection.getCode() + "-疑似问题清单.xlsx"; |
|
|
|
String filePath = UploadFileConfig.uploadFolder + "inspection_file/" + fileName; |
|
|
|
File fd = new File(UploadFileConfig.uploadFolder + "inspection_file"); |
|
|
|
if (!fd.exists()) { |
|
|
@@ -96,11 +93,10 @@ public class ExportInspectionFileByIdListService { |
|
|
|
|
|
|
|
this.easyExcel(inspection, inspectionFileExportExcelDtoList, filePath); |
|
|
|
|
|
|
|
response.setContentType("application/octet-stream;charset=UTF-8"); |
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8)); |
|
|
|
DownloadUtil.download(response, filePath, fileName); |
|
|
|
|
|
|
|
FileUtils.deleteFile(filePath); |
|
|
|
|
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
@@ -125,7 +121,7 @@ public class ExportInspectionFileByIdListService { |
|
|
|
inspectionFile = inspectionFileList.get(i); |
|
|
|
inspectionFileExportExcelDto = new InspectionFileExportExcelDto(); |
|
|
|
inspectionFileExportExcelDto.setSequence(i + 1); |
|
|
|
inspectionFileExportExcelDto.setQuestionDesc(inspectionFile.getQuestionDesc()); |
|
|
|
inspectionFileExportExcelDto.setQuestionName(inspectionFile.getQuestionName()); |
|
|
|
try { |
|
|
|
inspectionFileExportExcelDto.setFileOriginal(new URL(CommonConfig.imageURL + inspectionFile.getFileOriginal())); |
|
|
|
inspectionFileExportExcelDto.setFileImage(new URL(CommonConfig.imageURL + inspectionFile.getFileImage())); |
|
|
@@ -178,58 +174,16 @@ public class ExportInspectionFileByIdListService { |
|
|
|
|
|
|
|
EasyExcel.write(filePath, InspectionFileExportExcelDto.class).sheet("问题清单数据") |
|
|
|
.head(heads) |
|
|
|
// .registerWriteHandler(new SimpleColumnWidthStyleStrategy(20)) // 简单的列宽策略,列宽20 |
|
|
|
.registerWriteHandler(new CustomCellWriteHandler()) |
|
|
|
.registerWriteHandler(new CustomCellWriteWidthHandler()) |
|
|
|
// .registerWriteHandler(new CustomCellWriteHeightConfig()) |
|
|
|
.registerWriteHandler(horizontalCellStyleStrategy) |
|
|
|
.registerWriteHandler(new ImageModifyHandler()) |
|
|
|
.doWrite(inspectionFileExportExcelDtoList); // 数据源 |
|
|
|
|
|
|
|
|
|
|
|
// // 内容样式 |
|
|
|
// WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); |
|
|
|
// contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 水平居中 |
|
|
|
// contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); // 垂直居中 |
|
|
|
// contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);//细实线 |
|
|
|
// contentWriteCellStyle.setBorderTop(BorderStyle.THIN); |
|
|
|
// contentWriteCellStyle.setBorderRight(BorderStyle.THIN); |
|
|
|
// contentWriteCellStyle.setBorderBottom(BorderStyle.THIN); |
|
|
|
// |
|
|
|
// |
|
|
|
// //设计内容居中 |
|
|
|
// contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); //设置内容自动换行 |
|
|
|
// contentWriteCellStyle.setWrapped(true); |
|
|
|
// |
|
|
|
// //设置头部样式 |
|
|
|
// WriteCellStyle headWriteCellStyle = new WriteCellStyle(); |
|
|
|
// //设置头部标题居中 |
|
|
|
// headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); |
|
|
|
// // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现 |
|
|
|
// HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle); |
|
|
|
// |
|
|
|
// // 将数据写进流,如果是响应流则写进header对应的文件里 |
|
|
|
// ExcelWriter excelWriter = EasyExcel.write(filePath, InspectionFileExportExcelDto.class).build(); |
|
|
|
// |
|
|
|
// //指定sheet的名字和头信息 |
|
|
|
// WriteSheet writeSheet = EasyExcel.writerSheet(0, "日历导出") |
|
|
|
// .head(heads) |
|
|
|
// .registerWriteHandler(new SimpleColumnWidthStyleStrategy(20)) |
|
|
|
// .registerWriteHandler(horizontalCellStyleStrategy) |
|
|
|
// .registerWriteHandler(new CustomCellWriteHandler()) |
|
|
|
//// .registerWriteHandler(new CustomCellWriteHeightConfig()) |
|
|
|
// .registerWriteHandler(new ImageModifyHandler()) |
|
|
|
// .build(); |
|
|
|
// //将数据真正写入excel中 |
|
|
|
// excelWriter.write(inspectionFileExportExcelDtoList, writeSheet); |
|
|
|
// //千万别忘记finish 会帮忙关闭流 |
|
|
|
// excelWriter.finish(); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
log.info("生成数据导出excel异常"); |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
log.info("开始写入表格中"); |
|
|
|
|
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
} |