优化话费业务流程

dev-discount
袁野 2 years ago
parent 06897dc4de
commit 302736a0c9
  1. 2
      hai-bweb/src/main/java/com/bweb/controller/HighTestController.java
  2. 44
      hai-order/src/main/java/com/web/controller/notify/MobileRechargeNotifyController.java
  3. 2
      hai-schedule/src/main/java/com/hai/schedule/HighRechargeOrderSchedule.java
  4. 2
      hai-service/src/main/java/com/hai/config/RechargeConfig.java
  5. 11
      hai-service/src/main/java/com/hai/service/OutRechargeOrderService.java
  6. 58
      hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java

File diff suppressed because one or more lines are too long

@ -32,11 +32,6 @@ public class MobileRechargeNotifyController {
private static Logger log = LoggerFactory.getLogger(OutRechargeOrderServiceImpl.class);
@Resource
private OutRechargeOrderService outRechargeOrderService;
@Resource
private OutRechargeChildOrderService outRechargeChildOrderService;
@RequestMapping(value = "/rechargeCallbackByJj", method = RequestMethod.POST)
@ -51,14 +46,6 @@ public class MobileRechargeNotifyController {
log.info("尖椒订单充值-回调参数: " + dataObject);
log.info("============回调任务End=============");
// 判断是否充值成功
if (dataObject.getInteger("status") == 3) {
// 充值成功操作
outRechargeOrderService.completeOrder(dataObject.getString("out_order_id"));
} else {
// 充值失败操作
callbackResult(dataObject.getString("out_order_id"));
}
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
@ -87,12 +74,6 @@ public class MobileRechargeNotifyController {
log.info("龙阅订单充值-回调参数: " + reqBodyStr);
log.info("============回调任务End=============");
// 判断是否充值成功
if (state == 1) {
outRechargeOrderService.completeOrder(out_trade_num);
} else {
callbackResult(out_trade_num);
}
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
@ -141,15 +122,6 @@ public class MobileRechargeNotifyController {
log.info("畅停订单充值-回调参数: " + dataObject);
log.info("============回调任务End=============");
// 判断是否充值成功 并发送微信小程序服务通知
if (Objects.equals(status, "1")) {
outRechargeOrderService.completeOrder(orderid);
} else {
// 充值失败操作
callbackResult(orderid);
}
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
@ -163,20 +135,4 @@ public class MobileRechargeNotifyController {
}
// 充值回调结果处理
private void callbackResult(String orderNo) {
OutRechargeChildOrder childOrder = outRechargeChildOrderService.findByOrderNo(orderNo);
// 查询充值订单
OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderId(childOrder.getParentOrderId());
childOrder.setStatus(103);
childOrder.setUpdateTime(new Date());
outRechargeChildOrderService.updateOrder(childOrder);
rechargeOrder.setRechargeStatus(205);
outRechargeOrderService.updateOrder(rechargeOrder);
}
}

@ -55,7 +55,7 @@ public class HighRechargeOrderSchedule {
* @Date 14:18 2022/5/31
* @Param []
*/
@Scheduled(cron = "0 0/1 * * * ?") //每5分钟执行一次
@Scheduled(cron = "0 0/120 * * * ?") //每120分钟执行一次
public void initRechargeOrder() {
log.info("处理话费订单定时任务开始");
Map<String, Object> map = new HashMap<>();

@ -211,7 +211,7 @@ public class RechargeConfig {
paramMap.put("orderid" , object.getString("orderid"));
paramMap.put("sign", WxUtils.generateSignatureHg(paramMap , CommonSysConst.getSysConfig().getHgApiKey() , WXPayConstants.SignType.MD5));
log.info("发起畅停话费查询订单=");
log.info("发起畅停话费查询订单");
log.info("畅停话费查询订单-请求参数: " + JSON.toJSONString(paramMap));
JSONObject jsonObject = HttpsUtils.doPostForm(CommonSysConst.getSysConfig().getHgPostUrl()+ "external/api/searchOrder", paramSort(paramMap) , new HashMap<>());

@ -165,7 +165,7 @@ public interface OutRechargeOrderService {
* @Param [order, childOrder]
* @Return void
*/
void completeOrder(String orderNo);
void completeOrder(Long orderId);
/**
@ -199,4 +199,13 @@ public interface OutRechargeOrderService {
*/
Integer getRechargeOrderLegality(OutRechargeChildOrder childOrder) throws Exception;
/**
* @Author Sum1Dream
* @Name orderWhetherRecharge
* @Description // 订单是否可以充值
* @Date 16:11 2023/3/28
* @Param [childOrder]
* @Return java.lang.Integer 1满足继续充值条件 2订单满足退款条件 3订单不可以退款不可以继续充值 4:订单异常 5:订单充值完成
*/
Integer orderWhetherRecharge(OutRechargeOrder rechargeOrder) throws Exception;
}

@ -7,10 +7,10 @@ import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.security.AESEncodeUtil;
import com.hai.common.utils.*;
import com.hai.config.*;
import com.hai.dao.HighGasOrderPushMapper;
import com.hai.dao.OutRechargeOrderMapper;
import com.hai.dao.OutRechargeOrderMapperExt;
import com.hai.entity.*;
@ -22,12 +22,14 @@ import com.hai.order.type.OrderPayType;
import com.hai.order.type.OrderRefundOpUserType;
import com.hai.order.utils.OrderUtil;
import com.hai.service.*;
import com.hai.service.pay.impl.GoodsOrderServiceImpl;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
@ -35,7 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
@ -79,6 +81,9 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService {
@Resource
private HighOrderService highOrderService;
@Autowired
private RedisTemplate redisTemplate;
@Override
public List<OutRechargeOrder> getListRechargeOrder(Map<String, Object> map) {
OutRechargeOrderExample example = new OutRechargeOrderExample();
@ -371,7 +376,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService {
if (outRechargeOrder.getRechargeStatus() == 202) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法退款,订单已充值成功无法退款");
}
log.info("发起话费订单订单处理" + outRechargeOrder.getOrderNo() + "");
// 订单处理
HighOrder highOrder = highOrderService.getOrderByOrderNo(outRechargeOrder.getOrderNo());
orderService.refundOrder(highOrder, "话费自动退款",OrderRefundOpUserType.TYPE1,
@ -462,8 +467,17 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService {
}
@Override
public void prepaidRechargeHandle(OutRechargeOrder outRechargeOrder) throws Exception {
public void prepaidRechargeHandle(OutRechargeOrder outRechargeOrder){
String key = "recharge_" + outRechargeOrder.getId();
try {
// 分布式锁占坑
Boolean lock = redisTemplate.opsForValue().setIfAbsent(key, outRechargeOrder.getOrderNo());
if(Boolean.TRUE.equals(lock)) {
// 加锁成功,处理业务
// 判断订单是否可以继续充值 1:满足继续充值条件 2:订单满足退款条件 3:订单不可以退款不可以继续充值 4:订单异常 5:订单充值完成
int orderStatus = orderWhetherRecharge(outRechargeOrder);
@ -480,14 +494,29 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService {
highOrderService.updateOrder(highOrder);
}
if (orderStatus == 5) {
completeOrder(outRechargeOrder.getOrderNo());
completeOrder(outRechargeOrder.getId());
}
} else {
// 加锁失败,重试
Thread.sleep(100);
prepaidRechargeHandle(outRechargeOrder);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// 删除key,释放锁
redisTemplate.delete(key);
}
}
@Override
public void completeOrder(String orderNo) {
public void completeOrder(Long orderId) {
OutRechargeChildOrder childOrder = outRechargeChildOrderService.findByOrderNo(orderNo);
OutRechargeChildOrder childOrder = outRechargeChildOrderService.findByOrderId(orderId);
// 查询充值订单
OutRechargeOrder order = outRechargeOrderService.findByOrderId(childOrder.getParentOrderId());
@ -678,15 +707,8 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService {
}
/**
* @Author Sum1Dream
* @Name orderWhetherRecharge
* @Description // 订单是否可以充值
* @Date 16:11 2023/3/28
* @Param [childOrder]
* @Return java.lang.Integer 1满足继续充值条件 2订单满足退款条件 3订单不可以退款不可以继续充值 4:订单异常 5:订单充值完成
*/
private Integer orderWhetherRecharge(OutRechargeOrder rechargeOrder) throws Exception {
@Override
public Integer orderWhetherRecharge(OutRechargeOrder rechargeOrder) throws Exception {
// 查询子订单
List<OutRechargeChildOrder> childOrderList = outRechargeChildOrderService.getListRechargeChildOrderByOrderId(rechargeOrder.getId());

Loading…
Cancel
Save