提现异步回调 执行时间问题
This commit is contained in:
parent
59dd621bab
commit
17213fafd9
|
|
@ -2,9 +2,7 @@ package com.sqx.modules.pay.controller.app;
|
|||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.amazonaws.services.dynamodbv2.xspec.S;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sqx.common.annotation.Debounce;
|
||||
import com.sqx.common.utils.DateUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
|
|
@ -36,7 +34,6 @@ import io.swagger.annotations.Api;
|
|||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
|
@ -46,6 +43,9 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
|
|
@ -67,7 +67,7 @@ public class WuyouController {
|
|||
private final CashOutDao cashOutDao;
|
||||
private final CompletAwardService completAwardService;
|
||||
private final SysUserService sysUserService;
|
||||
|
||||
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
|
||||
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
WuyouController(OrdersService ordersService, PayDetailsDao payDetailsDao, UserService userService, InviteService inviteService, CashOutDao cashOutDao,
|
||||
|
|
@ -169,45 +169,17 @@ public class WuyouController {
|
|||
|
||||
@PostMapping("/extractNotify")
|
||||
public String extractNotify(HttpServletRequest request, NotifyDto notifyDto) {
|
||||
log.info("无忧支付提现回调, {}", notifyDto);
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("callbacks", notifyDto.getCallbacks());
|
||||
params.put("total", notifyDto.getTotal());
|
||||
params.put("out_trade_no", notifyDto.getOut_trade_no());
|
||||
params.put("status", notifyDto.getStatus());
|
||||
params.put("msg", notifyDto.getMsg());
|
||||
|
||||
String sign = Encrypt.getParamsSign(params);
|
||||
if (!sign.equals(notifyDto.getSign())) {
|
||||
log.error("无忧支付提现回调签名错误, 参数: {},签名结果:{}", JSONObject.toJSONString(notifyDto), sign);
|
||||
// return "签名错误";
|
||||
}
|
||||
CashOut cashOut = cashOutDao.selectOne(new QueryWrapper<CashOut>().eq("order_number", notifyDto.getOut_trade_no()));
|
||||
if (cashOut != null) {
|
||||
if ("2".equals(notifyDto.getStatus())) {
|
||||
cashOut.setState(1);
|
||||
cashOut.setOutAt(DateUtil.now());
|
||||
} else if(!cashOut.getState().equals(2)){
|
||||
cashOut.setState(2);
|
||||
cashOut.setRefund(notifyDto.getMsg());
|
||||
if(StringUtils.isNotBlank(notifyDto.getMsg()) && notifyDto.getMsg().contains("已驳回")){
|
||||
cashOut.setRefund("提现失败,请检查支付宝账号与收款人姓名后,重试。");
|
||||
}
|
||||
|
||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails(
|
||||
cashOut.getUserId(), null, null, "提现失败", 4, 1, 1,
|
||||
new BigDecimal(cashOut.getMoney()), "提现失败存入余额" + cashOut.getMoney() + "元", 1);
|
||||
//存入余额 钱
|
||||
userMoneyService.updateAmount(1, cashOut.getUserId(), Double.parseDouble(cashOut.getMoney()));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
}else{
|
||||
return "success";
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
scheduledExecutorService.schedule(() -> updateCashAsync(notifyDto), 3, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
cashOutDao.updateById(cashOut);
|
||||
}
|
||||
});
|
||||
return "success";
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/notify")
|
||||
public String notify(HttpServletRequest request, NotifyDto notifyDto) {
|
||||
log.info("无忧支付回调, {}", notifyDto);
|
||||
|
|
@ -363,4 +335,42 @@ public class WuyouController {
|
|||
activities(user, byUser);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void updateCashAsync(NotifyDto notifyDto){
|
||||
log.info("无忧支付提现回调, {}", notifyDto);
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("callbacks", notifyDto.getCallbacks());
|
||||
params.put("total", notifyDto.getTotal());
|
||||
params.put("out_trade_no", notifyDto.getOut_trade_no());
|
||||
params.put("status", notifyDto.getStatus());
|
||||
params.put("msg", notifyDto.getMsg());
|
||||
|
||||
String sign = Encrypt.getParamsSign(params);
|
||||
if (!sign.equals(notifyDto.getSign())) {
|
||||
log.error("无忧支付提现回调签名错误, 参数: {},签名结果:{}", JSONObject.toJSONString(notifyDto), sign);
|
||||
// return "签名错误";
|
||||
}
|
||||
CashOut cashOut = cashOutDao.selectOne(new QueryWrapper<CashOut>().eq("order_number", notifyDto.getOut_trade_no()));
|
||||
if (cashOut != null) {
|
||||
if ("2".equals(notifyDto.getStatus())) {
|
||||
cashOut.setState(1);
|
||||
cashOut.setOutAt(DateUtil.now());
|
||||
} else if(!cashOut.getState().equals(2)){
|
||||
cashOut.setState(2);
|
||||
cashOut.setRefund(notifyDto.getMsg());
|
||||
if(StringUtils.isNotBlank(notifyDto.getMsg()) && notifyDto.getMsg().contains("已驳回")){
|
||||
cashOut.setRefund("提现失败,请检查支付宝账号与收款人姓名后,重试。");
|
||||
}
|
||||
|
||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails(
|
||||
cashOut.getUserId(), null, null, "提现失败", 4, 1, 1,
|
||||
new BigDecimal(cashOut.getMoney()), "提现失败存入余额" + cashOut.getMoney() + "元", 1);
|
||||
//存入余额 钱
|
||||
userMoneyService.updateAmount(1, cashOut.getUserId(), Double.parseDouble(cashOut.getMoney()));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
}
|
||||
cashOutDao.updateById(cashOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue