diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTmsCostQuotePriceMapper.java b/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTmsCostQuotePriceMapper.java index 1ae4c1c19..c6585abd2 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTmsCostQuotePriceMapper.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTmsCostQuotePriceMapper.java @@ -32,11 +32,13 @@ public interface EmisTmsCostQuotePriceMapper extends BaseMapper matchTmsCostQuotePriceListByBillCode(@Param("billCode") String bilCode); + public List matchBatchFixedQuotePriceByBillCode(@Param("billCode") String bilCode,@Param("feeType") String feeType,@Param("blNeedMatchSupplier") String blNeedMatchSupplier); /** * 查询列表 diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsCostFeeServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsCostFeeServiceImpl.java index d967e029f..169543bf9 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsCostFeeServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsCostFeeServiceImpl.java @@ -13,9 +13,7 @@ package com.xdadan.erp.emis.service.impl; import java.math.BigDecimal; import java.text.ParseException; import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -277,7 +275,9 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService double costFee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString()); log.info("网点取件费:计算公式:" + calcExprStr + ",重量:" + waybill.getBillWeight().stripTrailingZeros().toPlainString()); - BigDecimal splitCostFee = BigDecimal.valueOf(costFee).setScale(2,BigDecimal.ROUND_HALF_UP); + // 取件费按进1获取 + costFee=WaybillHelper.calcSettledFee(costFee,"5"); + BigDecimal splitCostFee = BigDecimal.valueOf(costFee).setScale(0,BigDecimal.ROUND_HALF_UP); splitItem.setCostFee(splitCostFee); splitItem.setCurrency("CNY"); splitItem.setCalcExpr(itemCalcExpr); @@ -349,6 +349,8 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService double costFee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString()); log.info("网点派送费:计算公式:" + calcExprStr + ",重量:" + waybill.getBillWeight().stripTrailingZeros().toPlainString()); + costFee=WaybillHelper.calcSettledFee(costFee,"5"); + BigDecimal splitCostFee = BigDecimal.valueOf(costFee).setScale(2,BigDecimal.ROUND_HALF_UP); splitItem.setCostFee(splitCostFee); splitItem.setCurrency("CNY"); @@ -365,72 +367,178 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService emisTmsCostFeeSplitMapper.insertEmisTmsCostFeeSplit(splitItem); } - // 网点机场短驳费 + // 网点机场短驳费 - 1002 // (2)新创建表(短驳费):机场到网点之间的距离表;记录 起始网点、下一网点、开始日期、结束日期、公里数、单价、供应商、计费类型:按公斤 - // 从起始网点获取第一段批次 - // 根据单号和起始网点和短驳费用表找到是否有短驳费,获取短驳费单价 - List quotePriceList=emisTmsCostQuotePriceMapper.matchTmsCostQuotePriceListByBillCode(billCode); - if(!CollectionUtils.isEmpty(quotePriceList)){ - EmisTmsCostQuotePrice quotePrice0=quotePriceList.get(0); + List fixedQuotePrice1002List=emisTmsCostQuotePriceMapper.matchBatchFixedQuotePriceByBillCode(billCode,"1002","T"); + if(!CollectionUtils.isEmpty(fixedQuotePrice1002List)){ - EmisTmsCostFeeSplit splitItem = new EmisTmsCostFeeSplit(); + // 检查重复 + Map existsMap = new HashMap(); + for (EmisTmsCostQuotePrice quotePriceItem : fixedQuotePrice1002List) { - splitItem.setBillCode(billCode); - splitItem.setMainBillCode(billCode); - splitItem.setBillWeight(waybill.getBillWeight()); // 运单重量 - splitItem.setTotalVolume(waybill.getTotalVolume()); // 运单体积 + // 如果网点重复就忽略 + String uniqKey = quotePriceItem.getStartSiteCode() + "-"+quotePriceItem.getNextSiteCode(); + if(existsMap.containsKey(uniqKey)){ + continue; + } + existsMap.put(uniqKey,1); - // 运输成本 - splitItem.setBlManual("1"); // 手工计算 - splitItem.setCostNo("-1"); // 固定成本 - splitItem.setBatchNo(quotePrice0.getBatchNo()); - splitItem.setTransWeight(quotePrice0.getTransWeight()); // 运输重量 - splitItem.setTransVolume(BigDecimal.ZERO); // 运输体积 + EmisTmsCostFeeSplit splitItem = new EmisTmsCostFeeSplit(); - // 供应商 - splitItem.setSupplierCode(quotePrice0.getSupplierCode()); // 供应商 - splitItem.setTransSignNo(quotePrice0.getCarNo()); // 运输号 + splitItem.setBillCode(billCode); + splitItem.setMainBillCode(billCode); + splitItem.setBillWeight(waybill.getBillWeight()); // 运单重量 + splitItem.setTotalVolume(waybill.getTotalVolume()); // 运单体积 - // 起点到目的点 - splitItem.setSendPlace(quotePrice0.getStartSiteName()); - splitItem.setDestPlace(quotePrice0.getNextSiteName()); + // 运输成本 + splitItem.setBlManual("1"); // 手工计算 + splitItem.setCostNo("-1"); // 固定成本 + splitItem.setBatchNo(quotePriceItem.getBatchNo()); + splitItem.setTransWeight(quotePriceItem.getTransWeight()); // 运输重量 + splitItem.setTransVolume(BigDecimal.ZERO); // 运输体积 - splitItem.setBillMonth(DateUtils.parseDateToStr(DateUtils.YYYY_MM,waybill.getSendDate())); - splitItem.setTradeDate(waybill.getSignDate()); + // 供应商 + splitItem.setSupplierCode(quotePriceItem.getSupplierCode()); // 供应商 + splitItem.setTransSignNo(quotePriceItem.getCarNo()); // 运输号 - // 成本分摊 - splitItem.setFeeType("1002"); // 网点机场短驳费 - splitItem.setSplitType("1"); // 按重量分摊 - splitItem.setFeeItemId(-1L); // 无成本费用项来源 - splitItem.setSplitValue(waybill.getBillWeight()); // 分摊重量 + // 起点到目的点 + splitItem.setSendPlace(quotePriceItem.getStartSiteName()); + splitItem.setDestPlace(quotePriceItem.getNextSiteName()); - // 计算公式 首重1Kg 10元,续重1kg 1元 - // 总费用=单价*公里数 - BigDecimal totalDbCostFee = quotePrice0.getPrice().multiply(quotePrice0.getDistance()); - // 按总重量分摊 + splitItem.setBillMonth(DateUtils.parseDateToStr(DateUtils.YYYY_MM, waybill.getSendDate())); + splitItem.setTradeDate(waybill.getSignDate()); - String itemCalcExpr = "(w/t)*c"; - String calcExprStr=itemCalcExpr.replaceAll("w", waybill.getBillWeight().stripTrailingZeros().toPlainString()) - .replaceAll("t", quotePrice0.getTransWeight().stripTrailingZeros().toPlainString()) - .replaceAll("c", totalDbCostFee.stripTrailingZeros().toPlainString()); + // 成本分摊 + splitItem.setFeeType("1002"); // 网点机场短驳费 + splitItem.setSplitType("1"); // 按重量分摊 + splitItem.setFeeItemId(-1L); // 无成本费用项来源 + splitItem.setSplitValue(waybill.getBillWeight()); // 分摊重量 - double costFee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString()); + // 计算公式 首重1Kg 10元,续重1kg 1元 + // 总费用=单价*公里数 + BigDecimal totalDbCostFee = quotePriceItem.getPrice().multiply(quotePriceItem.getDistance()); + // 按总重量分摊 - log.info("网点机场短驳费:计算公式:" + calcExprStr + ",重量:" + waybill.getBillWeight().stripTrailingZeros().toPlainString()); + String itemCalcExpr = quotePriceItem.getCalculateExpression(); + String calcExprStr = itemCalcExpr.replaceAll("w", waybill.getBillWeight().stripTrailingZeros().toPlainString()) + .replaceAll("t", quotePriceItem.getTransWeight().stripTrailingZeros().toPlainString()) + .replaceAll("c", totalDbCostFee.stripTrailingZeros().toPlainString()); - BigDecimal splitCostFee = BigDecimal.valueOf(costFee).setScale(2,BigDecimal.ROUND_HALF_UP); - splitItem.setCostFee(splitCostFee); - splitItem.setCurrency("CNY"); - splitItem.setCalcExpr(itemCalcExpr); - splitItem.setCalcRemark(calcExprStr+"="+splitCostFee.stripTrailingZeros().toPlainString()); - splitItem.setRemark("网点机场短驳费"); + double costFee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString()); - // 总成本费用 - splitItem.setTransCostFee(totalDbCostFee); - splitItem.setCnyFee(totalDbCostFee); + log.info("网点机场短驳费:计算公式:" + calcExprStr + ",重量:" + waybill.getBillWeight().stripTrailingZeros().toPlainString()); - // 插入分摊明细数据 - emisTmsCostFeeSplitMapper.insertEmisTmsCostFeeSplit(splitItem); + costFee = WaybillHelper.calcSettledFee(costFee, quotePriceItem.getPriceType()); + + BigDecimal splitCostFee = BigDecimal.valueOf(costFee); + splitItem.setCostFee(splitCostFee); + splitItem.setCurrency("CNY"); + splitItem.setCalcExpr(itemCalcExpr); + splitItem.setCalcRemark(calcExprStr + "=" + splitCostFee.stripTrailingZeros().toPlainString()); + splitItem.setRemark("网点机场短驳费"); + + // 总成本费用 + splitItem.setTransCostFee(totalDbCostFee); + splitItem.setCnyFee(totalDbCostFee); + + // 插入分摊明细数据 + emisTmsCostFeeSplitMapper.insertEmisTmsCostFeeSplit(splitItem); + } + } + + + // 机场提货费操作费 - 1004 + List fixedQuotePrice1004List=emisTmsCostQuotePriceMapper.matchBatchFixedQuotePriceByBillCode(billCode,"1004","T"); + if(!CollectionUtils.isEmpty(fixedQuotePrice1004List)){ + + // 检查重复 + Map existsMap = new HashMap(); + for (EmisTmsCostQuotePrice quotePriceItem : fixedQuotePrice1004List) { + + // 如果网点重复就忽略 + String uniqKey = quotePriceItem.getStartSiteCode() + "-"+quotePriceItem.getNextSiteCode(); + if(existsMap.containsKey(uniqKey)){ + continue; + } + existsMap.put(uniqKey,1); + + // 计算 机场提货费操作费 + EmisTmsCostFeeSplit splitItem = new EmisTmsCostFeeSplit(); + splitItem.setBillCode(billCode); + splitItem.setMainBillCode(billCode); + splitItem.setBillWeight(waybill.getBillWeight()); // 运单重量 + splitItem.setTotalVolume(waybill.getTotalVolume()); // 运单体积 + + // 运输成本 + splitItem.setBlManual("1"); // 手工计算 + splitItem.setCostNo("-1"); // 固定成本 + splitItem.setBatchNo(quotePriceItem.getBatchNo()); + splitItem.setTransWeight(quotePriceItem.getTransWeight()); // 运输重量 + splitItem.setTransVolume(BigDecimal.ZERO); // 运输体积 + + // 供应商 + splitItem.setSupplierCode(quotePriceItem.getSupplierCode()); // 供应商 + splitItem.setTransSignNo(quotePriceItem.getCarNo()); // 运输号 + + // 起点到目的点 + splitItem.setSendPlace(quotePriceItem.getStartSiteName()); + splitItem.setDestPlace(quotePriceItem.getNextSiteName()); + + splitItem.setBillMonth(DateUtils.parseDateToStr(DateUtils.YYYY_MM, waybill.getSendDate())); + splitItem.setTradeDate(waybill.getSignDate()); + + // 成本分摊 + splitItem.setFeeType("1004"); // 网点机场操作费 + splitItem.setSplitType("1"); // 按重量分摊 + splitItem.setFeeItemId(-1L); // 无成本费用项来源 + splitItem.setSplitValue(waybill.getBillWeight()); // 分摊重量 + + // 总费用=单价*公里数 + BigDecimal totalDbCostFee = quotePriceItem.getPrice().multiply(quotePriceItem.getDistance()); + + String itemCalcExpr = quotePriceItem.getCalculateExpression(); + + // 正常计算公司 + String calcExprStr = itemCalcExpr.replaceAll("w", waybill.getBillWeight().stripTrailingZeros().toPlainString()) + .replaceAll("t", quotePriceItem.getTransWeight().stripTrailingZeros().toPlainString()) + .replaceAll("d", quotePriceItem.getPrice().stripTrailingZeros().toPlainString()) + .replaceAll("c", totalDbCostFee.stripTrailingZeros().toPlainString()); + + // 计算单次成本: 如果低于最低报价,则使用最低成本来分摊 + BigDecimal totalCost =quotePriceItem.getTransWeight().multiply(quotePriceItem.getPrice()); + if(totalCost.compareTo(quotePriceItem.getLeastPrice())<0){ + + totalDbCostFee=quotePriceItem.getLeastPrice(); // 总成本=最低报价 + + itemCalcExpr="(w/t)*c"; + calcExprStr = itemCalcExpr.replaceAll("w", waybill.getBillWeight().stripTrailingZeros().toPlainString()) + .replaceAll("t", quotePriceItem.getTransWeight().stripTrailingZeros().toPlainString()) + .replaceAll("c", totalDbCostFee.stripTrailingZeros().toPlainString()); + + } + + + + double costFee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString()); + + log.info("机场提货费操作费:计算公式:" + calcExprStr + ",重量:" + waybill.getBillWeight().stripTrailingZeros().toPlainString()); + + costFee = WaybillHelper.calcSettledFee(costFee, quotePriceItem.getPriceType()); + + BigDecimal splitCostFee = BigDecimal.valueOf(costFee); + splitItem.setCostFee(splitCostFee); + splitItem.setCurrency("CNY"); + splitItem.setCalcExpr(itemCalcExpr); + splitItem.setCalcRemark(calcExprStr + "=" + splitCostFee.stripTrailingZeros().toPlainString()); + splitItem.setRemark("机场提货费操作费"); + + // 总成本费用 + splitItem.setTransCostFee(totalDbCostFee); + splitItem.setCnyFee(totalDbCostFee); + + // 插入分摊明细数据 + emisTmsCostFeeSplitMapper.insertEmisTmsCostFeeSplit(splitItem); + } } // 搜索已录入成本的费用分摊 @@ -444,6 +552,8 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService } } } + + mergeCostFeeByBillCode(billCode); return 1; @@ -956,4 +1066,12 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService return 1; } + public static void main(String[] args) { + double costFee=WaybillHelper.calcSettledFee(0.001,"5"); +// BigDecimal splitCostFee = BigDecimal.valueOf(costFee).setScale(0,BigDecimal.ROUND_HALF_UP); + System.out.println(costFee); + } + + + } diff --git a/emis-biz/src/main/resources/mapper/EmisTmsCostQuotePriceMapper.xml b/emis-biz/src/main/resources/mapper/EmisTmsCostQuotePriceMapper.xml index f9cc03dc1..1a1c34cca 100644 --- a/emis-biz/src/main/resources/mapper/EmisTmsCostQuotePriceMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisTmsCostQuotePriceMapper.xml @@ -27,7 +27,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - @@ -74,7 +73,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - SELECT DISTINCT a.start_site_code, @@ -108,54 +107,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND c.del_flag = '0' AND a.start_site_code = b.start_site_code AND a.next_site_code = b.next_site_code - AND a.supplier_code = b.supplier_code + + AND a.supplier_code = b.supplier_code + AND b.batch_no = c.batch_no and a.start_date b.etd and b.etd a.end_date + and a.fee_type = #{feeType} AND c.bill_code = #{billCode} - limit 1 - - -