定时任务微信支付修改

This commit is contained in:
zhangheng 2023-12-01 10:00:21 +08:00
parent 2cb9bebd60
commit feadb4510b

View File

@ -10,10 +10,12 @@ import com.xinelu.common.enums.*;
import com.xinelu.manage.domain.appointmentorder.AppointmentOrder; import com.xinelu.manage.domain.appointmentorder.AppointmentOrder;
import com.xinelu.manage.domain.goodsOrder.GoodsOrder; import com.xinelu.manage.domain.goodsOrder.GoodsOrder;
import com.xinelu.manage.domain.paymentinfo.PaymentInfo; import com.xinelu.manage.domain.paymentinfo.PaymentInfo;
import com.xinelu.manage.domain.trainingorder.TrainingOrder;
import com.xinelu.manage.mapper.appointmentorder.AppointmentOrderMapper; import com.xinelu.manage.mapper.appointmentorder.AppointmentOrderMapper;
import com.xinelu.manage.mapper.goodsOrder.GoodsOrderMapper; import com.xinelu.manage.mapper.goodsOrder.GoodsOrderMapper;
import com.xinelu.manage.mapper.patientcouponreceive.PatientCouponReceiveMapper; import com.xinelu.manage.mapper.patientcouponreceive.PatientCouponReceiveMapper;
import com.xinelu.manage.mapper.paymentinfo.PaymentInfoMapper; import com.xinelu.manage.mapper.paymentinfo.PaymentInfoMapper;
import com.xinelu.manage.mapper.trainingorder.TrainingOrderMapper;
import com.xinelu.manage.vo.AppointOrderAndDetailsInfo; import com.xinelu.manage.vo.AppointOrderAndDetailsInfo;
import com.xinelu.manage.vo.goods.GoodsOrderAndDetailsInfo; import com.xinelu.manage.vo.goods.GoodsOrderAndDetailsInfo;
import com.xinelu.quartz.service.PaymentInfoTaskService; import com.xinelu.quartz.service.PaymentInfoTaskService;
@ -64,6 +66,8 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
private RedisTemplate<String, Objects> redisTemplate; private RedisTemplate<String, Objects> redisTemplate;
@Resource @Resource
private PatientCouponReceiveMapper patientCouponReceiveMapper; private PatientCouponReceiveMapper patientCouponReceiveMapper;
@Resource
private TrainingOrderMapper trainingOrderMapper;
/** /**
* 成功状态码 * 成功状态码
@ -85,7 +89,9 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
LocalDateTime localDateTime = LocalDateTime.now().minusHours(2); LocalDateTime localDateTime = LocalDateTime.now().minusHours(2);
List<AppointOrderAndDetailsInfo> appointmentOrderList = appointmentOrderMapper.getWaitPayAppointmentOrderList(localDateTime); List<AppointOrderAndDetailsInfo> appointmentOrderList = appointmentOrderMapper.getWaitPayAppointmentOrderList(localDateTime);
List<GoodsOrderAndDetailsInfo> goodsOrderList = goodsOrderMapper.getWaitPayGoodsOrderList(localDateTime); List<GoodsOrderAndDetailsInfo> goodsOrderList = goodsOrderMapper.getWaitPayGoodsOrderList(localDateTime);
if (CollectionUtils.isEmpty(appointmentOrderList) && CollectionUtils.isEmpty(goodsOrderList)) { //查询学习培训订单信息
List<TrainingOrder> waitPayTrainingOrderList = trainingOrderMapper.getWaitPayTrainingOrderListByTime(localDateTime, TrainingOrderStatusEnum.WAIT_PAY.getInfo());
if (CollectionUtils.isEmpty(appointmentOrderList) && CollectionUtils.isEmpty(goodsOrderList) && CollectionUtils.isEmpty(waitPayTrainingOrderList)) {
return; return;
} }
TransactionStatus transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition()); TransactionStatus transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition());
@ -97,6 +103,10 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
if (CollectionUtils.isNotEmpty(goodsOrderList)) { if (CollectionUtils.isNotEmpty(goodsOrderList)) {
processGoodsOrderInfo(goodsOrderList); processGoodsOrderInfo(goodsOrderList);
} }
//处理学习培训订单信息
if (CollectionUtils.isNotEmpty(waitPayTrainingOrderList)) {
handleWaitPayTrainingOrderInfo(waitPayTrainingOrderList);
}
transactionManager.commit(transactionStatus); transactionManager.commit(transactionStatus);
} catch (Exception e) { } catch (Exception e) {
transactionManager.rollback(transactionStatus); transactionManager.rollback(transactionStatus);
@ -123,7 +133,9 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
public void automaticUpdateOrderStatusTask() throws Exception { public void automaticUpdateOrderStatusTask() throws Exception {
List<AppointmentOrder> appointmentOrderList = appointmentOrderMapper.getWaitPayStatusAppointmentOrderList(OrderStatusEnum.WAIT_PAY.getInfo()); List<AppointmentOrder> appointmentOrderList = appointmentOrderMapper.getWaitPayStatusAppointmentOrderList(OrderStatusEnum.WAIT_PAY.getInfo());
List<GoodsOrder> goodsOrderList = goodsOrderMapper.getWaitPayStatusGoodsOrderList(GooodsOrderStatusEnum.WAIT_PAY.getInfo()); List<GoodsOrder> goodsOrderList = goodsOrderMapper.getWaitPayStatusGoodsOrderList(GooodsOrderStatusEnum.WAIT_PAY.getInfo());
if (CollectionUtils.isEmpty(appointmentOrderList) && CollectionUtils.isEmpty(goodsOrderList)) { //查询未支付的学习培训订单信息
List<TrainingOrder> waitPayTrainingOrderList = trainingOrderMapper.getWaitPayTrainingOrderList(TrainingOrderStatusEnum.WAIT_PAY.getInfo(), null);
if (CollectionUtils.isEmpty(appointmentOrderList) && CollectionUtils.isEmpty(goodsOrderList) && CollectionUtils.isEmpty(waitPayTrainingOrderList)) {
return; return;
} }
TransactionStatus transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition()); TransactionStatus transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition());
@ -134,6 +146,10 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
if (CollectionUtils.isNotEmpty(goodsOrderList)) { if (CollectionUtils.isNotEmpty(goodsOrderList)) {
updateGoodsPaymentInfo(goodsOrderList); updateGoodsPaymentInfo(goodsOrderList);
} }
//修改学习培训订单状态以及记录支付信息
if (CollectionUtils.isNotEmpty(waitPayTrainingOrderList)) {
handleWaitPayTrainingOrder(waitPayTrainingOrderList);
}
transactionManager.commit(transactionStatus); transactionManager.commit(transactionStatus);
} catch (Exception e) { } catch (Exception e) {
log.error("修改订单状态定时任务失败,失败原因为 =====> {}", e.getMessage()); log.error("修改订单状态定时任务失败,失败原因为 =====> {}", e.getMessage());
@ -268,7 +284,29 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
OrderStatusInfoVO statusInfoVO = weChatPaymentService.queryGoodsOrderStatus(goodsOrder.getOrderNo(), vo, goodsOrder.getBuySource()); OrderStatusInfoVO statusInfoVO = weChatPaymentService.queryGoodsOrderStatus(goodsOrder.getOrderNo(), vo, goodsOrder.getBuySource());
if (StringUtils.isNotBlank(statusInfoVO.getTradeStatus()) if (StringUtils.isNotBlank(statusInfoVO.getTradeStatus())
&& WeChatTradeStateEnum.SUCCESS.getInfo().equals(statusInfoVO.getTradeStatus())) { && WeChatTradeStateEnum.SUCCESS.getInfo().equals(statusInfoVO.getTradeStatus())) {
insertGoodsOrderPaymentInfo(goodsOrder, statusInfoVO); insertGoodsOrderPaymentInfo(goodsOrder, null, statusInfoVO);
}
}
}
/**
* 处理支付回调失败导致未及时更新学习培训订单状态的信息集合
*
* @param waitPayTrainingOrderList 未支付的学习培训订单集合
* @throws Exception 异常信息
*/
private void handleWaitPayTrainingOrder(List<TrainingOrder> waitPayTrainingOrderList) throws Exception {
for (TrainingOrder trainingOrder : waitPayTrainingOrderList) {
if (Objects.isNull(trainingOrder) || StringUtils.isBlank(trainingOrder.getTrainingOrderNo())) {
continue;
}
OrderStatusInfoVO vo = new OrderStatusInfoVO();
//学习培训订单状态查询接口和记录支付日志信息使用商品订单的方法在方法中做逻辑处理
OrderStatusInfoVO statusInfoVO = weChatPaymentService.queryGoodsOrderStatus(trainingOrder.getTrainingOrderNo(), vo, BuySourceEnum.TRAINING.getInfo());
if (StringUtils.isNotBlank(statusInfoVO.getTradeStatus())
&& WeChatTradeStateEnum.SUCCESS.getInfo().equals(statusInfoVO.getTradeStatus())) {
//修改订单状态和记录支付日志信息
insertGoodsOrderPaymentInfo(null, trainingOrder, statusInfoVO);
} }
} }
} }
@ -285,7 +323,7 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
int paymentInfoCount = paymentInfoMapper.getPaymentInfoByOrderNo(appointmentOrder.getOrderNo()); int paymentInfoCount = paymentInfoMapper.getPaymentInfoByOrderNo(appointmentOrder.getOrderNo());
if (paymentInfoCount <= 0) { if (paymentInfoCount <= 0) {
WeChatQueryOrderVO weChatQueryOrderVO = vo.getWeChatQueryOrderVO(); WeChatQueryOrderVO weChatQueryOrderVO = vo.getWeChatQueryOrderVO();
PaymentInfo paymentInfo = buildPaymentInfo(weChatQueryOrderVO, null, appointmentOrder); PaymentInfo paymentInfo = buildPaymentInfo(weChatQueryOrderVO, null, appointmentOrder, null);
int insertCount = paymentInfoMapper.insertPaymentInfo(paymentInfo); int insertCount = paymentInfoMapper.insertPaymentInfo(paymentInfo);
if (insertCount <= 0) { if (insertCount <= 0) {
log.error("记录预约订单支付日志出错,参数为 ====> [{}]", paymentInfo); log.error("记录预约订单支付日志出错,参数为 ====> [{}]", paymentInfo);
@ -295,21 +333,27 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
} }
/** /**
* 修改商品订单状态和记录商品订单支付日志信息 * 修改商品订单状态和记录商品订单支付日志信息及学习培训订单
* *
* @param goodsOrder 商品订单信息 * @param goodsOrder 商品订单信息
* @param vo 微信查单信息 * @param vo 微信查单信息
* @throws Exception 异常信息 * @throws Exception 异常信息
*/ */
private void insertGoodsOrderPaymentInfo(GoodsOrder goodsOrder, OrderStatusInfoVO vo) throws Exception { private void insertGoodsOrderPaymentInfo(GoodsOrder goodsOrder, TrainingOrder trainingOrder, OrderStatusInfoVO vo) throws Exception {
int paymentInfoCount = 0; int paymentInfoCount = 0;
if (Objects.nonNull(goodsOrder)) { if (Objects.nonNull(goodsOrder)) {
goodsOrderMapper.updateGoodsOrderStatus(GooodsOrderStatusEnum.WAIT_RECEIVED_GOODS.getInfo(), goodsOrder.getOrderNo()); goodsOrderMapper.updateGoodsOrderStatus(GooodsOrderStatusEnum.WAIT_RECEIVED_GOODS.getInfo(), goodsOrder.getOrderNo());
paymentInfoCount = paymentInfoMapper.getPaymentInfoByOrderNo(goodsOrder.getOrderNo()); paymentInfoCount = paymentInfoMapper.getPaymentInfoByOrderNo(goodsOrder.getOrderNo());
} }
//修改学习培训订单状态和记录支付日志信息
if (Objects.nonNull(trainingOrder)) {
trainingOrderMapper.updateTrainingOrderStatus(TrainingOrderStatusEnum.PAY.getInfo(), trainingOrder.getTrainingOrderNo());
paymentInfoCount = paymentInfoMapper.getPaymentInfoByOrderNo(trainingOrder.getTrainingOrderNo());
}
if (paymentInfoCount <= 0) { if (paymentInfoCount <= 0) {
WeChatQueryOrderVO weChatQueryOrderVO = vo.getWeChatQueryOrderVO(); WeChatQueryOrderVO weChatQueryOrderVO = vo.getWeChatQueryOrderVO();
PaymentInfo paymentInfo = buildPaymentInfo(weChatQueryOrderVO, goodsOrder, null); PaymentInfo paymentInfo = buildPaymentInfo(weChatQueryOrderVO, goodsOrder, null, trainingOrder);
int insertCount = paymentInfoMapper.insertPaymentInfo(paymentInfo); int insertCount = paymentInfoMapper.insertPaymentInfo(paymentInfo);
if (insertCount <= 0) { if (insertCount <= 0) {
log.error("记录商品或者学习培训支付订单支付日志出错,参数为 ====> [{}]", paymentInfo); log.error("记录商品或者学习培训支付订单支付日志出错,参数为 ====> [{}]", paymentInfo);
@ -326,7 +370,7 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
* @param appointmentOrderInfo 预约订单信息 * @param appointmentOrderInfo 预约订单信息
*/ */
public PaymentInfo buildPaymentInfo(WeChatQueryOrderVO weChatQueryOrderVO, GoodsOrder goodsOrderInfo, public PaymentInfo buildPaymentInfo(WeChatQueryOrderVO weChatQueryOrderVO, GoodsOrder goodsOrderInfo,
AppointmentOrder appointmentOrderInfo) { AppointmentOrder appointmentOrderInfo, TrainingOrder trainingOrder) {
PaymentInfo paymentInfo = new PaymentInfo(); PaymentInfo paymentInfo = new PaymentInfo();
if (Objects.nonNull(goodsOrderInfo)) { if (Objects.nonNull(goodsOrderInfo)) {
paymentInfo.setPatientId(Objects.isNull(goodsOrderInfo.getPatientId()) ? null : goodsOrderInfo.getPatientId()); paymentInfo.setPatientId(Objects.isNull(goodsOrderInfo.getPatientId()) ? null : goodsOrderInfo.getPatientId());
@ -336,6 +380,10 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
paymentInfo.setPatientId(Objects.isNull(appointmentOrderInfo.getPatientId()) ? null : appointmentOrderInfo.getPatientId()); paymentInfo.setPatientId(Objects.isNull(appointmentOrderInfo.getPatientId()) ? null : appointmentOrderInfo.getPatientId());
paymentInfo.setOrderNo(StringUtils.isBlank(appointmentOrderInfo.getOrderNo()) ? "" : appointmentOrderInfo.getOrderNo()); paymentInfo.setOrderNo(StringUtils.isBlank(appointmentOrderInfo.getOrderNo()) ? "" : appointmentOrderInfo.getOrderNo());
paymentInfo.setPayChannel(StringUtils.isBlank(appointmentOrderInfo.getOrderChannel()) ? "" : appointmentOrderInfo.getOrderChannel()); paymentInfo.setPayChannel(StringUtils.isBlank(appointmentOrderInfo.getOrderChannel()) ? "" : appointmentOrderInfo.getOrderChannel());
} else if (Objects.nonNull(trainingOrder)) {
paymentInfo.setNurseStationPersonId(Objects.isNull(trainingOrder.getNurseStationPersonId()) ? null : trainingOrder.getNurseStationPersonId());
paymentInfo.setOrderNo(StringUtils.isBlank(trainingOrder.getTrainingOrderNo()) ? "" : trainingOrder.getTrainingOrderNo());
paymentInfo.setPayChannel(StringUtils.isBlank(trainingOrder.getTrainingOrderChannel()) ? "" : trainingOrder.getTrainingOrderChannel());
} }
paymentInfo.setTransactionNo(StringUtils.isBlank(weChatQueryOrderVO.getTransactionId()) ? "" : weChatQueryOrderVO.getTransactionId()); paymentInfo.setTransactionNo(StringUtils.isBlank(weChatQueryOrderVO.getTransactionId()) ? "" : weChatQueryOrderVO.getTransactionId());
paymentInfo.setPayPrice(BigDecimal.valueOf(Objects.isNull(weChatQueryOrderVO.getAmount().getPayerTotal()) ? 0 : weChatQueryOrderVO.getAmount().getPayerTotal()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_DOWN)); paymentInfo.setPayPrice(BigDecimal.valueOf(Objects.isNull(weChatQueryOrderVO.getAmount().getPayerTotal()) ? 0 : weChatQueryOrderVO.getAmount().getPayerTotal()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_DOWN));
@ -370,4 +418,50 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
} }
} }
} }
/**
* 处理10分钟未支付的学习培训订单信息
*
* @param trainingOrderList 学习培训订单集合
* @throws Exception 异常信息
*/
private void handleWaitPayTrainingOrderInfo(List<TrainingOrder> trainingOrderList) throws Exception {
//本地系统中超过两小时未支付的订单集合
List<String> orderList = Lists.newArrayList();
//微信系统已经关闭状态的订单集合
List<String> closedOrderList = Lists.newArrayList();
for (TrainingOrder trainingOrder : trainingOrderList) {
if (Objects.isNull(trainingOrder) || StringUtils.isBlank(trainingOrder.getTrainingOrderNo())) {
continue;
}
OrderStatusInfoVO vo = new OrderStatusInfoVO();
//根据订单编号查询微信系统中订单的状态
OrderStatusInfoVO statusInfoVO = weChatPaymentService.queryGoodsOrderStatus(trainingOrder.getTrainingOrderNo(), vo, BuySourceEnum.TRAINING.getInfo());
if (BooleanUtils.isFalse(statusInfoVO.getPayFlag())) {
closedOrderList.add(trainingOrder.getTrainingOrderNo());
continue;
}
//关闭微信系统订单
int statusCode = weChatPaymentService.closeWeChatOrderInfo(trainingOrder.getTrainingOrderNo(), BuySourceEnum.TRAINING.getInfo());
if (statusCode == SUCCESS_CODE || statusCode == SUCCESS_CODE_TWO) {
orderList.add(trainingOrder.getTrainingOrderNo());
}
}
//关闭本地系统订单信息
if (CollectionUtils.isNotEmpty(orderList)) {
trainingOrderMapper.updateBatchTrainingOrderStatus(orderList, TrainingOrderStatusEnum.CANCEL.getInfo());
}
//关闭微信系统中已经关闭的订单而本地系统中未及时关闭的订单信息
if (CollectionUtils.isEmpty(closedOrderList)) {
return;
}
List<TrainingOrder> waitPayTrainingOrderList = trainingOrderMapper.getWaitPayTrainingOrderList(TrainingOrderStatusEnum.WAIT_PAY.getInfo(), closedOrderList);
if (CollectionUtils.isEmpty(waitPayTrainingOrderList)) {
return;
}
List<String> waitPayOrderList = waitPayTrainingOrderList.stream().filter(Objects::nonNull).filter(item -> StringUtils.isNotBlank(item.getTrainingOrderNo())).map(TrainingOrder::getTrainingOrderNo).distinct().collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(waitPayOrderList)) {
trainingOrderMapper.updateBatchTrainingOrderStatus(waitPayOrderList, TrainingOrderStatusEnum.CANCEL.getInfo());
}
}
} }