|  |  |  | 
|---|
|  |  |  | package com.ruoyi.study.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.ruoyi.common.core.constant.Constants; | 
|---|
|  |  |  | import com.ruoyi.common.core.domain.R; | 
|---|
|  |  |  | import com.ruoyi.common.core.exception.GlobalException; | 
|---|
|  |  |  | import com.ruoyi.common.core.web.domain.BaseModel; | 
|---|
|  |  |  | import com.ruoyi.common.core.web.page.PageInfo; | 
|---|
|  |  |  | import com.ruoyi.common.redis.service.RedisService; | 
|---|
|  |  |  | import com.ruoyi.common.security.service.TokenService; | 
|---|
|  |  |  | import com.ruoyi.goods.api.feignClient.GoodsClient; | 
|---|
|  |  |  | import com.ruoyi.goods.api.model.TGoodsVO; | 
|---|
|  |  |  | import com.ruoyi.management.api.feignClient.ManagementClient; | 
|---|
|  |  |  | import com.ruoyi.management.api.model.TSysSet; | 
|---|
|  |  |  | import com.ruoyi.study.domain.*; | 
|---|
|  |  |  | import com.ruoyi.study.dto.*; | 
|---|
|  |  |  | import com.ruoyi.study.service.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | import io.swagger.annotations.ApiImplicitParam; | 
|---|
|  |  |  | import io.swagger.annotations.ApiImplicitParams; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import kotlin.random.Random; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.util.StringUtils; | 
|---|
|  |  |  | import org.springframework.validation.annotation.Validated; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.sound.sampled.*; | 
|---|
|  |  |  | import java.io.BufferedInputStream; | 
|---|
|  |  |  | import java.io.File; | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.io.InputStream; | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.math.RoundingMode; | 
|---|
|  |  |  | import java.net.MalformedURLException; | 
|---|
|  |  |  | import java.net.URL; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private ITIntegralRecordService integralRecordService; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private RedisService redisService; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private ITUserService userService; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private TokenService tokenService; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private ITSubjectRecordService subjectRecordService; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private IUserStudyRecordService studyRecordService; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private ManagementClient managementClient; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private ITUserPresentRecordService userPresentRecordService; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private ITSubjectRecordDetailService subjectRecordDetailService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/testAddData") | 
|---|
|  |  |  | @ApiOperation(value = "测试分片", tags = {"测试分片"}) | 
|---|
|  |  |  | public R<Object> testAddData() { | 
|---|
|  |  |  | TSubjectRecordDetail tSubjectRecordDetail = new TSubjectRecordDetail(); | 
|---|
|  |  |  | tSubjectRecordDetail.setUserId(12); | 
|---|
|  |  |  | subjectRecordDetailService.save(tSubjectRecordDetail); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ICategoryService categoryService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/storyList") | 
|---|
|  |  |  | //    @ApiOperation(value = "配置学习类型选择故事", tags = {"题目管理"}) | 
|---|
|  |  |  | 
|---|
|  |  |  | if (StringUtils.hasLength(query.getName())) { | 
|---|
|  |  |  | wrapper.like("name", query.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.hasLength(query.getCategoryName())) { | 
|---|
|  |  |  | // 查询分类id包含的 | 
|---|
|  |  |  | List<Integer> collect = categoryService.lambdaQuery().eq(TCategory::getState, 2) | 
|---|
|  |  |  | .eq(TCategory::getType, 1) | 
|---|
|  |  |  | .like(TCategory::getName, query.getCategoryName()).list() | 
|---|
|  |  |  | .stream().map(TCategory::getId).collect(Collectors.toList());// 查询分类id包含的 | 
|---|
|  |  |  | List<Integer> collect2 = categoryService.lambdaQuery().eq(TCategory::getState, 2) | 
|---|
|  |  |  | .eq(TCategory::getType, 2) | 
|---|
|  |  |  | .like(TCategory::getName, query.getCategoryName()).list() | 
|---|
|  |  |  | .stream().map(TCategory::getParentId).collect(Collectors.toList()); | 
|---|
|  |  |  | collect.addAll(collect2); | 
|---|
|  |  |  | if (collect.isEmpty()) { | 
|---|
|  |  |  | collect.add(-1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wrapper.in("firstCategory", collect); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.hasLength(query.getEnglish())) { | 
|---|
|  |  |  | wrapper.like("english", query.getEnglish()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | wrapper.like("type", query.getType()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wrapper.eq("state", 1); | 
|---|
|  |  |  | List<TStory> tStories = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | switch (query.getStoryType()) { | 
|---|
|  |  |  | case 2: | 
|---|
|  |  |  | List<TStory> list = storyService.list(wrapper); | 
|---|
|  |  |  | for (TStory tSubject : list) { | 
|---|
|  |  |  | TCategory first = categoryService.getById(tSubject.getFirstCategory()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | TCategory second = categoryService.getById(tSubject.getSecondCategory()); | 
|---|
|  |  |  | if (first != null && second != null) { | 
|---|
|  |  |  | tSubject.setCategoryName(first.getName() + "-" + second.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | res.setRecords(list); | 
|---|
|  |  |  | res.setTotal(list.size()); | 
|---|
|  |  |  | return R.ok(res); | 
|---|
|  |  |  | 
|---|
|  |  |  | // 查询出error字段不为空的数据 | 
|---|
|  |  |  | wrapper.isNotNull("error"); | 
|---|
|  |  |  | List<TStory> list1 = storyService.list(wrapper); | 
|---|
|  |  |  | for (TStory tStory : list1) { | 
|---|
|  |  |  | TCategory first = categoryService.getById(tStory.getFirstCategory()); | 
|---|
|  |  |  | TCategory second = categoryService.getById(tStory.getSecondCategory()); | 
|---|
|  |  |  | if (first != null && second != null) { | 
|---|
|  |  |  | tStory.setCategoryName(first.getName() + "-" + second.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | res.setRecords(list1); | 
|---|
|  |  |  | res.setTotal(list1.size()); | 
|---|
|  |  |  | return R.ok(res); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/subjectList") | 
|---|
|  |  |  | //    @ApiOperation(value = "配置学习类型选择题目", tags = {"题目管理"}) | 
|---|
|  |  |  | public R<PageInfo<TSubject>> subjectList(@RequestBody ChoiceSubject query) { | 
|---|
|  |  |  | PageInfo<TSubject> res = new PageInfo<>(query.getPageNumber(), query.getPageSize()); | 
|---|
|  |  |  | QueryWrapper<TSubject> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | public R<IPage<TSubject>> subjectList(@RequestBody ChoiceSubject query) { | 
|---|
|  |  |  | // 创建分页对象,传入当前页和每页显示条数 | 
|---|
|  |  |  | IPage<TSubject> page = new Page<>(query.getPageNumber(), query.getPageSize());        QueryWrapper<TSubject> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | if (StringUtils.hasLength(query.getName())) { | 
|---|
|  |  |  | wrapper.like("name", query.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.hasLength(query.getCategoryName())) { | 
|---|
|  |  |  | // 查询分类id包含的 | 
|---|
|  |  |  | List<Integer> collect = categoryService.lambdaQuery().eq(TCategory::getState, 1) | 
|---|
|  |  |  | .eq(TCategory::getType, 1) | 
|---|
|  |  |  | .like(TCategory::getName, query.getCategoryName()).list() | 
|---|
|  |  |  | .stream().map(TCategory::getId).collect(Collectors.toList());// 查询分类id包含的 | 
|---|
|  |  |  | List<Integer> collect2 = categoryService.lambdaQuery().eq(TCategory::getState, 1) | 
|---|
|  |  |  | .eq(TCategory::getType, 2) | 
|---|
|  |  |  | .like(TCategory::getName, query.getCategoryName()).list() | 
|---|
|  |  |  | .stream().map(TCategory::getId).collect(Collectors.toList()); | 
|---|
|  |  |  | collect.addAll(collect2); | 
|---|
|  |  |  | if (collect2.isEmpty()) { | 
|---|
|  |  |  | if (collect.isEmpty()) { | 
|---|
|  |  |  | collect.add(-1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wrapper.in("firstCategory", collect); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | wrapper.in("secondCategory", collect2); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.hasLength(query.getEnglish())) { | 
|---|
|  |  |  | wrapper.like("english", query.getEnglish()); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (StringUtils.hasLength(query.getType())) { | 
|---|
|  |  |  | wrapper.like("type", query.getType()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TCategory> list5 = categoryService.list(); | 
|---|
|  |  |  | wrapper.eq("state", 1); | 
|---|
|  |  |  | // 执行分页查询 | 
|---|
|  |  |  | IPage<TSubject> res = subjectService.page(page, wrapper); | 
|---|
|  |  |  | List<TSubject> list = res.getRecords(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | switch (query.getStudyType()) { | 
|---|
|  |  |  | case 1: | 
|---|
|  |  |  | List<TSubject> list = subjectService.list(wrapper); | 
|---|
|  |  |  | for (TSubject tSubject : list) { | 
|---|
|  |  |  | TCategory first = list5.stream().filter(e->e.getId().equals(tSubject.getFirstCategory())).findFirst().orElse(null); | 
|---|
|  |  |  | TCategory second = list5.stream().filter(e->e.getId().equals(tSubject.getSecondCategory())).findFirst().orElse(null); | 
|---|
|  |  |  | if (first != null && second != null) { | 
|---|
|  |  |  | tSubject.setCategoryName(first.getName() + "-" + second.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | res.setRecords(list); | 
|---|
|  |  |  | res.setTotal(list.size()); | 
|---|
|  |  |  | return R.ok(res); | 
|---|
|  |  |  | case 2: | 
|---|
|  |  |  | // 查询出error字段不为空的数据 | 
|---|
|  |  |  | wrapper.isNotNull("error"); | 
|---|
|  |  |  | List<TSubject> list1 = subjectService.list(wrapper); | 
|---|
|  |  |  | res.setRecords(list1); | 
|---|
|  |  |  | res.setTotal(list1.size()); | 
|---|
|  |  |  | List<TSubject> tSubjects = new ArrayList<>(); | 
|---|
|  |  |  | for (TSubject tSubject : list1) { | 
|---|
|  |  |  | TCategory first = list5.stream().filter(e->e.getId().equals(tSubject.getFirstCategory())).findFirst().orElse(null); | 
|---|
|  |  |  | TCategory second = list5.stream().filter(e->e.getId().equals(tSubject.getSecondCategory())).findFirst().orElse(null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (first != null && second != null) { | 
|---|
|  |  |  | tSubject.setCategoryName(first.getName() + "-" + second.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!tSubject.getError().isEmpty()) { | 
|---|
|  |  |  | tSubjects.add(tSubject); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | res.setRecords(tSubjects); | 
|---|
|  |  |  | return R.ok(res); | 
|---|
|  |  |  | case 3: | 
|---|
|  |  |  | List<TSubject> list2 = subjectService.list(wrapper); | 
|---|
|  |  |  | for (TSubject tSubject : list2) { | 
|---|
|  |  |  | TCategory first = list5.stream().filter(e->e.getId().equals(tSubject.getFirstCategory())).findFirst().orElse(null); | 
|---|
|  |  |  | TCategory second = list5.stream().filter(e->e.getId().equals(tSubject.getSecondCategory())).findFirst().orElse(null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (first != null && second != null) { | 
|---|
|  |  |  | tSubject.setCategoryName(first.getName() + "-" + second.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | res.setRecords(list2); | 
|---|
|  |  |  | res.setTotal(list2.size()); | 
|---|
|  |  |  | return R.ok(res); | 
|---|
|  |  |  | case 4: | 
|---|
|  |  |  | // 查询出error字段不为空的数据 | 
|---|
|  |  |  | wrapper.isNotNull("error"); | 
|---|
|  |  |  | List<TSubject> list3 = subjectService.list(wrapper); | 
|---|
|  |  |  | res.setRecords(list3); | 
|---|
|  |  |  | res.setTotal(list3.size()); | 
|---|
|  |  |  | List<TSubject> tSubjects3 = new ArrayList<>(); | 
|---|
|  |  |  | for (TSubject tSubject : list3) { | 
|---|
|  |  |  | TCategory first = list5.stream().filter(e->e.getId().equals(tSubject.getFirstCategory())).findFirst().orElse(null); | 
|---|
|  |  |  | TCategory second = list5.stream().filter(e->e.getId().equals(tSubject.getSecondCategory())).findFirst().orElse(null); | 
|---|
|  |  |  | if (first != null && second != null) { | 
|---|
|  |  |  | tSubject.setCategoryName(first.getName() + "-" + second.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!tSubject.getError().isEmpty()) { | 
|---|
|  |  |  | tSubjects3.add(tSubject); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | res.setRecords(tSubjects3); | 
|---|
|  |  |  | return R.ok(res); | 
|---|
|  |  |  | case 5: | 
|---|
|  |  |  | List<TSubject> list4 = subjectService.list(wrapper); | 
|---|
|  |  |  | for (TSubject tSubject : list4) { | 
|---|
|  |  |  | TCategory first = list5.stream().filter(e->e.getId().equals(tSubject.getFirstCategory())).findFirst().orElse(null); | 
|---|
|  |  |  | TCategory second = list5.stream().filter(e->e.getId().equals(tSubject.getSecondCategory())).findFirst().orElse(null); | 
|---|
|  |  |  | if (first != null && second != null) { | 
|---|
|  |  |  | tSubject.setCategoryName(first.getName() + "-" + second.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | res.setRecords(list4); | 
|---|
|  |  |  | res.setTotal(list4.size()); | 
|---|
|  |  |  | return R.ok(res); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TSubject> objects = new ArrayList<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | .eq("week", week) | 
|---|
|  |  |  | .eq("type", type)); | 
|---|
|  |  |  | one.setQuarter(dto.getQuarter()); | 
|---|
|  |  |  | one.setQuarterRate(dto.getQuarterRate()); | 
|---|
|  |  |  | one.setTitle(dto.getTitle()); | 
|---|
|  |  |  | studyService.updateById(one); | 
|---|
|  |  |  | GameDTO game = dto.getGame(); | 
|---|
|  |  |  | StoryListenDTO storyListen = dto.getStoryListen(); | 
|---|
|  |  |  | System.err.println("学习配置"+dto); | 
|---|
|  |  |  | if (day == 6) { | 
|---|
|  |  |  | // 先判断有没有配置 | 
|---|
|  |  |  | TGame studyId = gameService.getOne(new QueryWrapper<TGame>() | 
|---|
|  |  |  | .eq("studyId", one.getId()) | 
|---|
|  |  |  | .eq("week", week)); | 
|---|
|  |  |  | if (studyId != null) { | 
|---|
|  |  |  | // 判断当前周目配置的题目数量 | 
|---|
|  |  |  | List<String> subjectId = getSubjectId(week); | 
|---|
|  |  |  | List<String> newSubjectId = subjectId.stream().map(data -> { | 
|---|
|  |  |  | if (data.startsWith(Constants.REDUCE)) { | 
|---|
|  |  |  | data = data.replace(Constants.REDUCE, Constants.EMPTY_STR); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return data; | 
|---|
|  |  |  | }).distinct().collect(Collectors.toList()); | 
|---|
|  |  |  | // 判断周目下题目是否足够 | 
|---|
|  |  |  | if (newSubjectId.size() < game.getCount()) { | 
|---|
|  |  |  | return R.fail("超级听力:当前周目下day1 - day5题目不足!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (newSubjectId.size() < game.getAnswerCount()) { | 
|---|
|  |  |  | return R.fail("超级记忆:当前周目下day1 - day5题目不足!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | studyId.setWeek(dto.getWeek()); | 
|---|
|  |  |  | studyId.setStudyId(one.getId()); | 
|---|
|  |  |  | studyId.setCount(game.getCount()); | 
|---|
|  |  |  | 
|---|
|  |  |  | studyId.setAnswerTime(game.getAnswerTime()); | 
|---|
|  |  |  | studyId.setAnswerIntegral(game.getAnswerIntegral()); | 
|---|
|  |  |  | studyId.setAnswerCount(game.getAnswerCount()); | 
|---|
|  |  |  | studyId.setRate(game.getRate()); | 
|---|
|  |  |  | studyId.setAnswerRate(game.getAnswerRate()); | 
|---|
|  |  |  | studyId.setSubjectIds(game.getSubjectIds()); | 
|---|
|  |  |  | studyId.setSubjectIdsOne(game.getSubjectIdsOne()); | 
|---|
|  |  |  | gameService.updateById(studyId); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 判断当前周目配置的题目数量 | 
|---|
|  |  |  | List<String> subjectId = getSubjectId(week); | 
|---|
|  |  |  | List<String> newSubjectId = subjectId.stream().map(data -> { | 
|---|
|  |  |  | if (data.startsWith(Constants.REDUCE)) { | 
|---|
|  |  |  | data = data.replace(Constants.REDUCE, Constants.EMPTY_STR); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return data; | 
|---|
|  |  |  | }).distinct().collect(Collectors.toList()); | 
|---|
|  |  |  | // 判断周目下题目是否足够 | 
|---|
|  |  |  | if (newSubjectId.size() < game.getCount()) { | 
|---|
|  |  |  | return R.fail("超级听力:当前周目下day1 - day5题目不足!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (newSubjectId.size() < game.getAnswerCount()) { | 
|---|
|  |  |  | return R.fail("超级记忆:当前周目下day1 - day5题目不足!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | TGame tGame = new TGame(); | 
|---|
|  |  |  | tGame.setWeek(dto.getWeek()); | 
|---|
|  |  |  | tGame.setAnswerRate(game.getAnswerRate()); | 
|---|
|  |  |  | tGame.setRate(game.getRate()); | 
|---|
|  |  |  | tGame.setStudyId(one.getId()); | 
|---|
|  |  |  | tGame.setCount(game.getCount()); | 
|---|
|  |  |  | tGame.setIntegral(game.getIntegral()); | 
|---|
|  |  |  | 
|---|
|  |  |  | tGame.setAnswerTime(game.getAnswerTime()); | 
|---|
|  |  |  | tGame.setAnswerIntegral(game.getAnswerIntegral()); | 
|---|
|  |  |  | tGame.setAnswerCount(game.getAnswerCount()); | 
|---|
|  |  |  | tGame.setSubjectIds(game.getSubjectIds()); | 
|---|
|  |  |  | tGame.setSubjectIdsOne(game.getSubjectIdsOne()); | 
|---|
|  |  |  | gameService.save(tGame); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | storyListenService.save(tStoryListen); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | List<Integer> ids = studyListenService.lambdaQuery().eq(TStudyListen::getId, one.getId()) | 
|---|
|  |  |  | .eq(TStudyListen::getWeek, week) | 
|---|
|  |  |  | .eq(TStudyListen::getDay, day).list().stream().map(TStudyListen::getId).collect(Collectors.toList()); | 
|---|
|  |  |  | for (Integer id : ids) { | 
|---|
|  |  |  | subjectRecordDetailService.remove(new LambdaQueryWrapper<TSubjectRecordDetail>() | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getObjectId, id) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getWeek, week) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getType, 1)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 删除原有数据 | 
|---|
|  |  |  | studyListenService.remove(new QueryWrapper<TStudyListen>() | 
|---|
|  |  |  | .eq("studyId", one.getId()) | 
|---|
|  |  |  | 
|---|
|  |  |  | tStudyListen.setIntegral(studyListenDTO.getIntegral()); | 
|---|
|  |  |  | tStudyListen.setWeek(week); | 
|---|
|  |  |  | tStudyListen.setIsVip(studyListenDTO.getIsVip()); | 
|---|
|  |  |  | tStudyListen.setRate(dto.getListenRate()); | 
|---|
|  |  |  | tStudyListen.setStudySort(studyListenDTO.getStudySort()); | 
|---|
|  |  |  | studyListenService.save(tStudyListen); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Integer> ids1 = studyLookService.lambdaQuery().eq(TStudyLook::getId, one.getId()) | 
|---|
|  |  |  | .eq(TStudyLook::getWeek, week) | 
|---|
|  |  |  | .eq(TStudyLook::getDay, day).list().stream().map(TStudyLook::getId).collect(Collectors.toList()); | 
|---|
|  |  |  | for (Integer id : ids1) { | 
|---|
|  |  |  | subjectRecordDetailService.remove(new LambdaQueryWrapper<TSubjectRecordDetail>() | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getObjectId, id) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getWeek, week) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getType, 2)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | studyLookService.remove(new QueryWrapper<TStudyLook>() | 
|---|
|  |  |  | .eq("studyId", one.getId()) | 
|---|
|  |  |  | 
|---|
|  |  |  | tStudyLook.setIntegral(studyLookDTO.getIntegral()); | 
|---|
|  |  |  | tStudyLook.setWeek(week); | 
|---|
|  |  |  | tStudyLook.setIsVip(studyLookDTO.getIsVip()); | 
|---|
|  |  |  | tStudyLook.setRate(dto.getLookRate()); | 
|---|
|  |  |  | tStudyLook.setStudySort(studyLookDTO.getStudySort()); | 
|---|
|  |  |  | studyLookService.save(tStudyLook); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Integer> ids2 = studyInductionService.lambdaQuery().eq(TStudyInduction::getId, one.getId()) | 
|---|
|  |  |  | .eq(TStudyInduction::getWeek, week) | 
|---|
|  |  |  | .eq(TStudyInduction::getDay, day).list().stream().map(TStudyInduction::getId).collect(Collectors.toList()); | 
|---|
|  |  |  | for (Integer id : ids2) { | 
|---|
|  |  |  | subjectRecordDetailService.remove(new LambdaQueryWrapper<TSubjectRecordDetail>() | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getObjectId, id) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getWeek, week) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getType, 3)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | studyInductionService.remove(new QueryWrapper<TStudyInduction>() | 
|---|
|  |  |  | .eq("studyId", one.getId()) | 
|---|
|  |  |  | 
|---|
|  |  |  | tStudyInduction.setSubject(studyInductionDTO.getSubject()); | 
|---|
|  |  |  | tStudyInduction.setIntegral(studyInductionDTO.getIntegral()); | 
|---|
|  |  |  | tStudyInduction.setWeek(week); | 
|---|
|  |  |  | tStudyInduction.setRate(dto.getInductionRate()); | 
|---|
|  |  |  | tStudyInduction.setIsVip(studyInductionDTO.getIsVip()); | 
|---|
|  |  |  | tStudyInduction.setStudySort(studyInductionDTO.getStudySort()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | studyInductionService.save(tStudyInduction); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Integer> ids3 = studyAnswerService.lambdaQuery().eq(TStudyAnswer::getId, one.getId()) | 
|---|
|  |  |  | .eq(TStudyAnswer::getWeek, week) | 
|---|
|  |  |  | .eq(TStudyAnswer::getDay, day).list().stream().map(TStudyAnswer::getId).collect(Collectors.toList()); | 
|---|
|  |  |  | for (Integer id : ids3) { | 
|---|
|  |  |  | subjectRecordDetailService.remove(new LambdaQueryWrapper<TSubjectRecordDetail>() | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getObjectId, id) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getWeek, week) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getType, 4)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | studyAnswerService.remove(new QueryWrapper<TStudyAnswer>() | 
|---|
|  |  |  | .eq("studyId", one.getId()) | 
|---|
|  |  |  | 
|---|
|  |  |  | tStudyAnswer.setAnswerSubject(studyAnswerDTO.getAnswerSubject()); | 
|---|
|  |  |  | tStudyAnswer.setIntegral(studyAnswerDTO.getIntegral()); | 
|---|
|  |  |  | tStudyAnswer.setWeek(week); | 
|---|
|  |  |  | tStudyAnswer.setRate(dto.getAnswerRate()); | 
|---|
|  |  |  | tStudyAnswer.setIsVip(studyAnswerDTO.getIsVip()); | 
|---|
|  |  |  | tStudyAnswer.setStudySort(studyAnswerDTO.getStudySort()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | studyAnswerService.save(tStudyAnswer); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Integer> ids4 = studyPairService.lambdaQuery().eq(TStudyPair::getId, one.getId()) | 
|---|
|  |  |  | .eq(TStudyPair::getWeek, week) | 
|---|
|  |  |  | .eq(TStudyPair::getDay, day).list().stream().map(TStudyPair::getId).collect(Collectors.toList()); | 
|---|
|  |  |  | for (Integer id : ids4) { | 
|---|
|  |  |  | subjectRecordDetailService.remove(new LambdaQueryWrapper<TSubjectRecordDetail>() | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getObjectId, id) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getWeek, week) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getType, 5)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | studyPairService.remove(new QueryWrapper<TStudyPair>() | 
|---|
|  |  |  | .eq("studyId", one.getId()) | 
|---|
|  |  |  | 
|---|
|  |  |  | tStudyPair.setSubject(studyPairDTO.getSubject()); | 
|---|
|  |  |  | tStudyPair.setIntegral(studyPairDTO.getIntegral()); | 
|---|
|  |  |  | tStudyPair.setWeek(week); | 
|---|
|  |  |  | tStudyPair.setRate(dto.getPairRate()); | 
|---|
|  |  |  | tStudyPair.setIsVip(studyPairDTO.getIsVip()); | 
|---|
|  |  |  | tStudyPair.setStudySort(studyPairDTO.getStudySort()); | 
|---|
|  |  |  | studyPairService.save(tStudyPair); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void main(String[] args) throws Exception { | 
|---|
|  |  |  | double temp = 1.687; | 
|---|
|  |  |  | System.err.println((int) temp); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | .eq("week", dto.getWeek()) | 
|---|
|  |  |  | .eq("type", dto.getType())); | 
|---|
|  |  |  | if (one != null) { | 
|---|
|  |  |  | one.setType(dto.getType()); | 
|---|
|  |  |  | one.setWeek(dto.getWeek()); | 
|---|
|  |  |  | one.setTitle(dto.getTitle()); | 
|---|
|  |  |  | one.setQuarter(dto.getQuarter()); | 
|---|
|  |  |  | studyService.saveOrUpdate(one); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | TStudy tStudy = new TStudy(); | 
|---|
|  |  |  | 
|---|
|  |  |  | tStudy.setQuarter(dto.getQuarter()); | 
|---|
|  |  |  | studyService.saveOrUpdate(tStudy); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 每次添加周目后需要根据季度来重新排序周目 | 
|---|
|  |  |  | if (dto.getType() == 1) { | 
|---|
|  |  |  | List<TStudy> list1 = studyService.lambdaQuery() | 
|---|
|  |  |  | .eq(TStudy::getType, 1) | 
|---|
|  |  |  | .orderByAsc(TStudy::getQuarter) | 
|---|
|  |  |  | .orderByAsc(TStudy::getWeek) | 
|---|
|  |  |  | .list(); | 
|---|
|  |  |  | int i = 1; | 
|---|
|  |  |  | List<TGame> games = gameService.list(new QueryWrapper<TGame>()); | 
|---|
|  |  |  | List<TStoryListen> storyListens = storyListenService.list(new QueryWrapper<TStoryListen>()); | 
|---|
|  |  |  | List<TStudyListen> studyListens = studyListenService.list(); | 
|---|
|  |  |  | List<TStudyLook> studyLooks = studyLookService.list(); | 
|---|
|  |  |  | List<TStudyInduction> studyInductions = studyInductionService.list(); | 
|---|
|  |  |  | List<TStudyAnswer> studyAnswers = studyAnswerService.list(); | 
|---|
|  |  |  | List<TStudyPair> studyPairs = studyPairService.list(); | 
|---|
|  |  |  | for (TStudy tStudy : list1) { | 
|---|
|  |  |  | System.err.println("进入修改"); | 
|---|
|  |  |  | tStudy.setWeek(i); | 
|---|
|  |  |  | // 将对应的题目配置修改week | 
|---|
|  |  |  | List<TGame> games1 = games.stream().filter(e -> e.getWeek().equals(tStudy.getWeek())).collect(Collectors.toList()); | 
|---|
|  |  |  | for (TGame tGame : games1) { | 
|---|
|  |  |  | tGame.setWeek(i); | 
|---|
|  |  |  | tGame.setStudyId(tStudy.getId()); | 
|---|
|  |  |  | gameService.updateById(tGame); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 听故事 | 
|---|
|  |  |  | List<TStoryListen> storyListens1 = storyListens.stream().filter(e -> e.getWeek().equals(tStudy.getWeek())).collect(Collectors.toList()); | 
|---|
|  |  |  | for (TStoryListen tStoryListen : storyListens1) { | 
|---|
|  |  |  | tStoryListen.setWeek(i); | 
|---|
|  |  |  | tStoryListen.setStudyId(tStudy.getId()); | 
|---|
|  |  |  | storyListenService.updateById(tStoryListen); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 听音选图 | 
|---|
|  |  |  | List<TStudyListen> studyListens1 = studyListens.stream().filter(e -> e.getWeek().equals(tStudy.getWeek())).collect(Collectors.toList()); | 
|---|
|  |  |  | for (TStudyListen tStudyListen : studyListens1) { | 
|---|
|  |  |  | tStudyListen.setWeek(i); | 
|---|
|  |  |  | tStudyListen.setStudyId(tStudy.getId()); | 
|---|
|  |  |  | studyListenService.updateById(tStudyListen); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 看图选音 | 
|---|
|  |  |  | List<TStudyLook> studyLooks1 = studyLooks.stream().filter(e -> e.getWeek().equals(tStudy.getWeek())).collect(Collectors.toList()); | 
|---|
|  |  |  | for (TStudyLook tStudyLook : studyLooks1) { | 
|---|
|  |  |  | tStudyLook.setWeek(i); | 
|---|
|  |  |  | tStudyLook.setStudyId(tStudy.getId()); | 
|---|
|  |  |  | studyLookService.updateById(tStudyLook); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 归纳判断 | 
|---|
|  |  |  | List<TStudyInduction> studyInductions1 = studyInductions.stream().filter(e -> e.getWeek().equals(tStudy.getWeek())).collect(Collectors.toList()); | 
|---|
|  |  |  | for (TStudyInduction tStudyInduction : studyInductions1) { | 
|---|
|  |  |  | tStudyInduction.setWeek(i); | 
|---|
|  |  |  | tStudyInduction.setStudyId(tStudy.getId()); | 
|---|
|  |  |  | System.err.println("归纳判断" + tStudy.getId()); | 
|---|
|  |  |  | studyInductionService.updateById(tStudyInduction); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TStudyAnswer> studyAnswers1 = studyAnswers.stream().filter(e -> e.getWeek().equals(tStudy.getWeek())).collect(Collectors.toList()); | 
|---|
|  |  |  | for (TStudyAnswer tStudyAnswer : studyAnswers1) { | 
|---|
|  |  |  | tStudyAnswer.setStudyId(tStudy.getId()); | 
|---|
|  |  |  | tStudyAnswer.setWeek(i); | 
|---|
|  |  |  | studyAnswerService.updateById(tStudyAnswer); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TStudyPair> studyPairs1 = studyPairs.stream().filter(e -> e.getWeek().equals(tStudy.getWeek())).collect(Collectors.toList()); | 
|---|
|  |  |  | for (TStudyPair tStudyPair : studyPairs1) { | 
|---|
|  |  |  | tStudyPair.setWeek(i); | 
|---|
|  |  |  | tStudyPair.setStudyId(tStudy.getId()); | 
|---|
|  |  |  | studyPairService.updateById(tStudyPair); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | i++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | studyService.updateBatchById(list1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | res.setWeeks(type); | 
|---|
|  |  |  | List<TStudy> list8 = studyService.list(new QueryWrapper<TStudy>() | 
|---|
|  |  |  | .eq("type", dto.getType()) | 
|---|
|  |  |  | .eq("week", dto.getWeek())); | 
|---|
|  |  |  | .eq("week", dto.getWeek()) | 
|---|
|  |  |  | .orderByAsc("quarter")); | 
|---|
|  |  |  | if (!list8.isEmpty()) { | 
|---|
|  |  |  | res.setQuarter(list8.get(0).getQuarter()); | 
|---|
|  |  |  | res.setTitle(list8.get(0).getTitle()); | 
|---|
|  |  |  | res.setQuarterRate(list8.get(0).getQuarterRate()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<StudyListenVO> listenVOS = new ArrayList<>(); | 
|---|
|  |  |  | List<GameVO> gameVOS = new ArrayList<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | // 听音选图 | 
|---|
|  |  |  | List<TStudyListen> list = studyListenService.list(new QueryWrapper<TStudyListen>() | 
|---|
|  |  |  | .eq("week", week) | 
|---|
|  |  |  | .eq("day", day)); | 
|---|
|  |  |  | .eq("day", day).orderByAsc("studySort")); | 
|---|
|  |  |  | List<TSubject> list9 = subjectService.list(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (TStudyListen tStudyListen : list) { | 
|---|
|  |  |  | StringBuilder temp = new StringBuilder(); | 
|---|
|  |  |  | StudyListenVO studyListenVO = new StudyListenVO(); | 
|---|
|  |  |  | if (StringUtils.hasLength(tStudyListen.getSubject())) { | 
|---|
|  |  |  | for (String s : tStudyListen.getSubject().split(",")) { | 
|---|
|  |  |  | TSubject byId = subjectService.getById(s); | 
|---|
|  |  |  | temp.append(byId.getName()).append(","); | 
|---|
|  |  |  | TSubject byId = list9.stream().filter(e -> e.getId().equals(Integer.valueOf(s))).findFirst().orElse(null); | 
|---|
|  |  |  | if (byId != null) { | 
|---|
|  |  |  | temp.append(byId.getName()).append(","); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String string = temp.toString(); | 
|---|
|  |  |  | studyListenVO.setName(string.substring(0, string.length() - 1)); | 
|---|
|  |  |  | studyListenVO.setIntegral(tStudyListen.getIntegral()); | 
|---|
|  |  |  | studyListenVO.setSubject(tStudyListen.getSubject()); | 
|---|
|  |  |  | studyListenVO.setIsVip(tStudyListen.getIsVip()); | 
|---|
|  |  |  | studyListenVO.setId(tStudyListen.getId()); | 
|---|
|  |  |  | studyListenVO.setType(tStudyListen.getType()); | 
|---|
|  |  |  | listenVOS.add(studyListenVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | res.setListenRate(tStudyListen.getRate()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 看音选图 | 
|---|
|  |  |  | List<TStudyLook> list1 = studyLookService.list(new QueryWrapper<TStudyLook>() | 
|---|
|  |  |  | .eq("week", week) | 
|---|
|  |  |  | .eq("day", day) | 
|---|
|  |  |  | .eq("day", day).orderByAsc("studySort") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | for (TStudyLook tStudyLook : list1) { | 
|---|
|  |  |  | int index = 0; | 
|---|
|  |  |  | 
|---|
|  |  |  | StudyLookVO studyLookVO1 = new StudyLookVO(); | 
|---|
|  |  |  | if (StringUtils.hasLength(tStudyLook.getSubject())) { | 
|---|
|  |  |  | for (String s : tStudyLook.getSubject().split(",")) { | 
|---|
|  |  |  | TSubject byId = subjectService.getById(s); | 
|---|
|  |  |  | names.append(byId.getName()).append(","); | 
|---|
|  |  |  | TSubject byId = list9.stream().filter(e -> e.getId().equals(Integer.valueOf(s))).findFirst().orElse(null); | 
|---|
|  |  |  | if (byId != null) { | 
|---|
|  |  |  | names.append(byId.getName()).append(","); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String[] split = tStudyLook.getSort().split(","); | 
|---|
|  |  |  | String s1 = split[index]; | 
|---|
|  |  |  | sorts.append(s1).append(","); | 
|---|
|  |  |  | 
|---|
|  |  |  | studyLookVO1.setIntegral(tStudyLook.getIntegral()); | 
|---|
|  |  |  | studyLookVO1.setSubject(tStudyLook.getSubject()); | 
|---|
|  |  |  | studyLookVO1.setIsVip(tStudyLook.getIsVip()); | 
|---|
|  |  |  | studyLookVO1.setId(tStudyLook.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | lookVOS.add(studyLookVO1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | res.setLookRate(tStudyLook.getRate()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 归纳排除 | 
|---|
|  |  |  | List<TStudyInduction> list2 = studyInductionService.list(new QueryWrapper<TStudyInduction>() | 
|---|
|  |  |  | .eq("week", week) | 
|---|
|  |  |  | .eq("day", day) | 
|---|
|  |  |  | .eq("day", day).orderByAsc("studySort") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | for (TStudyInduction tStudyInduction : list2) { | 
|---|
|  |  |  | StringBuilder names = new StringBuilder(); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (StringUtils.hasLength(tStudyInduction.getSubject())) { | 
|---|
|  |  |  | for (String s : tStudyInduction.getSubject().split(",")) { | 
|---|
|  |  |  | String replace = s.replace("-", ""); | 
|---|
|  |  |  | TSubject byId = subjectService.getById(replace); | 
|---|
|  |  |  | names.append(byId.getName()).append(","); | 
|---|
|  |  |  | TSubject byId = list9.stream().filter(e -> e.getId().equals(Integer.valueOf(replace))).findFirst().orElse(null); | 
|---|
|  |  |  | if (byId != null) { | 
|---|
|  |  |  | names.append(byId.getName()).append(","); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String string = names.toString(); | 
|---|
|  |  |  | studyInductionVO.setName(string.substring(0, string.length() - 1)); | 
|---|
|  |  |  | studyInductionVO.setIntegral(tStudyInduction.getIntegral()); | 
|---|
|  |  |  | studyInductionVO.setSubject(tStudyInduction.getSubject()); | 
|---|
|  |  |  | studyInductionVO.setIsVip(tStudyInduction.getIsVip()); | 
|---|
|  |  |  | studyInductionVO.setId(tStudyInduction.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | inductionVOS.add(studyInductionVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | res.setInductionRate(tStudyInduction.getRate()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 有问有答 | 
|---|
|  |  |  | List<TStudyAnswer> list3 = studyAnswerService.list(new QueryWrapper<TStudyAnswer>() | 
|---|
|  |  |  | .eq("week", week) | 
|---|
|  |  |  | .eq("day", day)); | 
|---|
|  |  |  | .eq("day", day).orderByAsc("studySort")); | 
|---|
|  |  |  | for (TStudyAnswer tStudyAnswer : list3) { | 
|---|
|  |  |  | StringBuilder names = new StringBuilder(); | 
|---|
|  |  |  | StudyAnswerVO studyAnswerVO = new StudyAnswerVO(); | 
|---|
|  |  |  | if (tStudyAnswer.getIsAnswer() != null) { | 
|---|
|  |  |  | if (tStudyAnswer.getIsAnswer() == 1) { | 
|---|
|  |  |  | if (tStudyAnswer.getSubject() != null) { | 
|---|
|  |  |  | TSubject byId = subjectService.getById(tStudyAnswer.getSubject()); | 
|---|
|  |  |  | names.append(byId.getName()).append(","); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | TSubject byId = list9.stream().filter(e -> e.getId().equals(tStudyAnswer.getSubject())).findFirst().orElse(null); | 
|---|
|  |  |  | if (byId != null) { | 
|---|
|  |  |  | names.append(byId.getName()).append(","); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (tStudyAnswer.getAnswerSubject() != null) { | 
|---|
|  |  |  | TSubject byId1 = subjectService.getById(tStudyAnswer.getAnswerSubject()); | 
|---|
|  |  |  | names.append(byId1.getName()).append(","); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | TSubject byId1 = list9.stream().filter(e -> e.getId().equals(tStudyAnswer.getAnswerSubject())).findFirst().orElse(null); | 
|---|
|  |  |  | if (byId1 != null) { | 
|---|
|  |  |  | names.append(byId1.getName()).append(","); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (tStudyAnswer.getSubject() != null) { | 
|---|
|  |  |  | TSubject byId = subjectService.getById(tStudyAnswer.getSubject()); | 
|---|
|  |  |  | names.append(byId.getName()).append(","); | 
|---|
|  |  |  | TSubject byId = list9.stream().filter(e -> e.getId().equals(tStudyAnswer.getSubject())).findFirst().orElse(null); | 
|---|
|  |  |  | if (byId != null) { | 
|---|
|  |  |  | names.append(byId.getName()).append(","); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (tStudyAnswer.getAnswerSubject() != null) { | 
|---|
|  |  |  | TSubject byId1 = subjectService.getById(tStudyAnswer.getAnswerSubject()); | 
|---|
|  |  |  | names.append(byId1.getName()).append(","); | 
|---|
|  |  |  | TSubject byId1 = list9.stream().filter(e -> e.getId().equals(tStudyAnswer.getAnswerSubject())).findFirst().orElse(null); | 
|---|
|  |  |  | if (byId1 != null) { | 
|---|
|  |  |  | names.append(byId1.getName()).append(","); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | studyAnswerVO.setIsVip(tStudyAnswer.getIsVip()); | 
|---|
|  |  |  | studyAnswerVO.setIsAnswer(tStudyAnswer.getIsAnswer()); | 
|---|
|  |  |  | studyAnswerVO.setSubject(tStudyAnswer.getSubject() + "," + tStudyAnswer.getAnswerSubject()); | 
|---|
|  |  |  | studyAnswerVO.setId(tStudyAnswer.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | answerVOS.add(studyAnswerVO); | 
|---|
|  |  |  | res.setAnswerRate(tStudyAnswer.getRate()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 音图相配 | 
|---|
|  |  |  | List<TStudyPair> list4 = studyPairService.list(new QueryWrapper<TStudyPair>() | 
|---|
|  |  |  | .eq("week", week) | 
|---|
|  |  |  | .eq("day", day) | 
|---|
|  |  |  | .eq("day", day).orderByAsc("studySort") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | for (TStudyPair tStudyPair : list4) { | 
|---|
|  |  |  | StringBuilder names = new StringBuilder(); | 
|---|
|  |  |  | StudyPairVO studyPairVO = new StudyPairVO(); | 
|---|
|  |  |  | if (StringUtils.hasLength(tStudyPair.getSubject())) { | 
|---|
|  |  |  | for (String s : tStudyPair.getSubject().split(",")) { | 
|---|
|  |  |  | TSubject byId = subjectService.getById(s); | 
|---|
|  |  |  | names.append(byId.getName()).append(","); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | TSubject byId = list9.stream().filter(e -> e.getId().equals(Integer.valueOf(s))).findFirst().orElse(null); | 
|---|
|  |  |  | if (byId != null) { | 
|---|
|  |  |  | names.append(byId.getName()).append(","); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String string = names.toString(); | 
|---|
|  |  |  | studyPairVO.setName(string.substring(0, string.length() - 1)); | 
|---|
|  |  |  | studyPairVO.setIntegral(tStudyPair.getIntegral()); | 
|---|
|  |  |  | studyPairVO.setSubject(tStudyPair.getSubject()); | 
|---|
|  |  |  | studyPairVO.setIsVip(tStudyPair.getIsVip()); | 
|---|
|  |  |  | studyPairVO.setId(tStudyPair.getId()); | 
|---|
|  |  |  | pairVOS.add(studyPairVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | res.setPairRate(tStudyPair.getRate()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TGame> list5 = gameService.list(new QueryWrapper<TGame>() | 
|---|
|  |  |  | 
|---|
|  |  |  | gameVO.setAnswerTime(tGame.getAnswerTime()); | 
|---|
|  |  |  | gameVO.setAnswerIntegral(tGame.getAnswerIntegral()); | 
|---|
|  |  |  | gameVO.setAnswerCount(tGame.getAnswerCount()); | 
|---|
|  |  |  | gameVO.setRate(tGame.getRate()); | 
|---|
|  |  |  | gameVO.setAnswerRate(tGame.getAnswerRate()); | 
|---|
|  |  |  | String subjectIds = tGame.getSubjectIds(); | 
|---|
|  |  |  | if(subjectIds!=null && subjectIds.length()>0){ | 
|---|
|  |  |  | gameVO.setSubjects(subjectService.list(new QueryWrapper<TSubject>() | 
|---|
|  |  |  | .in("id", subjectIds.split(",")))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String subjectIdsOne = tGame.getSubjectIdsOne(); | 
|---|
|  |  |  | if(subjectIdsOne!=null && subjectIdsOne.length()>0){ | 
|---|
|  |  |  | gameVO.setSubjectsOne(subjectService.list(new QueryWrapper<TSubject>() | 
|---|
|  |  |  | .in("id", subjectIdsOne.split(",")))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | gameVOS.add(gameVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TStoryListen> list6 = storyListenService.list(new QueryWrapper<TStoryListen>() | 
|---|
|  |  |  | .eq("week", week)); | 
|---|
|  |  |  | List<TStory> list10 = storyService.list(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (TStoryListen tStory : list6) { | 
|---|
|  |  |  | StoryVO storyVO = new StoryVO(); | 
|---|
|  |  |  | storyVO.setStory(tStory.getStory()); | 
|---|
|  |  |  | 
|---|
|  |  |  | StringBuilder sort1 = new StringBuilder(); | 
|---|
|  |  |  | if (StringUtils.hasLength(tStory.getStory())) { | 
|---|
|  |  |  | for (String s : tStory.getStory().split(",")) { | 
|---|
|  |  |  | TStory byId = storyService.getById(s); | 
|---|
|  |  |  | names.append(byId.getName()).append(","); | 
|---|
|  |  |  | TStory byId = list10.stream().filter(e -> e.getId().equals(Integer.valueOf(s))).findFirst().orElse(null); | 
|---|
|  |  |  | if (byId != null) { | 
|---|
|  |  |  | names.append(byId.getName()).append(","); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.hasLength(tStory.getLookStory())) { | 
|---|
|  |  |  | for (String s : tStory.getLookStory().split(",")) { | 
|---|
|  |  |  | TStory byId = storyService.getById(s); | 
|---|
|  |  |  | names1.append(byId.getName()).append(","); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | TStory byId = list10.stream().filter(e -> e.getId().equals(Integer.valueOf(s))).findFirst().orElse(null); | 
|---|
|  |  |  | if (byId != null) { | 
|---|
|  |  |  | names1.append(byId.getName()).append(","); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.hasLength(tStory.getSort())) { | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("/goodRecommend") | 
|---|
|  |  |  | @ApiOperation(value = "可兑换商品推荐", tags = {"学习端-首页"}) | 
|---|
|  |  |  | public R<List<TGoodsVO>> studySchedule() { | 
|---|
|  |  |  | public R<List<TGoodsVO>> goodRecommend() { | 
|---|
|  |  |  | return R.ok(goodsClient.goodRecommend().getData()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取正确及错误提示音效 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("/promptVoice") | 
|---|
|  |  |  | @ApiOperation(value = "获取正确及错误提示音效", tags = {"学习端-首页"}) | 
|---|
|  |  |  | public R<TSysSet> promptVoice() { | 
|---|
|  |  |  | return R.ok(managementClient.promptVoice().getData()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取当前季度游戏难度 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("/userGameDifficulty") | 
|---|
|  |  |  | @ApiOperation(value = "获取当前季度游戏难度", tags = {"学习端-首页"}) | 
|---|
|  |  |  | public R<Integer> userGameDifficulty(@RequestParam Integer week) { | 
|---|
|  |  |  | LoginUserParent loginStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == loginStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer userid = loginStudy.getUserid(); | 
|---|
|  |  |  | TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userid) | 
|---|
|  |  |  | .eq(TUserStudy::getDisabled, 0).one(); | 
|---|
|  |  |  | return R.ok(studyService.userGameDifficulty(studyRecord, week)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 首次页面加载时调用,获取学习进度及学习时长等信息 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param week 周目 | 
|---|
|  |  |  | * @param day  所属day | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("/studySchedule") | 
|---|
|  |  |  | @ApiOperation(value = "获取用户学习进度", tags = {"学习端-首页"}) | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(value = "周目", name = "week", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "所属day", name = "day", dataType = "Integer", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<TUserStudy> studySchedule(@RequestParam Integer week, @RequestParam Integer day) { | 
|---|
|  |  |  | TUserStudy result = studyService.studySchedule(String.valueOf(tokenService.getLoginUserStudy().getUserid()), week); | 
|---|
|  |  |  | return R.ok(result); | 
|---|
|  |  |  | public R<TUserStudy> studySchedule(@RequestParam Integer week) { | 
|---|
|  |  |  | LoginUserParent loginStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == loginStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer userid = loginStudy.getUserid(); | 
|---|
|  |  |  | TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, loginStudy.getUserid()) | 
|---|
|  |  |  | .eq(TUserStudy::getDisabled, 0).one(); | 
|---|
|  |  |  | TStudy study = studyService.lambdaQuery().eq(TStudy::getWeek, week).one(); | 
|---|
|  |  |  | if (study.getQuarter()!=1){ | 
|---|
|  |  |  | // 判断上季度 通关率 | 
|---|
|  |  |  | String quarterRate = study.getQuarterRate(); | 
|---|
|  |  |  | BigDecimal bigDecimal = new BigDecimal(quarterRate); | 
|---|
|  |  |  | // 查询五个自主学习通关率 | 
|---|
|  |  |  | List<TSubjectRecordDetail> list = subjectRecordDetailService.lambdaQuery().eq(TSubjectRecordDetail::getWeek, week) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getUserId, userid).list(); | 
|---|
|  |  |  | List<TSubjectRecordDetail> pass = list.stream().filter(e -> e.getStatus() == 2).collect(Collectors.toList()); | 
|---|
|  |  |  | if (list.isEmpty()){ | 
|---|
|  |  |  | return R.fail("上季度未达到通关率"+quarterRate+"%,当前通关率0%"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BigDecimal divide = new BigDecimal(pass.size()).divide(new BigDecimal(list.size()), 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  | if (divide.compareTo(bigDecimal)<1){ | 
|---|
|  |  |  | return R.fail("上季度未达到通关率"+quarterRate+"%,当前通关率"+divide.multiply(new BigDecimal(100))+"%"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (null != studyRecord) { | 
|---|
|  |  |  | // 计算当前周 day 1-5的总进度 | 
|---|
|  |  |  | int computeSchedule = studyService.computeSchedule(studyRecord, week); | 
|---|
|  |  |  | studyRecord.setComputeSchedule(computeSchedule); | 
|---|
|  |  |  | // 学习时长格式转换 | 
|---|
|  |  |  | Integer todayStudy = studyRecord.getTodayStudy(); | 
|---|
|  |  |  | studyRecord.setTodayStudy(Math.round((float) todayStudy / 3600)); | 
|---|
|  |  |  | Integer weekStudy = studyRecord.getWeekStudy(); | 
|---|
|  |  |  | studyRecord.setWeekStudy(Math.round((float) weekStudy / 3600)); | 
|---|
|  |  |  | Integer monthStudy = studyRecord.getMonthStudy(); | 
|---|
|  |  |  | studyRecord.setMonthStudy(Math.round((float) monthStudy / 3600)); | 
|---|
|  |  |  | // 总时长还需计算上游戏测试成绩时长 | 
|---|
|  |  |  | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userid) | 
|---|
|  |  |  | .eq(TGameRecord::getDisabled, 0).list(); | 
|---|
|  |  |  | int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum(); | 
|---|
|  |  |  | Integer totalStudy = studyRecord.getTotalStudy(); | 
|---|
|  |  |  | studyRecord.setTotalStudy(Math.round((float) (totalStudy + sum) / 3600)); | 
|---|
|  |  |  | studyRecord = studyService.studySchedule(studyRecord, week); | 
|---|
|  |  |  | // 数据库保存的是已完成的学习进度,返回前端时需要转换为剩余学习进度 | 
|---|
|  |  |  | Integer look = studyRecord.getLook(); | 
|---|
|  |  |  | if (look != 100 && look != -1) { | 
|---|
|  |  |  | studyRecord.setLook(100 - look); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer pair = studyRecord.getPair(); | 
|---|
|  |  |  | if (pair != 100 && pair != -1) { | 
|---|
|  |  |  | studyRecord.setPair(100 - pair); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer answer = studyRecord.getAnswer(); | 
|---|
|  |  |  | if (answer != 100 && answer != -1) { | 
|---|
|  |  |  | studyRecord.setAnswer(100 - answer); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer induction = studyRecord.getInduction(); | 
|---|
|  |  |  | if (induction != 100 && induction != -1) { | 
|---|
|  |  |  | studyRecord.setInduction(100 - induction); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer listen = studyRecord.getListen(); | 
|---|
|  |  |  | if (listen != 100 && listen != -1) { | 
|---|
|  |  |  | studyRecord.setListen(100 - listen); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(studyRecord); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(value = "季度 首次进入季度quarter默认传1", name = "quarter", dataType = "Integer", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<List<StudyWeekDTO>> weekList(@RequestParam(defaultValue = "1") Integer type, @RequestParam Integer quarter) { | 
|---|
|  |  |  | List<StudyWeekDTO> result = studyService.weekList(type, quarter); | 
|---|
|  |  |  | LoginUserParent loginUserStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == loginUserStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<StudyWeekDTO> result = studyService.weekList(type, quarter, loginUserStudy.getUserid()); | 
|---|
|  |  |  | return R.ok(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取在线时间赠送积分信息 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("/onlineDuration") | 
|---|
|  |  |  | @ApiOperation(value = "获取在线时间赠送积分信息(单位分钟)", tags = {"学习端-首页"}) | 
|---|
|  |  |  | public R<String> onlineDuration() { | 
|---|
|  |  |  | TSysSet sysSet = managementClient.promptVoice().getData(); | 
|---|
|  |  |  | if (null == sysSet) { | 
|---|
|  |  |  | throw new GlobalException("获取在线时间赠送积分信息失败!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 返回在线时长 | 
|---|
|  |  |  | return R.ok(sysSet.getTime()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据在线时间赠送积分(定时任务) | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("/giveIntegral") | 
|---|
|  |  |  | @ApiOperation(value = "根据在线时间赠送积分(定时任务)", tags = {"学习端-首页"}) | 
|---|
|  |  |  | public R<Boolean> giveIntegral() { | 
|---|
|  |  |  | LoginUserParent loginStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == loginStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | TSysSet sysSet = managementClient.promptVoice().getData(); | 
|---|
|  |  |  | if (null == sysSet) { | 
|---|
|  |  |  | throw new GlobalException("获取在线时间赠送积分信息失败!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String integral = sysSet.getIntegral(); | 
|---|
|  |  |  | // 计算时间间隔 | 
|---|
|  |  |  | TUserPresentRecord record = userPresentRecordService.lambdaQuery() | 
|---|
|  |  |  | .eq(TUserPresentRecord::getUserId, loginStudy.getUserid()) | 
|---|
|  |  |  | .orderByDesc(TUserPresentRecord::getPresentTime) | 
|---|
|  |  |  | .eq(TUserPresentRecord::getIsDelete, 0).last("limit 1").one(); | 
|---|
|  |  |  | boolean result = true; | 
|---|
|  |  |  | TUser user = userService.lambdaQuery().eq(TUser::getId, loginStudy.getUserid()) | 
|---|
|  |  |  | .eq(TUser::getDisabled, 0).one(); | 
|---|
|  |  |  | if (null == record) { | 
|---|
|  |  |  | // 赠送积分 | 
|---|
|  |  |  | result = userService.lambdaUpdate().set(TUser::getIntegral, user.getIntegral() + Integer.parseInt(integral)) | 
|---|
|  |  |  | .eq(TUser::getId, loginStudy.getUserid()).update(); | 
|---|
|  |  |  | // 添加赠送积分记录 | 
|---|
|  |  |  | TUserPresentRecord data = new TUserPresentRecord(); | 
|---|
|  |  |  | data.setUserId(loginStudy.getUserid()); | 
|---|
|  |  |  | data.setPresentTime(new Date()); | 
|---|
|  |  |  | data.setIsDelete(0); | 
|---|
|  |  |  | result = result && userPresentRecordService.save(data); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (System.currentTimeMillis() - record.getPresentTime().getTime() >= (long) Integer.parseInt(sysSet.getTime()) * 60 * 1000) { | 
|---|
|  |  |  | // 赠送积分 | 
|---|
|  |  |  | result = userService.lambdaUpdate() | 
|---|
|  |  |  | .set(TUser::getIntegral, user.getIntegral() + Integer.parseInt(integral)) | 
|---|
|  |  |  | .eq(TUser::getId, loginStudy.getUserid()).update(); | 
|---|
|  |  |  | // 添加赠送积分记录 | 
|---|
|  |  |  | TUserPresentRecord data = new TUserPresentRecord(); | 
|---|
|  |  |  | data.setUserId(loginStudy.getUserid()); | 
|---|
|  |  |  | data.setPresentTime(new Date()); | 
|---|
|  |  |  | data.setIsDelete(0); | 
|---|
|  |  |  | result = result && userPresentRecordService.save(data); | 
|---|
|  |  |  | // 生成积分明细 | 
|---|
|  |  |  | TIntegralRecord integralRecord = new TIntegralRecord(); | 
|---|
|  |  |  | integralRecord.setIntegral(sysSet.getIntegral()); | 
|---|
|  |  |  | integralRecord.setMethod(Constants.ONLINE_DURATION); | 
|---|
|  |  |  | integralRecord.setUserId(loginStudy.getUserid()); | 
|---|
|  |  |  | result = result && integralRecordService.save(integralRecord); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "获取题组学习进度信息", tags = {"学习端-题目"}) | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(value = "周目", name = "week", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "所属day", name = "day", dataType = "Integer", required = true) | 
|---|
|  |  |  | @ApiImplicitParam(value = "所属day", name = "day", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "类型(1:听音选图,2:看图选音,3:归纳排除,4:有问有答,5:音图相配)", name = "type", dataType = "Integer", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<TSubjectRecord> teamSchedule(@RequestParam Integer week, @RequestParam Integer day) { | 
|---|
|  |  |  | TSubjectRecord subjectRecord = subjectRecordService.lambdaQuery().eq(TSubjectRecord::getWeek, week).eq(TSubjectRecord::getDay, day) | 
|---|
|  |  |  | .eq(TSubjectRecord::getUserId, tokenService.getLoginUserStudy().getUserid()).eq(TSubjectRecord::getDisabled, 0).one(); | 
|---|
|  |  |  | return R.ok(subjectRecord); | 
|---|
|  |  |  | public R<SubjectRecordResultVO> teamSchedule(@RequestParam Integer week, @RequestParam Integer day, | 
|---|
|  |  |  | @RequestParam Integer type) { | 
|---|
|  |  |  | LoginUserParent loginStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == loginStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | TSubjectRecord subjectRecord = subjectRecordService.lambdaQuery().eq(TSubjectRecord::getWeek, week) | 
|---|
|  |  |  | .eq(TSubjectRecord::getDay, day) | 
|---|
|  |  |  | .eq(TSubjectRecord::getType, type) | 
|---|
|  |  |  | .eq(TSubjectRecord::getUserId, loginStudy.getUserid()) | 
|---|
|  |  |  | .eq(TSubjectRecord::getDisabled, 0).one(); | 
|---|
|  |  |  | // 返回结果 | 
|---|
|  |  |  | SubjectRecordResultVO result; | 
|---|
|  |  |  | if (null != subjectRecord) { | 
|---|
|  |  |  | /*// 题组id | 
|---|
|  |  |  | List<Integer> teamIds = Arrays.stream(subjectRecord.getBeforeSubject().split(",")).map(Integer::parseInt) | 
|---|
|  |  |  | .collect(Collectors.toList()); | 
|---|
|  |  |  | // 题目id | 
|---|
|  |  |  | List<Integer> topicIds = Arrays.stream(subjectRecord.getCompleteSubject().split(",")).map(Integer::parseInt) | 
|---|
|  |  |  | .collect(Collectors.toList());*/ | 
|---|
|  |  |  | result = new SubjectRecordResultVO(null, null, subjectRecord.getAnswerNumber(), subjectRecord.getCorrectNumber(), subjectRecord.getSchedule()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | result = null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("/exitLearning") | 
|---|
|  |  |  | @ApiOperation(value = "退出学习(记录学习进度等信息)", tags = {"学习端-题目"}) | 
|---|
|  |  |  | public R<Boolean> exitLearning(@RequestBody TSubjectRecord subjectRecord) { | 
|---|
|  |  |  | // 学习时长处理 | 
|---|
|  |  |  | return R.ok(subjectRecordService.updateById(subjectRecord)); | 
|---|
|  |  |  | public R<Boolean> exitLearning(@RequestBody ExitLearnVO exitLearn) { | 
|---|
|  |  |  | LoginUserParent loginStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == loginStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 退出学习如果已经存在中途学习记录,则删除记录,保存新学习记录 | 
|---|
|  |  |  | Integer userid = loginStudy.getUserid(); | 
|---|
|  |  |  | TSubjectRecord subjectRecord = subjectRecordService.lambdaQuery() | 
|---|
|  |  |  | .eq(TSubjectRecord::getUserId, userid) | 
|---|
|  |  |  | .eq(TSubjectRecord::getWeek, exitLearn.getWeek()) | 
|---|
|  |  |  | .eq(TSubjectRecord::getDay, exitLearn.getDay()) | 
|---|
|  |  |  | .eq(TSubjectRecord::getType, exitLearn.getType()) | 
|---|
|  |  |  | .eq(TSubjectRecord::getDisabled, 0) | 
|---|
|  |  |  | .one(); | 
|---|
|  |  |  | if (null != subjectRecord) { | 
|---|
|  |  |  | subjectRecordService.removeById(subjectRecord); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 判断当前week和day是否已完成学习 | 
|---|
|  |  |  | TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userid) | 
|---|
|  |  |  | .eq(TUserStudy::getDisabled, 0).one(); | 
|---|
|  |  |  | if (null == userStudy) { | 
|---|
|  |  |  | userStudy = createUserStudy(userid); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer quarter = exitLearn.getQuarter(); | 
|---|
|  |  |  | Integer week = exitLearn.getWeek(); | 
|---|
|  |  |  | Integer day = exitLearn.getDay(); | 
|---|
|  |  |  | int schedule = exitLearn.getSchedule() - 1; | 
|---|
|  |  |  | if (userStudy.getWeek().equals(exitLearn.getWeek()) && userStudy.getDay().equals(exitLearn.getDay())) { | 
|---|
|  |  |  | // 计算完成率 | 
|---|
|  |  |  | Integer type = exitLearn.getType(); | 
|---|
|  |  |  | // 更新用户学习完成率 | 
|---|
|  |  |  | if (Constants.ONE.equals(type)) { | 
|---|
|  |  |  | if (userStudy.getListen() != 100) { | 
|---|
|  |  |  | if (1 == exitLearn.getSchedule()) { | 
|---|
|  |  |  | userStudy.setListen(Constants.BURDEN_ONE); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 听音选图 | 
|---|
|  |  |  | List<TStudyListen> studyListens = studyListenService.listenSelectPicture(quarter, week, day); | 
|---|
|  |  |  | int item = 0; | 
|---|
|  |  |  | for (TStudyListen studyListen : studyListens) { | 
|---|
|  |  |  | item += studyListen.getSubject().split(",").length; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int i = (int) (((double) schedule / item) * 100); | 
|---|
|  |  |  | userStudy.setListen(i); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else if (Constants.TWO.equals(type)) { | 
|---|
|  |  |  | if (userStudy.getLook() != 100) { | 
|---|
|  |  |  | if (1 == exitLearn.getSchedule()) { | 
|---|
|  |  |  | userStudy.setLook(Constants.BURDEN_ONE); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 看图选音 | 
|---|
|  |  |  | List<TStudyLook> lookList = studyLookService.pictureSelectVoice(quarter, week, day); | 
|---|
|  |  |  | if (!lookList.isEmpty()) { | 
|---|
|  |  |  | int item = lookList.size(); | 
|---|
|  |  |  | int i = (int) (((double) schedule / item) * 100); | 
|---|
|  |  |  | userStudy.setLook(i); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else if (Constants.THREE.equals(type)) { | 
|---|
|  |  |  | if (userStudy.getInduction() != 100) { | 
|---|
|  |  |  | if (1 == exitLearn.getSchedule()) { | 
|---|
|  |  |  | userStudy.setInduction(Constants.BURDEN_ONE); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 归纳排除 | 
|---|
|  |  |  | List<TStudyInduction> inductionList = studyInductionService.induceExclude(quarter, week, day); | 
|---|
|  |  |  | if (!inductionList.isEmpty()) { | 
|---|
|  |  |  | int item = inductionList.size(); | 
|---|
|  |  |  | int i = (int) (((double) schedule / item) * 100); | 
|---|
|  |  |  | userStudy.setInduction(i); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else if (Constants.FOUR.equals(type)) { | 
|---|
|  |  |  | if (userStudy.getAnswer() != 100) { | 
|---|
|  |  |  | if (1 == exitLearn.getSchedule()) { | 
|---|
|  |  |  | userStudy.setAnswer(Constants.BURDEN_ONE); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 有问有答 | 
|---|
|  |  |  | List<TStudyAnswer> answerList = studyAnswerService.questionsAndAnswers(quarter, week, day); | 
|---|
|  |  |  | if (answerList.size() % Constants.TWO == Constants.ZERO) { | 
|---|
|  |  |  | int i = (int) (((double) schedule / (answerList.size() / 2)) * 100); | 
|---|
|  |  |  | userStudy.setAnswer(i); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else if (Constants.FIVE.equals(type)) { | 
|---|
|  |  |  | if (userStudy.getPair() != 100) { | 
|---|
|  |  |  | if (1 == exitLearn.getSchedule()) { | 
|---|
|  |  |  | userStudy.setPair(Constants.BURDEN_ONE); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 音图相配 | 
|---|
|  |  |  | List<TStudyPair> pairList = studyPairService.pictureMateVoice(quarter, week, day); | 
|---|
|  |  |  | if (!pairList.isEmpty()) { | 
|---|
|  |  |  | int item = pairList.size(); | 
|---|
|  |  |  | int i = (int) (((double) schedule / item) * 100); | 
|---|
|  |  |  | userStudy.setPair(i); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 学习时长更新 | 
|---|
|  |  |  | userStudy.setTotalStudy(userStudy.getTotalStudy() + exitLearn.getStudyTime()); | 
|---|
|  |  |  | userStudy.setTodayStudy(userStudy.getTodayStudy() + exitLearn.getStudyTime()); | 
|---|
|  |  |  | userStudy.setWeekStudy(userStudy.getWeekStudy() + exitLearn.getStudyTime()); | 
|---|
|  |  |  | userStudy.setMonthStudy(userStudy.getMonthStudy() + exitLearn.getStudyTime()); | 
|---|
|  |  |  | userStudyService.updateById(userStudy); | 
|---|
|  |  |  | return R.ok(subjectRecordService.exitLearning(exitLearn, userid)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 退出游戏/故事学习 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("/exitGameOrStory") | 
|---|
|  |  |  | @ApiOperation(value = "退出游戏/故事学习", tags = {"学习端-题目"}) | 
|---|
|  |  |  | public R<Boolean> exitGameOrStory(@RequestParam("studyTime") Integer studyTime) { | 
|---|
|  |  |  | LoginUserParent loginStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == loginStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer userid = loginStudy.getUserid(); | 
|---|
|  |  |  | // 判断当前week和day是否已完成学习 | 
|---|
|  |  |  | TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userid) | 
|---|
|  |  |  | .eq(TUserStudy::getDisabled, 0).one(); | 
|---|
|  |  |  | if (null == userStudy) { | 
|---|
|  |  |  | userStudy = createUserStudy(userid); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 学习时长更新 | 
|---|
|  |  |  | userStudy.setTotalStudy(userStudy.getTotalStudy() + studyTime); | 
|---|
|  |  |  | userStudy.setTodayStudy(userStudy.getTodayStudy() + studyTime); | 
|---|
|  |  |  | userStudy.setWeekStudy(userStudy.getWeekStudy() + studyTime); | 
|---|
|  |  |  | userStudy.setMonthStudy(userStudy.getMonthStudy() + studyTime); | 
|---|
|  |  |  | return R.ok(userStudyService.updateById(userStudy)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(value = "周目", name = "week", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "所属day", name = "day", dataType = "Integer", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<StudyListenResultVO> listenSelectPicture(@RequestParam Integer quarter, @RequestParam Integer week, @RequestParam Integer day) { | 
|---|
|  |  |  | public R<StudyListenResultVO> listenSelectPicture(@RequestParam Integer quarter, @RequestParam Integer week, | 
|---|
|  |  |  | @RequestParam Integer day) { | 
|---|
|  |  |  | // 判断当前登录用户是否为 会员 | 
|---|
|  |  |  | Boolean isVip = userService.isVip(); | 
|---|
|  |  |  | // 非会员只能查看非会员题目,会员可以查看所有题目 | 
|---|
|  |  |  | List<TStudyListen> studyListens = studyListenService.listenSelectPicture(quarter, week, day); | 
|---|
|  |  |  | for (TStudyListen studyListen : studyListens) { | 
|---|
|  |  |  | if (studyListen.getIsVip() == 1) { | 
|---|
|  |  |  | if (studyListen.getIsVip() == 0) { | 
|---|
|  |  |  | // 需要会员查看 | 
|---|
|  |  |  | if (!isVip) { | 
|---|
|  |  |  | // 不是会员 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(studyService.listenSelectPicture(week, day, studyListens)); | 
|---|
|  |  |  | return R.ok(studyService.listenSelectPicture(week, day, studyListens, tokenService.getLoginUserStudy().getUserid())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(value = "周目", name = "week", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "所属day", name = "day", dataType = "Integer", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<StudyLookResultVO> pictureSelectVoice(@RequestParam Integer quarter, @RequestParam Integer week, @RequestParam Integer day) { | 
|---|
|  |  |  | public R<StudyLookResultVO> pictureSelectVoice(@RequestParam Integer quarter, @RequestParam Integer week, | 
|---|
|  |  |  | @RequestParam Integer day) { | 
|---|
|  |  |  | // 判断当前登录用户是否为 会员 | 
|---|
|  |  |  | Boolean isVip = userService.isVip(); | 
|---|
|  |  |  | // 非会员只能查看非会员题目,会员可以查看所有题目 | 
|---|
|  |  |  | List<TStudyLook> lookList = studyLookService.pictureSelectVoice(quarter, week, day); | 
|---|
|  |  |  | for (TStudyLook studyListen : lookList) { | 
|---|
|  |  |  | if (studyListen.getIsVip() == 1) { | 
|---|
|  |  |  | if (studyListen.getIsVip() == 0) { | 
|---|
|  |  |  | // 需要会员查看 | 
|---|
|  |  |  | if (!isVip) { | 
|---|
|  |  |  | // 不是会员 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(studyService.pictureSelectVoice(week, day, lookList)); | 
|---|
|  |  |  | return studyService.pictureSelectVoice(week, day, lookList, tokenService.getLoginUserStudy().getUserid()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(value = "周目", name = "week", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "所属day", name = "day", dataType = "Integer", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<StudyInductionResultVO> induceExclude(@RequestParam Integer quarter, @RequestParam Integer week, @RequestParam Integer day) { | 
|---|
|  |  |  | public R<StudyInductionResultVO> induceExclude(@RequestParam Integer quarter, @RequestParam Integer week, | 
|---|
|  |  |  | @RequestParam Integer day) { | 
|---|
|  |  |  | // 判断当前登录用户是否为 会员 | 
|---|
|  |  |  | Boolean isVip = userService.isVip(); | 
|---|
|  |  |  | // 非会员只能查看非会员题目,会员可以查看所有题目 | 
|---|
|  |  |  | List<TStudyInduction> inductionList = studyInductionService.induceExclude(quarter, week, day); | 
|---|
|  |  |  | for (TStudyInduction studyListen : inductionList) { | 
|---|
|  |  |  | if (studyListen.getIsVip() == 1) { | 
|---|
|  |  |  | if (studyListen.getIsVip() == 0) { | 
|---|
|  |  |  | // 需要会员查看 | 
|---|
|  |  |  | if (!isVip) { | 
|---|
|  |  |  | // 不是会员 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(studyService.induceExclude(week, day, inductionList)); | 
|---|
|  |  |  | return studyService.induceExclude(week, day, inductionList, tokenService.getLoginUserStudy().getUserid()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(value = "周目", name = "week", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "所属day", name = "day", dataType = "Integer", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<StudyAnswerResultVO> questionsAndAnswers(@RequestParam Integer quarter, @RequestParam Integer week, @RequestParam Integer day) { | 
|---|
|  |  |  | public R<StudyAnswerResultVO> questionsAndAnswers(@RequestParam Integer quarter, @RequestParam Integer week, | 
|---|
|  |  |  | @RequestParam Integer day) { | 
|---|
|  |  |  | // 判断当前登录用户是否为 会员 | 
|---|
|  |  |  | Boolean isVip = userService.isVip(); | 
|---|
|  |  |  | // 非会员只能查看非会员题目,会员可以查看所有题目 | 
|---|
|  |  |  | List<TStudyAnswer> answerList = studyAnswerService.questionsAndAnswers(quarter, week, day); | 
|---|
|  |  |  | for (TStudyAnswer studyListen : answerList) { | 
|---|
|  |  |  | if (studyListen.getIsVip() == 1) { | 
|---|
|  |  |  | if (studyListen.getIsVip() == 0) { | 
|---|
|  |  |  | // 需要会员查看 | 
|---|
|  |  |  | if (!isVip) { | 
|---|
|  |  |  | // 不是会员 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(studyService.questionsAndAnswers(week, day, answerList)); | 
|---|
|  |  |  | return studyService.questionsAndAnswers(week, day, answerList, tokenService.getLoginUserStudy().getUserid()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(value = "周目", name = "week", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "所属day", name = "day", dataType = "Integer", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<StudyPairResultVO> pictureMateVoice(@RequestParam Integer quarter, @RequestParam Integer week, @RequestParam Integer day) { | 
|---|
|  |  |  | public R<StudyPairResultVO> pictureMateVoice(@RequestParam Integer quarter, @RequestParam Integer week, | 
|---|
|  |  |  | @RequestParam Integer day) { | 
|---|
|  |  |  | // 判断当前登录用户是否为 会员 | 
|---|
|  |  |  | Boolean isVip = userService.isVip(); | 
|---|
|  |  |  | // 非会员只能查看非会员题目,会员可以查看所有题目 | 
|---|
|  |  |  | List<TStudyPair> pairList = studyPairService.pictureMateVoice(quarter, week, day); | 
|---|
|  |  |  | for (TStudyPair pair : pairList) { | 
|---|
|  |  |  | if (pair.getIsVip() == 1) { | 
|---|
|  |  |  | if (pair.getIsVip() == 0) { | 
|---|
|  |  |  | // 需要会员查看 | 
|---|
|  |  |  | if (!isVip) { | 
|---|
|  |  |  | // 不是会员 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(studyService.pictureMateVoice(week, day, pairList)); | 
|---|
|  |  |  | return studyService.pictureMateVoice(week, day, pairList, tokenService.getLoginUserStudy().getUserid()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 2.0新增-记录答题状态 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("/answerQuestion") | 
|---|
|  |  |  | @ApiOperation(value = "2.0新增-记录答题状态", tags = {"学习端-听-自主学习"}) | 
|---|
|  |  |  | public R answerQuestion(@RequestBody @Validated AnswerQuestionDTO answerQuestionDTO) { | 
|---|
|  |  |  | LoginUserParent userStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == userStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | System.err.println("答题DTO"+answerQuestionDTO); | 
|---|
|  |  |  | TSubjectRecordDetail byId = subjectRecordDetailService.getById(answerQuestionDTO.getId()); | 
|---|
|  |  |  | byId.setUserId(null); | 
|---|
|  |  |  | byId.setStatus(answerQuestionDTO.getStatus()); | 
|---|
|  |  |  | subjectRecordDetailService.updateById(byId); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 2.0新增-重新开始 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("/restart") | 
|---|
|  |  |  | @ApiOperation(value = "2.0新增-重新开始", tags = {"学习端-听-自主学习"}) | 
|---|
|  |  |  | public R restart(@RequestBody RestartDTO restartDTO) { | 
|---|
|  |  |  | LoginUserParent userStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == userStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TSubjectRecordDetail> list = subjectRecordDetailService.lambdaQuery() | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getUserId, userStudy.getUserid()) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getWeek, restartDTO.getWeek()) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getDay, restartDTO.getDay()) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getType, restartDTO.getType()) | 
|---|
|  |  |  | .list(); | 
|---|
|  |  |  | for (TSubjectRecordDetail tSubjectRecordDetail : list) { | 
|---|
|  |  |  | tSubjectRecordDetail.setStatus(1); | 
|---|
|  |  |  | tSubjectRecordDetail.setUserId(null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | subjectRecordDetailService.updateBatchById(list); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 学习完成,生成学习记录,积分明细记录 | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("/completeLearning") | 
|---|
|  |  |  | @ApiOperation(value = "完成学习", tags = {"学习端-听-自主学习"}) | 
|---|
|  |  |  | public R<Boolean> completeLearning(@RequestBody CompleteStudyDTO completeStudy) { | 
|---|
|  |  |  | public R<Integer> completeLearning(@RequestBody CompleteStudyDTO completeStudy) { | 
|---|
|  |  |  | LoginUserParent userStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == userStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 登录用户id | 
|---|
|  |  |  | Integer userId = tokenService.getLoginUserStudy().getUserid(); | 
|---|
|  |  |  | Integer userId = userStudy.getUserid(); | 
|---|
|  |  |  | // 判断是否已完成该题组 | 
|---|
|  |  |  | boolean update = true; | 
|---|
|  |  |  | if (completeStudy.getIsComplete()) { | 
|---|
|  |  |  | List<Integer> studyIds = completeStudy.getStudyIds(); | 
|---|
|  |  |  | Integer type = completeStudy.getType(); | 
|---|
|  |  |  | int sum; | 
|---|
|  |  |  | if (Constants.ONE.equals(type)) { | 
|---|
|  |  |  | List<TStudyListen> studyListens = studyListenService.lambdaQuery().in(TStudyListen::getId, studyIds) | 
|---|
|  |  |  | .eq(TStudyListen::getDisabled, 0).list(); | 
|---|
|  |  |  | sum = studyListens.stream().mapToInt(TStudyListen::getIntegral).sum(); | 
|---|
|  |  |  | } else if (Constants.TWO.equals(type)) { | 
|---|
|  |  |  | List<TStudyLook> studyListens = studyLookService.lambdaQuery().in(TStudyLook::getId, studyIds) | 
|---|
|  |  |  | .eq(TStudyLook::getDisabled, 0).list(); | 
|---|
|  |  |  | sum = studyListens.stream().mapToInt(TStudyLook::getIntegral).sum(); | 
|---|
|  |  |  | } else if (Constants.THREE.equals(type)) { | 
|---|
|  |  |  | List<TStudyInduction> studyListens = studyInductionService.lambdaQuery().in(TStudyInduction::getId, studyIds) | 
|---|
|  |  |  | .eq(TStudyInduction::getDisabled, 0).list(); | 
|---|
|  |  |  | sum = studyListens.stream().mapToInt(TStudyInduction::getIntegral).sum(); | 
|---|
|  |  |  | } else if (Constants.FOUR.equals(type)) { | 
|---|
|  |  |  | List<TStudyAnswer> studyListens = studyAnswerService.lambdaQuery().in(TStudyAnswer::getId, studyIds) | 
|---|
|  |  |  | .eq(TStudyAnswer::getDisabled, 0).list(); | 
|---|
|  |  |  | sum = studyListens.stream().mapToInt(TStudyAnswer::getIntegral).sum(); | 
|---|
|  |  |  | } else if (Constants.FIVE.equals(type)) { | 
|---|
|  |  |  | List<TStudyPair> studyListens = studyPairService.lambdaQuery().in(TStudyPair::getId, studyIds) | 
|---|
|  |  |  | .eq(TStudyPair::getDisabled, 0).list(); | 
|---|
|  |  |  | sum = studyListens.stream().mapToInt(TStudyPair::getIntegral).sum(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return R.fail("题目信息异常!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | boolean update; | 
|---|
|  |  |  | // 清除中途退出记录 | 
|---|
|  |  |  | TSubjectRecord subjectRecord = subjectRecordService.lambdaQuery() | 
|---|
|  |  |  | .eq(TSubjectRecord::getUserId, userId) | 
|---|
|  |  |  | .eq(TSubjectRecord::getWeek, completeStudy.getWeek()) | 
|---|
|  |  |  | .eq(TSubjectRecord::getDay, completeStudy.getDay()) | 
|---|
|  |  |  | .eq(TSubjectRecord::getType, completeStudy.getType()) | 
|---|
|  |  |  | .eq(TSubjectRecord::getDisabled, 0) | 
|---|
|  |  |  | .one(); | 
|---|
|  |  |  | if (null != subjectRecord) { | 
|---|
|  |  |  | subjectRecordService.removeById(subjectRecord); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<String> studyIds = Arrays.stream(completeStudy.getStudyIds().split(",")) | 
|---|
|  |  |  | .collect(Collectors.toList()); | 
|---|
|  |  |  | Integer type = completeStudy.getType(); | 
|---|
|  |  |  | // 可获取的总积分数量以及获取用户该学习已获取的积分数量,并计算本次可获取的剩余积分数量 | 
|---|
|  |  |  | int sum = studyService.computeTotalIntegral(studyIds, type, completeStudy.getAccuracy()); | 
|---|
|  |  |  | // 用户已获取的积分数量 | 
|---|
|  |  |  | int obtainedIntegral; | 
|---|
|  |  |  | List<TUserStudyRecord> list = studyRecordService.lambdaQuery() | 
|---|
|  |  |  | .eq(TUserStudyRecord::getQuarter, completeStudy.getQuarter()) | 
|---|
|  |  |  | .eq(TUserStudyRecord::getWeek, completeStudy.getWeek()) | 
|---|
|  |  |  | .eq(TUserStudyRecord::getDay, completeStudy.getDay()) | 
|---|
|  |  |  | .eq(TUserStudyRecord::getType, 0) | 
|---|
|  |  |  | .eq(TUserStudyRecord::getStudyType, completeStudy.getType()) | 
|---|
|  |  |  | .eq(TUserStudyRecord::getUserId, userId).list(); | 
|---|
|  |  |  | if (list.isEmpty()) { | 
|---|
|  |  |  | obtainedIntegral = 0; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | obtainedIntegral = list.stream().map(TUserStudyRecord::getObtainedIntegral) | 
|---|
|  |  |  | .mapToInt(Integer::intValue).sum(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 计算本次可获取积分数量 | 
|---|
|  |  |  | if (sum > obtainedIntegral) { | 
|---|
|  |  |  | int integral = sum - obtainedIntegral; | 
|---|
|  |  |  | // 获取user详细信息,改变积分 | 
|---|
|  |  |  | TUser user = userService.getById(userId); | 
|---|
|  |  |  | user.setIntegral(user.getIntegral() + sum); | 
|---|
|  |  |  | update = userService.updateById(user); | 
|---|
|  |  |  | int i = user.getIntegral() + integral; | 
|---|
|  |  |  | update = userService.lambdaUpdate().eq(TUser::getId, userId).set(TUser::getIntegral, i).update(); | 
|---|
|  |  |  | // 生成积分明细记录 | 
|---|
|  |  |  | TIntegralRecord integralRecord = new TIntegralRecord(); | 
|---|
|  |  |  | integralRecord.setIntegral(String.valueOf(sum)); | 
|---|
|  |  |  | integralRecord.setIntegral(String.valueOf(integral)); | 
|---|
|  |  |  | integralRecord.setMethod(Constants.COMPLETE_LEARNING); | 
|---|
|  |  |  | integralRecord.setUserId(userId); | 
|---|
|  |  |  | update = update && integralRecordService.save(integralRecord); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 学习配置列表 | 
|---|
|  |  |  | List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0).orderByAsc(TStudy::getWeek).list(); | 
|---|
|  |  |  | if (studyList.isEmpty()) { | 
|---|
|  |  |  | throw new GlobalException("学习配置列表未配置或数据失效!"); | 
|---|
|  |  |  | // 生成学习完成记录 | 
|---|
|  |  |  | TUserStudyRecord record = new TUserStudyRecord(); | 
|---|
|  |  |  | record.setUserId(userId); | 
|---|
|  |  |  | record.setQuarter(completeStudy.getQuarter()); | 
|---|
|  |  |  | record.setWeek(completeStudy.getWeek()); | 
|---|
|  |  |  | record.setDay(completeStudy.getDay()); | 
|---|
|  |  |  | // 学习类型 | 
|---|
|  |  |  | record.setStudyType(completeStudy.getType()); | 
|---|
|  |  |  | record.setObtainedIntegral(integral); | 
|---|
|  |  |  | record.setType(Constants.ZERO); | 
|---|
|  |  |  | update = update && studyRecordService.save(record); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 更改学习记录 | 
|---|
|  |  |  | Boolean updateStudyRecord = userStudyService.exchangeStudyRecord(studyList, userId, completeStudy); | 
|---|
|  |  |  | return R.ok(update && updateStudyRecord); | 
|---|
|  |  |  | TUserStudy userStudyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId) | 
|---|
|  |  |  | .eq(TUserStudy::getDisabled, 0).one(); | 
|---|
|  |  |  | if (null == userStudyRecord) { | 
|---|
|  |  |  | userStudyRecord = createUserStudy(userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Boolean updateStudyRecord = userStudyService.exchangeStudyRecord(userStudyRecord, userId, completeStudy); | 
|---|
|  |  |  | return R.ok(sum > obtainedIntegral ? sum - obtainedIntegral : 0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(value = "难度(0入门、1中级、2困难)", name = "difficulty", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "所属周目", name = "week", dataType = "Integer", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<StudyGamerResultVO> gameHearing(@RequestParam Integer quarter, @RequestParam Integer difficulty, @RequestParam Integer week) { | 
|---|
|  |  |  | public R<StudyGameResultVO> gameHearing(@RequestParam Integer quarter, @RequestParam Integer difficulty, | 
|---|
|  |  |  | @RequestParam Integer week) { | 
|---|
|  |  |  | LoginUserParent userStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == userStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TSubjectRecordDetail> subjectRecordDetails = subjectRecordDetailService.lambdaQuery().eq(TSubjectRecordDetail::getUserId, userStudy.getUserid()) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getWeek, week).eq(BaseModel::getDisabled, 0).list(); | 
|---|
|  |  |  | List<TSubjectRecordDetail> listenList = subjectRecordDetails.stream().filter(e -> e.getType() == 5).collect(Collectors.toList()); | 
|---|
|  |  |  | int listenPass = (int) listenList.stream().filter(e -> e.getStatus() == 2).count(); | 
|---|
|  |  |  | int listenSize = listenList.size(); | 
|---|
|  |  |  | if (listenSize!=0){ | 
|---|
|  |  |  | // 先计算上一天的通关率 设置为两位小数 | 
|---|
|  |  |  | double listenRate = (double) listenPass /listenSize; | 
|---|
|  |  |  | BigDecimal divide = new BigDecimal(listenPass).divide(new BigDecimal(listenSize), 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  | TStudyPair one = studyPairService.lambdaQuery().eq(TStudyPair::getWeek, week) | 
|---|
|  |  |  | .eq(TStudyPair::getDay, 5).last("limit 1").one(); | 
|---|
|  |  |  | if (one!=null){ | 
|---|
|  |  |  | if (listenRate<(Double.parseDouble(one.getRate())/100)){ | 
|---|
|  |  |  | return R.fail("音图相配未达到通关率"+one.getRate()+"%,"+"当前通关率:"+divide.multiply(new BigDecimal(100))+"%"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer[] array = {0, 1, 2}; | 
|---|
|  |  |  | if (!Arrays.stream(array).collect(Collectors.toList()).contains(difficulty)) { | 
|---|
|  |  |  | throw new GlobalException("请选择符合规则的游戏难度!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | TGame game = gameService.gameHearing(quarter, week); | 
|---|
|  |  |  | if (null == game) { | 
|---|
|  |  |  | throw new GlobalException("当前季度该周目暂无配置游戏数据!"); | 
|---|
|  |  |  | 
|---|
|  |  |  | game.setIntegral(game.getIntegral().split(",")[difficulty]); | 
|---|
|  |  |  | game.setTime(game.getTime().split(",")[difficulty]); | 
|---|
|  |  |  | // 检验是否完成难度 | 
|---|
|  |  |  | studyService.checkDifficulty(difficulty, week, game); | 
|---|
|  |  |  | List<String> subjectId = getSubjectId(week); | 
|---|
|  |  |  | studyService.checkDifficulty(difficulty, week, game, userStudy.getUserid()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        List<String> subjectId = getSubjectId(week); | 
|---|
|  |  |  | List<String> subjectId = new ArrayList<>(); | 
|---|
|  |  |  | String subjectIds = game.getSubjectIds(); | 
|---|
|  |  |  | if(subjectIds!=null){ | 
|---|
|  |  |  | String[] split = subjectIds.split(","); | 
|---|
|  |  |  | for (String s : split) { | 
|---|
|  |  |  | subjectId.add(s); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<String> newSubjectId = subjectId.stream().map(data -> { | 
|---|
|  |  |  | if (data.startsWith(Constants.REDUCE)) { | 
|---|
|  |  |  | data = data.replace(Constants.REDUCE, Constants.EMPTY_STR); | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new GlobalException("当前周目下day1 - day5题目不足!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 根据游戏设置数量获取图片及语音 | 
|---|
|  |  |  | List<String> subjectData = new ArrayList<>(); | 
|---|
|  |  |  | Random random = new Random(); | 
|---|
|  |  |  | // 获取列表大小 | 
|---|
|  |  |  | int dataSize = newSubjectId.size(); | 
|---|
|  |  |  | // 生成随机索引并获取数据 | 
|---|
|  |  |  | for (int i = 0; i < game.getCount(); i++) { | 
|---|
|  |  |  | // 生成随机索引 | 
|---|
|  |  |  | int randomIndex = random.nextInt(dataSize); | 
|---|
|  |  |  | // 获取对应的数据并加入结果列表 | 
|---|
|  |  |  | subjectData.add(newSubjectId.get(randomIndex)); | 
|---|
|  |  |  | newSubjectId.remove(randomIndex); | 
|---|
|  |  |  | dataSize = newSubjectId.size(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<String> subjectData = getData(game, newSubjectId, 1); | 
|---|
|  |  |  | List<TSubject> subjectList = getSubjectList(subjectData); | 
|---|
|  |  |  | return R.ok(new StudyGamerResultVO(game, subjectList)); | 
|---|
|  |  |  | return R.ok(new StudyGameResultVO(game, subjectList)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(value = "季度", name = "quarter", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "所属周目", name = "week", dataType = "Integer", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<StudyGamerResultVO> gameMemory(@RequestParam Integer quarter, @RequestParam Integer week) { | 
|---|
|  |  |  | public R<StudyGameMemoryVO> gameMemory(@RequestParam Integer quarter, @RequestParam Integer week) { | 
|---|
|  |  |  | LoginUserParent userStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == userStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TSubjectRecordDetail> subjectRecordDetails = subjectRecordDetailService.lambdaQuery().eq(TSubjectRecordDetail::getUserId, userStudy.getUserid()) | 
|---|
|  |  |  | .eq(TSubjectRecordDetail::getWeek, week).eq(BaseModel::getDisabled, 0).list(); | 
|---|
|  |  |  | List<TSubjectRecordDetail> listenList = subjectRecordDetails.stream().filter(e -> e.getType() == 5).collect(Collectors.toList()); | 
|---|
|  |  |  | int listenPass = (int) listenList.stream().filter(e -> e.getStatus() == 2).count(); | 
|---|
|  |  |  | int listenSize = listenList.size(); | 
|---|
|  |  |  | if (listenSize!=0){ | 
|---|
|  |  |  | // 先计算上一天的通关率 设置为两位小数 | 
|---|
|  |  |  | double listenRate = (double) listenPass /listenSize; | 
|---|
|  |  |  | BigDecimal divide = new BigDecimal(listenPass).divide(new BigDecimal(listenSize), 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  | TStudyPair one = studyPairService.lambdaQuery().eq(TStudyPair::getWeek, week) | 
|---|
|  |  |  | .eq(TStudyPair::getDay, 5).last("limit 1").one(); | 
|---|
|  |  |  | if (one!=null){ | 
|---|
|  |  |  | if (listenRate<(Double.parseDouble(one.getRate())/100)){ | 
|---|
|  |  |  | return R.fail("音图相配未达到通关率"+one.getRate()+"%,"+"当前通关率:"+divide.multiply(new BigDecimal(100))+"%"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | TGame game = gameService.gameHearing(quarter, week); | 
|---|
|  |  |  | if (null == game) { | 
|---|
|  |  |  | throw new GlobalException("当前季度该周目暂无配置游戏数据!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<String> subjectId = getSubjectId(week); | 
|---|
|  |  |  | //        List<String> subjectId = getSubjectId(week); | 
|---|
|  |  |  | List<String> subjectId = new ArrayList<>(); | 
|---|
|  |  |  | String subjectIds = game.getSubjectIdsOne(); | 
|---|
|  |  |  | if(subjectIds!=null){ | 
|---|
|  |  |  | String[] split = subjectIds.split(","); | 
|---|
|  |  |  | for (String s : split) { | 
|---|
|  |  |  | subjectId.add(s); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<String> subjectData = getSubjectData(game, subjectId); | 
|---|
|  |  |  | List<TSubject> subjectList = getSubjectList(subjectData); | 
|---|
|  |  |  | // 返回数据 | 
|---|
|  |  |  | List<GameMemoryPhotoVO> photoList = new ArrayList<>(); | 
|---|
|  |  |  | List<GameMemoryVoiceVO> voiceList = new ArrayList<>(); | 
|---|
|  |  |  | for (TSubject tSubject : subjectList) { | 
|---|
|  |  |  | photoList.add(new GameMemoryPhotoVO(tSubject.getId(), tSubject.getImg())); | 
|---|
|  |  |  | voiceList.add(new GameMemoryVoiceVO(tSubject.getId(), tSubject.getCorrect())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | photoList = photoList.stream().distinct().collect(Collectors.toList()); | 
|---|
|  |  |  | voiceList = voiceList.stream().distinct().collect(Collectors.toList()); | 
|---|
|  |  |  | // 校验超级听力是否通过 | 
|---|
|  |  |  | // studyService.checkClearance(game,userStudy.getUserid()); | 
|---|
|  |  |  | // 框架记忆数量翻倍,前端需要根据数量画格子 | 
|---|
|  |  |  | game.setAnswerCount(game.getAnswerCount() * 2); | 
|---|
|  |  |  | return R.ok(new StudyGameMemoryVO(game, photoList, voiceList)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private List<String> getSubjectData(TGame game, List<String> subjectId) { | 
|---|
|  |  |  | List<String> newSubjectId = subjectId.stream().map(data -> { | 
|---|
|  |  |  | if (data.startsWith(Constants.REDUCE)) { | 
|---|
|  |  |  | data = data.replace(Constants.REDUCE, Constants.EMPTY_STR); | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new GlobalException("当前周目下day1 - day5题目不足!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 根据游戏设置数量获取图片及语音 | 
|---|
|  |  |  | return getData(game, newSubjectId, 2); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private List<String> getData(TGame game, List<String> newSubjectId, int num) { | 
|---|
|  |  |  | List<String> subjectData = new ArrayList<>(); | 
|---|
|  |  |  | Random random = new Random(); | 
|---|
|  |  |  | java.util.Random random = new java.util.Random(); | 
|---|
|  |  |  | // 获取列表大小 | 
|---|
|  |  |  | int dataSize = newSubjectId.size(); | 
|---|
|  |  |  | // 生成随机索引并获取数据 | 
|---|
|  |  |  | for (int i = 0; i < game.getCount(); i++) { | 
|---|
|  |  |  | int index; | 
|---|
|  |  |  | if (1 == num) { | 
|---|
|  |  |  | index = game.getCount(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | index = game.getAnswerCount(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (int i = 0; i < index; i++) { | 
|---|
|  |  |  | // 生成随机索引 | 
|---|
|  |  |  | int randomIndex = random.nextInt(dataSize); | 
|---|
|  |  |  | // 获取对应的数据并加入结果列表 | 
|---|
|  |  |  | 
|---|
|  |  |  | newSubjectId.remove(randomIndex); | 
|---|
|  |  |  | dataSize = newSubjectId.size(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TSubject> subjectList = getSubjectList(subjectData); | 
|---|
|  |  |  | // 格子翻倍,前端需要做连连看 | 
|---|
|  |  |  | List<TSubject> resultList = new ArrayList<>(); | 
|---|
|  |  |  | for (int i = 0; i < Constants.TWO; i++) { | 
|---|
|  |  |  | resultList.addAll(subjectList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 框架记忆数量翻倍,前端需要根据数量画格子 | 
|---|
|  |  |  | game.setAnswerCount(game.getAnswerCount() * 2); | 
|---|
|  |  |  | return R.ok(new StudyGamerResultVO(game, resultList)); | 
|---|
|  |  |  | return subjectData; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private List<TSubject> getSubjectList(List<String> subjectData) { | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("/gameAchievement") | 
|---|
|  |  |  | @ApiOperation(value = "完成游戏-记录游戏测试成绩", tags = {"学习端-听-自主游戏"}) | 
|---|
|  |  |  | public R<Boolean> gameAchievement(@RequestBody CompleteGameDTO completeStudy) { | 
|---|
|  |  |  | public R<Integer> gameAchievement(@RequestBody CompleteGameDTO completeStudy) { | 
|---|
|  |  |  | LoginUserParent loginUserStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == loginUserStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | * 游戏测试需要根据正确率计算本次测试可获得积分 | 
|---|
|  |  |  | * 并且需要判断如果该游戏用户已获取一部分积分,再次测试后正确率增长,只能获取高于上次正确率的部分积分 | 
|---|
|  |  |  | * 例如:游戏配置的积分是100,他的正确率是50%那么拿50分,下次他再玩这个游戏 正确率是60% 那么他该获得60分 但是上次已经拿了50 所以这次就只给他加10积分 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Integer userid = tokenService.getLoginUserStudy().getUserid(); | 
|---|
|  |  |  | TGame game = gameService.lambdaQuery().eq(TGame::getId, completeStudy.getGameId()).eq(TGame::getDisabled, 0).one(); | 
|---|
|  |  |  | Integer userid = loginUserStudy.getUserid(); | 
|---|
|  |  |  | TGame game = gameService.lambdaQuery().eq(TGame::getId, completeStudy.getGameId()) | 
|---|
|  |  |  | .eq(TGame::getDisabled, 0).one(); | 
|---|
|  |  |  | if (null == game) { | 
|---|
|  |  |  | throw new GlobalException("游戏信息异常!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 积分明细 | 
|---|
|  |  |  | List<TIntegralRecord> integralRecordList = integralRecordService.lambdaQuery().eq(TIntegralRecord::getUserId, userid) | 
|---|
|  |  |  | .eq(TIntegralRecord::getGameId, game.getId()).eq(TIntegralRecord::getDisabled, 0).list(); | 
|---|
|  |  |  | Integer difficulty = completeStudy.getDifficulty(); | 
|---|
|  |  |  | List<TIntegralRecord> integralRecordList = integralRecordService.lambdaQuery() | 
|---|
|  |  |  | .eq(TIntegralRecord::getUserId, userid) | 
|---|
|  |  |  | .eq(TIntegralRecord::getGameId, game.getId()) | 
|---|
|  |  |  | .eq(TIntegralRecord::getDisabled, 0) | 
|---|
|  |  |  | .eq(TIntegralRecord::getGameDifficulty, difficulty).list(); | 
|---|
|  |  |  | // 本次游戏总共能获取的积分数量 | 
|---|
|  |  |  | Integer integral; | 
|---|
|  |  |  | Integer item = null; | 
|---|
|  |  |  | if (completeStudy.getGameName().equals(Constants.HEARING)) { | 
|---|
|  |  |  | // 本次游戏总积分 | 
|---|
|  |  |  | integral = Integer.parseInt(game.getIntegral().split(",")[completeStudy.getDifficulty()]); | 
|---|
|  |  |  | integral = Integer.parseInt(game.getIntegral().split(",")[difficulty]); | 
|---|
|  |  |  | item = completeStudy.getDifficulty(); | 
|---|
|  |  |  | } else if (completeStudy.getGameName().equals(Constants.MEMORY)) { | 
|---|
|  |  |  | integralRecordList = integralRecordService.lambdaQuery() | 
|---|
|  |  |  | .eq(TIntegralRecord::getUserId, userid) | 
|---|
|  |  |  | .eq(TIntegralRecord::getGameId, game.getId()) | 
|---|
|  |  |  | .eq(TIntegralRecord::getDisabled, 0) | 
|---|
|  |  |  | .last("and gameDifficulty is null").list(); | 
|---|
|  |  |  | integral = game.getAnswerIntegral(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new GlobalException("该次游戏积分计算异常!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int gameAvailableIntegral = integral * (completeStudy.getAccuracy() / 100); | 
|---|
|  |  |  | Integer accuracy = completeStudy.getAccuracy(); | 
|---|
|  |  |  | if (accuracy >= 100) { | 
|---|
|  |  |  | accuracy = 100; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int gameAvailableIntegral = (int) (integral * ((double) completeStudy.getAccuracy() / 100)); | 
|---|
|  |  |  | Integer availableIntegral = gameService.countIntegral(userid, game, completeStudy, gameAvailableIntegral, integralRecordList); | 
|---|
|  |  |  | // 游戏测试记录 | 
|---|
|  |  |  | Boolean add = gameRecordService.add(completeStudy); | 
|---|
|  |  |  | // 可获得积分不为null时,才添加积分明细记录 | 
|---|
|  |  |  | if (null != availableIntegral) { | 
|---|
|  |  |  | add = add && integralRecordService.add(String.valueOf(availableIntegral), Constants.COMPLETE_GAME, completeStudy.getGameId(), null); | 
|---|
|  |  |  | if (null != availableIntegral && !Constants.ZERO.equals(availableIntegral)) { | 
|---|
|  |  |  | add = add && integralRecordService.add(String.valueOf(availableIntegral), | 
|---|
|  |  |  | Constants.COMPLETE_GAME, completeStudy.getGameId(), null, item, null); | 
|---|
|  |  |  | // 用户账户添加积分 | 
|---|
|  |  |  | TUser user = userService.getById(userid); | 
|---|
|  |  |  | user.setIntegral(user.getIntegral() + availableIntegral); | 
|---|
|  |  |  | add = add && userService.updateById(user); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(add); | 
|---|
|  |  |  | // 学习时长更新 | 
|---|
|  |  |  | TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userid) | 
|---|
|  |  |  | .eq(TUserStudy::getDisabled, 0).one(); | 
|---|
|  |  |  | if (null == userStudy) { | 
|---|
|  |  |  | userStudy = createUserStudy(userid); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 学习时长 | 
|---|
|  |  |  | userStudy.setTotalStudy(userStudy.getTotalStudy() + completeStudy.getUseTime()); | 
|---|
|  |  |  | userStudy.setTodayStudy(userStudy.getTodayStudy() + completeStudy.getUseTime()); | 
|---|
|  |  |  | userStudy.setWeekStudy(userStudy.getWeekStudy() + completeStudy.getUseTime()); | 
|---|
|  |  |  | userStudy.setMonthStudy(userStudy.getMonthStudy() + completeStudy.getUseTime()); | 
|---|
|  |  |  | userStudyService.updateById(userStudy); | 
|---|
|  |  |  | // 学习配置列表 | 
|---|
|  |  |  | List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0) | 
|---|
|  |  |  | .orderByAsc(TStudy::getWeek).list(); | 
|---|
|  |  |  | if (studyList.isEmpty()) { | 
|---|
|  |  |  | throw new GlobalException("学习配置列表未配置或数据失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 超级记忆逻辑 | 
|---|
|  |  |  | if (Constants.MEMORY.equals(completeStudy.getGameName())) { | 
|---|
|  |  |  | // 超级记忆正确率达到通关率标准,才能进入下一周目学习 | 
|---|
|  |  |  | // 校验是否通关超级听力与超级记忆,通关则学习记录更新为下一周目 | 
|---|
|  |  |  | userStudyService.checkRate(game, userid, completeStudy, studyList); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 超级听力需根据正确率判断是否允许进入下一难度 | 
|---|
|  |  |  | userStudyService.gameHearing(game, userid, completeStudy, studyList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(availableIntegral); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private TUserStudy createUserStudy(Integer userid) { | 
|---|
|  |  |  | TUserStudy userStudy = new TUserStudy(); | 
|---|
|  |  |  | userStudy.setUserId(userid); | 
|---|
|  |  |  | // 学习周目 | 
|---|
|  |  |  | TStudy tStudy = studyService.lambdaQuery().eq(TStudy::getQuarter, Constants.ONE) | 
|---|
|  |  |  | .orderByAsc(TStudy::getWeek).last("limit 1").one(); | 
|---|
|  |  |  | userStudy.setWeek(tStudy.getWeek()); | 
|---|
|  |  |  | userStudy.setDay(Constants.ONE); | 
|---|
|  |  |  | userStudy.setTotalStudy(Constants.ZERO); | 
|---|
|  |  |  | userStudy.setTodayStudy(Constants.ZERO); | 
|---|
|  |  |  | userStudy.setWeekStudy(Constants.ZERO); | 
|---|
|  |  |  | userStudy.setMonthStudy(Constants.ZERO); | 
|---|
|  |  |  | userStudy.setListen(Constants.BURDEN_ONE); | 
|---|
|  |  |  | userStudy.setLook(Constants.BURDEN_ONE); | 
|---|
|  |  |  | userStudy.setInduction(Constants.BURDEN_ONE); | 
|---|
|  |  |  | userStudy.setAnswer(Constants.BURDEN_ONE); | 
|---|
|  |  |  | userStudy.setPair(Constants.BURDEN_ONE); | 
|---|
|  |  |  | userStudyService.save(userStudy); | 
|---|
|  |  |  | return userStudy; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private List<String> getSubjectId(Integer week) { | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<StudyStoryListenResultVO> lookPictureDbu(@RequestParam Integer quarter, @RequestParam Integer week) { | 
|---|
|  |  |  | // 看图配音信息 | 
|---|
|  |  |  | TStoryListen listen = gettStoryListen(quarter, week); | 
|---|
|  |  |  | List<String> list = Arrays.asList(listen.getLookStory().split(",")); | 
|---|
|  |  |  | List<TStory> subjectList; | 
|---|
|  |  |  | if (!list.isEmpty()) { | 
|---|
|  |  |  | subjectList = storyService.lambdaQuery().in(TStory::getId, list).eq(TStory::getDisabled, 0).list(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | subjectList = new ArrayList<>(); | 
|---|
|  |  |  | TStoryListen storyListen = storyListenService.storyDetail(quarter, week); | 
|---|
|  |  |  | if (storyListen==null){ | 
|---|
|  |  |  | return R.fail("当前未配置看图配音信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(new StudyStoryListenResultVO(listen, subjectList)); | 
|---|
|  |  |  | // 题组信息 | 
|---|
|  |  |  | StudyStoryVO studyStory = new StudyStoryVO(); | 
|---|
|  |  |  | studyStory.setId(storyListen.getId()); | 
|---|
|  |  |  | studyStory.setIntegral(storyListen.getLookIntegral()); | 
|---|
|  |  |  | // 故事语音及图片信息 | 
|---|
|  |  |  | List<TStory> list = storyService.lookPictureDbu(storyListen, 0); | 
|---|
|  |  |  | return R.ok(new StudyStoryListenResultVO(studyStory, list)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(value = "所属周目", name = "week", dataType = "Integer", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<StudyStoryListenResultVO> frameworkMemory(@RequestParam Integer quarter, @RequestParam Integer week) { | 
|---|
|  |  |  | TStoryListen listen = gettStoryListen(quarter, week); | 
|---|
|  |  |  | // 获取对应图片语音 | 
|---|
|  |  |  | List<String> list = Arrays.asList(listen.getStory().split(",")); | 
|---|
|  |  |  | List<TStory> subjectList; | 
|---|
|  |  |  | if (!list.isEmpty()) { | 
|---|
|  |  |  | subjectList = storyService.lambdaQuery().in(TStory::getId, list).eq(TStory::getDisabled, 0).list(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | subjectList = new ArrayList<>(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(new StudyStoryListenResultVO(listen, subjectList)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private TStoryListen gettStoryListen(Integer quarter, Integer week) { | 
|---|
|  |  |  | // 看图配音信息 | 
|---|
|  |  |  | List<TStoryListen> storyListenList = storyListenService.storyDetail(quarter, week); | 
|---|
|  |  |  | if (storyListenList.isEmpty()) { | 
|---|
|  |  |  | throw new GlobalException("当前季度该周目下未配置故事信息!"); | 
|---|
|  |  |  | TStoryListen storyListen = storyListenService.storyDetail(quarter, week); | 
|---|
|  |  |  | if (storyListen==null){ | 
|---|
|  |  |  | return R.fail("当前未配置框架记忆信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 获取对应图片语音 | 
|---|
|  |  |  | TStoryListen listen; | 
|---|
|  |  |  | if (storyListenList.size() == Constants.ONE) { | 
|---|
|  |  |  | listen = storyListenList.get(Constants.ZERO); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 随机获取一组题 | 
|---|
|  |  |  | Random rand = new Random(); | 
|---|
|  |  |  | listen = storyListenList.get(rand.nextInt(storyListenList.size())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return listen; | 
|---|
|  |  |  | // 题组信息 | 
|---|
|  |  |  | StudyStoryVO studyStory = new StudyStoryVO(); | 
|---|
|  |  |  | studyStory.setId(storyListen.getId()); | 
|---|
|  |  |  | studyStory.setIntegral(storyListen.getIntegral()); | 
|---|
|  |  |  | // 故事语音及图片信息 | 
|---|
|  |  |  | List<TStory> list = storyService.lookPictureDbu(storyListen, 1); | 
|---|
|  |  |  | return R.ok(new StudyStoryListenResultVO(studyStory, list)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @GetMapping("/completeStory") | 
|---|
|  |  |  | @ApiOperation(value = "完成故事学习", tags = {"学习端-听-自主故事"}) | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(value = "积分数量", name = "integral", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "故事id", name = "storyId", dataType = "Integer", required = true) | 
|---|
|  |  |  | @ApiImplicitParam(value = "故事id", name = "storyId", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "类型(1:看图配音;2:超级记忆)", name = "type", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "正确率", name = "accuracy", dataType = "Integer"), | 
|---|
|  |  |  | @ApiImplicitParam(value = "学习时长(秒)", name = "studyTime", dataType = "Integer", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<Boolean> completeStory(@RequestParam Integer integral, @RequestParam Integer storyId) { | 
|---|
|  |  |  | TStoryListen storyListen = storyListenService.lambdaQuery().eq(TStoryListen::getId, storyId).eq(TStoryListen::getDisabled, 0).one(); | 
|---|
|  |  |  | public R<Integer> completeStory(@RequestParam Integer storyId, @RequestParam Integer type, | 
|---|
|  |  |  | Integer accuracy, @RequestParam Integer studyTime) { | 
|---|
|  |  |  | TStoryListen storyListen = storyListenService.lambdaQuery().eq(TStoryListen::getId, storyId) | 
|---|
|  |  |  | .eq(TStoryListen::getDisabled, 0).one(); | 
|---|
|  |  |  | if (null == storyListen) { | 
|---|
|  |  |  | throw new GlobalException("当前故事学习失败,故事信息异常,请重试!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 用户信息 | 
|---|
|  |  |  | Integer userId = tokenService.getLoginUserStudy().getUserid(); | 
|---|
|  |  |  | // 故事只有首次才能获取积分 | 
|---|
|  |  |  | TIntegralRecord integralRecord = integralRecordService.lambdaQuery().eq(TIntegralRecord::getUserId, userId) | 
|---|
|  |  |  | .eq(TIntegralRecord::getStoryId, storyId).eq(TIntegralRecord::getDisabled, 0).one(); | 
|---|
|  |  |  | Boolean result = true; | 
|---|
|  |  |  | if (null == integralRecord) { | 
|---|
|  |  |  | // 添加积分明细记录 | 
|---|
|  |  |  | result = integralRecordService.add(String.valueOf(integral), Constants.COMPLETE_STORY, null, storyId); | 
|---|
|  |  |  | TUser user = userService.lambdaQuery().eq(TUser::getId, userId).one(); | 
|---|
|  |  |  | // 添加积分 | 
|---|
|  |  |  | user.setIntegral(user.getIntegral() + integral); | 
|---|
|  |  |  | result = result && userService.updateById(user); | 
|---|
|  |  |  | LoginUserParent loginUserStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == loginUserStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(result); | 
|---|
|  |  |  | // 用户信息 | 
|---|
|  |  |  | Integer userId = loginUserStudy.getUserid(); | 
|---|
|  |  |  | Boolean result = true; | 
|---|
|  |  |  | // 学习时长更新 | 
|---|
|  |  |  | TStudy study = studyService.lambdaQuery().eq(TStudy::getId, storyListen.getStudyId()) | 
|---|
|  |  |  | .eq(TStudy::getDisabled, 0).one(); | 
|---|
|  |  |  | TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId) | 
|---|
|  |  |  | .eq(TUserStudy::getDisabled, 0).one(); | 
|---|
|  |  |  | if (null == userStudy) { | 
|---|
|  |  |  | userStudy = createUserStudy(userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | userStudy.setTotalStudy(userStudy.getTotalStudy() + studyTime); | 
|---|
|  |  |  | userStudy.setTodayStudy(userStudy.getTodayStudy() + studyTime); | 
|---|
|  |  |  | userStudy.setWeekStudy(userStudy.getWeekStudy() + studyTime); | 
|---|
|  |  |  | userStudy.setMonthStudy(userStudy.getMonthStudy() + studyTime); | 
|---|
|  |  |  | boolean update = userStudyService.updateById(userStudy); | 
|---|
|  |  |  | if (!update) { | 
|---|
|  |  |  | throw new GlobalException("学习时长更新失败!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 根据故事类型不同,逻辑处理 | 
|---|
|  |  |  | int sum = 0; | 
|---|
|  |  |  | if (Constants.ONE.equals(type)) { | 
|---|
|  |  |  | if (null == accuracy) { | 
|---|
|  |  |  | throw new GlobalException("自主故事-看图配音正确率异常!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (accuracy >= 100) { | 
|---|
|  |  |  | accuracy = 100; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 看图配音模式,也需要根据游戏正确率计算积分 | 
|---|
|  |  |  | double d = (double) accuracy / 100; | 
|---|
|  |  |  | int integral = (int) (storyListen.getLookIntegral() * d); | 
|---|
|  |  |  | int obtainedIntegral; | 
|---|
|  |  |  | // 看图配音已获取积分数量 | 
|---|
|  |  |  | List<TUserStudyRecord> list = studyRecordService.lambdaQuery() | 
|---|
|  |  |  | .eq(TUserStudyRecord::getStoryId, storyId) | 
|---|
|  |  |  | .eq(TUserStudyRecord::getType, 1) | 
|---|
|  |  |  | .eq(TUserStudyRecord::getQuarter, study.getQuarter()) | 
|---|
|  |  |  | .eq(TUserStudyRecord::getWeek, storyListen.getWeek()) | 
|---|
|  |  |  | .eq(TUserStudyRecord::getUserId, userId).list(); | 
|---|
|  |  |  | if (list.isEmpty()) { | 
|---|
|  |  |  | obtainedIntegral = 0; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | obtainedIntegral = list.stream().map(TUserStudyRecord::getObtainedIntegral) | 
|---|
|  |  |  | .mapToInt(Integer::intValue).sum(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 可获得积分计算 | 
|---|
|  |  |  | int i = integral - obtainedIntegral; | 
|---|
|  |  |  | if (i > 0) { | 
|---|
|  |  |  | TUserStudyRecord data = new TUserStudyRecord(); | 
|---|
|  |  |  | data.setUserId(userId); | 
|---|
|  |  |  | data.setObtainedIntegral(i); | 
|---|
|  |  |  | data.setType(Constants.ONE); | 
|---|
|  |  |  | data.setStoryId(storyId); | 
|---|
|  |  |  | data.setQuarter(study.getQuarter()); | 
|---|
|  |  |  | data.setWeek(storyListen.getWeek()); | 
|---|
|  |  |  | result = studyRecordService.save(data); | 
|---|
|  |  |  | sum = i; | 
|---|
|  |  |  | // 添加积分明细记录 | 
|---|
|  |  |  | result = integralRecordService.add(String.valueOf(sum), | 
|---|
|  |  |  | Constants.COMPLETE_STORY, null, storyId, null, Constants.ZERO); | 
|---|
|  |  |  | TUser user = userService.lambdaQuery().eq(TUser::getId, userId).one(); | 
|---|
|  |  |  | // 添加积分 | 
|---|
|  |  |  | user.setIntegral(user.getIntegral() + sum); | 
|---|
|  |  |  | result = result && userService.updateById(user); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 超级记忆只有首次才能获取积分 | 
|---|
|  |  |  | TIntegralRecord integralRecord = integralRecordService.lambdaQuery() | 
|---|
|  |  |  | .eq(TIntegralRecord::getUserId, userId) | 
|---|
|  |  |  | .eq(TIntegralRecord::getStoryId, storyId) | 
|---|
|  |  |  | .eq(TIntegralRecord::getDisabled, 0) | 
|---|
|  |  |  | .eq(TIntegralRecord::getStoryType, Constants.ONE) | 
|---|
|  |  |  | .one(); | 
|---|
|  |  |  | if (null == integralRecord) { | 
|---|
|  |  |  | // 添加积分明细记录 | 
|---|
|  |  |  | result = integralRecordService.add(String.valueOf(storyListen.getIntegral()), | 
|---|
|  |  |  | Constants.COMPLETE_STORY, null, storyId, null, Constants.ONE); | 
|---|
|  |  |  | TUser user = userService.lambdaQuery().eq(TUser::getId, userId).one(); | 
|---|
|  |  |  | // 添加积分 | 
|---|
|  |  |  | user.setIntegral(user.getIntegral() + storyListen.getIntegral()); | 
|---|
|  |  |  | result = result && userService.updateById(user); | 
|---|
|  |  |  | sum = storyListen.getIntegral(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(sum); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/studyRecord") | 
|---|
|  |  |  | @ApiOperation(value = "个人中心-学习记录", tags = {"学习端-个人中心"}) | 
|---|
|  |  |  | public R<StudyRecordResultVO> studyRecord() { | 
|---|
|  |  |  | Integer userId = tokenService.getLoginUserStudy().getUserid(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LoginUserParent userStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | if (null == userStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer userId = userStudy.getUserid(); | 
|---|
|  |  |  | // 学习记录 | 
|---|
|  |  |  | TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId) | 
|---|
|  |  |  | .eq(TUserStudy::getDisabled, 0).one(); | 
|---|
|  |  |  | // 游戏测试成绩 | 
|---|
|  |  |  | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userId) | 
|---|
|  |  |  | .eq(TGameRecord::getDisabled, 0).list(); | 
|---|
|  |  |  | // 总时长还需计算上游戏测试成绩时长 | 
|---|
|  |  |  | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery() | 
|---|
|  |  |  | .eq(TGameRecord::getUserId, userId) | 
|---|
|  |  |  | .eq(TGameRecord::getDisabled, 0) | 
|---|
|  |  |  | .orderByDesc(TGameRecord::getCreateTime) | 
|---|
|  |  |  | .list(); | 
|---|
|  |  |  | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm"); | 
|---|
|  |  |  | if (null != studyRecord) { | 
|---|
|  |  |  | // 学习时长格式转换 | 
|---|
|  |  |  | Integer todayStudy = studyRecord.getTodayStudy(); | 
|---|
|  |  |  | studyRecord.setTodayStudy(Math.round((float) todayStudy / 3600)); | 
|---|
|  |  |  | Integer weekStudy = studyRecord.getWeekStudy(); | 
|---|
|  |  |  | studyRecord.setWeekStudy(Math.round((float) weekStudy / 3600)); | 
|---|
|  |  |  | Integer monthStudy = studyRecord.getMonthStudy(); | 
|---|
|  |  |  | studyRecord.setMonthStudy(Math.round((float) monthStudy / 3600)); | 
|---|
|  |  |  | // 游戏总时长 | 
|---|
|  |  |  | int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum(); | 
|---|
|  |  |  | Integer totalStudy = studyRecord.getTotalStudy(); | 
|---|
|  |  |  | studyRecord.setTotalStudy(Math.round((float) (totalStudy) / 3600)); | 
|---|
|  |  |  | for (TGameRecord tGameRecord : gameRecordList) { | 
|---|
|  |  |  | tGameRecord.setTime(simpleDateFormat.format(tGameRecord.getCreateTime())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 剩余周目 | 
|---|
|  |  |  | List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0) | 
|---|
|  |  |  | .eq(TStudy::getType, Constants.ONE) | 
|---|
|  |  |  | .orderByAsc(TStudy::getWeek).list(); | 
|---|
|  |  |  | int size = studyService.residueWeek(studyRecord, studyList); | 
|---|
|  |  |  | studyRecord.setSurplus(size); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(new StudyRecordResultVO(studyRecord, gameRecordList)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "游戏测试成绩", tags = {"家长端-游戏测试成绩"}) | 
|---|
|  |  |  | public R<StudyRecordResultVO> record() { | 
|---|
|  |  |  | LoginUserParent loginUser1 = tokenService.getLoginUser1(); | 
|---|
|  |  |  | System.err.println("用户登录信息:" + loginUser1); | 
|---|
|  |  |  | if (loginUser1 == null) { | 
|---|
|  |  |  | return R.tokenError("登陆失效,请重新登录"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 学习记录 | 
|---|
|  |  |  | TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId) | 
|---|
|  |  |  | .eq(TUserStudy::getDisabled, 0).one(); | 
|---|
|  |  |  | // 总时长还需计算上游戏测试成绩时长 | 
|---|
|  |  |  | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery() | 
|---|
|  |  |  | .eq(TGameRecord::getUserId, userId) | 
|---|
|  |  |  | .eq(TGameRecord::getDisabled, 0) | 
|---|
|  |  |  | .orderByDesc(TGameRecord::getCreateTime) | 
|---|
|  |  |  | .list(); | 
|---|
|  |  |  | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm"); | 
|---|
|  |  |  | if (null != studyRecord) { | 
|---|
|  |  |  | // 学习时长格式转换 | 
|---|
|  |  |  | Integer todayStudy = studyRecord.getTodayStudy(); | 
|---|
|  |  |  | studyRecord.setTodayStudy(Math.round((float) todayStudy / 3600)); | 
|---|
|  |  |  | Integer weekStudy = studyRecord.getWeekStudy(); | 
|---|
|  |  |  | studyRecord.setWeekStudy(Math.round((float) weekStudy / 3600)); | 
|---|
|  |  |  | Integer monthStudy = studyRecord.getMonthStudy(); | 
|---|
|  |  |  | studyRecord.setMonthStudy(Math.round((float) monthStudy / 3600)); | 
|---|
|  |  |  | // 游戏总时长 | 
|---|
|  |  |  | int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum(); | 
|---|
|  |  |  | for (TGameRecord tGameRecord : gameRecordList) { | 
|---|
|  |  |  | tGameRecord.setTime(simpleDateFormat.format(tGameRecord.getCreateTime())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer totalStudy = studyRecord.getTotalStudy(); | 
|---|
|  |  |  | studyRecord.setTotalStudy(Math.round((float) (totalStudy) / 3600)); | 
|---|
|  |  |  | // 剩余周目 | 
|---|
|  |  |  | List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0) | 
|---|
|  |  |  | .eq(TStudy::getType, Constants.ONE) | 
|---|
|  |  |  | .orderByAsc(TStudy::getWeek).list(); | 
|---|
|  |  |  | int size = studyService.residueWeek(studyRecord, studyList); | 
|---|
|  |  |  | studyRecord.setSurplus(size); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(new StudyRecordResultVO(studyRecord, gameRecordList)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/recordManagement/{id}") | 
|---|
|  |  |  | @ApiOperation(value = "游戏测试成绩", tags = {"管理后台-查看用户详情"}) | 
|---|
|  |  |  | public R<StudyRecordResultVO> recordManagement(@PathVariable("id") Integer id) { | 
|---|
|  |  |  | // 学习记录 | 
|---|
|  |  |  | TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, id) | 
|---|
|  |  |  | .eq(TUserStudy::getDisabled, 0).one(); | 
|---|
|  |  |  | // 查询剩余周目 | 
|---|
|  |  |  | if (studyRecord != null) { | 
|---|
|  |  |  | 
|---|
|  |  |  | TUserStudy tUserStudy = new TUserStudy(); | 
|---|
|  |  |  | tUserStudy.setSurplus(studyService.list(new QueryWrapper<TStudy>() | 
|---|
|  |  |  | .eq("type", 1)).size()); | 
|---|
|  |  |  | tUserStudy.setTodayStudy(Constants.ZERO); | 
|---|
|  |  |  | tUserStudy.setTotalStudy(Constants.ZERO); | 
|---|
|  |  |  | tUserStudy.setWeekStudy(Constants.ZERO); | 
|---|
|  |  |  | tUserStudy.setMonthStudy(Constants.ZERO); | 
|---|
|  |  |  | studyRecord = tUserStudy; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 游戏测试成绩 | 
|---|
|  |  |  | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userId) | 
|---|
|  |  |  | // 学习时长格式转换 | 
|---|
|  |  |  | Integer todayStudy = studyRecord.getTodayStudy(); | 
|---|
|  |  |  | studyRecord.setTodayStudy(Math.round((float) todayStudy / 3600)); | 
|---|
|  |  |  | Integer weekStudy = studyRecord.getWeekStudy(); | 
|---|
|  |  |  | studyRecord.setWeekStudy(Math.round((float) weekStudy / 3600)); | 
|---|
|  |  |  | Integer monthStudy = studyRecord.getMonthStudy(); | 
|---|
|  |  |  | studyRecord.setMonthStudy(Math.round((float) monthStudy / 3600)); | 
|---|
|  |  |  | // 总时长还需计算上游戏测试成绩时长 | 
|---|
|  |  |  | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, id) | 
|---|
|  |  |  | .eq(TGameRecord::getDisabled, 0).list(); | 
|---|
|  |  |  | return R.ok(new StudyRecordResultVO(studyRecord, gameRecordList)); | 
|---|
|  |  |  | int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum(); | 
|---|
|  |  |  | Integer totalStudy = studyRecord.getTotalStudy(); | 
|---|
|  |  |  | studyRecord.setTotalStudy(Math.round((float) (totalStudy) / 3600)); | 
|---|
|  |  |  | StudyRecordResultVO studyRecordResultVO = new StudyRecordResultVO(studyRecord, gameRecordList); | 
|---|
|  |  |  | return R.ok(studyRecordResultVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/getIntegral") | 
|---|
|  |  |  | @ApiOperation(value = "获取剩余积分", tags = {"家长端-获取剩余积分"}) | 
|---|
|  |  |  | public R<Integer> getIntegral() { | 
|---|
|  |  |  | if (tokenService.getLoginUser1() == null) { | 
|---|
|  |  |  | return R.tokenError("登录失效"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer userId = tokenService.getLoginUser1().getUserid(); | 
|---|
|  |  |  | return R.ok(userService.getById(userId).getIntegral()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | if (tokenService.getLoginUserStudy() == null) { | 
|---|
|  |  |  | return R.tokenError("登录失效"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(integralRecordService.integralDetail(new Page<>(pageNum, pageSize), tokenService.getLoginUserStudy().getUserid(), time)); | 
|---|
|  |  |  | IPage<TIntegralRecord> page = integralRecordService.integralDetail(new Page<>(pageNum, pageSize), | 
|---|
|  |  |  | tokenService.getLoginUserStudy().getUserid(), time); | 
|---|
|  |  |  | for (TIntegralRecord record : page.getRecords()) { | 
|---|
|  |  |  | if (!record.getIntegral().startsWith("-")) { | 
|---|
|  |  |  | record.setIntegral("+" + record.getIntegral()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(page); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/integralDetailParent") | 
|---|
|  |  |  | @ApiOperation(value = "个人中心-积分明细", tags = {"家长端"}) | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(value = "查询时间 格式yyyy-MM", name = "time", dataType = "Integer"), | 
|---|
|  |  |  | @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "每页显示条数", name = "pageSize", dataType = "Integer", required = true) | 
|---|
|  |  |  | @ApiImplicitParam(value = "查询时间 格式yyyy-MM", name = "time"), | 
|---|
|  |  |  | @ApiImplicitParam(value = "页码", name = "pageNum", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "每页显示条数", name = "pageSize", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<IPage<TIntegralRecord>> integralDetailParent(String time, | 
|---|
|  |  |  | @RequestParam("pageNum") Integer pageNum, | 
|---|
|  |  |  | 
|---|
|  |  |  | if (tokenService.getLoginUser1() == null) { | 
|---|
|  |  |  | return R.tokenError("登录失效"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(integralRecordService.integralDetail(new Page<>(pageNum, pageSize), tokenService.getLoginUser1().getUserid(), time)); | 
|---|
|  |  |  | IPage<TIntegralRecord> page = integralRecordService.integralDetail(new Page<>(pageNum, pageSize), | 
|---|
|  |  |  | tokenService.getLoginUser1().getUserid(), time); | 
|---|
|  |  |  | for (TIntegralRecord record : page.getRecords()) { | 
|---|
|  |  |  | if (!record.getIntegral().startsWith("-")) { | 
|---|
|  |  |  | record.setIntegral("+" + record.getIntegral()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(page); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | public R<Boolean> addIntegralDetail(@RequestParam("integral") String integral, @RequestParam("method") String method) { | 
|---|
|  |  |  | // 当前登录用户 | 
|---|
|  |  |  | LoginUserParent userStudy = tokenService.getLoginUserStudy(); | 
|---|
|  |  |  | // 生成积分明细信息 | 
|---|
|  |  |  | TIntegralRecord integralRecord = new TIntegralRecord(); | 
|---|
|  |  |  | integralRecord.setIntegral(integral); | 
|---|
|  |  |  | integralRecord.setMethod(method); | 
|---|
|  |  |  | integralRecord.setUserId(userStudy.getUserid()); | 
|---|
|  |  |  | integralRecord.setDisabled(Boolean.FALSE); | 
|---|
|  |  |  | integralRecord.setCreateBy(userStudy.getPhone()); | 
|---|
|  |  |  | integralRecord.setCreateTime(new Date()); | 
|---|
|  |  |  | integralRecord.setUpdateBy(userStudy.getPhone()); | 
|---|
|  |  |  | integralRecord.setUpdateTime(new Date()); | 
|---|
|  |  |  | return R.ok(integralRecordService.save(integralRecord)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/addIntegralDetailParent") | 
|---|
|  |  |  | //    @ApiOperation(value = "添加-积分明细", tags = {"添加-积分明细"}) | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(value = "积分数量", name = "integral", dataType = "Integer", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(value = "变动源(完成学习、完成游戏...)", name = "method", dataType = "String", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<Boolean> addIntegralDetailParent(@RequestParam("integral") String integral, @RequestParam("method") String method) { | 
|---|
|  |  |  | // 当前登录用户 | 
|---|
|  |  |  | LoginUserParent userStudy = tokenService.getLoginUser1(); | 
|---|
|  |  |  | // 生成积分明细信息 | 
|---|
|  |  |  | TIntegralRecord integralRecord = new TIntegralRecord(); | 
|---|
|  |  |  | integralRecord.setIntegral(integral); | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(userService.updateById(user)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/exchangeIntegralParent") | 
|---|
|  |  |  | //    @ApiOperation(value = "用户积分变动", tags = {"用户积分变动"}) | 
|---|
|  |  |  | public R<Boolean> exchangeIntegralParent(@RequestParam("integral") Integer integral, @RequestParam("method") String method) { | 
|---|
|  |  |  | if (tokenService.getLoginUser1() == null) { | 
|---|
|  |  |  | return R.tokenError("登录失效"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | TUser user = userService.getById(tokenService.getLoginUser1().getUserid()); | 
|---|
|  |  |  | if (Constants.BURDEN.equals(method)) { | 
|---|
|  |  |  | user.setIntegral(user.getIntegral() - integral); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | user.setIntegral(user.getIntegral() + integral); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(userService.updateById(user)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/exchangeIntegral1") | 
|---|
|  |  |  | //    @ApiOperation(value = "用户积分变动", tags = {"用户积分变动"}) | 
|---|
|  |  |  | public R<Boolean> exchangeIntegral1(@RequestParam("integral") Integer integral, @RequestParam("method") String method) { | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(userService.updateById(user)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/lookVideo") | 
|---|
|  |  |  | //    @ApiOperation(value = "用户积分变动", tags = {"用户积分变动"}) | 
|---|
|  |  |  | public R<Boolean> lookVideo() { | 
|---|
|  |  |  | boolean update = userService.update(new LambdaUpdateWrapper<TUser>().set(TUser::getLookVideo, 0)); | 
|---|
|  |  |  | return R.ok(update); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 设置题组类型 常规 示例 | 
|---|
|  |  |  | * @param dto | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("/setStudyType") | 
|---|
|  |  |  | public R<Object> setStudyType(@RequestBody SetStudyTypeDto dto){ | 
|---|
|  |  |  | TStudyListen studyListen = studyListenService.getById(dto.getId()); | 
|---|
|  |  |  | studyListen.setType(dto.getType()); | 
|---|
|  |  |  | studyListen.setSubject(dto.getSubject()); | 
|---|
|  |  |  | return R.ok(studyListenService.updateById(studyListen)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|