Merge branch 'test'

This commit is contained in:
caojia
2026-11-11 11:32:25 +08:00
125 changed files with 1355 additions and 856 deletions
@@ -15,8 +15,8 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import com.bms.common.exception.ServiceException;
import com.bms.common.utils.SecurityUtils;
import com.bms.ar.domain.ArBankAccount;
import com.bms.ar.mapper.ArBankAccountMapper;
import com.bms.receivable.domain.ArBankAccount;
import com.bms.receivable.mapper.ArBankAccountMapper;
import com.bms.customer.customerinfo.domain.BmsCustomer;
import com.bms.customer.customerinfo.domain.BmsCustomerAttachment;
import com.bms.customer.customerinfo.mapper.BmsCustomerMapper;
@@ -25,7 +25,7 @@ public class BillingProperties
* Keep below Druid maxActive with headroom for other traffic.
*/
private int localRebillThreads = 16;
/** Night window auto-retry of prc_billing_task (all statuses) */
/** Hourly auto-retry of prc_billing_task (all statuses) */
private NightRetry nightRetry = new NightRetry();
private Oracle oracle = new Oracle();
@@ -120,8 +120,8 @@ public class BillingProperties
}
/**
* Overnight rebill window: pull prc_billing_task (all success_status) and retryTask.
* Default hours [0, 9) local time; empty result skips billing.
* Auto rebill window: pull prc_billing_task (all success_status) and retryTask.
* Default hours [0, 24) local time (all day); empty result skips billing.
*/
public static class NightRetry
{
@@ -129,8 +129,8 @@ public class BillingProperties
private boolean enabled = true;
/** Inclusive start hour (0 = 00:00) */
private int startHour = 0;
/** Exclusive end hour (9 = stop at 09:00) */
private int endHour = 9;
/** Exclusive end hour (24 = all day) */
private int endHour = 24;
/** Page size: bill this many then pull next page (default 500) */
private int batchSize = 500;
@@ -20,9 +20,6 @@ public class ChannelProductMap
private Long productId;
/** 打单套餐 ID,对应 prc_price_set.price_set_id(应收可填) */
private Long priceSetId;
/** 渠道名称(列表回显) */
private String channelName;
@@ -122,7 +122,7 @@ public class PrcOrderBill extends BaseEntity
private String creditArrearsStatus;
/** NONE / REFUNDED */
private String refundStatus;
/** Billing fail: 0 ok; 1/2/3 sales miss; 23/24/25 catalog miss; soft-fail amount=0, no fee rows */
/** Billing fail: 0 ok writes income bill+fee; non-0 amount=0, no income bill/fee */
private Integer billingFailStatus;
/** 失败原因 */
private String errorMessage;
@@ -0,0 +1,61 @@
package com.bms.price.domain.vo;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
/**
* Order-list billing fail reason popup payload.
*/
@Data
public class OrderBillFailReasonVo implements Serializable
{
private static final long serialVersionUID = 1L;
private String billId;
private String orderNo;
private String transferNo;
private String trackingNo;
private String customerCode;
private String customerName;
private String productCode;
private String productName;
private String countryCode;
private String countryName;
private String zoneCode;
private String zoneName;
private String destPostcode;
private Long priceSetId;
private String priceSetCode;
private String priceSetName;
private String setType;
private Long psvId;
private String versionNo;
private Long psdId;
private BigDecimal weight;
private BigDecimal chargeWeight;
private BigDecimal weightMin;
private BigDecimal weightMax;
private String weightLabel;
private BigDecimal freightRate;
private BigDecimal freightAmount;
private BigDecimal incomeTotal;
private String currency;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date bizDate;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date pickupDate;
private Integer billingFailStatus;
private String billingFailStatusLabel;
/** Raw persisted fail text. */
private String errorMessage;
/** Templated human-readable fail reason. */
private String failReasonDetail;
}
@@ -103,7 +103,7 @@ public class TmsPriceQuoteResult implements Serializable
private String creditArrearsStatus;
/** NONE / REFUNDED */
private String refundStatus;
/** Billing fail: 0 ok; 1/2/3 sales; 23/24/25 catalog (soft-fail on bill sync) */
/** Billing fail: 0 ok (income bill+fee); 1/2/3 sales; 23/24/25 catalog */
private Integer billingFailStatus;
private Integer pieces;
private BigDecimal actualWeight;
@@ -6,7 +6,8 @@ package com.bms.price.enums;
* 1/2/3 sales-price (package) miss: product / country / weight;
* 23/24/25 product-catalog price miss: product / country / weight;
* 4+ map to prc_billing_task.fail_code.
* Soft-fail income bill: 0/1/2/3/23/24/25; fee rows only for 0.
* 26 not billed yet (order-source sync only).
* Income bill + fee rows: only status 0.
*/
public enum BillBillingFailStatus
{
@@ -38,7 +39,9 @@ public enum BillBillingFailStatus
/** Product catalog miss: product hit but country/zone miss. */
CATALOG_COUNTRY(24),
/** Product catalog miss: product+country hit but weight band miss. */
CATALOG_WEIGHT(25);
CATALOG_WEIGHT(25),
/** Order landed from upstream but not billed yet. */
NOT_BILLED(26);
private final int code;
@@ -70,16 +73,23 @@ public enum BillBillingFailStatus
public static boolean isFail(Integer code)
{
return code != null && code.intValue() > SUCCESS.code;
if (code == null)
{
return false;
}
int value = code.intValue();
return value != SUCCESS.code && value != NOT_BILLED.code;
}
/** Soft-fail sales/catalog misses also persist prc_income_bill. */
public static boolean isNotBilled(Integer code)
{
return code != null && code.intValue() == NOT_BILLED.code;
}
/** Only success (0) persists prc_income_bill. */
public static boolean storesIncomeBill(Integer code)
{
int value = code == null ? SUCCESS.code : code.intValue();
return value == SUCCESS.code
|| value == PRODUCT.code || value == COUNTRY.code || value == WEIGHT.code
|| value == CATALOG_PRODUCT.code || value == CATALOG_COUNTRY.code || value == CATALOG_WEIGHT.code;
return code == null || code.intValue() == SUCCESS.code;
}
/** 仅 0 落 prc_income_bill_fee。 */
@@ -96,7 +106,7 @@ public enum BillBillingFailStatus
}
for (BillBillingFailStatus status : values())
{
if (status == SUCCESS)
if (status == SUCCESS || status == NOT_BILLED)
{
continue;
}
@@ -113,6 +123,7 @@ public enum BillBillingFailStatus
switch (this)
{
case SUCCESS:
case NOT_BILLED:
return null;
case PRODUCT:
return BillTaskFailCode.PRODUCT_NOT_HIT.getCode();
@@ -1,24 +1,19 @@
package com.bms.price.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.bms.price.domain.ChannelProductMap;
/**
* 渠道产品关系映射
* Channel-product pay-type mapping.
*/
public interface ChannelProductMapMapper
{
ChannelProductMap selectByChannelAndType(@Param("channelId") String channelId, @Param("payType") String payType);
List<ChannelProductMap> selectByPriceSetId(@Param("priceSetId") Long priceSetId);
int upsert(ChannelProductMap row);
int deleteByChannelAndType(@Param("channelId") String channelId, @Param("payType") String payType);
int deleteByChannelTypeAndPriceSet(@Param("channelId") String channelId, @Param("payType") String payType,
@Param("priceSetId") Long priceSetId);
int deleteByProductId(@Param("productId") Long productId);
}
@@ -17,8 +17,6 @@ public interface PayProductTermMapper
PayProductTerm selectByProductId(Long productId);
/** 打单产品所属套餐 ID */
Long selectLabelPriceSetIdByProduct(@Param("productId") Long productId);
List<PayProductTerm> selectByPriceSetId(@Param("priceSetId") Long priceSetId);
@@ -91,14 +91,6 @@ public interface IPayProductService
/** 从打单套餐移除产品(失效/清理对应 term 明细) */
int removeLabelProducts(Long priceSetId, Long[] productIds);
/** 打单套餐已绑定渠道列表 */
java.util.List<ChannelProductMap> listLabelChannels(Long priceSetId);
/** 打单套餐批量绑定渠道(写 AR + price_set_id) */
String bindLabelChannels(Long priceSetId, java.util.List<String> channelIds, Long productId);
/** 打单套餐解绑渠道 */
int unbindLabelChannel(Long priceSetId, String channelId);
/** 取消渠道上指定收付类型的产品。payType 为空时按应付 AP */
void unbindChannel(String channelId, String payType);
@@ -13,6 +13,7 @@ import com.bms.price.domain.vo.BatchAddIncomeBillFeeRequest;
import com.bms.price.domain.vo.ChargeWeightImportRow;
import com.bms.price.domain.vo.ChargeWeightTemplateRequest;
import com.bms.price.domain.vo.LocalRebillRequest;
import com.bms.price.domain.vo.OrderBillFailReasonVo;
import com.bms.price.domain.vo.RecalcBillPriceRequest;
import com.bms.price.domain.vo.UpdateIncomeBillFeeRequest;
import com.bms.price.domain.vo.TmsPriceBillRequest;
@@ -60,6 +61,9 @@ public interface IPrcOrderBillService
TmsPriceQuoteResult getBill(String billId);
/** Billing fail reason for order-list popup (data-scoped). */
OrderBillFailReasonVo getBillingFailReason(String billId);
TmsPriceQuoteResult getBillByOrderNo(String orderNo);
/** Manual add income fee from surcharge config; refresh receivable totals. */
@@ -1056,103 +1056,6 @@ public class PayProductServiceImpl implements IPayProductService
return n;
}
@Override
public List<ChannelProductMap> listLabelChannels(Long priceSetId)
{
if (priceSetId == null)
{
return Collections.emptyList();
}
List<ChannelProductMap> list = channelProductMapMapper.selectByPriceSetId(priceSetId);
return list == null ? Collections.emptyList() : list;
}
@Override
@Transactional(rollbackFor = Exception.class)
public String bindLabelChannels(Long priceSetId, List<String> channelIds, Long productId)
{
if (priceSetId == null)
{
throw new ServiceException("请选择打单套餐");
}
if (channelIds == null || channelIds.isEmpty())
{
throw new ServiceException("请选择要绑定的渠道");
}
if (productId == null)
{
throw new ServiceException("请选择套餐内应收产品");
}
PrcPriceSet set = priceSetMapper.selectPrcPriceSetById(priceSetId);
if (set == null || !PrcPriceSet.CATEGORY_LABEL.equalsIgnoreCase(String.valueOf(set.getSetCategory())))
{
throw new ServiceException("打单套餐不存在");
}
Long root = resolveRoot(productId);
boolean inSet = false;
List<PayProduct> products = selectLabelProducts(priceSetId);
for (PayProduct p : products)
{
if (p != null && root.equals(p.getProductId()))
{
inSet = true;
break;
}
}
if (!inSet)
{
throw new ServiceException("所选产品不属于本打单套餐");
}
String operator = SecurityUtils.getUsername();
int n = 0;
for (String channelId : channelIds)
{
if (isBlank(channelId))
{
continue;
}
ServiceChannel channel = serviceChannelMapper.selectServiceChannelById(channelId.trim());
if (channel == null || isBlank(channel.getChannelCode()))
{
throw new ServiceException("渠道不存在或渠道编码为空:" + channelId);
}
ChannelProductMap row = new ChannelProductMap();
row.setChannelId(channelId.trim());
row.setChannelCode(channel.getChannelCode());
row.setProductId(root);
row.setPriceSetId(priceSetId);
row.setPayType(PAY_TYPE_AR);
row.setCreateBy(operator);
row.setUpdateBy(operator);
channelProductMapMapper.upsert(row);
n++;
}
if (n <= 0)
{
throw new ServiceException("没有可绑定的渠道");
}
return "已绑定 " + n + " 个渠道";
}
@Override
@Transactional(rollbackFor = Exception.class)
public int unbindLabelChannel(Long priceSetId, String channelId)
{
if (priceSetId == null || isBlank(channelId))
{
return 0;
}
return channelProductMapMapper.deleteByChannelTypeAndPriceSet(channelId.trim(), PAY_TYPE_AR, priceSetId);
}
private Long resolveLabelPriceSetId(Long productId)
{
if (productId == null)
{
return null;
}
return payProductTermMapper.selectLabelPriceSetIdByProduct(productId);
}
@Override
public List<PayProduct> selectLabelProducts(Long priceSetId)
@@ -1756,10 +1659,6 @@ public class PayProductServiceImpl implements IPayProductService
row.setChannelCode(channel.getChannelCode());
row.setProductId(storedId);
row.setPayType(type);
if (PAY_TYPE_AR.equals(type))
{
row.setPriceSetId(resolveLabelPriceSetId(storedId));
}
String operator = SecurityUtils.getUsername();
row.setCreateBy(operator);
row.setUpdateBy(operator);
@@ -6,7 +6,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
@@ -28,8 +27,8 @@ import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.bms.ar.enums.ArIncomeBillFeeStatus;
import com.bms.ar.enums.ArOrderBillStatus;
import com.bms.receivable.enums.ArIncomeBillFeeStatus;
import com.bms.receivable.enums.ArOrderBillStatus;
import com.bms.common.annotation.DataScope;
import com.bms.common.core.domain.entity.SysUser;
import com.bms.common.exception.ServiceException;
@@ -63,6 +62,7 @@ import com.bms.price.domain.vo.BatchAddIncomeBillFeeRequest;
import com.bms.price.domain.vo.ChargeWeightImportRow;
import com.bms.price.domain.vo.ChargeWeightTemplateRequest;
import com.bms.price.domain.vo.LocalRebillRequest;
import com.bms.price.domain.vo.OrderBillFailReasonVo;
import com.bms.price.domain.vo.RecalcBillPriceRequest;
import com.bms.price.domain.vo.UpdateIncomeBillFeeRequest;
import com.bms.price.task.PrcBatchAddIncomeFeeAsyncRunner;
@@ -71,6 +71,7 @@ import com.bms.price.task.PrcChargeWeightImportAsyncRunner.ChargeWeightImportWor
import com.bms.price.task.PrcOrderBillExportAsyncRunner;
import com.bms.price.task.PrcOrderBillLocalRebillAsyncRunner;
import com.bms.price.task.PrcRecalcBillPriceAsyncRunner;
import com.bms.price.service.support.BillingFailReasonSupport;
import com.bms.price.service.support.OrderBillExportSupport;
import com.bms.price.domain.vo.TmsPriceBillRequest;
import com.bms.price.domain.vo.TmsOrderBillStatusResult;
@@ -86,6 +87,10 @@ import com.bms.price.mapper.PrcIncomeBillFeeMapper;
import com.bms.price.mapper.PrcIncomeBillMapper;
import com.bms.price.mapper.PrcOrderBillExtMapper;
import com.bms.price.mapper.PrcOrderBillMapper;
import com.bms.price.mapper.PrcPriceSetDetailMapper;
import com.bms.price.mapper.PrcPriceSetVersionMapper;
import com.bms.price.domain.PrcPriceSetDetail;
import com.bms.price.domain.PrcPriceSetVersion;
import com.bms.price.mapper.PrcPayBillFeeMapper;
import com.bms.price.mapper.PrcPayBillMapper;
import com.bms.price.oracle.OracleOrderBillExtFiller;
@@ -121,6 +126,12 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
@Autowired
private PrcOrderBillMapper orderBillMapper;
@Autowired
private PrcPriceSetVersionMapper priceSetVersionMapper;
@Autowired
private PrcPriceSetDetailMapper priceSetDetailMapper;
/** TMS 实时状态查询使用客户主档案,不读取订单上的历史状态快照。 */
@Autowired
private BmsCustomerMapper bmsCustomerMapper;
@@ -433,6 +444,86 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
payBillFeeMapper.selectByBillId(bill.getBillId()));
}
@Override
public OrderBillFailReasonVo getBillingFailReason(String billId)
{
if (StringUtils.isEmpty(billId))
{
throw new ServiceException(MessageUtils.message("price.bill.billIdRequired"));
}
PrcOrderBill query = new PrcOrderBill();
query.setBillId(billId.trim());
List<PrcOrderBill> list = self.selectBillList(query);
if (list == null || list.isEmpty())
{
throw new ServiceException(MessageUtils.message("price.bill.notFound"));
}
PrcOrderBill bill = list.get(0);
OrderBillFailReasonVo vo = new OrderBillFailReasonVo();
vo.setBillId(bill.getBillId());
vo.setOrderNo(bill.getOrderNo());
vo.setTransferNo(bill.getTransferNo());
vo.setTrackingNo(bill.getTrackingNo());
vo.setCustomerCode(bill.getCustomerCode());
vo.setCustomerName(bill.getCustomerName());
vo.setProductCode(bill.getProductCode());
vo.setProductName(bill.getProductName());
vo.setCountryCode(bill.getCountryCode());
vo.setCountryName(bill.getCountryName());
vo.setDestPostcode(bill.getDestPostcode());
vo.setPriceSetId(bill.getPriceSetId());
vo.setPriceSetCode(bill.getPriceSetCode());
vo.setPriceSetName(bill.getPriceSetName());
vo.setSetType(bill.getSetType());
vo.setPsvId(bill.getPsvId());
vo.setPsdId(bill.getPsdId());
vo.setWeight(bill.getWeight());
vo.setChargeWeight(bill.getChargeWeight());
vo.setWeightMin(bill.getWeightMin());
vo.setWeightMax(bill.getWeightMax());
vo.setWeightLabel(bill.getWeightLabel());
vo.setFreightRate(bill.getFreightRate());
vo.setFreightAmount(bill.getFreightAmount());
vo.setIncomeTotal(bill.getIncomeTotal());
vo.setCurrency(bill.getCurrency());
vo.setBizDate(bill.getBizDate());
vo.setPickupDate(bill.getPickupDate());
Integer status = bill.getBillingFailStatus() == null
? Integer.valueOf(BillBillingFailStatus.SUCCESS.getCode()) : bill.getBillingFailStatus();
vo.setBillingFailStatus(status);
vo.setBillingFailStatusLabel(OrderBillExportSupport.billingFailStatusLabel(status));
if (bill.getPsvId() != null && priceSetVersionMapper != null)
{
PrcPriceSetVersion ver = priceSetVersionMapper.selectPrcPriceSetVersionById(bill.getPsvId());
if (ver != null)
{
vo.setVersionNo(ver.getVersionNo());
}
}
if (bill.getPsdId() != null && priceSetDetailMapper != null)
{
PrcPriceSetDetail detail = priceSetDetailMapper.selectPrcPriceSetDetailById(bill.getPsdId());
if (detail != null)
{
vo.setZoneCode(detail.getZoneCode());
vo.setZoneName(detail.getZoneName());
}
}
String reason = bill.getErrorMessage();
if (StringUtils.isEmpty(reason))
{
reason = bill.getMatchMessage();
}
if (StringUtils.isEmpty(reason))
{
reason = vo.getBillingFailStatusLabel();
}
vo.setErrorMessage(reason);
vo.setFailReasonDetail(BillingFailReasonSupport.buildDetail(vo, reason));
return vo;
}
@Override
public TmsPriceQuoteResult getBillByOrderNo(String orderNo)
{
@@ -3091,7 +3182,8 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
bill.setBillId(UUID.randomUUID().toString());
bill.setArBillStatus(ArOrderBillStatus.UNBILLED.getCode());
bill.setRefundStatus(BillRefundStatus.NONE.getCode());
bill.setBillingFailStatus(Integer.valueOf(BillBillingFailStatus.SUCCESS.getCode()));
// Order-source sync only: mark not billed until quote/bill runs.
bill.setBillingFailStatus(Integer.valueOf(BillBillingFailStatus.NOT_BILLED.getCode()));
bill.setFreightRate(BigDecimal.ZERO);
bill.setBaseFreightRate(BigDecimal.ZERO);
bill.setRegistrationFee(BigDecimal.ZERO);
@@ -0,0 +1,114 @@
package com.bms.price.service.support;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.bms.common.utils.StringUtils;
import com.bms.price.domain.vo.OrderBillFailReasonVo;
/**
* Build templated billing-fail reason text for order-list popup.
*/
public final class BillingFailReasonSupport
{
private BillingFailReasonSupport() {}
private static final Map<Integer, String> TEMPLATES = new HashMap<Integer, String>();
static
{
TEMPLATES.put(Integer.valueOf(1), "\u3010\u9500\u552e\u4ef7\u672a\u5339\u914d\u4ea7\u54c1\u3011\n\u8ba2\u5355 {orderNo}\uff08\u8f6c\u5355\u53f7 {transferNo}\uff09\uff0c\u5ba2\u6237 {customer}\uff0c\u4ea7\u54c1 {product}\uff0c\u56fd\u5bb6 {country}\uff0c\u8ba1\u8d39\u65f6\u95f4 {bizDate}\u3002\n\u5728\u5ba2\u6237\u9500\u552e\u4ef7\u5957\u9910\u300c{priceSet}\u300d\u4e2d\u672a\u627e\u5230\u8be5\u4ea7\u54c1\uff0c\u8bf7\u68c0\u67e5\u5957\u9910\u4ea7\u54c1\u8303\u56f4\u6216\u4ea7\u54c1\u4ee3\u7801\u6620\u5c04\u3002");
TEMPLATES.put(Integer.valueOf(2), "\u3010\u9500\u552e\u4ef7\u672a\u5339\u914d\u56fd\u5bb6\u3011\n\u8ba2\u5355 {orderNo}\uff08\u8f6c\u5355\u53f7 {transferNo}\uff09\uff0c\u5ba2\u6237 {customer}\uff0c\u4ea7\u54c1 {product}\uff0c\u76ee\u7684\u56fd\u5bb6 {country}\uff0c\u90ae\u7f16 {postcode}\uff0c\u8ba1\u8d39\u65f6\u95f4 {bizDate}\u3002\n\u5957\u9910\u300c{priceSet}\u300d\u7248\u672c {version}\u5df2\u547d\u4e2d\u4ea7\u54c1\uff0c\u4f46\u672a\u547d\u4e2d\u56fd\u5bb6/\u5206\u533a\uff0c\u8bf7\u8865\u9f50\u56fd\u5bb6\u4e0e\u5206\u533a\u4ef7\u683c\u3002");
TEMPLATES.put(Integer.valueOf(3), "\u3010\u9500\u552e\u4ef7\u672a\u5339\u914d\u91cd\u91cf\u6bb5\u3011\n\u8ba2\u5355 {orderNo}\uff08\u8f6c\u5355\u53f7 {transferNo}\uff09\uff0c\u5ba2\u6237 {customer}\uff0c\u4ea7\u54c1 {product}\uff0c\u56fd\u5bb6 {country}\uff0c\u5206\u533a {zone}\uff0c\u8ba1\u8d39\u91cd {chargeWeight} kg\uff0c\u8ba1\u8d39\u65f6\u95f4 {bizDate}\u3002\n\u5957\u9910\u300c{priceSet}\u300d\u7248\u672c {version}\u5df2\u547d\u4e2d\u4ea7\u54c1\u4e0e\u56fd\u5bb6\uff0c\u4f46\u8ba1\u8d39\u91cd\u672a\u843d\u5728\u4ef7\u683c\u91cd\u91cf\u6bb5\u5185\uff0c\u8bf7\u68c0\u67e5\u91cd\u91cf\u6bb5\u8bbe\u7f6e\u3002");
TEMPLATES.put(Integer.valueOf(23), "\u3010\u4ea7\u54c1\u4ef7\u672a\u5339\u914d\u4ea7\u54c1\u3011\n\u8ba2\u5355 {orderNo}\uff08\u8f6c\u5355\u53f7 {transferNo}\uff09\uff0c\u5ba2\u6237 {customer}\uff0c\u4ea7\u54c1 {product}\uff0c\u56fd\u5bb6 {country}\uff0c\u8ba1\u8d39\u65f6\u95f4 {bizDate}\u3002\n\u4ea7\u54c1\u4ef7\u76ee\u5f55\u4e2d\u672a\u627e\u5230\u8be5\u4ea7\u54c1\uff0c\u8bf7\u68c0\u67e5\u4ea7\u54c1\u4ef7\u6863\u6848\u662f\u5426\u5df2\u7ef4\u62a4\u3002");
TEMPLATES.put(Integer.valueOf(24), "\u3010\u4ea7\u54c1\u4ef7\u672a\u5339\u914d\u56fd\u5bb6\u3011\n\u8ba2\u5355 {orderNo}\uff08\u8f6c\u5355\u53f7 {transferNo}\uff09\uff0c\u4ea7\u54c1 {product}\uff0c\u76ee\u7684\u56fd\u5bb6 {country}\uff0c\u90ae\u7f16 {postcode}\uff0c\u8ba1\u8d39\u65f6\u95f4 {bizDate}\u3002\n\u4ea7\u54c1\u4ef7\u5df2\u547d\u4e2d\u4ea7\u54c1\uff0c\u4f46\u672a\u547d\u4e2d\u56fd\u5bb6/\u5206\u533a\uff0c\u8bf7\u8865\u9f50\u4ea7\u54c1\u4ef7\u56fd\u5bb6\u4ef7\u683c\u3002");
TEMPLATES.put(Integer.valueOf(25), "\u3010\u4ea7\u54c1\u4ef7\u672a\u5339\u914d\u91cd\u91cf\u6bb5\u3011\n\u8ba2\u5355 {orderNo}\uff08\u8f6c\u5355\u53f7 {transferNo}\uff09\uff0c\u4ea7\u54c1 {product}\uff0c\u56fd\u5bb6 {country}\uff0c\u5206\u533a {zone}\uff0c\u8ba1\u8d39\u91cd {chargeWeight} kg\uff0c\u8ba1\u8d39\u65f6\u95f4 {bizDate}\u3002\n\u4ea7\u54c1\u4ef7\u5df2\u547d\u4e2d\u4ea7\u54c1\u4e0e\u56fd\u5bb6\uff0c\u4f46\u8ba1\u8d39\u91cd\u672a\u843d\u5728\u91cd\u91cf\u6bb5\u5185\uff0c\u8bf7\u68c0\u67e5\u4ea7\u54c1\u4ef7\u91cd\u91cf\u6bb5\u3002");
TEMPLATES.put(Integer.valueOf(4), "\u3010\u672a\u7ed1\u5b9a\u5957\u9910\u3011\n\u8ba2\u5355 {orderNo}\uff08\u8f6c\u5355\u53f7 {transferNo}\uff09\uff0c\u5ba2\u6237 {customer}\uff0c\u8ba1\u8d39\u65f6\u95f4 {bizDate}\u3002\n\u8be5\u5ba2\u6237\u672a\u7ed1\u5b9a\u9500\u552e\u4ef7\u5957\u9910\uff0c\u65e0\u6cd5\u6309\u5957\u9910\u53d6\u4ef7\uff0c\u8bf7\u5148\u5728\u5ba2\u6237/\u5957\u9910\u7ed1\u5b9a\u540e\u518d\u8ba1\u8d39\u3002");
TEMPLATES.put(Integer.valueOf(5), "\u3010\u5957\u9910\u672a\u542f\u7528/\u65e0\u751f\u6548\u7248\u672c\u3011\n\u8ba2\u5355 {orderNo}\uff08\u8f6c\u5355\u53f7 {transferNo}\uff09\uff0c\u5ba2\u6237 {customer}\uff0c\u5957\u9910\u300c{priceSet}\u300d\uff0c\u8ba1\u8d39\u65f6\u95f4 {bizDate}\u3002\n\u8ba1\u8d39\u65e5\u6ca1\u6709\u53ef\u7528\u7684\u5957\u9910\u751f\u6548\u7248\u672c\uff0c\u8bf7\u68c0\u67e5\u5957\u9910\u542f\u7528\u72b6\u6001\u4e0e\u7248\u672c\u751f\u6548\u671f\u3002");
}
public static String buildDetail(OrderBillFailReasonVo vo, String fallback)
{
if (vo == null)
{
return fallback;
}
Integer status = vo.getBillingFailStatus();
String tpl = status == null ? null : TEMPLATES.get(status);
if (StringUtils.isEmpty(tpl))
{
StringBuilder sb = new StringBuilder();
sb.append("\u3010").append(nz(vo.getBillingFailStatusLabel(), "\u8ba1\u8d39\u5931\u8d25")).append("\u3011\n");
sb.append("\u8ba2\u5355 ").append(nz(vo.getOrderNo(), "-"));
sb.append("\uff08\u8f6c\u5355\u53f7 ").append(nz(vo.getTransferNo(), "-")).append("\uff09");
sb.append("\uff0c\u5ba2\u6237 ").append(joinCodeName(vo.getCustomerCode(), vo.getCustomerName()));
sb.append("\uff0c\u4ea7\u54c1 ").append(joinCodeName(vo.getProductCode(), vo.getProductName()));
sb.append("\uff0c\u56fd\u5bb6 ").append(joinCodeName(vo.getCountryCode(), vo.getCountryName()));
sb.append("\uff0c\u8ba1\u8d39\u65f6\u95f4 ").append(fmtDate(vo.getBizDate())).append("\u3002\n");
sb.append(nz(fallback, nz(vo.getErrorMessage(), vo.getBillingFailStatusLabel())));
return sb.toString();
}
Map<String, String> ctx = new HashMap<String, String>();
ctx.put("orderNo", nz(vo.getOrderNo(), "-"));
ctx.put("transferNo", nz(vo.getTransferNo(), "-"));
ctx.put("trackingNo", nz(vo.getTrackingNo(), "-"));
ctx.put("customer", joinCodeName(vo.getCustomerCode(), vo.getCustomerName()));
ctx.put("product", joinCodeName(vo.getProductCode(), vo.getProductName()));
ctx.put("country", joinCodeName(vo.getCountryCode(), vo.getCountryName()));
ctx.put("zone", joinCodeName(vo.getZoneCode(), vo.getZoneName()));
ctx.put("postcode", nz(vo.getDestPostcode(), "-"));
ctx.put("priceSet", joinCodeName(vo.getPriceSetCode(), vo.getPriceSetName()));
ctx.put("version", nz(vo.getVersionNo(), "-"));
ctx.put("chargeWeight", fmtNum(vo.getChargeWeight()));
ctx.put("bizDate", fmtDate(vo.getBizDate()));
ctx.put("pickupDate", fmtDate(vo.getPickupDate()));
String out = tpl;
for (Map.Entry<String, String> e : ctx.entrySet())
{
out = out.replace("{" + e.getKey() + "}", e.getValue());
}
if (StringUtils.isNotEmpty(fallback) && !fallback.equals(vo.getBillingFailStatusLabel()))
{
out = out + "\n\u8be6\u60c5\uff1a" + fallback;
}
return out;
}
private static String joinCodeName(String code, String name)
{
if (StringUtils.isEmpty(code) && StringUtils.isEmpty(name))
{
return "-";
}
if (StringUtils.isEmpty(code))
{
return name;
}
if (StringUtils.isEmpty(name) || name.equals(code))
{
return code;
}
return code + "/" + name;
}
private static String fmtDate(Date d)
{
if (d == null)
{
return "-";
}
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d);
}
private static String fmtNum(BigDecimal n)
{
return n == null ? "-" : n.stripTrailingZeros().toPlainString();
}
private static String nz(String v, String def)
{
return StringUtils.isEmpty(v) ? def : v;
}
}
@@ -265,6 +265,7 @@ public final class OrderBillExportSupport
case 20: return "客户已停用";
case 21: return "运费为空";
case 22: return "未知失败";
case 26: return "未计费";
default: return String.valueOf(status);
}
}
@@ -16,13 +16,13 @@ import com.bms.price.mapper.PrcBillingTaskMapper;
import com.bms.price.service.IPrcBillingTaskService;
/**
* 夜间窗口按 prc_billing_task 自动重计费。
* Auto retry prc_billing_task on a schedule.
*
* <p>在 [startHour, endHour) 内(默认 00:00-09:00):最多拉取 {@value #DEFAULT_BATCH}
* 条任务 id(不限 success_status)-> 全部计费 -> 立刻拉下一页。
* 空页则跳过计费并结束本轮(下次 cron 再处理新数据)。</p>
* <p>Within [startHour, endHour) (default all day 00:00-24:00): pull up to {@value #DEFAULT_BATCH}
* task ids (any success_status) -> bill all -> pull next page.
* Empty page skips billing and ends this tick (next cron handles new rows).</p>
*
* <p>与监控手工重试 / 条件重试同一条重计费路径(先重置为 WAITING 再处理)。</p>
* <p>Same path as monitor manual / filter retry (reset to WAITING then process).</p>
*/
@Component
public class PrcBillingTaskNightRetryTask
@@ -52,10 +52,10 @@ public class PrcBillingTaskNightRetryTask
private IPrcBillingTaskService billingTaskService;
/**
* Fire every minute; if a previous run is still paging batches, skip.
* Fire every hour by default; if a previous run is still paging batches, skip.
* Hour gate uses bms.billing.night-retry start/end.
*/
@Scheduled(cron = "${bms.billing.night-retry.cron:0 0/1 0-8 * * ?}")
@Scheduled(cron = "${bms.billing.night-retry.cron:0 0 * * * ?}")
public void scheduledTick()
{
BillingProperties.NightRetry cfg = billingProperties == null ? null : billingProperties.getNightRetry();
@@ -28,11 +28,14 @@ import com.bms.price.config.BillingProperties;
import com.bms.price.domain.BatchAddIncomeBillFeeTask;
import com.bms.price.domain.PrcOrderBill;
import com.bms.price.domain.vo.LocalRebillRequest;
import com.bms.price.domain.vo.TmsPriceQuoteResult;
import com.bms.price.enums.BillBillingFailStatus;
import com.bms.price.mapper.PrcOrderBillMapper;
import com.bms.price.search.EsBizLogSupport;
import com.bms.price.search.IBillSearchStore;
import com.bms.price.search.TabOrderSyncEsLog;
import com.bms.price.service.IPrcOrderBillService;
import com.bms.price.service.support.OrderBillExportSupport;
/**
* Async local rebill from prc_order_bill only (no Oracle / MQ).
@@ -122,16 +125,33 @@ public class PrcOrderBillLocalRebillAsyncRunner
String one = ids.get(i);
try
{
orderBillService.rebillLocalByBillId(one);
success.incrementAndGet();
TmsPriceQuoteResult result = orderBillService.rebillLocalByBillId(one);
// Soft-fail still persists the order bill; count as fail in progress.
if (BillBillingFailStatus.isFail(result == null ? null : result.getBillingFailStatus()))
{
fail.incrementAndGet();
String tip = softFailMessage(result);
String transferLabel = failTransferLabel(one,
result == null ? null : result.getTransferNo());
appendFail(failTips, transferLabel, tip);
collectFailDetail(failDetails, one, tip);
log.warn("local rebill soft-fail taskId={} billId={} transferNo={} status={} msg={}",
taskId, one, transferLabel,
result == null ? null : result.getBillingFailStatus(), tip);
}
else
{
success.incrementAndGet();
}
}
catch (Exception e)
{
fail.incrementAndGet();
appendFail(failTips, one, e);
String transferLabel = failTransferLabel(one, null);
appendFail(failTips, transferLabel, e);
collectFailDetail(failDetails, one, e);
log.warn("local rebill failed taskId={} billId={} msg={}",
taskId, one, e.getMessage());
log.warn("local rebill failed taskId={} billId={} transferNo={} msg={}",
taskId, one, transferLabel, e.getMessage());
}
finally
{
@@ -250,6 +270,11 @@ public class PrcOrderBillLocalRebillAsyncRunner
}
private void collectFailDetail(List<Map<String, Object>> failDetails, String billId, Exception e)
{
collectFailDetail(failDetails, billId, errorMessage(e));
}
private void collectFailDetail(List<Map<String, Object>> failDetails, String billId, String message)
{
if (failDetails == null)
{
@@ -284,7 +309,7 @@ public class PrcOrderBillLocalRebillAsyncRunner
item.put("orderId", StringUtils.isEmpty(orderNo) ? billId : orderNo);
item.put("transferOrderId", transferNo);
item.put("trackingNo", trackingNo);
item.put("errorMessage", errorMessage(e));
item.put("errorMessage", StringUtils.isEmpty(message) ? "fail" : message);
failDetails.add(item);
}
}
@@ -427,7 +452,12 @@ public class PrcOrderBillLocalRebillAsyncRunner
return v;
}
private static void appendFail(StringBuilder failTips, String billId, Exception e)
private static void appendFail(StringBuilder failTips, String orderLabel, Exception e)
{
appendFail(failTips, orderLabel, errorMessage(e));
}
private static void appendFail(StringBuilder failTips, String orderLabel, String message)
{
synchronized (failTips)
{
@@ -439,10 +469,57 @@ public class PrcOrderBillLocalRebillAsyncRunner
{
failTips.append("; ");
}
failTips.append(billId).append(":").append(errorMessage(e));
failTips.append(StringUtils.isEmpty(orderLabel) ? "-" : orderLabel)
.append(":").append(StringUtils.isEmpty(message) ? "fail" : message);
}
}
/** Prefer transferNo in UI tips; fall back to orderNo, then billId. */
private String failTransferLabel(String billId, String transferNoHint)
{
if (StringUtils.isNotEmpty(transferNoHint))
{
return transferNoHint.trim();
}
if (StringUtils.isEmpty(billId) || orderBillMapper == null)
{
return billId;
}
try
{
PrcOrderBill bill = orderBillMapper.selectPrcOrderBillById(billId.trim());
if (bill != null)
{
if (StringUtils.isNotEmpty(bill.getTransferNo()))
{
return bill.getTransferNo().trim();
}
if (StringUtils.isNotEmpty(bill.getOrderNo()))
{
return bill.getOrderNo().trim();
}
}
}
catch (Exception ignore)
{
// tip label is best-effort
}
return billId;
}
private static String softFailMessage(TmsPriceQuoteResult result)
{
if (result == null)
{
return "billing fail";
}
if (StringUtils.isNotEmpty(result.getMatchMessage()))
{
return result.getMatchMessage();
}
return OrderBillExportSupport.billingFailStatusLabel(result.getBillingFailStatus());
}
private static String errorMessage(Exception e)
{
return StringUtils.isEmpty(e.getMessage()) ? e.getClass().getSimpleName() : e.getMessage();
@@ -1,4 +1,4 @@
package com.bms.ar.config;
package com.bms.receivable.config;
import java.util.concurrent.ThreadPoolExecutor;
import org.springframework.context.annotation.Bean;
@@ -1,4 +1,4 @@
package com.bms.ar.domain;
package com.bms.receivable.domain;
import java.math.BigDecimal;
import java.util.Date;
@@ -1,4 +1,4 @@
package com.bms.ar.domain;
package com.bms.receivable.domain;
import java.io.Serializable;
import java.util.Date;
@@ -1,4 +1,4 @@
package com.bms.ar.domain;
package com.bms.receivable.domain;
import java.math.BigDecimal;
import java.util.Date;
@@ -1,4 +1,4 @@
package com.bms.ar.domain;
package com.bms.receivable.domain;
import java.io.Serializable;
import java.math.BigDecimal;
@@ -1,4 +1,4 @@
package com.bms.ar.domain;
package com.bms.receivable.domain;
import java.io.Serializable;
import java.math.BigDecimal;
@@ -1,4 +1,4 @@
package com.bms.ar.domain;
package com.bms.receivable.domain;
import java.io.Serializable;
import java.util.Date;
@@ -1,4 +1,4 @@
package com.bms.ar.domain;
package com.bms.receivable.domain;
import java.io.Serializable;
import java.math.BigDecimal;
@@ -1,4 +1,4 @@
package com.bms.ar.domain;
package com.bms.receivable.domain;
import java.io.Serializable;
import java.util.Date;
@@ -1,4 +1,4 @@
package com.bms.ar.domain;
package com.bms.receivable.domain;
import java.io.Serializable;
import java.util.Date;
@@ -1,4 +1,4 @@
package com.bms.ar.domain.vo;
package com.bms.receivable.domain.vo;
import lombok.Data;
@@ -1,4 +1,4 @@
package com.bms.ar.domain.vo;
package com.bms.receivable.domain.vo;
import java.io.Serializable;
import java.math.BigDecimal;
@@ -1,4 +1,4 @@
package com.bms.ar.domain.vo;
package com.bms.receivable.domain.vo;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
@@ -1,4 +1,4 @@
package com.bms.ar.domain.vo;
package com.bms.receivable.domain.vo;
import java.util.Date;
import java.util.List;
@@ -8,7 +8,7 @@ import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import com.bms.common.config.serializer.StrictDateDeserializer;
import com.bms.ar.enums.ArBillSelectionMode;
import com.bms.receivable.enums.ArBillSelectionMode;
import lombok.Data;
/** 从订单计费结果生成正式账单的参数。 */
@@ -1,11 +1,11 @@
package com.bms.ar.domain.vo;
package com.bms.receivable.domain.vo;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import com.bms.ar.domain.ArBill;
import com.bms.ar.enums.ArBillStatus;
import com.bms.receivable.domain.ArBill;
import com.bms.receivable.enums.ArBillStatus;
import com.bms.common.annotation.Excel;
import lombok.Data;
@@ -1,9 +1,9 @@
package com.bms.ar.domain.vo;
package com.bms.receivable.domain.vo;
import java.util.Date;
import java.util.List;
import org.springframework.format.annotation.DateTimeFormat;
import com.bms.ar.domain.ArBill;
import com.bms.receivable.domain.ArBill;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -1,4 +1,4 @@
package com.bms.ar.domain.vo;
package com.bms.receivable.domain.vo;
import java.io.Serializable;
import java.math.BigDecimal;
@@ -1,4 +1,4 @@
package com.bms.ar.enums;
package com.bms.receivable.enums;
/**
* 应收账单余额核销单状态。
@@ -1,4 +1,4 @@
package com.bms.ar.enums;
package com.bms.receivable.enums;
/** 应收账单生成时用于截止日筛选的来源订单日期字段。 */
public enum ArBillDateType
@@ -1,4 +1,4 @@
package com.bms.ar.enums;
package com.bms.receivable.enums;
/** 应收账单异步生成任务状态。 */
public final class ArBillGenerateTaskStatus
@@ -1,4 +1,4 @@
package com.bms.ar.enums;
package com.bms.receivable.enums;
/** 应收账单生成状态,与账单业务状态分离。 */
public final class ArBillGenerationStatus
@@ -1,4 +1,4 @@
package com.bms.ar.enums;
package com.bms.receivable.enums;
/**
* 应收账单生成时的订单选择模式。
@@ -1,4 +1,4 @@
package com.bms.ar.enums;
package com.bms.receivable.enums;
/** 应收账单状态。数据库保存值使用 code,避免业务代码散落状态字符串。 */
public enum ArBillStatus
@@ -1,4 +1,4 @@
package com.bms.ar.enums;
package com.bms.receivable.enums;
/**
* 应收账单导出任务状态。
@@ -1,4 +1,4 @@
package com.bms.ar.enums;
package com.bms.receivable.enums;
/** 应收费用明细是否已经生成正式应收账单。 */
public enum ArIncomeBillFeeStatus
@@ -1,4 +1,4 @@
package com.bms.ar.enums;
package com.bms.receivable.enums;
/** 应收日志关联对象类型。 */
public enum ArLogObjectType
@@ -1,4 +1,4 @@
package com.bms.ar.enums;
package com.bms.receivable.enums;
/** 应收日志操作来源。 */
public enum ArLogOperationSource
@@ -1,4 +1,4 @@
package com.bms.ar.enums;
package com.bms.receivable.enums;
/** 应收日志操作类型。 */
public enum ArLogOperationType
@@ -1,4 +1,4 @@
package com.bms.ar.enums;
package com.bms.receivable.enums;
/** 应收操作日志结果。 */
public enum ArLogResult
@@ -1,4 +1,4 @@
package com.bms.ar.enums;
package com.bms.receivable.enums;
/** 计费订单的应收账单状态。 */
public enum ArOrderBillStatus
@@ -1,4 +1,4 @@
package com.bms.ar.event;
package com.bms.receivable.event;
/**
* 应收账单导出任务已提交事件。
@@ -1,4 +1,4 @@
package com.bms.ar.event;
package com.bms.receivable.event;
/**
* 应收账单异步生成任务已提交事件。
@@ -1,10 +1,10 @@
package com.bms.ar.mapper;
package com.bms.receivable.mapper;
import java.util.List;
import com.bms.ar.security.ArBillRowScope;
import com.bms.receivable.security.ArBillRowScope;
import org.apache.ibatis.annotations.Param;
import com.bms.ar.domain.ArBalanceWriteoff;
import com.bms.receivable.domain.ArBalanceWriteoff;
/**
* 应收账单余额核销 Mapper
@@ -1,9 +1,9 @@
package com.bms.ar.mapper;
package com.bms.receivable.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.bms.ar.domain.ArBankAccount;
import com.bms.receivable.domain.ArBankAccount;
public interface ArBankAccountMapper {
ArBankAccount selectDefaultByCurrency(@Param("currency") String currency);
@@ -1,10 +1,10 @@
package com.bms.ar.mapper;
package com.bms.receivable.mapper;
import java.util.List;
import com.bms.ar.security.ArBillRowScope;
import com.bms.receivable.security.ArBillRowScope;
import org.apache.ibatis.annotations.Param;
import com.bms.ar.domain.ArBillDetailFee;
import com.bms.receivable.domain.ArBillDetailFee;
public interface ArBillDetailFeeMapper {
List<ArBillDetailFee> selectByBillIdAndDetailIdScoped(@Param("arBillId") Long arBillId, @Param("detailId") Long detailId, @Param("scope") ArBillRowScope scope);
@@ -1,12 +1,12 @@
package com.bms.ar.mapper;
package com.bms.receivable.mapper;
import java.util.List;
import com.bms.ar.security.ArBillRowScope;
import com.bms.receivable.security.ArBillRowScope;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
import com.bms.ar.domain.ArBillDetail;
import com.bms.receivable.domain.ArBillDetail;
public interface ArBillDetailMapper {
List<ArBillDetail> selectByBillIdScoped(@Param("arBillId") Long arBillId, @Param("scope") ArBillRowScope scope);
@@ -1,10 +1,10 @@
package com.bms.ar.mapper;
package com.bms.receivable.mapper;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.bms.ar.domain.ArBillExport;
import com.bms.receivable.domain.ArBillExport;
public interface ArBillExportMapper {
List<ArBillExport> selectByBillId(Long arBillId);
@@ -1,17 +1,17 @@
package com.bms.ar.mapper;
package com.bms.receivable.mapper;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.bms.ar.domain.ArBillGenerateTask;
import com.bms.receivable.domain.ArBillGenerateTask;
/**
* 应收账单异步生成任务 Mapper。
*/
public interface ArBillGenerateTaskMapper {
List<ArBillGenerateTask> selectActiveByCreateByScoped(@Param("createBy") String createBy,
@Param("scope") com.bms.ar.security.ArBillRowScope scope);
@Param("scope") com.bms.receivable.security.ArBillRowScope scope);
ArBillGenerateTask selectById(Long taskId);
@@ -1,10 +1,10 @@
package com.bms.ar.mapper;
package com.bms.receivable.mapper;
import java.util.List;
import com.bms.ar.security.ArBillRowScope;
import com.bms.receivable.security.ArBillRowScope;
import org.apache.ibatis.annotations.Param;
import com.bms.ar.domain.ArBillLog;
import com.bms.receivable.domain.ArBillLog;
public interface ArBillLogMapper
{
@@ -1,14 +1,14 @@
package com.bms.ar.mapper;
package com.bms.receivable.mapper;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import com.bms.ar.security.ArBillRowScope;
import com.bms.receivable.security.ArBillRowScope;
import org.apache.ibatis.annotations.Param;
import com.bms.ar.domain.ArBill;
import com.bms.ar.domain.vo.ArBillQuery;
import com.bms.ar.domain.vo.ArBillSummary;
import com.bms.receivable.domain.ArBill;
import com.bms.receivable.domain.vo.ArBillQuery;
import com.bms.receivable.domain.vo.ArBillSummary;
public interface ArBillMapper {
List<ArBill> selectArBillList(@Param("query") ArBillQuery query, @Param("scope") ArBillRowScope scope);
@@ -36,6 +36,10 @@ public interface ArBillMapper {
int insertArBill(ArBill bill);
int updateProfitSnapshot(@Param("arBillId") Long arBillId,
@Param("shenzhenArea") String shenzhenArea,
@Param("guangzhouArea") String guangzhouArea);
int updateArBillStatus(@Param("arBillId") Long arBillId, @Param("status") String status,
@Param("remark") String remark, @Param("operator") String operator,
@Param("fromStatus") String fromStatus);
@@ -1,8 +1,8 @@
package com.bms.ar.mapper;
package com.bms.receivable.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.bms.ar.security.ArBillRowScope;
import com.bms.receivable.security.ArBillRowScope;
import com.bms.customer.customerinfo.domain.BmsCustomerOption;
public interface ArBillScopeMapper {
@@ -1,13 +1,13 @@
package com.bms.ar.mapper;
package com.bms.receivable.mapper;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.bms.ar.profit.ArCommissionRate;
import com.bms.ar.profit.ArWriteoffRate;
import com.bms.ar.profit.ArCommissionResult;
import com.bms.ar.profit.ArCommissionSummary;
import com.bms.ar.profit.ArProfitScope;
import com.bms.receivable.profit.ArCommissionRate;
import com.bms.receivable.profit.ArWriteoffRate;
import com.bms.receivable.profit.ArCommissionResult;
import com.bms.receivable.profit.ArCommissionSummary;
import com.bms.receivable.profit.ArProfitScope;
public interface ArCommissionMapper
{
@@ -1,9 +1,9 @@
package com.bms.ar.mapper;
package com.bms.receivable.mapper;
import java.util.Date;
import org.apache.ibatis.annotations.Param;
import com.bms.ar.domain.ArExportTemplate;
import com.bms.receivable.domain.ArExportTemplate;
public interface ArExportTemplateMapper {
/**
@@ -1,14 +1,14 @@
package com.bms.ar.mapper;
package com.bms.receivable.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.bms.ar.profit.ArProfitQuery;
import com.bms.ar.profit.ArProfitRow;
import com.bms.ar.profit.ArProfitScope;
import com.bms.ar.profit.ArProfitSummary;
import com.bms.ar.profit.ArProfitSalesOption;
import com.bms.ar.domain.ArBillDetailFee;
import com.bms.ar.domain.ArBillDetail;
import com.bms.receivable.profit.ArProfitQuery;
import com.bms.receivable.profit.ArProfitRow;
import com.bms.receivable.profit.ArProfitScope;
import com.bms.receivable.profit.ArProfitSummary;
import com.bms.receivable.profit.ArProfitSalesOption;
import com.bms.receivable.domain.ArBillDetailFee;
import com.bms.receivable.domain.ArBillDetail;
public interface ArProfitMapper
{
@@ -1,4 +1,4 @@
package com.bms.ar.profit;
package com.bms.receivable.profit;
import java.math.BigDecimal;
import java.util.Date;
@@ -1,4 +1,4 @@
package com.bms.ar.profit;
package com.bms.receivable.profit;
import java.math.BigDecimal;
import java.util.Date;
@@ -1,17 +1,17 @@
package com.bms.ar.profit;
package com.bms.receivable.profit;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.bms.ar.domain.ArBalanceWriteoff;
import com.bms.ar.domain.ArBill;
import com.bms.ar.mapper.ArCommissionMapper;
import com.bms.ar.mapper.ArBillMapper;
import com.bms.ar.enums.ArBillStatus;
import com.bms.ar.enums.ArBillGenerationStatus;
import com.bms.ar.security.ArBillRoleKeys;
import com.bms.receivable.domain.ArBalanceWriteoff;
import com.bms.receivable.domain.ArBill;
import com.bms.receivable.mapper.ArCommissionMapper;
import com.bms.receivable.mapper.ArBillMapper;
import com.bms.receivable.enums.ArBillStatus;
import com.bms.receivable.enums.ArBillGenerationStatus;
import com.bms.receivable.security.ArBillRoleKeys;
import com.bms.common.exception.ServiceException;
import com.bms.common.core.domain.entity.SysUser;
import com.bms.common.utils.SecurityUtils;
@@ -1,4 +1,4 @@
package com.bms.ar.profit;
package com.bms.receivable.profit;
import java.math.BigDecimal;
import lombok.Data;
@@ -1,4 +1,4 @@
package com.bms.ar.profit;
package com.bms.receivable.profit;
import java.util.Date;
import lombok.Data;
@@ -1,4 +1,4 @@
package com.bms.ar.profit;
package com.bms.receivable.profit;
import java.math.BigDecimal;
import java.util.Date;
@@ -1,4 +1,4 @@
package com.bms.ar.profit;
package com.bms.receivable.profit;
import lombok.Data;
@@ -1,4 +1,4 @@
package com.bms.ar.profit;
package com.bms.receivable.profit;
/** 后端构造的数据范围,不接收前端传入的权限参数。 */
public record ArProfitScope(boolean all, boolean self, boolean department, Long userId, Long deptId)
@@ -1,9 +1,9 @@
package com.bms.ar.profit;
package com.bms.receivable.profit;
import java.util.Arrays;
import java.util.Set;
import org.springframework.stereotype.Component;
import com.bms.ar.security.ArBillRoleKeys;
import com.bms.receivable.security.ArBillRoleKeys;
import com.bms.common.constant.Constants;
import com.bms.common.core.domain.entity.SysRole;
import com.bms.common.core.domain.entity.SysUser;
@@ -1,10 +1,10 @@
package com.bms.ar.profit;
package com.bms.receivable.profit;
import java.util.List;
import org.springframework.stereotype.Service;
import com.bms.ar.mapper.ArProfitMapper;
import com.bms.ar.domain.ArBillDetailFee;
import com.bms.ar.domain.ArBillDetail;
import com.bms.receivable.mapper.ArProfitMapper;
import com.bms.receivable.domain.ArBillDetailFee;
import com.bms.receivable.domain.ArBillDetail;
@Service
public class ArProfitService
@@ -1,4 +1,4 @@
package com.bms.ar.profit;
package com.bms.receivable.profit;
import java.math.BigDecimal;
import lombok.Data;
@@ -1,4 +1,4 @@
package com.bms.ar.profit;
package com.bms.receivable.profit;
import java.math.BigDecimal;
import java.util.Date;
@@ -1,4 +1,4 @@
package com.bms.ar.profit;
package com.bms.receivable.profit;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -1,4 +1,4 @@
package com.bms.ar.security;
package com.bms.receivable.security;
import java.util.Set;
@@ -1,4 +1,4 @@
package com.bms.ar.security;
package com.bms.receivable.security;
/** 仅由后端构造,不能绑定到 HTTP 查询对象。 */
public final class ArBillRowScope {
@@ -1,4 +1,4 @@
package com.bms.ar.security;
package com.bms.receivable.security;
import java.util.Arrays;
import java.util.List;
@@ -7,7 +7,7 @@ import java.util.function.Supplier;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Component;
import com.bms.ar.mapper.ArBillScopeMapper;
import com.bms.receivable.mapper.ArBillScopeMapper;
import com.bms.common.constant.Constants;
import com.bms.common.core.domain.entity.SysRole;
import com.bms.common.core.domain.entity.SysUser;
@@ -1,8 +1,8 @@
package com.bms.ar.service;
package com.bms.receivable.service;
import java.util.List;
import com.bms.ar.domain.ArBalanceWriteoff;
import com.bms.ar.domain.ArBill;
import com.bms.receivable.domain.ArBalanceWriteoff;
import com.bms.receivable.domain.ArBill;
/**
* 应收账单余额核销 Service接口
@@ -1,10 +1,10 @@
package com.bms.ar.service;
package com.bms.receivable.service;
import java.util.List;
import com.bms.ar.domain.ArBillLog;
import com.bms.ar.enums.ArLogObjectType;
import com.bms.ar.enums.ArLogOperationType;
import com.bms.receivable.domain.ArBillLog;
import com.bms.receivable.enums.ArLogObjectType;
import com.bms.receivable.enums.ArLogOperationType;
public interface IArBillLogService {
List<ArBillLog> selectLogList(ArBillLog query);
@@ -1,20 +1,20 @@
package com.bms.ar.service;
package com.bms.receivable.service;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import com.bms.ar.domain.ArBill;
import com.bms.ar.domain.ArBankAccount;
import com.bms.ar.domain.ArBillDetail;
import com.bms.ar.domain.ArBillDetailFee;
import com.bms.ar.domain.ArBillExport;
import com.bms.ar.domain.ArBillGenerateTask;
import com.bms.ar.domain.ArBillLog;
import com.bms.ar.domain.vo.ArBillGenerateRequest;
import com.bms.ar.domain.vo.ArBillGenerateQuery;
import com.bms.ar.domain.vo.ArBillActionRequest;
import com.bms.ar.domain.vo.ArBillQuery;
import com.bms.ar.domain.vo.ArBillSummary;
import com.bms.receivable.domain.ArBill;
import com.bms.receivable.domain.ArBankAccount;
import com.bms.receivable.domain.ArBillDetail;
import com.bms.receivable.domain.ArBillDetailFee;
import com.bms.receivable.domain.ArBillExport;
import com.bms.receivable.domain.ArBillGenerateTask;
import com.bms.receivable.domain.ArBillLog;
import com.bms.receivable.domain.vo.ArBillGenerateRequest;
import com.bms.receivable.domain.vo.ArBillGenerateQuery;
import com.bms.receivable.domain.vo.ArBillActionRequest;
import com.bms.receivable.domain.vo.ArBillQuery;
import com.bms.receivable.domain.vo.ArBillSummary;
import com.bms.price.domain.PrcOrderBill;
/**
@@ -1,4 +1,4 @@
package com.bms.ar.service.impl;
package com.bms.receivable.service.impl;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -12,21 +12,21 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import com.bms.ar.domain.ArBalanceWriteoff;
import com.bms.ar.domain.ArBill;
import com.bms.ar.domain.ArBillLog;
import com.bms.ar.enums.ArBalanceWriteoffStatus;
import com.bms.ar.enums.ArBillStatus;
import com.bms.ar.enums.ArLogObjectType;
import com.bms.ar.enums.ArLogOperationSource;
import com.bms.ar.enums.ArLogOperationType;
import com.bms.ar.enums.ArLogResult;
import com.bms.ar.mapper.ArBalanceWriteoffMapper;
import com.bms.ar.mapper.ArBillMapper;
import com.bms.ar.security.ArBillScopeResolver;
import com.bms.ar.profit.ArCommissionService;
import com.bms.ar.service.IArBalanceWriteoffService;
import com.bms.ar.service.IArBillLogService;
import com.bms.receivable.domain.ArBalanceWriteoff;
import com.bms.receivable.domain.ArBill;
import com.bms.receivable.domain.ArBillLog;
import com.bms.receivable.enums.ArBalanceWriteoffStatus;
import com.bms.receivable.enums.ArBillStatus;
import com.bms.receivable.enums.ArLogObjectType;
import com.bms.receivable.enums.ArLogOperationSource;
import com.bms.receivable.enums.ArLogOperationType;
import com.bms.receivable.enums.ArLogResult;
import com.bms.receivable.mapper.ArBalanceWriteoffMapper;
import com.bms.receivable.mapper.ArBillMapper;
import com.bms.receivable.security.ArBillScopeResolver;
import com.bms.receivable.profit.ArCommissionService;
import com.bms.receivable.service.IArBalanceWriteoffService;
import com.bms.receivable.service.IArBillLogService;
import com.bms.common.exception.ServiceException;
import com.bms.common.utils.SecurityUtils;
import com.bms.customer.customermoney.domain.CustomerReceipt;
@@ -1,4 +1,4 @@
package com.bms.ar.service.impl;
package com.bms.receivable.service.impl;
import java.util.List;
@@ -6,14 +6,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.bms.ar.domain.ArBillLog;
import com.bms.ar.enums.ArLogObjectType;
import com.bms.ar.enums.ArLogOperationSource;
import com.bms.ar.enums.ArLogOperationType;
import com.bms.ar.enums.ArLogResult;
import com.bms.ar.mapper.ArBillLogMapper;
import com.bms.ar.security.ArBillScopeResolver;
import com.bms.ar.service.IArBillLogService;
import com.bms.receivable.domain.ArBillLog;
import com.bms.receivable.enums.ArLogObjectType;
import com.bms.receivable.enums.ArLogOperationSource;
import com.bms.receivable.enums.ArLogOperationType;
import com.bms.receivable.enums.ArLogResult;
import com.bms.receivable.mapper.ArBillLogMapper;
import com.bms.receivable.security.ArBillScopeResolver;
import com.bms.receivable.service.IArBillLogService;
import com.bms.common.utils.uuid.IdUtils;
@Service
@@ -1,4 +1,4 @@
package com.bms.ar.service.impl;
package com.bms.receivable.service.impl;
import java.io.File;
import java.io.IOException;
@@ -44,49 +44,49 @@ import org.springframework.transaction.support.TransactionTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson2.JSON;
import com.bms.ar.domain.ArBill;
import com.bms.ar.domain.ArBankAccount;
import com.bms.ar.domain.ArBillDetail;
import com.bms.ar.domain.ArBillDetailFee;
import com.bms.ar.domain.ArBillExport;
import com.bms.ar.domain.ArBillGenerateTask;
import com.bms.ar.domain.ArBillLog;
import com.bms.ar.domain.ArExportTemplate;
import com.bms.ar.event.ArBillExportTaskEvent;
import com.bms.ar.event.ArBillGenerateTaskEvent;
import com.bms.ar.enums.ArBillGenerateTaskStatus;
import com.bms.ar.enums.ArBillDateType;
import com.bms.ar.enums.ArBillGenerationStatus;
import com.bms.ar.enums.ArBillSelectionMode;
import com.bms.ar.enums.ArBillStatus;
import com.bms.ar.enums.ArExportStatus;
import com.bms.ar.enums.ArIncomeBillFeeStatus;
import com.bms.ar.enums.ArLogObjectType;
import com.bms.ar.enums.ArLogOperationSource;
import com.bms.ar.enums.ArLogOperationType;
import com.bms.ar.enums.ArLogResult;
import com.bms.ar.enums.ArOrderBillStatus;
import com.bms.ar.mapper.ArBillDetailFeeMapper;
import com.bms.ar.mapper.ArBillDetailMapper;
import com.bms.ar.mapper.ArBillExportMapper;
import com.bms.ar.mapper.ArBillLogMapper;
import com.bms.ar.mapper.ArBillMapper;
import com.bms.ar.security.ArBillScopeResolver;
import com.bms.receivable.domain.ArBill;
import com.bms.receivable.domain.ArBankAccount;
import com.bms.receivable.domain.ArBillDetail;
import com.bms.receivable.domain.ArBillDetailFee;
import com.bms.receivable.domain.ArBillExport;
import com.bms.receivable.domain.ArBillGenerateTask;
import com.bms.receivable.domain.ArBillLog;
import com.bms.receivable.domain.ArExportTemplate;
import com.bms.receivable.event.ArBillExportTaskEvent;
import com.bms.receivable.event.ArBillGenerateTaskEvent;
import com.bms.receivable.enums.ArBillGenerateTaskStatus;
import com.bms.receivable.enums.ArBillDateType;
import com.bms.receivable.enums.ArBillGenerationStatus;
import com.bms.receivable.enums.ArBillSelectionMode;
import com.bms.receivable.enums.ArBillStatus;
import com.bms.receivable.enums.ArExportStatus;
import com.bms.receivable.enums.ArIncomeBillFeeStatus;
import com.bms.receivable.enums.ArLogObjectType;
import com.bms.receivable.enums.ArLogOperationSource;
import com.bms.receivable.enums.ArLogOperationType;
import com.bms.receivable.enums.ArLogResult;
import com.bms.receivable.enums.ArOrderBillStatus;
import com.bms.receivable.mapper.ArBillDetailFeeMapper;
import com.bms.receivable.mapper.ArBillDetailMapper;
import com.bms.receivable.mapper.ArBillExportMapper;
import com.bms.receivable.mapper.ArBillLogMapper;
import com.bms.receivable.mapper.ArBillMapper;
import com.bms.receivable.security.ArBillScopeResolver;
import com.bms.customer.customerinfo.domain.BmsCustomerOption;
import com.bms.customer.customerinfo.domain.BmsCustomer;
import com.bms.customer.customerinfo.mapper.BmsCustomerMapper;
import com.bms.common.core.domain.entity.SysUser;
import com.bms.system.mapper.SysUserMapper;
import com.bms.ar.mapper.ArBillGenerateTaskMapper;
import com.bms.ar.mapper.ArBankAccountMapper;
import com.bms.ar.mapper.ArExportTemplateMapper;
import com.bms.ar.service.IArBillLogService;
import com.bms.ar.service.IArBillService;
import com.bms.ar.domain.vo.ArBillActionRequest;
import com.bms.ar.domain.vo.ArBillGenerateQuery;
import com.bms.ar.domain.vo.ArBillGenerateRequest;
import com.bms.ar.domain.vo.ArBillQuery;
import com.bms.ar.domain.vo.ArBillSummary;
import com.bms.receivable.mapper.ArBillGenerateTaskMapper;
import com.bms.receivable.mapper.ArBankAccountMapper;
import com.bms.receivable.mapper.ArExportTemplateMapper;
import com.bms.receivable.service.IArBillLogService;
import com.bms.receivable.service.IArBillService;
import com.bms.receivable.domain.vo.ArBillActionRequest;
import com.bms.receivable.domain.vo.ArBillGenerateQuery;
import com.bms.receivable.domain.vo.ArBillGenerateRequest;
import com.bms.receivable.domain.vo.ArBillQuery;
import com.bms.receivable.domain.vo.ArBillSummary;
import com.bms.common.config.BmsConfig;
import com.bms.common.exception.ServiceException;
import com.bms.common.utils.DateUtils;
@@ -116,7 +116,7 @@ public class ArBillServiceImpl implements IArBillService {
private static final Logger log = LoggerFactory.getLogger(ArBillServiceImpl.class);
private static final String EXPORT_TEMPLATE_BUSINESS_TYPE = "AR_BILL";
private static final String EXPORT_TEMPLATE_RESOURCE = "templates/ar/ar_bill_template.xlsx";
private static final String EXPORT_TEMPLATE_RESOURCE = "templates/receivable/ar_bill_template.xlsx";
/**
* Excel 行号从 1 开始;模板第 4 行是表头,明细从第 5 行开始写入。
*/
@@ -935,6 +935,12 @@ public class ArBillServiceImpl implements IArBillService {
throw new ServiceException("账单生成结果为空或订单数量发生变化,请重新生成");
}
ArBill finalBill = billMapper.selectArBillById(task.getArBillId());
// 明细与费用已全部落库;快照和 READY 状态必须在同一事务中提交。
if (billMapper.updateProfitSnapshot(task.getArBillId(),
com.bms.price.enums.ProfitAreaRule.SHENZHEN.getCustomerArea(),
com.bms.price.enums.ProfitAreaRule.GUANGZHOU.getCustomerArea()) != 1) {
throw new ServiceException("账单毛利快照更新失败,请重新生成");
}
billMapper.updateArBillGenerationStatus(task.getArBillId(),
ArBillGenerationStatus.READY, task.getCreateBy(), null);
if (generateTaskMapper.markSuccess(taskId, new Date()) != 1) {
@@ -1748,6 +1754,7 @@ public class ArBillServiceImpl implements IArBillService {
}
return switch (status) {
case SUCCESS -> "";
case NOT_BILLED -> "未计费";
case PRODUCT -> "销售价未匹配产品";
case COUNTRY -> "销售价未匹配国家";
case WEIGHT -> "销售价未匹配重量段";
@@ -1,4 +1,4 @@
package com.bms.ar.task;
package com.bms.receivable.task;
import java.util.Date;
@@ -12,8 +12,8 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;
import com.bms.ar.event.ArBillExportTaskEvent;
import com.bms.ar.service.IArBillService;
import com.bms.receivable.event.ArBillExportTaskEvent;
import com.bms.receivable.service.IArBillService;
/**
* 应收账单导出异步任务执行器。
@@ -1,4 +1,4 @@
package com.bms.ar.task;
package com.bms.receivable.task;
import java.util.Date;
@@ -12,9 +12,9 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;
import com.bms.ar.domain.ArBillGenerateTask;
import com.bms.ar.event.ArBillGenerateTaskEvent;
import com.bms.ar.service.IArBillService;
import com.bms.receivable.domain.ArBillGenerateTask;
import com.bms.receivable.event.ArBillGenerateTaskEvent;
import com.bms.receivable.service.IArBillService;
/**
* 应收账单异步生成任务调度器。
@@ -6,37 +6,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectByChannelAndType" resultType="com.bms.price.domain.ChannelProductMap">
select id, channel_id as channelId, channel_code as channelCode, product_id as productId,
price_set_id as priceSetId, pay_type as payType, create_by as createBy, create_time as createTime,
pay_type as payType, create_by as createBy, create_time as createTime,
update_by as updateBy, update_time as updateTime
from srv_channel_product_map
where channel_id = #{channelId} and pay_type = #{payType}
limit 1
</select>
<select id="selectByPriceSetId" resultType="com.bms.price.domain.ChannelProductMap">
select m.id, m.channel_id as channelId, m.channel_code as channelCode, m.product_id as productId,
m.price_set_id as priceSetId, m.pay_type as payType,
c.channel_name as channelName, p.product_name as productName,
m.create_by as createBy, m.create_time as createTime,
m.update_by as updateBy, m.update_time as updateTime
from srv_channel_product_map m
left join srv_service_channel c on c.id = m.channel_id
left join pay_product p on p.product_id = m.product_id
where m.price_set_id = #{priceSetId}
and m.pay_type = 'AR'
order by m.update_time desc, m.id desc
</select>
<insert id="upsert">
insert into srv_channel_product_map (
channel_id, channel_code, product_id, price_set_id, pay_type, create_by, create_time, update_by, update_time
channel_id, channel_code, product_id, pay_type, create_by, create_time, update_by, update_time
) values (
#{channelId}, #{channelCode}, #{productId}, #{priceSetId}, #{payType}, #{createBy}, sysdate(), #{updateBy}, sysdate()
#{channelId}, #{channelCode}, #{productId}, #{payType}, #{createBy}, sysdate(), #{updateBy}, sysdate()
)
on duplicate key update
channel_code = values(channel_code),
product_id = values(product_id),
price_set_id = values(price_set_id),
update_by = values(update_by),
update_time = sysdate()
</insert>
@@ -46,13 +32,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where channel_id = #{channelId} and pay_type = #{payType}
</delete>
<delete id="deleteByChannelTypeAndPriceSet">
delete from srv_channel_product_map
where channel_id = #{channelId}
and pay_type = #{payType}
and price_set_id = #{priceSetId}
</delete>
<delete id="deleteByProductId">
delete from srv_channel_product_map where product_id = #{productId}
</delete>
@@ -41,15 +41,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
limit 1
</select>
<select id="selectLabelPriceSetIdByProduct" resultType="long">
select price_set_id
from pay_product_term
where product_id = #{productId}
and price_set_id is not null
order by case when status = '1' then 0 when status = '0' then 1 else 2 end, version_no desc, term_id desc
limit 1
</select>
<!-- 打单套餐产品列表:待生效+生效 -->
<select id="selectByPriceSetId" resultType="com.bms.price.domain.PayProductTerm">
select t.term_id as termId, t.dict_value as dictValue, t.product_id as productId, t.price_set_id as priceSetId,
@@ -2,7 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.ar.mapper.ArBalanceWriteoffMapper">
<mapper namespace="com.bms.receivable.mapper.ArBalanceWriteoffMapper">
<resultMap id="ArBalanceWriteoffResult" type="ArBalanceWriteoff">
<id property="writeoffId" column="writeoff_id"/>
@@ -93,7 +93,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="query.params != null and query.params.endTime != null and query.params.endTime != ''">
and date_format(w.writeoff_date,'%y%m%d') &lt;= date_format(#{query.params.endTime},'%y%m%d')
</if>
<include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>
<include refid="com.bms.receivable.mapper.ArBillScopeMapper.billScope"/>
</where>
order by w.create_time desc, w.writeoff_id desc
</select>
@@ -2,7 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.ar.mapper.ArBankAccountMapper">
<mapper namespace="com.bms.receivable.mapper.ArBankAccountMapper">
<resultMap id="ArBankAccountResult" type="ArBankAccount">
<id property="bankAccountId" column="bank_account_id"/>
<result property="accountName" column="account_name"/>
@@ -2,7 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.ar.mapper.ArBillDetailFeeMapper">
<mapper namespace="com.bms.receivable.mapper.ArBillDetailFeeMapper">
<!-- 账单明细费用项读写;批量查询仅接收当前明细批次的 ID。 -->
<resultMap id="ArBillDetailFeeResult" type="ArBillDetailFee">
<id property="detailFeeId" column="detail_fee_id"/>
@@ -102,7 +102,7 @@
inner join ar_bill_detail d on d.detail_id = f.detail_id
where d.ar_bill_id = #{arBillId}
and f.detail_id = #{detailId}
AND EXISTS (SELECT 1 FROM ar_bill b WHERE b.ar_bill_id = d.ar_bill_id <include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>)
AND EXISTS (SELECT 1 FROM ar_bill b WHERE b.ar_bill_id = d.ar_bill_id <include refid="com.bms.receivable.mapper.ArBillScopeMapper.billScope"/>)
order by f.fee_no, f.detail_fee_id
</select>
@@ -2,7 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.ar.mapper.ArBillDetailMapper">
<mapper namespace="com.bms.receivable.mapper.ArBillDetailMapper">
<!-- 账单明细读写;详情页分页查询,导出任务按游标批量查询。 -->
<resultMap id="ArBillDetailResult" type="ArBillDetail">
<id property="detailId" column="detail_id"/>
@@ -51,7 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
product_code, product_name, goods_description, country_code, country_name, dest_postcode,
actual_weight, receive_weight, volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height,
currency, total_amount, product_amount, redline_amount, billing_fail_status, remark, create_by, create_time
from ar_bill_detail where ar_bill_id = #{arBillId} AND EXISTS (SELECT 1 FROM ar_bill b WHERE b.ar_bill_id = ar_bill_detail.ar_bill_id <include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>)
from ar_bill_detail where ar_bill_id = #{arBillId} AND EXISTS (SELECT 1 FROM ar_bill b WHERE b.ar_bill_id = ar_bill_detail.ar_bill_id <include refid="com.bms.receivable.mapper.ArBillScopeMapper.billScope"/>)
order by detail_no
</select>
@@ -2,7 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.ar.mapper.ArBillExportMapper">
<mapper namespace="com.bms.receivable.mapper.ArBillExportMapper">
<!-- 导出任务和历史记录;PROCESSING/SUCCESS/FAILED 由异步执行器更新。 -->
<resultMap id="ArBillExportResult" type="ArBillExport">
<id property="exportId" column="export_id"/>
@@ -2,7 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.ar.mapper.ArBillGenerateTaskMapper">
<mapper namespace="com.bms.receivable.mapper.ArBillGenerateTaskMapper">
<!-- 生成任务表是异步任务的持久化队列;状态更新均带前置状态条件,保证多节点抢占幂等。 -->
<resultMap id="ArBillGenerateTaskResult" type="ArBillGenerateTask">
<id property="taskId" column="task_id"/>
@@ -74,7 +74,7 @@
where create_by = #{createBy}
and status in ('WAITING', 'RUNNING', 'CANCEL_REQUESTED')
AND EXISTS (SELECT 1 FROM ar_bill b WHERE b.ar_bill_id = ar_bill_generate_task.ar_bill_id
<include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>)
<include refid="com.bms.receivable.mapper.ArBillScopeMapper.billScope"/>)
order by create_time desc, task_id desc
</select>
@@ -2,7 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.ar.mapper.ArBillLogMapper">
<mapper namespace="com.bms.receivable.mapper.ArBillLogMapper">
<resultMap id="ArBillLogResult" type="ArBillLog">
<id property="logId" column="log_id"/>
<result property="arBillId" column="ar_bill_id"/>
@@ -51,7 +51,7 @@
</if>
<if test="query.requestId != null and query.requestId != ''">and l.request_id = #{query.requestId}</if>
<if test="query.result != null and query.result != ''">and l.result = #{query.result}</if>
<include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>
<include refid="com.bms.receivable.mapper.ArBillScopeMapper.billScope"/>
</where>
order by l.create_time desc, l.log_id desc
</select>
@@ -2,7 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.ar.mapper.ArBillMapper">
<mapper namespace="com.bms.receivable.mapper.ArBillMapper">
<!-- 账单头查询、状态流转和金额/生成进度更新。带 ForUpdate 的查询用于核销并发控制。 -->
<resultMap id="ArBillResult" type="ArBill">
<id property="arBillId" column="ar_bill_id"/>
@@ -39,7 +39,7 @@
<result property="updateTime" column="update_time"/>
</resultMap>
<resultMap id="ArBillSummaryResult" type="com.bms.ar.domain.vo.ArBillSummary">
<resultMap id="ArBillSummaryResult" type="com.bms.receivable.domain.vo.ArBillSummary">
<result property="totalAmount" column="total_amount"/>
<result property="writtenOffAmount" column="written_off_amount"/>
<result property="unwrittenAmount" column="unwritten_amount"/>
@@ -106,7 +106,7 @@
<if test="query.billDateStart != null">and bill_date &gt;= #{query.billDateStart}</if>
<if test="query.billDateEnd != null">and bill_date &lt;= #{query.billDateEnd}</if>
<if test="query.billPeriodEnd != null">and bill_period_end = #{query.billPeriodEnd}</if>
<include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>
<include refid="com.bms.receivable.mapper.ArBillScopeMapper.billScope"/>
</where>
</sql>
@@ -132,7 +132,7 @@
<select id="selectArBillByIdScoped" resultMap="ArBillResult">
select b.* from ar_bill b where b.ar_bill_id = #{arBillId}
<include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>
<include refid="com.bms.receivable.mapper.ArBillScopeMapper.billScope"/>
</select>
<select id="selectArBillByBillNo" parameterType="string" resultMap="ArBillResult">
@@ -172,7 +172,7 @@
and status in ('CONFIRMED', 'PARTIAL_WRITTEN_OFF')
and (generation_status is null or generation_status = 'READY')
and unwritten_amount &gt; 0
<include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>
<include refid="com.bms.receivable.mapper.ArBillScopeMapper.billScope"/>
order by bill_date asc, ar_bill_id asc
</select>
@@ -193,6 +193,49 @@
#{confirmedBy}, #{confirmedTime}, #{createBy}, #{createUserId}, sysdate(), #{updateBy}, sysdate())
</insert>
<!-- 只在生成完成时汇总当前账单;历史回填使用相同的校验口径。 -->
<update id="updateProfitSnapshot">
update ar_bill b
left join (
select d.ar_bill_id, count(*) as detail_count, sum(d.total_amount) as detail_total,
count(distinct d.currency) as detail_currency_count, min(d.currency) as detail_currency,
sum(case when d.currency is not null and f.currency_count = 1 and f.fee_currency = d.currency
then 0 else 1 end) as currency_errors,
sum(case when d.total_amount is not null and f.sales_amount is not null
and f.sales_amount = d.total_amount then 0 else 1 end) as amount_errors,
case when count(f.product_amount) = count(*) then sum(f.product_amount) else null end as product_total,
case when count(f.redline_amount) = count(*) then sum(f.redline_amount) else null end as redline_total
from ar_bill_detail d
left join (
select fee.detail_id,
case when count(fee.amount) = count(*) then sum(fee.amount) else null end as sales_amount,
case when count(fee.currency) = count(*) then count(distinct fee.currency) else 0 end as currency_count,
min(fee.currency) as fee_currency,
case when count(fee.product_amount) = count(*) then sum(fee.product_amount) else null end as product_amount,
case when count(fee.redline_amount) = count(*) then sum(fee.redline_amount) else null end as redline_amount
from ar_bill_detail_fee fee
join ar_bill_detail fd on fd.detail_id = fee.detail_id
where fd.ar_bill_id = #{arBillId}
group by fee.detail_id
) f on f.detail_id = d.detail_id
where d.ar_bill_id = #{arBillId}
group by d.ar_bill_id
) a on a.ar_bill_id = b.ar_bill_id
set b.product_amount = case when abs(a.product_total) &lt;= 99999999999999.9999 then a.product_total else null end,
b.redline_amount = case when abs(a.redline_total) &lt;= 99999999999999.9999 then a.redline_total else null end,
b.profit_calc_status = case
when a.detail_count is null or a.detail_count = 0 then 'NO_DETAIL'
when b.profit_customer_area is null or b.profit_customer_area not in (#{shenzhenArea}, #{guangzhouArea}) then 'MISSING_AREA'
when b.currency is null or a.currency_errors > 0 or a.detail_currency_count != 1 or a.detail_currency != b.currency then 'CURRENCY_MISMATCH'
when b.total_amount is null or a.amount_errors > 0 or a.detail_total != b.total_amount then 'AMOUNT_MISMATCH'
when (b.profit_customer_area = #{shenzhenArea} and a.product_total is null)
or (b.profit_customer_area = #{guangzhouArea} and a.redline_total is null) then 'MISSING_PRICE'
when (b.profit_customer_area = #{shenzhenArea} and abs(a.product_total) > 99999999999999.9999)
or (b.profit_customer_area = #{guangzhouArea} and abs(a.redline_total) > 99999999999999.9999) then 'PRICE_OVERFLOW'
else 'READY' end
where b.ar_bill_id = #{arBillId} and b.generation_status = 'GENERATING'
</update>
<update id="updateArBillStatus">
update ar_bill
set status = #{status},
@@ -1,6 +1,6 @@
<?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.ar.mapper.ArBillScopeMapper">
<mapper namespace="com.bms.receivable.mapper.ArBillScopeMapper">
<resultMap id="CustomerOption" type="com.bms.customer.customerinfo.domain.BmsCustomerOption">
<id property="customerId" column="customer_id"/>
<result property="customerCode" column="customer_code"/>
@@ -35,7 +35,7 @@
<when test="scope != null and scope.all"/>
<otherwise>
AND EXISTS (SELECT 1 FROM ctr_customer c WHERE c.customer_id = b.customer_id
<include refid="com.bms.ar.mapper.ArBillScopeMapper.customerScope"/>
<include refid="com.bms.receivable.mapper.ArBillScopeMapper.customerScope"/>
)
</otherwise>
</choose>
@@ -1,13 +1,13 @@
<?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.ar.mapper.ArCommissionMapper">
<resultMap id="rate" type="com.bms.ar.profit.ArCommissionRate">
<mapper namespace="com.bms.receivable.mapper.ArCommissionMapper">
<resultMap id="rate" type="com.bms.receivable.profit.ArCommissionRate">
<id property="rateId" column="rate_id"/><result property="salesUserId" column="sales_user_id"/>
<result property="salesUserCode" column="sales_user_code"/><result property="salesUserName" column="sales_user_name"/>
<result property="rate" column="rate"/><result property="effectiveAt" column="effective_at"/>
<result property="createBy" column="create_by"/><result property="remark" column="remark"/>
</resultMap>
<resultMap id="missingRate" type="com.bms.ar.profit.ArWriteoffRate">
<resultMap id="missingRate" type="com.bms.receivable.profit.ArWriteoffRate">
<id property="writeoffId" column="writeoff_id"/><result property="arBillId" column="ar_bill_id"/>
<result property="billNo" column="bill_no"/><result property="customerName" column="customer_name"/>
<result property="salesUserId" column="sales_user_id"/><result property="salesUserName" column="sales_user_name"/>
@@ -16,7 +16,7 @@
<result property="status" column="status"/><result property="confirmedBy" column="confirmed_by"/>
<result property="confirmedTime" column="confirmed_time"/><result property="remark" column="confirm_remark"/>
</resultMap>
<resultMap id="commissionResult" type="com.bms.ar.profit.ArCommissionResult">
<resultMap id="commissionResult" type="com.bms.receivable.profit.ArCommissionResult">
<id property="resultId" column="result_id"/><result property="arBillId" column="ar_bill_id"/>
<result property="detailId" column="detail_id"/><result property="billNo" column="bill_no"/>
<result property="orderNo" column="order_no"/><result property="salesUserName" column="sales_user_name"/>
@@ -27,7 +27,7 @@
<result property="salesUserId" column="sales_user_id"/><result property="weightedRate" column="weighted_rate"/>
<result property="billAmount" column="bill_amount"/>
</resultMap>
<resultMap id="commissionSummary" type="com.bms.ar.profit.ArCommissionSummary">
<resultMap id="commissionSummary" type="com.bms.receivable.profit.ArCommissionSummary">
<result property="salesUserId" column="sales_user_id"/><result property="salesUserName" column="sales_user_name"/>
<result property="currency" column="currency"/><result property="orderCount" column="order_count"/>
<result property="pendingCount" column="pending_count"/><result property="commissionAmount" column="commission_amount"/>
@@ -44,7 +44,7 @@
where sales_user_id = #{salesUserId} and effective_at &lt;= #{at}
order by effective_at desc, rate_id desc limit 1 for update
</select>
<insert id="insertRate" parameterType="com.bms.ar.profit.ArCommissionRate" useGeneratedKeys="true" keyProperty="rateId">
<insert id="insertRate" parameterType="com.bms.receivable.profit.ArCommissionRate" useGeneratedKeys="true" keyProperty="rateId">
insert into ar_profit_commission_rate(sales_user_id, rate, effective_at, create_by, create_time, remark)
values(#{salesUserId}, #{rate}, #{effectiveAt}, #{createBy}, sysdate(), #{remark})
</insert>
@@ -104,7 +104,7 @@
<otherwise>and r.result_status != 'REVERSED' and b.status = 'WRITTEN_OFF' and b.generation_status = 'READY'</otherwise>
</choose>
<if test="billId != null">and r.ar_bill_id = #{billId}</if>
<include refid="com.bms.ar.mapper.ArProfitMapper.scopeCondition"/>
<include refid="com.bms.receivable.mapper.ArProfitMapper.scopeCondition"/>
order by r.result_id desc
</select>
<select id="selectCommissionSummary" resultMap="commissionSummary">
@@ -121,7 +121,7 @@
from ar_profit_commission_result r join ar_bill b on b.ar_bill_id = r.ar_bill_id
where r.result_status != 'REVERSED' and b.status = 'WRITTEN_OFF' and b.generation_status = 'READY'
<if test="billId != null">and r.ar_bill_id = #{billId}</if>
<include refid="com.bms.ar.mapper.ArProfitMapper.scopeCondition"/>
<include refid="com.bms.receivable.mapper.ArProfitMapper.scopeCondition"/>
group by r.sales_user_id, r.currency
order by sales_user_name, r.currency
</select>
@@ -2,7 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.ar.mapper.ArExportTemplateMapper">
<mapper namespace="com.bms.receivable.mapper.ArExportTemplateMapper">
<!-- 模板管理查询;导出提交时会把选中的模板版本快照到导出任务。 -->
<resultMap id="ArExportTemplateResult" type="ArExportTemplate">
<id property="templateId" column="template_id"/>
@@ -1,7 +1,7 @@
<?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.ar.mapper.ArProfitMapper">
<resultMap id="row" type="com.bms.ar.profit.ArProfitRow">
<mapper namespace="com.bms.receivable.mapper.ArProfitMapper">
<resultMap id="row" type="com.bms.receivable.profit.ArProfitRow">
<id property="arBillId" column="ar_bill_id"/>
<result property="billNo" column="bill_no"/><result property="billName" column="bill_name"/>
<result property="billDate" column="bill_date"/>
@@ -13,19 +13,19 @@
<result property="salesGrossMarginRate" column="sales_gross_margin_rate"/>
<result property="writtenOffAmount" column="written_off_amount"/><result property="unwrittenAmount" column="unwritten_amount"/>
</resultMap>
<resultMap id="summary" type="com.bms.ar.profit.ArProfitSummary">
<resultMap id="summary" type="com.bms.receivable.profit.ArProfitSummary">
<result property="currency" column="currency"/><result property="billCount" column="bill_count"/>
<result property="salesAmount" column="sales_amount"/><result property="productAmount" column="product_amount"/>
<result property="salesGrossProfit" column="sales_gross_profit"/><result property="salesGrossMarginRate" column="sales_gross_margin_rate"/>
<result property="commissionAmount" column="commission_amount"/>
<result property="writtenOffAmount" column="written_off_amount"/><result property="unwrittenAmount" column="unwritten_amount"/>
</resultMap>
<resultMap id="detail" type="com.bms.ar.domain.ArBillDetail">
<resultMap id="detail" type="com.bms.receivable.domain.ArBillDetail">
<id property="detailId" column="detail_id"/><result property="orderNo" column="order_no"/>
<result property="productName" column="product_name"/><result property="currency" column="currency"/>
<result property="totalAmount" column="total_amount"/>
</resultMap>
<resultMap id="fee" type="com.bms.ar.domain.ArBillDetailFee">
<resultMap id="fee" type="com.bms.receivable.domain.ArBillDetailFee">
<id property="detailFeeId" column="detail_fee_id"/><result property="detailId" column="detail_id"/>
<result property="feeName" column="fee_name"/><result property="feeType" column="fee_type"/>
<result property="amount" column="amount"/><result property="productAmount" column="product_amount"/>
@@ -60,7 +60,16 @@
<if test="query.endBillDate != null">and b.bill_date &lt;= #{query.endBillDate}</if>
</sql>
<!-- 按费用快照先聚合到订单,再聚合到完整账单,避免账单金额及费用重复。 -->
<!-- 报表直接读取账单快照。 -->
<sql id="validProfitSnapshot">
b.profit_calc_status = 'READY' and b.total_amount is not null
and ((b.profit_customer_area = #{shenzhenArea} and b.product_amount is not null)
or (b.profit_customer_area = #{guangzhouArea} and b.redline_amount is not null))
</sql>
<sql id="areaProductAmount">
case when b.profit_customer_area = #{shenzhenArea} then b.product_amount
when b.profit_customer_area = #{guangzhouArea} then b.redline_amount else null end
</sql>
<sql id="billRows">
<bind name="shenzhenArea" value="@com.bms.price.enums.ProfitAreaRule@SHENZHEN.getCustomerArea()"/>
<bind name="guangzhouArea" value="@com.bms.price.enums.ProfitAreaRule@GUANGZHOU.getCustomerArea()"/>
@@ -68,45 +77,12 @@
b.profit_customer_area as customer_area,
b.profit_sales_user_name as sales_user_name, b.currency, b.status,
b.total_amount as sales_amount, b.written_off_amount, b.unwritten_amount,
case when a.detail_count > 0 and a.invalid_count = 0 and b.total_amount is not null
and a.detail_total = b.total_amount then a.product_total else null end as product_amount,
case when a.detail_count > 0 and a.invalid_count = 0 and b.total_amount is not null
and a.detail_total = b.total_amount then b.total_amount - a.product_total else null end as sales_gross_profit,
case when a.detail_count > 0 and a.invalid_count = 0 and b.total_amount is not null
and a.detail_total = b.total_amount and b.total_amount != 0
then round((b.total_amount - a.product_total) * 100 / b.total_amount, 4) else null end as sales_gross_margin_rate,
case when a.detail_count > 0 and a.invalid_count = 0 and b.total_amount is not null
and a.detail_total = b.total_amount then 0 else 1 end as profit_incomplete
case when <include refid="validProfitSnapshot"/> then <include refid="areaProductAmount"/> else null end as product_amount,
case when <include refid="validProfitSnapshot"/> then b.total_amount - (<include refid="areaProductAmount"/>) else null end as sales_gross_profit,
case when <include refid="validProfitSnapshot"/> and b.total_amount != 0
then round((b.total_amount - (<include refid="areaProductAmount"/>)) * 100 / b.total_amount, 4) else null end as sales_gross_margin_rate,
case when <include refid="validProfitSnapshot"/> then 0 else 1 end as profit_incomplete
from ar_bill b
left join (
select d.ar_bill_id, count(*) as detail_count, sum(d.total_amount) as detail_total,
sum(case when d.total_amount is not null and d.currency is not null and b.currency is not null
and d.currency = b.currency and f.currency_count = 1 and f.fee_currency = d.currency
and f.sales_amount is not null and f.sales_amount = d.total_amount
and ((b.profit_customer_area = #{shenzhenArea} and f.product_complete = 1)
or (b.profit_customer_area = #{guangzhouArea} and f.redline_complete = 1))
then 0 else 1 end) as invalid_count,
sum(case when b.profit_customer_area = #{shenzhenArea} then f.product_amount
when b.profit_customer_area = #{guangzhouArea} then f.redline_amount else null end) as product_total
from ar_bill_detail d join ar_bill b on b.ar_bill_id = d.ar_bill_id
left join (
select fee.detail_id,
case when count(fee.amount) = count(*) then sum(fee.amount) else null end as sales_amount,
case when count(fee.currency) = count(*) then count(distinct fee.currency) else 0 end as currency_count,
min(fee.currency) as fee_currency,
case when count(fee.product_amount) = count(*) then sum(fee.product_amount) else null end as product_amount,
case when count(fee.redline_amount) = count(*) then sum(fee.redline_amount) else null end as redline_amount,
case when count(fee.product_amount) = count(*) then 1 else 0 end as product_complete,
case when count(fee.redline_amount) = count(*) then 1 else 0 end as redline_complete
from ar_bill_detail_fee fee
join ar_bill_detail d on d.detail_id = fee.detail_id
join ar_bill b on b.ar_bill_id = d.ar_bill_id
<include refid="billConditions"/>
group by fee.detail_id
) f on f.detail_id = d.detail_id
<include refid="billConditions"/>
group by d.ar_bill_id
) a on a.ar_bill_id = b.ar_bill_id
<include refid="billConditions"/>
</sql>
<select id="selectBills" resultMap="row">
@@ -133,7 +109,7 @@
) commission on commission.currency = t.currency
group by t.currency order by t.currency
</select>
<select id="selectSalesOptions" resultType="com.bms.ar.profit.ArProfitSalesOption">
<select id="selectSalesOptions" resultType="com.bms.receivable.profit.ArProfitSalesOption">
select u.user_id as userId, u.nick_name as name, u.user_name as code
from sys_user u
where u.del_flag = '0' and u.status = '0'