diff --git a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java index 8f1edc5..88529c1 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java +++ b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java @@ -4,6 +4,7 @@ package com.luoo.comment.controller; import api.PageResult; import api.Result; import api.StatusCode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.github.houbb.sensitive.word.bs.SensitiveWordBs; import com.github.houbb.sensitive.word.core.SensitiveWordHelper; import com.luoo.comment.dao.PublicationLikeDao; @@ -42,6 +43,7 @@ import util.IdWorker; import util.StringTools; import javax.servlet.http.HttpServletRequest; +import java.io.IOException; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -373,7 +375,16 @@ public class CommentController extends BaseController { .userId(userLoginDto.getUserId()) .build(); - rabbitTemplate.convertAndSend("pointLog", userPointLog); + ObjectMapper objectMapper = new ObjectMapper(); + + try { + String json = objectMapper.writeValueAsString(userPointLog); + System.out.println(json); + + rabbitTemplate.convertAndSend("pointLog", json); + } catch (IOException e) { + e.printStackTrace(); + } return Result.success(commentResp); } diff --git a/luoo_user/src/main/java/com/luoo/user/listener/PointLogListener.java b/luoo_user/src/main/java/com/luoo/user/listener/PointLogListener.java index 6187463..42c1468 100644 --- a/luoo_user/src/main/java/com/luoo/user/listener/PointLogListener.java +++ b/luoo_user/src/main/java/com/luoo/user/listener/PointLogListener.java @@ -1,5 +1,6 @@ package com.luoo.user.listener; +import com.fasterxml.jackson.databind.ObjectMapper; import com.luoo.user.pojo.UserPointLog; import com.luoo.user.service.UserPointLogService; import lombok.extern.slf4j.Slf4j; @@ -9,6 +10,9 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.io.IOException; +import java.util.Map; + /** * @program: luoo_parent * @description: 积分日志队列 @@ -24,11 +28,18 @@ public class PointLogListener { private UserPointLogService userPointLogService; @RabbitHandler - public void executePointLog(Object userPointLog) { - log.info("userPointLog:{}", userPointLog); - UserPointLog result = new UserPointLog(); - BeanUtils.copyProperties(userPointLog, result); - userPointLogService.add(result); + public void executePointLog(String json) { + log.info("userPointLog:{}", json); + + ObjectMapper objectMapper = new ObjectMapper(); + + try { + UserPointLog userPointLog = objectMapper.readValue(json, UserPointLog.class); + userPointLogService.add(userPointLog); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java b/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java index fba3ef0..5b481bf 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java @@ -1,6 +1,7 @@ package com.luoo.user.service; import api.PageResult; +import com.fasterxml.jackson.databind.ObjectMapper; import com.luoo.user.Scheduler.DrawLotteryScheduler; import com.luoo.user.config.EnvConfig; import com.luoo.user.dao.LotteryDao; @@ -21,6 +22,7 @@ import enums.UserTypeEnum; import enums.UserVipStatusEnum; import exception.BizException; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -306,7 +308,16 @@ public class LotteryService { .score(lottery.getPoint()) .build(); - rabbitTemplate.convertAndSend("pointLog", userPointLog); + ObjectMapper objectMapper = new ObjectMapper(); + + try { + String json = objectMapper.writeValueAsString(userPointLog); + System.out.println(json); + + rabbitTemplate.convertAndSend("pointLog", json); + } catch (IOException e) { + e.printStackTrace(); + } }); diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java index d519c7e..fece562 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java @@ -1,6 +1,7 @@ package com.luoo.user.service; import api.PageResult; +import com.fasterxml.jackson.databind.ObjectMapper; import com.luoo.user.dao.LotteryUserDao; import com.luoo.user.dao.TaskPointDao; import com.luoo.user.dao.UserInfoDao; @@ -19,6 +20,7 @@ import constants.TaskPointIdConstants; import dto.UserLoginDto; import enums.PointEnums; +import java.io.IOException; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.List; @@ -133,7 +135,16 @@ public class UserPointLogService { .userId(userId) .build(); - rabbitTemplate.convertAndSend("pointLog", userPointLog); + ObjectMapper objectMapper = new ObjectMapper(); + + try { + String json = objectMapper.writeValueAsString(userPointLog); + System.out.println(json); + + rabbitTemplate.convertAndSend("pointLog", json); + } catch (IOException e) { + e.printStackTrace(); + } } private void addByTask(String taskPointId, UserLoginDto userLoginDto) { @@ -146,7 +157,16 @@ public class UserPointLogService { .userId(userLoginDto.getUserId()) .build(); - rabbitTemplate.convertAndSend("pointLog", userPointLog); + ObjectMapper objectMapper = new ObjectMapper(); + + try { + String json = objectMapper.writeValueAsString(userPointLog); + System.out.println(json); + + rabbitTemplate.convertAndSend("pointLog", json); + } catch (IOException e) { + e.printStackTrace(); + } } /**