This commit is contained in:
linfso 2025-07-02 12:05:30 +08:00
parent 8dc9c4146a
commit 86b5b368dd
3 changed files with 79 additions and 49 deletions

View File

@ -84,6 +84,8 @@ public interface EmisTmsCostFeeSplitMapper extends BaseMapper<EmisTmsCostFeeSpli
public int deleteByCostNoAndBillCode(@Param("costNo") String costNo,@Param("billCode") String billCode);
public int deleteByBillCodeAndFeeType(@Param("billCode") String billCode,@Param("feeType") String feeType);
public int deleteEmisTmsCostFeeSplitByBillCode(String BillCode);
/**

View File

@ -226,54 +226,70 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService
@Transactional
public int reCalcCostFeeByBillCode(String billCode) throws EmisBizError {
// 根据运单号删除该运单计算的费用
emisTmsCostFeeSplitMapper.deleteEmisTmsCostFeeSplitByBillCode(billCode);
// 计算固定成本费用-取件费
EmisWaybill waybill=emisWaybillMapper.selectEmisWaybillByBillCode(billCode);
if(waybill==null){
throw new EmisBizError(EmisBizErrorType.FAIL,"运单不存在");
}
// 根据运单号删除该运单计算的费用
emisTmsCostFeeSplitMapper.deleteEmisTmsCostFeeSplitByBillCode(billCode);
// 虚拟单取主单
EmisWaybill mainWaybill=null;
String mainBillCode = billCode;
if( "1".equals(waybill.getBlVirtual()) ){
mainBillCode=waybill.getMasterBillCode();
mainWaybill=emisWaybillMapper.selectEmisWaybillByBillCode(mainBillCode);
}else{
mainWaybill=waybill;
}
// bug:1682 (1)快递类型的货(取件费):寄件国家:中国,取件方式:上门取件,取件成本:首重1Kg 10元,续重1kg 1元
// 只有主单才会计算取件费
if("2".equals(waybill.getPickupMethod())
&& !"1".equals(waybill.getBlVirtual())
&& "0086".equals(waybill.getSendCountry()) ){
if("2".equals(mainWaybill.getPickupMethod())
&& !"1".equals(mainWaybill.getBlVirtual())
&& "0086".equals(mainWaybill.getSendCountry()) ){
EmisTmsCostFeeSplit splitItem = new EmisTmsCostFeeSplit();
splitItem.setBillCode(billCode);
splitItem.setMainBillCode(billCode);
splitItem.setBillWeight(waybill.getBillWeight()); // 运单重量
splitItem.setTotalVolume(waybill.getTotalVolume()); // 运单体积
splitItem.setMainBillCode(mainBillCode);
splitItem.setBillWeight(mainWaybill.getBillWeight()); // 运单重量
splitItem.setTotalVolume(mainWaybill.getTotalVolume()); // 运单体积
// 运输成本
splitItem.setBlManual("1"); // 手工计算
splitItem.setCostNo("-1"); // 固定成本
splitItem.setBatchNo("-1");
splitItem.setTransWeight(waybill.getBillWeight()); // 运输重量
splitItem.setTransVolume(waybill.getTotalVolume()); // 运输体积
splitItem.setTransWeight(mainWaybill.getBillWeight()); // 运输重量
splitItem.setTransVolume(mainWaybill.getTotalVolume()); // 运输体积
// 供应商
splitItem.setSupplierCode("10213"); // 供应商
splitItem.setTransSignNo(waybill.getTakePieceEmployeeName()); // 运输号
splitItem.setTransSignNo(mainWaybill.getTakePieceEmployeeName()); // 运输号
splitItem.setSendPlace("客户现场");
splitItem.setDestPlace(waybill.getSendSiteName());
splitItem.setBillMonth(DateUtils.parseDateToStr(DateUtils.YYYY_MM,waybill.getSendDate()));
splitItem.setTradeDate(waybill.getSendDate());
splitItem.setDestPlace(mainWaybill.getSendSiteName());
splitItem.setBillMonth(DateUtils.parseDateToStr(DateUtils.YYYY_MM,mainWaybill.getSendDate()));
splitItem.setTradeDate(mainWaybill.getSendDate());
// 成本分摊
splitItem.setFeeType("1001"); // 网点取件费
splitItem.setSplitType("1"); // 按重量分摊
splitItem.setFeeItemId(-1L); // 无成本费用项来源
splitItem.setSplitValue(waybill.getBillWeight());
splitItem.setSplitValue(mainWaybill.getBillWeight());
// 计算公式 首重1Kg 10元,续重1kg 1元
String itemCalcExpr = "s+(w-1)*d";
if(waybill.getBillWeight().doubleValue() <= 1.0){
if(mainWaybill.getBillWeight().doubleValue() <= 1.0){
itemCalcExpr="s";
}
String calcExprStr=getCalcFeeExpStr(itemCalcExpr,waybill.getBillWeight(),BigDecimal.valueOf(10.0D),BigDecimal.valueOf(1.0D));
String calcExprStr=getCalcFeeExpStr(itemCalcExpr,mainWaybill.getBillWeight(),BigDecimal.valueOf(10.0D),BigDecimal.valueOf(1.0D));
double costFee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString());
log.info("网点取件费:计算公式:" + calcExprStr + ",重量:" + waybill.getBillWeight().stripTrailingZeros().toPlainString());
log.info("网点取件费:计算公式:" + calcExprStr + ",重量:" + mainWaybill.getBillWeight().stripTrailingZeros().toPlainString());
// 取件费按进1获取
costFee=WaybillHelper.calcSettledFee(costFee,"5");
@ -289,6 +305,9 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService
splitItem.setCnyFee(splitCostFee);
// 插入分摊明细数据
// 先删除取件费,再插入
emisTmsCostFeeSplitMapper.deleteByBillCodeAndFeeType(mainBillCode,"1001");
emisTmsCostFeeSplitMapper.insertEmisTmsCostFeeSplit(splitItem);
}
@ -296,58 +315,56 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService
// (3)快递类型货(派送费):目的国家(柬埔寨、缅甸、孟加拉、越南、老挝)末端派送费 首重1Kg 2美金 15元,续重1kg 0.2美金/1.5元;
// 派送
if(
"1".equals(waybill.getCarryType()) // 快递
&& "1".equals(waybill.getDispatchMethod()) // 派送
&& !"1".equals(waybill.getBlVirtual())
"1".equals(mainWaybill.getCarryType()) // 快递
&& "1".equals(mainWaybill.getDispatchMethod()) // 派送
&& (
"0855".equals(waybill.getReceiveCountry()) // 柬埔寨
|| "0095".equals(waybill.getReceiveCountry()) // 缅甸
|| "0880".equals(waybill.getReceiveCountry()) // 孟加拉
|| "0084".equals(waybill.getReceiveCountry()) // 越南
|| "0856".equals(waybill.getReceiveCountry()) // 老挝
"0855".equals(mainWaybill.getReceiveCountry()) // 柬埔寨
|| "0095".equals(mainWaybill.getReceiveCountry()) // 缅甸
|| "0880".equals(mainWaybill.getReceiveCountry()) // 孟加拉
|| "0084".equals(mainWaybill.getReceiveCountry()) // 越南
|| "0856".equals(mainWaybill.getReceiveCountry()) // 老挝
)
){
EmisTmsCostFeeSplit splitItem = new EmisTmsCostFeeSplit();
splitItem.setBillCode(billCode);
splitItem.setMainBillCode(billCode);
splitItem.setBillWeight(waybill.getBillWeight()); // 运单重量
splitItem.setTotalVolume(waybill.getTotalVolume()); // 运单体积
splitItem.setMainBillCode(mainBillCode);
splitItem.setBillWeight(mainWaybill.getBillWeight()); // 运单重量
splitItem.setTotalVolume(mainWaybill.getTotalVolume()); // 运单体积
// 运输成本
splitItem.setBlManual("1"); // 手工计算
splitItem.setCostNo("-1"); // 固定成本
splitItem.setBatchNo("-1");
splitItem.setTransWeight(waybill.getBillWeight()); // 运输重量
splitItem.setTransVolume(waybill.getTotalVolume()); // 运输体积
splitItem.setTransWeight(mainWaybill.getBillWeight()); // 运输重量
splitItem.setTransVolume(mainWaybill.getTotalVolume()); // 运输体积
// 供应商
splitItem.setSupplierCode("10214"); // 供应商
splitItem.setTransSignNo(waybill.getDispatchManName()); // 运输号
splitItem.setTransSignNo(mainWaybill.getDispatchManName()); // 运输号
// 目的网点到客户现场
splitItem.setSendPlace(waybill.getDispatchUnderlingSiteName());
splitItem.setSendPlace(mainWaybill.getDispatchUnderlingSiteName());
splitItem.setDestPlace("客户现场");
splitItem.setBillMonth(DateUtils.parseDateToStr(DateUtils.YYYY_MM,waybill.getSendDate()));
splitItem.setTradeDate(waybill.getDispatchDate());
splitItem.setTradeDate(mainWaybill.getDispatchDate());
// 成本分摊
splitItem.setFeeType("1003"); // 网点取件费
splitItem.setSplitType("1"); // 按重量分摊
splitItem.setFeeItemId(-1L); // 无成本费用项来源
splitItem.setSplitValue(waybill.getBillWeight());
splitItem.setSplitValue(mainWaybill.getBillWeight());
// 网点派送费计算公式 首重1Kg 15元,续重1kg 1.5元
String itemCalcExpr = "s+(w-1)*d";
if(waybill.getBillWeight().doubleValue() <= 1.0){
if(mainWaybill.getBillWeight().doubleValue() <= 1.0){
itemCalcExpr="s";
}
String calcExprStr=getCalcFeeExpStr(itemCalcExpr,waybill.getBillWeight(),BigDecimal.valueOf(15.0D),BigDecimal.valueOf(1.5D));
String calcExprStr=getCalcFeeExpStr(itemCalcExpr,mainWaybill.getBillWeight(),BigDecimal.valueOf(15.0D),BigDecimal.valueOf(1.5D));
double costFee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString());
log.info("网点派送费:计算公式:" + calcExprStr + ",重量:" + waybill.getBillWeight().stripTrailingZeros().toPlainString());
log.info("网点派送费:计算公式:" + calcExprStr + ",重量:" + mainWaybill.getBillWeight().stripTrailingZeros().toPlainString());
costFee=WaybillHelper.calcSettledFee(costFee,"5");
@ -363,6 +380,9 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService
splitItem.setTransCostFee(splitCostFee);
splitItem.setCnyFee(splitCostFee);
// 先删除取件费,再插入
emisTmsCostFeeSplitMapper.deleteByBillCodeAndFeeType(mainBillCode,"1003");
// 插入分摊明细数据
emisTmsCostFeeSplitMapper.insertEmisTmsCostFeeSplit(splitItem);
}
@ -371,7 +391,6 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService
// (2)新创建表(短驳费):机场到网点之间的距离表;记录 起始网点、下一网点、开始日期、结束日期、公里数、单价、供应商、计费类型:按公斤
List<EmisTmsCostQuotePrice> fixedQuotePrice1002List=emisTmsCostQuotePriceMapper.matchBatchFixedQuotePriceByBillCode(billCode,"1002",1);
if(!CollectionUtils.isEmpty(fixedQuotePrice1002List)){
// 检查重复
Map existsMap = new HashMap();
for (EmisTmsCostQuotePrice quotePriceItem : fixedQuotePrice1002List) {
@ -386,7 +405,7 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService
EmisTmsCostFeeSplit splitItem = new EmisTmsCostFeeSplit();
splitItem.setBillCode(billCode);
splitItem.setMainBillCode(billCode);
splitItem.setMainBillCode(mainBillCode);
splitItem.setBillWeight(waybill.getBillWeight()); // 运单重量
splitItem.setTotalVolume(waybill.getTotalVolume()); // 运单体积
@ -436,7 +455,7 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService
splitItem.setCalcExpr(itemCalcExpr);
splitItem.setCalcRemark(calcExprStr + "=" + splitCostFee.stripTrailingZeros().toPlainString());
splitItem.setRemark("网点机场短驳费");
splitItem.setBlVirtual(waybill.getBlVirtual());
// 总成本费用
splitItem.setTransCostFee(totalDbCostFee);
splitItem.setCnyFee(totalDbCostFee);
@ -446,7 +465,6 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService
}
}
// 机场提货费操作费 - 1004
List<EmisTmsCostQuotePrice> fixedQuotePrice1004List=emisTmsCostQuotePriceMapper.matchBatchFixedQuotePriceByBillCode(billCode,"1004",-1);
if(!CollectionUtils.isEmpty(fixedQuotePrice1004List)){
@ -465,7 +483,8 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService
// 计算 机场提货费操作费
EmisTmsCostFeeSplit splitItem = new EmisTmsCostFeeSplit();
splitItem.setBillCode(billCode);
splitItem.setMainBillCode(billCode);
splitItem.setMainBillCode(mainBillCode);
splitItem.setBillWeight(waybill.getBillWeight()); // 运单重量
splitItem.setTotalVolume(waybill.getTotalVolume()); // 运单体积
@ -494,7 +513,7 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService
splitItem.setSplitValue(waybill.getBillWeight()); // 分摊重量
// 总费用=单价*公里数
BigDecimal totalDbCostFee = quotePriceItem.getPrice().multiply(quotePriceItem.getDistance());
BigDecimal totalDbCostFee = quotePriceItem.getPrice().multiply(quotePriceItem.getTransWeight());
String itemCalcExpr = quotePriceItem.getCalculateExpression();
@ -505,11 +524,9 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService
.replaceAll("c", totalDbCostFee.stripTrailingZeros().toPlainString());
// 计算单次成本: 如果低于最低报价,则使用最低成本来分摊
BigDecimal totalCost =quotePriceItem.getTransWeight().multiply(quotePriceItem.getPrice());
if(totalCost.compareTo(quotePriceItem.getLeastPrice())<0){
if( totalDbCostFee.doubleValue() < quotePriceItem.getLeastPrice().doubleValue() ){
totalDbCostFee=quotePriceItem.getLeastPrice(); // 总成本=最低报价
itemCalcExpr="(w/t)*c";
calcExprStr = itemCalcExpr.replaceAll("w", waybill.getBillWeight().stripTrailingZeros().toPlainString())
.replaceAll("t", quotePriceItem.getTransWeight().stripTrailingZeros().toPlainString())
@ -533,6 +550,7 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService
// 总成本费用
splitItem.setTransCostFee(totalDbCostFee);
splitItem.setCnyFee(totalDbCostFee);
splitItem.setBlVirtual(waybill.getBlVirtual());
// 插入分摊明细数据
emisTmsCostFeeSplitMapper.insertEmisTmsCostFeeSplit(splitItem);

View File

@ -115,7 +115,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="batchNo != null and batchNo != ''"> and a.batch_no=#{batchNo}</if>
<if test="feeItemId != null "> and a.fee_item_id = #{feeItemId}</if>
<if test="billCode != null and billCode != ''">
and ( FIND_IN_SET(a.main_bill_code,#{billCode}) or a.main_bill_code like concat('%', #{billCode}, '%') )
and ( FIND_IN_SET(a.bill_code,#{billCode}) or a.bill_code like concat('%', #{billCode}, '%') )
</if>
<if test="mainBillCode != null and mainBillCode != ''">
and ( FIND_IN_SET(a.main_bill_code,#{mainBillCode}) or a.main_bill_code like concat('%', #{mainBillCode}, '%') )
</if>
<if test="sendPlace != null and sendPlace != ''"> and a.send_place=#{sendPlace}</if>
<if test="destPlace != null and destPlace != ''"> and a.dest_place=#{destPlace}</if>
@ -345,6 +348,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update emis_tms_cost_fee_split set del_flag='1' where del_flag='0' and cost_no = #{costNo}
</delete>
<delete id="deleteByBillCodeAndFeeType" >
update emis_tms_cost_fee_split set del_flag='1'
where del_flag='0'
and bill_code = #{billCode}
and fee_type = #{feeType}
</delete>
<delete id="deleteByCostNoAndBillCode" >
update emis_tms_cost_fee_split set del_flag='1'
where del_flag='0'