From e5982e928948f41bc05e39c25932c00379edf083 Mon Sep 17 00:00:00 2001 From: caihaohan Date: Thu, 27 Jun 2024 18:02:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B3=95=E8=A7=84=E5=A4=8D=E5=90=88?= =?UTF-8?q?=E5=9E=8B=E8=AF=84=E4=BC=B0=E5=BA=93-=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LawsConformityAssessmentController.java | 16 +- .../LawsEvaluationNotMetController.java | 14 +- ...wsConformityAssessmentLibraryExportVO.java | 166 ++++++++++++++++ .../entity/vo/MaterialFile.java | 15 ++ ...awsConformityAssessmentLibraryService.java | 18 +- .../ILawsEvaluationNotMetLibraryService.java | 3 +- ...onformityAssessmentLibraryServiceImpl.java | 188 +++++++++++++++++- ...awsEvaluationNotMetLibraryServiceImpl.java | 3 +- .../standard/entity/LawsDomesticStandard.java | 2 +- 9 files changed, 402 insertions(+), 23 deletions(-) create mode 100644 laws-modules/src/main/java/com/jero/modules/assessmentLibrary/entity/vo/LawsConformityAssessmentLibraryExportVO.java create mode 100644 laws-modules/src/main/java/com/jero/modules/assessmentLibrary/entity/vo/MaterialFile.java diff --git a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/controller/LawsConformityAssessmentController.java b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/controller/LawsConformityAssessmentController.java index ae32d6ad..3425760b 100644 --- a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/controller/LawsConformityAssessmentController.java +++ b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/controller/LawsConformityAssessmentController.java @@ -6,6 +6,7 @@ import com.jero.common.api.vo.Result; import com.jero.common.aspect.annotation.AutoLog; import com.jero.modules.assessmentLibrary.entity.LawsConformityAssessmentLibrary; import com.jero.modules.assessmentLibrary.entity.LawsConformityAssessmentLibraryDetail; +import com.jero.modules.assessmentLibrary.entity.LawsEvaluationNotMetLibrary; import com.jero.modules.assessmentLibrary.service.ILawsConformityAssessmentLibraryService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -17,6 +18,8 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; @Api(tags = "法规符合性评估库-法规符合性评估库") @RestController @@ -58,7 +61,7 @@ public class LawsConformityAssessmentController { @AutoLog(value = "法规符合性评估库-法规符合性评估库-查看") @ApiOperation(value = "法规符合性评估库-法规符合性评估库-查看", notes = "法规符合性评估库-法规符合性评估库-查看") @GetMapping(value = "/detail") - @ApiOperationSupport(order = 1) + @ApiOperationSupport(order = 2) @RequiresPermissions("lawsConformityAssessment:detail") public Result> detail(LawsConformityAssessmentLibraryDetail lawsConformityAssessmentLibraryDetail, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @@ -68,4 +71,15 @@ public class LawsConformityAssessmentController { return Result.OK(pageList); } + /** + * 导出excel + */ + @AutoLog(value = "法规符合性评估库-法规符合性评估库-导出") + @ApiOperation(value="法规符合性评估库-法规符合性评估库-导出", notes="法规符合性评估库-法规符合性评估库-导出") + @RequiresPermissions("lawsConformityAssessment:export") + @GetMapping(value = "/exportXls", produces = "application/zip") + public void exportXls(HttpServletResponse response, LawsConformityAssessmentLibrary lawsConformityAssessmentLibrary, HttpServletRequest req) { + lawsConformityAssessmentLibraryService.export(response, lawsConformityAssessmentLibrary, "法规符合性评估库", "法规符合性评估库", req); + } + } diff --git a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/controller/LawsEvaluationNotMetController.java b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/controller/LawsEvaluationNotMetController.java index 208d5bc5..5f92aedb 100644 --- a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/controller/LawsEvaluationNotMetController.java +++ b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/controller/LawsEvaluationNotMetController.java @@ -32,7 +32,7 @@ import java.util.List; * @Date: 2023-09-11 * @Version: V1.0 */ -@Api(tags="不符合项") +@Api(tags="法规符合性评估库-不符合项库") @RestController @RequestMapping("/assessment/lawsEvaluationNotMet") @Slf4j @@ -44,8 +44,8 @@ public class LawsEvaluationNotMetController extends JeroController> queryPageList(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @@ -59,8 +59,8 @@ public class LawsEvaluationNotMetController extends JeroController batchClose(@RequestBody LawsEvaluationNotMetLibrary lawsEvaluationNotMet) { String ids = lawsEvaluationNotMet.getIds(); @@ -91,8 +91,8 @@ public class LawsEvaluationNotMetController extends JeroController materialFileList = Collections.emptyList(); + + +} \ No newline at end of file diff --git a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/entity/vo/MaterialFile.java b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/entity/vo/MaterialFile.java new file mode 100644 index 00000000..141c4118 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/entity/vo/MaterialFile.java @@ -0,0 +1,15 @@ +package com.jero.modules.assessmentLibrary.entity.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.jeecgframework.poi.excel.annotation.Excel; + +@Data +public class MaterialFile { + @ApiModelProperty(value = "id") + private String id; + + @Excel(name = "佐证材料", width = 15) + @ApiModelProperty(value = "佐证材料") + private String fileName; +} diff --git a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/ILawsConformityAssessmentLibraryService.java b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/ILawsConformityAssessmentLibraryService.java index e1120ea3..d1f000aa 100644 --- a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/ILawsConformityAssessmentLibraryService.java +++ b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/ILawsConformityAssessmentLibraryService.java @@ -4,6 +4,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.jero.modules.assessmentLibrary.entity.LawsConformityAssessmentLibrary; import com.baomidou.mybatisplus.extension.service.IService; import com.jero.modules.assessmentLibrary.entity.LawsConformityAssessmentLibraryDetail; +import com.jero.modules.assessmentLibrary.entity.LawsEvaluationNotMetLibrary; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; /** * @author ThinkBook @@ -19,7 +23,8 @@ public interface ILawsConformityAssessmentLibraryService extends IService queryPage(LawsConformityAssessmentLibrary lawsConformityAssessmentLibrary, Integer pageNo, Integer pageSize); + IPage queryPage(LawsConformityAssessmentLibrary lawsConformityAssessmentLibrary, + Integer pageNo, Integer pageSize); /** * 查看 分页列表 @@ -28,5 +33,14 @@ public interface ILawsConformityAssessmentLibraryService extends IService detail(LawsConformityAssessmentLibraryDetail lawsConformityAssessmentLibraryDetail, Integer pageNo, Integer pageSize); + IPage detail(LawsConformityAssessmentLibraryDetail lawsConformityAssessmentLibraryDetail, + Integer pageNo, Integer pageSize); + + /** + * 导出 + * @param lawsConformityAssessmentLibrary + * @return + */ + void export(HttpServletResponse response, LawsConformityAssessmentLibrary lawsConformityAssessmentLibrary, + String fileName, String sheetName, HttpServletRequest req); } diff --git a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/ILawsEvaluationNotMetLibraryService.java b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/ILawsEvaluationNotMetLibraryService.java index 1d1b5281..14f58caf 100644 --- a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/ILawsEvaluationNotMetLibraryService.java +++ b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/ILawsEvaluationNotMetLibraryService.java @@ -39,5 +39,6 @@ public interface ILawsEvaluationNotMetLibraryService extends IService - implements ILawsConformityAssessmentLibraryService { + implements ILawsConformityAssessmentLibraryService { + + @Value("${jero.path.exportExcelTempPath}") + private String exportExcelTempPath; + + @Resource + private IOSSFileService ossFileService; + + private static final String EXPORT_EXCEL_TEMP = "exportExcelTemp"; + + @Resource + private SysWaterMarkUtil sysWaterMarkUtil; @Resource private LawsConformityAssessmentLibraryMapper lawsConformityAssessmentLibraryMapper; @@ -71,6 +104,141 @@ public class LawsConformityAssessmentLibraryServiceImpl extends ServiceImpl data = this.queryPage(lawsConformityAssessmentLibrary, 1, Integer.MAX_VALUE); + List records = data.getRecords(); + // 找到每条数据的详细信息 + Map> allDetailMap = new HashMap<>(); + LawsConformityAssessmentLibraryDetail condition = new LawsConformityAssessmentLibraryDetail(); + records.forEach(item -> { + condition.setBindId(item.getId()); + IPage detail = this.detail(condition, 1, Integer.MAX_VALUE); + allDetailMap.put(item.getId(), detail.getRecords()); + }); + + // 组合成导出数据 + List recordsExport = new ArrayList<>(); + records.forEach(item -> { + List lawsConformityAssessmentLibraryDetails = allDetailMap.get(item.getId()); + List vos = BeanCopyUtils.copyBeanList(lawsConformityAssessmentLibraryDetails, LawsConformityAssessmentLibraryExportVO.class); + vos.forEach(e -> { + e.setStandardNumber(item.getStandardNumber()); + e.setStandardName(item.getStandardName()); + e.setApplicableMarket(item.getApplicableMarket()); + e.setValuationTime(item.getValuationTime()); + }); + recordsExport.addAll(vos); + }); + + this.settleDocuments(url, recordsExport); + + // 生成excel + ExportParams exportParams = new ExportParams(); + exportParams.setType(ExcelType.HSSF); + Workbook workbook = ExcelExportUtil.exportExcel(exportParams, LawsConformityAssessmentLibraryExportVO.class, recordsExport); + // 生成超链接 + generateHyperlink(recordsExport, workbook); + // 导出excel + workbook.write(fos); + // 生成并导出zip + ZipUtil.toZip(url, response.getOutputStream(), response, true); + } catch (Exception e) { + log.error("导出excel异常", e); + throw new JeroBootException("导出excel异常", e); + } finally { + // 删除文件 + if (new File(url).exists()) { + FileUtils.deleteFolders(url); + } + } + } + + private static void generateHyperlink(List vos, Workbook workbook) { + Sheet sheet = workbook.getSheetAt(0); + // 设置字体颜色、下划线 + CellStyle cellStyle = workbook.createCellStyle(); + Font font = workbook.createFont(); + font.setColor(IndexedColors.BLUE.getIndex()); + font.setUnderline(Font.U_SINGLE); + cellStyle.setFont(font); + cellStyle.setWrapText(true); + int i = 1; + for (LawsConformityAssessmentLibraryExportVO vo : vos) { + if (!Objects.isNull(vo.getMaterial()) && !vo.getMaterialFileList().isEmpty()) { + for (MaterialFile materialFile : vo.getMaterialFileList()) { + Row row = sheet.getRow(i); + Cell cell = row.getCell(6); + // 设置超链接 HYPERLINK("https://www.baidu.com", "百度") + cell.setCellFormula("HYPERLINK(\"" + materialFile.getFileName() + "\", \"" + materialFile.getFileName() + "\")"); + cell.setCellStyle(cellStyle); + i += 1; + } + } else { + i += 1; + } + } + } + + private void settleDocuments(String url, List excelVos) throws + IOException { + for (LawsConformityAssessmentLibraryExportVO vo : excelVos) { + // 查询文件 + if (StringUtils.isNotBlank(vo.getMaterial())) { + List fileIdList = Arrays.asList(vo.getMaterial().split(",")); + List ossFileList = ossFileService.listByIds(fileIdList); + if (!ossFileList.isEmpty()) { + // 赋值 + List materialFileList = com.jero.common.util.BeanCopyUtils.copyBeanList(ossFileList, MaterialFile.class); + vo.setMaterialFileList(materialFileList); + // 写出文件 + for (OSSFile ossFile : ossFileList) { + InputStream inputStream = MinioUtil.getMinioFile(MinioUtil.getBucketName(), ossFile.getUrl()); + // pdf加水印 + if (StringUtils.endsWithIgnoreCase(ossFile.getFileName(), ".pdf")) { + inputStream = sysWaterMarkUtil.addWatermarkToPdf(inputStream); + } + // 导出文件 + String filePath = url + File.separator + ossFile.getFileName(); + writeToLocal(filePath, inputStream); + } + } + } + } + } + + /** + * 将InputStream写入本地文件 + * + * @param filePath + * @param input + * @throws IOException + */ + public void writeToLocal(String filePath, InputStream input) + throws IOException { + int index; + byte[] bytes = new byte[1024]; + try (FileOutputStream downloadFile = new FileOutputStream(filePath)) { + while ((index = input.read(bytes)) != -1) { + downloadFile.write(bytes, 0, index); + downloadFile.flush(); + } + } catch (Exception e) { + log.error("将InputStream写入本地失败:{}", e.getMessage()); + } finally { + input.close(); + } + } + } diff --git a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/impl/LawsEvaluationNotMetLibraryServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/impl/LawsEvaluationNotMetLibraryServiceImpl.java index 7721cee9..601782c1 100644 --- a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/impl/LawsEvaluationNotMetLibraryServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/impl/LawsEvaluationNotMetLibraryServiceImpl.java @@ -79,7 +79,8 @@ public class LawsEvaluationNotMetLibraryServiceImpl extends ServiceImpl lawsEvaluationNotMets = this.queryPage(lawsEvaluationNotMet, 1, Integer.MAX_VALUE, req); diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/entity/LawsDomesticStandard.java b/laws-modules/src/main/java/com/jero/modules/laws/standard/entity/LawsDomesticStandard.java index 1a898a27..65cea686 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/standard/entity/LawsDomesticStandard.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/standard/entity/LawsDomesticStandard.java @@ -57,7 +57,7 @@ public class LawsDomesticStandard implements Serializable { @ApiModelProperty(value = "0表示未删除,1表示删除") @TableLogic private java.lang.Integer delFlag; - /**标准性质*/ + /**类型*/ @Excel(name = "类型", width = 15) @ApiModelProperty(value = "类型") private java.lang.String type;