|
|
@@ -53,19 +53,17 @@ public class SecondGoodsTradeXxlJob {
|
|
|
*/
|
|
|
@XxlJob("secondTradeRemind")
|
|
|
public void secondTradeRemind() throws Exception {
|
|
|
- Date now = Date.from(LocalDateTime.now().plusMinutes(10).withSecond(0).withNano(0).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
-
|
|
|
- // 查询所有待交易
|
|
|
- LambdaQueryWrapper<SecondTradeRecord> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(SecondTradeRecord::getTradeStatus, 3);
|
|
|
- wrapper.eq(SecondTradeRecord::getTransactionTime, now);
|
|
|
- List<SecondTradeRecord> tradeRecordList = secondTradeRecordMapper.selectList(wrapper);
|
|
|
-
|
|
|
- for (SecondTradeRecord tradeRecord : tradeRecordList) {
|
|
|
- // 十分钟前
|
|
|
-// LocalDateTime tenMinutesAgo = tradeRecord.getTransactionTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().minusMinutes(10).withSecond(0).withNano(0);
|
|
|
-// // 交易时间的十分钟前
|
|
|
-// if (now.isEqual(tenMinutesAgo)) {
|
|
|
+ log.info("开始执行定时任务: 二手交易平台 - 10分钟后交易提醒 - secondTradeRemind");
|
|
|
+ try {
|
|
|
+ Date now = Date.from(LocalDateTime.now().plusMinutes(10).withSecond(0).withNano(0).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+
|
|
|
+ // 查询所有待交易
|
|
|
+ LambdaQueryWrapper<SecondTradeRecord> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(SecondTradeRecord::getTradeStatus, 3);
|
|
|
+ wrapper.eq(SecondTradeRecord::getTransactionTime, now);
|
|
|
+ List<SecondTradeRecord> tradeRecordList = secondTradeRecordMapper.selectList(wrapper);
|
|
|
+
|
|
|
+ for (SecondTradeRecord tradeRecord : tradeRecordList) {
|
|
|
LifeUser buyer = lifeUserMapper.selectById(tradeRecord.getBuyerId());
|
|
|
LifeUser seller = lifeUserMapper.selectById(tradeRecord.getSellerId());
|
|
|
|
|
|
@@ -175,7 +173,9 @@ public class SecondGoodsTradeXxlJob {
|
|
|
webSocketVo.setText(JSONObject.from(lifeNotice).toJSONString());
|
|
|
webSocketVo.setMessageId(lifeMessage.getId());
|
|
|
alienStoreFeign.sendMsgToClientByPhoneId(sellerPhoneId, JSONObject.from(webSocketVo).toJSONString());
|
|
|
-// }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("SecondGoodsTradeXxlJob.secondTradeRemind Error Msg={}", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -184,6 +184,7 @@ public class SecondGoodsTradeXxlJob {
|
|
|
*/
|
|
|
@XxlJob("secondTradeConfirm")
|
|
|
public void secondTradeConfirm() throws Exception {
|
|
|
+ log.info("开始执行定时任务: 二手交易平台 - 到达交易时间时,给买家和卖家发送交易确认提醒 - secondTradeConfirm");
|
|
|
try {
|
|
|
Date now = Date.from(LocalDateTime.now().withSecond(0).withNano(0).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
|
|
|
@@ -194,70 +195,67 @@ public class SecondGoodsTradeXxlJob {
|
|
|
List<SecondTradeRecord> tradeRecordList = secondTradeRecordMapper.selectList(wrapper);
|
|
|
|
|
|
for (SecondTradeRecord tradeRecord : tradeRecordList) {
|
|
|
-// LocalDateTime tenMinutesAgo = tradeRecord.getTransactionTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().withSecond(0).withNano(0);
|
|
|
-// if (now.isEqual(tenMinutesAgo)) {
|
|
|
- LifeUser buyer = lifeUserMapper.selectById(tradeRecord.getBuyerId());
|
|
|
- LifeUser seller = lifeUserMapper.selectById(tradeRecord.getSellerId());
|
|
|
- SecondGoods goods = secondGoodsMapper.selectById(tradeRecord.getGoodsId());
|
|
|
-
|
|
|
- String buyerPhoneId = null == buyer ? "" : "user_" + buyer.getUserPhone();
|
|
|
- String sellerPhoneId = null == seller ? "" : "user_" + seller.getUserPhone();
|
|
|
-
|
|
|
- // 给买家发送通知
|
|
|
- LifeNotice lifeNotice = new LifeNotice();
|
|
|
- lifeNotice.setSenderId("system");
|
|
|
- lifeNotice.setReceiverId(buyerPhoneId);
|
|
|
- lifeNotice.setBusinessId(tradeRecord.getId());
|
|
|
- lifeNotice.setTitle("商品是否交易成功");
|
|
|
- lifeNotice.setNoticeType(1);
|
|
|
- // 封装通知信息
|
|
|
- JSONObject noticeMessage = new JSONObject();
|
|
|
- noticeMessage.put("goodsId", goods.getId());
|
|
|
- noticeMessage.put("goodsHomeImage", goods.getHomeImage());
|
|
|
- noticeMessage.put("goodsTitle", goods.getTitle());
|
|
|
- noticeMessage.put("tradeId", tradeRecord.getId());
|
|
|
- noticeMessage.put("transactionAmount", tradeRecord.getTransactionAmount());
|
|
|
- noticeMessage.put("transactionLatitudeLongitude", tradeRecord.getTransactionLatitudeLongitude());
|
|
|
- noticeMessage.put("transactionLatitudeLongitudeAddress", tradeRecord.getTransactionLatitudeLongitudeAddress());
|
|
|
- noticeMessage.put("transactionLocation", tradeRecord.getTransactionLocation());
|
|
|
- noticeMessage.put("transactionTime", tradeRecord.getTransactionTime());
|
|
|
- noticeMessage.put("tradeStatus", tradeRecord.getTradeStatus());
|
|
|
- noticeMessage.put("message", "您有一笔交易已完成, 请前往确认");
|
|
|
- lifeNotice.setContext(noticeMessage.toJSONString());
|
|
|
- lifeNoticeMapper.insert(lifeNotice);
|
|
|
-
|
|
|
- // 给买家推送通知
|
|
|
- WebSocketVo webSocketVo = new WebSocketVo();
|
|
|
- webSocketVo.setSenderId("system");
|
|
|
- webSocketVo.setReceiverId(buyerPhoneId);
|
|
|
- webSocketVo.setCategory("notice");
|
|
|
- webSocketVo.setNoticeType("1");
|
|
|
- webSocketVo.setType("5");
|
|
|
- webSocketVo.setIsRead(0);
|
|
|
- webSocketVo.setText(JSONObject.from(lifeNotice).toJSONString());
|
|
|
- alienStoreFeign.sendMsgToClientByPhoneId(buyerPhoneId, JSONObject.from(webSocketVo).toJSONString());
|
|
|
-
|
|
|
- // 给卖家发送通知
|
|
|
- lifeNotice = new LifeNotice();
|
|
|
- lifeNotice.setSenderId("system");
|
|
|
- lifeNotice.setReceiverId(sellerPhoneId);
|
|
|
- lifeNotice.setBusinessId(tradeRecord.getId());
|
|
|
- lifeNotice.setTitle("商品是否交易成功");
|
|
|
- lifeNotice.setNoticeType(1);
|
|
|
- lifeNotice.setContext(noticeMessage.toJSONString());
|
|
|
- lifeNoticeMapper.insert(lifeNotice);
|
|
|
-
|
|
|
- // 给卖家推送通知
|
|
|
- webSocketVo = new WebSocketVo();
|
|
|
- webSocketVo.setSenderId("system");
|
|
|
- webSocketVo.setReceiverId(sellerPhoneId);
|
|
|
- webSocketVo.setCategory("notice");
|
|
|
- webSocketVo.setNoticeType("1");
|
|
|
- webSocketVo.setType("5");
|
|
|
- webSocketVo.setIsRead(0);
|
|
|
- webSocketVo.setText(JSONObject.from(lifeNotice).toJSONString());
|
|
|
- alienStoreFeign.sendMsgToClientByPhoneId(sellerPhoneId, JSONObject.from(webSocketVo).toJSONString());
|
|
|
-// }
|
|
|
+ LifeUser buyer = lifeUserMapper.selectById(tradeRecord.getBuyerId());
|
|
|
+ LifeUser seller = lifeUserMapper.selectById(tradeRecord.getSellerId());
|
|
|
+ SecondGoods goods = secondGoodsMapper.selectById(tradeRecord.getGoodsId());
|
|
|
+
|
|
|
+ String buyerPhoneId = null == buyer ? "" : "user_" + buyer.getUserPhone();
|
|
|
+ String sellerPhoneId = null == seller ? "" : "user_" + seller.getUserPhone();
|
|
|
+
|
|
|
+ // 给买家发送通知
|
|
|
+ LifeNotice lifeNotice = new LifeNotice();
|
|
|
+ lifeNotice.setSenderId("system");
|
|
|
+ lifeNotice.setReceiverId(buyerPhoneId);
|
|
|
+ lifeNotice.setBusinessId(tradeRecord.getId());
|
|
|
+ lifeNotice.setTitle("商品是否交易成功");
|
|
|
+ lifeNotice.setNoticeType(1);
|
|
|
+ // 封装通知信息
|
|
|
+ JSONObject noticeMessage = new JSONObject();
|
|
|
+ noticeMessage.put("goodsId", goods.getId());
|
|
|
+ noticeMessage.put("goodsHomeImage", goods.getHomeImage());
|
|
|
+ noticeMessage.put("goodsTitle", goods.getTitle());
|
|
|
+ noticeMessage.put("tradeId", tradeRecord.getId());
|
|
|
+ noticeMessage.put("transactionAmount", tradeRecord.getTransactionAmount());
|
|
|
+ noticeMessage.put("transactionLatitudeLongitude", tradeRecord.getTransactionLatitudeLongitude());
|
|
|
+ noticeMessage.put("transactionLatitudeLongitudeAddress", tradeRecord.getTransactionLatitudeLongitudeAddress());
|
|
|
+ noticeMessage.put("transactionLocation", tradeRecord.getTransactionLocation());
|
|
|
+ noticeMessage.put("transactionTime", tradeRecord.getTransactionTime());
|
|
|
+ noticeMessage.put("tradeStatus", tradeRecord.getTradeStatus());
|
|
|
+ noticeMessage.put("message", "您有一笔交易已完成, 请前往确认");
|
|
|
+ lifeNotice.setContext(noticeMessage.toJSONString());
|
|
|
+ lifeNoticeMapper.insert(lifeNotice);
|
|
|
+
|
|
|
+ // 给买家推送通知
|
|
|
+ WebSocketVo webSocketVo = new WebSocketVo();
|
|
|
+ webSocketVo.setSenderId("system");
|
|
|
+ webSocketVo.setReceiverId(buyerPhoneId);
|
|
|
+ webSocketVo.setCategory("notice");
|
|
|
+ webSocketVo.setNoticeType("1");
|
|
|
+ webSocketVo.setType("5");
|
|
|
+ webSocketVo.setIsRead(0);
|
|
|
+ webSocketVo.setText(JSONObject.from(lifeNotice).toJSONString());
|
|
|
+ alienStoreFeign.sendMsgToClientByPhoneId(buyerPhoneId, JSONObject.from(webSocketVo).toJSONString());
|
|
|
+
|
|
|
+ // 给卖家发送通知
|
|
|
+ lifeNotice = new LifeNotice();
|
|
|
+ lifeNotice.setSenderId("system");
|
|
|
+ lifeNotice.setReceiverId(sellerPhoneId);
|
|
|
+ lifeNotice.setBusinessId(tradeRecord.getId());
|
|
|
+ lifeNotice.setTitle("商品是否交易成功");
|
|
|
+ lifeNotice.setNoticeType(1);
|
|
|
+ lifeNotice.setContext(noticeMessage.toJSONString());
|
|
|
+ lifeNoticeMapper.insert(lifeNotice);
|
|
|
+
|
|
|
+ // 给卖家推送通知
|
|
|
+ webSocketVo = new WebSocketVo();
|
|
|
+ webSocketVo.setSenderId("system");
|
|
|
+ webSocketVo.setReceiverId(sellerPhoneId);
|
|
|
+ webSocketVo.setCategory("notice");
|
|
|
+ webSocketVo.setNoticeType("1");
|
|
|
+ webSocketVo.setType("5");
|
|
|
+ webSocketVo.setIsRead(0);
|
|
|
+ webSocketVo.setText(JSONObject.from(lifeNotice).toJSONString());
|
|
|
+ alienStoreFeign.sendMsgToClientByPhoneId(sellerPhoneId, JSONObject.from(webSocketVo).toJSONString());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("SecondGoodsTradeXxlJob.secondTradeConfirm Error Mgs={}", e.getMessage());
|
|
|
@@ -269,24 +267,29 @@ public class SecondGoodsTradeXxlJob {
|
|
|
*/
|
|
|
@XxlJob("secondTradeTimeoutCancel")
|
|
|
private void secondTradeTimeoutCancel() {
|
|
|
- LocalDateTime now = LocalDateTime.now().withSecond(0).withNano(0);
|
|
|
-
|
|
|
- // 查询所有待确认
|
|
|
- LambdaQueryWrapper<SecondTradeRecord> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(SecondTradeRecord::getTradeStatus, 1);
|
|
|
- List<SecondTradeRecord> tradeRecordList = secondTradeRecordMapper.selectList(queryWrapper);
|
|
|
- List<Integer> tradeIdList = new ArrayList<>();
|
|
|
- for (SecondTradeRecord tradeRecord : tradeRecordList) {
|
|
|
- LocalDateTime tenMinutesAgo = tradeRecord.getTransactionTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().withSecond(0).withNano(0);
|
|
|
- if (now.isEqual(tenMinutesAgo)) {
|
|
|
- tradeIdList.add(tradeRecord.getId());
|
|
|
+ log.info("开始执行定时任务: 二手交易平台 - 交易超时未确认则自动取消 - secondTradeTimeoutCancel");
|
|
|
+ try {
|
|
|
+ LocalDateTime now = LocalDateTime.now().withSecond(0).withNano(0);
|
|
|
+
|
|
|
+ // 查询所有待确认
|
|
|
+ LambdaQueryWrapper<SecondTradeRecord> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(SecondTradeRecord::getTradeStatus, 1);
|
|
|
+ List<SecondTradeRecord> tradeRecordList = secondTradeRecordMapper.selectList(queryWrapper);
|
|
|
+ List<Integer> tradeIdList = new ArrayList<>();
|
|
|
+ for (SecondTradeRecord tradeRecord : tradeRecordList) {
|
|
|
+ LocalDateTime tenMinutesAgo = tradeRecord.getTransactionTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().withSecond(0).withNano(0);
|
|
|
+ if (now.isEqual(tenMinutesAgo)) {
|
|
|
+ tradeIdList.add(tradeRecord.getId());
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if (CollectionUtil.isNotEmpty(tradeIdList)) {
|
|
|
- LambdaUpdateWrapper<SecondTradeRecord> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- updateWrapper.in(SecondTradeRecord::getId, tradeIdList)
|
|
|
- .set(SecondTradeRecord::getTradeStatus, 6);
|
|
|
- secondTradeRecordMapper.update(null, updateWrapper);
|
|
|
+ if (CollectionUtil.isNotEmpty(tradeIdList)) {
|
|
|
+ LambdaUpdateWrapper<SecondTradeRecord> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.in(SecondTradeRecord::getId, tradeIdList)
|
|
|
+ .set(SecondTradeRecord::getTradeStatus, 6);
|
|
|
+ secondTradeRecordMapper.update(null, updateWrapper);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("SecondGoodsTradeXxlJob.secondTradeTimeoutCancel Error Mgs={}", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -296,6 +299,7 @@ public class SecondGoodsTradeXxlJob {
|
|
|
@XxlJob("readMessage")
|
|
|
@Scheduled(cron = "0 * * * * ?")
|
|
|
public void readMessage() {
|
|
|
+ log.info("开始执行定时任务: 二手交易平台 - 每分钟从redis中读取已读的消息id 并将数据库设为已读 - readMessage");
|
|
|
try {
|
|
|
if (CollectionUtil.isEmpty(baseRedisService.getList("readMessageIdKey"))) return;
|
|
|
|