From d4093d81c0d60e830cb8372b40c1d7d042ce9239 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期四, 19 六月 2025 19:38:04 +0800 Subject: [PATCH] 修改直播列表 --- ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/lottery/LotteryEventServiceImpl.java | 116 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 58 insertions(+), 58 deletions(-) diff --git a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/lottery/LotteryEventServiceImpl.java b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/lottery/LotteryEventServiceImpl.java index 6becbd0..3fa41a3 100644 --- a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/lottery/LotteryEventServiceImpl.java +++ b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/lottery/LotteryEventServiceImpl.java @@ -39,7 +39,7 @@ * @Date 2025/5/8 18:05 */ @Service -public class LotteryEventServiceImpl extends ServiceImpl<LotteryEventMapper, LotteryEvent> implements ILotteryEventService { +public class LotteryEventServiceImpl extends ServiceImpl<LotteryEventMapper, TLotteryEvent> implements ILotteryEventService { @Resource private IUserLotteryEventService userLotteryEventService; @@ -77,20 +77,20 @@ @Override public LotteryEventVo getLotteryEvent(String id) { Long userId = SecurityUtils.getUserId(); - LotteryEvent lotteryEvent = this.getById(id); + TLotteryEvent lotteryEvent = this.getById(id); //构建返回结果 LotteryEventVo vo = new LotteryEventVo(); vo.setId(lotteryEvent.getId()); vo.setName(lotteryEvent.getName()); vo.setActivityProfile(lotteryEvent.getActivityProfile()); - List<UserLotteryEvent> userLotteryEvents = userLotteryEventService.list(new QueryWrapper<UserLotteryEvent>().eq("lottery_event_id", id)); + List<TUserLotteryEvent> userLotteryEvents = userLotteryEventService.list(new QueryWrapper<TUserLotteryEvent>().eq("lottery_event_id", id)); vo.setLaveTimes(lotteryEvent.getTimes() - userLotteryEvents.size()); //查询抽检活动奖品 - List<LotteryEventPrize> lotteryEventPrizeList = lotteryEventPrizeService.list(new QueryWrapper<LotteryEventPrize>().eq("lottery_event_id", id)); + List<TLotteryEventPrize> lotteryEventPrizeList = lotteryEventPrizeService.list(new QueryWrapper<TLotteryEventPrize>().eq("lottery_event_id", id)); vo.setPrizeList(lotteryEventPrizeList); //答题正确率 if (5 == lotteryEvent.getActivityType()) { - UserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<UserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); + TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); if (null == questionsServiceOne) { vo.setCorrectAnswerRate(questionsServiceOne.getCorrectAnswerRate()); } @@ -129,10 +129,10 @@ public R lotteryDraw(String id) { Long userId = SecurityUtils.getUserId(); Member member = remoteMemberService.getMember(userId).getData(); - LotteryEvent lotteryEvent = this.getById(id); + TLotteryEvent lotteryEvent = this.getById(id); //判断答题抽奖是否满足抽奖条件 if (lotteryEvent.getActivityType() == 5) { - UserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<UserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); + TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); if (questionsServiceOne.getCorrectAnswerRate().compareTo(lotteryEvent.getAccuracy()) < 0) { return R.fail("答题抽奖失败,答题正确率低于活动要求"); } @@ -144,17 +144,17 @@ boolean tryLock = lock.tryLock(30, TimeUnit.SECONDS); if (tryLock) { //判断抽奖次数是否用完 - int count = userLotteryEventService.count(new QueryWrapper<UserLotteryEvent>().eq("lottery_event_id", id).eq("user_id", userId)); + int count = userLotteryEventService.count(new QueryWrapper<TUserLotteryEvent>().eq("lottery_event_id", id).eq("user_id", userId)); if (lotteryEvent.getTimes() <= count) { return R.fail("抽奖次数已用完"); } - List<LotteryEventPrize> lotteryEventPrizeList = lotteryEventPrizeService.list(new QueryWrapper<LotteryEventPrize>().eq("lottery_event_id", id)); + List<TLotteryEventPrize> lotteryEventPrizeList = lotteryEventPrizeService.list(new QueryWrapper<TLotteryEventPrize>().eq("lottery_event_id", id)); //开始抽奖,根据中奖概率来抽奖 - List<LotteryEventPrize> list = new ArrayList<>(); - for (LotteryEventPrize lotteryEventPrize : lotteryEventPrizeList) { + List<TLotteryEventPrize> list = new ArrayList<>(); + for (TLotteryEventPrize lotteryEventPrize : lotteryEventPrizeList) { int winRate = lotteryEventPrize.getWinRate().intValue(); for (int i = 0; i < winRate; i++) { - LotteryEventPrize event = new LotteryEventPrize(); + TLotteryEventPrize event = new TLotteryEventPrize(); BeanUtil.copyProperties(lotteryEventPrize, event); list.add(event); } @@ -163,9 +163,9 @@ Collections.shuffle(list); //开始获取随机数 int random = new Random().nextInt(list.size()); - LotteryEventPrize lotteryEventPrize = lotteryEventPrizeList.get(random); + TLotteryEventPrize lotteryEventPrize = lotteryEventPrizeList.get(random); //添加中奖商品 - UserLotteryEvent userLotteryEvent = new UserLotteryEvent(); + TUserLotteryEvent userLotteryEvent = new TUserLotteryEvent(); userLotteryEvent.setId(IdUtils.simpleUUID()); userLotteryEvent.setUserId(userId); userLotteryEvent.setLotteryEventId(id); @@ -258,12 +258,12 @@ @Transactional public R editLotteryEvent(MgtLotteryEventEditDTO dto) { //先检查开始-结束时间范围内,系统中是否有该活动 - List<LotteryEvent> lotteryEvents = this.baseMapper.selectList(new LambdaQueryWrapper<LotteryEvent>() - .eq(LotteryEvent::getDelFlag, 0)//未删除的 - .eq(LotteryEvent::getActivityType, dto.getActivityType())//类型相同的 - .between(LotteryEvent::getStartTime, dto.getStartTime(), dto.getEndTime())//开始时间在这个活动的(开始-结束)范围内的 + List<TLotteryEvent> lotteryEvents = this.baseMapper.selectList(new LambdaQueryWrapper<TLotteryEvent>() + .eq(TLotteryEvent::getDelFlag, 0)//未删除的 + .eq(TLotteryEvent::getActivityType, dto.getActivityType())//类型相同的 + .between(TLotteryEvent::getStartTime, dto.getStartTime(), dto.getEndTime())//开始时间在这个活动的(开始-结束)范围内的 .or() - .between(LotteryEvent::getEndTime, dto.getStartTime(), dto.getEndTime())//结束时间在这个活动的(开始-结束)范围内的 + .between(TLotteryEvent::getEndTime, dto.getStartTime(), dto.getEndTime())//结束时间在这个活动的(开始-结束)范围内的 ); if (null != lotteryEvents && !lotteryEvents.isEmpty()) { // 新增记录时直接返回错误 @@ -277,32 +277,32 @@ return R.fail("编辑抽奖活动与现有其他活动时间范围冲突"); } } - LotteryEvent lotteryEvent = new LotteryEvent(); + TLotteryEvent lotteryEvent = new TLotteryEvent(); if (null != dto.getId()) { //编辑 lotteryEvent=this.baseMapper.selectById(dto.getId()); - if (null == lotteryEvent||lotteryEvent.getDelFlag() != 0) { + if (null == lotteryEvent || lotteryEvent.getDelFlag() != 0) { return R.fail("该抽奖活动已被删除"); } if (!lotteryEvent.getActivityType().equals(dto.getActivityType())) { return R.fail("编辑抽奖活动不能修改开启方式"); } - if(!lotteryEvent.getName().equals(dto.getName())) { + if (!lotteryEvent.getName().equals(dto.getName())) { return R.fail("编辑抽奖活动不能修改抽奖名称"); } //答题类型 - if (lotteryEvent.getActivityType().equals(5)){ - //将之前的题干数据、答案选项数据删除 + if (lotteryEvent.getActivityType().equals(5)) { + //将之前的题干数据、答案选项数据删除 //先删除答案选项数据 - lotteryEventQuestionsAnswersService.remove(new LambdaQueryWrapper<LotteryEventQuestionsAnswers>() - .eq(LotteryEventQuestionsAnswers::getLotteryEventId,lotteryEvent.getId())); + lotteryEventQuestionsAnswersService.remove(new LambdaQueryWrapper<TLotteryEventQuestionsAnswers>() + .eq(TLotteryEventQuestionsAnswers::getLotteryEventId, lotteryEvent.getId())); //再删除题干数据 - lotteryEventQuestionsService.remove(new LambdaQueryWrapper<LotteryEventQuestions>() - .eq(LotteryEventQuestions::getLotteryEventId,lotteryEvent.getId())); + lotteryEventQuestionsService.remove(new LambdaQueryWrapper<TLotteryEventQuestions>() + .eq(TLotteryEventQuestions::getLotteryEventId, lotteryEvent.getId())); } //奖品数据删除 - /*lotteryEventPrizeService.remove(new LambdaQueryWrapper<LotteryEventPrize>() - .eq(LotteryEventPrize::getLotteryEventId,lotteryEvent.getId()));*/ + /*lotteryEventPrizeService.remove(new LambdaQueryWrapper<TLotteryEventPrize>() + .eq(TLotteryEventPrize::getLotteryEventId,lotteryEvent.getId()));*/ lotteryEventPrizeService.deleteByLotteryEventId(lotteryEvent.getId()); } //新增 @@ -312,21 +312,21 @@ lotteryEvent.setId(IdUtils.simpleUUID()); lotteryEvent.setCreateTime(LocalDateTime.now()); lotteryEvent.setCreateUserId(dto.getUserId()); - }else { + } else { lotteryEvent.setUpdateTime(LocalDateTime.now()); lotteryEvent.setUpdateUserId(dto.getUserId()); } //保存抽奖活动 this.saveOrUpdate(lotteryEvent); // 保存奖品数据 - LotteryEvent finalLotteryEvent = lotteryEvent;//jdk8及之后 变量在初始化后确实没有被重新赋值,可直接引用,无需显式声明为 final - List<LotteryEventPrize> prizeList = dto.getMgtLotteryEventPrizeDTOList().stream() + TLotteryEvent finalLotteryEvent = lotteryEvent;//jdk8及之后 变量在初始化后确实没有被重新赋值,可直接引用,无需显式声明为 final + List<TLotteryEventPrize> prizeList = dto.getMgtLotteryEventPrizeDTOList().stream() .map(prizeDTO -> { - LotteryEventPrize prize = new LotteryEventPrize(); + TLotteryEventPrize prize = new TLotteryEventPrize(); prize.setId(IdUtils.simpleUUID()); prize.setLotteryEventId(finalLotteryEvent.getId()); prize.setPrizeType(prizeDTO.getPrizeType()); - if (null != prizeDTO.getObjectId()){ + if (null != prizeDTO.getObjectId()) { prize.setObjectId(prizeDTO.getObjectId()); } prize.setObjectName(prizeDTO.getObjectName()); @@ -340,16 +340,16 @@ if (dto.getActivityType().equals(5)) { //保存题干数据 for (MgtLotteryEventQuestionDTO questionDTO : dto.getMgtLotteryQuestionDTOList()) { - LotteryEventQuestions question = new LotteryEventQuestions(); + TLotteryEventQuestions question = new TLotteryEventQuestions(); question.setId(IdUtils.simpleUUID()); question.setLotteryEventId(finalLotteryEvent.getId()); question.setName(questionDTO.getName()); question.setSort(questionDTO.getSort()); lotteryEventQuestionsService.save(question); //保存答案选项数据 - List<LotteryEventQuestionsAnswers> answersList = questionDTO.getAnswersDTOList().stream() + List<TLotteryEventQuestionsAnswers> answersList = questionDTO.getAnswersDTOList().stream() .map(answersDTO -> { - LotteryEventQuestionsAnswers answer = new LotteryEventQuestionsAnswers(); + TLotteryEventQuestionsAnswers answer = new TLotteryEventQuestionsAnswers(); answer.setId(IdUtils.simpleUUID()); answer.setLotteryEventId(finalLotteryEvent.getId()); answer.setLotteryEventQuestionsId(question.getId()); @@ -411,7 +411,7 @@ @Override public R<MgtLotteryEventDetailVO> getLotteryEventDetailById(String id) { - LotteryEvent lotteryEvent = this.getById(id); + TLotteryEvent lotteryEvent = this.getById(id); if (null == lotteryEvent) { return R.fail("该抽奖活动不存在"); } @@ -426,23 +426,23 @@ } if(lotteryEvent.getActivityType()==5){ //题干数据 - List<LotteryEventQuestions> questionsList = lotteryEventQuestionsService.getBaseMapper().selectList(new LambdaQueryWrapper<LotteryEventQuestions>().eq(LotteryEventQuestions::getLotteryEventId, lotteryEvent.getId())); + List<TLotteryEventQuestions> questionsList = lotteryEventQuestionsService.getBaseMapper().selectList(new LambdaQueryWrapper<TLotteryEventQuestions>().eq(TLotteryEventQuestions::getLotteryEventId, lotteryEvent.getId())); List<MgtLotteryEventQuestionVO> questionsVOList = questionsList.stream().map(question -> { MgtLotteryEventQuestionVO questionVO = new MgtLotteryEventQuestionVO(); BeanUtils.copyProperties(question, questionVO); //答案选项数据 - List<LotteryEventQuestionsAnswers> answersList = lotteryEventQuestionsAnswersService.getBaseMapper().selectList(new LambdaQueryWrapper<LotteryEventQuestionsAnswers>() - .eq(LotteryEventQuestionsAnswers::getLotteryEventId, lotteryEvent.getId()) - .eq(LotteryEventQuestionsAnswers::getLotteryEventQuestionsId, questionVO.getId())); + List<TLotteryEventQuestionsAnswers> answersList = lotteryEventQuestionsAnswersService.getBaseMapper().selectList(new LambdaQueryWrapper<TLotteryEventQuestionsAnswers>() + .eq(TLotteryEventQuestionsAnswers::getLotteryEventId, lotteryEvent.getId()) + .eq(TLotteryEventQuestionsAnswers::getLotteryEventQuestionsId, questionVO.getId())); questionVO.setAnswersVOList(answersList); return questionVO; }).collect(Collectors.toList()); //题干数据排序 // 自定义 Comparator 实现 - Comparator<LotteryEventQuestions> sortComparator = new Comparator<LotteryEventQuestions>() { + Comparator<TLotteryEventQuestions> sortComparator = new Comparator<TLotteryEventQuestions>() { @Override - public int compare(LotteryEventQuestions q1, LotteryEventQuestions q2) { + public int compare(TLotteryEventQuestions q1, TLotteryEventQuestions q2) { return Integer.compare(q1.getSort(), q2.getSort()); } }; @@ -451,33 +451,33 @@ vo.setMgtLotteryQuestionVOList(questionsVOList); } //奖项信息 - /*List<LotteryEventPrize> prizeList = lotteryEventPrizeService.getBaseMapper().selectList(new LambdaQueryWrapper<LotteryEventPrize>() - .eq(LotteryEventPrize::getLotteryEventId, lotteryEvent.getId()));*/ - List<LotteryEventPrize> prizeList = lotteryEventPrizeService.getPrizeListByLotteryEventId(lotteryEvent.getId()); + /*List<TLotteryEventPrize> prizeList = lotteryEventPrizeService.getBaseMapper().selectList(new LambdaQueryWrapper<TLotteryEventPrize>() + .eq(TLotteryEventPrize::getLotteryEventId, lotteryEvent.getId()));*/ + List<TLotteryEventPrize> prizeList = lotteryEventPrizeService.getPrizeListByLotteryEventId(lotteryEvent.getId()); vo.setLotteryEventPrizeList(prizeList); - + return R.ok(vo); } @Override public R deleteMgtLotteryEvent(String id) { - LotteryEvent lotteryEvent = this.getById(id); + TLotteryEvent lotteryEvent = this.getById(id); if (null == lotteryEvent || lotteryEvent.getDelFlag()!=0) { return R.ok(); } //1.奖品数据删除 -/* lotteryEventPrizeService.remove(new LambdaQueryWrapper<LotteryEventPrize>() - .eq(LotteryEventPrize::getLotteryEventId,lotteryEvent.getId()));*/ +/* lotteryEventPrizeService.remove(new LambdaQueryWrapper<TLotteryEventPrize>() + .eq(TLotteryEventPrize::getLotteryEventId,lotteryEvent.getId()));*/ lotteryEventPrizeService.deleteByLotteryEventId(lotteryEvent.getId()); //2.答题类型 - if (lotteryEvent.getActivityType().equals(5)){ + if (lotteryEvent.getActivityType().equals(5)) { //先删除答案选项数据 - lotteryEventQuestionsAnswersService.remove(new LambdaQueryWrapper<LotteryEventQuestionsAnswers>() - .eq(LotteryEventQuestionsAnswers::getLotteryEventId,lotteryEvent.getId())); + lotteryEventQuestionsAnswersService.remove(new LambdaQueryWrapper<TLotteryEventQuestionsAnswers>() + .eq(TLotteryEventQuestionsAnswers::getLotteryEventId, lotteryEvent.getId())); //再删除题干数据 - lotteryEventQuestionsService.remove(new LambdaQueryWrapper<LotteryEventQuestions>() - .eq(LotteryEventQuestions::getLotteryEventId,lotteryEvent.getId())); + lotteryEventQuestionsService.remove(new LambdaQueryWrapper<TLotteryEventQuestions>() + .eq(TLotteryEventQuestions::getLotteryEventId, lotteryEvent.getId())); } //3.抽奖活动删除 lotteryEvent.setDelFlag(1); @@ -487,7 +487,7 @@ @Override public R endImmediatelyLotteryEvent(String id) { - LotteryEvent lotteryEvent = this.getById(id); + TLotteryEvent lotteryEvent = this.getById(id); if (null == lotteryEvent || lotteryEvent.getDelFlag()!=0) { return R.fail("该抽奖活动不存在"); } -- Gitblit v1.7.1