From 2b77da7dbdaed24246972b32269aaa62dfc85c10 Mon Sep 17 00:00:00 2001 From: Gauthier LO Date: Mon, 24 Feb 2025 16:20:35 +0100 Subject: [PATCH] feat : string converter --- .../ShippingInvoiceController.java | 42 +++++++++++++++++++ .../PlatformOrderShippingInvoiceService.java | 38 +++++++++++++++++ .../src/main/resources/application-prod.yml | 2 + 3 files changed, 82 insertions(+) diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/ShippingInvoiceController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/ShippingInvoiceController.java index ebf486c62..c086b7ea8 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/ShippingInvoiceController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/ShippingInvoiceController.java @@ -431,4 +431,46 @@ public class ShippingInvoiceController { shippingInvoiceService.setPaid(shippingNumbers); return Result.ok("Invoice set to paid."); } + + @GetMapping(value = "/downloadCustomFile") + public ResponseEntity downloadCustomFile(@RequestParam("input") String input) throws IOException, UserException { + boolean isEmployee = securityService.checkIsEmployee(); + Client client; + if (!isEmployee) { + client = clientService.getCurrentClient(); + if (client == null) { + log.error("Couldn't find the client"); + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .contentType(MediaType.TEXT_PLAIN) + .body(""); + } + log.error("Client {} is trying to download excel from string converter tool", client.getInternalCode()); + return ResponseEntity.status(HttpStatus.FORBIDDEN) + .contentType(MediaType.TEXT_PLAIN) + .body("You are not allowed to download this invoice."); + } + LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + String filename = platformOrderShippingInvoiceService.getCustomExcelPath(sysUser.getUsername(), input); + File file = new File(filename); + + log.info("Filename : {}", file); + + HttpHeaders header = new HttpHeaders(); + header.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename); + header.add("Cache-Control", "no-cache, no-store, must-revalidate"); + header.add("Pragma", "no-cache"); + header.add("Expires", "0"); + + Path path = Paths.get(file.getAbsolutePath()); + + log.info("Absolute Path : {} \nLength : {}", path, file.length()); + ByteArrayResource resource = new ByteArrayResource(Files.readAllBytes(path)); + + return ResponseEntity.ok() + .headers(header) + .contentLength(file.length()) + .contentType(MediaType.parseMediaType("application/octet-stream")) + .body(resource); + + } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/PlatformOrderShippingInvoiceService.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/PlatformOrderShippingInvoiceService.java index 0c061ed31..845171ad4 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/PlatformOrderShippingInvoiceService.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/PlatformOrderShippingInvoiceService.java @@ -138,6 +138,9 @@ public class PlatformOrderShippingInvoiceService { private String INVOICE_DETAIL_PDF_DIR; @Value("${jeecg.path.invoiceDetailExportDir}") private String INVOICE_DETAIL_EXPORT_DIR; + + @Value("${jeecg.path.customFileDir}") + private String CUSTOM_FILE_DIR; private static final String EXTENSION = ".xlsx"; private final static String[] DETAILS_TITLES = { @@ -194,6 +197,9 @@ public class PlatformOrderShippingInvoiceService { "Ventes 42j", "Prix à l'unité", }; + private final static String[] CUSTOM_FILE_TITLES = { + "SKU", + }; public Period getValidPeriod(List shopIDs) { Date begin = platformOrderMapper.findEarliestUninvoicedPlatformOrder(shopIDs); @@ -618,6 +624,34 @@ public class PlatformOrderShippingInvoiceService { System.gc(); return Files.readAllBytes(target); } + public byte[] exportCustomExcel(String username, String data) throws IOException { + SheetManager sheetManager = SheetManager.createXLSX(); + sheetManager.startDetailsSheet(); + for (String title : CUSTOM_FILE_TITLES) { + sheetManager.write(title); + sheetManager.nextCol(); + } + sheetManager.moveCol(0); + sheetManager.nextRow(); + List skuList = Stream.of(data.split("\n")).collect(Collectors.toList()); + for (String sku : skuList) { + sheetManager.write(sku); + sheetManager.moveCol(0); + sheetManager.nextRow(); + } + + Path target = Paths.get(CUSTOM_FILE_DIR, "Custom_" + username + ".xlsx"); + int i = 2; + while (Files.exists(target)) { + target = Paths.get(CUSTOM_FILE_DIR, "Custom_" + username + "_" + i + ".xlsx"); + i++; + } + Files.createFile(target); + sheetManager.export(target); + sheetManager.getWorkbook().close(); + System.gc(); + return Files.readAllBytes(target); + } /** * make shipping invoice by client and type (shipping or complete) @@ -829,6 +863,10 @@ public class PlatformOrderShippingInvoiceService { } return pathList.get(0).toString(); } + public String getCustomExcelPath(String username, String data) throws IOException { + exportCustomExcel(username, data); + return getPath(CUSTOM_FILE_DIR, username).get(0).toString(); + } public String convertToPdf(String invoiceNumber, String fileType) throws Exception { String excelFilePath = getInvoiceList(invoiceNumber, fileType);// (C:\PATH\filename.xlsx) diff --git a/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml b/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml index 38df8da3a..eb64a4ae9 100644 --- a/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml +++ b/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml @@ -241,6 +241,8 @@ jeecg: shippingInvoicePdfDir: /wia/invoices/pdf/shipping shippingInvoiceDetailPdfDir: /wia/invoices/pdf/shippingDetail invoiceDetailExportDir: /wia/invoices/invoiceDetailExport + + customFileDir: /wia/invoices/custom # sku csv file for image search skuCsvPath: /mnt/wia/products/sku.csv # CDG location