mirror of https://github.com/jeecgboot/jeecg-boot
commit
1edd474305
|
@ -431,4 +431,46 @@ public class ShippingInvoiceController {
|
||||||
shippingInvoiceService.setPaid(shippingNumbers);
|
shippingInvoiceService.setPaid(shippingNumbers);
|
||||||
return Result.ok("Invoice set to paid.");
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,6 +138,9 @@ public class PlatformOrderShippingInvoiceService {
|
||||||
private String INVOICE_DETAIL_PDF_DIR;
|
private String INVOICE_DETAIL_PDF_DIR;
|
||||||
@Value("${jeecg.path.invoiceDetailExportDir}")
|
@Value("${jeecg.path.invoiceDetailExportDir}")
|
||||||
private String INVOICE_DETAIL_EXPORT_DIR;
|
private String INVOICE_DETAIL_EXPORT_DIR;
|
||||||
|
|
||||||
|
@Value("${jeecg.path.customFileDir}")
|
||||||
|
private String CUSTOM_FILE_DIR;
|
||||||
private static final String EXTENSION = ".xlsx";
|
private static final String EXTENSION = ".xlsx";
|
||||||
|
|
||||||
private final static String[] DETAILS_TITLES = {
|
private final static String[] DETAILS_TITLES = {
|
||||||
|
@ -194,6 +197,9 @@ public class PlatformOrderShippingInvoiceService {
|
||||||
"Ventes 42j",
|
"Ventes 42j",
|
||||||
"Prix à l'unité",
|
"Prix à l'unité",
|
||||||
};
|
};
|
||||||
|
private final static String[] CUSTOM_FILE_TITLES = {
|
||||||
|
"SKU",
|
||||||
|
};
|
||||||
|
|
||||||
public Period getValidPeriod(List<String> shopIDs) {
|
public Period getValidPeriod(List<String> shopIDs) {
|
||||||
Date begin = platformOrderMapper.findEarliestUninvoicedPlatformOrder(shopIDs);
|
Date begin = platformOrderMapper.findEarliestUninvoicedPlatformOrder(shopIDs);
|
||||||
|
@ -618,6 +624,34 @@ public class PlatformOrderShippingInvoiceService {
|
||||||
System.gc();
|
System.gc();
|
||||||
return Files.readAllBytes(target);
|
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<String> 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)
|
* make shipping invoice by client and type (shipping or complete)
|
||||||
|
@ -829,6 +863,10 @@ public class PlatformOrderShippingInvoiceService {
|
||||||
}
|
}
|
||||||
return pathList.get(0).toString();
|
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 {
|
public String convertToPdf(String invoiceNumber, String fileType) throws Exception {
|
||||||
String excelFilePath = getInvoiceList(invoiceNumber, fileType);// (C:\PATH\filename.xlsx)
|
String excelFilePath = getInvoiceList(invoiceNumber, fileType);// (C:\PATH\filename.xlsx)
|
||||||
|
|
||||||
|
|
|
@ -241,6 +241,8 @@ jeecg:
|
||||||
shippingInvoicePdfDir: /wia/invoices/pdf/shipping
|
shippingInvoicePdfDir: /wia/invoices/pdf/shipping
|
||||||
shippingInvoiceDetailPdfDir: /wia/invoices/pdf/shippingDetail
|
shippingInvoiceDetailPdfDir: /wia/invoices/pdf/shippingDetail
|
||||||
invoiceDetailExportDir: /wia/invoices/invoiceDetailExport
|
invoiceDetailExportDir: /wia/invoices/invoiceDetailExport
|
||||||
|
|
||||||
|
customFileDir: /wia/invoices/custom
|
||||||
# sku csv file for image search
|
# sku csv file for image search
|
||||||
skuCsvPath: /mnt/wia/products/sku.csv
|
skuCsvPath: /mnt/wia/products/sku.csv
|
||||||
# CDG location
|
# CDG location
|
||||||
|
|
Loading…
Reference in New Issue