|
|
@@ -1,6 +1,9 @@
|
|
|
package com.td.boss.game.complayergoods.service;
|
|
|
|
|
|
+import com.riven.redisson.annotation.RedissonListener;
|
|
|
+import com.riven.redisson.message.RedissonHeaders;
|
|
|
import com.td.boss.common.service.*;
|
|
|
+import com.td.boss.config.delay.pojo.PlayerGoods;
|
|
|
import com.td.boss.game.complayergoods.pojo.ComPlayerGoods;
|
|
|
import com.td.boss.game.complayergoods.vo.ComPlayerGoodsSimpleVo;
|
|
|
import com.td.boss.game.complayergoods.vo.ComPlayerGoodsTypeSumVo;
|
|
|
@@ -8,8 +11,11 @@ import com.td.boss.game.complayergoods.vo.ComPlayerGoodsVo;
|
|
|
import com.td.boss.game.complayergoods.repository.ComPlayerGoodsRepository;
|
|
|
import com.td.boss.util.CopyUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.messaging.handler.annotation.Header;
|
|
|
+import org.springframework.messaging.handler.annotation.Payload;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import javax.persistence.EntityManager;
|
|
|
import javax.persistence.PersistenceContext;
|
|
|
import java.util.List;
|
|
|
@@ -17,7 +23,7 @@ import java.util.Optional;
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
|
-public class ComPlayerGoodsServiceImpl extends CommonServiceImpl<ComPlayerGoodsVo, ComPlayerGoods, String> implements ComPlayerGoodsService{
|
|
|
+public class ComPlayerGoodsServiceImpl extends CommonServiceImpl<ComPlayerGoodsVo, ComPlayerGoods, String> implements ComPlayerGoodsService {
|
|
|
|
|
|
@PersistenceContext
|
|
|
private EntityManager em;
|
|
|
@@ -26,8 +32,8 @@ public class ComPlayerGoodsServiceImpl extends CommonServiceImpl<ComPlayerGoodsV
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public ComPlayerGoods findByUserIdAndIndexAndType(String userId,Integer index, Integer type) {
|
|
|
- Optional<ComPlayerGoods> comPlayerGoods = comPlayerGoodsRepository.findByUserIdAndGoodsIndexAndGoodsType(userId,index,type);
|
|
|
+ public ComPlayerGoods findByUserIdAndIndexAndType(String userId, Integer index, Integer type) {
|
|
|
+ Optional<ComPlayerGoods> comPlayerGoods = comPlayerGoodsRepository.findByUserIdAndGoodsIndexAndGoodsType(userId, index, type);
|
|
|
return comPlayerGoods.orElse(null);
|
|
|
}
|
|
|
|
|
|
@@ -41,4 +47,44 @@ public class ComPlayerGoodsServiceImpl extends CommonServiceImpl<ComPlayerGoodsV
|
|
|
public List<ComPlayerGoodsTypeSumVo> findAllGroupByGoodsType() {
|
|
|
return comPlayerGoodsRepository.findAmountSumByGoodsType();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理仓库断电损耗 延迟任务
|
|
|
+ *
|
|
|
+ * @param messageId 消息id
|
|
|
+ * @param queue 队列
|
|
|
+ * @param sendTimestamp 发送时间戳
|
|
|
+ * @param expectedDelayMillis 预计延迟
|
|
|
+ * @param myHeader 头
|
|
|
+ * @param playerGoods 玩家物品
|
|
|
+ */
|
|
|
+ @RedissonListener(queues = "playerGoods", messageConverter = "playerGoodsMessageConverter")
|
|
|
+ public void handler(@Header(value = RedissonHeaders.MESSAGE_ID, required = false) String messageId,
|
|
|
+ @Header(RedissonHeaders.DELIVERY_QUEUE_NAME) String queue,
|
|
|
+ @Header(RedissonHeaders.SEND_TIMESTAMP) long sendTimestamp,
|
|
|
+ @Header(RedissonHeaders.EXPECTED_DELAY_MILLIS) long expectedDelayMillis,
|
|
|
+ @Header(value = "my_header", required = false, defaultValue = "test") String myHeader,
|
|
|
+ @Payload PlayerGoods playerGoods) {
|
|
|
+ /**
|
|
|
+ * 1.注入
|
|
|
+ * @Autowired
|
|
|
+ * private RedissonTemplate redissonTemplate;
|
|
|
+ *
|
|
|
+ * 2.像队列中添加延迟任务
|
|
|
+ * PlayerGoods playerGoods = new PlayerGoods();
|
|
|
+ * playerGoods.setUserId("1002");
|
|
|
+ * redissonTemplate.sendWithDelay("playerGoods", playerGoods, 10000);
|
|
|
+ */
|
|
|
+
|
|
|
+ System.out.println(messageId);
|
|
|
+ System.out.println(queue);
|
|
|
+ System.out.println(myHeader);
|
|
|
+ long actualDelay = System.currentTimeMillis() - (sendTimestamp + expectedDelayMillis);
|
|
|
+ System.out.println("receive " + playerGoods + ", delayed " + actualDelay + " millis");
|
|
|
+
|
|
|
+ List<ComPlayerGoods> allByUserId = comPlayerGoodsRepository.findAllByUserId(playerGoods.getUserId());
|
|
|
+ System.out.println("查一下:" + allByUserId);
|
|
|
+ System.out.println(allByUserId);
|
|
|
+
|
|
|
+ }
|
|
|
}
|