Browse Source

模版修改

java8
han\hanst 4 months ago
parent
commit
c5487a5955
  1. 76
      src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java
  2. 21
      src/main/java/com/xujie/sys/modules/ecss/controller/CoDelController.java
  3. 35
      src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java
  4. BIN
      src/main/resources/templates/declaration-all-seal-template.xlsx
  5. BIN
      src/main/resources/templates/declaration-all-template.xlsx
  6. BIN
      src/main/resources/templates/declaration-all2-template.xlsx
  7. BIN
      src/main/resources/templates/declaration-invoice-seal-template.xlsx
  8. BIN
      src/main/resources/templates/declaration-invoice2-template.xlsx
  9. BIN
      src/main/resources/templates/declaration-packingList2-template.xlsx

76
src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java

@ -74,8 +74,11 @@ public class ExcelTemplate {
moveShape = false; moveShape = false;
moveSeal = false; moveSeal = false;
cellStyle = false; cellStyle = false;
cellStyle2 = false;
rangeStyle = false; rangeStyle = false;
priceRight = false; priceRight = false;
intRight = false;
delRight = false;
} }
private boolean findAndRemoveMergedRegion(XSSFSheet sheet, int rowIndex) { private boolean findAndRemoveMergedRegion(XSSFSheet sheet, int rowIndex) {
@ -211,8 +214,18 @@ public class ExcelTemplate {
c.setCellValue(result); // 字符串 c.setCellValue(result); // 字符串
} else { } else {
try { try {
double num = Double.parseDouble(result.replace(",", ""));
c.setCellValue(num); // 数值
// 更严格的数字检查
String cleanResult = result.replace(",", "").trim();
if (!cleanResult.isEmpty() && !cleanResult.equals("-") && !cleanResult.equals(".")) {
double num = Double.parseDouble(cleanResult);
if (Double.isFinite(num)) {
c.setCellValue(num); // 数值
} else {
c.setCellValue(result); // 字符串
}
} else {
c.setCellValue(result); // 字符串
}
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
c.setCellValue(result); // 字符串 c.setCellValue(result); // 字符串
} }
@ -223,24 +236,29 @@ public class ExcelTemplate {
while (matcherDtl.find()) { while (matcherDtl.find()) {
for (int ri = 1; ri <= matcherDtl.groupCount(); ri++) { for (int ri = 1; ri <= matcherDtl.groupCount(); ri++) {
String field = matcherDtl.group(ri); String field = matcherDtl.group(ri);
c.setCellValue(cellValue.replace(matcherDtl.group(0), String.valueOf(listVariables.get(i - dtlRowIndex).getOrDefault(field, ""))));
// 检查数组边界避免越界异常
int listIndex = i - dtlRowIndex;
if (listIndex >= 0 && listIndex < listVariables.size()) {
c.setCellValue(cellValue.replace(matcherDtl.group(0), String.valueOf(listVariables.get(listIndex).getOrDefault(field, ""))));
}
} }
// 设置样式
if (cellStyle) {
XSSFCellStyle style = c.getCellStyle();
style.setBorderBottom(BorderStyle.NONE);
style.setBorderTop(BorderStyle.NONE);
style.setWrapText(true);
style.setAlignment(HorizontalAlignment.LEFT);
c.setCellStyle(style);
if (rangeStyle && j < 4) {
for (int mi = 0; mi < 3; mi++) {
XSSFCell nextc = sheet.getRow(i).getCell(c.getColumnIndex()+mi+1);
if (nextc == null) {
continue;
}
nextc.setCellStyle(style);
}
// 设置样式
if (cellStyle && dtlRowIndex >= 0 && i >= dtlRowIndex && i < dtlRowIndex + listVariables.size()) {
XSSFCellStyle style = c.getCellStyle();
style.setBorderBottom(BorderStyle.NONE);
style.setBorderTop(BorderStyle.NONE);
style.setWrapText(true);
style.setAlignment(HorizontalAlignment.LEFT);
c.setCellStyle(style);
if (rangeStyle && j < 4) {
for (int mi = 0; mi < 3; mi++) {
XSSFCell nextc = sheet.getRow(i).getCell(c.getColumnIndex()+mi+1);
if (nextc == null) {
continue;
} }
nextc.setCellStyle(style);
} }
} }
} }
@ -282,9 +300,13 @@ public class ExcelTemplate {
style2.setAlignment(HorizontalAlignment.LEFT); style2.setAlignment(HorizontalAlignment.LEFT);
style2.setWrapText(true); style2.setWrapText(true);
c2.setCellStyle(style2); c2.setCellStyle(style2);
if (priceRight) { //仅供发票excel使用89是价格列居右
if (priceRight) { //仅供发票excel使用678是价格列居右
for (int i = 6; i < 9; i++) { for (int i = 6; i < 9; i++) {
XSSFCell c7 = sheet.getRow(dtlRow).getCell(i);
XSSFRow row = sheet.getRow(dtlRow);
if (row == null) {
continue;
}
XSSFCell c7 = row.getCell(i);
if (c7 == null) { if (c7 == null) {
continue; continue;
} }
@ -326,11 +348,14 @@ public class ExcelTemplate {
c7.setCellStyle(style7); c7.setCellStyle(style7);
} }
} }
if (intRight) { //仅供箱单excel使用 if (intRight) { //仅供箱单excel使用
for (int i = 4; i < 9; i++) { for (int i = 4; i < 9; i++) {
XSSFCell c7 = sheet.getRow(dtlRow).getCell(i);
XSSFRow row = sheet.getRow(dtlRow);
if (row == null) {
continue;
}
XSSFCell c7 = row.getCell(i);
if (c7 == null) { if (c7 == null) {
continue; continue;
} }
@ -372,7 +397,6 @@ public class ExcelTemplate {
} }
c7.setCellStyle(style7); c7.setCellStyle(style7);
} }
} }
} }
} }
@ -380,7 +404,11 @@ public class ExcelTemplate {
for (Integer dtlRow : dtlRows) { for (Integer dtlRow : dtlRows) {
for (int i = 6; i < 12; i++) { for (int i = 6; i < 12; i++) {
if (i==6 || i==11) { if (i==6 || i==11) {
XSSFCell c7 = sheet.getRow(dtlRow).getCell(i);
XSSFRow row = sheet.getRow(dtlRow);
if (row == null) {
continue;
}
XSSFCell c7 = row.getCell(i);
if (c7 == null) { if (c7 == null) {
continue; continue;
} }

21
src/main/java/com/xujie/sys/modules/ecss/controller/CoDelController.java

@ -405,45 +405,38 @@ public class CoDelController {
} }
@PostMapping("/downloadDeclarationElements") @PostMapping("/downloadDeclarationElements")
public R downloadDeclarationElements(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
public void downloadDeclarationElements(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
coDelService.downloadDeclarationElements(response, data); coDelService.downloadDeclarationElements(response, data);
return R.ok();
} }
@PostMapping("/downloadDeclaration") @PostMapping("/downloadDeclaration")
public R downloadDeclaration(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
public void downloadDeclaration(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
coDelService.downloadDeclaration(response, data); coDelService.downloadDeclaration(response, data);
return R.ok();
} }
@PostMapping("/downloadInvoice") @PostMapping("/downloadInvoice")
public R downloadInvoice(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
public void downloadInvoice(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
coDelService.downloadInvoice(response, data); coDelService.downloadInvoice(response, data);
return R.ok();
} }
@PostMapping("/downloadPackingList") @PostMapping("/downloadPackingList")
public R downloadPackingList(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
public void downloadPackingList(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
coDelService.downloadPackingList(response, data); coDelService.downloadPackingList(response, data);
return R.ok();
} }
@PostMapping("/downloadExportGoods") @PostMapping("/downloadExportGoods")
public R downloadExportGoods(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
public void downloadExportGoods(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
coDelService.downloadExportGoods(response, data); coDelService.downloadExportGoods(response, data);
return R.ok();
} }
@PostMapping("/downloadContract") @PostMapping("/downloadContract")
public R downloadContract(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
public void downloadContract(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
coDelService.downloadContract(response, data); coDelService.downloadContract(response, data);
return R.ok();
} }
@PostMapping("/downloadAll") @PostMapping("/downloadAll")
public R downloadAll(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
public void downloadAll(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
coDelService.downloadAll(response, data); coDelService.downloadAll(response, data);
return R.ok();
} }
@PostMapping("/saveOneClickPacking") @PostMapping("/saveOneClickPacking")

35
src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java

@ -1604,34 +1604,41 @@ public class CoDelServiceImpl implements CoDelService {
XSSFWorkbook workbook = null; XSSFWorkbook workbook = null;
try { try {
ExcelTemplate template = ExcelTemplate.load(new ClassPathResource(xlsx).getInputStream()); ExcelTemplate template = ExcelTemplate.load(new ClassPathResource(xlsx).getInputStream());
// 第一个sheet - 出口货物委托书
extractedExportGoods(data, template); extractedExportGoods(data, template);
workbook = template.render(0); workbook = template.render(0);
// 出口货物委托书发票箱单报关单申报要素
// 开始第二个sheet 发票
// 第二个sheet - 发票
template.clearAll(); template.clearAll();
extractedInvoice(data, template,notifyHeader);
workbook = template.render(1);
// 第三个sheet 箱单
extractedInvoice(data, template, notifyHeader);
template.render(1);
// 第三个sheet - 箱单
template.clearAll(); template.clearAll();
exportPackingList(data, template,notifyHeader,0);
workbook = template.render(2);
// 第四个sheet 报关单
exportPackingList(data, template, notifyHeader, 0);
template.render(2);
// 第四个sheet - 报关单
template.clearAll(); template.clearAll();
extractedDeclaration(data, template); extractedDeclaration(data, template);
workbook = template.render(3);
// 第五个sheet 申报要素
template.render(3);
// 第五个sheet - 申报要素
template.clearAll(); template.clearAll();
extractedElements(data, template); extractedElements(data, template);
workbook = template.render(4);
// 第六个sheet 合同
template.render(4);
// 第六个sheet - 合同 (仅特定BU需要)
if (notifyHeader.getBuNo().equals("04-MHM") || notifyHeader.getBuNo().equals("02-Hardtag")) { if (notifyHeader.getBuNo().equals("04-MHM") || notifyHeader.getBuNo().equals("02-Hardtag")) {
template.clearAll(); template.clearAll();
extractedContract(data, template); extractedContract(data, template);
workbook = template.render(5);
template.render(5);
} }
workbook.write(response.getOutputStream());
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename=\"单证信息.xlsx\""); response.setHeader("Content-Disposition", "attachment; filename=\"单证信息.xlsx\"");
workbook.write(response.getOutputStream());
response.flushBuffer(); response.flushBuffer();
} catch (IOException e) { } catch (IOException e) {
log.error("报关导出所有异常:{}", e.getMessage()); log.error("报关导出所有异常:{}", e.getMessage());

BIN
src/main/resources/templates/declaration-all-seal-template.xlsx

BIN
src/main/resources/templates/declaration-all-template.xlsx

BIN
src/main/resources/templates/declaration-all2-template.xlsx

BIN
src/main/resources/templates/declaration-invoice-seal-template.xlsx

BIN
src/main/resources/templates/declaration-invoice2-template.xlsx

BIN
src/main/resources/templates/declaration-packingList2-template.xlsx

Loading…
Cancel
Save