|
|
@@ -2,7 +2,7 @@ package org.dromara.backstage.business.payments;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.core.util.ObjUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -26,7 +26,6 @@ import org.dromara.common.json.utils.JsonUtils;
|
|
|
import org.dromara.common.redis.utils.CacheUtils;
|
|
|
import org.dromara.consume.api.RemoteConsumeService;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
-import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -34,7 +33,6 @@ import java.math.BigDecimal;
|
|
|
import java.text.MessageFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
|
import java.util.concurrent.atomic.LongAdder;
|
|
|
@@ -54,11 +52,9 @@ import java.util.concurrent.atomic.LongAdder;
|
|
|
@Slf4j
|
|
|
public class PayOrderBusiness {
|
|
|
private final PayBaseBusiness payBaseBusiness;
|
|
|
- private final ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
|
|
|
@DubboReference
|
|
|
private final RemoteConsumeService remoteConsumeService;
|
|
|
- private final SpringUtils springUtils;
|
|
|
|
|
|
/**
|
|
|
* 生成收支原始订单信息,写t_xf_creditAccountBack表
|
|
|
@@ -136,12 +132,12 @@ public class PayOrderBusiness {
|
|
|
public R<PurseInOutBo> createNormalOrder(PurseInOutBo orderBo) {
|
|
|
// 将收支请求写入原始收支记录表
|
|
|
log.info("[准备创建{}订单-[{}]", CreditTypeEnum.getMessage(Integer.parseInt(orderBo.getCreditType())), JSONUtil.toJsonStr(orderBo));
|
|
|
- XfCreditAccountBackVo OriginalOrder = createOrder(orderBo);
|
|
|
- orderBo.setOriginalId(OriginalOrder.getBackId());
|
|
|
+ XfCreditAccountBackVo originalOrder = createOrder(orderBo);
|
|
|
+ orderBo.setOriginalId(originalOrder.getBackId());
|
|
|
|
|
|
// 原始收支记录成功,收支入账
|
|
|
log.info("准备[{}订单入账]-[{}]", CreditTypeEnum.getMessage(Integer.parseInt(orderBo.getCreditType())), JSONUtil.toJsonStr(orderBo));
|
|
|
- PurseInOutBo result = postOrder(orderBo);
|
|
|
+ PurseInOutBo result = SpringUtils.getAopProxy(this).postOrder(orderBo);
|
|
|
|
|
|
return R.ok(result);
|
|
|
}
|
|
|
@@ -149,14 +145,13 @@ public class PayOrderBusiness {
|
|
|
/**
|
|
|
* 补助收支入账
|
|
|
*
|
|
|
- * @return 入账结果
|
|
|
*/
|
|
|
@Async("threadPoolTaskExecutor")
|
|
|
public void createSubsidyOrder() {
|
|
|
// 获取需要入账的补助明细
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
List<PtSubsidyitemVo> list = payBaseBusiness.selectPostSubsidyItem();
|
|
|
- if (ObjUtil.isEmpty(list) || list.isEmpty()) {
|
|
|
+ if (ObjectUtil.isEmpty(list) || list.isEmpty()) {
|
|
|
log.info("[补助到账]-[没有需要入账的补助明细]");
|
|
|
}
|
|
|
// 使用线程安全的计数器和集合
|
|
|
@@ -170,22 +165,16 @@ public class PayOrderBusiness {
|
|
|
|
|
|
try {
|
|
|
List<CompletableFuture<Void>> batchFutures = batches.stream()
|
|
|
- .map(batch -> CompletableFuture.runAsync(() -> {
|
|
|
- batch.parallelStream().forEach(item -> {
|
|
|
-
|
|
|
- R<PurseInOutBo> result = doSubsidyOrderHandle(item);
|
|
|
-
|
|
|
- if (R.isSuccess(result)) {
|
|
|
- successCount.increment();
|
|
|
- } else {
|
|
|
- failCount.increment();
|
|
|
- errInfo.add(new StringBuilder()
|
|
|
- .append('[').append(result.getMsg()).append("]-[")
|
|
|
- .append(JsonUtils.toJsonString(item)).append(']')
|
|
|
- .toString());
|
|
|
- }
|
|
|
- });
|
|
|
- }))
|
|
|
+ .map(batch -> CompletableFuture.runAsync(() -> batch.parallelStream().forEach(item -> {
|
|
|
+ R<PurseInOutBo> result = doSubsidyOrderHandle(item);
|
|
|
+ if (result.getCode()==R.SUCCESS) {
|
|
|
+ successCount.increment();
|
|
|
+ } else {
|
|
|
+ failCount.increment();
|
|
|
+ errInfo.add('[' + result.getMsg() + "]-[" +
|
|
|
+ JsonUtils.toJsonString(item) + ']');
|
|
|
+ }
|
|
|
+ })))
|
|
|
.toList();
|
|
|
|
|
|
// 等待所有批次完成
|
|
|
@@ -200,16 +189,6 @@ public class PayOrderBusiness {
|
|
|
if (!errInfo.isEmpty()) {
|
|
|
log.error("补助到账失败详情: {}", String.join("; ", errInfo));
|
|
|
}
|
|
|
-
|
|
|
- //list.parallelStream().forEach(item -> {
|
|
|
- // // doSubsidyOrderHandle(item, mapCount, infoList);
|
|
|
- // // 使用线程池进行补助入账
|
|
|
- // threadPoolTaskExecutor.execute(() -> doSubsidyOrderHandle(item, mapCount, infoList));
|
|
|
- //});
|
|
|
- //java.lang.String message = MessageFormat.format("补助到账完成,成功[{0}]条,失败[{1}]条", mapCount.get("successCount"), mapCount.get("errorCount"));
|
|
|
- //infoList.forEach(log::error);
|
|
|
- //log.info(message);
|
|
|
- //return R.ok(message);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -235,12 +214,12 @@ public class PayOrderBusiness {
|
|
|
PurseInOutBo commissionBo = computeCommission(bo);
|
|
|
try {
|
|
|
if (commissionBo != null) {
|
|
|
- R<PurseInOutBo> commissionResult = createNormalOrder(commissionBo);
|
|
|
+ R<PurseInOutBo> commissionResult = SpringUtils.getAopProxy(this).createNormalOrder(commissionBo);
|
|
|
if (commissionResult.getCode() != R.SUCCESS) {
|
|
|
return R.fail(commissionResult.getMsg());
|
|
|
}
|
|
|
}
|
|
|
- R<PurseInOutBo> result = createNormalOrder(bo);
|
|
|
+ R<PurseInOutBo> result = SpringUtils.getAopProxy(this).createNormalOrder(bo);
|
|
|
if (result.getCode() == R.SUCCESS) {
|
|
|
// 如果充值成功,更新缓存中的余额
|
|
|
updateCacheBalanceByUserId(bo.getUserId(), bo.getReceiptMoney(), bo.getBagCode());
|
|
|
@@ -270,7 +249,7 @@ public class PayOrderBusiness {
|
|
|
// 退款是记支出,所以金额设置为负数
|
|
|
boCopy.setReceiptMoney(boCopy.getReceiptMoney().negate());
|
|
|
try {
|
|
|
- R<PurseInOutBo> result = createNormalOrder(boCopy);
|
|
|
+ R<PurseInOutBo> result = SpringUtils.getAopProxy(this).createNormalOrder(boCopy);
|
|
|
if (result.getCode() == R.SUCCESS) {
|
|
|
// 如果退款成功,更新缓存中的余额
|
|
|
updateCacheBalanceByUserId(bo.getUserId(), boCopy.getReceiptMoney(),bo.getBagCode());
|
|
|
@@ -306,41 +285,14 @@ public class PayOrderBusiness {
|
|
|
return orderBo;
|
|
|
}
|
|
|
|
|
|
- private void doSubsidyOrderHandle(PtSubsidyitemVo item, Map<String, Integer> mapCount, List<String> infoList) {
|
|
|
- PurseInOutBo orderBo = createSubsidyPostBo(item);
|
|
|
- int successCount;
|
|
|
- int errorCount;
|
|
|
-
|
|
|
- try {
|
|
|
- R<PurseInOutBo> result = createNormalOrder(orderBo);
|
|
|
- if (result.getCode() == R.SUCCESS) {
|
|
|
- // 到账成功,更新补助明细的 到账状态
|
|
|
- item.setGetDate(DateUtil.date());
|
|
|
- item.setFillStatus("Y");
|
|
|
- PtSubsidyitemBo bo = BeanUtil.copyProperties(item, PtSubsidyitemBo.class);
|
|
|
- boolean bl = payBaseBusiness.updatePostSubsidyItemStatus(bo);
|
|
|
- if (bl) {
|
|
|
- successCount = mapCount.get("successCount");
|
|
|
- successCount++;
|
|
|
- mapCount.put("successCount", successCount);
|
|
|
- }
|
|
|
- } else {
|
|
|
- errorCount = mapCount.get("errorCount");
|
|
|
- errorCount++;
|
|
|
- mapCount.put("errorCount", errorCount);
|
|
|
- infoList.add(MessageFormat.format("[补助到账失败]-[补助信息:{0}]-[错误信息:{1}]", JSONUtil.toJsonStr(orderBo),
|
|
|
- result.getData().toString()));
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- infoList.add(MessageFormat.format("[补助到账失败]-[补助信息:{0}]-[错误信息:{1}]", JSONUtil.toJsonStr(orderBo), e.getMessage()));
|
|
|
- }
|
|
|
- }
|
|
|
private R<PurseInOutBo> doSubsidyOrderHandle(PtSubsidyitemVo item) {
|
|
|
PurseInOutBo orderBo = createSubsidyPostBo(item);
|
|
|
|
|
|
try {
|
|
|
R<PurseInOutBo> result = SpringUtils.getAopProxy(this).createNormalOrder(orderBo);
|
|
|
- if(R.isSuccess(result)) {
|
|
|
+ if (result.getCode() == R.SUCCESS) {
|
|
|
+ // 到账成功,更新补助明细到账状态,同时更新个人余额缓存
|
|
|
+ updateCacheBalanceByUserId(orderBo.getUserId(), orderBo.getReceiptMoney(),orderBo.getBagCode());
|
|
|
// 到账成功,更新补助明细的 到账状态
|
|
|
item.setGetDate(DateUtil.date());
|
|
|
item.setFillStatus("Y");
|
|
|
@@ -352,11 +304,6 @@ public class PayOrderBusiness {
|
|
|
return R.fail(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
- private void updateCacheBalanceByUserId(Long id, BigDecimal dealMoney) {
|
|
|
- BigDecimal balance = remoteConsumeService.getUserTotalBalance(id);
|
|
|
- balance = balance.add(dealMoney);
|
|
|
- remoteConsumeService.cacheUserTotalBalance(id, balance);
|
|
|
- }
|
|
|
|
|
|
private void updateCacheBalanceByUserId(Long id, BigDecimal dealMoney, String bagCode) {
|
|
|
String key = String.format("%s_%s", id, bagCode);
|