release-- 完善系统消息功能,增加开奖和中奖通知功能。

release-2024-04-25
wangqing 2 months ago
parent 972ace2e1a
commit f281c47069

@ -48,7 +48,9 @@ public class UserMessageDto implements Serializable {
*/
private String content;
private String objectId;
private String objectType;
/**
* 0 1
*/

@ -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<UserMessage> pageList = userMessageService.findSearch(userId,page,size);
// return Result.success(new PageResult<UserMessage>(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<UserMessage> pageList = userMessageService.getSystemMessageList(userId,MessageTypeEnum.SYSTEM_MESSAGE.getType(), page, size);
return Result.success(new PageResult<UserMessage>(pageList.getTotalElements(),pageList.getContent()));
}
}

@ -19,5 +19,7 @@ public interface UserMessageDao extends MongoRepository<UserMessage,String> {
UserMessage findTopByUserIdOrderBySendTimeDesc(String userId);
Page<UserMessage> findAllByUserIdAndTypeOrderBySendTimeDesc(String userId,int type,Pageable pageable);
}

@ -50,6 +50,10 @@ public class UserMessage implements Serializable {
*/
private String content;
private String objectId;
private String objectType;
/**
* 0 1

@ -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()));
}

@ -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);
}

@ -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<UserMessage> getSystemMessageList(String userId,int type, int page, int size) {
Pageable pageable = PageRequest.of(page-1,size);
return userMessageDao.findAllByUserIdAndTypeOrderBySendTimeDesc(userId,type,pageable);
}
}

Loading…
Cancel
Save