diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisTransLineController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisTransLineController.java index 303ac5fb9..798f20bc9 100644 --- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisTransLineController.java +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisTransLineController.java @@ -72,7 +72,7 @@ public class EmisTransLineController extends EmisBaseController * 查询线路列表 -- 精简 */ // @PreAuthorize("@ss.hasPermi('emis:emisTransLine:list')") - @JacksonFilter(include= {"id","lineCode","lineName","lineNameEn","meterRate","transType"},value= EmisTransLine.class,type= JacksonFilter.JscksonFilterType.RESPONSE) + @JacksonFilter(include= {"id","lineCode","lineName","lineNameEn","meterRate","transType","status"},value= EmisTransLine.class,type= JacksonFilter.JscksonFilterType.RESPONSE) @GetMapping("/listSimple") public TableDataInfo listSimple(EmisTransLine emisTransLine) { @@ -86,6 +86,29 @@ public class EmisTransLineController extends EmisBaseController + startPage(); + List list = emisTransLineService.selectEmisTransLineList(emisTransLine); + return getDataTable(list); + } + + /** + * 全部线路-包含停用 + * @param emisTransLine + * @return + */ + @JacksonFilter(include= {"id","lineCode","lineName","lineNameEn","meterRate","transType","status"},value= EmisTransLine.class,type= JacksonFilter.JscksonFilterType.RESPONSE) + @GetMapping("/listSimpleAll") + public TableDataInfo listSimpleAll(EmisTransLine emisTransLine) + { + // 总部不限制 + if(!(getLoginUser().getUser().isTopSite())){ + EmisSite site=emisBaseService.getSiteByCode(getLoginUser().getUser().getOwnerSiteCode()); + emisTransLine.setLogoType(site.getLogoType()); + emisTransLine.getParams().put("needFilterLogoTyoe","1"); + } + + + startPage(); List list = emisTransLineService.selectEmisTransLineList(emisTransLine); return getDataTable(list); diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTmsCostQuotePrice.java b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTmsCostQuotePrice.java index 5bd1b6b35..130b4cd5d 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTmsCostQuotePrice.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTmsCostQuotePrice.java @@ -43,10 +43,28 @@ public class EmisTmsCostQuotePrice extends BaseEntity private BigDecimal distance; /* 费用类型 运输费 */ private String feeType; + /* 固定总费用 */ + private BigDecimal fee; + /* 最低价格 */ + private BigDecimal leastPrice; + /* 价格取值 */ + private String priceType; /* 计费单价 */ private BigDecimal price; /* 费用币种 */ private String currency; + /* 起始重量 */ + private Double startWeight; + /* 结束重量 */ + private Double endWeight; + /* 首重 */ + private Double initialWeight; + /* 续重 */ + private Double additionalWeight; + /* 条件表达式 */ + private String conditionExpression; + /* 计算表达式 */ + private String calculateExpression; /* 计费类型 1-重量计费 2-体积计费 */ private String billType; /* 供应商代码 */ @@ -57,7 +75,8 @@ public class EmisTmsCostQuotePrice extends BaseEntity /* 结束日期 */ @JsonFormat(pattern = "yyyy-MM-dd") private Date endDate; - + /* 启用状态 1-启用 0-停用 */ + private String blOpen; // 扩展字段 ------ /** 起始网点名称 */ diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTmsCostFeeSplitMapper.java b/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTmsCostFeeSplitMapper.java index dfbdad0d1..866194a40 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTmsCostFeeSplitMapper.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTmsCostFeeSplitMapper.java @@ -84,6 +84,8 @@ public interface EmisTmsCostFeeSplitMapper extends BaseMapper matchTmsCostQuotePriceListByBillCode(@Param("billCode") String bilCode); + public List matchBatchFixedQuotePriceByBillCode(@Param("billCode") String bilCode,@Param("feeType") String feeType,@Param("blNeedMatchSupplier") Integer blNeedMatchSupplier); /** * 查询列表 diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleInvoiceChRecordServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleInvoiceChRecordServiceImpl.java index 2930151bd..83a097a3f 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleInvoiceChRecordServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleInvoiceChRecordServiceImpl.java @@ -470,7 +470,16 @@ public class EmisSettleInvoiceChRecordServiceImpl extends EmisBaseService implem order.setDetailInfos(goodsList); - JSONObject jRst =HXSdk.asyncOpenBillReceive(order,emisBaseInvoiceChInfo.getToken()); + + JSONObject jRst = null; + + try { + jRst = HXSdk.asyncOpenBillReceive(order, emisBaseInvoiceChInfo.getToken()); + }catch(Exception ex){ + ex.printStackTrace(); + throw new EmisBizError(EmisBizErrorType.FAIL,"航信税金系统出错,请联系航信人员"); + } + // 如果token失效则重新获取token再触发一次 /* "code": "B0301", 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..a35cdb4ef 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; @@ -228,56 +226,74 @@ 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()); - 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); @@ -289,6 +305,9 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService splitItem.setCnyFee(splitCostFee); // 插入分摊明细数据 + // 先删除取件费,再插入 + emisTmsCostFeeSplitMapper.deleteByBillCodeAndFeeType(mainBillCode,"1001"); + emisTmsCostFeeSplitMapper.insertEmisTmsCostFeeSplit(splitItem); } @@ -296,58 +315,58 @@ 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"); BigDecimal splitCostFee = BigDecimal.valueOf(costFee).setScale(2,BigDecimal.ROUND_HALF_UP); splitItem.setCostFee(splitCostFee); @@ -361,76 +380,182 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService splitItem.setTransCostFee(splitCostFee); splitItem.setCnyFee(splitCostFee); + // 先删除取件费,再插入 + emisTmsCostFeeSplitMapper.deleteByBillCodeAndFeeType(mainBillCode,"1003"); + // 插入分摊明细数据 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",1); + if(!CollectionUtils.isEmpty(fixedQuotePrice1002List)){ + // 检查重复 + Map existsMap = new HashMap(); + for (EmisTmsCostQuotePrice quotePriceItem : fixedQuotePrice1002List) { - EmisTmsCostFeeSplit splitItem = new EmisTmsCostFeeSplit(); + // 如果网点重复就忽略 + String uniqKey = quotePriceItem.getStartSiteCode() + "-"+quotePriceItem.getNextSiteCode(); + if(existsMap.containsKey(uniqKey)){ + continue; + } + existsMap.put(uniqKey,1); - splitItem.setBillCode(billCode); - splitItem.setMainBillCode(billCode); - splitItem.setBillWeight(waybill.getBillWeight()); // 运单重量 - splitItem.setTotalVolume(waybill.getTotalVolume()); // 运单体积 + EmisTmsCostFeeSplit splitItem = new EmisTmsCostFeeSplit(); - // 运输成本 - splitItem.setBlManual("1"); // 手工计算 - splitItem.setCostNo("-1"); // 固定成本 - splitItem.setBatchNo(quotePrice0.getBatchNo()); - splitItem.setTransWeight(quotePrice0.getTransWeight()); // 运输重量 - splitItem.setTransVolume(BigDecimal.ZERO); // 运输体积 + splitItem.setBillCode(billCode); + splitItem.setMainBillCode(mainBillCode); + splitItem.setBillWeight(waybill.getBillWeight()); // 运单重量 + splitItem.setTotalVolume(waybill.getTotalVolume()); // 运单体积 - // 供应商 - splitItem.setSupplierCode(quotePrice0.getSupplierCode()); // 供应商 - splitItem.setTransSignNo(quotePrice0.getCarNo()); // 运输号 + // 运输成本 + splitItem.setBlManual("1"); // 手工计算 + splitItem.setCostNo("-1"); // 固定成本 + splitItem.setBatchNo(quotePriceItem.getBatchNo()); + splitItem.setTransWeight(quotePriceItem.getTransWeight()); // 运输重量 + splitItem.setTransVolume(BigDecimal.ZERO); // 运输体积 - // 起点到目的点 - splitItem.setSendPlace(quotePrice0.getStartSiteName()); - splitItem.setDestPlace(quotePrice0.getNextSiteName()); + // 供应商 + splitItem.setSupplierCode(quotePriceItem.getSupplierCode()); // 供应商 + splitItem.setTransSignNo(quotePriceItem.getCarNo()); // 运输号 - splitItem.setBillMonth(DateUtils.parseDateToStr(DateUtils.YYYY_MM,waybill.getSendDate())); - splitItem.setTradeDate(waybill.getSignDate()); + // 起点到目的点 + splitItem.setSendPlace(quotePriceItem.getStartSiteName()); + splitItem.setDestPlace(quotePriceItem.getNextSiteName()); - // 成本分摊 - splitItem.setFeeType("1002"); // 网点机场短驳费 - splitItem.setSplitType("1"); // 按重量分摊 - splitItem.setFeeItemId(-1L); // 无成本费用项来源 - splitItem.setSplitValue(waybill.getBillWeight()); // 分摊重量 + splitItem.setBillMonth(DateUtils.parseDateToStr(DateUtils.YYYY_MM, waybill.getSendDate())); + splitItem.setTradeDate(waybill.getSignDate()); - // 计算公式 首重1Kg 10元,续重1kg 1元 - // 总费用=单价*公里数 - BigDecimal totalDbCostFee = quotePrice0.getPrice().multiply(quotePrice0.getDistance()); - // 按总重量分摊 + // 成本分摊 + splitItem.setFeeType("1002"); // 网点机场短驳费 + splitItem.setSplitType("1"); // 按重量分摊 + splitItem.setFeeItemId(-1L); // 无成本费用项来源 + splitItem.setSplitValue(waybill.getBillWeight()); // 分摊重量 - 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()); + // 计算公式 首重1Kg 10元,续重1kg 1元 + // 总费用=单价*公里数 + BigDecimal totalDbCostFee = quotePriceItem.getPrice().multiply(quotePriceItem.getDistance()); + // 按总重量分摊 - double costFee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString()); + String itemCalcExpr = quotePriceItem.getCalculateExpression(); + String calcExprStr = itemCalcExpr.replaceAll("w", waybill.getBillWeight().stripTrailingZeros().toPlainString()) + .replaceAll("t", quotePriceItem.getTransWeight().stripTrailingZeros().toPlainString()) + .replaceAll("c", totalDbCostFee.stripTrailingZeros().toPlainString()); - log.info("网点机场短驳费:计算公式:" + calcExprStr + ",重量:" + waybill.getBillWeight().stripTrailingZeros().toPlainString()); + double costFee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString()); - 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("网点机场短驳费"); + log.info("网点机场短驳费:计算公式:" + calcExprStr + ",重量:" + waybill.getBillWeight().stripTrailingZeros().toPlainString()); - // 总成本费用 - splitItem.setTransCostFee(totalDbCostFee); - splitItem.setCnyFee(totalDbCostFee); + costFee = WaybillHelper.calcSettledFee(costFee, quotePriceItem.getPriceType()); - // 插入分摊明细数据 - emisTmsCostFeeSplitMapper.insertEmisTmsCostFeeSplit(splitItem); + BigDecimal splitCostFee = BigDecimal.valueOf(costFee); + splitItem.setCostFee(splitCostFee); + splitItem.setCurrency("CNY"); + splitItem.setCalcExpr(itemCalcExpr); + splitItem.setCalcRemark(calcExprStr + "=" + splitCostFee.stripTrailingZeros().toPlainString()); + splitItem.setRemark("网点机场短驳费"); + splitItem.setBlVirtual(waybill.getBlVirtual()); + // 总成本费用 + splitItem.setTransCostFee(totalDbCostFee); + splitItem.setCnyFee(totalDbCostFee); + + // 插入分摊明细数据 + emisTmsCostFeeSplitMapper.insertEmisTmsCostFeeSplit(splitItem); + } + } + + // 机场提货费操作费 - 1004 + List fixedQuotePrice1004List=emisTmsCostQuotePriceMapper.matchBatchFixedQuotePriceByBillCode(billCode,"1004",-1); + 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(mainBillCode); + 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(quotePriceItem.getEtd()); + + // 成本分摊 + splitItem.setFeeType("1004"); // 网点机场操作费 + splitItem.setSplitType("1"); // 按重量分摊 + splitItem.setFeeItemId(-1L); // 无成本费用项来源 + splitItem.setSplitValue(waybill.getBillWeight()); // 分摊重量 + + // 总费用=单价*公里数 + BigDecimal totalDbCostFee = quotePriceItem.getPrice().multiply(quotePriceItem.getTransWeight()); + + 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()); + + // 计算单次成本: 如果低于最低报价,则使用最低成本来分摊 + 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()) + .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); + splitItem.setPrice(quotePriceItem.getPrice()); + splitItem.setBlVirtual(waybill.getBlVirtual()); + + // 插入分摊明细数据 + emisTmsCostFeeSplitMapper.insertEmisTmsCostFeeSplit(splitItem); + } } // 搜索已录入成本的费用分摊 @@ -444,6 +569,8 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService } } } + + mergeCostFeeByBillCode(billCode); return 1; @@ -672,14 +799,21 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService } EmisWaybill waybill = billCodeItem.getWaybillDetail(); + + String mainBillCode=waybill.getBillCode(); + if("1".equals(waybill.getBlVirtual())){ + mainBillCode=waybill.getMasterBillCode(); + } + EmisTmsCostFee costFeeDetail= billCodeItem.getCostFeeDetail(); + // 循环费用类型 for (EmisTmsCostFeeFeeitem feeItem: listFeeItemRel) { EmisTmsCostFeeSplit splitItem = new EmisTmsCostFeeSplit(); splitItem.setBillCode(billCode); - splitItem.setMainBillCode(billCode); + splitItem.setMainBillCode(mainBillCode); splitItem.setBillWeight(waybill.getBillWeight()); // 运单重量 splitItem.setTotalVolume(waybill.getTotalVolume()); // 运单体积 @@ -831,12 +965,12 @@ public class EmisTmsCostFeeServiceImpl implements IEmisTmsCostFeeService updProfit.setBillFee(emisTmsCostProfit.getBillFee()); // 获取主单成本费用 - double costFee=emisTmsCostFeeSplitMapper.getCostFeeByMainBillCode(billCode); + double costFee=emisTmsCostFeeSplitMapper.getCostFeeByMainBillCode(mainBillCode); updProfit.setCostFee(BigDecimal.valueOf(costFee)); updProfit.setBillProfit(emisTmsCostProfit.getBillFee().subtract(updProfit.getCostFee())); emisTmsCostProfitMapper.updateEmisTmsCostProfit(updProfit); - log.info("==>费用计算:==>:{}: {}-{}=",billCode,updProfit.getBillFee(),updProfit.getCostFee(),updProfit.getBillProfit()); + log.info("==>费用计算:==>:{}:{}-{}=",mainBillCode+":"+billCode,updProfit.getBillFee(),updProfit.getCostFee(),updProfit.getBillProfit()); return 1; } @@ -956,4 +1090,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/EmisTmsCostFeeSplitMapper.xml b/emis-biz/src/main/resources/mapper/EmisTmsCostFeeSplitMapper.xml index cb506445c..4ea49e016 100644 --- a/emis-biz/src/main/resources/mapper/EmisTmsCostFeeSplitMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisTmsCostFeeSplitMapper.xml @@ -115,7 +115,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and a.batch_no=#{batchNo} and a.fee_item_id = #{feeItemId} - 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}, '%') ) + + + and ( FIND_IN_SET(a.main_bill_code,#{mainBillCode}) or a.main_bill_code like concat('%', #{mainBillCode}, '%') ) and a.send_place=#{sendPlace} and a.dest_place=#{destPlace} @@ -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} + + update emis_tms_cost_fee_split set del_flag='1' + where del_flag='0' + and bill_code = #{billCode} + and fee_type = #{feeType} + + update emis_tms_cost_fee_split set del_flag='1' where del_flag='0' diff --git a/emis-biz/src/main/resources/mapper/EmisTmsCostProfitMapper.xml b/emis-biz/src/main/resources/mapper/EmisTmsCostProfitMapper.xml index 671196bc2..5219138ef 100644 --- a/emis-biz/src/main/resources/mapper/EmisTmsCostProfitMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisTmsCostProfitMapper.xml @@ -37,7 +37,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" a.bill_code=b.bill_code and a.del_flag='0' and b.del_flag='0' and b.id = #{id} - and FIND_IN_SET(b.`bill_code`,#{billCode}) + + and ( + FIND_IN_SET(b.`bill_code`,#{billCode}) or + exists ( + select 1 from emis_waybill c where c.master_bill_code = a.bill_code and FIND_IN_SET(c.`bill_code`,#{billCode}) + ) + ) and b.standard_fee = #{standardFee} and b.bill_fee = #{billFee} and b.cost_fee = #{costFee} @@ -100,6 +106,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and a.calc_fee_type = #{params.calcFeeType} + + + and exists ( + select 1 from emis_waybill_batch_status ewbs where a.bill_code=ewbs.bill_code + ) + + + + and not exists ( + select 1 from emis_waybill_batch_status ewbs where a.bill_code=ewbs.bill_code + ) + + + + + and exists ( + select 1 from emis_waybill_batch_status ewbs where a.bill_code=ewbs.bill_code + ) + + + + and not exists ( + select 1 from emis_waybill_batch_status ewbs where a.bill_code=ewbs.bill_code + ) + + and a.send_date = ]]> #{params.beginSendDate} @@ -202,11 +234,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from emis_tms_cost_profit where id = #{id} + update emis_tms_cost_profit set del_flag='1' where id = #{id} - delete from emis_tms_cost_profit where id in + update emis_tms_cost_profit set del_flag='1' where id in #{id} diff --git a/emis-biz/src/main/resources/mapper/EmisTmsCostQuotePriceMapper.xml b/emis-biz/src/main/resources/mapper/EmisTmsCostQuotePriceMapper.xml index 535eb0a54..2748846c2 100644 --- a/emis-biz/src/main/resources/mapper/EmisTmsCostQuotePriceMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisTmsCostQuotePriceMapper.xml @@ -10,13 +10,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + - + @@ -32,7 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, start_site_code, next_site_code, distance, fee_type, price, currency, bill_type, supplier_code, start_date, end_date, remark, tenant_id, del_flag, create_by, create_time, update_by, update_time, create_site, update_site from emis_tms_cost_quote_price + select id, start_site_code, next_site_code, distance, fee_type, fee, least_price, price_type, price, currency, start_weight, end_weight, initial_weight, additional_weight, condition_expression, calculate_expression, bill_type, supplier_code, start_date, end_date, bl_open, remark, tenant_id, del_flag, create_by, create_time, update_by, update_time, create_site, update_site from emis_tms_cost_quote_price - SELECT DISTINCT a.start_site_code, a.next_site_code, a.distance, - a.fee_type, + a.least_price, + a.price_type, + a.fee, a.price, + a.fee_type, a.currency, a.bill_type, a.supplier_code, a.start_date, a.end_date, + a.calculate_expression, b.batch_no, b.car_no, @@ -94,9 +107,12 @@ 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} @@ -108,12 +124,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and next_site_code = #{nextSiteCode} and distance = #{distance} and fee_type = #{feeType} + and fee = #{fee} and price = #{price} and currency = #{currency} + and start_weight = #{startWeight} + and end_weight = #{endWeight} + and initial_weight = #{initialWeight} + and additional_weight = #{additionalWeight} + and condition_expression = #{conditionExpression} + and calculate_expression = #{calculateExpression} and bill_type = #{billType} and supplier_code = #{supplierCode} and start_date = #{startDate} and end_date = #{endDate} + and bl_open = #{blOpen} and remark = #{remark} and tenant_id = #{tenantId} and del_flag = #{delFlag} @@ -127,11 +151,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + insert into emis_tms_cost_quote_price @@ -140,12 +164,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" next_site_code, distance, fee_type, + fee, + least_price, + price_type, price, currency, + start_weight, + end_weight, + initial_weight, + additional_weight, + condition_expression, + calculate_expression, bill_type, supplier_code, start_date, end_date, + bl_open, remark, tenant_id, del_flag, @@ -155,19 +189,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update_time, create_site, update_site, - + #{id}, #{startSiteCode}, #{nextSiteCode}, #{distance}, #{feeType}, + #{fee}, + #{leastPrice}, + #{priceType}, #{price}, #{currency}, + #{startWeight}, + #{endWeight}, + #{initialWeight}, + #{additionalWeight}, + #{conditionExpression}, + #{calculateExpression}, #{billType}, #{supplierCode}, #{startDate}, #{endDate}, + #{blOpen}, #{remark}, #{tenantId}, #{delFlag}, @@ -177,7 +221,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{updateTime}, #{createSite}, #{updateSite}, - + @@ -187,12 +231,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" next_site_code = #{nextSiteCode}, distance = #{distance}, fee_type = #{feeType}, + fee = #{fee}, + least_price = #{leastPrice}, + price_type = #{priceType}, price = #{price}, currency = #{currency}, + start_weight = #{startWeight}, + end_weight = #{endWeight}, + initial_weight = #{initialWeight}, + additional_weight = #{additionalWeight}, + condition_expression = #{conditionExpression}, + calculate_expression = #{calculateExpression}, bill_type = #{billType}, supplier_code = #{supplierCode}, start_date = #{startDate}, end_date = #{endDate}, + bl_open = #{blOpen}, remark = #{remark}, tenant_id = #{tenantId}, del_flag = #{delFlag}, @@ -207,11 +261,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from emis_tms_cost_quote_price where id = #{id} + update emis_tms_cost_quote_price set del_flag='1' where id = #{id} - delete from emis_tms_cost_quote_price where id in + update emis_tms_cost_quote_price set del_flag='1' where id in #{id}