| | |
| | | page.setSize(dto.getPageSize()); |
| | | page.setCurrent(dto.getPageNum()); |
| | | List<AppLotteryEventPageVo> activityPageVoList = lotteryEventService.pageAppLotteryEvent(page,userId); |
| | | activityPageVoList.forEach(vo -> { |
| | | String startTime = vo.getStartTime(); |
| | | String endTime = vo.getEndTime(); |
| | | if (LocalDateTime.now().isBefore(LocalDateTime.parse(startTime))) { |
| | | vo.setStatus(1); |
| | | } |
| | | if (LocalDateTime.now().isAfter(LocalDateTime.parse(endTime))) { |
| | | vo.setStatus(3); |
| | | } |
| | | if (LocalDateTime.now().isAfter(LocalDateTime.parse(startTime)) && LocalDateTime.now().isBefore(LocalDateTime.parse(endTime))) { |
| | | vo.setStatus(2); |
| | | } |
| | | }); |
| | | return R.ok(page.setRecords(activityPageVoList)); |
| | | } |
| | | |
| | |
| | | }) |
| | | public R<LotteryEventInfoVo> getLotteryEventInfo(@PathVariable("id") String id){ |
| | | Long userId = SecurityUtils.getUserId(); |
| | | LotteryEvent lotteryEvent = lotteryEventService.getById(id); |
| | | TLotteryEvent lotteryEvent = lotteryEventService.getById(id); |
| | | LotteryEventInfoVo vo = new LotteryEventInfoVo(); |
| | | vo.setId(lotteryEvent.getId()); |
| | | vo.setName(lotteryEvent.getName()); |
| | | vo.setActivityProfile(lotteryEvent.getActivityProfile()); |
| | | vo.setStartTime(lotteryEvent.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | vo.setActivityContent(lotteryEvent.getActivityContent()); |
| | | 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)); |
| | | vo.setParticipation(count > 0); |
| | | //答题抽奖需要判断是否答题完成 |
| | | if (5 == lotteryEvent.getActivityType()) { |
| | | UserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<UserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | vo.setContinueAnswer(null != questionsServiceOne ? questionsServiceOne.getStatus() : 0); |
| | | vo.setAnswerStartTime(null != questionsServiceOne ? questionsServiceOne.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) : null); |
| | | vo.setAnswerTimeLimit(lotteryEvent.getAnsweringTime()); |
| | |
| | | @ApiOperation(value = "获取答题题目【2.0】", tags = "抽奖活动") |
| | | public R<LotteryEventQuestionsVo> getLotteryEventQuestions(@RequestBody LotteryEventQuestionsDto dto) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | UserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<UserLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).eq("user_id", userId)); |
| | | TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).eq("user_id", userId)); |
| | | LotteryEventQuestionsVo vo = new LotteryEventQuestionsVo(); |
| | | int count = lotteryEventServiceQuestionsService.count(new QueryWrapper<LotteryEventQuestions>().eq("lottery_event_id", dto.getId())); |
| | | int count = lotteryEventServiceQuestionsService.count(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId())); |
| | | vo.setTotal(count); |
| | | //没有答题,直接从第一题开始 |
| | | if (null == questionsServiceOne) { |
| | | if (-1 == dto.getStepOrDown()) { |
| | | return R.fail("操作失败"); |
| | | } |
| | | LotteryEventQuestions questions = lotteryEventServiceQuestionsService.getOne(new QueryWrapper<LotteryEventQuestions>().eq("lottery_event_id", dto.getId()).orderByAsc("sort")); |
| | | vo.setCurrent(1); |
| | | TLotteryEventQuestions questions = lotteryEventServiceQuestionsService.getOne(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).orderByAsc("sort").last(" limit 1")); |
| | | vo.setCurrent(0); |
| | | vo.setName(questions.getName()); |
| | | List<LotteryEventQuestionsAnswers> list = lotteryEventQuestionsAnswersService.list(new QueryWrapper<LotteryEventQuestionsAnswers>().eq("lottery_event_questions_id", questions.getId())); |
| | | List<TLotteryEventQuestionsAnswers> list = lotteryEventQuestionsAnswersService.list(new QueryWrapper<TLotteryEventQuestionsAnswers>().eq("lottery_event_questions_id", questions.getId())); |
| | | //封装答题 |
| | | List<Map<String, String>> options = list.stream().map(item -> { |
| | | Map<String, String> map = new HashMap<>(); |
| | |
| | | } |
| | | current++; |
| | | } |
| | | List<LotteryEventQuestions> list = lotteryEventServiceQuestionsService.list(new QueryWrapper<LotteryEventQuestions>().eq("lottery_event_id", dto.getId()).orderByAsc("sort")); |
| | | LotteryEventQuestions lotteryEventQuestions = list.get(current); |
| | | List<TLotteryEventQuestions> list = lotteryEventServiceQuestionsService.list(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).orderByAsc("sort")); |
| | | TLotteryEventQuestions lotteryEventQuestions = list.get(current); |
| | | vo.setCurrent(current); |
| | | vo.setName(lotteryEventQuestions.getName()); |
| | | List<LotteryEventQuestionsAnswers> list1 = lotteryEventQuestionsAnswersService.list(new QueryWrapper<LotteryEventQuestionsAnswers>().eq("lottery_event_questions_id", lotteryEventQuestions.getId())); |
| | | List<TLotteryEventQuestionsAnswers> list1 = lotteryEventQuestionsAnswersService.list(new QueryWrapper<TLotteryEventQuestionsAnswers>().eq("lottery_event_questions_id", lotteryEventQuestions.getId())); |
| | | //封装答题 |
| | | List<Map<String, String>> options = list1.stream().map(item -> { |
| | | Map<String, String> map = new HashMap<>(); |
| | |
| | | return map; |
| | | }).collect(Collectors.toList()); |
| | | if (-1 == dto.getStepOrDown()) { |
| | | UserLotteryEventQuestionsAnswers one = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<UserLotteryEventQuestionsAnswers>().eq("lottery_event_id", dto.getId()).eq("user_id", userId).orderByDesc("create_time").last(" limit 0, 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()); |
| | | } |
| | |
| | | @PostMapping("/answerQuestion") |
| | | @ApiOperation(value = "答题操作【2.0】", tags = "抽奖活动") |
| | | public R answerQuestion(@RequestBody AnswerQuestionDto dto) { |
| | | List<LotteryEventQuestions> list = lotteryEventServiceQuestionsService.list(new QueryWrapper<LotteryEventQuestions>().eq("lottery_event_id", dto.getId()).orderByAsc("sort")); |
| | | LotteryEventQuestions lotteryEventQuestions = list.get(dto.getCurrent()); |
| | | List<LotteryEventQuestionsAnswers> list1 = lotteryEventQuestionsAnswersService.list(new QueryWrapper<LotteryEventQuestionsAnswers>().eq("lottery_event_questions_id", lotteryEventQuestions.getId())); |
| | | LotteryEventQuestionsAnswers lotteryEventQuestionsAnswers = list1.stream().filter(item -> item.getAnswers().equals(dto.getAnswer())).findAny().orElse(null); |
| | | List<TLotteryEventQuestions> list = lotteryEventServiceQuestionsService.list(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).orderByAsc("sort")); |
| | | TLotteryEventQuestions lotteryEventQuestions = list.get(dto.getCurrent()); |
| | | List<TLotteryEventQuestionsAnswers> list1 = lotteryEventQuestionsAnswersService.list(new QueryWrapper<TLotteryEventQuestionsAnswers>().eq("lottery_event_questions_id", lotteryEventQuestions.getId())); |
| | | TLotteryEventQuestionsAnswers lotteryEventQuestionsAnswers = list1.stream().filter(item -> item.getAnswers().equals(dto.getAnswer())).findAny().orElse(null); |
| | | //构建答题数据 |
| | | Long userId = SecurityUtils.getUserId(); |
| | | UserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<UserLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).eq("user_id", userId)); |
| | | TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).eq("user_id", userId)); |
| | | if (null == questionsServiceOne) { |
| | | questionsServiceOne = new UserLotteryEventQuestions(); |
| | | questionsServiceOne = new TUserLotteryEventQuestions(); |
| | | questionsServiceOne.setId(IdUtils.simpleUUID()); |
| | | questionsServiceOne.setUserId(userId); |
| | | questionsServiceOne.setLotteryEventId(dto.getId()); |
| | |
| | | userLotteryEventQuestionsService.save(questionsServiceOne); |
| | | } |
| | | //构建或者修改答题数据 |
| | | UserLotteryEventQuestionsAnswers one = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<UserLotteryEventQuestionsAnswers>().eq("lottery_event_question_id", lotteryEventQuestions.getId()).eq("user_id", userId)); |
| | | TUserLotteryEventQuestionsAnswers one = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<TUserLotteryEventQuestionsAnswers>().eq("lottery_event_question_id", lotteryEventQuestions.getId()).eq("user_id", userId)); |
| | | if (null == one) { |
| | | one = new UserLotteryEventQuestionsAnswers(); |
| | | one = new TUserLotteryEventQuestionsAnswers(); |
| | | one.setId(IdUtils.simpleUUID()); |
| | | one.setLotteryEventId(dto.getId()); |
| | | one.setUserId(userId); |
| | |
| | | }) |
| | | public R<Boolean> endAnswerQuestion(@PathVariable("id") String id) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | LotteryEvent lotteryEvent = lotteryEventService.getById(id); |
| | | UserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<UserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | TLotteryEvent lotteryEvent = lotteryEventService.getById(id); |
| | | TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | questionsServiceOne.setStatus(2); |
| | | questionsServiceOne.setEndTime(LocalDateTime.now()); |
| | | //计算正确率 |
| | | List<UserLotteryEventQuestionsAnswers> list = userLotteryEventQuestionsAnswersService.list(new QueryWrapper<UserLotteryEventQuestionsAnswers>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | 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(); |
| | | BigDecimal multiply = new BigDecimal(right).divide(new BigDecimal(count), 4, BigDecimal.ROUND_HALF_UP).setScale(4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)); |