parent
7c27a163e0
commit
98dcb76e59
@ -0,0 +1,121 @@
|
||||
package com.luoo.user.service;
|
||||
|
||||
import com.luoo.user.dao.LotteryDao;
|
||||
import com.luoo.user.dao.LotteryUserDao;
|
||||
import com.luoo.user.dao.UserInfoDao;
|
||||
import com.luoo.user.pojo.Lottery;
|
||||
import com.luoo.user.pojo.LotteryUser;
|
||||
import com.luoo.user.pojo.QLottery;
|
||||
import com.luoo.user.pojo.UserInfo;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import dto.UserMessageDto;
|
||||
import enums.MessageTypeEnum;
|
||||
import enums.PointEnums;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @program: luoo_parent
|
||||
* @description:
|
||||
* @author: yawei.huang
|
||||
* @create: 2024-12-06 19:20
|
||||
**/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SendLotteryService {
|
||||
|
||||
// 中奖信息
|
||||
String[] winLotteryMessages = {
|
||||
"恭喜你中奖了,你的运气真是太好了,连我都想跟你借钱买彩票了!",
|
||||
"看来你的运气被幸运星咬了一口,中了个大奖!",
|
||||
"你这是中了头奖,是不是昨晚做梦都在笑啊?",
|
||||
"你的手气真是好得不得了,我都怀疑你是不是偷偷摸摸地跟财神爷打了招呼!",
|
||||
"恭喜你中奖,你这是要发家致富的节奏啊!",
|
||||
"你这是要把彩票中心吃垮的节奏啊,中了这么多奖!",
|
||||
"你的运气真是好得让人眼红,我都想拜你为师,学学怎么中奖!",
|
||||
"你的中奖概率比被闪电击中还低,你真是天生的幸运儿!",
|
||||
"你的中奖记录比我的恋爱记录还丰富,真是让人羡慕嫉妒恨!",
|
||||
"恭喜你中奖,你这是要成为我们朋友圈的土豪啊!",
|
||||
"你这是要把彩票中心的钱都赢光,让他们破产吗?",
|
||||
"你的中奖运气真是让人羡慕,我都想去拜拜财神爷,看看能不能沾沾你的光!",
|
||||
"你的中奖记录比我的考试成绩还高,真是让人佩服得五体投地!",
|
||||
"恭喜你中奖,你这是要成为我们村里的大富翁啊!"
|
||||
};
|
||||
|
||||
private final LotteryDao lotteryDao;
|
||||
|
||||
private final LotteryUserDao lotteryUserDao;
|
||||
|
||||
private final UserMessageService userMessageService;
|
||||
|
||||
private final UserInfoDao userInfoDao;
|
||||
|
||||
private final JPAQueryFactory jpaQueryFactory;
|
||||
|
||||
public SendLotteryService(LotteryDao lotteryDao, LotteryUserDao lotteryUserDao, UserMessageService userMessageService, UserInfoDao userInfoDao, JPAQueryFactory jpaQueryFactory) {
|
||||
this.lotteryDao = lotteryDao;
|
||||
this.lotteryUserDao = lotteryUserDao;
|
||||
this.userMessageService = userMessageService;
|
||||
this.userInfoDao = userInfoDao;
|
||||
this.jpaQueryFactory = jpaQueryFactory;
|
||||
}
|
||||
|
||||
|
||||
public List<Lottery> findFinishList() {
|
||||
// select * from tb_lottery where status = 2 and send_type is null
|
||||
QLottery qLottery = QLottery.lottery;
|
||||
return jpaQueryFactory.selectFrom(qLottery)
|
||||
.where(qLottery.status.eq(PointEnums.LOTTERY_STATUS_LOTTERY.getCode())
|
||||
.and(qLottery.sendType.isNull()))
|
||||
.fetch();
|
||||
}
|
||||
|
||||
public void sendLotteryResultMessage(String id) {
|
||||
|
||||
Lottery lottery = lotteryDao.findById(id).get();
|
||||
// 当前状态必须是已开奖状态
|
||||
// 必须是没有推送状态(校验状态,防止任务已被取消)
|
||||
if (Objects.equals(lottery.getStatus(), PointEnums.LOTTERY_STATUS_LOTTERY.getCode())
|
||||
&& lottery.getSendType() == null
|
||||
) {
|
||||
List<LotteryUser> lotteryUserList = lotteryUserDao.findByLotteryId(id);
|
||||
|
||||
lotteryUserList.forEach(lotteryUser -> {
|
||||
UserMessageDto userMessageDto = new UserMessageDto();
|
||||
if (Objects.equals(lotteryUser.getResult(), PointEnums.LOTTERY_RESULT_WIN.getCode())) {
|
||||
// 发送恭喜中奖站内信
|
||||
userMessageDto.setType(MessageTypeEnum.SYSTEM_MESSAGE.getType());
|
||||
userMessageDto.setTitle("恭喜中奖!");
|
||||
String userId = lotteryUser.getUserId();
|
||||
UserInfo userInfo = userInfoDao.getById(userId);
|
||||
String content = "亲爱的" + userInfo.getNickName() + ",您在积分抽奖 " + lottery.getTitle() + " 中幸运中奖!";
|
||||
userMessageDto.setObjectId(lottery.getId());
|
||||
userMessageDto.setObjectType("lottery_" + lottery.getType());
|
||||
userMessageDto.setObjectCover(lottery.getImage());
|
||||
// winLotteryMessages 随机选取一条
|
||||
userMessageDto.setContent(content + winLotteryMessages[new Random().nextInt(winLotteryMessages.length)]);
|
||||
userMessageDto.setUserId(userId);
|
||||
} else {
|
||||
userMessageDto.setType(MessageTypeEnum.SYSTEM_MESSAGE.getType());
|
||||
userMessageDto.setTitle("开奖通知");
|
||||
String userId = lotteryUser.getUserId();
|
||||
String content = "您参与的活动 " + lottery.getTitle() + " 已经开奖";
|
||||
userMessageDto.setContent(content);
|
||||
userMessageDto.setObjectId(lottery.getId());
|
||||
userMessageDto.setObjectType("lottery_" + lottery.getType());
|
||||
userMessageDto.setObjectCover(lottery.getImage());
|
||||
userMessageDto.setUserId(userId);
|
||||
}
|
||||
userMessageService.sendUserMessage(userMessageDto);
|
||||
});
|
||||
|
||||
lottery.setSendType(PointEnums.LOTTERY_STATUS_PUSH.getCode());
|
||||
lotteryDao.save(lottery);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
alter table tb_lottert
|
||||
add send_type tinyint null comment '结果是否已推送 1-已推送';
|
Loading…
Reference in new issue