|
@@ -7,20 +7,25 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import shop.alien.config.redis.BaseRedisService;
|
|
|
+import shop.alien.entity.second.SecondGoods;
|
|
|
import shop.alien.entity.second.SecondTradeRecord;
|
|
|
import shop.alien.entity.store.LifeMessage;
|
|
|
import shop.alien.entity.store.LifeNotice;
|
|
|
import shop.alien.entity.store.LifeUser;
|
|
|
+import shop.alien.entity.store.vo.WebSocketVo;
|
|
|
import shop.alien.job.feign.AlienStoreFeign;
|
|
|
import shop.alien.mapper.LifeMessageMapper;
|
|
|
import shop.alien.mapper.LifeNoticeMapper;
|
|
|
import shop.alien.mapper.LifeUserMapper;
|
|
|
+import shop.alien.mapper.second.SecondGoodsMapper;
|
|
|
import shop.alien.mapper.second.SecondTradeRecordMapper;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Slf4j
|
|
@@ -40,11 +45,93 @@ public class SecondGoodsTradeXxlJob {
|
|
|
|
|
|
private final BaseRedisService baseRedisService;
|
|
|
|
|
|
+ private final SecondGoodsMapper secondGoodsMapper;
|
|
|
+
|
|
|
/**
|
|
|
- * 商品交易时间十分钟之前发送签到提醒
|
|
|
+ * 二手交易平台 - 交易时间前的十分钟之前 给买家和卖家发送通知提醒
|
|
|
*/
|
|
|
@XxlJob("secondTradeRemind")
|
|
|
- public void secondTradeRemind() {
|
|
|
+ public void secondTradeRemind() throws Exception {
|
|
|
+ LocalDateTime now = LocalDateTime.now().withSecond(0).withNano(0);
|
|
|
+
|
|
|
+ // 查询所有待交易
|
|
|
+ LambdaQueryWrapper<SecondTradeRecord> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(SecondTradeRecord::getTradeStatus, 3);
|
|
|
+ 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(buyerPhoneId, JSONObject.from(webSocketVo).toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 二手交易平台 - 到达交易时间时,给买家和卖家发送交易确认提醒
|
|
|
+ */
|
|
|
+ @XxlJob("secondTradeConfirm")
|
|
|
+ public void secondTradeConfirm() throws Exception {
|
|
|
try {
|
|
|
LocalDateTime now = LocalDateTime.now().withSecond(0).withNano(0);
|
|
|
|
|
@@ -54,117 +141,110 @@ public class SecondGoodsTradeXxlJob {
|
|
|
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);
|
|
|
- // 交易时间的十分钟前
|
|
|
+ LocalDateTime tenMinutesAgo = tradeRecord.getTransactionTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().withSecond(0).withNano(0);
|
|
|
if (now.isEqual(tenMinutesAgo)) {
|
|
|
- // 封装交易信息
|
|
|
- JSONObject message = new JSONObject();
|
|
|
- message.put("tradeId", tradeRecord.getId());
|
|
|
- message.put("transactionAmount", tradeRecord.getTransactionAmount());
|
|
|
- message.put("transactionLatitudeLongitude", tradeRecord.getTransactionLatitudeLongitude());
|
|
|
- message.put("transactionLatitudeLongitudeAddress", tradeRecord.getTransactionLatitudeLongitudeAddress());
|
|
|
- message.put("transactionLocation", tradeRecord.getTransactionLocation());
|
|
|
- message.put("transactionTime", tradeRecord.getTransactionTime());
|
|
|
- message.put("tradeStatus", tradeRecord.getTradeStatus());
|
|
|
-
|
|
|
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();
|
|
|
|
|
|
- // 给买家发送消息
|
|
|
- LifeMessage lifeMessage = new LifeMessage();
|
|
|
- lifeMessage.setSenderId(sellerPhoneId);
|
|
|
- lifeMessage.setReceiverId(buyerPhoneId);
|
|
|
- lifeMessage.setContent(message.toJSONString());
|
|
|
- lifeMessage.setType("5");
|
|
|
- lifeMessageMapper.insert(lifeMessage);
|
|
|
-
|
|
|
- // 给买家推送消息
|
|
|
-// WebsocketVo websocketVo = new WebsocketVo();
|
|
|
-// websocketVo.setSenderId(sellerPhoneId);
|
|
|
-// websocketVo.setReceiverId(buyerPhoneId);
|
|
|
-// websocketVo.setCategory("message");
|
|
|
-// websocketVo.setType("5");
|
|
|
-// websocketVo.setText(message.toJSONString());
|
|
|
-// websocketVo.setMessageId(lifeMessage.getId());
|
|
|
- alienStoreFeign.sendMsgToClientByPhoneId(buyerPhoneId, sellerPhoneId, buyerPhoneId, "message", "5", message.toJSONString(), lifeMessage.getId());
|
|
|
-
|
|
|
// 给买家发送通知
|
|
|
LifeNotice lifeNotice = new LifeNotice();
|
|
|
lifeNotice.setSenderId("system");
|
|
|
lifeNotice.setReceiverId(buyerPhoneId);
|
|
|
lifeNotice.setBusinessId(tradeRecord.getId());
|
|
|
- lifeNotice.setTitle("交易签到提醒");
|
|
|
- lifeNotice.setContext("您有一笔交易即将开始, 请及时前往查看");
|
|
|
+ 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 = new WebsocketVo();
|
|
|
-// websocketVo.setSenderId("system");
|
|
|
-// websocketVo.setReceiverId(buyerPhoneId);
|
|
|
-// websocketVo.setCategory("notice");
|
|
|
-// websocketVo.setType("5");
|
|
|
-// websocketVo.setText(message.toJSONString());
|
|
|
-// websocketVo.setMessageId(lifeMessage.getId());
|
|
|
- alienStoreFeign.sendMsgToClientByPhoneId(buyerPhoneId, "system", buyerPhoneId, "notice", "5", message.toJSONString(), lifeMessage.getId());
|
|
|
-
|
|
|
- // 给卖家发送消息
|
|
|
- lifeMessage = new LifeMessage();
|
|
|
- lifeMessage.setSenderId(buyerPhoneId);
|
|
|
- lifeMessage.setReceiverId(sellerPhoneId);
|
|
|
- lifeMessage.setContent(message.toJSONString());
|
|
|
- lifeMessage.setType("5");
|
|
|
- lifeMessageMapper.insert(lifeMessage);
|
|
|
-
|
|
|
- // 给卖家推送消息
|
|
|
-// websocketVo = new WebsocketVo();
|
|
|
-// websocketVo.setSenderId(buyerPhoneId);
|
|
|
-// websocketVo.setReceiverId(sellerPhoneId);
|
|
|
-// websocketVo.setCategory("message");
|
|
|
-// websocketVo.setType("5");
|
|
|
-// websocketVo.setText(message.toJSONString());
|
|
|
-// websocketVo.setMessageId(lifeMessage.getId());
|
|
|
- alienStoreFeign.sendMsgToClientByPhoneId(sellerPhoneId, buyerPhoneId, sellerPhoneId, "message", "5", message.toJSONString(), lifeMessage.getId());
|
|
|
+ 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.setContext("您有一笔交易即将开始, 请及时前往查看");
|
|
|
+ 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.setType("5");
|
|
|
-// websocketVo.setText(message.toJSONString());
|
|
|
-// websocketVo.setMessageId(lifeMessage.getId());
|
|
|
- alienStoreFeign.sendMsgToClientByPhoneId(sellerPhoneId, "system", sellerPhoneId, "notice", "5", message.toJSONString(), lifeMessage.getId());
|
|
|
+ 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(buyerPhoneId, JSONObject.from(webSocketVo).toJSONString());
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- log.error("SecondGoodsTradeXxlJob.secondTradeRemind Error Mgs={}", e.getMessage());
|
|
|
+ log.error("SecondGoodsTradeXxlJob.secondTradeConfirm Error Mgs={}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 二手交易平台 - 交易超时未确认则自动取消
|
|
|
+ */
|
|
|
+ @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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isNotEmpty(tradeIdList)) {
|
|
|
+ LambdaUpdateWrapper<SecondTradeRecord> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.in(SecondTradeRecord::getId, tradeIdList)
|
|
|
+ .set(SecondTradeRecord::getTradeStatus, 6);
|
|
|
+ secondTradeRecordMapper.update(null, updateWrapper);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 每分钟从redis中读取已读的消息id 并将数据库设为已读
|
|
|
+ * 二手交易平台 - 每分钟从redis中读取已读的消息id 并将数据库设为已读
|
|
|
*/
|
|
|
@XxlJob("readMessage")
|
|
|
+ @Scheduled(cron = "0 * * * * ?")
|
|
|
public void readMessage() {
|
|
|
try {
|
|
|
- if (CollectionUtil.isEmpty(baseRedisService.getList("readMessageIdKey"))) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (CollectionUtil.isEmpty(baseRedisService.getList("readMessageIdKey"))) return;
|
|
|
|
|
|
List<String> dataList = baseRedisService.popBatchFromList("readMessageIdKey");
|
|
|
if (CollectionUtil.isNotEmpty(dataList)) {
|