diff --git a/luoo_common/src/main/java/dto/UserMessageDto.java b/luoo_common/src/main/java/dto/UserMessageDto.java index 2f2fea0..5f7a983 100644 --- a/luoo_common/src/main/java/dto/UserMessageDto.java +++ b/luoo_common/src/main/java/dto/UserMessageDto.java @@ -48,7 +48,9 @@ public class UserMessageDto implements Serializable { */ private String content; + private String objectId; + private String objectType; /** * 是否已读 0为未读 1为已读 */ diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java index 866f55d..e10bee5 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java @@ -89,6 +89,7 @@ public class UserMessageController extends BaseController { UserMessage userMessageComment = userMessageService.findByUseridAndType(userId,MessageTypeEnum.COMMENT.getType());// 评论 UserMessage userMessageFollow = userMessageService.findByUseridAndType(userId,MessageTypeEnum.FOLLOW.getType());// UserMessage userMessageThumbup = userMessageService.findByUseridAndType(userId,MessageTypeEnum.THUMB_UP.getType());// + UserMessage userMessageSystem = userMessageService.findByUseridAndType(userId,MessageTypeEnum.SYSTEM_MESSAGE.getType());// 系统消息 if (null != userMessageComment) { UserInfo userInfo1 = userInfoService.findById(userMessageComment.getSendUserId()); if(null != userInfo1) { @@ -112,6 +113,7 @@ public class UserMessageController extends BaseController { map.put("comment",userMessageComment); map.put("follow",userMessageFollow); map.put("thumbup",userMessageThumbup); + map.put("system",userMessageSystem); // Page pageList = userMessageService.findSearch(userId,page,size); // return Result.success(new PageResult(pageList.getTotalElements(),pageList.getContent())); return Result.success(map); @@ -131,4 +133,19 @@ public class UserMessageController extends BaseController { return Result.success(); } + // 查询我收到的评论 + @ApiOperation(value = "查询系统消息", notes = "游客无法获取") + @GetMapping("/systemMessageList/{page}/{size}") + public Result getSystemMessage(@PathVariable int page, @PathVariable int size, + @RequestHeader(value = "Authorization", required = true) String authorization) { + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + Page pageList = userMessageService.getSystemMessageList(userId,MessageTypeEnum.SYSTEM_MESSAGE.getType(), page, size); + return Result.success(new PageResult(pageList.getTotalElements(),pageList.getContent())); + } + } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java b/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java index f5d03cd..098851e 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java @@ -19,5 +19,7 @@ public interface UserMessageDao extends MongoRepository { UserMessage findTopByUserIdOrderBySendTimeDesc(String userId); + Page findAllByUserIdAndTypeOrderBySendTimeDesc(String userId,int type,Pageable pageable); + } diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java index 78375f4..d73c0e8 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java @@ -50,6 +50,10 @@ public class UserMessage implements Serializable { */ private String content; + private String objectId; + + private String objectType; + /** * 是否已读 0为未读 1为已读 diff --git a/luoo_user/src/main/java/com/luoo/user/service/DrawLotteryService.java b/luoo_user/src/main/java/com/luoo/user/service/DrawLotteryService.java index 57222f2..7241330 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/DrawLotteryService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/DrawLotteryService.java @@ -142,6 +142,20 @@ public class DrawLotteryService { // 全部中奖 winnerList = lotteryUserList; } + lotteryUserList.forEach(lotteryUser -> { + UserMessageDto userMessageDto = new UserMessageDto(); + userMessageDto.setType(MessageTypeEnum.SYSTEM_MESSAGE.getType()); + userMessageDto.setTitle("开奖通知"); + String userId = lotteryUser.getUserId(); +// 你参与的“落网10周年纪念CD抽嚳磴㡳跆活动”已经开奖 + String content = "您参与的活动 " + lottery.getTitle() + " 已经开奖"; + userMessageDto.setContent(content); + userMessageDto.setObjectId(lottery.getId()); + userMessageDto.setObjectType("lottery"); + userMessageDto.setUserId(userId); + userMessageService.sendUserMessage(userMessageDto); + }); + winnerList.forEach(lotteryUser -> { lotteryUser.setResult(PointEnums.LOTTERY_RESULT_WIN.getCode()); @@ -153,19 +167,23 @@ public class DrawLotteryService { // 发送恭喜中奖站内信 UserMessageDto userMessageDto = new UserMessageDto(); - userMessageDto.setType(MessageTypeEnum.PRIVATE_MESSAGE.getType()); - userMessageDto.setSendUserId(StringUtils.isNotBlank(token) ? jwtUtil.getUserLoginDto(token).getUserId() : null); +// userMessageDto.setType(MessageTypeEnum.PRIVATE_MESSAGE.getType()); + userMessageDto.setType(MessageTypeEnum.SYSTEM_MESSAGE.getType()); +// userMessageDto.setSendUserId(StringUtils.isNotBlank(token) ? jwtUtil.getUserLoginDto(token).getUserId() : null); userMessageDto.setTitle("恭喜中奖!"); String userId = lotteryUser.getUserId(); UserInfo userInfo = userInfoDao.getById(userId); - String content = "亲爱的" + userInfo.getNickName() + ",您在积分抽奖 " + lottery.getTitle() + " 中幸运中奖,可以加微信号 indier 联系到我们。"; + String content = "亲爱的" + userInfo.getNickName() + ",您在积分抽奖 " + lottery.getTitle() + " 中幸运中奖!"; + userMessageDto.setObjectId(lottery.getId()); + userMessageDto.setObjectType("lottery"); // winLotteryMessages 随机选取一条 userMessageDto.setContent(content + winLotteryMessages[new Random().nextInt(winLotteryMessages.length)]); userMessageDto.setUserId(userId); - userMessageDto.setSendUserAvatar(Constants.RESOURCE_PREFIX + (StringUtils.isNotBlank(token) ? jwtUtil.getUserLoginDto(token).getAvatar() : null)); - userMessageDto.setSendUserNickName(StringUtils.isNotBlank(token) ? jwtUtil.getUserLoginDto(token).getNickName() : null); +// userMessageDto.setSendUserAvatar(Constants.RESOURCE_PREFIX + (StringUtils.isNotBlank(token) ? jwtUtil.getUserLoginDto(token).getAvatar() : null)); +// userMessageDto.setSendUserNickName(StringUtils.isNotBlank(token) ? jwtUtil.getUserLoginDto(token).getNickName() : null); + userMessageService.sendUserMessage(userMessageDto); }); } @@ -184,6 +202,7 @@ public class DrawLotteryService { // 对新列表进行洗牌操作 Collections.shuffle(shuffledList, new Random()); + // 返回前 winnersCount 个元素 return shuffledList.subList(0, Math.min(winnersCount, shuffledList.size())); } 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 e83fc9c..41cb5d2 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 @@ -318,6 +318,9 @@ public class LotteryService { lotteryDao.save(lottery); String result = drawLotteryScheduler.scheduleDraw(lottery.getApplyEndTime(), id); + + //处理定时发消息 + if (StringUtils.isNotBlank(result)) { throw new BizException(result); } diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java b/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java index 40e97d1..ad5b156 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java @@ -8,6 +8,7 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.data.mongodb.core.BulkOperations; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; @@ -91,4 +92,10 @@ public class UserMessageService { public UserMessage findByUseridAndType(String userId, int type) { return userMessageDao.findTopByUserIdAndTypeOrderBySendTimeDesc(userId,type); } + + public Page getSystemMessageList(String userId,int type, int page, int size) { + Pageable pageable = PageRequest.of(page-1,size); + + return userMessageDao.findAllByUserIdAndTypeOrderBySendTimeDesc(userId,type,pageable); + } }