| | |
| | | vo.setAnswerStartTime(null != questionsServiceOne ? questionsServiceOne.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) : null); |
| | | vo.setAnswerTimeLimit(lotteryEvent.getAnsweringTime()); |
| | | if (vo.getContinueAnswer() == 1) { |
| | | long remainingTime = lotteryEvent.getAnsweringTime() - LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")) - questionsServiceOne.getCreateTime().toEpochSecond(ZoneOffset.of("+8")); |
| | | long remainingTime = (lotteryEvent.getAnsweringTime() * 60) - (LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")) - questionsServiceOne.getCreateTime().toEpochSecond(ZoneOffset.of("+8"))); |
| | | int count1 = userLotteryEventQuestionsAnswersService.count(new QueryWrapper<TUserLotteryEventQuestionsAnswers>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | vo.setRemainingTime(remainingTime); |
| | | vo.setCurrent(count1 - 1); |
| | |
| | | Integer current = dto.getCurrent(); |
| | | if (-1 == dto.getStepOrDown()) { |
| | | if (current - 1 < 0) { |
| | | return R.fail("操作失败"); |
| | | current = 0; |
| | | } |
| | | current--; |
| | | } else { |
| | | //下一题 |
| | | if (current >= count) { |
| | | return R.fail("操作失败"); |
| | | } |
| | | current++; |
| | | //下一题 |
| | | current++; |
| | | if (current >= count) { |
| | | current = count - 1; |
| | | } |
| | | } |
| | | List<TLotteryEventQuestions> list = lotteryEventServiceQuestionsService.list(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).orderByAsc("sort")); |
| | | TLotteryEventQuestions lotteryEventQuestions = list.get(current); |
| | |
| | | map.put("name", item.getAnswers()); |
| | | return map; |
| | | }).collect(Collectors.toList()); |
| | | if (-1 == dto.getStepOrDown()) { |
| | | if (-1 == dto.getStepOrDown() || current == list.size() - 1) { |
| | | TUserLotteryEventQuestionsAnswers one = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<TUserLotteryEventQuestionsAnswers>().eq("lottery_event_id", dto.getId()).eq("user_id", userId).orderByDesc("create_time").last(" limit 0, 1")); |
| | | if (null != one) { |
| | | vo.setAnswer(lotteryEventQuestionsAnswersService.getById(one.getLotteryEventQuestionsAnswersId()).getAnswers()); |
| | |
| | | one.setLotteryEventQuestionId(lotteryEventQuestions.getId()); |
| | | one.setLotteryEventQuestionsAnswersId(lotteryEventQuestionsAnswers.getId()); |
| | | one.setCreateTime(LocalDateTime.now()); |
| | | }else{ |
| | | one.setLotteryEventQuestionsAnswersId(lotteryEventQuestionsAnswers.getId()); |
| | | } |
| | | one.setIsCorrect(0); |
| | | //答案正确 |
| | |
| | | one.setIsCorrect(1); |
| | | } |
| | | userLotteryEventQuestionsAnswersService.saveOrUpdate(one); |
| | | //判断 |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | TLotteryEvent lotteryEvent = lotteryEventService.getById(id); |
| | | TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | if (null == questionsServiceOne) { |
| | | return R.fail("请先进行答题操作"); |
| | | questionsServiceOne = new TUserLotteryEventQuestions(); |
| | | questionsServiceOne.setId(IdUtils.simpleUUID()); |
| | | questionsServiceOne.setUserId(userId); |
| | | questionsServiceOne.setLotteryEventId(id); |
| | | questionsServiceOne.setStatus(1); |
| | | questionsServiceOne.setCreateTime(LocalDateTime.now()); |
| | | } |
| | | questionsServiceOne.setStatus(2); |
| | | questionsServiceOne.setEndTime(LocalDateTime.now()); |
| | |
| | | int right = list.stream().filter(item -> 1 == item.getIsCorrect()).collect(Collectors.toList()).size(); |
| | | 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.updateById(questionsServiceOne); |
| | | userLotteryEventQuestionsService.saveOrUpdate(questionsServiceOne); |
| | | if (multiply.compareTo(lotteryEvent.getAccuracy()) >= 0) { |
| | | return R.ok(true); |
| | | } |