| | |
| | | Long userId = SecurityUtils.getUserId(); |
| | | TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).eq("user_id", userId)); |
| | | LotteryEventQuestionsVo vo = new LotteryEventQuestionsVo(); |
| | | vo.setId(dto.getId()); |
| | | int count = lotteryEventServiceQuestionsService.count(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId())); |
| | | vo.setTotal(count); |
| | | //没有答题,直接从第一题开始 |
| | |
| | | } |
| | | current--; |
| | | } else { |
| | | current++; |
| | | //下一题 |
| | | current++; |
| | | if (current >= count) { |
| | |
| | | public R<Boolean> endAnswerQuestion(@PathVariable("id") String id) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | TLotteryEvent lotteryEvent = lotteryEventService.getById(id); |
| | | if(null == lotteryEvent){ |
| | | return R.fail("无效的抽奖活动id"); |
| | | } |
| | | TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | if (null == questionsServiceOne) { |
| | | questionsServiceOne = new TUserLotteryEventQuestions(); |
| | |
| | | questionsServiceOne.setStatus(2); |
| | | questionsServiceOne.setEndTime(LocalDateTime.now()); |
| | | //计算正确率 |
| | | List<TUserLotteryEventQuestionsAnswers> list = userLotteryEventQuestionsAnswersService.list(new QueryWrapper<TUserLotteryEventQuestionsAnswers>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | int count = list.size(); |
| | | int right = list.stream().filter(item -> 1 == item.getIsCorrect()).collect(Collectors.toList()).size(); |
| | | int count = lotteryEventQuestionsAnswersService.count(new QueryWrapper<TLotteryEventQuestionsAnswers>().eq("lottery_event_id", id)); |
| | | int right = userLotteryEventQuestionsAnswersService.count(new QueryWrapper<TUserLotteryEventQuestionsAnswers>().eq("lottery_event_id", id).eq("user_id", userId).eq("is_correct", 1)); |
| | | BigDecimal multiply = new BigDecimal(right).divide(new BigDecimal(count), 4, BigDecimal.ROUND_HALF_UP).setScale(4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)); |
| | | questionsServiceOne.setCorrectAnswerRate(multiply); |
| | | userLotteryEventQuestionsService.saveOrUpdate(questionsServiceOne); |