Browse Source

箱单导出

java8
han\hanst 8 months ago
parent
commit
fcc9e08b1e
  1. 57
      src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java
  2. 5
      src/main/java/com/xujie/sys/modules/ecss/controller/CoDelController.java
  3. 2
      src/main/java/com/xujie/sys/modules/ecss/service/CoDelService.java
  4. 64
      src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java
  5. 7
      src/main/resources/mapper/ecss/EcssCommonMapper.xml
  6. BIN
      src/main/resources/templates/packing-template.xlsx

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

@ -43,6 +43,9 @@ public class ExcelTemplate {
// 报关单
@Setter
private boolean delRight = false;
// 箱单
@Setter
private boolean boxFlag = false;
private ExcelTemplate(){}
@ -183,6 +186,7 @@ public class ExcelTemplate {
}
List<Integer> dtlRows = new ArrayList<>();
List<Integer> boxRows = new ArrayList<>();
//整体填值
for (int i = 0; i <= sheet.getLastRowNum(); i++) {
XSSFRow row = sheet.getRow(i);
@ -202,6 +206,9 @@ public class ExcelTemplate {
if ("#{levy}".equals(cellValue)) {
dtlRows.add(i);
}
if ("#{cmcInvoice}".equals(cellValue)) {
boxRows.add(i);
}
Matcher matcherHdr = PATTERN_HDR_FIELD.matcher(cellValue);
String result = c.getStringCellValue();
while (matcherHdr.find()) {
@ -243,7 +250,7 @@ public class ExcelTemplate {
}
}
}
// 设置样式
if (cellStyle && dtlRowIndex >= 0 && i >= dtlRowIndex && i < dtlRowIndex + listVariables.size()) {
XSSFCellStyle style = c.getCellStyle();
@ -445,6 +452,54 @@ public class ExcelTemplate {
}
}
}
if (boxFlag) {
for (Integer dtlRow : boxRows) {
for (int i = 1; i < 6; i++) {
if (i==1 || i==4 || i==5) {
XSSFRow row = sheet.getRow(dtlRow);
if (row == null) {
continue;
}
XSSFCell c7 = row.getCell(i);
if (c7 == null) {
continue;
}
// 尝试把字符串转成数值
if (c7.getCellType() == CellType.STRING) {
String strVal = c7.getStringCellValue();
if (strVal != null && !strVal.trim().isEmpty()) {
try {
double num = Double.parseDouble(strVal.replace(",", ""));
c7.setCellValue(num); // 转换为数值写回
} catch (NumberFormatException e) {
// 如果不是数字就保留原字符串
System.out.println("非数字,保持原值: " + strVal);
}
}
}
// 创建样式
XSSFCellStyle style7 = workbook.createCellStyle();
style7.setBorderRight(BorderStyle.THIN);
style7.setBorderLeft(BorderStyle.THIN);
style7.setBorderBottom(BorderStyle.THIN);
style7.setBorderTop(BorderStyle.THIN);
Font font7 = workbook.createFont();
font7.setFontName("DengXian"); // 等线
font7.setFontHeightInPoints((short) 11); // 11号
style7.setFont(font7);
style7.setVerticalAlignment(VerticalAlignment.CENTER);
style7.setAlignment(HorizontalAlignment.RIGHT);
// 设置千分位格式
DataFormat dataFormat = workbook.createDataFormat();
style7.setDataFormat(dataFormat.getFormat("#,##0"));
c7.setCellStyle(style7);
}
}
}
}
return workbook;
}
}

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

