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
@@ -13,13 +13,13 @@ import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bms.ar.domain.ArBill;
import com.bms.ar.domain.ArBalanceWriteoff;
import com.bms.ar.domain.vo.ArBillListExportRow;
import com.bms.ar.domain.vo.ArBillQuery;
import com.bms.ar.domain.vo.ArBillSummary;
import com.bms.ar.service.IArBalanceWriteoffService;
import com.bms.ar.service.IArBillService;
import com.bms.receivable.domain.ArBill;
import com.bms.receivable.domain.ArBalanceWriteoff;
import com.bms.receivable.domain.vo.ArBillListExportRow;
import com.bms.receivable.domain.vo.ArBillQuery;
import com.bms.receivable.domain.vo.ArBillSummary;
import com.bms.receivable.service.IArBalanceWriteoffService;
import com.bms.receivable.service.IArBillService;
import com.bms.common.annotation.Log;
import com.bms.common.core.controller.BaseController;
import com.bms.common.core.domain.AjaxResult;
@@ -152,8 +152,8 @@ public class BillingController extends BaseController
{
query = new PrcOrderBill();
}
// Billing list only shows success and the three soft misses.
query.setBillingFailStatuses(limitBillingListFailStatus(query.getBillingFailStatuses()));
// Billing list only shows successfully billed orders.
query.setBillingFailStatuses(limitBillingListFailStatus());
query.setBillingFailStatus(null);
startPage();
List<PrcOrderBill> list = prcOrderBillService.selectBillList(query);
@@ -161,7 +161,7 @@ public class BillingController extends BaseController
}
/**
* Async export billing list by current filters (status limited to 0-3).
* Async export billing list by current filters (status limited to success=0).
* Requires at least one meaningful filter. Poll task then download.
*/
@PreAuthorize("@ss.hasPermi('price:billing:export')")
@@ -178,7 +178,7 @@ public class BillingController extends BaseController
{
return error(MessageUtils.message("price.bill.export.filterRequired"));
}
query.setBillingFailStatuses(limitBillingListFailStatus(query.getBillingFailStatuses()));
query.setBillingFailStatuses(limitBillingListFailStatus());
query.setBillingFailStatus(null);
return successTask(prcOrderBillService.submitOrderBillExport(
PrcOrderBillExportTask.TYPE_BILLING, query));
@@ -204,32 +204,13 @@ public class BillingController extends BaseController
prcOrderBillService.downloadOrderBillExport(taskId, response);
}
private static List<Integer> limitBillingListFailStatus(List<Integer> requested)
private static List<Integer> limitBillingListFailStatus()
{
// Soft-fail list: success + sales 1/2/3 + product-catalog 23/24/25
List<Integer> allowed = Arrays.asList(
Integer.valueOf(0), Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3),
Integer.valueOf(23), Integer.valueOf(24), Integer.valueOf(25));
if (requested == null || requested.isEmpty())
{
return new ArrayList<Integer>(allowed);
}
List<Integer> kept = new ArrayList<Integer>();
for (Integer status : requested)
{
if (status != null && allowed.contains(status) && !kept.contains(status))
{
kept.add(status);
}
}
if (kept.isEmpty())
{
kept.add(Integer.valueOf(-1));
}
return kept;
// Billing list is success-only (billing_fail_status = 0).
return new ArrayList<Integer>(Arrays.asList(Integer.valueOf(0)));
}
/** All prc_order_bill rows. Billing list stays limited to status 0-3. */
/** All prc_order_bill rows. Billing list stays limited to status 0. */
@PreAuthorize("@ss.hasPermi('price:orderBill:list')")
@GetMapping("/orderBill/list")
public TableDataInfo orderBillList(PrcOrderBill query)
@@ -239,6 +220,15 @@ public class BillingController extends BaseController
return getDataTable(list);
}
/** Order-list popup: billing fail reason by billId (data-scoped). */
@PreAuthorize("@ss.hasPermi('price:orderBill:list')")
@GetMapping("/orderBill/{billId}/failReason")
public AjaxResult orderBillFailReason(@PathVariable("billId") String billId)
{
return success(prcOrderBillService.getBillingFailReason(billId));
}
/**
* Async export order list by current filters.
* Requires at least one meaningful filter (default orderStatuses alone is not enough).
@@ -217,54 +217,6 @@ public class LabelPackageController extends BaseController
return toAjax(payProductService.removeLabelProducts(priceSetId, productIds));
}
@PreAuthorize("@ss.hasPermi('price:label:query')")
@GetMapping("/{priceSetId}/channels")
public AjaxResult listChannels(@PathVariable Long priceSetId)
{
priceSetService.assertSetCategory(priceSetId, PrcPriceSet.CATEGORY_LABEL);
return success(payProductService.listLabelChannels(priceSetId));
}
@PreAuthorize("@ss.hasPermi('price:label:edit')")
@Log(title = "打单套餐绑定渠道", businessType = BusinessType.UPDATE)
@PutMapping("/{priceSetId}/channels")
public AjaxResult bindChannels(@PathVariable Long priceSetId, @RequestBody Map<String, Object> body)
{
priceSetService.assertSetCategory(priceSetId, PrcPriceSet.CATEGORY_LABEL);
List<String> channelIds = new ArrayList<String>();
Object rawIds = body == null ? null : body.get("channelIds");
if (rawIds instanceof List<?>)
{
for (Object item : (List<?>) rawIds)
{
if (item != null && !String.valueOf(item).trim().isEmpty())
{
channelIds.add(String.valueOf(item).trim());
}
}
}
Long productId = null;
Object rawProductId = body == null ? null : body.get("productId");
if (rawProductId instanceof Number)
{
productId = ((Number) rawProductId).longValue();
}
else if (rawProductId != null && !String.valueOf(rawProductId).trim().isEmpty()
&& !"null".equalsIgnoreCase(String.valueOf(rawProductId).trim()))
{
productId = Long.valueOf(String.valueOf(rawProductId).trim());
}
return success(payProductService.bindLabelChannels(priceSetId, channelIds, productId));
}
@PreAuthorize("@ss.hasPermi('price:label:edit')")
@Log(title = "打单套餐解绑渠道", businessType = BusinessType.DELETE)
@DeleteMapping("/{priceSetId}/channels/{channelId}")
public AjaxResult unbindChannel(@PathVariable Long priceSetId, @PathVariable String channelId)
{
priceSetService.assertSetCategory(priceSetId, PrcPriceSet.CATEGORY_LABEL);
return toAjax(payProductService.unbindLabelChannel(priceSetId, channelId));
}
@PreAuthorize("@ss.hasPermi('price:label:list')")
@GetMapping("/customer/list")
@@ -1,4 +1,4 @@
package com.bms.web.controller.ar;
package com.bms.web.controller.receivable;
import java.util.List;
@@ -7,8 +7,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.bms.ar.domain.ArBankAccount;
import com.bms.ar.service.IArBillService;
import com.bms.receivable.domain.ArBankAccount;
import com.bms.receivable.service.IArBillService;
import com.bms.common.core.controller.BaseController;
import com.bms.common.core.domain.AjaxResult;
@@ -1,4 +1,4 @@
package com.bms.web.controller.ar;
package com.bms.web.controller.receivable;
import java.util.ArrayList;
import java.util.List;
@@ -23,21 +23,20 @@ import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.bms.ar.domain.ArBill;
import com.bms.ar.domain.ArBankAccount;
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.ArBillActionRequest;
import com.bms.ar.domain.vo.ArBillGenerateQuery;
import com.bms.ar.domain.vo.ArBillGeneratePreviewExportRow;
import com.bms.ar.domain.vo.ArBillGenerateRequest;
import com.bms.ar.domain.vo.ArBillListExportRow;
import com.bms.ar.domain.vo.ArBillQuery;
import com.bms.ar.enums.ArBillDateType;
import com.bms.ar.service.IArBillService;
import com.bms.ar.security.ArBillScopeResolver;
import com.bms.receivable.domain.ArBill;
import com.bms.receivable.domain.ArBankAccount;
import com.bms.receivable.domain.ArBillDetailFee;
import com.bms.receivable.domain.ArBillGenerateTask;
import com.bms.receivable.domain.ArBillLog;
import com.bms.receivable.domain.vo.ArBillActionRequest;
import com.bms.receivable.domain.vo.ArBillGenerateQuery;
import com.bms.receivable.domain.vo.ArBillGeneratePreviewExportRow;
import com.bms.receivable.domain.vo.ArBillGenerateRequest;
import com.bms.receivable.domain.vo.ArBillListExportRow;
import com.bms.receivable.domain.vo.ArBillQuery;
import com.bms.receivable.enums.ArBillDateType;
import com.bms.receivable.service.IArBillService;
import com.bms.receivable.security.ArBillScopeResolver;
import com.bms.common.annotation.Log;
import com.bms.common.core.controller.BaseController;
import com.bms.common.core.domain.AjaxResult;
@@ -1,4 +1,4 @@
package com.bms.web.controller.ar;
package com.bms.web.controller.receivable;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@@ -12,9 +12,8 @@ import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bms.ar.domain.ArBalanceWriteoff;
import com.bms.ar.domain.ArBill;
import com.bms.ar.service.IArBalanceWriteoffService;
import com.bms.receivable.domain.ArBalanceWriteoff;
import com.bms.receivable.service.IArBalanceWriteoffService;
import com.bms.common.annotation.Log;
import com.bms.common.core.controller.BaseController;
import com.bms.common.core.domain.AjaxResult;
@@ -6,16 +6,16 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bms.ar.profit.ArCommissionRate;
import com.bms.ar.profit.ArCommissionService;
import com.bms.ar.profit.ArProfitQuery;
import com.bms.ar.profit.ArProfitService;
import com.bms.ar.profit.ArWriteoffRate;
import com.bms.receivable.profit.ArCommissionRate;
import com.bms.receivable.profit.ArCommissionService;
import com.bms.receivable.profit.ArProfitQuery;
import com.bms.receivable.profit.ArProfitService;
import com.bms.receivable.profit.ArWriteoffRate;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PathVariable;
import jakarta.servlet.http.HttpServletResponse;
import com.bms.ar.profit.ArProfitRow;
import com.bms.ar.profit.ArCommissionResult;
import com.bms.receivable.profit.ArProfitRow;
import com.bms.receivable.profit.ArCommissionResult;
import com.bms.common.utils.poi.ExcelUtil;
import com.bms.price.enums.ProfitAreaRule;
import com.bms.common.annotation.Log;
@@ -42,14 +42,14 @@ bms:
order-source-sync-threads: 16
# Order-list local rebill workers (2~24). Pair with Druid maxActive >= threads + 8.
local-rebill-threads: 16
# Night auto-rebill: hours 0-8, pull 500 (all statuses) -> bill -> next 500 until empty / 09:00.
# Empty page => no billing.
# Auto-rebill: every hour all day, pull 500 (all statuses) -> bill -> next 500 until empty.
# Empty page => no billing. Window [start-hour, end-hour).
night-retry:
enabled: true
start-hour: 0
end-hour: 9
end-hour: 24
batch-size: 500
cron: "0 0/1 0-8 * * ?"
cron: "0 0 * * * ?"
oracle:
# SLAVE datasource Oracle main-order table (schema.table allowed)
order-table: WEISHI_USER.TAB_ORDER
@@ -11,14 +11,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.jupiter.api.Test;
import com.bms.ar.domain.ArBalanceWriteoff;
import com.bms.ar.domain.ArBill;
import com.bms.ar.mapper.ArCommissionMapper;
import com.bms.ar.profit.ArCommissionRate;
import com.bms.ar.profit.ArCommissionResult;
import com.bms.ar.profit.ArCommissionService;
import com.bms.ar.profit.ArProfitScope;
import com.bms.ar.profit.ArProfitScopeResolver;
import com.bms.receivable.domain.ArBalanceWriteoff;
import com.bms.receivable.domain.ArBill;
import com.bms.receivable.mapper.ArCommissionMapper;
import com.bms.receivable.profit.ArCommissionRate;
import com.bms.receivable.profit.ArCommissionResult;
import com.bms.receivable.profit.ArCommissionService;
import com.bms.receivable.profit.ArProfitScope;
import com.bms.receivable.profit.ArProfitScopeResolver;
import com.bms.common.exception.ServiceException;
class ArCommissionServiceTest
@@ -8,22 +8,47 @@ import java.util.Map;
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
import org.apache.ibatis.session.Configuration;
import org.junit.jupiter.api.Test;
import com.bms.ar.profit.ArProfitQuery;
import com.bms.ar.profit.ArProfitScope;
import com.bms.ar.profit.ArCommissionResult;
import com.bms.receivable.profit.ArProfitQuery;
import com.bms.receivable.profit.ArProfitScope;
import com.bms.receivable.profit.ArCommissionResult;
class ArProfitMapperSqlTest
{
@Test
void snapshotCalculationIsScopedToTheGeneratingBill() throws Exception
{
Configuration configuration = new Configuration();
configuration.getTypeAliasRegistry().registerAlias("ArBill", com.bms.receivable.domain.ArBill.class);
for (String resource : new String[] {"mapper/receivable/ArBillScopeMapper.xml", "mapper/receivable/ArBillMapper.xml"})
{
try (InputStream input = getClass().getClassLoader().getResourceAsStream(resource))
{
new XMLMapperBuilder(input, configuration, resource, configuration.getSqlFragments()).parse();
}
}
var bound = configuration.getMappedStatement("com.bms.receivable.mapper.ArBillMapper.updateProfitSnapshot")
.getBoundSql(Map.of("arBillId", 42L, "shenzhenArea", "C", "guangzhouArea", "GZ"));
String sql = bound.getSql();
assertTrue(sql.contains("fd.ar_bill_id = ?"));
assertTrue(sql.contains("d.ar_bill_id = ?"));
assertTrue(sql.contains("b.ar_bill_id = ? and b.generation_status = 'GENERATING'"));
assertTrue(sql.contains("f.sales_amount = d.total_amount"));
assertTrue(sql.contains("a.detail_total != b.total_amount"));
assertTrue(sql.contains("'MISSING_PRICE'"));
assertTrue(sql.contains("'CURRENCY_MISMATCH'"));
assertTrue(sql.contains("'PRICE_OVERFLOW'"));
}
@Test
void commissionInReportSummaryUsesBillFiltersAndDataScope() throws Exception
{
Configuration configuration = new Configuration();
String resource = "mapper/ar/ArProfitMapper.xml";
String resource = "mapper/receivable/ArProfitMapper.xml";
try (InputStream input = getClass().getClassLoader().getResourceAsStream(resource))
{
new XMLMapperBuilder(input, configuration, resource, configuration.getSqlFragments()).parse();
}
var statement = configuration.getMappedStatement("com.bms.ar.mapper.ArProfitMapper.selectSummary");
var statement = configuration.getMappedStatement("com.bms.receivable.mapper.ArProfitMapper.selectSummary");
ArProfitQuery query = new ArProfitQuery();
query.setCustomerId(5L);
query.setBillNo("AR123");
@@ -65,7 +90,7 @@ class ArProfitMapperSqlTest
{
Configuration configuration = new Configuration();
// 提成 Mapper 先加载时也必须能解析引用的报表权限片段。
for (String resource : new String[] { "mapper/ar/ArCommissionMapper.xml", "mapper/ar/ArProfitMapper.xml" })
for (String resource : new String[] {"mapper/receivable/ArCommissionMapper.xml", "mapper/receivable/ArProfitMapper.xml"})
{
try (InputStream input = getClass().getClassLoader().getResourceAsStream(resource))
{
@@ -74,7 +99,7 @@ class ArProfitMapperSqlTest
}
for (String id : new String[] { "selectBills", "selectSummary", "selectBillDetails", "selectFees" })
{
String name = "com.bms.ar.mapper.ArProfitMapper." + id;
String name = "com.bms.receivable.mapper.ArProfitMapper." + id;
String self = configuration.getMappedStatement(name).getBoundSql(Map.of(
"query", new ArProfitQuery(), "scope", new ArProfitScope(false, true, false, 8L, 10L))).getSql();
String manager = configuration.getMappedStatement(name).getBoundSql(Map.of(
@@ -84,18 +109,26 @@ class ArProfitMapperSqlTest
assertTrue(manager.contains("find_in_set"));
assertTrue(manager.contains("b.status in"));
}
String bills = configuration.getMappedStatement("com.bms.ar.mapper.ArProfitMapper.selectBills")
String bills = configuration.getMappedStatement("com.bms.receivable.mapper.ArProfitMapper.selectBills")
.getBoundSql(Map.of("query", new ArProfitQuery(), "scope", new ArProfitScope(true, false, false, 8L, 10L))).getSql();
assertTrue(bills.contains("from ar_bill b"));
assertTrue(bills.contains("b.bill_name"));
assertTrue(bills.contains("b.profit_calc_status = 'READY'"));
assertTrue(bills.contains("b.product_amount"));
assertTrue(bills.contains("b.redline_amount"));
assertFalse(bills.contains("ar_bill_detail"));
assertFalse(bills.contains("order_no"));
String billCommission = configuration.getMappedStatement("com.bms.ar.mapper.ArCommissionMapper.selectCommissionSummary")
String summary = configuration.getMappedStatement("com.bms.receivable.mapper.ArProfitMapper.selectSummary")
.getBoundSql(Map.of("query", new ArProfitQuery(), "scope", new ArProfitScope(true, false, false, 8L, 10L))).getSql();
assertFalse(summary.contains("ar_bill_detail"));
assertTrue(summary.contains("ar_profit_commission_result"));
String billCommission = configuration.getMappedStatement("com.bms.receivable.mapper.ArCommissionMapper.selectCommissionSummary")
.getBoundSql(Map.of("billId", 9L, "scope", new ArProfitScope(true, false, false, 8L, 10L))).getSql();
assertTrue(billCommission.contains("r.ar_bill_id = ?"));
assertTrue(billCommission.contains("then null"));
for (String id : new String[] { "selectResults", "selectCommissionSummary" })
{
var statement = configuration.getMappedStatement("com.bms.ar.mapper.ArCommissionMapper." + id);
var statement = configuration.getMappedStatement("com.bms.receivable.mapper.ArCommissionMapper." + id);
String self = statement.getBoundSql(Map.of("billId", 9L, "includeReversed", true,
"scope", new ArProfitScope(false, true, false, 8L, 10L))).getSql();
String department = statement.getBoundSql(Map.of("includeReversed", false,
@@ -113,7 +146,7 @@ class ArProfitMapperSqlTest
assertFalse(all.contains("b.profit_sales_user_id = ?"));
assertFalse(all.contains("find_in_set"));
}
var salesSql = configuration.getMappedStatement("com.bms.ar.mapper.ArProfitMapper.selectSalesOptions")
var salesSql = configuration.getMappedStatement("com.bms.receivable.mapper.ArProfitMapper.selectSalesOptions")
.getBoundSql(Map.of("keyword", "sales"));
assertTrue(salesSql.getSql().contains("from sys_user u"));
assertTrue(salesSql.getSql().contains("u.nick_name like"));
@@ -121,11 +154,11 @@ class ArProfitMapperSqlTest
assertFalse(salesSql.getSql().contains("ar_bill"));
assertFalse(salesSql.getSql().contains("sys_role"));
assertTrue(salesSql.getSql().contains("limit 50"));
String settlement = configuration.getMappedStatement("com.bms.ar.mapper.ArCommissionMapper.selectSettlementInputs")
String settlement = configuration.getMappedStatement("com.bms.receivable.mapper.ArCommissionMapper.selectSettlementInputs")
.getBoundSql(Map.of("billId", 1L)).getSql();
assertTrue(settlement.contains("w.status = 'EFFECTIVE'"));
assertTrue(settlement.contains("b.status = 'WRITTEN_OFF'"));
var insert = configuration.getMappedStatement("com.bms.ar.mapper.ArCommissionMapper.insertResults")
var insert = configuration.getMappedStatement("com.bms.receivable.mapper.ArCommissionMapper.insertResults")
.getBoundSql(Map.of("items", java.util.List.of(new ArCommissionResult(), new ArCommissionResult()), "operator", "test"));
assertTrue(insert.getSql().contains("ar_profit_commission_result"));
assertTrue(insert.getParameterMappings().size() == 16);
@@ -4,10 +4,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.Test;
import com.bms.ar.profit.ArProfitScopeResolver;
import com.bms.receivable.profit.ArProfitScopeResolver;
import com.bms.common.core.domain.entity.SysRole;
import com.bms.common.core.domain.entity.SysUser;
import com.bms.common.core.domain.model.LoginUser;
@@ -6,9 +6,9 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import java.math.BigDecimal;
import java.util.List;
import com.bms.ar.profit.CommissionCalculator;
import com.bms.ar.profit.ArCommissionResult;
import com.bms.ar.profit.CommissionCalculator.Writeoff;
import com.bms.receivable.profit.CommissionCalculator;
import com.bms.receivable.profit.ArCommissionResult;
import com.bms.receivable.profit.CommissionCalculator.Writeoff;
import org.junit.jupiter.api.Test;
class CommissionCalculatorTest
@@ -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,

Some files were not shown because too many files have changed in this diff Show More