Compare commits
4 Commits
501056bb17
...
36837f94bf
| Author | SHA1 | Date | |
|---|---|---|---|
| 36837f94bf | |||
| dd2efef456 | |||
| d7f7ebd981 | |||
| be3856a59c |
@@ -43,6 +43,7 @@ import com.bms.price.domain.vo.BatchAddIncomeBillFeeRequest;
|
|||||||
import com.bms.price.domain.vo.BillingTaskSubmitRequest;
|
import com.bms.price.domain.vo.BillingTaskSubmitRequest;
|
||||||
import com.bms.price.domain.vo.ChargeWeightImportRow;
|
import com.bms.price.domain.vo.ChargeWeightImportRow;
|
||||||
import com.bms.price.domain.vo.ChargeWeightTemplateRequest;
|
import com.bms.price.domain.vo.ChargeWeightTemplateRequest;
|
||||||
|
import com.bms.price.domain.vo.LocalRebillRequest;
|
||||||
import com.bms.price.domain.vo.RecalcBillPriceRequest;
|
import com.bms.price.domain.vo.RecalcBillPriceRequest;
|
||||||
import com.bms.price.domain.vo.UpdateChargeWeightRequest;
|
import com.bms.price.domain.vo.UpdateChargeWeightRequest;
|
||||||
import com.bms.price.domain.vo.UpdateIncomeBillFeeRequest;
|
import com.bms.price.domain.vo.UpdateIncomeBillFeeRequest;
|
||||||
@@ -197,6 +198,30 @@ public class BillingController extends BaseController
|
|||||||
return success(orderBillProductCheckService.listOrdersByProduct(query));
|
return success(orderBillProductCheckService.listOrdersByProduct(query));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Order-list rebill from local prc_order_bill only (no Oracle TAB_ORDER).
|
||||||
|
* Poll {@code GET /orderBill/rebill/task/{taskId}}.
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('price:orderBill:rebill')")
|
||||||
|
@Log(title = "Order bill local rebill", businessType = BusinessType.UPDATE)
|
||||||
|
@PostMapping("/orderBill/rebill")
|
||||||
|
public AjaxResult submitLocalRebill(@RequestBody LocalRebillRequest request)
|
||||||
|
{
|
||||||
|
return successTask(prcOrderBillService.submitLocalRebill(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("@ss.hasPermi('price:orderBill:rebill')")
|
||||||
|
@GetMapping("/orderBill/rebill/task/{taskId}")
|
||||||
|
public AjaxResult getLocalRebillTask(@PathVariable("taskId") String taskId)
|
||||||
|
{
|
||||||
|
BatchAddIncomeBillFeeTask task = prcOrderBillService.getLocalRebillTask(taskId);
|
||||||
|
if (task == null)
|
||||||
|
{
|
||||||
|
return error(MessageUtils.message("price.bill.recalc.taskNotExists"));
|
||||||
|
}
|
||||||
|
return success(task);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Order no options for remote-search dropdown (bill list multi search).
|
* Order no options for remote-search dropdown (bill list multi search).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -40,6 +40,14 @@ bms:
|
|||||||
# 同步已直接复用订单行(跳过每单 Oracle 公网查询),瓶颈在 MySQL 计费写入,
|
# 同步已直接复用订单行(跳过每单 Oracle 公网查询),瓶颈在 MySQL 计费写入,
|
||||||
# 同客户行锁冲突由 billWithDbRetry 3 次重试兜底,16 路实测吞吐最高。
|
# 同客户行锁冲突由 billWithDbRetry 3 次重试兜底,16 路实测吞吐最高。
|
||||||
order-source-sync-threads: 16
|
order-source-sync-threads: 16
|
||||||
|
# Night auto-rebill: hours 0-8, pull 500 (all statuses) -> bill -> next 500 until empty / 09:00.
|
||||||
|
# Empty page => no billing.
|
||||||
|
night-retry:
|
||||||
|
enabled: true
|
||||||
|
start-hour: 0
|
||||||
|
end-hour: 9
|
||||||
|
batch-size: 500
|
||||||
|
cron: "0 0/1 0-8 * * ?"
|
||||||
oracle:
|
oracle:
|
||||||
# SLAVE datasource Oracle main-order table (schema.table allowed)
|
# SLAVE datasource Oracle main-order table (schema.table allowed)
|
||||||
order-table: WEISHI_USER.TAB_ORDER
|
order-table: WEISHI_USER.TAB_ORDER
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ public class BillingProperties
|
|||||||
private int consumerThreads = 8;
|
private int consumerThreads = 8;
|
||||||
/** Concurrent threads for monitor order-source sync */
|
/** Concurrent threads for monitor order-source sync */
|
||||||
private int orderSourceSyncThreads = 8;
|
private int orderSourceSyncThreads = 8;
|
||||||
|
/** Night window auto-retry of prc_billing_task (all statuses) */
|
||||||
|
private NightRetry nightRetry = new NightRetry();
|
||||||
private Oracle oracle = new Oracle();
|
private Oracle oracle = new Oracle();
|
||||||
|
|
||||||
public String getMqMode()
|
public String getMqMode()
|
||||||
@@ -82,6 +84,16 @@ public class BillingProperties
|
|||||||
this.orderSourceSyncThreads = orderSourceSyncThreads;
|
this.orderSourceSyncThreads = orderSourceSyncThreads;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NightRetry getNightRetry()
|
||||||
|
{
|
||||||
|
return nightRetry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNightRetry(NightRetry nightRetry)
|
||||||
|
{
|
||||||
|
this.nightRetry = nightRetry;
|
||||||
|
}
|
||||||
|
|
||||||
public Oracle getOracle()
|
public Oracle getOracle()
|
||||||
{
|
{
|
||||||
return oracle;
|
return oracle;
|
||||||
@@ -92,6 +104,62 @@ public class BillingProperties
|
|||||||
this.oracle = oracle;
|
this.oracle = oracle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overnight rebill window: pull prc_billing_task (all success_status) and retryTask.
|
||||||
|
* Default hours [0, 9) local time; empty result skips billing.
|
||||||
|
*/
|
||||||
|
public static class NightRetry
|
||||||
|
{
|
||||||
|
/** Master switch */
|
||||||
|
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;
|
||||||
|
/** Page size: bill this many then pull next page (default 500) */
|
||||||
|
private int batchSize = 500;
|
||||||
|
|
||||||
|
public boolean isEnabled()
|
||||||
|
{
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled)
|
||||||
|
{
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStartHour()
|
||||||
|
{
|
||||||
|
return startHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartHour(int startHour)
|
||||||
|
{
|
||||||
|
this.startHour = startHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEndHour()
|
||||||
|
{
|
||||||
|
return endHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndHour(int endHour)
|
||||||
|
{
|
||||||
|
this.endHour = endHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBatchSize()
|
||||||
|
{
|
||||||
|
return batchSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBatchSize(int batchSize)
|
||||||
|
{
|
||||||
|
this.batchSize = batchSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class Oracle
|
public static class Oracle
|
||||||
{
|
{
|
||||||
/** Upstream main-order table name on SLAVE/Oracle DS */
|
/** Upstream main-order table name on SLAVE/Oracle DS */
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.bms.price.domain.vo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Order-list local rebill: use prc_order_bill only (no Oracle TAB_ORDER).
|
||||||
|
* scopeMode SELECTED = billIds; ALL = filters (orderIdentifiers / customer / bizDate...).
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LocalRebillRequest implements Serializable
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** ALL | SELECTED */
|
||||||
|
private String scopeMode;
|
||||||
|
private List<String> billIds;
|
||||||
|
private List<String> orderNos;
|
||||||
|
private List<String> trackingNos;
|
||||||
|
private List<String> transferNos;
|
||||||
|
private List<String> orderIdentifiers;
|
||||||
|
private List<String> customerCodes;
|
||||||
|
private List<String> productCodes;
|
||||||
|
private List<Integer> orderStatuses;
|
||||||
|
private List<Integer> billingFailStatuses;
|
||||||
|
private String countryCode;
|
||||||
|
private String creditArrearsStatus;
|
||||||
|
private String beginBizDate;
|
||||||
|
private String endBizDate;
|
||||||
|
}
|
||||||
@@ -21,6 +21,12 @@ public interface PrcOrderBillMapper
|
|||||||
|
|
||||||
public List<PrcOrderBill> selectPrcOrderBillList(PrcOrderBill bill);
|
public List<PrcOrderBill> selectPrcOrderBillList(PrcOrderBill bill);
|
||||||
|
|
||||||
|
/** bill_id only (same filters / data-scope as list), for large local rebill. */
|
||||||
|
List<String> selectPrcOrderBillIds(PrcOrderBill bill);
|
||||||
|
|
||||||
|
/** Count matching bills (same filters / data-scope as list). */
|
||||||
|
int countPrcOrderBillIds(PrcOrderBill bill);
|
||||||
|
|
||||||
/** Distinct customer+product groups for product-check (order counts in filter window). */
|
/** Distinct customer+product groups for product-check (order counts in filter window). */
|
||||||
List<Map<String, Object>> selectDistinctProductGroups(PrcOrderBill bill);
|
List<Map<String, Object>> selectDistinctProductGroups(PrcOrderBill bill);
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import com.bms.price.domain.vo.BatchAddIncomeBillFeePreview;
|
|||||||
import com.bms.price.domain.vo.BatchAddIncomeBillFeeRequest;
|
import com.bms.price.domain.vo.BatchAddIncomeBillFeeRequest;
|
||||||
import com.bms.price.domain.vo.ChargeWeightImportRow;
|
import com.bms.price.domain.vo.ChargeWeightImportRow;
|
||||||
import com.bms.price.domain.vo.ChargeWeightTemplateRequest;
|
import com.bms.price.domain.vo.ChargeWeightTemplateRequest;
|
||||||
|
import com.bms.price.domain.vo.LocalRebillRequest;
|
||||||
import com.bms.price.domain.vo.RecalcBillPriceRequest;
|
import com.bms.price.domain.vo.RecalcBillPriceRequest;
|
||||||
import com.bms.price.domain.vo.UpdateIncomeBillFeeRequest;
|
import com.bms.price.domain.vo.UpdateIncomeBillFeeRequest;
|
||||||
import com.bms.price.domain.vo.TmsPriceBillRequest;
|
import com.bms.price.domain.vo.TmsPriceBillRequest;
|
||||||
@@ -135,4 +136,25 @@ public interface IPrcOrderBillService
|
|||||||
* Requires existing prc_order_bill; skips AR editable guard.
|
* Requires existing prc_order_bill; skips AR editable guard.
|
||||||
*/
|
*/
|
||||||
void recalcBillPriceByBillId(String billId, String mode);
|
void recalcBillPriceByBillId(String billId, String mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full rebill from local prc_order_bill only (no Oracle upstream).
|
||||||
|
* Rebuilds TmsPriceBillRequest from the bill row then calls {@link #bill}.
|
||||||
|
*/
|
||||||
|
TmsPriceQuoteResult rebillLocalByBillId(String billId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Async local rebill by selected billIds or list filters. Returns taskId for progress poll.
|
||||||
|
* Large sets: only bill_id loaded, then processed in pages of 500 with parallel workers.
|
||||||
|
*/
|
||||||
|
String submitLocalRebill(LocalRebillRequest request);
|
||||||
|
|
||||||
|
/** Poll Redis progress for local rebill task. */
|
||||||
|
BatchAddIncomeBillFeeTask getLocalRebillTask(String taskId);
|
||||||
|
|
||||||
|
/** Data-scoped bill_id list for local rebill (same filters as order-bill list). */
|
||||||
|
List<String> selectBillIdsForLocalRebill(PrcOrderBill query);
|
||||||
|
|
||||||
|
/** Data-scoped count for local rebill. */
|
||||||
|
int countBillIdsForLocalRebill(PrcOrderBill query);
|
||||||
}
|
}
|
||||||
|
|||||||
+246
@@ -12,6 +12,8 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -50,11 +52,13 @@ import com.bms.price.domain.vo.BatchAddIncomeBillFeePreview;
|
|||||||
import com.bms.price.domain.vo.BatchAddIncomeBillFeeRequest;
|
import com.bms.price.domain.vo.BatchAddIncomeBillFeeRequest;
|
||||||
import com.bms.price.domain.vo.ChargeWeightImportRow;
|
import com.bms.price.domain.vo.ChargeWeightImportRow;
|
||||||
import com.bms.price.domain.vo.ChargeWeightTemplateRequest;
|
import com.bms.price.domain.vo.ChargeWeightTemplateRequest;
|
||||||
|
import com.bms.price.domain.vo.LocalRebillRequest;
|
||||||
import com.bms.price.domain.vo.RecalcBillPriceRequest;
|
import com.bms.price.domain.vo.RecalcBillPriceRequest;
|
||||||
import com.bms.price.domain.vo.UpdateIncomeBillFeeRequest;
|
import com.bms.price.domain.vo.UpdateIncomeBillFeeRequest;
|
||||||
import com.bms.price.task.PrcBatchAddIncomeFeeAsyncRunner;
|
import com.bms.price.task.PrcBatchAddIncomeFeeAsyncRunner;
|
||||||
import com.bms.price.task.PrcChargeWeightImportAsyncRunner;
|
import com.bms.price.task.PrcChargeWeightImportAsyncRunner;
|
||||||
import com.bms.price.task.PrcChargeWeightImportAsyncRunner.ChargeWeightImportWorkItem;
|
import com.bms.price.task.PrcChargeWeightImportAsyncRunner.ChargeWeightImportWorkItem;
|
||||||
|
import com.bms.price.task.PrcOrderBillLocalRebillAsyncRunner;
|
||||||
import com.bms.price.task.PrcRecalcBillPriceAsyncRunner;
|
import com.bms.price.task.PrcRecalcBillPriceAsyncRunner;
|
||||||
import com.bms.price.domain.vo.TmsPriceBillRequest;
|
import com.bms.price.domain.vo.TmsPriceBillRequest;
|
||||||
import com.bms.price.domain.vo.TmsOrderBillStatusResult;
|
import com.bms.price.domain.vo.TmsOrderBillStatusResult;
|
||||||
@@ -87,6 +91,8 @@ import com.bms.price.task.PrcCreditArrearsClearAsyncRunner;
|
|||||||
@Service
|
@Service
|
||||||
public class PrcOrderBillServiceImpl implements IPrcOrderBillService
|
public class PrcOrderBillServiceImpl implements IPrcOrderBillService
|
||||||
{
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(PrcOrderBillServiceImpl.class);
|
||||||
|
|
||||||
private static final String DICT_FEE_TYPE = "bms_fee_type";
|
private static final String DICT_FEE_TYPE = "bms_fee_type";
|
||||||
private static final String FEE_TYPE_REFUND = "REFUND";
|
private static final String FEE_TYPE_REFUND = "REFUND";
|
||||||
|
|
||||||
@@ -143,6 +149,9 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
|
|||||||
@Autowired
|
@Autowired
|
||||||
private PrcRecalcBillPriceAsyncRunner recalcBillPriceAsyncRunner;
|
private PrcRecalcBillPriceAsyncRunner recalcBillPriceAsyncRunner;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PrcOrderBillLocalRebillAsyncRunner localRebillAsyncRunner;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IBmsBizRuleService bizRuleService;
|
private IBmsBizRuleService bizRuleService;
|
||||||
|
|
||||||
@@ -150,6 +159,8 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
|
|||||||
private static final int BATCH_ADD_FEE_PREVIEW_LIMIT = 20;
|
private static final int BATCH_ADD_FEE_PREVIEW_LIMIT = 20;
|
||||||
private static final int CHARGE_WEIGHT_IMPORT_MAX = 5000;
|
private static final int CHARGE_WEIGHT_IMPORT_MAX = 5000;
|
||||||
private static final int RECALC_PRICE_MAX = 5000;
|
private static final int RECALC_PRICE_MAX = 5000;
|
||||||
|
/** Soft max for one local-rebill job (id-only load + paged parallel). */
|
||||||
|
private static final int LOCAL_REBILL_MAX = 100000;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@@ -694,6 +705,241 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
|
|||||||
persistProductOrRedlineOnly(bill, result, productMode);
|
persistProductOrRedlineOnly(bill, result, productMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final int LOCAL_REBILL_DB_RETRY_MAX = 3;
|
||||||
|
private static final long LOCAL_REBILL_DB_RETRY_BASE_MS = 80L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local rebill without outer txn: each {@link #bill} starts its own transaction so
|
||||||
|
* MySQL deadlock can be retried cleanly (same idea as billing-task billWithDbRetry).
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TmsPriceQuoteResult rebillLocalByBillId(String billId)
|
||||||
|
{
|
||||||
|
if (StringUtils.isEmpty(billId))
|
||||||
|
{
|
||||||
|
throw new ServiceException(MessageUtils.message("price.bill.billIdRequired"));
|
||||||
|
}
|
||||||
|
PrcOrderBill bill = orderBillMapper.selectPrcOrderBillById(billId.trim());
|
||||||
|
if (bill == null)
|
||||||
|
{
|
||||||
|
throw new ServiceException(MessageUtils.message("price.bill.notFound"));
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(bill.getOrderNo()))
|
||||||
|
{
|
||||||
|
throw new ServiceException(MessageUtils.message("price.bill.orderNoRequired"));
|
||||||
|
}
|
||||||
|
if (bill.getBizDate() == null)
|
||||||
|
{
|
||||||
|
throw new ServiceException(MessageUtils.message("price.bill.bizDateRequired"));
|
||||||
|
}
|
||||||
|
TmsPriceBillRequest req = buildBillRequestFromBill(bill);
|
||||||
|
return billLocalWithDbRetry(billId.trim(), req);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TmsPriceQuoteResult billLocalWithDbRetry(String billId, TmsPriceBillRequest billReq)
|
||||||
|
{
|
||||||
|
RuntimeException last = null;
|
||||||
|
for (int attempt = 1; attempt <= LOCAL_REBILL_DB_RETRY_MAX; attempt++)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return self.bill(billReq);
|
||||||
|
}
|
||||||
|
catch (RuntimeException e)
|
||||||
|
{
|
||||||
|
last = e;
|
||||||
|
if (attempt < LOCAL_REBILL_DB_RETRY_MAX && isRetryableDbConflict(e))
|
||||||
|
{
|
||||||
|
long sleepMs = LOCAL_REBILL_DB_RETRY_BASE_MS * attempt
|
||||||
|
+ (long) (Math.random() * LOCAL_REBILL_DB_RETRY_BASE_MS);
|
||||||
|
log.warn("local rebill db conflict, retry billId={} attempt={}/{} sleepMs={} msg={}",
|
||||||
|
billId, Integer.valueOf(attempt), Integer.valueOf(LOCAL_REBILL_DB_RETRY_MAX),
|
||||||
|
Long.valueOf(sleepMs), StringUtils.substring(e.getMessage(), 0, 200));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Thread.sleep(sleepMs);
|
||||||
|
}
|
||||||
|
catch (InterruptedException ie)
|
||||||
|
{
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw last != null ? last : new ServiceException("local rebill retry exhausted");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Deadlock / lock wait — safe to retry whole bill txn (parallel local rebill). */
|
||||||
|
private static boolean isRetryableDbConflict(Throwable e)
|
||||||
|
{
|
||||||
|
Throwable t = e;
|
||||||
|
while (t != null)
|
||||||
|
{
|
||||||
|
String name = t.getClass().getName();
|
||||||
|
if (name.indexOf("DeadlockLoser") >= 0
|
||||||
|
|| name.indexOf("CannotAcquireLock") >= 0
|
||||||
|
|| name.indexOf("MySQLTransactionRollback") >= 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
String msg = t.getMessage();
|
||||||
|
if (msg != null)
|
||||||
|
{
|
||||||
|
String m = msg.toLowerCase();
|
||||||
|
if (m.indexOf("deadlock") >= 0
|
||||||
|
|| m.indexOf("try restarting transaction") >= 0
|
||||||
|
|| m.indexOf("lock wait timeout") >= 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t = t.getCause();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String submitLocalRebill(LocalRebillRequest request)
|
||||||
|
{
|
||||||
|
if (request == null)
|
||||||
|
{
|
||||||
|
throw new ServiceException(MessageUtils.message("price.bill.recalc.filterRequired"));
|
||||||
|
}
|
||||||
|
PrcOrderBill query = buildLocalRebillQuery(request);
|
||||||
|
int total = self.countBillIdsForLocalRebill(query);
|
||||||
|
if (total <= 0)
|
||||||
|
{
|
||||||
|
throw new ServiceException(MessageUtils.message("price.bill.recalc.noMatch"));
|
||||||
|
}
|
||||||
|
if (total > LOCAL_REBILL_MAX)
|
||||||
|
{
|
||||||
|
throw new ServiceException(MessageUtils.message("price.bill.recalc.tooMany",
|
||||||
|
Integer.valueOf(LOCAL_REBILL_MAX)));
|
||||||
|
}
|
||||||
|
// Id-only: avoid loading full prc_order_bill rows for large jobs.
|
||||||
|
List<String> billIds = self.selectBillIdsForLocalRebill(query);
|
||||||
|
if (billIds == null || billIds.isEmpty())
|
||||||
|
{
|
||||||
|
throw new ServiceException(MessageUtils.message("price.bill.recalc.noMatch"));
|
||||||
|
}
|
||||||
|
String taskId = IdUtils.fastSimpleUUID();
|
||||||
|
localRebillAsyncRunner.put(taskId, BatchAddIncomeBillFeeTask.STATUS_PENDING, 0, "queued", null,
|
||||||
|
billIds.size(), 0, 0);
|
||||||
|
// One ES op-log per batch on finish (LOCAL_REBILL_DONE); fail orders go into detail.failDetails.
|
||||||
|
localRebillAsyncRunner.run(taskId, billIds, request);
|
||||||
|
return taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BatchAddIncomeBillFeeTask getLocalRebillTask(String taskId)
|
||||||
|
{
|
||||||
|
if (StringUtils.isEmpty(taskId) || localRebillAsyncRunner == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return localRebillAsyncRunner.get(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@DataScope(deptAlias = "su", deptField = "dept_id", userAlias = "su", userField = "user_id", permission = "price:billing:bill")
|
||||||
|
public List<String> selectBillIdsForLocalRebill(PrcOrderBill query)
|
||||||
|
{
|
||||||
|
if (query == null)
|
||||||
|
{
|
||||||
|
return new ArrayList<String>();
|
||||||
|
}
|
||||||
|
normalizeLocalRebillQuery(query);
|
||||||
|
List<String> ids = orderBillMapper.selectPrcOrderBillIds(query);
|
||||||
|
return ids == null ? new ArrayList<String>() : ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@DataScope(deptAlias = "su", deptField = "dept_id", userAlias = "su", userField = "user_id", permission = "price:billing:bill")
|
||||||
|
public int countBillIdsForLocalRebill(PrcOrderBill query)
|
||||||
|
{
|
||||||
|
if (query == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
normalizeLocalRebillQuery(query);
|
||||||
|
return orderBillMapper.countPrcOrderBillIds(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PrcOrderBill buildLocalRebillQuery(LocalRebillRequest request)
|
||||||
|
{
|
||||||
|
String scopeMode = StringUtils.nvl(request.getScopeMode(), "").trim().toUpperCase();
|
||||||
|
PrcOrderBill query = new PrcOrderBill();
|
||||||
|
if ("SELECTED".equals(scopeMode))
|
||||||
|
{
|
||||||
|
List<String> billIds = normalizeCodeList(request.getBillIds());
|
||||||
|
if (billIds == null || billIds.isEmpty())
|
||||||
|
{
|
||||||
|
throw new ServiceException(MessageUtils.message("price.bill.recalc.selectedRequired"));
|
||||||
|
}
|
||||||
|
query.setBillIds(billIds);
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
List<String> orderNos = normalizeCodeList(request.getOrderNos());
|
||||||
|
List<String> trackingNos = normalizeCodeList(request.getTrackingNos());
|
||||||
|
List<String> transferNos = normalizeCodeList(request.getTransferNos());
|
||||||
|
List<String> orderIdentifiers = normalizeCodeList(request.getOrderIdentifiers());
|
||||||
|
List<String> customerCodes = normalizeCodeList(request.getCustomerCodes());
|
||||||
|
List<String> productCodes = normalizeCodeList(request.getProductCodes());
|
||||||
|
String creditArrearsStatus = StringUtils.isEmpty(request.getCreditArrearsStatus()) ? null
|
||||||
|
: request.getCreditArrearsStatus().trim();
|
||||||
|
String countryCode = StringUtils.isEmpty(request.getCountryCode()) ? null
|
||||||
|
: request.getCountryCode().trim().toUpperCase();
|
||||||
|
String beginBizDate = StringUtils.isEmpty(request.getBeginBizDate()) ? null : request.getBeginBizDate().trim();
|
||||||
|
String endBizDate = StringUtils.isEmpty(request.getEndBizDate()) ? null : request.getEndBizDate().trim();
|
||||||
|
boolean hasFilter = (orderNos != null && !orderNos.isEmpty())
|
||||||
|
|| (trackingNos != null && !trackingNos.isEmpty())
|
||||||
|
|| (transferNos != null && !transferNos.isEmpty())
|
||||||
|
|| (orderIdentifiers != null && !orderIdentifiers.isEmpty())
|
||||||
|
|| (customerCodes != null && !customerCodes.isEmpty())
|
||||||
|
|| (productCodes != null && !productCodes.isEmpty())
|
||||||
|
|| StringUtils.isNotEmpty(creditArrearsStatus)
|
||||||
|
|| StringUtils.isNotEmpty(countryCode)
|
||||||
|
|| StringUtils.isNotEmpty(beginBizDate)
|
||||||
|
|| StringUtils.isNotEmpty(endBizDate);
|
||||||
|
if (!hasFilter)
|
||||||
|
{
|
||||||
|
throw new ServiceException(MessageUtils.message("price.bill.recalc.filterRequired"));
|
||||||
|
}
|
||||||
|
query.setOrderNos(orderNos);
|
||||||
|
query.setTrackingNos(trackingNos);
|
||||||
|
query.setTransferNos(transferNos);
|
||||||
|
query.setOrderIdentifiers(orderIdentifiers);
|
||||||
|
query.setCustomerCodes(customerCodes);
|
||||||
|
query.setProductCodes(productCodes);
|
||||||
|
query.setOrderStatuses(request.getOrderStatuses());
|
||||||
|
query.setBillingFailStatuses(request.getBillingFailStatuses());
|
||||||
|
query.setCreditArrearsStatus(creditArrearsStatus);
|
||||||
|
query.setCountryCode(countryCode);
|
||||||
|
if (beginBizDate != null)
|
||||||
|
{
|
||||||
|
query.getParams().put("beginBizDate", beginBizDate);
|
||||||
|
}
|
||||||
|
if (endBizDate != null)
|
||||||
|
{
|
||||||
|
query.getParams().put("endBizDate", endBizDate);
|
||||||
|
}
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void normalizeLocalRebillQuery(PrcOrderBill query)
|
||||||
|
{
|
||||||
|
query.setOrderNos(normalizeCodeList(query.getOrderNos()));
|
||||||
|
query.setCustomerCodes(normalizeCodeList(query.getCustomerCodes()));
|
||||||
|
query.setProductCodes(normalizeCodeList(query.getProductCodes()));
|
||||||
|
query.setTrackingNos(normalizeCodeList(query.getTrackingNos()));
|
||||||
|
query.setTransferNos(normalizeCodeList(query.getTransferNos()));
|
||||||
|
query.setOrderIdentifiers(normalizeCodeList(query.getOrderIdentifiers()));
|
||||||
|
query.setBillIds(normalizeCodeList(query.getBillIds()));
|
||||||
|
}
|
||||||
|
|
||||||
private static String normalizeRecalcMode(String mode)
|
private static String normalizeRecalcMode(String mode)
|
||||||
{
|
{
|
||||||
String m = StringUtils.nvl(mode, "").trim().toUpperCase();
|
String m = StringUtils.nvl(mode, "").trim().toUpperCase();
|
||||||
|
|||||||
+203
@@ -0,0 +1,203 @@
|
|||||||
|
package com.bms.price.task;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import com.bms.price.config.BillingProperties;
|
||||||
|
import com.bms.price.domain.PrcBillingTask;
|
||||||
|
import com.bms.price.enums.BillTaskSuccessStatus;
|
||||||
|
import com.bms.price.mapper.PrcBillingTaskMapper;
|
||||||
|
import com.bms.price.service.IPrcBillingTaskService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Night window auto-rebill from prc_billing_task.
|
||||||
|
*
|
||||||
|
* <p>During [startHour, endHour) (default 00:00-09:00): pull up to {@value #DEFAULT_BATCH}
|
||||||
|
* task ids (all success_status) -> bill them all -> immediately pull the next page.
|
||||||
|
* Empty page => skip billing and end this run (next cron may pick up new rows).</p>
|
||||||
|
*
|
||||||
|
* <p>Same rebill path as monitor manual retry / filter retry (reset WAITING then process).</p>
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class PrcBillingTaskNightRetryTask
|
||||||
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(PrcBillingTaskNightRetryTask.class);
|
||||||
|
|
||||||
|
/** Default page size: bill this many, then pull next page */
|
||||||
|
public static final int DEFAULT_BATCH = 500;
|
||||||
|
public static final int MIN_BATCH = 1;
|
||||||
|
public static final int MAX_BATCH = 1000;
|
||||||
|
|
||||||
|
private final AtomicBoolean running = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
/** Keyset cursor within the current local-day window; reset when the window day changes. */
|
||||||
|
private volatile long lastTaskId = 0L;
|
||||||
|
private volatile int windowDayOfYear = -1;
|
||||||
|
private volatile int windowYear = -1;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BillingProperties billingProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PrcBillingTaskMapper billingTaskMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Lazy
|
||||||
|
private IPrcBillingTaskService billingTaskService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fire every minute; 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 * * ?}")
|
||||||
|
public void scheduledTick()
|
||||||
|
{
|
||||||
|
BillingProperties.NightRetry cfg = billingProperties == null ? null : billingProperties.getNightRetry();
|
||||||
|
if (cfg == null || !cfg.isEnabled())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!inWindow(cfg.getStartHour(), cfg.getEndHour()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!running.compareAndSet(false, true))
|
||||||
|
{
|
||||||
|
log.debug("billing night-retry skip: previous run still paging");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
runUntilEmptyOrEnd(cfg);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
log.error("billing night-retry run failed", e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
running.set(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pull batch -> bill all -> pull next batch, until no data or outside window.
|
||||||
|
*/
|
||||||
|
private void runUntilEmptyOrEnd(BillingProperties.NightRetry cfg)
|
||||||
|
{
|
||||||
|
resetCursorIfNewWindowDay();
|
||||||
|
int batch = clampBatch(cfg.getBatchSize());
|
||||||
|
PrcBillingTask query = new PrcBillingTask();
|
||||||
|
int page = 0;
|
||||||
|
int totalOk = 0;
|
||||||
|
int totalFail = 0;
|
||||||
|
|
||||||
|
while (inWindow(cfg.getStartHour(), cfg.getEndHour()))
|
||||||
|
{
|
||||||
|
List<Long> ids = billingTaskMapper.selectTaskIdsByFilter(
|
||||||
|
query, Long.valueOf(lastTaskId), batch);
|
||||||
|
if (ids == null || ids.isEmpty())
|
||||||
|
{
|
||||||
|
if (lastTaskId > 0L)
|
||||||
|
{
|
||||||
|
lastTaskId = 0L;
|
||||||
|
log.info("billing night-retry full scan done pages={} ok={} fail={}, cursor reset",
|
||||||
|
page, totalOk, totalFail);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log.info("billing night-retry no data, skip billing");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
page++;
|
||||||
|
log.info("billing night-retry page={} pull batchSize={} fetched={} lastTaskIdBefore={}",
|
||||||
|
page, batch, ids.size(), lastTaskId);
|
||||||
|
|
||||||
|
int ok = 0;
|
||||||
|
int fail = 0;
|
||||||
|
for (Long taskId : ids)
|
||||||
|
{
|
||||||
|
if (taskId == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
lastTaskId = taskId.longValue();
|
||||||
|
if (!inWindow(cfg.getStartHour(), cfg.getEndHour()))
|
||||||
|
{
|
||||||
|
log.info("billing night-retry stop mid-page: reached end-hour page={} ok={} fail={}",
|
||||||
|
page, totalOk + ok, totalFail + fail);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PrcBillingTask task = billingTaskService.retryTask(taskId);
|
||||||
|
if (task != null && BillTaskSuccessStatus.SUCCESS.getCode().equals(task.getSuccessStatus()))
|
||||||
|
{
|
||||||
|
ok++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fail++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (RuntimeException e)
|
||||||
|
{
|
||||||
|
fail++;
|
||||||
|
log.warn("billing night-retry failed taskId={} msg={}", taskId, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
totalOk += ok;
|
||||||
|
totalFail += fail;
|
||||||
|
log.info("billing night-retry page={} done fetched={} ok={} fail={} lastTaskId={}",
|
||||||
|
page, ids.size(), ok, fail, lastTaskId);
|
||||||
|
// This page billed; loop immediately pulls the next page.
|
||||||
|
}
|
||||||
|
log.info("billing night-retry window closed pages={} ok={} fail={}", page, totalOk, totalFail);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetCursorIfNewWindowDay()
|
||||||
|
{
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
int year = cal.get(Calendar.YEAR);
|
||||||
|
int day = cal.get(Calendar.DAY_OF_YEAR);
|
||||||
|
if (year != windowYear || day != windowDayOfYear)
|
||||||
|
{
|
||||||
|
windowYear = year;
|
||||||
|
windowDayOfYear = day;
|
||||||
|
lastTaskId = 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean inWindow(int startHour, int endHour)
|
||||||
|
{
|
||||||
|
int start = Math.max(0, Math.min(23, startHour));
|
||||||
|
int end = Math.max(1, Math.min(24, endHour));
|
||||||
|
if (start >= end)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
|
||||||
|
return hour >= start && hour < end;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int clampBatch(int batchSize)
|
||||||
|
{
|
||||||
|
if (batchSize < MIN_BATCH)
|
||||||
|
{
|
||||||
|
return DEFAULT_BATCH;
|
||||||
|
}
|
||||||
|
if (batchSize > MAX_BATCH)
|
||||||
|
{
|
||||||
|
return MAX_BATCH;
|
||||||
|
}
|
||||||
|
return batchSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
+312
@@ -0,0 +1,312 @@
|
|||||||
|
package com.bms.price.task;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import com.bms.common.core.redis.RedisCache;
|
||||||
|
import com.bms.common.utils.StringUtils;
|
||||||
|
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.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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Async local rebill from prc_order_bill only (no Oracle / no MQ).
|
||||||
|
* Large jobs: process in pages of {@link #PAGE_SIZE}; each page runs in a short-lived worker pool.
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class PrcOrderBillLocalRebillAsyncRunner
|
||||||
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(PrcOrderBillLocalRebillAsyncRunner.class);
|
||||||
|
|
||||||
|
public static final String CACHE_KEY_PREFIX = "price:billing:localRebill:task:";
|
||||||
|
public static final int TTL_MINUTES = 120;
|
||||||
|
/** Bill this many, wait for page done, then next page. */
|
||||||
|
public static final int PAGE_SIZE = 500;
|
||||||
|
public static final int MIN_THREADS = 2;
|
||||||
|
public static final int MAX_THREADS = 16;
|
||||||
|
private static final int FAIL_DETAIL_MAX = 200;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Lazy
|
||||||
|
private IPrcOrderBillService orderBillService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisCache redisCache;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BillingProperties billingProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IBillSearchStore billSearchStore;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PrcOrderBillMapper orderBillMapper;
|
||||||
|
|
||||||
|
@Async("threadPoolTaskExecutor")
|
||||||
|
public void run(String taskId, List<String> billIds)
|
||||||
|
{
|
||||||
|
run(taskId, billIds, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Async("threadPoolTaskExecutor")
|
||||||
|
public void run(String taskId, List<String> billIds, LocalRebillRequest request)
|
||||||
|
{
|
||||||
|
int total = billIds == null ? 0 : billIds.size();
|
||||||
|
AtomicInteger success = new AtomicInteger(0);
|
||||||
|
AtomicInteger fail = new AtomicInteger(0);
|
||||||
|
StringBuilder failTips = new StringBuilder();
|
||||||
|
List<Map<String, Object>> failDetails = Collections.synchronizedList(new ArrayList<Map<String, Object>>());
|
||||||
|
int threads = clampThreads(billingProperties == null ? null : billingProperties.getOrderSourceSyncThreads());
|
||||||
|
ExecutorService pool = newWorkerPool(threads, "local-rebill");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
put(taskId, BatchAddIncomeBillFeeTask.STATUS_RUNNING, 1, "running", null, total, 0, 0);
|
||||||
|
if (total == 0)
|
||||||
|
{
|
||||||
|
put(taskId, BatchAddIncomeBillFeeTask.STATUS_FAIL, 100, "failed", "no bills", 0, 0, 0);
|
||||||
|
saveDoneLog(taskId, request, total, 0, 0, threads, failDetails, "FAIL", "no bills");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int processed = 0;
|
||||||
|
for (int from = 0; from < total; from += PAGE_SIZE)
|
||||||
|
{
|
||||||
|
int to = Math.min(from + PAGE_SIZE, total);
|
||||||
|
List<String> page = billIds.subList(from, to);
|
||||||
|
List<Callable<Boolean>> jobs = new ArrayList<Callable<Boolean>>(page.size());
|
||||||
|
for (String billId : page)
|
||||||
|
{
|
||||||
|
final String one = billId;
|
||||||
|
jobs.add(() -> {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
orderBillService.rebillLocalByBillId(one);
|
||||||
|
success.incrementAndGet();
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
fail.incrementAndGet();
|
||||||
|
appendFail(failTips, one, e);
|
||||||
|
collectFailDetail(failDetails, one, e);
|
||||||
|
log.warn("local rebill failed taskId={} billId={} msg={}",
|
||||||
|
taskId, one, e.getMessage());
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
invokeAllQuiet(pool, jobs);
|
||||||
|
processed = to;
|
||||||
|
int percent = Math.min(99, (int) Math.floor(100.0 * processed / total));
|
||||||
|
put(taskId, BatchAddIncomeBillFeeTask.STATUS_RUNNING, percent,
|
||||||
|
"processing " + processed + "/" + total + " page=" + ((from / PAGE_SIZE) + 1),
|
||||||
|
null, total, success.get(), fail.get());
|
||||||
|
}
|
||||||
|
String msg = "success=" + success.get() + ", fail=" + fail.get();
|
||||||
|
String err = fail.get() > 0 && failTips.length() > 0 ? failTips.toString() : null;
|
||||||
|
put(taskId, BatchAddIncomeBillFeeTask.STATUS_SUCCESS, 100, msg, err,
|
||||||
|
total, success.get(), fail.get());
|
||||||
|
String doneStatus = fail.get() > 0 ? EsBizLogSupport.STATUS_FAIL : EsBizLogSupport.STATUS_SUCCESS;
|
||||||
|
String doneErr = fail.get() > 0 ? ("fail=" + fail.get() + ", ok=" + success.get()) : null;
|
||||||
|
saveDoneLog(taskId, request, total, success.get(), fail.get(), threads, failDetails, doneStatus, doneErr);
|
||||||
|
log.info("local rebill done taskId={} total={} success={} fail={} threads={} pageSize={}",
|
||||||
|
taskId, total, success.get(), fail.get(), threads, PAGE_SIZE);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
log.error("local rebill aborted taskId={}", taskId, e);
|
||||||
|
String msg = errorMessage(e);
|
||||||
|
put(taskId, BatchAddIncomeBillFeeTask.STATUS_FAIL, 100, "failed", msg,
|
||||||
|
total, success.get(), fail.get());
|
||||||
|
saveDoneLog(taskId, request, total, success.get(), fail.get(), threads, failDetails,
|
||||||
|
EsBizLogSupport.STATUS_FAIL, msg);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
shutdownPool(pool);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveDoneLog(String taskId, LocalRebillRequest request, int total, int ok, int fail,
|
||||||
|
int threads, List<Map<String, Object>> failDetails, String status, String errorMessage)
|
||||||
|
{
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<String, Object>();
|
||||||
|
resp.put("taskId", taskId);
|
||||||
|
resp.put("total", Integer.valueOf(total));
|
||||||
|
resp.put("ok", Integer.valueOf(ok));
|
||||||
|
resp.put("fail", Integer.valueOf(fail));
|
||||||
|
resp.put("success", Integer.valueOf(ok));
|
||||||
|
resp.put("threads", Integer.valueOf(threads));
|
||||||
|
resp.put("pageSize", Integer.valueOf(PAGE_SIZE));
|
||||||
|
if (failDetails != null && !failDetails.isEmpty())
|
||||||
|
{
|
||||||
|
resp.put("failDetails", new ArrayList<Map<String, Object>>(failDetails));
|
||||||
|
}
|
||||||
|
TabOrderSyncEsLog.save(billSearchStore, taskId, "LOCAL_REBILL_DONE", request, resp, status, errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void collectFailDetail(List<Map<String, Object>> failDetails, String billId, Exception e)
|
||||||
|
{
|
||||||
|
if (failDetails == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
synchronized (failDetails)
|
||||||
|
{
|
||||||
|
if (failDetails.size() >= FAIL_DETAIL_MAX)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, Object> item = new LinkedHashMap<String, Object>();
|
||||||
|
item.put("billId", billId);
|
||||||
|
String orderNo = null;
|
||||||
|
String transferNo = null;
|
||||||
|
String trackingNo = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PrcOrderBill bill = orderBillMapper == null || StringUtils.isEmpty(billId)
|
||||||
|
? null : orderBillMapper.selectPrcOrderBillById(billId.trim());
|
||||||
|
if (bill != null)
|
||||||
|
{
|
||||||
|
orderNo = bill.getOrderNo();
|
||||||
|
transferNo = bill.getTransferNo();
|
||||||
|
trackingNo = bill.getTrackingNo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ignore)
|
||||||
|
{
|
||||||
|
// detail enrichment is best-effort
|
||||||
|
}
|
||||||
|
item.put("orderId", StringUtils.isEmpty(orderNo) ? billId : orderNo);
|
||||||
|
item.put("transferOrderId", transferNo);
|
||||||
|
item.put("trackingNo", trackingNo);
|
||||||
|
item.put("errorMessage", errorMessage(e));
|
||||||
|
failDetails.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void put(String taskId, String status, int percent, String message, String error,
|
||||||
|
int total, int success, int fail)
|
||||||
|
{
|
||||||
|
BatchAddIncomeBillFeeTask task = new BatchAddIncomeBillFeeTask();
|
||||||
|
task.setTaskId(taskId);
|
||||||
|
task.setStatus(status);
|
||||||
|
task.setPercent(percent);
|
||||||
|
task.setMessage(message);
|
||||||
|
task.setError(error);
|
||||||
|
task.setTotal(total);
|
||||||
|
task.setSuccess(success);
|
||||||
|
task.setFail(fail);
|
||||||
|
redisCache.setCacheObject(CACHE_KEY_PREFIX + taskId, task, TTL_MINUTES, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BatchAddIncomeBillFeeTask get(String taskId)
|
||||||
|
{
|
||||||
|
return redisCache.getCacheObject(CACHE_KEY_PREFIX + taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void invokeAllQuiet(ExecutorService pool, List<Callable<Boolean>> jobs) throws InterruptedException
|
||||||
|
{
|
||||||
|
List<Future<Boolean>> futures = pool.invokeAll(jobs);
|
||||||
|
for (Future<Boolean> f : futures)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
f.get();
|
||||||
|
}
|
||||||
|
catch (ExecutionException e)
|
||||||
|
{
|
||||||
|
// counted in job body
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ExecutorService newWorkerPool(int threads, String namePrefix)
|
||||||
|
{
|
||||||
|
AtomicInteger seq = new AtomicInteger(0);
|
||||||
|
ThreadFactory factory = r -> {
|
||||||
|
Thread t = new Thread(r);
|
||||||
|
t.setName(namePrefix + "-" + seq.incrementAndGet());
|
||||||
|
t.setDaemon(true);
|
||||||
|
return t;
|
||||||
|
};
|
||||||
|
return Executors.newFixedThreadPool(Math.max(1, threads), factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void shutdownPool(ExecutorService pool)
|
||||||
|
{
|
||||||
|
if (pool == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pool.shutdown();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!pool.awaitTermination(60, TimeUnit.SECONDS))
|
||||||
|
{
|
||||||
|
pool.shutdownNow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
pool.shutdownNow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int clampThreads(Integer n)
|
||||||
|
{
|
||||||
|
int v = n == null ? 8 : n.intValue();
|
||||||
|
if (v < MIN_THREADS)
|
||||||
|
{
|
||||||
|
return MIN_THREADS;
|
||||||
|
}
|
||||||
|
if (v > MAX_THREADS)
|
||||||
|
{
|
||||||
|
return MAX_THREADS;
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void appendFail(StringBuilder failTips, String billId, Exception e)
|
||||||
|
{
|
||||||
|
synchronized (failTips)
|
||||||
|
{
|
||||||
|
if (failTips.length() >= 800)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (failTips.length() > 0)
|
||||||
|
{
|
||||||
|
failTips.append("; ");
|
||||||
|
}
|
||||||
|
failTips.append(billId).append(":").append(errorMessage(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String errorMessage(Exception e)
|
||||||
|
{
|
||||||
|
return StringUtils.isEmpty(e.getMessage()) ? e.getClass().getSimpleName() : e.getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -409,9 +409,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
limit #{limit}
|
limit #{limit}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectPrcOrderBillList" parameterType="PrcOrderBill" resultMap="PrcOrderBillResult">
|
<!-- Shared list filters for full row / id-only / count queries. -->
|
||||||
<include refid="selectPrcOrderBillVo"/>
|
<sql id="prcOrderBillListWhere">
|
||||||
<where>
|
|
||||||
<if test="billId != null and billId != ''">
|
<if test="billId != null and billId != ''">
|
||||||
AND p.bill_id = #{billId}
|
AND p.bill_id = #{billId}
|
||||||
</if>
|
</if>
|
||||||
@@ -540,10 +539,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
AND date_format(p.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
|
AND date_format(p.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
|
||||||
</if>
|
</if>
|
||||||
<include refid="orderBillDataScopeFilter"/>
|
<include refid="orderBillDataScopeFilter"/>
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectPrcOrderBillList" parameterType="PrcOrderBill" resultMap="PrcOrderBillResult">
|
||||||
|
<include refid="selectPrcOrderBillVo"/>
|
||||||
|
<where>
|
||||||
|
<include refid="prcOrderBillListWhere"/>
|
||||||
</where>
|
</where>
|
||||||
order by p.create_time desc, p.bill_id desc
|
order by p.create_time desc, p.bill_id desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- Id-only for large local rebill (avoid loading full rows into memory). -->
|
||||||
|
<select id="selectPrcOrderBillIds" parameterType="PrcOrderBill" resultType="string">
|
||||||
|
select p.bill_id
|
||||||
|
from prc_order_bill p
|
||||||
|
<where>
|
||||||
|
<include refid="prcOrderBillListWhere"/>
|
||||||
|
</where>
|
||||||
|
order by p.bill_id asc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="countPrcOrderBillIds" parameterType="PrcOrderBill" resultType="int">
|
||||||
|
select count(1)
|
||||||
|
from prc_order_bill p
|
||||||
|
<where>
|
||||||
|
<include refid="prcOrderBillListWhere"/>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
<!-- rename_bill_tables.sql 已将需求文档中的 prc_bill 映射为本项目的 prc_order_bill。 -->
|
<!-- rename_bill_tables.sql 已将需求文档中的 prc_bill 映射为本项目的 prc_order_bill。 -->
|
||||||
<!-- 生成弹窗预览:按客户、截止日、币种和订单号/运单号/转单号 OR 条件分页查询未入账订单。 -->
|
<!-- 生成弹窗预览:按客户、截止日、币种和订单号/运单号/转单号 OR 条件分页查询未入账订单。 -->
|
||||||
<sql id="orderIdentifierCondition">
|
<sql id="orderIdentifierCondition">
|
||||||
|
|||||||
@@ -85,6 +85,50 @@ export function listOrderBillsByProduct(data) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Order-list local rebill (prc_order_bill only, no Oracle). Returns { taskId }. */
|
||||||
|
export function submitLocalRebill(data) {
|
||||||
|
return request({
|
||||||
|
url: '/price/billing/orderBill/rebill',
|
||||||
|
method: 'post',
|
||||||
|
data,
|
||||||
|
timeout: 120000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLocalRebillTask(taskId) {
|
||||||
|
return request({
|
||||||
|
url: '/price/billing/orderBill/rebill/task/' + taskId,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Async local rebill; poll until done.
|
||||||
|
* @param {object} data LocalRebillRequest
|
||||||
|
* @param {(task: object) => void} [onProgress]
|
||||||
|
*/
|
||||||
|
export async function localRebillAsync(data, onProgress) {
|
||||||
|
const submitRes = await submitLocalRebill(data)
|
||||||
|
const d = submitRes && submitRes.data
|
||||||
|
const taskId = d && (d.taskId || d)
|
||||||
|
if (!taskId) throw new Error('missing local rebill taskId')
|
||||||
|
const started = Date.now()
|
||||||
|
const maxMs = 30 * 60 * 1000
|
||||||
|
while (Date.now() - started < maxMs) {
|
||||||
|
const res = await getLocalRebillTask(String(taskId))
|
||||||
|
const task = res.data || {}
|
||||||
|
if (typeof onProgress === 'function') onProgress(task)
|
||||||
|
if (task.status === 'SUCCESS') return { task }
|
||||||
|
if (task.status === 'FAIL') {
|
||||||
|
const err = new Error(task.error || task.message || 'local rebill failed')
|
||||||
|
err.task = task
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 800))
|
||||||
|
}
|
||||||
|
throw new Error('local rebill timeout')
|
||||||
|
}
|
||||||
|
|
||||||
/** Receivable bill detail */
|
/** Receivable bill detail */
|
||||||
export function getBill(billId) {
|
export function getBill(billId) {
|
||||||
return request({
|
return request({
|
||||||
|
|||||||
@@ -39,8 +39,9 @@
|
|||||||
<div class="json-panel__head"><span>失败明细(共 {{ failRows.length }} 单)</span></div>
|
<div class="json-panel__head"><span>失败明细(共 {{ failRows.length }} 单)</span></div>
|
||||||
<el-table :data="failRows" border size="small" max-height="280" class="fail-table">
|
<el-table :data="failRows" border size="small" max-height="280" class="fail-table">
|
||||||
<el-table-column label="订单号" prop="orderId" min-width="160" show-overflow-tooltip />
|
<el-table-column label="订单号" prop="orderId" min-width="160" show-overflow-tooltip />
|
||||||
|
<el-table-column label="运单号" prop="trackingNo" min-width="140" show-overflow-tooltip />
|
||||||
<el-table-column label="转单号" prop="transferOrderId" min-width="140" show-overflow-tooltip />
|
<el-table-column label="转单号" prop="transferOrderId" min-width="140" show-overflow-tooltip />
|
||||||
<el-table-column label="错误信息" prop="errorMessage" min-width="220" show-overflow-tooltip />
|
<el-table-column label="错误信息" prop="errorMessage" min-width="240" show-overflow-tooltip />
|
||||||
</el-table>
|
</el-table>
|
||||||
</div>
|
</div>
|
||||||
<div class="json-panel">
|
<div class="json-panel">
|
||||||
@@ -113,6 +114,10 @@ function actionLabel(row) {
|
|||||||
if (action === 'COMPARE_DONE') {
|
if (action === 'COMPARE_DONE') {
|
||||||
return row.status === 'FAIL' ? '比对完成(失败)' : '比对完成'
|
return row.status === 'FAIL' ? '比对完成(失败)' : '比对完成'
|
||||||
}
|
}
|
||||||
|
if (action === 'LOCAL_REBILL') return '本地重新计费'
|
||||||
|
if (action === 'LOCAL_REBILL_DONE') {
|
||||||
|
return row.status === 'FAIL' ? '本地重新计费完成(有失败)' : '本地重新计费完成'
|
||||||
|
}
|
||||||
return action || '-'
|
return action || '-'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
type="primary"
|
type="primary"
|
||||||
plain
|
plain
|
||||||
icon="Refresh"
|
icon="Refresh"
|
||||||
|
:loading="batchLoading"
|
||||||
v-hasPermi="['price:orderBill:rebill']"
|
v-hasPermi="['price:orderBill:rebill']"
|
||||||
@click="openFilterRebill()"
|
@click="openFilterRebill()"
|
||||||
>重新计费</el-button>
|
>重新计费</el-button>
|
||||||
@@ -91,7 +92,35 @@
|
|||||||
<el-tag size="small" :type="billingFailTagType(row.billingFailStatus)">{{ billingFailLabel(row.billingFailStatus) }}</el-tag>
|
<el-tag size="small" :type="billingFailTagType(row.billingFailStatus)">{{ billingFailLabel(row.billingFailStatus) }}</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</basic-table>
|
</basic-table>
|
||||||
<order-source-sync-dialog ref="syncDialogRef" @success="onRebillSuccess" />
|
<el-dialog
|
||||||
|
v-model="rebillProgressVisible"
|
||||||
|
title="本地重新计费"
|
||||||
|
width="480px"
|
||||||
|
append-to-body
|
||||||
|
destroy-on-close
|
||||||
|
:close-on-click-modal="!batchLoading"
|
||||||
|
:close-on-press-escape="!batchLoading"
|
||||||
|
:show-close="!batchLoading"
|
||||||
|
>
|
||||||
|
<el-progress
|
||||||
|
:percentage="rebillProgressPercent"
|
||||||
|
:status="rebillProgressStatus"
|
||||||
|
:stroke-width="14"
|
||||||
|
striped
|
||||||
|
:striped-flow="batchLoading"
|
||||||
|
/>
|
||||||
|
<div class="rebill-progress__msg">{{ rebillProgressMessage }}</div>
|
||||||
|
<div class="rebill-progress__text">
|
||||||
|
总数 {{ rebillProgressTotal }}
|
||||||
|
/ 成功 {{ rebillProgressSuccess }}
|
||||||
|
/ 失败 {{ rebillProgressFail }}
|
||||||
|
</div>
|
||||||
|
<p v-if="batchLoading" class="rebill-progress__hint">请勿关闭页面,大量订单重新计费可能需要一些时间</p>
|
||||||
|
<template #footer>
|
||||||
|
<el-button v-if="!batchLoading" type="primary" @click="rebillProgressVisible = false">关闭</el-button>
|
||||||
|
<el-button v-else disabled>执行中...</el-button>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
<order-source-sync-log-drawer ref="logDrawerRef" />
|
<order-source-sync-log-drawer ref="logDrawerRef" />
|
||||||
<order-bill-product-check-drawer ref="productCheckDrawerRef" />
|
<order-bill-product-check-drawer ref="productCheckDrawerRef" />
|
||||||
</div>
|
</div>
|
||||||
@@ -99,18 +128,22 @@
|
|||||||
|
|
||||||
<script setup name="OrderBillQuery">
|
<script setup name="OrderBillQuery">
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
import { listOrderBill, listOrderNoOptions, listTrackingNoOptions, listTransferNoOptions } from '@/api/price/billing'
|
import { listOrderBill, listOrderNoOptions, listTrackingNoOptions, listTransferNoOptions, localRebillAsync } from '@/api/price/billing'
|
||||||
import { syncOrderSourceSelected } from '@/api/monitor/orderSource'
|
|
||||||
import OrderSourceSyncDialog from '../../monitor/orderSource/components/OrderSourceSyncDialog.vue'
|
|
||||||
import OrderSourceSyncLogDrawer from '../../monitor/orderSource/components/OrderSourceSyncLogDrawer.vue'
|
import OrderSourceSyncLogDrawer from '../../monitor/orderSource/components/OrderSourceSyncLogDrawer.vue'
|
||||||
import OrderBillProductCheckDrawer from './components/OrderBillProductCheckDrawer.vue'
|
import OrderBillProductCheckDrawer from './components/OrderBillProductCheckDrawer.vue'
|
||||||
|
|
||||||
const tableRef = ref()
|
const tableRef = ref()
|
||||||
const syncDialogRef = ref()
|
|
||||||
const logDrawerRef = ref()
|
const logDrawerRef = ref()
|
||||||
const productCheckDrawerRef = ref()
|
const productCheckDrawerRef = ref()
|
||||||
const checkLoading = ref(false)
|
const checkLoading = ref(false)
|
||||||
const batchLoading = ref(false)
|
const batchLoading = ref(false)
|
||||||
|
const rebillProgressVisible = ref(false)
|
||||||
|
const rebillProgressPercent = ref(0)
|
||||||
|
const rebillProgressMessage = ref('')
|
||||||
|
const rebillProgressStatus = ref(undefined)
|
||||||
|
const rebillProgressTotal = ref(0)
|
||||||
|
const rebillProgressSuccess = ref(0)
|
||||||
|
const rebillProgressFail = ref(0)
|
||||||
const tableHeight = ref(480)
|
const tableHeight = ref(480)
|
||||||
let tableResizeObserver = null
|
let tableResizeObserver = null
|
||||||
|
|
||||||
@@ -262,14 +295,27 @@ function currentIdentifiers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildRebillFilter() {
|
function buildRebillFilter() {
|
||||||
const q = tableRef.value?.getQueryParams?.() || {}
|
const q = applySearchRanges(tableRef.value?.getQueryParams?.() || {})
|
||||||
const filter = { orderIdentifiers: currentIdentifiers() }
|
const filter = {
|
||||||
if (Array.isArray(q.customerCodes) && q.customerCodes.length) {
|
scopeMode: 'ALL',
|
||||||
filter.customerCodes = q.customerCodes
|
orderIdentifiers: currentIdentifiers(),
|
||||||
|
customerCodes: Array.isArray(q.customerCodes) ? q.customerCodes : [],
|
||||||
|
productCodes: Array.isArray(q.productCodes) ? q.productCodes : [],
|
||||||
|
orderStatuses: Array.isArray(q.orderStatuses) ? q.orderStatuses : [],
|
||||||
|
billingFailStatuses: Array.isArray(q.billingFailStatuses) ? q.billingFailStatuses : [],
|
||||||
|
beginBizDate: q.params?.beginBizDate || null,
|
||||||
|
endBizDate: q.params?.endBizDate || null
|
||||||
}
|
}
|
||||||
return filter
|
return filter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasRebillFilter(filter) {
|
||||||
|
const ids = filter.orderIdentifiers || []
|
||||||
|
if (ids.length) return true
|
||||||
|
const hasCustomer = Array.isArray(filter.customerCodes) && filter.customerCodes.length > 0
|
||||||
|
const hasBizDate = !!(filter.beginBizDate && filter.endBizDate)
|
||||||
|
return hasCustomer && hasBizDate
|
||||||
|
}
|
||||||
|
|
||||||
function buildCheckQuery() {
|
function buildCheckQuery() {
|
||||||
const q = tableRef.value?.getQueryParams?.() || {}
|
const q = tableRef.value?.getQueryParams?.() || {}
|
||||||
@@ -293,40 +339,86 @@ function handleCheckProducts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function runLocalRebill(payload, confirmText) {
|
||||||
|
try {
|
||||||
|
await ElMessageBox.confirm(confirmText, '二次确认', { type: 'warning' })
|
||||||
|
} catch (e) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
batchLoading.value = true
|
||||||
|
rebillProgressVisible.value = true
|
||||||
|
rebillProgressPercent.value = 0
|
||||||
|
rebillProgressStatus.value = undefined
|
||||||
|
rebillProgressMessage.value = '任务提交中…'
|
||||||
|
rebillProgressTotal.value = 0
|
||||||
|
rebillProgressSuccess.value = 0
|
||||||
|
rebillProgressFail.value = 0
|
||||||
|
try {
|
||||||
|
const { task } = await localRebillAsync(payload, (t) => {
|
||||||
|
const total = Number(t.total) || 0
|
||||||
|
const success = Number(t.success) || 0
|
||||||
|
const fail = Number(t.fail) || 0
|
||||||
|
rebillProgressPercent.value = Math.min(100, Number(t.percent) || 0)
|
||||||
|
rebillProgressTotal.value = total
|
||||||
|
rebillProgressSuccess.value = success
|
||||||
|
rebillProgressFail.value = fail
|
||||||
|
if (t.status === 'PENDING') {
|
||||||
|
rebillProgressMessage.value = '排队中…'
|
||||||
|
} else if (t.status === 'RUNNING') {
|
||||||
|
rebillProgressMessage.value = '正在重新计费 ' + success + '/' + total +
|
||||||
|
(fail ? ('(失败 ' + fail + ')') : '')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const success = Number(task && task.success) || 0
|
||||||
|
const fail = Number(task && task.fail) || 0
|
||||||
|
rebillProgressPercent.value = 100
|
||||||
|
rebillProgressStatus.value = fail > 0 ? 'warning' : 'success'
|
||||||
|
rebillProgressTotal.value = Number(task && task.total) || rebillProgressTotal.value
|
||||||
|
rebillProgressSuccess.value = success
|
||||||
|
rebillProgressFail.value = fail
|
||||||
|
rebillProgressMessage.value = '完成:成功 ' + success + ' / 失败 ' + fail +
|
||||||
|
(fail && task.error ? (';' + task.error) : '')
|
||||||
|
tableRef.value?.refresh?.()
|
||||||
|
} catch (e) {
|
||||||
|
const task = e && e.task
|
||||||
|
rebillProgressStatus.value = 'exception'
|
||||||
|
rebillProgressMessage.value = (e && e.message) || '重新计费失败'
|
||||||
|
if (task) {
|
||||||
|
rebillProgressPercent.value = Math.min(100, Number(task.percent) || 100)
|
||||||
|
rebillProgressTotal.value = Number(task.total) || 0
|
||||||
|
rebillProgressSuccess.value = Number(task.success) || 0
|
||||||
|
rebillProgressFail.value = Number(task.fail) || 0
|
||||||
|
tableRef.value?.refresh?.()
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
batchLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function openFilterRebill() {
|
function openFilterRebill() {
|
||||||
const identifiers = currentIdentifiers()
|
const filter = buildRebillFilter()
|
||||||
if (!identifiers.length) {
|
const identifiers = filter.orderIdentifiers || []
|
||||||
ElMessage.warning('请输入单号后再重新计费,或勾选订单后点重新计费选中')
|
if (!hasRebillFilter(filter)) {
|
||||||
|
ElMessage.warning('请输入单号,或选择客户并选择计费时间后再重新计费;也可勾选订单后点重新计费选中')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (identifiers.length > MAX_REBILL) {
|
if (identifiers.length > MAX_REBILL) {
|
||||||
ElMessage.warning('单次最多重新计费 ' + MAX_REBILL + ' 个单号')
|
ElMessage.warning('单次最多重新计费 ' + MAX_REBILL + ' 个单号')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ElMessageBox.confirm(
|
let confirmText
|
||||||
'将按 ' + identifiers.length + ' 个单号查上游订单并重新计费,确认继续?',
|
if (identifiers.length) {
|
||||||
'二次确认',
|
confirmText = '将按 ' + identifiers.length + ' 个单号从本地订单表重新计费(不查上游),确认继续?'
|
||||||
{ type: 'warning' }
|
} else {
|
||||||
).then(() => {
|
confirmText = '将按当前列表筛选(客户 + 计费时间等)从本地订单表重新计费(不查上游),确认继续?'
|
||||||
syncDialogRef.value?.open(buildRebillFilter(), true)
|
|
||||||
}).catch(() => {})
|
|
||||||
}
|
|
||||||
|
|
||||||
function toSyncRow(row) {
|
|
||||||
return {
|
|
||||||
orderId: row.orderNo,
|
|
||||||
orgOrderId: row.trackingNo,
|
|
||||||
transferOrderId: row.transferNo,
|
|
||||||
customerCode: row.customerCode,
|
|
||||||
pickupDate: row.bizDate || row.pickupDate || row.orderTime || null
|
|
||||||
}
|
}
|
||||||
|
runLocalRebill(filter, confirmText)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function handleBatchRebill(selection) {
|
function handleBatchRebill(selection) {
|
||||||
const rows = selection || []
|
const rows = selection || []
|
||||||
if (!rows.length) return
|
if (!rows.length) return
|
||||||
const missingTime = rows.filter(row => !toSyncRow(row).pickupDate).length
|
const missingTime = rows.filter(row => !(row.bizDate || row.pickupDate || row.orderTime)).length
|
||||||
if (missingTime) {
|
if (missingTime) {
|
||||||
ElMessage.warning(missingTime + ' 条没有计费时间,无法重新计费')
|
ElMessage.warning(missingTime + ' 条没有计费时间,无法重新计费')
|
||||||
return
|
return
|
||||||
@@ -335,20 +427,15 @@ function handleBatchRebill(selection) {
|
|||||||
ElMessage.warning('选中重新计费最多 200 条')
|
ElMessage.warning('选中重新计费最多 200 条')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ElMessageBox.confirm('确认重新计费选中的 ' + rows.length + ' 条订单?', '二次确认', { type: 'warning' }).then(() => {
|
const billIds = rows.map(r => r.billId).filter(Boolean)
|
||||||
batchLoading.value = true
|
if (!billIds.length) {
|
||||||
return syncOrderSourceSelected(rows.map(toSyncRow))
|
ElMessage.warning('选中行缺少 billId,无法重新计费')
|
||||||
}).then(res => {
|
return
|
||||||
const data = (res && res.data) || {}
|
}
|
||||||
ElMessage.success('完成:成功 ' + (data.ok || 0) + ' / 失败 ' + (data.fail || 0))
|
runLocalRebill(
|
||||||
tableRef.value?.refresh?.()
|
{ scopeMode: 'SELECTED', billIds },
|
||||||
}).catch(() => {}).finally(() => {
|
'确认用本地订单数据重新计费选中的 ' + rows.length + ' 条订单?'
|
||||||
batchLoading.value = false
|
)
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function onRebillSuccess() {
|
|
||||||
tableRef.value?.refresh?.()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchOrderIdentifiers(keyword) {
|
function searchOrderIdentifiers(keyword) {
|
||||||
@@ -418,4 +505,7 @@ onBeforeUnmount(() => {
|
|||||||
.order-bill-query :deep(.basic-form .el-form-item .el-date-editor) {
|
.order-bill-query :deep(.basic-form .el-form-item .el-date-editor) {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
.rebill-progress__msg { margin-top: 12px; color: var(--el-text-color-regular); }
|
||||||
|
.rebill-progress__text { margin-top: 8px; font-size: 13px; color: var(--el-text-color-secondary); }
|
||||||
|
.rebill-progress__hint { margin-top: 12px; font-size: 12px; color: var(--el-color-warning); }
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user