应付模块菜单调整,新增应付费用编辑等

This commit is contained in:
liuminghui
2026-11-16 15:50:51 +08:00
parent 5b8d4de262
commit 49f24a6b1b
66 changed files with 3247 additions and 119 deletions
@@ -136,6 +136,10 @@ public class BmsSupplier extends BaseEntity
@Excel(name = "合作状态", readConverterExp = "0=正常,1=暂停,2=终止")
private String cooperationStatus;
/** 数据来源,字典 bms_supplier_data_source。空表示未填写 */
@Excel(name = "数据来源", dictType = "bms_supplier_data_source")
private String dataSource;
/** 绑定的渠道/服务ID */
private String channelIds;
@@ -26,6 +26,9 @@ public interface BmsSupplierMapper
/** 修改供应商 */
public int updateBmsSupplier(BmsSupplier bmsSupplier);
/** 只更新供应商绑定的渠道编码。 */
public int updateSupplierChannels(BmsSupplier bmsSupplier);
/** 删除供应商 */
public int deleteBmsSupplierBySupplierId(Long supplierId);
@@ -26,6 +26,9 @@ public interface IBmsSupplierService
/** 修改供应商 */
public int updateBmsSupplier(BmsSupplier bmsSupplier);
/** 只改这一家供应商绑定的渠道,其它资料不动。 */
public int bindChannels(Long supplierId, String channelIds);
/** 批量删除供应商 */
public int deleteBmsSupplierBySupplierIds(Long[] supplierIds);
@@ -1,6 +1,7 @@
package com.bms.customer.supplierinfo.service.impl;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import com.bms.common.annotation.DataScope;
@@ -302,6 +303,61 @@ public class BmsSupplierServiceImpl implements IBmsSupplierService
return bmsSupplierMapper.updateBmsSupplier(bmsSupplier);
}
/**
* 只改绑定渠道。不走整单修改,避免把附件、采购员和合同日期清掉。
*/
@Override
public int bindChannels(Long supplierId, String channelIds)
{
if (supplierId == null)
{
throw new ServiceException("请选择供应商");
}
if (bmsSupplierMapper.selectBmsSupplierBySupplierId(supplierId) == null)
{
throw new ServiceException("供应商不存在");
}
String value = joinChannels(channelIds);
if (value.length() > 1000)
{
throw new ServiceException("绑定的渠道过多,请减少后再保存");
}
BmsSupplier row = new BmsSupplier();
row.setSupplierId(supplierId);
row.setChannelIds(value);
row.setUpdateBy(SecurityUtils.getUsername());
row.setUpdateTime(DateUtils.getNowDate());
int rows = bmsSupplierMapper.updateSupplierChannels(row);
if (rows == 0)
{
throw new ServiceException("供应商不存在");
}
return rows;
}
/** 渠道编码去空白、去重,仍按选择顺序用逗号拼起来。 */
private static String joinChannels(String channelIds)
{
if (StringUtils.isEmpty(channelIds))
{
return "";
}
LinkedHashSet<String> codes = new LinkedHashSet<>();
for (String part : channelIds.split(","))
{
if (part == null)
{
continue;
}
String code = part.trim();
if (!code.isEmpty())
{
codes.add(code);
}
}
return String.join(",", codes);
}
@Transactional(rollbackFor = Exception.class)
@Override
public int deleteBmsSupplierBySupplierIds(Long[] supplierIds)
@@ -20,6 +20,9 @@ public class SrvBillAirAllocFee
/** 费用状态,字典 bill_fee_status */
private String billFeeStatus;
/** 费用类型,字典 bms_fee_type 的英文编码 */
private String feeType;
private String feeName;
private BigDecimal price;
@@ -15,9 +15,12 @@ public class SrvBillAirFee
private String billCode;
/** 附加费编号 prc_surcharge.sc_id */
/** 费用类型,字典 bms_fee_type 的英文编码 */
private String feeType;
/** 附加费配置ID,对应 prc_surcharge.sc_id */
private Long scId;
/** 附加费名称,仅展示,不入库 */
private String feeName;
@@ -0,0 +1,21 @@
package com.bms.price.domain;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
/** 一票订单的应付费用,按 abcd 四段排好。 */
@Data
public class PayOrderFeeBoard
{
private String billId;
private String orderNo;
private String ladingNo;
private List<PayOrderFeeSection> sections = new ArrayList<>();
/** 这票订单的应付费用日志,新的在前 */
private List<PrcPayBillFeeLog> logs = new ArrayList<>();
}
@@ -0,0 +1,47 @@
package com.bms.price.domain;
import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
/** 应付列表费用弹框里的一条费用。 */
@Data
public class PayOrderFeeLine
{
/** 费用明细 ID。新增时为空 */
private String feeId;
/** 费用类型,字典 bms_fee_type 的英文编码。手输名称放不下时记 MANUAL */
private String feeType;
/** 费用项名称。手工费用按填写的名称保存 */
private String feeName;
/** 1A 2B 3C 4D */
private String level;
private BigDecimal amount;
private String currency;
/** CALC 尾程计算,LADING 提单分摊,MANUAL 手工 */
private String feeSource;
private String remark;
/** 已进入应付账单时不能删除 */
private Long statementLineId;
/** 创建人 */
private String createBy;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/** 更新人 */
private String updateBy;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
}
@@ -0,0 +1,16 @@
package com.bms.price.domain;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
/** 应付费用的一个阶段。1A 头程仓储,2B 提单运输,3C 清关,4D 尾程。 */
@Data
public class PayOrderFeeSection
{
private String level;
private String title;
private List<PayOrderFeeLine> fees = new ArrayList<>();
}
@@ -0,0 +1,17 @@
package com.bms.price.domain;
import lombok.Data;
/** 应付列表查询条件。 */
@Data
public class PayOrderQuery
{
private String orderNo;
/** 多个订单号。由服务按逗号、空格或换行拆开。 */
private java.util.List<String> orderNos;
private String ladingNo;
private String customerName;
}
@@ -0,0 +1,14 @@
package com.bms.price.domain;
import lombok.Data;
/** 应付列表上的费用重算条件。一次只按订单号或提单号其中一种。 */
@Data
public class PayOrderRecalcCommand
{
/** ORDER 按订单号,LADING 按提单号 */
private String sourceType;
/** 单号原文。可用逗号、空格或换行分隔 */
private String text;
}
@@ -0,0 +1,18 @@
package com.bms.price.domain;
import lombok.Data;
/** 费用重算里的一票结果。 */
@Data
public class PayOrderRecalcLine
{
private String orderNo;
private String ladingNo;
/** 这一票是否已经生成应付费用 */
private boolean success;
/** 失败原因。成功时为空 */
private String message;
}
@@ -0,0 +1,19 @@
package com.bms.price.domain;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
/** 一次费用重算的结果。失败行不影响已经成功的订单。 */
@Data
public class PayOrderRecalcResult
{
/** 计费成功的订单数 */
private int successCount;
/** 未生成费用的订单数,含找不到的单号 */
private int failCount;
/** 每一票或每一个没对上的单号 */
private List<PayOrderRecalcLine> lines = new ArrayList<>();
}
@@ -0,0 +1,42 @@
package com.bms.price.domain;
import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
/** 应付列表里的一票订单。提单号来自订单扩展上的空运单号。 */
@Data
public class PayOrderRow
{
private String billId;
private String orderNo;
private String ladingNo;
private String trackingNo;
private String customerName;
private String productName;
private String countryName;
private String channelName;
private BigDecimal chargeWeight;
private BigDecimal payTotal;
private String currency;
/** 应付计费状态,字典 bms_pay_calc_status:1计费成功,2计费失败 */
private Integer payCalcStatus;
/** 计费失败原因 */
private String payCalcMsg;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date bizDate;
}
@@ -24,8 +24,15 @@ public class PrcPayBill implements Serializable
private BigDecimal redlineAmount;
/** 成本价合计(当前计费结果) */
private BigDecimal costAmount;
/** 应付合计(当前等于成本价) */
/** 应付合计(当前等于成本价,落库后按全部未删除明细重算) */
private BigDecimal payTotal;
/** 应付计费状态,字典 bms_pay_calc_status:1计费成功,2计费失败 */
private Integer payCalcStatus;
/** 计费失败原因,最长 100 字 */
private String payCalcMsg;
/** 业务员/销售员 */
private String belongSaler;
/** 销售员编码 */
@@ -17,8 +17,13 @@ public class PrcPayBillFee implements Serializable
private Long billId;
/** 应付主表ID */
private String payBillId;
/** 费用类型,字典 bms_fee_type 的英文编码 */
private String feeType;
/** 展示用的费用项名称,不入库。附加费取配置名称,其余取字典标签 */
private String feeName;
/** 尾程计算时是附加费配置ID。提单分摊时是 srv_bill_air_fee.id */
private Long scId;
/** 费用所属阶段:1 a段,2 b段,3 c段,4 d段 */
@@ -31,7 +36,7 @@ public class PrcPayBillFee implements Serializable
/** CALC 计算,LADING 提单分摊,MANUAL 人工 */
private String feeSource;
/** 来源数据id */
/** 来源数据id。提单分摊时为 srv_bill_air_fee.id */
private String sourceId;
/** 是否删除:0未删除 1已删除 */
@@ -44,6 +49,16 @@ public class PrcPayBillFee implements Serializable
private Long settleSupplierId;
private String settleSupplierName;
/** 创建人 */
private String createBy;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 更新人 */
private String updateBy;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}
@@ -0,0 +1,37 @@
package com.bms.price.domain;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
/** 应付费用日志 prc_pay_bill_fee_log */
@Data
public class PrcPayBillFeeLog implements Serializable
{
private static final long serialVersionUID = 1L;
private Long logId;
private String feeId;
private Long billId;
/** 费用项 */
private String feeName;
private BigDecimal amount;
private String currency;
/** 操作类型,字典 bms_pay_fee_log_type */
private String operationType;
/** 操作人 */
private String createBy;
/** 操作时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
}
@@ -0,0 +1,30 @@
package com.bms.price.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.bms.price.domain.PayOrderQuery;
import com.bms.price.domain.PayOrderRow;
/** 应付列表。 */
public interface PayOrderListMapper
{
List<PayOrderRow> selectList(PayOrderQuery query);
PayOrderRow selectRow(@Param("billId") String billId);
/**
* 按订单号精确找出要重算的订单。
*
* @param orderNos 订单号,已去重
* @return 订单号和提单号
*/
List<PayOrderRow> selectByOrderNos(@Param("orderNos") List<String> orderNos);
/**
* 按提单号找出下面的全部订单。提单号对应订单扩展上的空运单号。
*
* @param ladingNos 提单号,已去重
* @return 这些提单下的订单
*/
List<PayOrderRow> selectByLadingNos(@Param("ladingNos") List<String> ladingNos);
}
@@ -0,0 +1,25 @@
package com.bms.price.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.bms.price.domain.PrcPayBillFeeLog;
/** 应付费用日志 prc_pay_bill_fee_log。 */
public interface PrcPayBillFeeLogMapper
{
/**
* 批量写入应付费用日志。
*
* @param logs 本次操作的费用快照
* @return 影响行数
*/
int insertBatch(@Param("list") List<PrcPayBillFeeLog> logs);
/**
* 按订单读取费用日志,新的在前。
*
* @param billId 计费订单 ID
* @return 日志
*/
List<PrcPayBillFeeLog> selectByBillId(@Param("billId") Long billId);
}
@@ -15,6 +15,39 @@ public interface PrcPayBillFeeMapper
*/
public List<PrcPayBillFee> selectByBillId(Long billId);
/**
* 按费用明细 ID 读取一行。已逻辑删除的也返回,调用方自己判断。
*
* @param feeId 费用明细 ID
* @return 费用行,没有时为 null
*/
public PrcPayBillFee selectByFeeId(@Param("feeId") String feeId);
/**
* 写入一条手工费用。来源固定为 MANUAL,并记下创建人、更新人。
*
* @param fee 费用项、金额、币种、说明和所属阶段
* @return 影响行数
*/
public int insertManual(PrcPayBillFee fee);
/**
* 逻辑删除一条费用。已经进入应付账单的行不删。
*
* @param feeId 费用明细 ID
* @param operator 当前登录人
* @return 影响行数
*/
public int markFeeDeleted(@Param("feeId") String feeId, @Param("operator") String operator);
/**
* 这票订单里已经进入应付账单的计算费用条数。有则不能重算覆盖。
*
* @param billId 计费订单 ID
* @return 已出账的计算费用条数
*/
public int countSettledCalc(@Param("billId") Long billId);
/**
* 插入一条订单应付费用。
*
@@ -53,6 +86,9 @@ public interface PrcPayBillFeeMapper
/** 这条提单费用已经分摊到的订单。作废前取出,用来重算应付总额。 */
public List<Long> selectBillIdsByLadingFee(@Param("feeId") Long feeId);
/** 这条提单费用已经分摊、且还没删除的订单费用。作废前取出,用来记日志。 */
public List<PrcPayBillFee> selectAliveByLadingFee(@Param("feeId") Long feeId);
/** 明细还没挂上应付主表时,按订单补上主表 ID。单次不超过 1000 个订单。 */
public int bindPayBillId(@Param("billIds") List<Long> billIds);
@@ -65,4 +65,16 @@ public interface PrcPayBillMapper
/** 订单还没有应付主表时补一行,总额随后按明细重算。单次不超过 1000 个订单。 */
int insertMissingPayBills(@Param("billIds") List<Long> billIds, @Param("operator") String operator);
/**
* 写下这票应付的计费状态和失败原因。成功时原因传空。
*
* @param billId 计费订单 ID,对应 prc_pay_bill.bill_id
* @param status 1计费成功,2计费失败
* @param message 失败原因,最长 100 字;成功时为 null
* @param operator 操作人账号
* @return 影响行数
*/
int markCalcStatus(@Param("billId") Long billId, @Param("status") Integer status,
@Param("message") String message, @Param("operator") String operator);
}
@@ -0,0 +1,646 @@
package com.bms.price.pay;
import java.math.BigDecimal;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.bms.common.enums.PaymentMesEnum;
import com.bms.common.exception.ServiceException;
import com.bms.masterdata.domain.ServiceChannel;
import com.bms.masterdata.mapper.ServiceChannelMapper;
import com.bms.price.domain.PayOrderCostResult;
import com.bms.price.domain.PayPostcodeGroup;
import com.bms.price.domain.PayPostcodeLine;
import com.bms.price.domain.PayProduct;
import com.bms.price.domain.PaySurcharge;
import com.bms.price.domain.PaySurchargeRule;
import com.bms.price.domain.PayWeightBand;
import com.bms.price.domain.PrcOrderBill;
import com.bms.price.domain.PrcOrderBillExt;
import com.bms.price.mapper.PayPostcodeMapper;
import com.bms.price.mapper.PrcOrderBillExtMapper;
import com.bms.price.mapper.PrcOrderBillMapper;
import com.bms.price.service.IPayProductService;
import com.bms.price.service.IPaySurchargeRuleService;
/**
* 按一票已经落库的订单,算出应付尾程运费和订单附加费。
* 这里只计算,不写费用。账单生成、Oracle 订单同步和其他入口都调用这一处。
*/
@Component
public class PayOrderFeeCalculator
{
private static final ZoneId SHANGHAI = ZoneId.of("GMT+8");
@Autowired
private PrcOrderBillMapper orderBillMapper;
@Autowired
private PrcOrderBillExtMapper orderBillExtMapper;
@Autowired
private ServiceChannelMapper serviceChannelMapper;
@Autowired
private IPayProductService payProductService;
@Autowired
private PayPostcodeMapper payPostcodeMapper;
@Autowired
private IPaySurchargeRuleService paySurchargeRuleService;
/**
* 计算一票订单的尾程运费和附加费。渠道、价卡、分区或重量不齐时抛出业务异常,调用方决定是否落库。
*
* @param billId 计费订单 ID,对应 prc_order_bill.bill_id
* @return 渠道、价卡版本、币种、尾程运费和订单附加费
*/
public PayOrderCostResult calculate(Long billId)
{
PrcOrderBill bill = requireOrder(billId);
PrcOrderBillExt ext = orderBillExtMapper.selectByBillId(bill.getBillId());
ServiceChannel channel = resolveChannel(ext);
Date priceDate = bizDate(bill);
PayProduct product = payProductService.selectPriceForDate(channel.getId(), priceDate);
BigDecimal weight = chargeWeight(bill);
Integer orderStatus = orderStatus(bill, ext);
List<PayPostcodeGroup> linked = linkedGroups(product);
String zoneName = resolveZone(channel, product, bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName(), linked);
applyCurrentSurcharge(channel.getId(), product);
List<PaySurchargeRule> billingRules = product.getBillingRules();
boolean postcodeOn = ruleOn(billingRules, PaySurchargeRules.POSTCODE);
boolean zoneOn = ruleOn(billingRules, PaySurchargeRules.ZONE);
List<PayRemoteBook.Hit> remoteHits = prefixRules(billingRules, PaySurchargeRules.POSTCODE)
? null : remoteHits(linked, bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName());
PayOrderCostResult result = PayCostCalculator.calculate(product, weight, bill.getPkgLength(), bill.getPkgWidth(),
bill.getPkgHeight(), bill.getDestPostcode(), zoneName, priceDate, orderStatus, remoteHits, postcodeOn, zoneOn,
bill.getCountryCode(), bill.getCountryName());
result.setBillId(bill.getBillId());
result.setChannelId(channel.getId());
result.setChannelName(channel.getChannelName());
result.setVersionNo(product.getVersionNo());
result.setMessage(explain(channel, product, result.getMessage()));
return result;
}
/**
* 读取这票订单当前尾程价卡上的归属供应商。渠道或价卡不齐时返回空字符串,不抛异常。
*
* @param billId 计费订单 ID
* @return 价卡归属供应商名称,没有时为空字符串
*/
public String supplierName(Long billId)
{
if (billId == null)
{
return "";
}
try
{
PrcOrderBill bill = orderBillMapper.selectPrcOrderBillById(billId);
if (bill == null)
{
return "";
}
ServiceChannel channel = resolveChannel(orderBillExtMapper.selectByBillId(bill.getBillId()));
PayProduct product = payProductService.selectPriceForDate(channel.getId(), bizDate(bill));
return product.getSupplierName() == null ? "" : product.getSupplierName().trim();
}
catch (ServiceException ex)
{
return "";
}
}
/**
* 读取计费订单。单号为空或库里没有这票时抛出业务异常。
*
* @param billId 计费订单 ID
* @return 订单主表
*/
private PrcOrderBill requireOrder(Long billId)
{
if (billId == null)
{
throw PaymentMesEnum.BMS_PAY_PICK_ORDER.exception();
}
PrcOrderBill bill = orderBillMapper.selectPrcOrderBillById(billId);
if (bill == null)
{
throw PaymentMesEnum.BMS_PAY_ORDER_MISS.exception();
}
return bill;
}
/**
* 取价日。优先用订单业务日,没有时用下单时间。
*
* @param bill 计费订单
* @return 用来命中价卡版本的日期,两边都空时为 null
*/
private static Date bizDate(PrcOrderBill bill)
{
return bill.getBizDate() != null ? bill.getBizDate() : bill.getOrderTime();
}
/**
* 计费重。按计费重、重量、实重、收货重的顺序,取第一个大于 0 的值。
*
* @param bill 计费订单
* @return 公斤数,都没有时为 null
*/
private static BigDecimal chargeWeight(PrcOrderBill bill)
{
return firstPositive(bill.getChargeWeight(), bill.getWeight(), bill.getActualWeight(), bill.getReceiveWeight());
}
/**
* 订单状态。主表没有时用扩展表,用来判断退件类附加费是否收取。
*
* @param bill 计费订单
* @param ext 订单扩展,可以没有
* @return 订单状态,两边都没有时为 null
*/
private static Integer orderStatus(PrcOrderBill bill, PrcOrderBillExt ext)
{
return bill.getOrderStatus() != null ? bill.getOrderStatus() : (ext == null ? null : ext.getOrderStatus());
}
/**
* 拼出这次计算用了哪条渠道、哪个产品和哪一版价卡。
*
* @param channel 订单渠道
* @param product 订单日期命中的价卡版本
* @param detail 计算器给出的费用说明
* @return 带渠道和版本的说明
*/
private static String explain(ServiceChannel channel, PayProduct product, String detail)
{
String channelName = channel.getChannelName() == null ? channel.getChannelCode() : channel.getChannelName();
String end = product.getTermEnd() == null ? "不限" : day(product.getTermEnd());
return "渠道「" + channelName + "」" + product.getProductName() + " 第 " + product.getVersionNo()
+ " 版(" + day(product.getTermStart()) + " 至 " + end + ")," + detail;
}
/**
* 运费仍按订单日期取版本。附加费明细和计费条件改用这个产品今天生效的版本。
*
* @param channelId 渠道 ID
* @param priced 订单日期已经命中的价卡,方法会改写它的附加费和计费条件
*/
private void applyCurrentSurcharge(String channelId, PayProduct priced)
{
try
{
PayProduct current = payProductService.selectPriceForDate(channelId, new Date());
if (current != null && current.getSurcharges() != null)
{
priced.setSurcharges(current.getSurcharges());
}
}
catch (ServiceException ignored)
{
// 今天没有生效版本时,附加费明细仍用订单日期命中的那一版
}
List<PaySurchargeRule> rules = paySurchargeRuleService.listForCalc(priced);
priced.setBillingRules(rules == null ? new ArrayList<>() : rules);
}
/**
* 这条计费条件是否启用。没有配置行时视为关闭。
*
* @param rules 当前产品的计费条件
* @param calcRule 条件编码,如 POSTCODE、ZONE
* @return 有启用行时为 true
*/
private static boolean ruleOn(List<PaySurchargeRule> rules, String calcRule)
{
if (rules == null)
{
return false;
}
for (PaySurchargeRule rule : rules)
{
if (rule != null && calcRule.equals(rule.getCalcRule()) && !"0".equals(rule.getEnabled()))
{
return true;
}
}
return false;
}
/**
* 计费条件里是否已经写了邮编前缀。写了就不再去应付邮编配置里查偏远。
*
* @param rules 当前产品的计费条件
* @param calcRule 条件编码,目前用于 POSTCODE
* @return 有非空邮编前缀时为 true
*/
private static boolean prefixRules(List<PaySurchargeRule> rules, String calcRule)
{
if (rules == null)
{
return false;
}
for (PaySurchargeRule rule : rules)
{
if (rule == null || !calcRule.equals(rule.getCalcRule()) || "0".equals(rule.getEnabled()) || rule.getDetail() == null)
{
continue;
}
Object postcodes = rule.getDetail().get("postcodes");
if (postcodes != null && !String.valueOf(postcodes).isBlank())
{
return true;
}
}
return false;
}
/**
* 用产品名称、报价工作表、字典值和关联分区表,对上这份产品的邮编配置。
*
* @param product 当前价卡版本
* @return 名称能对上的邮编组,没有时为空列表
*/
private List<PayPostcodeGroup> linkedGroups(PayProduct product)
{
List<String> names = new ArrayList<>();
addName(names, product.getProductName());
addName(names, product.getSheetName());
addName(names, product.getDictValue());
addName(names, product.getRelatedSheet());
if (names.isEmpty())
{
return new ArrayList<>();
}
List<PayPostcodeGroup> found = payPostcodeMapper.selectGroupsForProduct(names);
return found == null ? new ArrayList<>() : found;
}
/**
* 把非空名称放进匹配列表,已有的不重复加入。
*
* @param names 已经收集的名称
* @param value 产品名、工作表名或字典值
*/
private static void addName(List<String> names, String value)
{
if (value == null || value.isBlank())
{
return;
}
String name = value.trim();
if (!names.contains(name))
{
names.add(name);
}
}
/**
* 判断这票是否偏远。产品报价表已经挂了偏远名单时只用那一份,没命中就不再回价卡邮编。
* 没有这份产品名单时,改查目的国家的偏远邮编;国家名单没命中则返回 null,价卡上的邮编条件仍可用。
*
* @param linked 已对上的邮编组
* @param postcode 收件邮编
* @param countryCode 目的国二字码
* @param countryName 目的国名称
* @return 命中的偏远分区;产品有名单但没命中时返回空列表
*/
private List<PayRemoteBook.Hit> remoteHits(List<PayPostcodeGroup> linked, String postcode, String countryCode, String countryName)
{
boolean productBook = false;
for (PayPostcodeGroup group : linked)
{
if (group != null && PayRemoteBook.remoteGroup(group))
{
productBook = true;
break;
}
}
if (productBook)
{
return hitsOf(linked, postcode, countryCode, countryName);
}
if (blank(countryCode) && blank(countryName))
{
return null;
}
List<PayPostcodeGroup> countryGroups = payPostcodeMapper.selectRemoteGroupsByCountry(countryCode, countryName);
if (countryGroups == null || countryGroups.isEmpty())
{
return null;
}
List<PayRemoteBook.Hit> hits = hitsOf(countryGroups, postcode, countryCode, countryName);
return hits == null || hits.isEmpty() ? null : hits;
}
/**
* 在给定邮编组里做偏远匹配。没有偏远组时返回 null,有组但邮编没命中时返回空列表。
*
* @param groups 参与匹配的邮编组
* @param postcode 收件邮编
* @param countryCode 目的国二字码
* @param countryName 目的国名称
* @return 命中结果
*/
private List<PayRemoteBook.Hit> hitsOf(List<PayPostcodeGroup> groups, String postcode, String countryCode, String countryName)
{
List<Long> remoteIds = new ArrayList<>();
boolean anyRemote = false;
for (PayPostcodeGroup group : groups)
{
if (group == null || group.getGroupId() == null || !PayRemoteBook.remoteGroup(group))
{
continue;
}
anyRemote = true;
if (sameCountry(group, countryCode, countryName))
{
remoteIds.add(group.getGroupId());
}
}
if (!anyRemote)
{
return null;
}
if (remoteIds.isEmpty())
{
return new ArrayList<>();
}
List<PayPostcodeLine> lines = postcode == null || postcode.isBlank()
? new ArrayList<>() : payPostcodeMapper.selectLinesByGroups(remoteIds);
return PayRemoteBook.hits(groups, lines, postcode, countryCode, countryName);
}
/**
* 价卡有多个地区时,选出这一票对应的价格列。优先用产品关联的邮编分区,对不上再按名称关键字找。
* 只有一个地区时返回 null,计费不再按分区过滤。
*
* @param channel 订单渠道,关键字匹配时备用
* @param product 当前价卡版本
* @param postcode 收件邮编
* @param countryCode 目的国二字码
* @param countryName 目的国名称
* @param linked 已对上的邮编组
* @return 价卡上的地区名,单地区时为 null
*/
private String resolveZone(ServiceChannel channel, PayProduct product, String postcode, String countryCode, String countryName,
List<PayPostcodeGroup> linked)
{
List<String> zoneNames = zoneNames(product);
if (zoneNames.size() <= 1)
{
return null;
}
List<Long> linkedZoneIds = zoneGroupIds(linked, countryCode, countryName);
if (!linkedZoneIds.isEmpty())
{
return decideZone(zoneNames, linkedZoneIds, postcode);
}
List<String> tokens = PayZoneMatcher.searchTokens(product.getProductName(), product.getSheetName());
if (tokens.isEmpty())
{
tokens = PayZoneMatcher.searchTokens(channel.getChannelName(), channel.getChannelCode());
}
if (tokens.isEmpty())
{
throw new ServiceException("产品「" + product.getProductName() + "」有多个地区,订单邮编无法对应到产品");
}
List<PayPostcodeGroup> groups = new ArrayList<>();
for (PayPostcodeGroup group : payPostcodeMapper.selectGroupsByTokens(tokens))
{
if (sameCountry(group, countryCode, countryName))
{
groups.add(group);
}
}
if (groups.isEmpty())
{
throw new ServiceException("产品「" + product.getProductName() + "」有多个地区,没有找到对应的邮编分区");
}
List<Long> groupIds = new ArrayList<>();
for (PayPostcodeGroup group : groups)
{
groupIds.add(group.getGroupId());
}
Set<Long> usable = new LinkedHashSet<>();
for (PayPostcodeLine key : payPostcodeMapper.selectRegionKeys(groupIds))
{
String region = key.getZoneName() != null && !key.getZoneName().isBlank() ? key.getZoneName() : key.getRegionName();
if (PayZoneMatcher.mapRegion(zoneNames, region) != null)
{
usable.add(key.getGroupId());
}
}
if (usable.isEmpty())
{
throw new ServiceException("产品「" + product.getProductName() + "」有多个地区,邮编分区对不上价卡上的地区");
}
return decideZone(zoneNames, new ArrayList<>(usable), postcode);
}
/**
* 在给定邮编组里,用收件邮编决定价卡地区。对不上时抛出业务异常。
*
* @param zoneNames 价卡上的地区名
* @param groupIds 参与匹配的邮编组
* @param postcode 收件邮编
* @return 命中的地区名
*/
private String decideZone(List<String> zoneNames, List<Long> groupIds, String postcode)
{
PayZoneMatcher.Decision decision = PayZoneMatcher.resolve(zoneNames, payPostcodeMapper.selectLinesByGroups(groupIds), postcode);
if (decision.getMessage() != null)
{
throw new ServiceException(decision.getMessage());
}
if (decision.getZoneName() == null)
{
throw PaymentMesEnum.BMS_PAY_NO_ZONE.exception();
}
return decision.getZoneName();
}
/**
* 取出用来选派送费的普通分区。偏远、附加费邮编和不可达不参与选区。
*
* @param linked 已对上的邮编组
* @param countryCode 目的国二字码
* @param countryName 目的国名称
* @return 可参与选区的邮编组 ID
*/
private static List<Long> zoneGroupIds(List<PayPostcodeGroup> linked, String countryCode, String countryName)
{
List<Long> ids = new ArrayList<>();
if (linked == null)
{
return ids;
}
for (PayPostcodeGroup group : linked)
{
if (group == null || group.getGroupId() == null || PayRemoteBook.remoteGroup(group) || "FEE".equals(group.getConfigKind()))
{
continue;
}
if ("UNREACH".equalsIgnoreCase(group.getCoverage() == null ? "" : group.getCoverage().trim()))
{
continue;
}
if (!sameCountry(group, countryCode, countryName))
{
continue;
}
ids.add(group.getGroupId());
}
return ids;
}
/**
* 收集价卡重量段和分区附加费上的地区名。
*
* @param product 当前价卡版本
* @return 去重后的地区名
*/
private static List<String> zoneNames(PayProduct product)
{
Set<String> names = new LinkedHashSet<>();
if (product.getWeightBands() != null)
{
for (PayWeightBand band : product.getWeightBands())
{
if (band != null && band.getZoneName() != null && !band.getZoneName().isBlank())
{
names.add(band.getZoneName().trim());
}
}
}
if (product.getSurcharges() != null)
{
for (PaySurcharge fee : product.getSurcharges())
{
if (fee != null && PaySurchargeRules.ZONE.equals(fee.getCalcRule()) && fee.getZoneName() != null && !fee.getZoneName().isBlank())
{
names.add(fee.getZoneName().trim());
}
}
}
return new ArrayList<>(names);
}
/**
* 判断邮编组是否和订单目的国相同。两边都没写国家时视为相同。
*
* @param group 邮编组
* @param countryCode 订单目的国二字码
* @param countryName 订单目的国名称
* @return 国家能对上时为 true
*/
private static boolean sameCountry(PayPostcodeGroup group, String countryCode, String countryName)
{
if (blank(countryCode) && blank(countryName))
{
return true;
}
if (blank(group.getCountryCode()) && blank(group.getCountryName()))
{
return true;
}
if (!blank(countryCode) && countryCode.equalsIgnoreCase(group.getCountryCode()))
{
return true;
}
return !blank(countryName) && countryName.equals(group.getCountryName());
}
/**
* 从订单扩展找出渠道。先按渠道 ID,再按渠道编码,最后按渠道名称。
*
* @param ext 订单计费扩展
* @return 服务渠道
*/
private ServiceChannel resolveChannel(PrcOrderBillExt ext)
{
if (ext == null)
{
throw PaymentMesEnum.BMS_PAY_NO_CHANNEL.exception();
}
ServiceChannel channel = blank(ext.getProductChannelId()) ? null : serviceChannelMapper.selectServiceChannelById(ext.getProductChannelId().trim());
if (channel == null && !blank(ext.getProductFloorCode()))
{
channel = serviceChannelMapper.selectServiceChannelByCode(ext.getProductFloorCode().trim());
}
if (channel == null && !blank(ext.getProductFloor()))
{
List<ServiceChannel> named = serviceChannelMapper.selectServiceChannelByName(ext.getProductFloor().trim());
if (named != null && named.size() > 1)
{
throw new ServiceException("渠道名称「" + ext.getProductFloor().trim() + "」对应了多条渠道,请先在订单上指定渠道");
}
channel = named == null || named.isEmpty() ? null : named.get(0);
}
if (channel == null)
{
throw PaymentMesEnum.BMS_PAY_CH_SYNC.exception();
}
return channel;
}
/**
* 把日期格式化成 yyyy-MM-dd。空日期表示不限。
*
* @param date 有效期起或止
* @return 日期文本
*/
private static String day(Date date)
{
if (date == null)
{
return "不限";
}
if (date instanceof java.sql.Date sql)
{
return sql.toLocalDate().toString();
}
return date.toInstant().atZone(SHANGHAI).toLocalDate().toString();
}
/**
* 按传入顺序取第一个大于 0 的重量。
*
* @param values 计费重、重量、实重、收货重
* @return 第一个正数,都没有时返回 null
*/
private static BigDecimal firstPositive(BigDecimal... values)
{
if (values == null)
{
return null;
}
for (BigDecimal value : values)
{
if (value != null && value.compareTo(BigDecimal.ZERO) > 0)
{
return value;
}
}
return null;
}
/**
* 判断文本是否为空。
*
* @param value 待判断文本
* @return 为 null 或空白时返回 true
*/
private static boolean blank(String value)
{
return value == null || value.isBlank();
}
}
@@ -23,6 +23,14 @@ public interface IPayOrderCostService
*/
PayOrderCostResult generateIsolated(Long billId);
/**
* 订单同步后落地尾程费用。已经进入应付账单的计算费用不再覆盖。
*
* @param billId 计费订单 ID
* @return 本次落地的结果;费用已经出账时返回 null
*/
PayOrderCostResult landIfOpen(Long billId);
/**
* 这票订单当前尾程价卡上的归属供应商名称。没有价卡时返回空字符串。
*
@@ -30,4 +38,12 @@ public interface IPayOrderCostService
* @return 价卡归属名称
*/
String cardSupplierName(Long billId);
/**
* 把这票订单记成应付计费失败。单独提交,不跟着外面回滚掉。
*
* @param billId 计费订单 ID
* @param reason 失败原因,最长 100 字
*/
void markCalcFail(Long billId, String reason);
}
@@ -0,0 +1,43 @@
package com.bms.price.service;
import java.util.List;
import com.bms.price.domain.PayOrderFeeBoard;
import com.bms.price.domain.PayOrderFeeLine;
import com.bms.price.domain.PayOrderQuery;
import com.bms.price.domain.PayOrderRecalcCommand;
import com.bms.price.domain.PayOrderRecalcResult;
import com.bms.price.domain.PayOrderRow;
/** 应付列表。 */
public interface IPayOrderListService
{
List<PayOrderRow> list(PayOrderQuery query);
PayOrderFeeBoard fees(String billId);
/**
* 在指定费用段手工增加一行费用。来源记 MANUAL,创建人是当前登录用户。
*
* @param billId 计费订单 ID
* @param line 费用项、金额、币种、说明和所属阶段
* @return 写入后的费用行
*/
PayOrderFeeLine addManualFee(String billId, PayOrderFeeLine line);
/**
* 逻辑删除一条应付费用。已经进入应付账单的费用不能删。
*
* @param feeId 费用明细 ID
*/
void removeFee(String feeId);
/**
* 按订单号或提单号批量重算尾程应付。一票失败不影响其他订单。
* 成功时应付主表记计费成功,应付总额按全部未删除明细重算。
* 失败时记计费失败和原因。已经进入应付账单的费用不覆盖。
*
* @param command 重算方式(ORDER 或 LADING)和单号原文
* @return 成功数、失败数和每一票的结果
*/
PayOrderRecalcResult recalc(PayOrderRecalcCommand command);
}
@@ -0,0 +1,170 @@
package com.bms.price.service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bms.common.utils.SecurityUtils;
import com.bms.price.domain.PrcPayBillFee;
import com.bms.price.domain.PrcPayBillFeeLog;
import com.bms.price.mapper.PrcPayBillFeeLogMapper;
/**
* 应付费用日志。各入口只调用这里,写入失败只打日志,不把异常交回业务。
*/
@Service
public class PayBillFeeLogService
{
private static final Logger log = LoggerFactory.getLogger(PayBillFeeLogService.class);
/** 新增,字典 bms_pay_fee_log_type */
public static final String ADD = "1";
/** 编辑 */
public static final String EDIT = "2";
/** 删除 */
public static final String DELETE = "3";
/** 重算费用 */
public static final String RECALC = "4";
/** 废弃 */
public static final String VOID = "5";
private static final int BATCH_SIZE = 200;
@Autowired
private PrcPayBillFeeLogMapper payBillFeeLogMapper;
/**
* 记一条费用日志。异常只打印,不向外抛。
*
* @param fee 费用项、金额、币种和所属订单
* @param operationType 字典值,见本类常量
*/
public void record(PrcPayBillFee fee, String operationType)
{
if (fee == null)
{
return;
}
record(Collections.singletonList(fee), operationType);
}
/**
* 按同一操作类型记一批费用日志。异常只打印,不向外抛。
*
* @param fees 本次涉及的费用
* @param operationType 字典值,见本类常量
*/
public void record(List<PrcPayBillFee> fees, String operationType)
{
try
{
List<PrcPayBillFeeLog> rows = snapshots(fees, operationType);
for (int from = 0; from < rows.size(); from += BATCH_SIZE)
{
payBillFeeLogMapper.insertBatch(rows.subList(from, Math.min(from + BATCH_SIZE, rows.size())));
}
}
catch (Exception ex)
{
log.error("写入应付费用日志失败 operationType={}", operationType, ex);
}
}
/**
* 读取一票订单的费用日志。表还没建或查询失败时返回空列表,并打印错误。
*
* @param billId 计费订单 ID
* @return 日志,新的在前
*/
public List<PrcPayBillFeeLog> list(Long billId)
{
if (billId == null)
{
return Collections.emptyList();
}
try
{
List<PrcPayBillFeeLog> rows = payBillFeeLogMapper.selectByBillId(billId);
return rows == null ? Collections.emptyList() : rows;
}
catch (Exception ex)
{
log.error("读取应付费用日志失败 billId={}", billId, ex);
return Collections.emptyList();
}
}
private List<PrcPayBillFeeLog> snapshots(List<PrcPayBillFee> fees, String operationType)
{
List<PrcPayBillFeeLog> rows = new ArrayList<>();
if (fees == null || fees.isEmpty() || operationType == null || operationType.isBlank())
{
return rows;
}
String operator = operator();
String type = cut(operationType.trim(), 32);
for (PrcPayBillFee fee : fees)
{
if (fee == null || fee.getBillId() == null)
{
continue;
}
PrcPayBillFeeLog row = new PrcPayBillFeeLog();
row.setFeeId(cut(fee.getFeeId(), 64));
row.setBillId(fee.getBillId());
row.setFeeName(cut(nameOf(fee), 100));
row.setAmount(fee.getAmount());
String currency = fee.getCurrency() == null ? null : fee.getCurrency().trim();
row.setCurrency(currency == null || currency.isEmpty() ? null : cut(currency, 10));
row.setOperationType(type);
row.setCreateBy(operator);
rows.add(row);
}
return rows;
}
private static String nameOf(PrcPayBillFee fee)
{
String name = fee.getFeeName() == null ? "" : fee.getFeeName().trim();
if (!name.isEmpty())
{
return name;
}
String type = fee.getFeeType() == null ? "" : fee.getFeeType().trim();
return type.isEmpty() ? "费用" : type;
}
private static String operator()
{
try
{
String name = SecurityUtils.getUsername();
if (name == null || name.isBlank())
{
return "system";
}
return cut(name.trim(), 64);
}
catch (Exception ex)
{
return "system";
}
}
private static String cut(String value, int max)
{
if (value == null)
{
return null;
}
String text = value.trim();
return text.length() <= max ? text : text.substring(0, max);
}
}
@@ -48,6 +48,7 @@ import com.bms.price.mapper.PrcPayBillFeeMapper;
import com.bms.price.pay.PaySettleSupport;
import com.bms.price.service.IPayBillService;
import com.bms.price.service.IPayOrderCostService;
import com.bms.price.service.PayBillFeeLogService;
import com.bms.price.service.IPrcPayBillFeeService;
/**
@@ -73,6 +74,9 @@ public class PayBillServiceImpl implements IPayBillService
@Autowired
private IPrcPayBillFeeService payBillFeeService;
@Autowired
private PayBillFeeLogService payBillFeeLogService;
@Autowired
private PayFinanceMapper payFinanceMapper;
@@ -577,22 +581,19 @@ public class PayBillServiceImpl implements IPayBillService
adjust.setFeeId(UUID.randomUUID().toString());
adjust.setBillId(line.getOrderBillId());
adjust.setPayBillId(source == null ? null : source.getPayBillId());
adjust.setFeeType("对账调整");
adjust.setFeeType("ADJUST");
adjust.setFeeName("对账调整");
adjust.setScId(open.getDiffId());
adjust.setFeeLevel(line.getFeeLevel());
adjust.setAmount(delta);
adjust.setCurrency(line.getCurrency());
adjust.setFeeSource("MANUAL");
adjust.setSourceId(source == null ? null : source.getFeeId());
adjust.setSourceId(source == null ? null : source.getSourceId());
adjust.setRemark(open.getReason());
adjust.setSettleSupplierId(bill.getSupplierId());
adjust.setSettleSupplierName(bill.getSupplierName());
payBillFeeMapper.insertPrcPayBillFee(adjust);
if (adjust.getSourceId() == null || adjust.getSourceId().isBlank())
{
payBillFeeMapper.fillSourceIdByFeeIds(List.of(adjust.getFeeId()));
}
payBillFeeLogService.record(adjust, PayBillFeeLogService.ADD);
payFinanceMapper.stampFee(adjust.getFeeId(), bill.getSupplierId(), bill.getSupplierName());
if (line.getOrderBillId() != null)
{
@@ -604,7 +605,7 @@ public class PayBillServiceImpl implements IPayBillService
extra.setOrderBillId(line.getOrderBillId());
extra.setOrderNo(line.getOrderNo());
extra.setLadingNo(line.getLadingNo());
extra.setFeeName(adjust.getFeeName());
extra.setFeeName("对账调整");
extra.setFeeSource("MANUAL");
extra.setFeeLevel(line.getFeeLevel());
extra.setAmount(delta);
@@ -35,6 +35,7 @@ import com.bms.price.pay.PayRemoteBook;
import com.bms.price.pay.PaySurchargeRules;
import com.bms.price.pay.PayZoneMatcher;
import com.bms.price.service.IPayOrderCostService;
import com.bms.price.service.PayBillFeeLogService;
import com.bms.price.service.IPayProductService;
import com.bms.price.service.IPaySurchargeRuleService;
import com.bms.price.service.IPrcPayBillFeeService;
@@ -66,6 +67,9 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
@Autowired
private IPrcPayBillFeeService payBillFeeService;
@Autowired
private PayBillFeeLogService payBillFeeLogService;
@Autowired
private PaySettleSupport paySettleSupport;
@@ -89,6 +93,27 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
return generate(billId);
}
/**
* 订单同步后落地尾程费用。已经进入应付账单的计算费用不再覆盖。
*
* @param billId 计费订单 ID
* @return 本次落地的结果;费用已经出账时返回 null
*/
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public PayOrderCostResult landIfOpen(Long billId)
{
if (billId == null)
{
return null;
}
if (payBillFeeMapper.countSettledCalc(billId) > 0)
{
return null;
}
return generate(billId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public PayOrderCostResult generate(Long billId)
@@ -141,6 +166,42 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
return result;
}
/**
* 单独记下计费失败。重算事务回滚后,这条状态仍然保留。
*
* @param billId 计费订单 ID
* @param reason 失败原因,超过 100 字会截断
*/
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void markCalcFail(Long billId, String reason)
{
if (billId == null)
{
return;
}
String message = reason == null ? "" : reason.trim();
if (message.length() > 100)
{
message = message.substring(0, 100);
}
String operator = "system";
try
{
String name = SecurityUtils.getUsername();
if (name != null && !name.isBlank())
{
operator = name;
}
}
catch (Exception ignored)
{
operator = "system";
}
payBillMapper.insertMissingPayBills(List.of(billId), operator);
payBillMapper.markCalcStatus(billId, 2, message, operator);
}
@Override
public String cardSupplierName(Long billId)
{
@@ -587,6 +648,7 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
*/
private void saveFees(Long billId, String payBillId, List<PayCostLine> fees)
{
boolean recalc = hasCalcFee(billId);
payBillFeeMapper.deleteByBillId(billId);
List<PrcPayBillFee> rows = new java.util.ArrayList<>();
long fallback = 1L;
@@ -618,6 +680,30 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
{
payBillFeeService.refreshTotals(java.util.List.of(billId));
}
payBillFeeLogService.record(rows, recalc ? PayBillFeeLogService.RECALC : PayBillFeeLogService.ADD);
}
/** 这票订单上还有没删除的计算费用。有则本次落库是重算,没有则是首次生成。 */
private boolean hasCalcFee(Long billId)
{
List<PrcPayBillFee> current = payBillFeeMapper.selectByBillId(billId);
if (current == null)
{
return false;
}
for (PrcPayBillFee fee : current)
{
if (fee == null)
{
continue;
}
String source = fee.getFeeSource();
if (source == null || source.isBlank() || "CALC".equals(source))
{
return true;
}
}
return false;
}
/**
@@ -0,0 +1,446 @@
package com.bms.price.service.impl;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.bms.common.enums.PaymentMesEnum;
import com.bms.common.exception.ServiceException;
import com.bms.common.utils.SecurityUtils;
import com.bms.price.domain.PayOrderFeeBoard;
import com.bms.price.domain.PrcPayBill;
import com.bms.price.domain.PayOrderFeeLine;
import com.bms.price.domain.PayOrderFeeSection;
import com.bms.price.domain.PayOrderQuery;
import com.bms.price.domain.PayOrderRecalcCommand;
import com.bms.price.domain.PayOrderRecalcLine;
import com.bms.price.domain.PayOrderRecalcResult;
import com.bms.price.domain.PayOrderRow;
import com.bms.price.domain.PrcPayBillFee;
import com.bms.price.mapper.PayOrderListMapper;
import com.bms.price.mapper.PrcPayBillFeeMapper;
import com.bms.price.mapper.PrcPayBillMapper;
import com.bms.price.service.IPayOrderCostService;
import com.bms.price.service.PayBillFeeLogService;
import com.bms.price.service.IPayOrderListService;
import com.bms.price.service.IPrcPayBillFeeService;
@Service
public class PayOrderListServiceImpl implements IPayOrderListService
{
private static final int MAX_ORDER_NOS = 500;
private static final Map<String, String> TITLES = new LinkedHashMap<>();
static
{
TITLES.put("1", "A段(头程仓储)");
TITLES.put("2", "B段(提单运输)");
TITLES.put("3", "C段(清关)");
TITLES.put("4", "D段(尾程)");
}
@Autowired
private PayOrderListMapper payOrderListMapper;
@Autowired
private PrcPayBillFeeMapper payBillFeeMapper;
@Autowired
private IPayOrderCostService payOrderCostService;
@Autowired
private PrcPayBillMapper payBillMapper;
@Autowired
private IPrcPayBillFeeService payBillFeeService;
@Autowired
private PayBillFeeLogService payBillFeeLogService;
@Override
public List<PayOrderRow> list(PayOrderQuery query)
{
PayOrderQuery safe = query == null ? new PayOrderQuery() : query;
List<String> orderNos = orderNos(safe.getOrderNo());
if (orderNos.size() > MAX_ORDER_NOS)
{
throw new ServiceException("一次最多查询" + MAX_ORDER_NOS + "个订单号");
}
if (orderNos.size() > 1)
{
safe.setOrderNos(orderNos);
safe.setOrderNo(null);
}
else
{
safe.setOrderNos(null);
safe.setOrderNo(orderNos.isEmpty() ? null : orderNos.get(0));
}
return payOrderListMapper.selectList(safe);
}
/**
* 按订单号或提单号逐票重算尾程应付。找不到的单号记失败,已经出账的费用不覆盖。
*
* @param command 重算方式和单号原文
* @return 成功数、失败数和明细
*/
@Override
public PayOrderRecalcResult recalc(PayOrderRecalcCommand command)
{
if (command == null || command.getSourceType() == null || command.getSourceType().isBlank())
{
throw new ServiceException("请选择按订单号或按提单号重算");
}
String source = command.getSourceType().trim();
List<String> nos = orderNos(command.getText());
if (nos.isEmpty())
{
throw new ServiceException("请填写单号");
}
if (nos.size() > MAX_ORDER_NOS)
{
throw new ServiceException("一次最多重算" + MAX_ORDER_NOS + "个单号");
}
boolean byOrder = "ORDER".equalsIgnoreCase(source);
boolean byLading = "LADING".equalsIgnoreCase(source);
if (!byOrder && !byLading)
{
throw new ServiceException("请选择按订单号或按提单号重算");
}
List<PayOrderRow> found = byOrder ? payOrderListMapper.selectByOrderNos(nos) : payOrderListMapper.selectByLadingNos(nos);
if (found == null)
{
found = new ArrayList<>();
}
if (found.size() > MAX_ORDER_NOS)
{
throw new ServiceException("一次最多重算" + MAX_ORDER_NOS + "票订单");
}
PayOrderRecalcResult result = new PayOrderRecalcResult();
LinkedHashSet<String> hit = new LinkedHashSet<>();
for (PayOrderRow order : found)
{
if (order == null || order.getBillId() == null || order.getBillId().isBlank())
{
continue;
}
hit.add(byOrder ? order.getOrderNo() : order.getLadingNo());
PayOrderRecalcLine line = new PayOrderRecalcLine();
line.setOrderNo(order.getOrderNo());
line.setLadingNo(order.getLadingNo());
if (payBillFeeMapper.countSettledCalc(Long.valueOf(order.getBillId().trim())) > 0)
{
line.setSuccess(false);
line.setMessage("费用已进入应付账单,未重算");
result.getLines().add(line);
result.setFailCount(result.getFailCount() + 1);
continue;
}
try
{
payOrderCostService.generateIsolated(Long.valueOf(order.getBillId().trim()));
line.setSuccess(true);
result.setSuccessCount(result.getSuccessCount() + 1);
}
catch (Exception ex)
{
String message = ex.getMessage() == null ? "应付费用生成失败" : ex.getMessage();
try
{
payOrderCostService.markCalcFail(Long.valueOf(order.getBillId().trim()), message);
}
catch (Exception markEx)
{
message = message + ";计费状态未写入";
}
line.setSuccess(false);
line.setMessage(message);
result.setFailCount(result.getFailCount() + 1);
}
result.getLines().add(line);
}
for (String no : nos)
{
if (hit.contains(no))
{
continue;
}
PayOrderRecalcLine line = new PayOrderRecalcLine();
if (byOrder)
{
line.setOrderNo(no);
line.setMessage("没有找到这个订单");
}
else
{
line.setLadingNo(no);
line.setMessage("这个提单下没有订单");
}
line.setSuccess(false);
result.getLines().add(line);
result.setFailCount(result.getFailCount() + 1);
}
return result;
}
@Override
public PayOrderFeeBoard fees(String billId)
{
if (billId == null || billId.isBlank())
{
throw PaymentMesEnum.BMS_PAY_PICK_ORDER.exception();
}
PayOrderRow order = payOrderListMapper.selectRow(billId.trim());
if (order == null)
{
throw PaymentMesEnum.BMS_PAY_ORDER_MISS.exception();
}
Map<String, PayOrderFeeSection> sections = new LinkedHashMap<>();
for (Map.Entry<String, String> title : TITLES.entrySet())
{
PayOrderFeeSection section = new PayOrderFeeSection();
section.setLevel(title.getKey());
section.setTitle(title.getValue());
sections.put(title.getKey(), section);
}
List<PrcPayBillFee> owned = payBillFeeMapper.selectByBillId(Long.valueOf(order.getBillId().trim()));
if (owned != null)
{
for (PrcPayBillFee fee : owned)
{
if (fee == null)
{
continue;
}
sections.get(levelOf(fee)).getFees().add(toLine(fee));
}
}
PayOrderFeeBoard board = new PayOrderFeeBoard();
board.setBillId(order.getBillId());
board.setOrderNo(order.getOrderNo());
board.setLadingNo(order.getLadingNo());
board.setSections(List.copyOf(sections.values()));
board.setLogs(payBillFeeLogService.list(Long.valueOf(order.getBillId().trim())));
return board;
}
/**
* 在指定费用段增加一行手工费用,并按未删除明细重算应付总额。
*
* @param billId 计费订单 ID
* @param line 费用项、金额、币种、说明和所属阶段
* @return 刚写入的费用行
*/
@Override
@Transactional(rollbackFor = Exception.class)
public PayOrderFeeLine addManualFee(String billId, PayOrderFeeLine line)
{
PayOrderRow order = requireOrder(billId);
if (line == null)
{
throw new ServiceException("请填写费用");
}
String level = line.getLevel() == null ? "" : line.getLevel().trim();
if (!TITLES.containsKey(level))
{
throw new ServiceException("请选择费用阶段");
}
String feeName = firstText(line.getFeeName(), line.getFeeType());
if (feeName.isEmpty())
{
throw new ServiceException("请填写费用项");
}
if (feeName.length() > 100)
{
feeName = feeName.substring(0, 100);
}
String feeType = firstText(line.getFeeType(), "MANUAL");
if (feeType.length() > 30)
{
feeType = "MANUAL";
}
if (line.getAmount() == null)
{
throw new ServiceException("请填写金额");
}
BigDecimal amount = line.getAmount().setScale(2, RoundingMode.HALF_UP);
if (amount.abs().compareTo(new BigDecimal("9999999999.99")) > 0)
{
throw new ServiceException("金额超出范围");
}
String currency = firstText(line.getCurrency(), "CNY").toUpperCase();
if (currency.length() > 10)
{
throw new ServiceException("币种过长");
}
String remark = line.getRemark() == null ? null : line.getRemark().trim();
if (remark != null && remark.length() > 200)
{
throw new ServiceException("说明不能超过200字");
}
Long orderBillId = Long.valueOf(order.getBillId().trim());
String operator = operator();
payBillMapper.insertMissingPayBills(List.of(orderBillId), operator);
PrcPayBill payBill = payBillMapper.selectByBillId(orderBillId);
PrcPayBillFee fee = new PrcPayBillFee();
fee.setFeeId(UUID.randomUUID().toString());
fee.setBillId(orderBillId);
fee.setPayBillId(payBill == null ? null : payBill.getPayBillId());
fee.setFeeType(feeType);
fee.setFeeName(feeName);
fee.setScId(manualScId());
fee.setFeeLevel(level);
fee.setAmount(amount);
fee.setCurrency(currency);
fee.setRemark(remark == null || remark.isEmpty() ? null : remark);
fee.setFeeSource("MANUAL");
fee.setCreateBy(operator);
fee.setUpdateBy(operator);
payBillFeeMapper.insertManual(fee);
payBillFeeService.refreshTotals(List.of(orderBillId));
payBillFeeLogService.record(fee, PayBillFeeLogService.ADD);
PrcPayBillFee saved = payBillFeeMapper.selectByFeeId(fee.getFeeId());
return toLine(saved == null ? fee : saved);
}
/**
* 逻辑删除一条费用,并按剩余未删除明细重算应付总额。
*
* @param feeId 费用明细 ID
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void removeFee(String feeId)
{
if (feeId == null || feeId.isBlank())
{
throw new ServiceException("请选择要删除的费用");
}
PrcPayBillFee fee = payBillFeeMapper.selectByFeeId(feeId.trim());
if (fee == null || "1".equals(fee.getIsDeleted()))
{
throw new ServiceException("费用不存在");
}
if (fee.getStatementLineId() != null)
{
throw new ServiceException("费用已进入应付账单,不能删除");
}
int rows = payBillFeeMapper.markFeeDeleted(feeId.trim(), operator());
if (rows == 0)
{
throw new ServiceException("费用已进入应付账单,不能删除");
}
payBillFeeLogService.record(fee, PayBillFeeLogService.DELETE);
if (fee.getBillId() != null)
{
payBillFeeService.refreshTotals(List.of(fee.getBillId()));
}
}
/** 费用弹框一行。手工费用直接用保存下来的名称。 */
private static PayOrderFeeLine toLine(PrcPayBillFee fee)
{
PayOrderFeeLine line = new PayOrderFeeLine();
line.setFeeId(fee.getFeeId());
line.setFeeType(fee.getFeeType());
line.setFeeName(fee.getFeeName());
line.setLevel(fee.getFeeLevel());
line.setAmount(fee.getAmount());
line.setCurrency(fee.getCurrency());
line.setFeeSource(fee.getFeeSource() == null || fee.getFeeSource().isBlank() ? "CALC" : fee.getFeeSource());
line.setRemark(fee.getRemark());
line.setStatementLineId(fee.getStatementLineId());
line.setCreateBy(fee.getCreateBy());
line.setCreateTime(fee.getCreateTime());
line.setUpdateBy(fee.getUpdateBy());
line.setUpdateTime(fee.getUpdateTime());
return line;
}
/** 当前登录人。同步线程没有登录信息时记 system。 */
private static String operator()
{
try
{
String name = SecurityUtils.getUsername();
return name == null || name.isBlank() ? "system" : name;
}
catch (Exception ex)
{
return "system";
}
}
private static String firstText(String primary, String fallback)
{
if (primary != null && !primary.isBlank())
{
return primary.trim();
}
return fallback == null ? "" : fallback.trim();
}
/** 手工费用用负数序号,避免和同一费用项的计算费用撞上唯一键。 */
private static long manualScId()
{
long tick = System.nanoTime();
if (tick == Long.MIN_VALUE)
{
return -1L;
}
long value = -Math.abs(tick);
return value == 0L ? -1L : value;
}
private PayOrderRow requireOrder(String billId)
{
if (billId == null || billId.isBlank())
{
throw PaymentMesEnum.BMS_PAY_PICK_ORDER.exception();
}
PayOrderRow order = payOrderListMapper.selectRow(billId.trim());
if (order == null || order.getBillId() == null || order.getBillId().isBlank())
{
throw PaymentMesEnum.BMS_PAY_ORDER_MISS.exception();
}
return order;
}
/** 订单号按逗号、顿号、分号、空白拆开,并去掉重复和空白。 */
private static List<String> orderNos(String text)
{
LinkedHashSet<String> values = new LinkedHashSet<>();
if (text != null)
{
for (String part : text.split("[,,、;;\\s]+"))
{
String token = part.trim();
if (!token.isEmpty())
{
values.add(token);
}
}
}
return new ArrayList<>(values);
}
/** 已经标明阶段的按阶段放。尾程计算出来的派送费和附加费没有阶段时归到 D 段。 */
private static String levelOf(PrcPayBillFee fee)
{
String level = fee.getFeeLevel();
if ("1".equals(level) || "2".equals(level) || "3".equals(level) || "4".equals(level))
{
return level;
}
return "4";
}
}
@@ -106,6 +106,7 @@ import com.bms.customer.customermoney.api.CreditUsageCommand;
import com.bms.customer.customermoney.api.CustomerFundBizType;
import com.bms.customer.customermoney.api.ICustomerAccountApi;
import com.bms.customer.customermoney.vo.CustomerAccountStatusVO;
import com.bms.price.service.IPayOrderCostService;
import com.bms.price.service.IPrcOrderBillService;
import com.bms.price.service.IPrcSurchargeService;
import com.bms.price.service.ITmsPriceQuoteService;
@@ -124,6 +125,9 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
@Lazy
private IPrcOrderBillService self;
@Autowired
private IPayOrderCostService payOrderCostService;
@Autowired
private ITmsPriceQuoteService tmsPriceQuoteService;
@@ -3270,7 +3274,7 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
/**
* 订单来源同步:用上游字段完整覆盖本地账单 + ext。
* 不做报价、不占用授信、不涉及费用,也不校验 AR/退费。
* 不做应收报价、不占用授信。订单提交成功后,再按应付产品落地尾程运费和订单附加费。
*/
@Override
@Transactional(rollbackFor = Exception.class)
@@ -3375,9 +3379,109 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
// ES 映射中 response.ok 为 long 类型,使用 1/0 而非布尔 true/false。
billSearchStore.save(EsLogType.BILL, bizId, req.toJSONString(),
"{\"ok\":1,\"action\":\"UPSTREAM_SYNC\"}");
landTailFeesAfterCommit(bill);
return bill.getBillId();
}
/**
* 等这票订单提交成功后再算尾程应付。生成失败只打日志并写入 ES,不回滚订单,也不往外抛。
*
* @param bill 刚写入的计费订单
*/
private void landTailFeesAfterCommit(PrcOrderBill bill)
{
if (bill == null || bill.getBillId() == null || payOrderCostService == null)
{
return;
}
Long billId = bill.getBillId();
String orderNo = bill.getOrderNo();
String transferNo = bill.getTransferNo();
if (!TransactionSynchronizationManager.isSynchronizationActive())
{
landTailFeesQuietly(billId, orderNo, transferNo);
return;
}
try
{
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization()
{
@Override
public void afterCommit()
{
landTailFeesQuietly(billId, orderNo, transferNo);
}
});
}
catch (RuntimeException ex)
{
log.warn("订单同步后应付费用未安排生成 billId={}", billId, ex);
savePayFeeFailEs(billId, orderNo, transferNo, ex);
}
}
/**
* 落地还没出账的尾程运费和订单附加费。任何失败都只记录异常并写入 ES,留给下次同步再试。
*
* @param billId 计费订单 ID
* @param orderNo 订单号
* @param transferNo 转单号,ES 检索优先用它
*/
private void landTailFeesQuietly(Long billId, String orderNo, String transferNo)
{
try
{
payOrderCostService.landIfOpen(billId);
}
catch (Exception ex)
{
log.warn("订单同步后应付费用生成失败 billId={}", billId, ex);
savePayFeeFailEs(billId, orderNo, transferNo, ex);
try
{
payOrderCostService.markCalcFail(billId, ex.getMessage());
}
catch (Exception markEx)
{
log.warn("应付计费失败状态未写入 billId={}", billId, markEx);
}
}
}
/**
* 把应付费用生成失败写进订单原有的 ES 日志。bizId 与订单同步相同,优先转单号。
*
* @param billId 计费订单 ID
* @param orderNo 订单号
* @param transferNo 转单号
* @param ex 生成失败的异常
*/
private void savePayFeeFailEs(Long billId, String orderNo, String transferNo, Exception ex)
{
if (billSearchStore == null)
{
return;
}
try
{
String message = ex == null || ex.getMessage() == null ? "应付费用生成失败" : ex.getMessage();
JSONObject req = new JSONObject();
req.put("action", "PAY_FEE_FAIL");
req.put("orderNo", orderNo);
req.put("transferNo", transferNo);
req.put("billId", billId);
req.put("errorMessage", message);
String bizId = StringUtils.isNotEmpty(transferNo) ? transferNo.trim()
: (StringUtils.isNotEmpty(orderNo) ? orderNo.trim() : String.valueOf(billId));
billSearchStore.save(EsLogType.BILL, bizId, req.toJSONString(),
"{\"ok\":0,\"action\":\"PAY_FEE_FAIL\"}", EsBizLogSupport.STATUS_FAIL, message);
}
catch (Exception logEx)
{
log.warn("应付费用失败日志写入 ES 失败 billId={}", billId, logEx);
}
}
/** 按编码尽力查询客户 ID;查询不到时保留原 ID。 */
private Long resolveCustomerIdByCode(String customerCode, Long previousId)
{
@@ -43,19 +43,6 @@ public class PrcPayBillFeeServiceImpl implements IPrcPayBillFeeService
{
List<PrcPayBillFee> chunk = fees.subList(from, Math.min(from + BATCH_SIZE, fees.size()));
payBillFeeMapper.insertBatch(chunk);
List<String> ownIds = new ArrayList<>();
for (PrcPayBillFee fee : chunk)
{
if (fee != null && fee.getFeeId() != null && !fee.getFeeId().isBlank()
&& (fee.getSourceId() == null || fee.getSourceId().isBlank()))
{
ownIds.add(fee.getFeeId());
}
}
if (!ownIds.isEmpty())
{
payBillFeeMapper.fillSourceIdByFeeIds(ownIds);
}
for (PrcPayBillFee fee : chunk)
{
if (fee != null && fee.getBillId() != null)
@@ -27,6 +27,7 @@ import com.bms.price.mapper.SrvBillAirAllocMapper;
import com.bms.price.mapper.SrvBillAirFeeMapper;
import com.bms.price.mapper.SrvBillAirMapper;
import com.bms.price.service.IPrcPayBillFeeService;
import com.bms.price.service.PayBillFeeLogService;
import com.bms.price.service.ISrvBillAirAllocService;
/**
@@ -59,6 +60,9 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService
@Autowired
private IPrcPayBillFeeService payBillFeeService;
@Autowired
private PayBillFeeLogService payBillFeeLogService;
@Override
public List<SrvBillAirAllocFee> preview(List<String> billCodes)
{
@@ -237,9 +241,8 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService
row.setFeeId(UUID.randomUUID().toString());
row.setBillId(order.getBillId());
row.setPayBillId(payBillIds.get(order.getBillId()));
String name = blankName(fee);
row.setFeeType(name.length() <= 30 ? name : name.substring(0, 30));
row.setFeeName(name);
row.setFeeType(dictType(fee.getFeeType()));
row.setFeeName(fee.getFeeName());
row.setScId(fee.getId() == null ? 0L : fee.getId());
row.setFeeLevel(fee.getFeeLevel());
row.setAmount(amount);
@@ -247,6 +250,7 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService
row.setRoundMode("HALF_UP");
row.setRemark(remark(fee));
row.setFeeSource(FEE_SOURCE);
row.setSourceId(fee.getId() == null ? null : String.valueOf(fee.getId()));
row.setIsDeleted("0");
return row;
}
@@ -259,6 +263,7 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService
}
int rows = batch.size();
payBillFeeService.insertBatchAndRefreshTotals(new ArrayList<>(batch));
payBillFeeLogService.record(batch, PayBillFeeLogService.ADD);
batch.clear();
return rows;
}
@@ -378,6 +383,15 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService
return ids;
}
private static String dictType(String feeType)
{
if (feeType == null || !feeType.trim().matches("[A-Z][A-Z0-9_]*"))
{
return "SURCHARGE";
}
return feeType.trim();
}
private static String blankName(SrvBillAirAllocFee fee)
{
if (fee.getFeeName() != null && !fee.getFeeName().isBlank())
@@ -28,12 +28,14 @@ import com.bms.price.airbill.domain.SrvBillAirRoleFeeCommand;
import com.bms.price.airbill.domain.SrvBillAirRoleFeeQuery;
import com.bms.price.airbill.domain.SrvBillAirFeeLog;
import com.bms.price.airbill.domain.SrvBillAirFeeSave;
import com.bms.price.domain.PrcPayBillFee;
import com.bms.price.domain.PrcSurcharge;
import com.bms.price.mapper.PrcPayBillFeeMapper;
import com.bms.price.mapper.PrcSurchargeMapper;
import com.bms.price.mapper.SrvBillAirFeeMapper;
import com.bms.price.mapper.SrvBillAirMapper;
import com.bms.price.service.IPrcPayBillFeeService;
import com.bms.price.service.PayBillFeeLogService;
import com.bms.price.service.IPrcSurchargeService;
import com.bms.price.service.ISrvBillAirFeeService;
import com.bms.system.service.ISysDictTypeService;
@@ -70,6 +72,9 @@ public class SrvBillAirFeeServiceImpl implements ISrvBillAirFeeService
@Autowired
private IPrcPayBillFeeService payBillFeeService;
@Autowired
private PayBillFeeLogService payBillFeeLogService;
@Autowired
private IPrcSurchargeService surchargeService;
@@ -210,7 +215,8 @@ public class SrvBillAirFeeServiceImpl implements ISrvBillAirFeeService
throw new ServiceException("第" + line + "行备注不能超过500字");
}
SrvBillAirFee fee = new SrvBillAirFee();
fee.setFeeType(String.valueOf(chosen.getScId()));
fee.setScId(chosen.getScId());
fee.setFeeType(chosen.getFeeType() == null || chosen.getFeeType().isBlank() ? "SURCHARGE" : chosen.getFeeType().trim());
fee.setFeeName(chosen.getScName());
fee.setFeeLevel(level);
fee.setPrice(row.getPrice());
@@ -410,7 +416,9 @@ public class SrvBillAirFeeServiceImpl implements ISrvBillAirFeeService
Operator operator = operator();
Date now = DateUtils.getNowDate();
List<Long> affectedBills = payBillFeeMapper.selectBillIdsByLadingFee(feeId);
List<PrcPayBillFee> allocated = payBillFeeMapper.selectAliveByLadingFee(feeId);
payBillFeeMapper.markLadingFeeDeleted(feeId);
payBillFeeLogService.record(allocated, PayBillFeeLogService.VOID);
payBillFeeService.refreshTotals(affectedBills);
if (feeMapper.voidFee(feeId, code, operator.account, now) != 1)
{
@@ -556,7 +564,7 @@ public class SrvBillAirFeeServiceImpl implements ISrvBillAirFeeService
String feeLevel = trim(raw.getFeeLevel());
String currency = trim(raw.getCurrency());
String remark = trim(raw.getRemark());
Long scId = parseScId(feeType);
Long scId = raw.getScId() != null && raw.getScId() > 0 ? raw.getScId() : parseScId(feeType);
if (scId == null)
{
throw PaymentMesEnum.BMS_PAY_PICK_ITEM.exception();
@@ -566,7 +574,7 @@ public class SrvBillAirFeeServiceImpl implements ISrvBillAirFeeService
{
throw PaymentMesEnum.BMS_PAY_ITEM_MISS.exception();
}
feeType = String.valueOf(scId);
feeType = surcharge.getFeeType() == null || surcharge.getFeeType().isBlank() ? "SURCHARGE" : surcharge.getFeeType().trim();
if (!feeLevel.isEmpty() && (feeLevel.length() > 32 || !levelLabels.containsKey(feeLevel)))
{
throw PaymentMesEnum.BMS_PAY_LEVEL.exception();
@@ -597,6 +605,7 @@ public class SrvBillAirFeeServiceImpl implements ISrvBillAirFeeService
}
SrvBillAirFee fee = new SrvBillAirFee();
fee.setFeeType(feeType);
fee.setScId(scId);
fee.setFeeLevel(feeLevel);
fee.setFeeScene(trim(raw.getFeeScene()));
fee.setAllocFlag("1");
@@ -660,8 +669,8 @@ public class SrvBillAirFeeServiceImpl implements ISrvBillAirFeeService
Map<String, String> dimLabels, Map<String, String> statusLabels, Map<String, String> currencyLabels)
{
List<SrvBillAirFeeLog.FieldChange> changes = new ArrayList<>();
addChange(changes, "feeType", "费用项", label(feeLabels, value(before, SrvBillAirFee::getFeeType)),
label(feeLabels, value(after, SrvBillAirFee::getFeeType)));
addChange(changes, "scId", "费用项", label(feeLabels, scKey(before)),
label(feeLabels, scKey(after)));
addChange(changes, "price", "价格", priceText(before), priceText(after));
addChange(changes, "currency", "收费币种", label(currencyLabels, value(before, SrvBillAirFee::getCurrency)),
label(currencyLabels, value(after, SrvBillAirFee::getCurrency)));
@@ -766,7 +775,7 @@ public class SrvBillAirFeeServiceImpl implements ISrvBillAirFeeService
{
return;
}
String id = trim(fee.getFeeType());
String id = scKey(fee);
if (id.isEmpty() || names.containsKey(id))
{
return;
@@ -774,6 +783,11 @@ public class SrvBillAirFeeServiceImpl implements ISrvBillAirFeeService
names.put(id, surchargeName(id));
}
private static String scKey(SrvBillAirFee fee)
{
return fee == null || fee.getScId() == null ? "" : String.valueOf(fee.getScId());
}
private String surchargeName(String feeType)
{
Long scId = parseScId(feeType);
@@ -32,7 +32,7 @@ import com.bms.price.search.TabOrderSyncEsLog;
import com.bms.price.service.IPrcOrderBillService;
/**
* 分页读取 Oracle TAB_ORDER,再多线程覆盖本地账单字段(不计费)。
* 分页读取 Oracle TAB_ORDER,覆盖本地订单,并在订单提交后落地尾程应付。
*/
@Component
public class TabOrderSyncAsyncRunner
@@ -316,7 +316,7 @@ public class TabOrderSyncAsyncRunner
}
}
/** 解析出 Oracle 行后覆盖本地账单及其扩展信息(不计费)。 */
/** 解析出 Oracle 行后覆盖本地账单。应付费用在订单提交后另算,失败只记日志。 */
private Long overwriteOne(com.bms.price.oracle.TabOrderRow row)
{
Map<String, Object> raw = row == null ? null : row.getRaw();
@@ -32,6 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="cooperationStartDate" column="cooperation_start_date" />
<result property="contractEndDate" column="contract_end_date" />
<result property="cooperationStatus" column="cooperation_status" />
<result property="dataSource" column="data_source" />
<result property="channelIds" column="channel_ids" />
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
@@ -47,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
s.is_enable, s.purchaser_user_id, s.purchaser_user, s.settlement_user_id, s.settlement_user,
s.service_user_id, s.service_user, s.ed, s.zq, s.settlement_type, s.temp_ed, s.account_balance,
s.foreign_currency_balance, s.credit_ed, s.weight_threshold, s.throw_ratio, s.cooperation_start_date,
s.contract_end_date, s.cooperation_status, s.channel_ids, s.remark,
s.contract_end_date, s.cooperation_status, s.data_source, s.channel_ids, s.remark,
s.create_by, s.create_time, s.update_by, s.update_time, s.del_flag
from sup_supplier s
<!-- 数据权限:采购/销售(仅本人 s.purchaser_user_id)/部门经理(本部门 su.dept_id);
@@ -124,6 +125,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="cooperationStartDate != null">cooperation_start_date,</if>
<if test="contractEndDate != null">contract_end_date,</if>
<if test="cooperationStatus != null">cooperation_status,</if>
<if test="dataSource != null">data_source,</if>
<if test="channelIds != null">channel_ids,</if>
<if test="remark != null">remark,</if>
<if test="createBy != null">create_by,</if>
@@ -157,6 +159,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="cooperationStartDate != null">#{cooperationStartDate},</if>
<if test="contractEndDate != null">#{contractEndDate},</if>
<if test="cooperationStatus != null">#{cooperationStatus},</if>
<if test="dataSource != null">#{dataSource},</if>
<if test="channelIds != null">#{channelIds},</if>
<if test="remark != null">#{remark},</if>
<if test="createBy != null">#{createBy},</if>
@@ -194,6 +197,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="cooperationStartDate != null">cooperation_start_date = #{cooperationStartDate},</if>
contract_end_date = #{contractEndDate},
<if test="cooperationStatus != null">cooperation_status = #{cooperationStatus},</if>
data_source = #{dataSource},
<if test="channelIds != null">channel_ids = #{channelIds},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
@@ -203,6 +207,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where supplier_id = #{supplierId}
</update>
<update id="updateSupplierChannels" parameterType="com.bms.customer.supplierinfo.domain.BmsSupplier">
update sup_supplier
set channel_ids = #{channelIds},
update_by = #{updateBy},
update_time = #{updateTime}
where supplier_id = #{supplierId}
and del_flag = '0'
</update>
<delete id="deleteBmsSupplierBySupplierId" parameterType="Long">
delete from sup_supplier where supplier_id = #{supplierId}
</delete>
@@ -58,9 +58,20 @@
o.product_name as productName, o.country_code as countryCode, o.country_name as countryName,
o.dest_postcode as destPostcode, e.air_no_old as ladingNo, e.product_floor as channelName,
e.supplier_name as supplierName,
(select group_concat(concat(ifnull(nullif(trim(f.fee_name), ''), ifnull(f.fee_type, '费用')), ' ', format(f.amount, 2))
order by field(f.fee_type, 'BASIC_FREIGHT', 'REGISTRATION_FEE', 'SURCHARGE', 'REFUND'), f.fee_id separator ';')
from prc_pay_bill_fee f where f.bill_id = o.bill_id and f.is_deleted = '0') as feeText,
(select group_concat(concat(
case
when f.fee_source = 'LADING' and nullif(trim(air_sc.sc_name), '') is not null then air_sc.sc_name
when f.fee_type = 'SURCHARGE' and nullif(trim(item_sc.sc_name), '') is not null then item_sc.sc_name
when nullif(trim(dict.dict_label), '') is not null then dict.dict_label
else ifnull(f.fee_type, '费用')
end, ' ', format(f.amount, 2))
order by field(f.fee_type, 'BASIC_FREIGHT', 'REGISTRATION_FEE', 'SURCHARGE', 'REFUND', 'ADJUST'), f.fee_id separator ';')
from prc_pay_bill_fee f
left join srv_bill_air_fee air on f.fee_source = 'LADING' and air.id = f.sc_id
left join prc_surcharge air_sc on air_sc.sc_id = air.sc_id
left join prc_surcharge item_sc on ifnull(f.fee_source, '') &lt;&gt; 'LADING' and item_sc.sc_id = f.sc_id
left join sys_dict_data dict on dict.dict_type = 'bms_fee_type' and dict.dict_value = f.fee_type
where f.bill_id = o.bill_id and f.is_deleted = '0') as feeText,
(select count(*) from prc_pay_bill_fee f
where f.bill_id = o.bill_id and ifnull(f.is_deleted, '0') = '0') as feeCount,
(select count(*) from prc_pay_bill_fee f
@@ -106,14 +117,24 @@
</select>
<select id="selectOrderFees" resultType="com.bms.price.domain.PrcPayBillFee">
select fee_id as feeId, bill_id as billId, pay_bill_id as payBillId, fee_type as feeType, fee_name as feeName,
sc_id as scId, fee_level as feeLevel, amount, currency, fee_source as feeSource, source_id as sourceId,
is_deleted as isDeleted
from prc_pay_bill_fee
where is_deleted = '0'
and bill_id in
select f.fee_id as feeId, f.bill_id as billId, f.pay_bill_id as payBillId, f.fee_type as feeType,
case
when f.fee_source = 'LADING' and nullif(trim(air_sc.sc_name), '') is not null then air_sc.sc_name
when f.fee_type = 'SURCHARGE' and nullif(trim(item_sc.sc_name), '') is not null then item_sc.sc_name
when nullif(trim(dict.dict_label), '') is not null then dict.dict_label
else f.fee_type
end as feeName,
f.sc_id as scId, f.fee_level as feeLevel, f.amount, f.currency, f.fee_source as feeSource, f.source_id as sourceId,
f.is_deleted as isDeleted
from prc_pay_bill_fee f
left join srv_bill_air_fee air on f.fee_source = 'LADING' and air.id = f.sc_id
left join prc_surcharge air_sc on air_sc.sc_id = air.sc_id
left join prc_surcharge item_sc on ifnull(f.fee_source, '') &lt;&gt; 'LADING' and item_sc.sc_id = f.sc_id
left join sys_dict_data dict on dict.dict_type = 'bms_fee_type' and dict.dict_value = f.fee_type
where f.is_deleted = '0'
and f.bill_id in
<foreach collection="billIds" item="id" open="(" separator="," close=")">#{id}</foreach>
order by bill_id, fee_id
order by f.bill_id, f.fee_id
</select>
<insert id="insertPayBill" useGeneratedKeys="true" keyProperty="billId">
@@ -228,10 +249,20 @@
<select id="selectFreeFees" resultType="com.bms.price.domain.PrcPayBillFee">
select f.fee_id as feeId, f.bill_id as billId, f.pay_bill_id as payBillId, f.fee_type as feeType,
f.fee_name as feeName, f.sc_id as scId, f.fee_level as feeLevel, f.amount, f.currency,
case
when f.fee_source = 'LADING' and nullif(trim(air_sc.sc_name), '') is not null then air_sc.sc_name
when f.fee_type = 'SURCHARGE' and nullif(trim(item_sc.sc_name), '') is not null then item_sc.sc_name
when nullif(trim(dict.dict_label), '') is not null then dict.dict_label
else f.fee_type
end as feeName,
f.sc_id as scId, f.fee_level as feeLevel, f.amount, f.currency,
f.fee_source as feeSource, f.source_id as sourceId, f.settle_supplier_id as settleSupplierId,
f.settle_supplier_name as settleSupplierName
from prc_pay_bill_fee f
left join srv_bill_air_fee air on f.fee_source = 'LADING' and air.id = f.sc_id
left join prc_surcharge air_sc on air_sc.sc_id = air.sc_id
left join prc_surcharge item_sc on ifnull(f.fee_source, '') &lt;&gt; 'LADING' and item_sc.sc_id = f.sc_id
left join sys_dict_data dict on dict.dict_type = 'bms_fee_type' and dict.dict_value = f.fee_type
where ifnull(f.is_deleted, '0') = '0'
and f.statement_line_id is null
and f.bill_id in
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.price.mapper.PayOrderListMapper">
<sql id="orderColumns">
select p.bill_id as billId,
p.order_no as orderNo,
nullif(trim(e.air_no_old), '') as ladingNo,
p.tracking_no as trackingNo,
p.customer_name as customerName,
p.product_name as productName,
p.country_name as countryName,
p.product_floor as channelName,
p.charge_weight as chargeWeight,
ifnull(b.pay_total, p.pay_total) as payTotal,
p.currency as currency,
b.pay_calc_status as payCalcStatus,
b.pay_calc_msg as payCalcMsg,
p.biz_date as bizDate
from prc_order_bill p
left join prc_order_bill_ext e on e.bill_id = p.bill_id
left join prc_pay_bill b on b.bill_id = p.bill_id
</sql>
<select id="selectList" resultType="com.bms.price.domain.PayOrderRow">
<include refid="orderColumns"/>
<where>
<if test="orderNos != null and orderNos.size() &gt; 0">
and p.order_no in
<foreach collection="orderNos" item="no" open="(" separator="," close=")">#{no}</foreach>
</if>
<if test="(orderNos == null or orderNos.size() == 0) and orderNo != null and orderNo != ''">
and p.order_no like concat('%', #{orderNo}, '%')
</if>
<if test="ladingNo != null and ladingNo != ''">
and trim(e.air_no_old) like concat('%', #{ladingNo}, '%')
</if>
<if test="customerName != null and customerName != ''">
and (p.customer_name like concat('%', #{customerName}, '%')
or p.customer_code like concat('%', #{customerName}, '%'))
</if>
</where>
order by p.create_time desc, p.bill_id desc
</select>
<select id="selectRow" resultType="com.bms.price.domain.PayOrderRow">
<include refid="orderColumns"/>
where p.bill_id = #{billId}
</select>
<select id="selectByOrderNos" resultType="com.bms.price.domain.PayOrderRow">
select p.bill_id as billId,
p.order_no as orderNo,
nullif(trim(e.air_no_old), '') as ladingNo
from prc_order_bill p
left join prc_order_bill_ext e on e.bill_id = p.bill_id
where p.order_no in
<foreach collection="orderNos" item="no" open="(" separator="," close=")">#{no}</foreach>
</select>
<select id="selectByLadingNos" resultType="com.bms.price.domain.PayOrderRow">
select p.bill_id as billId,
p.order_no as orderNo,
nullif(trim(e.air_no_old), '') as ladingNo
from prc_order_bill p
left join prc_order_bill_ext e on e.bill_id = p.bill_id
where trim(e.air_no_old) in
<foreach collection="ladingNos" item="no" open="(" separator="," close=")">#{no}</foreach>
</select>
</mapper>
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.price.mapper.PrcPayBillFeeLogMapper">
<resultMap type="PrcPayBillFeeLog" id="PrcPayBillFeeLogResult">
<id property="logId" column="log_id" />
<result property="feeId" column="fee_id" />
<result property="billId" column="bill_id" />
<result property="feeName" column="fee_name" />
<result property="amount" column="amount" />
<result property="currency" column="currency" />
<result property="operationType" column="operation_type" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
</resultMap>
<insert id="insertBatch">
insert into prc_pay_bill_fee_log (
fee_id, bill_id, fee_name, amount, currency, operation_type, create_by, create_time
) values
<foreach collection="list" item="item" separator=",">
(#{item.feeId}, #{item.billId}, #{item.feeName}, #{item.amount}, #{item.currency},
#{item.operationType}, #{item.createBy}, sysdate())
</foreach>
</insert>
<select id="selectByBillId" resultMap="PrcPayBillFeeLogResult">
select log_id, fee_id, bill_id, fee_name, amount, currency, operation_type, create_by, create_time
from prc_pay_bill_fee_log
where bill_id = #{billId}
order by log_id desc
</select>
</mapper>
@@ -19,35 +19,91 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="remark" column="remark" />
<result property="sourceId" column="source_id" />
<result property="isDeleted" column="is_deleted" />
<result property="statementLineId" column="statement_line_id" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="feeItemName">
case
when f.fee_source = 'MANUAL' and nullif(trim(f.fee_name), '') is not null then f.fee_name
when f.fee_source = 'LADING' and nullif(trim(air_sc.sc_name), '') is not null then air_sc.sc_name
when f.fee_type = 'SURCHARGE' and nullif(trim(item_sc.sc_name), '') is not null then item_sc.sc_name
when nullif(trim(f.fee_name), '') is not null then f.fee_name
when nullif(trim(dict.dict_label), '') is not null then dict.dict_label
else f.fee_type
end
</sql>
<sql id="feeItemJoin">
left join srv_bill_air_fee air on f.fee_source = 'LADING' and air.id = f.sc_id
left join prc_surcharge air_sc on air_sc.sc_id = air.sc_id
left join prc_surcharge item_sc on ifnull(f.fee_source, '') &lt;&gt; 'LADING' and item_sc.sc_id = f.sc_id
left join sys_dict_data dict on dict.dict_type = 'bms_fee_type' and dict.dict_value = f.fee_type
</sql>
<select id="selectByBillId" parameterType="Long" resultMap="PrcPayBillFeeResult">
select fee_id, bill_id, pay_bill_id, fee_type, fee_name, sc_id, fee_level, amount, currency, round_mode, remark,
fee_source, source_id, is_deleted, create_time
from prc_pay_bill_fee
where bill_id = #{billId}
and is_deleted = '0'
order by field(fee_type, 'BASIC_FREIGHT', 'REGISTRATION_FEE', 'SURCHARGE', 'REFUND'), fee_id
select f.fee_id, f.bill_id, f.pay_bill_id, f.fee_type, <include refid="feeItemName"/> as fee_name,
f.sc_id, f.fee_level, f.amount, f.currency, f.round_mode, f.remark,
f.fee_source, f.source_id, f.is_deleted, f.statement_line_id,
f.create_by, f.create_time, f.update_by, f.update_time
from prc_pay_bill_fee f
<include refid="feeItemJoin"/>
where f.bill_id = #{billId}
and f.is_deleted = '0'
order by field(f.fee_type, 'BASIC_FREIGHT', 'REGISTRATION_FEE', 'SURCHARGE', 'REFUND', 'ADJUST'), f.fee_id
</select>
<select id="selectByFeeId" resultMap="PrcPayBillFeeResult">
select f.fee_id, f.bill_id, f.pay_bill_id, f.fee_type, <include refid="feeItemName"/> as fee_name,
f.sc_id, f.fee_level, f.amount, f.currency, f.round_mode, f.remark,
f.fee_source, f.source_id, f.is_deleted, f.statement_line_id,
f.create_by, f.create_time, f.update_by, f.update_time
from prc_pay_bill_fee f
<include refid="feeItemJoin"/>
where f.fee_id = #{feeId}
limit 1
</select>
<insert id="insertManual" parameterType="PrcPayBillFee">
insert into prc_pay_bill_fee (
fee_id, bill_id, pay_bill_id, fee_type, fee_name, sc_id, fee_level, amount, currency, remark,
fee_source, is_deleted, create_by, create_time, update_by, update_time
) values (
#{feeId}, #{billId}, #{payBillId}, #{feeType}, #{feeName}, #{scId}, #{feeLevel}, #{amount}, #{currency}, #{remark},
'MANUAL', '0', #{createBy}, sysdate(), #{updateBy}, sysdate()
)
</insert>
<update id="markFeeDeleted">
update prc_pay_bill_fee
set is_deleted = '1',
update_by = #{operator},
update_time = sysdate()
where fee_id = #{feeId}
and ifnull(is_deleted, '0') = '0'
and statement_line_id is null
</update>
<insert id="insertPrcPayBillFee" parameterType="PrcPayBillFee">
insert into prc_pay_bill_fee (
fee_id, bill_id, pay_bill_id, fee_type, fee_name, sc_id, fee_level, amount, currency, round_mode, remark,
fee_id, bill_id, pay_bill_id, fee_type, sc_id, fee_level, amount, currency, round_mode, remark,
fee_source, source_id, is_deleted, create_time
) values (
#{feeId}, #{billId}, #{payBillId}, #{feeType}, #{feeName}, #{scId}, #{feeLevel}, #{amount}, #{currency}, #{roundMode}, #{remark},
#{feeId}, #{billId}, #{payBillId}, #{feeType}, #{scId}, #{feeLevel}, #{amount}, #{currency}, #{roundMode}, #{remark},
ifnull(#{feeSource}, 'CALC'), #{sourceId}, ifnull(#{isDeleted}, '0'), sysdate()
)
</insert>
<insert id="insertBatch" parameterType="java.util.List">
insert into prc_pay_bill_fee (
fee_id, bill_id, pay_bill_id, fee_type, fee_name, sc_id, fee_level, amount, currency, round_mode, remark,
fee_id, bill_id, pay_bill_id, fee_type, sc_id, fee_level, amount, currency, round_mode, remark,
fee_source, source_id, is_deleted, create_time
) values
<foreach collection="list" item="item" separator=",">
(#{item.feeId}, #{item.billId}, #{item.payBillId}, #{item.feeType}, #{item.feeName}, #{item.scId}, #{item.feeLevel},
(#{item.feeId}, #{item.billId}, #{item.payBillId}, #{item.feeType}, #{item.scId}, #{item.feeLevel},
#{item.amount}, #{item.currency}, #{item.roundMode}, #{item.remark}, ifnull(#{item.feeSource}, 'CALC'),
#{item.sourceId}, ifnull(#{item.isDeleted}, '0'), sysdate())
</foreach>
@@ -83,6 +139,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and bill_id is not null
</select>
<select id="selectAliveByLadingFee" resultMap="PrcPayBillFeeResult">
select f.fee_id, f.bill_id, f.pay_bill_id, f.fee_type, <include refid="feeItemName"/> as fee_name,
f.sc_id, f.fee_level, f.amount, f.currency, f.round_mode, f.remark,
f.fee_source, f.source_id, f.is_deleted, f.statement_line_id,
f.create_by, f.create_time, f.update_by, f.update_time
from prc_pay_bill_fee f
<include refid="feeItemJoin"/>
where f.fee_source = 'LADING'
and f.sc_id = #{feeId}
and ifnull(f.is_deleted, '0') = '0'
</select>
<update id="markLadingFeeDeleted">
update prc_pay_bill_fee
set is_deleted = '1'
@@ -91,13 +159,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and ifnull(is_deleted, '0') = '0'
</update>
<update id="fillSourceIdByFeeIds">
update prc_pay_bill_fee
set source_id = fee_id
where (source_id is null or source_id = '')
and fee_id in
<foreach collection="feeIds" item="feeId" open="(" separator="," close=")">#{feeId}</foreach>
</update>
<select id="countSettledCalc" resultType="int">
select count(1)
from prc_pay_bill_fee
where bill_id = #{billId}
and ifnull(is_deleted, '0') = '0'
and (fee_source is null or fee_source = '' or fee_source = 'CALC')
and statement_line_id is not null
</select>
<delete id="deleteByBillId" parameterType="Long">
delete from prc_pay_bill_fee
@@ -129,7 +129,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<foreach collection="billIds" item="billId" open="(" separator="," close=")">#{billId}</foreach>
</update>
<delete id="deleteByBillId" parameterType="Long">
<update id="markCalcStatus">
update prc_pay_bill
set pay_calc_status = #{status},
pay_calc_msg = #{message},
update_by = #{operator},
update_time = sysdate()
where bill_id = #{billId}
</update>
<delete id="deleteByBillId" parameterType="String">
delete from prc_pay_bill where bill_id = #{billId}
</delete>
</mapper>
@@ -4,11 +4,11 @@
<select id="selectPendingFees" resultType="com.bms.price.airbill.domain.SrvBillAirAllocFee">
select f.id, f.bill_code as billCode, a.guid as ladingId, f.fee_level as feeLevel,
f.bill_fee_status as billFeeStatus, sc.sc_name as feeName, f.price, f.currency,
f.bill_fee_status as billFeeStatus, f.fee_type as feeType, sc.sc_name as feeName, f.price, f.currency,
f.alloc_dim as allocDim
from srv_bill_air_fee f
left join srv_bill_air a on a.bill_code = f.bill_code
left join prc_surcharge sc on sc.sc_id = f.fee_type and ifnull(sc.is_del, '0') = '0'
left join prc_surcharge sc on sc.sc_id = f.sc_id and ifnull(sc.is_del, '0') = '0'
where f.del_flag = '0'
and f.bill_fee_status = '0'
and f.bill_code in
@@ -3,13 +3,13 @@
<mapper namespace="com.bms.price.mapper.SrvBillAirFeeMapper">
<select id="selectByBillCode" resultType="com.bms.price.airbill.domain.SrvBillAirFee">
select f.id, f.bill_code as billCode, f.fee_type as feeType, sc.sc_name as feeName,
select f.id, f.bill_code as billCode, f.fee_type as feeType, f.sc_id as scId, sc.sc_name as feeName,
f.fee_level as feeLevel, f.bill_fee_status as billFeeStatus,
f.alloc_flag as allocFlag, f.alloc_dim as allocDim, f.price, f.currency, f.remark,
f.create_by as createBy, f.create_time as createTime, f.update_by as updateBy,
f.update_time as updateTime, f.del_flag as delFlag
from srv_bill_air_fee f
left join prc_surcharge sc on sc.sc_id = f.fee_type and ifnull(sc.is_del, '0') = '0'
left join prc_surcharge sc on sc.sc_id = f.sc_id and ifnull(sc.is_del, '0') = '0'
where f.bill_code = #{billCode}
and f.del_flag = '0'
and ifnull(f.bill_fee_status, '0') &lt;&gt; '2'
@@ -28,13 +28,13 @@
</sql>
<select id="selectRoleFees" parameterType="com.bms.price.airbill.domain.SrvBillAirRoleFeeQuery" resultType="com.bms.price.airbill.domain.SrvBillAirFee">
select f.id, f.bill_code as billCode, f.fee_type as feeType, sc.sc_name as feeName,
select f.id, f.bill_code as billCode, f.fee_type as feeType, f.sc_id as scId, sc.sc_name as feeName,
f.fee_level as feeLevel, f.fee_scene as feeScene, f.bill_fee_status as billFeeStatus,
f.alloc_flag as allocFlag, f.alloc_dim as allocDim, f.price, f.currency, f.remark,
f.create_by as createBy, f.create_time as createTime, f.update_by as updateBy,
f.update_time as updateTime, f.del_flag as delFlag
from srv_bill_air_fee f
left join prc_surcharge sc on sc.sc_id = f.fee_type and ifnull(sc.is_del, '0') = '0'
left join prc_surcharge sc on sc.sc_id = f.sc_id and ifnull(sc.is_del, '0') = '0'
where f.del_flag = '0'
and ifnull(f.bill_fee_status, '0') &lt;&gt; '2'
and f.fee_scene = #{feeScene}
@@ -64,13 +64,13 @@
</select>
<select id="selectLive" resultType="com.bms.price.airbill.domain.SrvBillAirFee">
select f.id, f.bill_code as billCode, f.fee_type as feeType, sc.sc_name as feeName,
select f.id, f.bill_code as billCode, f.fee_type as feeType, f.sc_id as scId, sc.sc_name as feeName,
f.fee_level as feeLevel, f.bill_fee_status as billFeeStatus,
f.alloc_flag as allocFlag, f.alloc_dim as allocDim, f.price, f.currency, f.remark,
f.create_by as createBy, f.create_time as createTime, f.update_by as updateBy,
f.update_time as updateTime, f.del_flag as delFlag
from srv_bill_air_fee f
left join prc_surcharge sc on sc.sc_id = f.fee_type and ifnull(sc.is_del, '0') = '0'
left join prc_surcharge sc on sc.sc_id = f.sc_id and ifnull(sc.is_del, '0') = '0'
where f.id = #{id}
and f.bill_code = #{billCode}
and f.del_flag = '0'
@@ -79,10 +79,10 @@
<insert id="insertFee" useGeneratedKeys="true" keyProperty="id">
insert into srv_bill_air_fee (
bill_code, fee_type, fee_level, fee_scene, bill_fee_status, alloc_flag, alloc_dim, price, currency, remark,
bill_code, fee_type, sc_id, fee_level, fee_scene, bill_fee_status, alloc_flag, alloc_dim, price, currency, remark,
create_by, create_time, update_by, update_time, del_flag
) values (
#{billCode}, #{feeType}, #{feeLevel}, #{feeScene}, '0', #{allocFlag}, #{allocDim}, #{price}, #{currency}, #{remark},
#{billCode}, #{feeType}, #{scId}, #{feeLevel}, #{feeScene}, '0', #{allocFlag}, #{allocDim}, #{price}, #{currency}, #{remark},
#{createBy}, #{createTime}, #{updateBy}, #{updateTime}, '0'
)
</insert>
@@ -90,6 +90,7 @@
<update id="updateFee">
update srv_bill_air_fee
set fee_type = #{feeType},
sc_id = #{scId},
fee_level = #{feeLevel},
alloc_flag = #{allocFlag},
alloc_dim = #{allocDim},