demand: 海运账单bug修改

committer: heyu
This commit is contained in:
aike 2025-04-24 18:18:36 +08:00
parent e5b46b3846
commit 0648f44ccc
2 changed files with 110 additions and 37 deletions

View File

@ -4,7 +4,7 @@ import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext; import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
import com.alibaba.excel.write.metadata.style.WriteCellStyle; import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont; import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; import com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
/** /**
@ -13,8 +13,7 @@ import org.apache.poi.ss.usermodel.*;
* @Description CellStyleStrategy * @Description CellStyleStrategy
* @createTime 2025年04月09日 * @createTime 2025年04月09日
*/ */
public class CellStyleStrategy extends HorizontalCellStyleStrategy { public class CellStyleStrategy extends AbstractVerticalCellStyleStrategy {
private final WriteCellStyle headWriteCellStyle; private final WriteCellStyle headWriteCellStyle;
@ -74,8 +73,34 @@ public class CellStyleStrategy extends HorizontalCellStyleStrategy {
WriteCellStyle.merge(this.headWriteCellStyle, cellData.getOrCreateStyle()); WriteCellStyle.merge(this.headWriteCellStyle, cellData.getOrCreateStyle());
} }
@Override
protected void setContentCellStyle(CellWriteHandlerContext context) { protected void setContentCellStyle(CellWriteHandlerContext context) {
// 设置行高
context.getRow().setHeight((short) (23 * 20)); context.getRow().setHeight((short) (23 * 20));
if (stopProcessing(context)) {
return;
}
// 获取或创建单元格样式
WriteCellData<?> cellData = context.getFirstCellData();
WriteCellStyle writeCellStyle = cellData.getOrCreateStyle();
// 设置边框样式
writeCellStyle.setBorderTop(BorderStyle.THIN);
writeCellStyle.setBorderRight(BorderStyle.THIN);
writeCellStyle.setBorderBottom(BorderStyle.THIN);
writeCellStyle.setBorderLeft(BorderStyle.THIN);
// 设置对齐方式
writeCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
writeCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
// 设置字体
WriteFont writeFont = new WriteFont();
writeFont.setFontName("微软雅黑");
writeFont.setFontHeightInPoints((short) 8);
writeCellStyle.setWriteFont(writeFont);
} }
private void setRowStyle(CellWriteHandlerContext context, short height, short fontSize, short fontColor, boolean isBold, short backgroundColor) { private void setRowStyle(CellWriteHandlerContext context, short height, short fontSize, short fontColor, boolean isBold, short backgroundColor) {

View File

@ -40,6 +40,7 @@ import com.xdadan.erp.emis.service.EmisBaseService;
import com.xdadan.erp.emis.service.excelCellStrategy.CellStyleStrategy; import com.xdadan.erp.emis.service.excelCellStrategy.CellStyleStrategy;
import com.xdadan.erp.emis.service.excelCellStrategy.CustomCellWriteHandler; import com.xdadan.erp.emis.service.excelCellStrategy.CustomCellWriteHandler;
import com.xdadan.erp.emis.utils.WaybillHelper; import com.xdadan.erp.emis.utils.WaybillHelper;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
@ -833,7 +834,6 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
return 1; return 1;
} }
@Override @Override
public void exportSeaWayBill(HttpServletResponse response, EmisSettleBill emisSettleBill) { public void exportSeaWayBill(HttpServletResponse response, EmisSettleBill emisSettleBill) {
try { try {
@ -845,20 +845,27 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
EmisSettleBill bill = emisBaseService.getSettleBillBySettleBillNo(emisSettleBill.getSettleBillNo()); EmisSettleBill bill = emisBaseService.getSettleBillBySettleBillNo(emisSettleBill.getSettleBillNo());
// 子账单 // 子账单
List<EmisSettleSubBill> list = emisBaseService.selectSubBillListBySettleBillNo(emisSettleBill.getSettleBillNo()); List<EmisSettleSubBill> list = emisBaseService
.selectSubBillListBySettleBillNo(emisSettleBill.getSettleBillNo());
// 运单号 // 运单号
List<String> billCodeList = list.stream() List<String> billCodeList = list.stream()
.map(EmisSettleSubBill::getBillCode) .map(EmisSettleSubBill::getBillCode)
.collect(Collectors.toList()); .collect(Collectors.toList());
if (org.springframework.util.CollectionUtils.isEmpty(list) || org.springframework.util.CollectionUtils.isEmpty(billCodeList)) { if (CollectionUtils.isEmpty(list)
|| CollectionUtils.isEmpty(billCodeList)) {
return; return;
} }
// 结算对象
String settlement = Optional.ofNullable(list.get(0)).map(e -> StringUtil.isNotBlank(e.getCustName()) ? e.getCustName() : e.getCustomerName()).orElse("");
// 根据运单号查询运单详情 // 根据运单号查询运单详情
List<EmisWaybillAndFeeitem> emisWaybills = emisSettleSubBillFeeitemMapper.selectEmisWaybillListByBillCodeList(billCodeList); List<EmisWaybillAndFeeitem> emisWaybills = emisSettleSubBillFeeitemMapper
Map<String, EmisWaybillAndFeeitem> emisWaybillMap = emisWaybills.stream().collect(Collectors.toMap(EmisWaybillAndFeeitem::getBillCode, i -> i)); .selectEmisWaybillListByBillCodeList(billCodeList);
if (MapUtil.isEmpty(emisWaybillMap) || org.springframework.util.CollectionUtils.isEmpty(emisWaybills)) { Map<String, EmisWaybillAndFeeitem> emisWaybillMap = emisWaybills.stream()
.collect(Collectors.toMap(EmisWaybillAndFeeitem::getBillCode, i -> i));
if (MapUtil.isEmpty(emisWaybillMap) || CollectionUtils.isEmpty(emisWaybills)) {
return; return;
} }
log.info("select emisWaybills is success, emisWaybills,{}", emisWaybills); log.info("select emisWaybills is success, emisWaybills,{}", emisWaybills);
@ -866,7 +873,24 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
// 运单费用条目 // 运单费用条目
List<EmisSettleSubBillFeeitem> emisWaybillFeeitemList = new ArrayList<>(); List<EmisSettleSubBillFeeitem> emisWaybillFeeitemList = new ArrayList<>();
emisWaybills.forEach(emisWaybill -> { emisWaybills.forEach(emisWaybill -> {
if (Objects.nonNull(emisWaybill) && CollectionUtil.isNotEmpty(emisWaybill.getSettleSubBillFeeitemList())) { // 一口价运单特殊处理
EmisWaybill waybill = null;
String billCode = emisWaybill.getBillCode();
if(StringUtil.isNotBlank(billCode)) {
waybill = emisWaybillMapper.selectEmisWaybillByBillCode(billCode);
}
if (waybill != null && "3".equals(waybill.getCalcFeeType()) && CollectionUtil.isNotEmpty(emisWaybill.getSettleSubBillFeeitemList())) {
EmisSettleSubBillFeeitem emisSettleSubBillFeeitem = emisWaybill.getSettleSubBillFeeitemList().get(0);
emisSettleSubBillFeeitem.setFeeName("运输费");
emisSettleSubBillFeeitem.setCurrency("CNY");
List<EmisSettleSubBill> bills = list.stream().filter(i -> billCode.equals(i.getBillCode())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(bills) && (bills.get(0) != null && (bills.get(0).getBillFee() != null))) {
emisSettleSubBillFeeitem.setBillFee(bills.get(0).getBillFee());
}
}
if (Objects.nonNull(emisWaybill)
&& CollectionUtil.isNotEmpty(emisWaybill.getSettleSubBillFeeitemList())) {
emisWaybillFeeitemList.addAll(emisWaybill.getSettleSubBillFeeitemList()); emisWaybillFeeitemList.addAll(emisWaybill.getSettleSubBillFeeitemList());
} }
}); });
@ -893,21 +917,26 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
ExcelWriter excelWriter = EasyExcel.write(outputStream).excelType(ExcelTypeEnum.XLSX).build(); ExcelWriter excelWriter = EasyExcel.write(outputStream).excelType(ExcelTypeEnum.XLSX).build();
List<List<String>> contentHeader = this.buildHeader(); List<List<String>> contentHeader = this.buildHeader();
HorizontalCellStyleStrategy horizontalCellStyleStrategy = HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(null,
new HorizontalCellStyleStrategy(null, contentWriteCellStyle); contentWriteCellStyle);
// 构建大表头 // 构建大表头
WriteSheet writeSheet1 = EasyExcel.writerSheet("sheet").needHead(Boolean.FALSE) WriteSheet writeSheet1 = EasyExcel.writerSheet("sheet").needHead(Boolean.FALSE)
.registerWriteHandler(horizontalCellStyleStrategy) .registerWriteHandler(horizontalCellStyleStrategy)
.registerWriteHandler(new CellStyleStrategy(new WriteCellStyle())).build(); .registerWriteHandler(new CellStyleStrategy(new WriteCellStyle())).build();
List<List<String>> header1 = contentHeader.stream().map(item -> Collections.singletonList("探路供应链(上海)")).collect(Collectors.toList()); List<List<String>> header1 = contentHeader.stream().map(item -> Collections.singletonList("探路供应链(上海)"))
.collect(Collectors.toList());
WriteTable t1 = EasyExcel.writerTable(0).needHead(Boolean.TRUE).head(header1).build(); WriteTable t1 = EasyExcel.writerTable(0).needHead(Boolean.TRUE).head(header1).build();
excelWriter.write((Collection<?>) null, writeSheet1, t1); excelWriter.write((Collection<?>) null, writeSheet1, t1);
List<List<String>> header2 = contentHeader.stream().map(item -> Collections.singletonList(year + "年" + month + "月海运费确认书")).collect(Collectors.toList()); List<List<String>> header2 = contentHeader.stream()
.map(item -> Collections.singletonList(year + "年" + month + "月海运费确认书"))
.collect(Collectors.toList());
WriteTable t2 = EasyExcel.writerTable(1).needHead(Boolean.TRUE).head(header2).build(); WriteTable t2 = EasyExcel.writerTable(1).needHead(Boolean.TRUE).head(header2).build();
excelWriter.write((Collection<?>) null, writeSheet1, t2); excelWriter.write((Collection<?>) null, writeSheet1, t2);
List<List<String>> header3 = contentHeader.stream().map(item -> Collections.singletonList("结算对象:探路供应链公司")).collect(Collectors.toList()); List<List<String>> header3 = contentHeader.stream()
.map(item -> Collections.singletonList("结算对象:" + settlement))
.collect(Collectors.toList());
header3.set(9, Collections.singletonList("出账日期:" + date)); header3.set(9, Collections.singletonList("出账日期:" + date));
header3.set(10, Collections.singletonList("出账日期:" + date)); header3.set(10, Collections.singletonList("出账日期:" + date));
header3.set(11, Collections.singletonList("出账日期:" + date)); header3.set(11, Collections.singletonList("出账日期:" + date));
@ -926,12 +955,14 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
List<EmisSettleSubBillFeeitem> settleSubBillFeeitemList = emisWaybill.getSettleSubBillFeeitemList(); List<EmisSettleSubBillFeeitem> settleSubBillFeeitemList = emisWaybill.getSettleSubBillFeeitemList();
calculateSubtotal(settleSubBillFeeitemList, subtotalMap); calculateSubtotal(settleSubBillFeeitemList, subtotalMap);
settleSubBillFeeitemList.forEach(item -> { settleSubBillFeeitemList.forEach(item -> {
result.add(Lists.newArrayList(emisWaybill.getLadingBillCode(), emisWaybill.getBillCode(), emisWaybill.getCompanyCode(), emisWaybill.getDeparturePort(), result.add(Lists.newArrayList(emisWaybill.getLadingBillCode(), emisWaybill.getBillCode(),
emisWaybill.getDestinationPort(), emisWaybill.getBoxQuantity(), String.valueOf(emisWaybill.getParcelQty()), emisWaybill.getCompanyCode(), emisWaybill.getDeparturePort(),
emisWaybill.getDestinationPort(), emisWaybill.getBoxQuantity(),
String.valueOf(emisWaybill.getParcelQty()),
emisWaybill.getBillWeight().stripTrailingZeros().toPlainString(), emisWaybill.getBillWeight().stripTrailingZeros().toPlainString(),
emisWaybill.getTotalVolume().stripTrailingZeros().toPlainString(), emisWaybill.getTotalVolume().stripTrailingZeros().toPlainString(),
item.getFeeName(), item.getCurrency(), item.getBillFee().stripTrailingZeros().toPlainString() item.getFeeName(), item.getCurrency(),
)); item.getBillFee().stripTrailingZeros().toPlainString()));
}); });
// 小表头 // 小表头
WriteSheet sheet = EasyExcel.writerSheet("sheet") WriteSheet sheet = EasyExcel.writerSheet("sheet")
@ -941,27 +972,41 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
excelWriter.write((Collection<?>) null, sheet, writeTable0); excelWriter.write((Collection<?>) null, sheet, writeTable0);
// 行数据 // 行数据
WriteTable writeTable1 = EasyExcel.writerTable(num + 1).needHead(Boolean.TRUE).head(contentHeader).build(); WriteTable writeTable1 = EasyExcel.writerTable(num + 1).needHead(Boolean.TRUE).head(contentHeader)
.build();
excelWriter.write(result, writeSheet1, writeTable1); excelWriter.write(result, writeSheet1, writeTable1);
log.info("Building the first row is success"); log.info("Building the first row is success");
// 小计 // 小计
List<List<String>> nameHeader2 = contentHeader.stream().map(item -> Collections.singletonList("小计: USD金额:" + subtotalMap.get("usdSubtotal") + " CNY金额:" + subtotalMap.get("cnySubtotal"))).collect(Collectors.toList()); if (MapUtil.isNotEmpty(subtotalMap)) {
WriteTable writeTable2 = EasyExcel.writerTable(num + 2).needHead(Boolean.TRUE).head(nameHeader2).build(); List<List<String>> nameHeader2 = contentHeader.stream()
.map(item -> Collections.singletonList("小计: USD金额:" + subtotalMap.get("usdSubtotal")
+ " CNY金额:" + subtotalMap.get("cnySubtotal")))
.collect(Collectors.toList());
WriteTable writeTable2 = EasyExcel.writerTable(num + 2).needHead(Boolean.TRUE).head(nameHeader2)
.build();
excelWriter.write((Collection<?>) null, writeSheet1, writeTable2); excelWriter.write((Collection<?>) null, writeSheet1, writeTable2);
}
num = num + 2; num = num + 2;
} }
// 总计 // 总计
List<List<String>> nameHeader3 = contentHeader.stream().map(item -> Collections.singletonList("总计: USD金额:" + textMap.get("usdTotal") + " CNY金额:" + textMap.get("cnyTotal"))).collect(Collectors.toList()); if (MapUtil.isNotEmpty(textMap)) {
WriteTable writeTable3 = EasyExcel.writerTable(num + 1).needHead(Boolean.TRUE).head(nameHeader3).build(); List<List<String>> nameHeader3 = contentHeader.stream()
.map(item -> Collections.singletonList(
"总计: USD金额:" + textMap.get("usdTotal") + " CNY金额:" + textMap.get("cnyTotal")))
.collect(Collectors.toList());
WriteTable writeTable3 = EasyExcel.writerTable(num + 1).needHead(Boolean.TRUE).head(nameHeader3)
.build();
excelWriter.write((Collection<?>) null, writeSheet1, writeTable3); excelWriter.write((Collection<?>) null, writeSheet1, writeTable3);
}
log.info("exportSeaWayBill is success"); log.info("exportSeaWayBill is success");
// 设置响应头信息 // 设置响应头信息
String fileName = bill.getSettleBillName() + "_海运账单.xlsx"; String fileName = bill.getSettleBillName() + "_海运账单.xlsx";
response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.name())); response.setHeader("Content-Disposition",
"attachment;filename*=utf-8''" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()));
response.setContentType("application/octet-stream"); response.setContentType("application/octet-stream");
// 关流 // 关流
excelWriter.finish(); excelWriter.finish();
@ -988,10 +1033,10 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
return header; return header;
} }
private static void calculateTotal(List<EmisSettleSubBillFeeitem> emisWaybillFeeitemList,
Map<String, Object> textMap) {
private static void calculateTotal(List<EmisSettleSubBillFeeitem> emisWaybillFeeitemList, Map<String, Object> textMap) {
Map<String, List<EmisSettleSubBillFeeitem>> emisWaybillFeeitemMap = emisWaybillFeeitemList.stream() Map<String, List<EmisSettleSubBillFeeitem>> emisWaybillFeeitemMap = emisWaybillFeeitemList.stream()
.filter(i -> StringUtil.isNotBlank(i.getCurrency()))
.collect(Collectors.groupingBy(EmisSettleSubBillFeeitem::getCurrency)); .collect(Collectors.groupingBy(EmisSettleSubBillFeeitem::getCurrency));
if (MapUtil.isNotEmpty(emisWaybillFeeitemMap)) { if (MapUtil.isNotEmpty(emisWaybillFeeitemMap)) {
@ -1012,8 +1057,10 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
} }
} }
private static void calculateSubtotal(List<EmisSettleSubBillFeeitem> emisWaybillFeeitemList, Map<String, Object> textMap) { private static void calculateSubtotal(List<EmisSettleSubBillFeeitem> emisWaybillFeeitemList,
Map<String, Object> textMap) {
Map<String, List<EmisSettleSubBillFeeitem>> emisWaybillFeeitemMap = emisWaybillFeeitemList.stream() Map<String, List<EmisSettleSubBillFeeitem>> emisWaybillFeeitemMap = emisWaybillFeeitemList.stream()
.filter(i -> StringUtil.isNotBlank(i.getCurrency()))
.collect(Collectors.groupingBy(EmisSettleSubBillFeeitem::getCurrency)); .collect(Collectors.groupingBy(EmisSettleSubBillFeeitem::getCurrency));
if (MapUtil.isNotEmpty(emisWaybillFeeitemMap)) { if (MapUtil.isNotEmpty(emisWaybillFeeitemMap)) {
@ -1034,7 +1081,8 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
} }
} }
private static void countA(String key, Map<String, Object> textMap, String usdSubtotal, String count, String cnySubtotal) { private static void countA(String key, Map<String, Object> textMap, String usdSubtotal, String count,
String cnySubtotal) {
if ("USD".equals(key)) { if ("USD".equals(key)) {
textMap.put(usdSubtotal, count); textMap.put(usdSubtotal, count);
} else { } else {
@ -1042,7 +1090,8 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
} }
} }
private static void countB(String key, Map<String, Object> textMap, String usdSubtotal, String count, String cnySubtotal) { private static void countB(String key, Map<String, Object> textMap, String usdSubtotal, String count,
String cnySubtotal) {
if ("USD".equals(key)) { if ("USD".equals(key)) {
textMap.put(usdSubtotal, count); textMap.put(usdSubtotal, count);
textMap.put(cnySubtotal, "0"); textMap.put(cnySubtotal, "0");
@ -1052,7 +1101,6 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
} }
} }
/** /**
* 修改结算总账单 * 修改结算总账单
* *