Browse Source

数量可以小数,小数位数自适应

ecss-tx
han\hanst 3 months ago
parent
commit
61e3c811f6
  1. 66
      src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java
  2. 29
      src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelServiceImpl.java
  3. 2
      src/main/resources/mapper/ecss/CoDelMapper.xml
  4. 2
      src/main/resources/mapper/ecss/EcssCommonMapper.xml
  5. BIN
      src/main/resources/templates/declaration-all-template-WOERMA-pdf.xlsx
  6. BIN
      src/main/resources/templates/declaration-all-template-WOERMA-upc-pdf.xlsx
  7. BIN
      src/main/resources/templates/declaration-all-template-WOERMA-upc.xlsx
  8. BIN
      src/main/resources/templates/declaration-all-template-WOERMA.xlsx
  9. BIN
      src/main/resources/templates/declaration-all-template-pdf.xlsx
  10. BIN
      src/main/resources/templates/declaration-all-template-upc-pdf.xlsx
  11. BIN
      src/main/resources/templates/declaration-all-template-upc.xlsx
  12. BIN
      src/main/resources/templates/declaration-all-template.xlsx
  13. BIN
      src/main/resources/templates/export-goods-template.xlsx

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

@ -9,6 +9,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -299,6 +300,14 @@ public class ExcelTemplate {
double num = Double.parseDouble(cleanResult);
if (Double.isFinite(num)) {
c.setCellValue(num); // 数值
// goods_total_qty 根据实际小数位动态设置格式
if ("${goods_total_qty}".equals(cellValue)) {
XSSFCellStyle fmtStyle = workbook.createCellStyle();
fmtStyle.cloneStyleFrom(c.getCellStyle());
DataFormat dataFormat = workbook.createDataFormat();
fmtStyle.setDataFormat(dataFormat.getFormat(buildDecimalFormat(num)));
c.setCellStyle(fmtStyle);
}
} else {
c.setCellValue(result); // 字符串
}
@ -419,11 +428,15 @@ public class ExcelTemplate {
style7.setVerticalAlignment(VerticalAlignment.TOP);
style7.setAlignment(HorizontalAlignment.RIGHT);
// 设置千分位格式
// 设置千分位格式根据单元格实际小数位动态决定格式
DataFormat dataFormat = workbook.createDataFormat();
style7.setDataFormat(i==6?dataFormat.getFormat("#,##0"):
i==7?dataFormat.getFormat("#,##0.00000")
:dataFormat.getFormat("#,##0.00"));
String numFmt;
if (c7.getCellType() == CellType.NUMERIC) {
numFmt = buildDecimalFormat(c7.getNumericCellValue());
} else {
numFmt = "#,##0.00";
}
style7.setDataFormat(dataFormat.getFormat(numFmt));
c7.setCellStyle(style7);
}
@ -478,14 +491,12 @@ public class ExcelTemplate {
style7.setVerticalAlignment(VerticalAlignment.TOP);
style7.setAlignment(HorizontalAlignment.RIGHT);
// 设置千分位格式
if (i==4 || i==5 || i==8) {
DataFormat dataFormat = workbook.createDataFormat();
style7.setDataFormat(dataFormat.getFormat("#,##0"));
} else {
DataFormat dataFormat = workbook.createDataFormat();
style7.setDataFormat(dataFormat.getFormat("#,##0.00"));
}
// 设置千分位格式根据单元格实际小数位动态决定格式
DataFormat dataFormat = workbook.createDataFormat();
String numFmt2 = (c7.getCellType() == CellType.NUMERIC)
? buildDecimalFormat(c7.getNumericCellValue())
: "#,##0.00";
style7.setDataFormat(dataFormat.getFormat(numFmt2));
c7.setCellStyle(style7);
}
}
@ -541,9 +552,12 @@ public class ExcelTemplate {
style7.setFont(font7);
style7.setVerticalAlignment(VerticalAlignment.CENTER);
style7.setAlignment(HorizontalAlignment.RIGHT);
// 设置千分位格式
// 设置千分位格式根据单元格实际小数位动态决定格式
DataFormat dataFormat = workbook.createDataFormat();
style7.setDataFormat(i==6?dataFormat.getFormat("#,##0"):dataFormat.getFormat("#,##0.00"));
String numFmt3 = (c7.getCellType() == CellType.NUMERIC)
? buildDecimalFormat(c7.getNumericCellValue())
: "#,##0.00";
style7.setDataFormat(dataFormat.getFormat(numFmt3));
c7.setCellStyle(style7);
}
}
@ -589,9 +603,12 @@ public class ExcelTemplate {
style7.setVerticalAlignment(VerticalAlignment.CENTER);
style7.setAlignment(HorizontalAlignment.RIGHT);
// 设置千分位格式
// 设置千分位格式根据单元格实际小数位动态决定格式
DataFormat dataFormat = workbook.createDataFormat();
style7.setDataFormat(dataFormat.getFormat("#,##0"));
String numFmt4 = (c7.getCellType() == CellType.NUMERIC)
? buildDecimalFormat(c7.getNumericCellValue())
: "#,##0";
style7.setDataFormat(dataFormat.getFormat(numFmt4));
c7.setCellStyle(style7);
}
}
@ -662,4 +679,21 @@ public class ExcelTemplate {
return workbook;
}
/**
* 根据数值的实际小数位数动态生成 Excel 数字格式串带千分位
* 1.0 "#,##0"12.34 "#,##0.00"0.00123 "#,##0.00000"
* 使用 Double.toString() BigDecimal 再去尾零避免浮点误差导致位数虚高
*/
private String buildDecimalFormat(double value) {
if (value == 0) {
return "#,##0";
}
BigDecimal bd = new BigDecimal(Double.toString(Math.abs(value))).stripTrailingZeros();
int scale = Math.max(0, bd.scale());
if (scale == 0) {
return "#,##0";
}
return "#,##0." + "0".repeat(scale);
}
}

