Browse Source

体积

java8
han\hanst 6 months ago
parent
commit
5867defaec
  1. 1
      src/main/java/com/xujie/sys/modules/ecss/data/EcssCoDelNotifyDetailData.java
  2. 4
      src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java
  3. 148
      src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java
  4. 24
      src/main/resources/mapper/ecss/CoDelMapper.xml

1
src/main/java/com/xujie/sys/modules/ecss/data/EcssCoDelNotifyDetailData.java

@ -23,4 +23,5 @@ public class EcssCoDelNotifyDetailData extends EcssCoDelNotifyDetail {
private BigDecimal rolls;
private BigDecimal useQty;
private BigDecimal surplusQty;
private String packageNo;
}

4
src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java

@ -176,6 +176,8 @@ public interface CoDelMapper {
List<Map> exportCoDelPalletDetail(EcssCoDelNotifyHeaderData data);
List<Map> getCoDelPalletDetailGroupByPn(EcssCoDelNotifyHeaderData data);
List<Map> exportCoDelBoxList(EcssCoDelNotifyHeaderData data);
void updateEcssDeclarationHeader(EcssDeclarationHeaderData data);
@ -205,6 +207,8 @@ public interface CoDelMapper {
List<Map> getPackageNoByPartNo(@Param("site") String site,@Param("partNos") List<String> partNos);
List<Map> getPackageNoByPn(@Param("site") String site,@Param("pns") List<String> pns);
List<EcssPackageData> getPackageList(@Param("site") String site,@Param("buNo") String buNo,@Param("packageNos") List<String> packageNos);
IPage<EcssTemplate> searchEcssTemplateData(Page<EcssTemplate> ecssTemplateDataPage, @Param("query") EcssTemplate data);

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

@ -2465,9 +2465,20 @@ public class CoDelServiceImpl implements CoDelService {
template.addVar("sellerLabel", "Name of seller Checkpoint Commercial (Shanghai) Co.. Ltd.");
}
template.addVar("Shipping_Mark", stringInput(data.getShippingMark()));
template.addVar("Measurement", !palletHeaderData.isPresent()?"":palletHeaderData.get().getLength().
multiply(palletHeaderData.get().getWidth()).multiply(palletHeaderData.get().getHeight()).
multiply(BigDecimal.valueOf(totalPlt)).setScale(2, RoundingMode.HALF_UP));
// 体积计算优先使用栈板体积栈板不存在时根据装箱明细的物料计算体积
BigDecimal totalVolume = BigDecimal.ZERO;
if (palletHeaderData.isPresent()) {
// 使用栈板体积计算
totalVolume = palletHeaderData.get().getLength()
.multiply(palletHeaderData.get().getWidth())
.multiply(palletHeaderData.get().getHeight())
.multiply(BigDecimal.valueOf(totalPlt))
.setScale(2, RoundingMode.HALF_UP);
} else {
// 栈板不存在时根据装箱明细的物料计算体积
totalVolume = calculateVolumeByMaterials(notifyHeader);
}
template.addVar("Measurement", totalVolume);
template.addListVarAll(exportList);
}
@ -2555,9 +2566,20 @@ public class CoDelServiceImpl implements CoDelService {
template.addVar("net_weight", netWeight.setScale(2, RoundingMode.HALF_UP));
template.addVar("gross_weight", grossWeight.setScale(2, RoundingMode.HALF_UP));
template.addVar("volume", palletHeaderData.isPresent() ?palletHeaderData.get().getLength().
multiply(palletHeaderData.get().getWidth()).multiply(palletHeaderData.get().getHeight()).
multiply(BigDecimal.valueOf(totalPlt)).setScale(2, RoundingMode.HALF_UP):"");
// 体积计算优先使用栈板体积栈板不存在时根据装箱明细的物料计算体积
BigDecimal totalVolume = BigDecimal.ZERO;
if (palletHeaderData.isPresent()) {
// 使用栈板体积计算
totalVolume = palletHeaderData.get().getLength()
.multiply(palletHeaderData.get().getWidth())
.multiply(palletHeaderData.get().getHeight())
.multiply(BigDecimal.valueOf(totalPlt))
.setScale(2, RoundingMode.HALF_UP);
} else {
// 栈板不存在时根据装箱明细的物料计算体积
totalVolume = calculateVolumeByMaterials(notifyHeader);
}
template.addVar("volume", totalVolume);
template.addVar("highest", palletHeaderData.isPresent() ?palletHeaderData.map(ecssCoDelPalletHeaderData ->
ecssCoDelPalletHeaderData.getLength().setScale(2, RoundingMode.HALF_UP)
+ "*" + ecssCoDelPalletHeaderData.getWidth().setScale(2, RoundingMode.HALF_UP) + "*"
@ -2592,6 +2614,120 @@ public class CoDelServiceImpl implements CoDelService {
template.addListVarAll(notifyDetailGroup);
}
/**
* 根据装箱明细的物料计算体积
* 每种物料每个pn是一种物料维护的箱子的长***箱数
*
* @return 总体积
*/
private BigDecimal calculateVolumeByMaterials(EcssCoDelNotifyHeaderData notifyHeader) {
List<Map> palletDetailList = coDelMapper.getCoDelPalletDetailGroupByPn(notifyHeader);
if (palletDetailList == null || palletDetailList.isEmpty()) {
return BigDecimal.ZERO;
}
try {
// 获取所有物料编号
List<String> pns = palletDetailList.stream()
.map(detail -> (String) detail.get("pn"))
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
if (pns.isEmpty()) {
return BigDecimal.ZERO;
}
// 根据物料编号获取packageNo
List<Map> packageNoList = coDelMapper.getPackageNoByPn(notifyHeader.getSite(), pns);
Map<String, String> partNoToPackageNoMap = packageNoList.stream()
.collect(Collectors.toMap(
map -> (String) map.get("pn"),
map -> (String) map.get("packageNo"),
(existing, replacement) -> existing // 处理重复key的情况
));
// 获取所有packageNo对应的包装信息
List<String> packageNos = packageNoList.stream()
.map(map -> (String) map.get("packageNo"))
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
if (packageNos.isEmpty()) {
log.warn("未找到物料对应的包装信息,物料编号: {}", pns);
return BigDecimal.ZERO;
}
// 获取包装信息长宽高
List<EcssPackageData> packageDataList = coDelMapper.getPackageList(notifyHeader.getSite(), notifyHeader.getBuNo(), packageNos);
Map<String, EcssPackageData> packageNoToDataMap = packageDataList.stream()
.collect(Collectors.toMap(
EcssPackageData::getPackageNo,
packageData -> packageData,
(existing, replacement) -> existing
));
// 计算总体积
BigDecimal totalVolume = BigDecimal.ZERO;
for (Map detail : palletDetailList) {
String pn = (String) detail.get("pn");
Object boxQtyObj = detail.get("box_qty");
if (pn == null || boxQtyObj == null) {
continue;
}
// 获取箱数
BigDecimal boxQty;
if (boxQtyObj instanceof BigDecimal) {
boxQty = (BigDecimal) boxQtyObj;
} else {
boxQty = new BigDecimal(boxQtyObj.toString());
}
// 获取包装信息
String packageNo = partNoToPackageNoMap.get(pn);
if (packageNo == null) {
log.warn("物料 {} 未维护packageNo", pn);
continue;
}
EcssPackageData packageData = packageNoToDataMap.get(packageNo);
if (packageData == null) {
log.warn("包装编号 {} 未找到对应的包装信息", packageNo);
continue;
}
// 检查长宽高是否都有值
if (packageData.getLength() == null || packageData.getWidth() == null || packageData.getHeight() == null) {
log.warn("包装编号 {} 的长宽高信息不完整", packageNo);
continue;
}
// 计算该物料的体积***箱数
BigDecimal materialVolume = packageData.getLength()
.multiply(packageData.getWidth())
.multiply(packageData.getHeight())
.multiply(boxQty);
totalVolume = totalVolume.add(materialVolume);
log.debug("物料 {} 包装 {} 箱数 {} 单箱体积 {} 总体积 {}",
pn, packageNo, boxQty,
packageData.getLength().multiply(packageData.getWidth()).multiply(packageData.getHeight()),
materialVolume);
}
return totalVolume.setScale(2, RoundingMode.HALF_UP);
} catch (Exception e) {
log.error("计算物料体积时发生异常", e);
return BigDecimal.ZERO;
}
}
/**
* 计算FSC纸重量
*/

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

@ -118,7 +118,8 @@
select a.site,a.bu_no,a.delNo,a.item_no,a.salesOrder,a.salesOrder_item_no,a.customerPO,a.line,a.version,a.status,a.family,
a.part_no,a.part_description,a.qty,a.lt,a.cmc_comment,a.saleType,a.awb_bl,a.shipping_number,a.forwarder_info,isnull(a.surplus_qty,0) surplusQty,
a.currency,a.tp,a.ttl_amount,a.sum_price,a.so,a.upc,a.remark,a.erp_delItemNo,a.pn,CONVERT(DECIMAL(20, 0),a.nocartons) as nocartons,
c.num_value as boxrolls,d.num_value as rollqty,w.num_value as boxweight,#{cmcInvoice} as cmcInvoice,a.modifyFlag,b.hsCodeDesc,a.vat,a.roll,a.carton
c.num_value as boxrolls,d.num_value as rollqty,w.num_value as boxweight,#{cmcInvoice} as cmcInvoice,a.modifyFlag,
b.hsCodeDesc,a.vat,a.roll,a.carton,b.packageNo
from ecss_CoDelNotifydetail a
left join part b on a.site=b.site and a.part_no=b.part_no
left join part_sub_properties_value c on a.part_no=c.part_no and c.site=a.site and c.bu_no=a.bu_no
@ -820,6 +821,18 @@ left join ecss_CoDelNotifyHeader noHeader on a.site=noHeader.site and a.delNo=no
where a.site=#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo} and b.site is not null GROUP BY b.part_no
</select>
<select id="getCoDelPalletDetailGroupByPn" resultType="java.util.Map">
select b.pn,CONVERT(DECIMAL(20, 0),sum(b.qty)) as total_qty,
CONVERT(DECIMAL(20, 0),sum(DISTINCT a.box_qty)) as box_qty,
CONVERT(DECIMAL(20, 0),sum(b.rolls)) as rolls,
CONVERT(DECIMAL(20, 2),sum(a.net_weight)) as net_weight,
CONVERT(DECIMAL(20, 2),sum(a.gross_weight)) as gross_weight,
CONVERT(DECIMAL(20, 0),sum(b.rolls*b.qty)) as qty_per_carton
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
where a.site=#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo} GROUP BY b.pn
</select>
<select id="exportCoDelBoxList" resultType="java.util.Map">
select CONVERT(DECIMAL(20, 0),sum(a.box_qty)) as box_qty
from ecss_CoDelBoxList a
@ -937,6 +950,15 @@ left join ecss_CoDelNotifyHeader noHeader on a.site=noHeader.site and a.delNo=no
</foreach>
</select>
<select id="getPackageNoByPn" resultType="java.util.Map">
select p.sku as pn,p.packageNo
from Part p
where p.site=#{site,jdbcType=VARCHAR} and p.sku in
<foreach item="item" index="index" collection="pns" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="getPackageList" resultType="EcssPackageData">
select * from ecss_package where site=#{site} and buNo=#{buNo}
and package_no in

Loading…
Cancel
Save