|
@@ -2,28 +2,19 @@ package org.springblade.common.utils;
|
|
|
|
|
|
|
|
import com.yeepay.yop.sdk.exception.YopServiceException;
|
|
import com.yeepay.yop.sdk.exception.YopServiceException;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
-import org.springblade.common.enums.AppConstant;
|
|
|
|
|
import org.springblade.core.tool.api.R;
|
|
import org.springblade.core.tool.api.R;
|
|
|
-import org.springblade.ldt.bills.entity.BalanceBills;
|
|
|
|
|
-import org.springblade.ldt.bills.entity.Bills;
|
|
|
|
|
-import org.springblade.ldt.bills.entity.FrozenRec;
|
|
|
|
|
-import org.springblade.ldt.bills.entity.PointBills;
|
|
|
|
|
import org.springblade.ldt.bills.service.IBalanceBillsService;
|
|
import org.springblade.ldt.bills.service.IBalanceBillsService;
|
|
|
import org.springblade.ldt.bills.service.IBillsService;
|
|
import org.springblade.ldt.bills.service.IBillsService;
|
|
|
import org.springblade.ldt.bills.service.IFrozenRecService;
|
|
import org.springblade.ldt.bills.service.IFrozenRecService;
|
|
|
import org.springblade.ldt.bills.service.IPointBillsService;
|
|
import org.springblade.ldt.bills.service.IPointBillsService;
|
|
|
-import org.springblade.ldt.user.entity.LoginUser;
|
|
|
|
|
-import org.springblade.ldt.user.entity.UserChannelPoint;
|
|
|
|
|
import org.springblade.ldt.user.service.ILoginUserService;
|
|
import org.springblade.ldt.user.service.ILoginUserService;
|
|
|
import org.springblade.ldt.user.service.IUserChannelPointService;
|
|
import org.springblade.ldt.user.service.IUserChannelPointService;
|
|
|
-import org.springblade.payment.entity.SuccessParams;
|
|
|
|
|
|
|
+import org.springblade.payment.handle.handler.CancelTradeHandle;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author July
|
|
* @author July
|
|
@@ -35,12 +26,7 @@ import java.util.Objects;
|
|
|
@ControllerAdvice
|
|
@ControllerAdvice
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
public class GlobalExceptionHandler {
|
|
public class GlobalExceptionHandler {
|
|
|
- private ILoginUserService loginUserService;
|
|
|
|
|
- private IBillsService billsService;
|
|
|
|
|
- private IPointBillsService pointBillsService;
|
|
|
|
|
- private IBalanceBillsService balanceBillsService;
|
|
|
|
|
- private IFrozenRecService frozenRecService;
|
|
|
|
|
- private IUserChannelPointService userChannelPointService;
|
|
|
|
|
|
|
+ private CancelTradeHandle cancelTradeHandle;
|
|
|
|
|
|
|
|
@ExceptionHandler(YopServiceException.class)
|
|
@ExceptionHandler(YopServiceException.class)
|
|
|
public R defaultErrorHandler(YopServiceException e) {
|
|
public R defaultErrorHandler(YopServiceException e) {
|
|
@@ -50,49 +36,8 @@ public class GlobalExceptionHandler {
|
|
|
@Transactional
|
|
@Transactional
|
|
|
@ExceptionHandler(TradeException.class)
|
|
@ExceptionHandler(TradeException.class)
|
|
|
public R tradeErrorHandler(TradeException e) {
|
|
public R tradeErrorHandler(TradeException e) {
|
|
|
- SuccessParams successParams = e.getSuccessParams();
|
|
|
|
|
-
|
|
|
|
|
- if (ObjectUtils.isNotEmpty(successParams)) {
|
|
|
|
|
- Bills bills = successParams.getBills();
|
|
|
|
|
- synchronized (bills.getId().toString().intern()) {
|
|
|
|
|
- FrozenRec frozenRec = frozenRecService.getById(bills.getId());
|
|
|
|
|
- UserChannelPoint channelPoint = userChannelPointService.getById(successParams.getChannelId());
|
|
|
|
|
-
|
|
|
|
|
- //修改用户冻结余额或积分
|
|
|
|
|
- LoginUser user = loginUserService.getById(bills.getPayId());
|
|
|
|
|
- if (ObjectUtils.isNotEmpty(user)) {
|
|
|
|
|
- if (Objects.equals(frozenRec.getFrozenType(), "point")) {
|
|
|
|
|
- user.setChannelPoint(user.getChannelPoint().add(frozenRec.getFrozenNum()));
|
|
|
|
|
- user.setFrozenPoint(user.getFrozenPoint().subtract(frozenRec.getFrozenNum()));
|
|
|
|
|
- if (ObjectUtils.isNotEmpty(channelPoint)) {
|
|
|
|
|
- channelPoint.setAvailable(channelPoint.getAvailable().add(frozenRec.getFrozenNum()));
|
|
|
|
|
- userChannelPointService.saveOrUpdate(channelPoint);
|
|
|
|
|
- }
|
|
|
|
|
- } else if (Objects.equals(frozenRec.getFrozenType(), "balance")) {
|
|
|
|
|
- user.setBalance(user.getBalance().add(frozenRec.getFrozenNum()));
|
|
|
|
|
- user.setFrozenBalance(user.getFrozenBalance().subtract(frozenRec.getFrozenNum()));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (ObjectUtils.isNotEmpty(frozenRec)) {
|
|
|
|
|
- frozenRecService.removeById(frozenRec);
|
|
|
|
|
- }
|
|
|
|
|
- loginUserService.saveOrUpdate(user);
|
|
|
|
|
- }
|
|
|
|
|
- bills.setPayStatus(AppConstant.BillPayStatus.取消付款.name());
|
|
|
|
|
- billsService.saveOrUpdate(bills);
|
|
|
|
|
-
|
|
|
|
|
- PointBills pointBills = pointBillsService.getById(successParams.getPointBillsId());
|
|
|
|
|
- if (ObjectUtils.isNotEmpty(pointBills)) {
|
|
|
|
|
- pointBills.setPayStatus(AppConstant.BillPayStatus.取消付款.name());
|
|
|
|
|
- pointBillsService.saveOrUpdate(pointBills);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- BalanceBills balanceBills = balanceBillsService.getById(successParams.getBalanceBillsId());
|
|
|
|
|
- if (ObjectUtils.isNotEmpty(balanceBills)) {
|
|
|
|
|
- balanceBills.setPayStatus(AppConstant.BillPayStatus.取消付款.name());
|
|
|
|
|
- balanceBillsService.saveOrUpdate(balanceBills);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(e.getSuccessParams())) {
|
|
|
|
|
+ cancelTradeHandle.handle(e.getSuccessParams());
|
|
|
}
|
|
}
|
|
|
return R.fail(e.getResultCode(), e.getMessage());
|
|
return R.fail(e.getResultCode(), e.getMessage());
|
|
|
}
|
|
}
|