29
src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelServiceImpl.java

@ -2601,7 +2601,7 @@ public class CoDelExcelServiceImpl implements CoDelExcelService {
// 每一个物料加属性对应一个属性用来下面遍历发货通知单明细时获取具体属性值
Map<String, List<PartSubPropertiesValueData>> partNoAndItemNoMap = propertiesValues.stream()
.collect(Collectors.groupingBy(PartSubPropertiesValue::getPropertiesItemNo));
int qty = ((BigDecimal)eorder.get("qty")).setScale(0, RoundingMode.HALF_UP).intValue();
BigDecimal qty = ((BigDecimal)eorder.get("qty")).setScale(6, RoundingMode.HALF_UP);
BigDecimal fscW = fscWeight(partNoAndItemNoMap,partNo, qty, nodifyData.getLossratio());
lossratio = (fscW.compareTo(BigDecimal.ZERO)>0?"\n"+"FSC Mix Credit SGSHK-COC-321321":"")+
"\n" + (nodifyData.getEhundred()!=null && StringUtils.isNotEmpty(nodifyData.getEhundred())
@ -2731,7 +2731,7 @@ public class CoDelExcelServiceImpl implements CoDelExcelService {
BigDecimal grossWeight = BigDecimal.valueOf(0.0);
BigDecimal netWeight = BigDecimal.valueOf(0.0);
BigDecimal rolls = BigDecimal.valueOf(0.0);
int totalQty = 0;
BigDecimal totalQty = BigDecimal.valueOf(0.0);
List<Map> exportList = new ArrayList<>();//全部需要导出的明细
EcssCoDelPalletHeaderData boxData = new EcssCoDelPalletHeaderData();
boxData.setSite(data.getSite());
@ -2749,10 +2749,10 @@ public class CoDelExcelServiceImpl implements CoDelExcelService {
for (int i = 0; i < checkList.size(); i++) {
Map eorder = checkList.get(i);
String partNo = (String) eorder.get("part_no");
int qty = ((BigDecimal)eorder.get("qty")).setScale(0, RoundingMode.HALF_UP).intValue();
totalQty = totalQty + qty;
BigDecimal qty = ((BigDecimal)eorder.get("qty")).setScale(6, RoundingMode.HALF_UP);
totalQty = totalQty.add(qty);
BigDecimal noCartons = list.get(m).get("box_qty")!=null?(BigDecimal) list.get(m).get("box_qty"):BigDecimal.ZERO;
eorder.put("total_qty", ((BigDecimal)eorder.get("qty")).setScale(0, RoundingMode.HALF_UP).intValue());
eorder.put("total_qty", ((BigDecimal)eorder.get("qty")).setScale(6, RoundingMode.HALF_UP));
// 合箱时第一行显示数值用于合并单元格居中显示
boolean isFirstRow = (i == 0);
eorder.put("noCartons", isFirstRow ? noCartons.setScale(0, RoundingMode.HALF_UP) : "");
@ -2845,7 +2845,7 @@ public class CoDelExcelServiceImpl implements CoDelExcelService {
template.addVar("total_weight", (grossWeight.add(palletWeight)).setScale(2, RoundingMode.HALF_UP));
template.addVar("total_netweight", netWeight.setScale(2, RoundingMode.HALF_UP));
template.addVar("total_box", totalCartons.setScale(0, RoundingMode.HALF_UP));
template.addVar("total_qty", totalQty);
template.addVar("goods_total_qty", totalQty);
template.addVar("total_rolls", rolls.setScale(0, RoundingMode.HALF_UP));
// 下面是可选的或者手动维护的
// RFID需要的
@ -3076,7 +3076,7 @@ public class CoDelExcelServiceImpl implements CoDelExcelService {
for (int i = 0; i < checkList.size(); i++) {
Map eorder = checkList.get(i);
String partNo = (String) eorder.get("part_no");
int qty = ((BigDecimal) eorder.get("qty")).setScale(0, RoundingMode.HALF_UP).intValue();
BigDecimal qty = ((BigDecimal) eorder.get("qty")).setScale(6, RoundingMode.HALF_UP);
eorder.put("total_qty", qty);
//totalQty += qty;
@ -3261,7 +3261,7 @@ public class CoDelExcelServiceImpl implements CoDelExcelService {
template.addVar("total_weight", (grossWeight.add(palletWeight)).setScale(2, RoundingMode.HALF_UP));
template.addVar("total_netweight", netWeight.setScale(2, RoundingMode.HALF_UP));
template.addVar("total_box", totalCartons.setScale(0, RoundingMode.HALF_UP));
template.addVar("total_qty", totalQty);
template.addVar("goods_total_qty", totalQty);
template.addVar("total_rolls", rolls.setScale(0, RoundingMode.HALF_UP));
// RFID和Label需要的额外信息
@ -3321,7 +3321,9 @@ public class CoDelExcelServiceImpl implements CoDelExcelService {
}
// 装箱明细
List<Map> palletDetailList = coDelMapper.exportCoDelPalletDetail(notifyHeader);
int totalQty=palletDetailList.stream().mapToInt(o -> Integer.parseInt(o.get("total_qty").toString())).sum();
BigDecimal totalQty = palletDetailList.stream()
.map(o -> new BigDecimal(o.get("total_qty").toString()))
.reduce(BigDecimal.ZERO, BigDecimal::add);
Map<Object, Map> palletMap = palletDetailList.stream().collect(Collectors.toMap( o -> o.get("part_no"), o -> o));
template.addVar("hs_code_desc", stringInput(nodifyDetailList.get(0).get("hsCodeDescEn")!=null?sbEn.toString():""));
String hsCodes = nodifyDetailList.stream()
@ -3371,7 +3373,7 @@ public class CoDelExcelServiceImpl implements CoDelExcelService {
totalPlt+"PLT("+ecHeader.getBoxQty()+"CTN)"):"");
template.addVar("price", ttlAmount.setScale(2, RoundingMode.HALF_UP));
template.addVar("total_qty", totalQty);
template.addVar("goods_total_qty", totalQty);
// 托盘重量=根据每个pallet的重量*数量累加
BigDecimal palletWeight = BigDecimal.ZERO;
for (EcssCoDelPalletHeaderData palletHeader : palletHeaderDataList) {
@ -3622,7 +3624,7 @@ public class CoDelExcelServiceImpl implements CoDelExcelService {
* 计算FSC纸重量
*/
private BigDecimal fscWeight(Map<String, List<PartSubPropertiesValueData>> partNoAndItemNoMap, String partNo,
int totalQty, String lossratio) {
BigDecimal totalQty, String lossratio) {
PartSubPropertiesValueData FSC001 = partNoAndItemNoMap.get("FSC001")==null?null:partNoAndItemNoMap.get("FSC001").get(0);//P距
PartSubPropertiesValueData FSC002 = partNoAndItemNoMap.get("FSC002")==null?null:partNoAndItemNoMap.get("FSC002").get(0);//排数
PartSubPropertiesValueData FSC003 = partNoAndItemNoMap.get("FSC003")==null?null:partNoAndItemNoMap.get("FSC003").get(0);//1米标签面积
@ -3661,13 +3663,12 @@ public class CoDelExcelServiceImpl implements CoDelExcelService {
return fscWeight.add(fscWeight2).setScale(2, RoundingMode.DOWN);
}
private BigDecimal getFSC(int totalQty, String lossratio,
private BigDecimal getFSC(BigDecimal totalQty, String lossratio,
BigDecimal bom, BigDecimal row, BigDecimal area, BigDecimal width, BigDecimal pju) {
BigDecimal fscWeight;
BigDecimal qianzhang = ((bom.divide(row,6, RoundingMode.HALF_UP)).multiply(pju)).
divide(BigDecimal.valueOf(1000),6, RoundingMode.HALF_UP);
fscWeight = qianzhang.multiply(BigDecimal.valueOf(totalQty).
divide(BigDecimal.valueOf(1000),6, RoundingMode.HALF_UP)).
fscWeight = qianzhang.multiply(totalQty.divide(BigDecimal.valueOf(1000),6, RoundingMode.HALF_UP)).
multiply(width.divide(BigDecimal.valueOf(1000),6, RoundingMode.HALF_UP)).
multiply(BigDecimal.valueOf(0.16)).
multiply(area.divide(width.divide(BigDecimal.valueOf(1000),6, RoundingMode.HALF_UP),6, RoundingMode.HALF_UP)).

2
src/main/resources/mapper/ecss/CoDelMapper.xml

@ -936,7 +936,7 @@ left join ecss_CoDelNotifyHeader noHeader on a.site=noHeader.site and a.delNo=no
)
SELECT
part_no,
CONVERT(DECIMAL(20, 0), SUM(qty)) as total_qty,
CONVERT(DECIMAL(20, 6), SUM(qty)) as total_qty,
CONVERT(DECIMAL(20, 0), SUM(DISTINCT box_qty)) as box_qty,
CONVERT(DECIMAL(20, 0), SUM(rolls)) as rolls,
-- 按数量比例分配净重和毛重

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

@ -132,7 +132,7 @@
<select id="searchEcssCoDelNotifyDetailList" resultType="java.util.Map">
select a.item_no,a.customerPO,a.part_no,a.part_description,a.currency,
CONVERT(DECIMAL(20, 0), a.qty) as qty,CONVERT(DECIMAL(20, 5), a.tp) as unitPrice,b.hsCode,
CONVERT(DECIMAL(20, 6), a.qty) as qty,CONVERT(DECIMAL(20, 5), a.tp) as unitPrice,b.hsCode,
a.upc,a.salesOrder as so,a.ttl_amount,a.pn,h.hsCodeDesc,h.hsCodeDescEn,a.cmc_comment,
CASE WHEN a.modifyFlag = 1 THEN '是' ELSE '否' END AS modifyFlag
from ecss_CoDelNotifydetail a

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

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

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

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

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

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

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

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

BIN
src/main/resources/templates/export-goods-template.xlsx

Loading…
Cancel
Save