|
|
@@ -15,10 +15,12 @@ import shop.alien.entity.second.SecondTradeOperation;
|
|
|
import shop.alien.entity.second.SecondTradeRecord;
|
|
|
import shop.alien.entity.second.vo.SecondTradeRecordVo;
|
|
|
import shop.alien.entity.store.LifeMessage;
|
|
|
+import shop.alien.entity.store.LifeNotice;
|
|
|
import shop.alien.entity.store.LifeUser;
|
|
|
import shop.alien.entity.store.StoreDictionary;
|
|
|
import shop.alien.entity.store.vo.WebSocketVo;
|
|
|
import shop.alien.mapper.LifeMessageMapper;
|
|
|
+import shop.alien.mapper.LifeNoticeMapper;
|
|
|
import shop.alien.mapper.LifeUserMapper;
|
|
|
import shop.alien.mapper.StoreDictionaryMapper;
|
|
|
import shop.alien.mapper.second.SecondGoodsMapper;
|
|
|
@@ -29,9 +31,7 @@ import shop.alien.second.feign.AlienStoreFeign;
|
|
|
import shop.alien.second.service.SecondTradeRecordService;
|
|
|
import shop.alien.util.common.JwtUtil;
|
|
|
|
|
|
-import java.time.LocalDate;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.ZoneId;
|
|
|
+import java.time.*;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
@@ -54,6 +54,7 @@ public class SecondTradeRecordServiceImpl extends ServiceImpl<SecondTradeRecordM
|
|
|
private final SecondGoodsMapper secondGoodsMapper;
|
|
|
private final SecondGoodsRecordMapper secondGoodsRecordMapper;
|
|
|
private final LifeMessageMapper lifeMessageMapper;
|
|
|
+ private final LifeNoticeMapper lifeNoticeMapper;
|
|
|
private final LifeUserMapper lifeUserMapper;
|
|
|
private final AlienStoreFeign alienStoreFeign;
|
|
|
private final StoreDictionaryMapper storeDictionaryMapper;
|
|
|
@@ -102,6 +103,11 @@ public class SecondTradeRecordServiceImpl extends ServiceImpl<SecondTradeRecordM
|
|
|
// 发送消息
|
|
|
sendMsg(goods, trade, 1, "4");
|
|
|
|
|
|
+ // 创建交易时间小于十分钟,直接发送交易提醒
|
|
|
+ if (Math.abs(Duration.between(Instant.now(), trade.getTransactionTime().toInstant()).getSeconds()) < 600) {
|
|
|
+ sendSignInMessage(trade);
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
} catch (Exception e) {
|
|
|
log.error("SecondTradeRecordServiceImpl.createTrade(): Error Msg={}", e.getMessage());
|
|
|
@@ -478,4 +484,122 @@ public class SecondTradeRecordServiceImpl extends ServiceImpl<SecondTradeRecordM
|
|
|
throw new Exception(e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void sendSignInMessage(SecondTradeRecord tradeRecord) throws Exception {
|
|
|
+ log.info("二手交易平台-创建交易时间小于十分钟,直接发送交易提醒---sendSignInMessage()---");
|
|
|
+ try {
|
|
|
+ LifeUser buyer = lifeUserMapper.selectById(tradeRecord.getBuyerId());
|
|
|
+ LifeUser seller = lifeUserMapper.selectById(tradeRecord.getSellerId());
|
|
|
+
|
|
|
+ String buyerPhoneId = null == buyer ? "" : "user_" + buyer.getUserPhone();
|
|
|
+ String sellerPhoneId = null == seller ? "" : "user_" + seller.getUserPhone();
|
|
|
+
|
|
|
+ // 封装交易信息
|
|
|
+ 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());
|
|
|
+
|
|
|
+ // 给买家发送消息
|
|
|
+ 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, JSONObject.from(webSocketVo).toJSONString());
|
|
|
+
|
|
|
+ // 给买家发送通知
|
|
|
+ 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("tradeId", tradeRecord.getId());
|
|
|
+ noticeMessage.put("otherSideUserId", tradeRecord.getSellerId());
|
|
|
+ noticeMessage.put("otherSidePhoneId", sellerPhoneId);
|
|
|
+ noticeMessage.put("otherSideName", null == seller ? "" : seller.getUserName());
|
|
|
+ noticeMessage.put("otherSideImage", null == seller ? "" : seller.getUserImage());
|
|
|
+ noticeMessage.put("message", "您有一笔交易即将开始, 请及时前往查看");
|
|
|
+ lifeNotice.setContext(noticeMessage.toJSONString());
|
|
|
+ lifeNoticeMapper.insert(lifeNotice);
|
|
|
+
|
|
|
+ // 给买家推送通知
|
|
|
+ webSocketVo = new WebSocketVo();
|
|
|
+ webSocketVo.setSenderId("system");
|
|
|
+ webSocketVo.setReceiverId(buyerPhoneId);
|
|
|
+ webSocketVo.setCategory("notice");
|
|
|
+ webSocketVo.setNoticeType("1");
|
|
|
+ webSocketVo.setType("5");
|
|
|
+ webSocketVo.setText(JSONObject.from(lifeNotice).toJSONString());
|
|
|
+ webSocketVo.setMessageId(lifeMessage.getId());
|
|
|
+ alienStoreFeign.sendMsgToClientByPhoneId(buyerPhoneId, JSONObject.from(webSocketVo).toJSONString());
|
|
|
+
|
|
|
+ // 给卖家发送消息
|
|
|
+ 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, JSONObject.from(webSocketVo).toJSONString());
|
|
|
+
|
|
|
+ // 给卖家发送通知
|
|
|
+ lifeNotice = new LifeNotice();
|
|
|
+ lifeNotice.setSenderId("system");
|
|
|
+ lifeNotice.setReceiverId(sellerPhoneId);
|
|
|
+ lifeNotice.setBusinessId(tradeRecord.getId());
|
|
|
+ lifeNotice.setTitle("商品交易签到");
|
|
|
+ lifeNotice.setNoticeType(1);
|
|
|
+ // 封装通知信息
|
|
|
+ noticeMessage = new JSONObject();
|
|
|
+ noticeMessage.put("tradeId", tradeRecord.getId());
|
|
|
+ noticeMessage.put("otherSideUserId", tradeRecord.getBuyerId());
|
|
|
+ noticeMessage.put("otherSidePhoneId", buyerPhoneId);
|
|
|
+ noticeMessage.put("otherSideName", null == buyer ? "" : buyer.getUserName());
|
|
|
+ noticeMessage.put("otherSideImage", null == buyer ? "" : buyer.getUserImage());
|
|
|
+ noticeMessage.put("message", "您有一笔交易即将开始, 请及时前往查看");
|
|
|
+ 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.setText(JSONObject.from(lifeNotice).toJSONString());
|
|
|
+ webSocketVo.setMessageId(lifeMessage.getId());
|
|
|
+ alienStoreFeign.sendMsgToClientByPhoneId(sellerPhoneId, JSONObject.from(webSocketVo).toJSONString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("SecondTradeRecordServiceImpl.sendSignInMessage(): Error Msg={}", e.getMessage());
|
|
|
+ throw new Exception(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|