From 8c6327da1e57033a8d331d11e7f2e81496f1d6b5 Mon Sep 17 00:00:00 2001 From: sfd <sun.sunshine@163.com> Date: 星期五, 23 五月 2025 15:15:24 +0800 Subject: [PATCH] 修改导入导出规则 --- aps-modules/aps-core/src/main/java/com/aps/core/controller/mainPlan/ApsGasPipelineMoController.java | 24 +++++++++++++++++++++++- 1 files changed, 23 insertions(+), 1 deletions(-) diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/controller/mainPlan/ApsGasPipelineMoController.java b/aps-modules/aps-core/src/main/java/com/aps/core/controller/mainPlan/ApsGasPipelineMoController.java index f99787f..10d4244 100644 --- a/aps-modules/aps-core/src/main/java/com/aps/core/controller/mainPlan/ApsGasPipelineMoController.java +++ b/aps-modules/aps-core/src/main/java/com/aps/core/controller/mainPlan/ApsGasPipelineMoController.java @@ -7,13 +7,19 @@ import com.aps.common.log.annotation.Log; import com.aps.common.log.enums.BusinessType; import com.aps.common.security.annotation.RequiresPermissions; +import com.aps.common.security.utils.DictUtils; import com.aps.core.domain.ApsGasPipelineMo; import com.aps.core.service.IApsGasPipelineMoService; +import com.aps.system.api.domain.SysDictData; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletResponse; import lombok.SneakyThrows; import org.apache.commons.io.IOUtils; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.usermodel.WorkbookFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ByteArrayResource; import org.springframework.http.HttpHeaders; @@ -21,6 +27,8 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.List; @@ -56,7 +64,7 @@ @Operation(summary = "瀵煎叆绠¤矾鎵嬪伐姘斾綋宸ュ崟鏁版嵁", description = "鎵归噺瀵煎叆") @Log(title = "瀵煎叆绠¤矾鎵嬪伐姘斾綋宸ュ崟鏁版嵁", businessType = BusinessType.IMPORT) - @RequiresPermissions("gasPipeline:mo:import") +// @RequiresPermissions("gasPipeline:mo:import") @PostMapping("/importData") public AjaxResult importData(MultipartFile file) throws Exception { @@ -135,6 +143,20 @@ @GetMapping("/template") public ResponseEntity<ByteArrayResource> exportTemplate() { byte[] file = IOUtils.resourceToByteArray("/templates/姘斾綋宸ュ崟鏁版嵁妯℃澘v1.0.xlsx"); + Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(file)); + Sheet sheet = workbook.getSheet("瀛楀吀-鐢熶骇鍩哄湴"); + List<SysDictData> sysDictDataList = DictUtils.getDictCache("aps_factory"); + if (sysDictDataList != null) { + for (int i = 0; i < sysDictDataList.size(); i++) { + Row row = sheet.createRow(i + 1); + row.createCell(0).setCellValue(sysDictDataList.get(i).getDictValue()); + row.createCell(1).setCellValue(sysDictDataList.get(i).getDictLabel()); + } + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + workbook.write(baos); + file = baos.toByteArray(); + } + workbook.close(); ByteArrayResource resource = new ByteArrayResource(file); return ResponseEntity.ok() .header("Access-Control-Expose-Headers", HttpHeaders.CONTENT_DISPOSITION) -- Gitblit v1.9.3