@ -429,6 +429,11 @@ public class CoDelController {
coDelService.downloadPackingList(response, data);
}
@PostMapping("/exportPackingTemplate")
public void exportPackingTemplate(HttpServletResponse response, @RequestBody EcssCoDelNotifyHeaderData data) {
coDelService.exportPackingTemplate(response, data);
}
@PostMapping("/downloadExportGoods")
public void downloadExportGoods(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) {
coDelService.downloadExportGoods(response, data);

2
src/main/java/com/xujie/sys/modules/ecss/service/CoDelService.java

@ -125,6 +125,8 @@ public interface CoDelService {
void downloadPackingList(HttpServletResponse response, EcssDeclarationHeaderData data);
void exportPackingTemplate(HttpServletResponse response, EcssCoDelNotifyHeaderData data);
void downloadExportGoods(HttpServletResponse response, EcssDeclarationHeaderData data);
void downloadContract(HttpServletResponse response, EcssDeclarationHeaderData data);

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

@ -1729,6 +1729,70 @@ public class CoDelServiceImpl implements CoDelService {
}
}
/**
* 导出装箱数据导入模版
*/
@Override
public void exportPackingTemplate(HttpServletResponse response, EcssCoDelNotifyHeaderData data) {
try {
ExcelTemplate template = ExcelTemplate.load(new ClassPathResource("templates/packing-template.xlsx").getInputStream());
template.setBoxFlag(true);
// 获取装箱数据
List<Map<String, Object>> palletList = sqlSession.selectList("ecssMapper.searchCoDelPalletData", data);
if (palletList == null || palletList.isEmpty()) {
// 如果没有装箱数据获取通知单明细数据
palletList = sqlSession.selectList("ecssMapper.searchEcssCoDelNotifyDetail", data);
}
//计算总数和总箱数
int totalQty = 0;
int totalBoxQty = 0;
for (Map<String, Object> item : palletList) {
Object qtyObj = item.get("qty");
Object boxQtyObj = item.get("boxQty");
int qty = 0;
int boxQty = 0;
if (qtyObj instanceof Number) {
qty = ((Number) qtyObj).intValue();
} else if (qtyObj instanceof String) {
try {
qty = Integer.parseInt((String) qtyObj);
} catch (NumberFormatException e) {
qty = 0; // 或者根据需求处理异常
}
}
if (boxQtyObj instanceof Number) {
boxQty = ((Number) boxQtyObj).intValue();
} else if (boxQtyObj instanceof String) {
try {
boxQty = Integer.parseInt((String) boxQtyObj);
} catch (NumberFormatException e) {
boxQty = 0; // 或者根据需求处理异常
}
}
totalQty += qty;
totalBoxQty += boxQty;
item.put("qty", qty);
item.put("boxQty", boxQty);
}
template.addVar("totalQty", totalQty);
template.addVar("totalBox", totalBoxQty);
// 添加数据列表
template.addListVarAll( palletList);
try (XSSFWorkbook workbook = template.render(0)) {
workbook.write(response.getOutputStream());
}
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename=\"装箱数据导入模版.xlsx\"");
response.flushBuffer();
} catch (Exception e) {
log.error("导出装箱数据模版异常:{}", e.getMessage());
e.printStackTrace();
throw new RuntimeException("导出装箱数据模版异常:"+e.getMessage());
}
}
/**
* 导出出口货物委托书
*/

7
src/main/resources/mapper/ecss/EcssCommonMapper.xml

@ -32,7 +32,8 @@
</select>
<select id="searchEcssCoDelNotifyDetail" resultType="java.util.Map">
select a.*,#{cmcInvoice} as cmcInvoice,#{shippingMode} as shippingMode,#{destination} as destination
select a.*,#{cmcInvoice} as cmcInvoice,#{shippingMode} as shippingMode,#{destination} as destination,
CONVERT(varchar(10), #{readyDate}, 120) AS readyDate
from ecss_CoDelNotifydetail a
<where>
And a.site = #{site}
@ -44,9 +45,11 @@
<select id="searchCoDelPalletData" resultType="java.util.Map">
select b.po_no as customerPO,b.part_no,b.qty,
a.box_qty as boxQty,b.rolls,b.pn,a.gross_weight as grossWeight,a.net_weight as netWeight,
#{cmcInvoice} as cmcInvoice,#{shippingMode} as shippingMode,#{destination} as destination
#{cmcInvoice} as cmcInvoice,#{shippingMode} as shippingMode,#{destination} as destination,
c.remark,CONVERT(varchar(10), #{readyDate}, 120) AS readyDate
from ecss_CoDelBoxList a
left join ecss_CoDelPalletDetail b on a.site=b.site and a.bu_no=b.bu_no and a.delNo=b.delNo and a.item_no=b.seq_no
left join ecss_CoDelNotifydetail c on b.site=c.site and b.bu_no=c.bu_no and b.delNo=c.delNo and b.notify_detail_item_no=c.item_no
where a.site=#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo} and b.site is not null
</select>

BIN
src/main/resources/templates/packing-template.xlsx

Loading…
Cancel
Save