|
@@ -28,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -150,23 +151,23 @@ public class PackingBillPdfServiceImpl implements IPackingBillPdfService {
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<Integer, List<JSONObject>> getPackingProduct(BillProve billProve) {
|
|
|
- //通过批次号查询装箱产品
|
|
|
+ // 通过批次号查询装箱产品
|
|
|
List<ShipmentPackingProduct> packingProducts = iShipmentPackingProductService.getByBatchCode(billProve.getTenantId(), billProve.getBatchCode());
|
|
|
if (CollectionUtils.isEmpty(packingProducts)) {
|
|
|
return new HashMap<>();
|
|
|
}
|
|
|
Map<String, List<ShipmentPackingProduct>> map = new HashMap<>();
|
|
|
- //按照箱子id分组
|
|
|
+ // 按照箱子id分组
|
|
|
Map<String, List<ShipmentPackingProduct>> collect = packingProducts.stream().collect(Collectors.groupingBy(ShipmentPackingProduct::getShipmentPackingId));
|
|
|
for (Map.Entry<String, List<ShipmentPackingProduct>> entry : collect.entrySet()) {
|
|
|
List<ShipmentPackingProduct> value = entry.getValue();
|
|
|
- //按照产品id排序,避免不同箱子相同产品、数量顺序不一样
|
|
|
+ // 按照产品id排序,避免不同箱子相同产品、数量顺序不一样
|
|
|
value = value.stream().sorted(Comparator.comparing(ShipmentPackingProduct::getProductId)).collect(Collectors.toList());
|
|
|
|
|
|
- //这个箱子所有的产品、数量key,key=产品id-数量(id-10,id-20,id-30),多个产品","分割
|
|
|
+ // 这个箱子所有的产品、数量key,key=产品id-数量(id-10,id-20,id-30),多个产品","分割
|
|
|
String key = "";
|
|
|
if (StringUtil.equalsIgnoreCase(AuthUtil.getTenantId(), "GOLDSUN")) {
|
|
|
- //装箱尺寸
|
|
|
+ // 装箱尺寸
|
|
|
Double packagLong = 0.00;
|
|
|
Double packagWide = 0.00;
|
|
|
Double packagHigh = 0.00;
|
|
@@ -184,20 +185,20 @@ public class PackingBillPdfServiceImpl implements IPackingBillPdfService {
|
|
|
}
|
|
|
|
|
|
String finalOverallDimensions = overallDimensions;
|
|
|
- //这个箱子所有的产品、数量key,key=产品id-数量(id-10,id-20,id-30),多个产品","分割
|
|
|
+ // 这个箱子所有的产品、数量key,key=产品id-数量(id-10,id-20,id-30),多个产品","分割
|
|
|
key = value.stream().map(obj -> obj.getProductId() + "-" + obj.getQuantity() + "-" + finalOverallDimensions).distinct().collect(Collectors.joining(","));
|
|
|
} else {
|
|
|
- //这个箱子所有的产品、数量key,key=产品id-数量(id-10,id-20,id-30),多个产品","分割
|
|
|
+ // 这个箱子所有的产品、数量key,key=产品id-数量(id-10,id-20,id-30),多个产品","分割
|
|
|
key = value.stream().map(obj -> obj.getProductId() + "-" + obj.getQuantity()).distinct().collect(Collectors.joining(","));
|
|
|
}
|
|
|
|
|
|
- //根据key从map中获取是否存在
|
|
|
+ // 根据key从map中获取是否存在
|
|
|
List<ShipmentPackingProduct> list = map.get(key);
|
|
|
- if (list == null || list.size() <= 0) {
|
|
|
- //不存在,存入
|
|
|
+ if (list == null || list.size() == 0) {
|
|
|
+ // 不存在,存入
|
|
|
map.put(key, value);
|
|
|
} else {
|
|
|
- //箱子的产品+数量完全相同存放在一起
|
|
|
+ // 箱子的产品+数量完全相同存放在一起
|
|
|
list.addAll(value);
|
|
|
}
|
|
|
}
|
|
@@ -210,26 +211,30 @@ public class PackingBillPdfServiceImpl implements IPackingBillPdfService {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
List<JSONObject> values = new ArrayList<>();
|
|
|
|
|
|
- //根据产品id-数量去重
|
|
|
- ArrayList<ShipmentPackingProduct> products = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(obj -> obj.getProductId() + "-" + obj.getQuantity()))), ArrayList::new));
|
|
|
+ // 根据产品id-数量去重
|
|
|
+ ArrayList<ShipmentPackingProduct> products = list.stream()
|
|
|
+ .collect(Collectors.collectingAndThen(
|
|
|
+ Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(obj -> obj.getProductId() + "-" + obj.getQuantity()))),
|
|
|
+ ArrayList::new)
|
|
|
+ );
|
|
|
|
|
|
- //总箱数,根据箱子id去重
|
|
|
+ // 总箱数,根据箱子id去重
|
|
|
// long boxTotal = list.stream().map(ShipmentPackingProduct::getShipmentPackingId).distinct().count();
|
|
|
ArrayList<ShipmentPackingProduct> box = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(obj -> obj.getShipmentPackingId()))), ArrayList::new));
|
|
|
long boxTotal = box.stream().filter(obj -> obj.getTotalBoxes() != null).mapToInt(ShipmentPackingProduct::getTotalBoxes).sum();
|
|
|
jsonObject.put("boxTotal", boxTotal);
|
|
|
|
|
|
- //总数量
|
|
|
+ // 总数量
|
|
|
Integer allQuantity = 0;
|
|
|
- //装箱尺寸
|
|
|
+ // 装箱尺寸
|
|
|
Double packagLong = 0.00;
|
|
|
Double packagWide = 0.00;
|
|
|
Double packagHigh = 0.00;
|
|
|
for (ShipmentPackingProduct product : products) {
|
|
|
if (boxTotal > 0) {
|
|
|
- //产品总数量=·装箱数量*箱数
|
|
|
- Long totalNum = product.getQuantity() * boxTotal;
|
|
|
- product.setTotalNum(totalNum.intValue());
|
|
|
+ // 产品总数量=·装箱数量*箱数
|
|
|
+ long totalNum = product.getQuantity() * boxTotal;
|
|
|
+ product.setTotalNum((int) totalNum);
|
|
|
} else {
|
|
|
product.setTotalNum(0);
|
|
|
}
|
|
@@ -255,7 +260,7 @@ public class PackingBillPdfServiceImpl implements IPackingBillPdfService {
|
|
|
}
|
|
|
//保留2位小数
|
|
|
BigDecimal gw = new BigDecimal(grossWeight);
|
|
|
- gw = gw.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ gw = gw.setScale(2, RoundingMode.HALF_UP);
|
|
|
jsonObject.put("grossWeight", gw.toPlainString());
|
|
|
|
|
|
//产品总净重
|
|
@@ -266,22 +271,22 @@ public class PackingBillPdfServiceImpl implements IPackingBillPdfService {
|
|
|
}
|
|
|
//保留2位小数
|
|
|
BigDecimal nw = new BigDecimal(netWeight);
|
|
|
- nw = nw.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ nw = nw.setScale(2, RoundingMode.HALF_UP);
|
|
|
jsonObject.put("netWeight", nw.toPlainString());
|
|
|
|
|
|
//产品总体积
|
|
|
- BigDecimal b1 = new BigDecimal(0.00);
|
|
|
+ BigDecimal b1 = new BigDecimal("0.00");
|
|
|
// double volume = products.stream().filter(obj -> obj.getVolume() != null).mapToDouble(ShipmentPackingProduct::getVolume).sum();
|
|
|
- double volume = products.stream().filter(obj -> obj.getVolume() != null).map(obj -> obj.getVolume()).collect(Collectors.toList()).get(0);
|
|
|
+ double volume = products.stream().map(ShipmentPackingProduct::getVolume).filter(Objects::nonNull).collect(Collectors.toList()).get(0);
|
|
|
if (volume > 0) {
|
|
|
BigDecimal volumeBig = new BigDecimal(volume);
|
|
|
//乘以总箱数
|
|
|
volumeBig = volumeBig.multiply(new BigDecimal(boxTotal));
|
|
|
- b1 = volumeBig.divide(new BigDecimal(1000000));
|
|
|
+ b1 = volumeBig.divide(new BigDecimal("1000000"));
|
|
|
//保留2位数
|
|
|
- b1 = b1.setScale(3, BigDecimal.ROUND_HALF_UP);
|
|
|
+ b1 = b1.setScale(3, RoundingMode.HALF_UP);
|
|
|
if (b1.doubleValue() <= 0) {
|
|
|
- b1 = new BigDecimal(0.00);
|
|
|
+ b1 = new BigDecimal("0.00");
|
|
|
}
|
|
|
}
|
|
|
jsonObject.put("volume", b1.toPlainString());
|