|
|
@@ -55,6 +55,7 @@ import com.zhongshu.card.server.core.httpRequest.ApiRequestService;
|
|
|
import com.zhongshu.card.server.core.service.base.CommonService;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.service.devices.DeviceInfoServiceImpl;
|
|
|
+import com.zhongshu.card.server.core.service.keyExpire.impl.OrderKeyExpire;
|
|
|
import com.zhongshu.card.server.core.service.mqtt.MqttServiceImpl;
|
|
|
import com.zhongshu.card.server.core.service.org.OrganizationServiceImpl;
|
|
|
import com.zhongshu.card.server.core.service.org.OrganizationUserServiceImpl;
|
|
|
@@ -132,8 +133,11 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
@Autowired
|
|
|
private OrganizationUserServiceImpl organizationUserService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OrderKeyExpire orderKeyExpire;
|
|
|
+
|
|
|
/**
|
|
|
- * 创建流水
|
|
|
+ * 创建流水/订单记录
|
|
|
*
|
|
|
* @param mqttDataId
|
|
|
* @return
|
|
|
@@ -217,9 +221,12 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
expirationTime = OrderConfig.orderExpirationTime;
|
|
|
}
|
|
|
expenseFlow.setExpirationTime(System.currentTimeMillis() + expirationTime);
|
|
|
+ expenseFlow.setExpireTime(expirationTime);
|
|
|
|
|
|
// 验证参数、填充数据
|
|
|
commonVerifyExpenseFlow(expenseFlow);
|
|
|
+ // 开始计时订单过期时间
|
|
|
+ delayedTimeout(expenseFlow);
|
|
|
return ResultContent.buildSuccess(expenseFlow);
|
|
|
}
|
|
|
|
|
|
@@ -525,7 +532,10 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
sendMessageModel.setUserId(userId);
|
|
|
log.info("mq topic : {}", topic);
|
|
|
mqttService.sendMessage(sendMessageModel);
|
|
|
+ // 记录设备使用记录数据
|
|
|
payCallService.buildDeviceUseRecord(expenseFlow);
|
|
|
+ // 取消定时任务
|
|
|
+ clearDelayedTimeout(expenseFlow);
|
|
|
} else {
|
|
|
log.error("wxSurePaymentTypeOrderPayCallSuccess 订单为空: {}", orderNo);
|
|
|
}
|
|
|
@@ -582,6 +592,7 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
entity.setPaymentType(PaymentType.UserWallet);
|
|
|
expenseFlowDao.save(entity);
|
|
|
}
|
|
|
+ // 添加设备使用记录
|
|
|
payCallService.buildDeviceUseRecord(entity);
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
@@ -1131,7 +1142,54 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
Map<String, Object> standardData = new HashMap<>();
|
|
|
standardData.put("orderState", OrderState.Expired);
|
|
|
standardData.put("payRemark", "超时关闭");
|
|
|
+
|
|
|
+ standardData.put("isClosed", Boolean.TRUE);
|
|
|
+ standardData.put("closeUserId", "");
|
|
|
+ standardData.put("closeReason", "超时关闭");
|
|
|
+ standardData.put("closeTime", System.currentTimeMillis());
|
|
|
+
|
|
|
commonService.updateData(entity.getId(), standardData, ExpenseFlow.class.getSimpleName());
|
|
|
+ clearDelayedTimeout(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 把新创建的订单加入延时
|
|
|
+ */
|
|
|
+ public void delayedTimeout(ExpenseFlow order) {
|
|
|
+ if (ObjectUtils.isEmpty(order)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ orderKeyExpire.saveKey(order.getOrderNo(), order.getExpireTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void clearDelayedTimeout(ExpenseFlow order) {
|
|
|
+ if (ObjectUtils.isEmpty(order)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ orderKeyExpire.deleteKey(order.getOrderNo());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void handleDelayedTask(String orderNo) {
|
|
|
+ ExpenseFlow expenseFlow = expenseFlowDao.findTopByOrderNoOrderByCreateTimeDesc(orderNo);
|
|
|
+ if (ObjectUtils.isEmpty(expenseFlow)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String id = expenseFlow.getId();
|
|
|
+ try {
|
|
|
+ String lockKey = commonService.acquire(id, 5000L, expenseFlow);
|
|
|
+ log.info("lockKey: {}", lockKey);
|
|
|
+ if (StringUtils.isNotEmpty(lockKey)) {
|
|
|
+ if (expenseFlow.getOrderState() == OrderState.WAIT_PAYMENT
|
|
|
+ && expenseFlow.getExpirationTime() <= System.currentTimeMillis()) {
|
|
|
+ // 为待支付并且支付时间已过
|
|
|
+ markOrderTimeOut(expenseFlow);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ commonService.release(id, expenseFlow);
|
|
|
}
|
|
|
}
|
|
|
|