|
|
|
@ -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()); |
|
|
|
|