统一修改ruoyi->bms
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package com.bms.price.task;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.bms.price.service.IPrcPriceSetService;
|
||||
|
||||
/**
|
||||
* Refresh prc_price_set_version status (draft/pending/effect/expired).
|
||||
* Startup + every 3 hours so PENDING becomes EFFECT when effective_time is reached.
|
||||
*/
|
||||
@Component
|
||||
public class BmsStatusRefreshTask implements ApplicationRunner
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(BmsStatusRefreshTask.class);
|
||||
|
||||
@Autowired
|
||||
private IPrcPriceSetService priceSetService;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args)
|
||||
{
|
||||
refresh("startup");
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 0/3 * * ?")
|
||||
public void scheduledRefresh()
|
||||
{
|
||||
refresh("scheduled");
|
||||
}
|
||||
|
||||
private void refresh(String scene)
|
||||
{
|
||||
try
|
||||
{
|
||||
int n = priceSetService.refreshAllVersionStatus();
|
||||
log.info("{} prc_price_set_version expire/status refreshed, sets={}", scene, n);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("{} prc_price_set_version refresh failed", scene, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
package com.bms.price.task;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.bms.common.utils.StringUtils;
|
||||
import com.bms.price.domain.PrcOrderBill;
|
||||
import com.bms.price.enums.BillCreditArrearsStatus;
|
||||
import com.bms.price.mapper.PrcOrderBillMapper;
|
||||
import com.bms.price.search.EsBizLogSupport;
|
||||
import com.bms.price.search.EsLogType;
|
||||
import com.bms.price.search.IBillSearchStore;
|
||||
|
||||
/**
|
||||
* 异步清除订单额度欠费状态(余额充值等审核入账后)。
|
||||
* 自行注入 Mapper / ES,避免与 IPrcOrderBillService 循环依赖。
|
||||
*/
|
||||
@Component
|
||||
public class PrcCreditArrearsClearAsyncRunner
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(PrcCreditArrearsClearAsyncRunner.class);
|
||||
|
||||
@Autowired
|
||||
private PrcOrderBillMapper orderBillMapper;
|
||||
|
||||
@Autowired(required = false)
|
||||
private IBillSearchStore billSearchStore;
|
||||
|
||||
@Async("threadPoolTaskExecutor")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void run(String customerCode, BigDecimal amount)
|
||||
{
|
||||
String code = StringUtils.trim(customerCode);
|
||||
try
|
||||
{
|
||||
if (StringUtils.isEmpty(code) || amount == null || amount.compareTo(BigDecimal.ZERO) <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
BigDecimal remaining = amount;
|
||||
List<PrcOrderBill> bills = orderBillMapper.selectArrearsByCustomerCode(code,
|
||||
BillCreditArrearsStatus.ARREARS.getCode());
|
||||
if (bills == null || bills.isEmpty())
|
||||
{
|
||||
saveSummaryEsLog(code, amount, 0, remaining, true, "no arrears orders");
|
||||
return;
|
||||
}
|
||||
String normal = BillCreditArrearsStatus.NORMAL.getCode();
|
||||
int updated = 0;
|
||||
for (PrcOrderBill bill : bills)
|
||||
{
|
||||
BigDecimal orderAmt = nz(bill.getIncomeTotal());
|
||||
if (orderAmt.compareTo(remaining) > 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
orderBillMapper.updateCreditArrearsStatus(bill.getBillId(), normal, "receipt");
|
||||
remaining = remaining.subtract(orderAmt);
|
||||
updated++;
|
||||
saveOrderEsLog(bill, amount, orderAmt, remaining, true, null);
|
||||
if (remaining.compareTo(BigDecimal.ZERO) <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
saveSummaryEsLog(code, amount, updated, remaining, true, null);
|
||||
log.info("async clear credit arrears done, customerCode={}, amount={}, updated={}",
|
||||
code, amount, Integer.valueOf(updated));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("async clear credit arrears failed, customerCode={}, amount={}",
|
||||
code, amount, e);
|
||||
String msg = e.getMessage();
|
||||
if (StringUtils.isEmpty(msg))
|
||||
{
|
||||
msg = e.getClass().getSimpleName();
|
||||
}
|
||||
saveSummaryEsLog(code, amount, 0, amount, false, msg);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private void saveSummaryEsLog(String customerCode, BigDecimal amount, int updated,
|
||||
BigDecimal remaining, boolean success, String note)
|
||||
{
|
||||
if (billSearchStore == null || StringUtils.isEmpty(customerCode))
|
||||
{
|
||||
return;
|
||||
}
|
||||
JSONObject req = new JSONObject();
|
||||
req.put("action", "CLEAR_ARREARS");
|
||||
req.put("scope", "SUMMARY");
|
||||
req.put("customerCode", customerCode);
|
||||
req.put("amount", amount);
|
||||
JSONObject resp = new JSONObject();
|
||||
resp.put("success", Boolean.valueOf(success));
|
||||
resp.put("updatedCount", Integer.valueOf(updated));
|
||||
resp.put("remainingAmount", remaining);
|
||||
if (StringUtils.isNotEmpty(note))
|
||||
{
|
||||
resp.put("msg", note);
|
||||
}
|
||||
String status = success ? EsBizLogSupport.STATUS_SUCCESS : EsBizLogSupport.STATUS_FAIL;
|
||||
String err = success ? null : EsBizLogSupport.cut(note);
|
||||
billSearchStore.save(EsLogType.ARREARS, customerCode, req.toJSONString(), resp.toJSONString(), status, err);
|
||||
}
|
||||
|
||||
private void saveOrderEsLog(PrcOrderBill bill, BigDecimal batchAmount, BigDecimal orderAmt,
|
||||
BigDecimal remaining, boolean success, String errorMessage)
|
||||
{
|
||||
if (billSearchStore == null || bill == null || StringUtils.isEmpty(bill.getOrderNo()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
JSONObject req = new JSONObject();
|
||||
req.put("action", "CLEAR_ARREARS");
|
||||
req.put("scope", "ORDER");
|
||||
req.put("orderNo", bill.getOrderNo());
|
||||
req.put("billId", bill.getBillId());
|
||||
req.put("customerCode", bill.getCustomerCode());
|
||||
req.put("batchAmount", batchAmount);
|
||||
req.put("orderIncomeTotal", orderAmt);
|
||||
req.put("fromStatus", BillCreditArrearsStatus.ARREARS.getCode());
|
||||
req.put("toStatus", BillCreditArrearsStatus.NORMAL.getCode());
|
||||
JSONObject resp = new JSONObject();
|
||||
resp.put("success", Boolean.valueOf(success));
|
||||
resp.put("remainingAmount", remaining);
|
||||
if (StringUtils.isNotEmpty(errorMessage))
|
||||
{
|
||||
resp.put("msg", errorMessage);
|
||||
}
|
||||
String status = success ? EsBizLogSupport.STATUS_SUCCESS : EsBizLogSupport.STATUS_FAIL;
|
||||
String err = success ? null : EsBizLogSupport.cut(errorMessage);
|
||||
billSearchStore.save(EsLogType.ARREARS, bill.getOrderNo(), req.toJSONString(), resp.toJSONString(), status, err);
|
||||
}
|
||||
|
||||
private static BigDecimal nz(BigDecimal v)
|
||||
{
|
||||
return v == null ? BigDecimal.ZERO : v;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.bms.price.task;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.domain.PrcPriceSet;
|
||||
import com.bms.price.domain.PrcPriceSetDetail;
|
||||
import com.bms.price.domain.PrcPriceSetSaveTask;
|
||||
import com.bms.price.service.IPrcPriceSetService;
|
||||
|
||||
/**
|
||||
* Async runner for price-set save (avoids HTTP timeout on large detail snapshots).
|
||||
*/
|
||||
@Component
|
||||
public class PrcPriceSetSaveAsyncRunner
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(PrcPriceSetSaveAsyncRunner.class);
|
||||
|
||||
public static final String CACHE_KEY_PREFIX = "price:set:save:task:";
|
||||
public static final int TTL_MINUTES = 60;
|
||||
|
||||
@Autowired
|
||||
private IPrcPriceSetService priceSetService;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Async("threadPoolTaskExecutor")
|
||||
public void run(String taskId, PrcPriceSet set)
|
||||
{
|
||||
try
|
||||
{
|
||||
put(taskId, PrcPriceSetSaveTask.STATUS_RUNNING, 8, "saving basic", null, null);
|
||||
set.setSaveTaskId(taskId);
|
||||
Long id = priceSetService.savePrcPriceSet(set);
|
||||
put(taskId, PrcPriceSetSaveTask.STATUS_SUCCESS, 100, "done", id, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("async save price set failed, taskId={}", taskId, e);
|
||||
String msg = e.getMessage();
|
||||
if (StringUtils.isEmpty(msg))
|
||||
{
|
||||
msg = e.getClass().getSimpleName();
|
||||
}
|
||||
put(taskId, PrcPriceSetSaveTask.STATUS_FAIL, 100, "failed", null, msg);
|
||||
}
|
||||
}
|
||||
|
||||
/** Background write of detail surcharge snapshots for many rows. */
|
||||
@Async("threadPoolTaskExecutor")
|
||||
public void runSurchargeBatch(String taskId, List<PrcPriceSetDetail> details)
|
||||
{
|
||||
try
|
||||
{
|
||||
put(taskId, PrcPriceSetSaveTask.STATUS_RUNNING, 10, "saving surcharges", null, null);
|
||||
int rows = priceSetService.batchUpdateDetailSurcharges(details);
|
||||
put(taskId, PrcPriceSetSaveTask.STATUS_SUCCESS, 100, "done", null, null);
|
||||
log.info("async surcharge batch done, taskId={}, rows={}", taskId, rows);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("async surcharge batch failed, taskId={}", taskId, e);
|
||||
String msg = e.getMessage();
|
||||
if (StringUtils.isEmpty(msg))
|
||||
{
|
||||
msg = e.getClass().getSimpleName();
|
||||
}
|
||||
put(taskId, PrcPriceSetSaveTask.STATUS_FAIL, 100, "failed", null, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void put(String taskId, String status, int percent, String message, Long priceSetId, String error)
|
||||
{
|
||||
PrcPriceSetSaveTask task = new PrcPriceSetSaveTask();
|
||||
task.setTaskId(taskId);
|
||||
task.setStatus(status);
|
||||
task.setPercent(percent);
|
||||
task.setMessage(message);
|
||||
task.setPriceSetId(priceSetId);
|
||||
task.setError(error);
|
||||
redisCache.setCacheObject(CACHE_KEY_PREFIX + taskId, task, TTL_MINUTES, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
public PrcPriceSetSaveTask get(String taskId)
|
||||
{
|
||||
return redisCache.getCacheObject(CACHE_KEY_PREFIX + taskId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user