package com.ruoyi.study.service.impl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ruoyi.common.core.constant.Constants;
|
import com.ruoyi.common.core.exception.GlobalException;
|
import com.ruoyi.study.domain.*;
|
import com.ruoyi.study.dto.StudyWeekDTO;
|
import com.ruoyi.study.mapper.TStudyMapper;
|
import com.ruoyi.study.service.*;
|
import com.ruoyi.study.vo.*;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 学习类型 听 周目配置 服务实现类
|
* </p>
|
*
|
* @author 无关风月
|
* @since 2024-04-26
|
*/
|
@Service
|
public class TStudyServiceImpl extends ServiceImpl<TStudyMapper, TStudy> implements ITStudyService {
|
|
@Resource
|
private ITUserStudyService userStudyService;
|
@Resource
|
private ITSubjectService subjectService;
|
@Resource
|
private ITGameRecordService gameRecordService;
|
@Resource
|
private ITStudyAnswerService studyAnswerService;
|
@Resource
|
private ITStudyInductionService studyInductionService;
|
@Resource
|
private ITStudyLookService studyLookService;
|
@Resource
|
private ITStudyListenService studyListenService;
|
@Resource
|
private ITStudyPairService studyPairService;
|
@Resource
|
private ITGameService gameService;
|
@Resource
|
private ITStoryListenService storyListenService;
|
|
private final static Map<Integer, Integer> GAME_DIFFICULTY_MAP = new HashMap<>();
|
|
static {
|
GAME_DIFFICULTY_MAP.put(1, 0);
|
GAME_DIFFICULTY_MAP.put(2, 1);
|
}
|
|
@Override
|
public List<StudyWeekDTO> weekList(Integer type, Integer quarter, Integer userId) {
|
List<StudyWeekDTO> result = new ArrayList<>();
|
// 根据季度和type查询学习配置
|
List<TStudy> study = lambdaQuery().eq(TStudy::getQuarter, quarter).eq(TStudy::getType, type)
|
.eq(TStudy::getDisabled, 0).orderByAsc(TStudy::getWeek).list();
|
for (TStudy item : study) {
|
Integer week = item.getWeek();
|
String title = item.getTitle();
|
Integer id = item.getId();
|
// 计算总积分
|
int total = 0;
|
List<Integer> dayList = new ArrayList<>();
|
// 有问有答
|
List<TStudyAnswer> answerList = studyAnswerService.lambdaQuery()
|
.eq(TStudyAnswer::getStudyId, id)
|
.eq(TStudyAnswer::getWeek, week)
|
.eq(TStudyAnswer::getDisabled, 0).list();
|
for (TStudyAnswer data : answerList) {
|
Integer day = data.getDay();
|
if (!dayList.contains(day)) {
|
total += data.getIntegral();
|
dayList.add(day);
|
}
|
}
|
dayList.clear();
|
// 归纳判断
|
List<TStudyInduction> inductionList = studyInductionService.lambdaQuery()
|
.eq(TStudyInduction::getStudyId, id)
|
.eq(TStudyInduction::getWeek, week)
|
.eq(TStudyInduction::getDisabled, 0).list();
|
for (TStudyInduction data : inductionList) {
|
Integer day = data.getDay();
|
if (!dayList.contains(day)) {
|
total += data.getIntegral();
|
dayList.add(day);
|
}
|
}
|
dayList.clear();
|
// 看图选音
|
List<TStudyLook> lookList = studyLookService.lambdaQuery()
|
.eq(TStudyLook::getStudyId, id)
|
.eq(TStudyLook::getWeek, week)
|
.eq(TStudyLook::getDisabled, 0).list();
|
for (TStudyLook data : lookList) {
|
Integer day = data.getDay();
|
if (!dayList.contains(day)) {
|
total += data.getIntegral();
|
dayList.add(day);
|
}
|
}
|
dayList.clear();
|
// 听音选图
|
List<TStudyListen> listenList = studyListenService.lambdaQuery()
|
.eq(TStudyListen::getStudyId, id)
|
.eq(TStudyListen::getWeek, week)
|
.eq(TStudyListen::getDisabled, 0).list();
|
for (TStudyListen data : listenList) {
|
Integer day = data.getDay();
|
if (!dayList.contains(day)) {
|
total += data.getIntegral();
|
dayList.add(day);
|
}
|
}
|
dayList.clear();
|
// 音图相配
|
List<TStudyPair> pairList = studyPairService.lambdaQuery()
|
.eq(TStudyPair::getStudyId, id)
|
.eq(TStudyPair::getWeek, week)
|
.eq(TStudyPair::getDisabled, 0).list();
|
for (TStudyPair data : pairList) {
|
Integer day = data.getDay();
|
if (!dayList.contains(day)) {
|
total += data.getIntegral();
|
dayList.add(day);
|
}
|
}
|
dayList.clear();
|
// 自主游戏
|
List<TGame> gameList = gameService.lambdaQuery().eq(TGame::getStudyId, id)
|
.eq(TGame::getDisabled, 0)
|
.eq(TGame::getWeek, week).list();
|
// 自主游戏-超级听力
|
List<String> gameIntegral = gameList.stream().map(TGame::getIntegral).collect(Collectors.toList());
|
for (String s : gameIntegral) {
|
List<String> list = Arrays.stream(s.split(",")).collect(Collectors.toList());
|
total += list.stream().mapToInt(Integer::parseInt).sum();
|
}
|
// 自主游戏-框架记忆
|
List<Integer> gameAnswerIntegral = gameList.stream().map(TGame::getAnswerIntegral).collect(Collectors.toList());
|
for (Integer integral : gameAnswerIntegral) {
|
if (null != integral) {
|
total += integral;
|
}
|
}
|
// 自主故事
|
List<TStoryListen> storyListenList = storyListenService.lambdaQuery()
|
.eq(TStoryListen::getStudyId, id)
|
.eq(TStoryListen::getWeek, week)
|
.eq(TStoryListen::getDisabled, 0).list();
|
// 自主故事 - 框架记忆
|
total += storyListenList.stream().map(TStoryListen::getIntegral).mapToInt(Integer::intValue).sum();
|
// 自主故事 - 看图配音
|
total += storyListenList.stream().map(TStoryListen::getLookIntegral).mapToInt(Integer::intValue).sum();
|
// 判断周目是否可以进入学习
|
Boolean canStudy = checkWeekCanStudy(userId, item);
|
result.add(new StudyWeekDTO(week, type, quarter, title, total, canStudy));
|
}
|
return result;
|
}
|
|
@Override
|
public TUserStudy studySchedule(TUserStudy studyRecord, Integer week) {
|
// 剩余周目
|
List<TStudy> studyList = this.lambdaQuery().eq(TStudy::getDisabled, 0)
|
.eq(TStudy::getType, Constants.ONE)
|
.orderByAsc(TStudy::getWeek).list();
|
// 已学习到的周目
|
Integer studyWeek = studyRecord.getWeek();
|
// 学习到的季度
|
Integer studyQuarter = 1;
|
// 当前所点击进入的周目所属季度
|
Integer currentQuarter = 1;
|
// 根据季度分组封装
|
Map<Integer, List<TStudy>> integerListMap = getIntegerListMap(studyList);
|
for (Map.Entry<Integer, List<TStudy>> map : integerListMap.entrySet()) {
|
List<TStudy> list = map.getValue();
|
for (TStudy study : list) {
|
Integer itemWeek = study.getWeek();
|
if (studyWeek.equals(itemWeek)) {
|
studyQuarter = map.getKey();
|
break;
|
}
|
}
|
for (TStudy study : list) {
|
Integer itemWeek = study.getWeek();
|
if (week.equals(itemWeek)) {
|
currentQuarter = map.getKey();
|
break;
|
}
|
}
|
}
|
// 已学习季度 大于当前周目所属季度,所有学习均已完成
|
if (studyQuarter > currentQuarter) {
|
studyRecord.setWeek(week);
|
studyRecord.setDay(Constants.SIX);
|
studyRecord.setListen(Constants.ONE_HUNDRED);
|
studyRecord.setLook(Constants.ONE_HUNDRED);
|
studyRecord.setInduction(Constants.ONE_HUNDRED);
|
studyRecord.setAnswer(Constants.ONE_HUNDRED);
|
studyRecord.setPair(Constants.ONE_HUNDRED);
|
studyRecord.setGameDifficulty(Constants.TWO);
|
studyRecord.setComputeSchedule(Constants.ONE_HUNDRED);
|
} else if (studyQuarter < currentQuarter) {
|
studyRecord.setWeek(week);
|
studyRecord.setDay(Constants.ONE);
|
studyRecord.setListen(Constants.BURDEN_ONE);
|
studyRecord.setLook(Constants.BURDEN_ONE);
|
studyRecord.setInduction(Constants.BURDEN_ONE);
|
studyRecord.setAnswer(Constants.BURDEN_ONE);
|
studyRecord.setPair(Constants.BURDEN_ONE);
|
studyRecord.setGameDifficulty(null);
|
studyRecord.setComputeSchedule(Constants.ZERO);
|
} else {
|
List<TStudy> tStudies = integerListMap.get(studyQuarter);
|
List<Integer> weekList = tStudies.stream().map(TStudy::getWeek).collect(Collectors.toList());
|
int i = weekList.indexOf(studyWeek);
|
int i1 = weekList.indexOf(week);
|
if (i > i1) {
|
studyRecord.setWeek(week);
|
studyRecord.setDay(Constants.SIX);
|
studyRecord.setListen(Constants.ONE_HUNDRED);
|
studyRecord.setLook(Constants.ONE_HUNDRED);
|
studyRecord.setInduction(Constants.ONE_HUNDRED);
|
studyRecord.setAnswer(Constants.ONE_HUNDRED);
|
studyRecord.setPair(Constants.ONE_HUNDRED);
|
studyRecord.setGameDifficulty(Constants.TWO);
|
studyRecord.setComputeSchedule(Constants.ONE_HUNDRED);
|
} else if (i < i1) {
|
studyRecord.setWeek(week);
|
studyRecord.setDay(Constants.ONE);
|
studyRecord.setListen(Constants.BURDEN_ONE);
|
studyRecord.setLook(Constants.BURDEN_ONE);
|
studyRecord.setInduction(Constants.BURDEN_ONE);
|
studyRecord.setAnswer(Constants.BURDEN_ONE);
|
studyRecord.setPair(Constants.BURDEN_ONE);
|
studyRecord.setGameDifficulty(null);
|
studyRecord.setComputeSchedule(Constants.ZERO);
|
}
|
}
|
return studyRecord;
|
}
|
|
/**
|
* @param userId 用户id
|
* @return 当前周目是否学习
|
*/
|
private Boolean checkWeekCanStudy(Integer userId, TStudy study) {
|
TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId)
|
.eq(TUserStudy::getDisabled, 0).one();
|
if (null == userStudy) {
|
userStudy = new TUserStudy();
|
userStudy.setUserId(userId);
|
// 学习周目
|
TStudy tStudy = this.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.getWeek() >= study.getWeek();
|
}
|
|
@Override
|
public void checkDifficulty(Integer difficulty, Integer week, TGame game, Integer userid) {
|
// 判断用户是否完成上一个等级
|
if (!Constants.ZERO.equals(difficulty)) {
|
Integer level = GAME_DIFFICULTY_MAP.get(difficulty);
|
if (null == level) {
|
throw new GlobalException("游戏等级异常,请重试!");
|
}
|
// 游戏通关率
|
String clearanceRate = game.getRate().split(",")[level];
|
// 获取用户游戏进度
|
List<TGameRecord> list = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userid)
|
.eq(TGameRecord::getGameId, game.getId())
|
.ge(TGameRecord::getAccuracy, clearanceRate)
|
.eq(TGameRecord::getGameDifficulty, level).list();
|
if (list.isEmpty()) {
|
throw new GlobalException("请先完成上一难度再挑战当前难度!");
|
}
|
}
|
}
|
|
@Override
|
public StudyListenResultVO listenSelectPicture(Integer week, Integer day, List<TStudyListen> studyListens) {
|
if (studyListens.isEmpty()) {
|
throw new GlobalException("当前学习周目题目数量不足!");
|
}
|
// 题组信息
|
LearnStudyVO learnStudy = new LearnStudyVO();
|
String ids = studyListens.stream().map(TStudyListen::getId).map(String::valueOf)
|
.collect(Collectors.joining(","));
|
learnStudy.setId(ids);
|
int total = 0;
|
for (TStudyListen data : studyListens) {
|
if (null != data) {
|
total += data.getIntegral();
|
}
|
}
|
learnStudy.setIntegral(total);
|
// 语音及图片
|
List<List<TSubject>> subjectList = new ArrayList<>();
|
for (TStudyListen studyListen : studyListens) {
|
List<String> subjectIds = Arrays.stream(studyListen.getSubject().split(",")).collect(Collectors.toList());
|
List<TSubject> list = new ArrayList<>();
|
// 图片及语音集合
|
for (String id : subjectIds) {
|
TSubject data = subjectService.lambdaQuery().eq(TSubject::getId, id)
|
.eq(TSubject::getDisabled, 0).one();
|
list.add(data);
|
}
|
subjectList.add(list);
|
}
|
return new StudyListenResultVO(learnStudy, subjectList);
|
}
|
|
@Override
|
public StudyLookResultVO pictureSelectVoice(Integer week, Integer day, List<TStudyLook> lookList) {
|
if (lookList.isEmpty()) {
|
throw new GlobalException("当前学习周目题目数量不足!");
|
}
|
// 题组信息
|
LearnStudyVO learnStudy = new LearnStudyVO();
|
String ids = lookList.stream().map(TStudyLook::getId).map(String::valueOf)
|
.collect(Collectors.joining(","));
|
learnStudy.setId(ids);
|
int total = 0;
|
for (TStudyLook data : lookList) {
|
if (null != data) {
|
total += data.getIntegral();
|
}
|
}
|
learnStudy.setIntegral(total);
|
// 语音及图片
|
List<List<TSubject>> subjectList = new ArrayList<>();
|
for (TStudyLook studyLook : lookList) {
|
List<String> sortList = Arrays.stream(studyLook.getSort().split(",")).collect(Collectors.toList());
|
List<String> subjectIds = Arrays.stream(studyLook.getSubject().split(",")).collect(Collectors.toList());
|
List<TSubject> list = new ArrayList<>();
|
// 图片及语音集合
|
for (int i = 0; i < subjectIds.size(); i++) {
|
TSubject data = subjectService.lambdaQuery().eq(TSubject::getId, subjectIds.get(i))
|
.eq(TSubject::getDisabled, 0).one();
|
data.setSort(Integer.parseInt(sortList.get(i)));
|
list.add(data);
|
}
|
// 根据顺序排序
|
list.sort(Comparator.comparingInt(TSubject::getSort));
|
subjectList.add(list);
|
}
|
return new StudyLookResultVO(learnStudy, subjectList);
|
}
|
|
@Override
|
public StudyInductionResultVO induceExclude(Integer week, Integer day, List<TStudyInduction> inductionList) {
|
if (inductionList.isEmpty()) {
|
throw new GlobalException("当前学习周目题目数量不足!");
|
}
|
// 题组信息
|
LearnStudyVO learnStudy = new LearnStudyVO();
|
String ids = inductionList.stream().map(TStudyInduction::getId).map(String::valueOf)
|
.collect(Collectors.joining(","));
|
learnStudy.setId(ids);
|
int total = 0;
|
for (TStudyInduction data : inductionList) {
|
if (null != data) {
|
total += data.getIntegral();
|
}
|
}
|
learnStudy.setIntegral(total);
|
// 语音及图片
|
List<List<TSubject>> subjectList = new ArrayList<>();
|
for (TStudyInduction data : inductionList) {
|
List<String> subjectIds = Arrays.stream(data.getSubject().split(",")).collect(Collectors.toList());
|
List<TSubject> subjectLists = new ArrayList<>();
|
// 第一组题 固定下标为0,1,2的题
|
for (int i = 0; i < Constants.THREE; i++) {
|
String id = subjectIds.get(i);
|
if (!id.startsWith("-")) {
|
subjectLists.add(subjectService.getById(id));
|
}
|
}
|
for (int i = 0; i < Constants.THREE; i++) {
|
String id = subjectIds.get(i);
|
if (id.startsWith("-")) {
|
id = id.replace("-", "");
|
subjectLists.add(subjectService.getById(id));
|
}
|
}
|
// 第二组题,固定下标为3,4的题
|
for (int i = Constants.THREE; i < Constants.FIVE; i++) {
|
String id = subjectIds.get(i);
|
if (!id.startsWith("-")) {
|
subjectLists.add(subjectService.getById(id));
|
}
|
}
|
for (int i = Constants.THREE; i < Constants.FIVE; i++) {
|
String id = subjectIds.get(i);
|
if (id.startsWith("-")) {
|
id = id.replace("-", "");
|
subjectLists.add(subjectService.getById(id));
|
}
|
}
|
subjectLists.add(subjectService.getById(subjectIds.get(subjectIds.size() - 1).replace("-", "")));
|
subjectList.add(subjectLists);
|
}
|
return new StudyInductionResultVO(learnStudy, subjectList);
|
}
|
|
@Override
|
public StudyAnswerResultVO questionsAndAnswers(Integer week, Integer day, List<TStudyAnswer> answerList) {
|
if (answerList.isEmpty()) {
|
throw new GlobalException("当前学习周目题目数量不足!");
|
}
|
// 题组信息
|
LearnStudyVO learnStudy = new LearnStudyVO();
|
String ids = answerList.stream().map(TStudyAnswer::getId).map(String::valueOf)
|
.collect(Collectors.joining(","));
|
learnStudy.setId(ids);
|
int total = 0;
|
for (TStudyAnswer data : answerList) {
|
if (null != data) {
|
total += data.getIntegral();
|
}
|
}
|
learnStudy.setIntegral(total);
|
// 题目语音及图片信息
|
List<List<QuestionsAnswersSubjectVO>> subjectList = new ArrayList<>();
|
for (int i = 0; i < answerList.size(); i += Constants.TWO) {
|
List<QuestionsAnswersSubjectVO> voList = new ArrayList<>();
|
// 一组题目为四道题,
|
TStudyAnswer one = answerList.get(i);
|
TStudyAnswer two = answerList.get(i + 1);
|
voAdd(voList, one);
|
voAdd(voList, two);
|
subjectList.add(voList);
|
}
|
return new StudyAnswerResultVO(learnStudy, subjectList);
|
}
|
|
private void voAdd(List<QuestionsAnswersSubjectVO> voList, TStudyAnswer one) {
|
// 第一道题问题及答案
|
Integer subject = one.getSubject();
|
Integer answerSubject = one.getAnswerSubject();
|
// 问题题目信息
|
QuestionsAnswersSubjectVO oneVO = new QuestionsAnswersSubjectVO();
|
TSubject one1 = subjectService.lambdaQuery().eq(TSubject::getId, subject)
|
.eq(TSubject::getDisabled, 0).one();
|
copyProperties(one1, oneVO);
|
// 回答题目信息
|
QuestionsAnswersSubjectVO twoVO = new QuestionsAnswersSubjectVO();
|
TSubject two1 = subjectService.lambdaQuery().eq(TSubject::getId, answerSubject)
|
.eq(TSubject::getDisabled, 0).one();
|
copyProperties(two1, twoVO);
|
// 判断第一组题目的问题题目及回答题目,哪个是答案
|
if (Constants.ZERO.equals(one.getIsAnswer())) {
|
oneVO.setIsQuestion(1);
|
twoVO.setIsQuestion(0);
|
} else {
|
oneVO.setIsQuestion(0);
|
twoVO.setIsQuestion(1);
|
}
|
voList.add(oneVO);
|
voList.add(twoVO);
|
}
|
|
private void copyProperties(TSubject subject, QuestionsAnswersSubjectVO vo) {
|
vo.setId(subject.getId());
|
vo.setName(subject.getName());
|
vo.setEnglish(subject.getEnglish());
|
vo.setType(subject.getType());
|
vo.setState(subject.getState());
|
vo.setImg(subject.getImg());
|
vo.setCorrect(subject.getCorrect());
|
vo.setError(subject.getError());
|
vo.setSort(subject.getSort());
|
}
|
|
@Override
|
public StudyPairResultVO pictureMateVoice(Integer week, Integer day, List<TStudyPair> pair) {
|
if (pair.isEmpty()) {
|
throw new GlobalException("当前学习周目题目数量不足!");
|
}
|
// 题组信息
|
LearnStudyVO learnStudy = new LearnStudyVO();
|
String ids = pair.stream().map(TStudyPair::getId).map(String::valueOf)
|
.collect(Collectors.joining(","));
|
learnStudy.setId(ids);
|
int total = 0;
|
for (TStudyPair data : pair) {
|
if (null != data) {
|
total += data.getIntegral();
|
}
|
}
|
learnStudy.setIntegral(total);
|
// 语音及图片
|
List<List<TSubject>> subjectList = new ArrayList<>();
|
for (TStudyPair data : pair) {
|
List<String> subjectIds = Arrays.stream(data.getSubject().split(",")).collect(Collectors.toList());
|
List<TSubject> subjectLists = new ArrayList<>();
|
for (String id : subjectIds) {
|
if (id.startsWith("-")) {
|
id = id.replace("-", "");
|
}
|
subjectLists.add(subjectService.getById(id));
|
}
|
subjectList.add(subjectLists);
|
}
|
return new StudyPairResultVO(learnStudy, subjectList);
|
}
|
|
@Override
|
public int computeSchedule(TUserStudy result, Integer week) {
|
List<TStudy> studyList = this.lambdaQuery().eq(TStudy::getDisabled, 0)
|
.eq(TStudy::getType, 1)
|
.orderByAsc(TStudy::getWeek).list();
|
// 基础学习进度
|
Integer day = result.getDay();
|
Integer studyWeek = result.getWeek();
|
Map<Integer, List<TStudy>> studyMap = new HashMap<>(8);
|
for (TStudy study : studyList) {
|
Integer quarter = study.getQuarter();
|
List<TStudy> itemList = studyMap.get(quarter);
|
if (null == itemList) {
|
itemList = new ArrayList<>();
|
}
|
itemList.add(study);
|
studyMap.put(quarter, itemList);
|
}
|
// 学习进度所属季度
|
int studyQuarter = 1;
|
// 当前进入周目所属季度
|
int thisQuarter = 1;
|
for (Map.Entry<Integer, List<TStudy>> map : studyMap.entrySet()) {
|
Integer key = map.getKey();
|
List<TStudy> list = map.getValue();
|
List<Integer> collect = list.stream().map(TStudy::getWeek).collect(Collectors.toList());
|
if (collect.contains(studyWeek)) {
|
studyQuarter = key;
|
}
|
if (collect.contains(week)) {
|
thisQuarter = key;
|
}
|
}
|
// 默认进度为 0
|
int defaultSchedule;
|
// 季度判断
|
if (studyQuarter > thisQuarter) {
|
defaultSchedule = 100;
|
} else if (studyQuarter < thisQuarter) {
|
defaultSchedule = 0;
|
} else {
|
List<TStudy> tStudies = studyMap.get(studyQuarter);
|
List<Integer> weekList = tStudies.stream().map(TStudy::getWeek).collect(Collectors.toList());
|
int studyIndex = weekList.indexOf(studyWeek);
|
int weekIndex = weekList.indexOf(week);
|
if (studyIndex > weekIndex) {
|
defaultSchedule = 100;
|
} else if (studyIndex < weekIndex) {
|
defaultSchedule = 0;
|
} else {
|
// 根据day初始化学习进度
|
if (Constants.ONE.equals(day)) {
|
defaultSchedule = 0;
|
} else if (Constants.TWO.equals(day)) {
|
defaultSchedule = 20;
|
} else if (Constants.THREE.equals(day)) {
|
defaultSchedule = 40;
|
} else if (Constants.FOUR.equals(day)) {
|
defaultSchedule = 60;
|
} else if (Constants.FIVE.equals(day)) {
|
defaultSchedule = 80;
|
} else {
|
defaultSchedule = 0;
|
}
|
// 根据五种学习计算进度
|
Integer listen = result.getListen();
|
if (!Constants.BURDEN_ONE.equals(listen)) {
|
defaultSchedule += (int) (((double) listen / 100) * 4);
|
}
|
Integer look = result.getLook();
|
if (!Constants.BURDEN_ONE.equals(look)) {
|
defaultSchedule += (int) (((double) look / 100) * 4);
|
}
|
Integer induction = result.getInduction();
|
if (!Constants.BURDEN_ONE.equals(induction)) {
|
defaultSchedule += (int) (((double) induction / 100) * 4);
|
}
|
Integer answer = result.getAnswer();
|
if (!Constants.BURDEN_ONE.equals(answer)) {
|
defaultSchedule += (int) (((double) answer / 100) * 4);
|
}
|
Integer pair = result.getPair();
|
if (!Constants.BURDEN_ONE.equals(pair)) {
|
defaultSchedule += (int) (((double) pair / 100) * 4);
|
}
|
}
|
}
|
// week以超过当前week,进度为 100%
|
/*if (itemBool) {
|
defaultSchedule = 100;
|
} else {
|
// 根据day初始化学习进度
|
if (Constants.ONE.equals(day)) {
|
defaultSchedule = 0;
|
} else if (Constants.TWO.equals(day)) {
|
defaultSchedule = 20;
|
} else if (Constants.THREE.equals(day)) {
|
defaultSchedule = 40;
|
} else if (Constants.FOUR.equals(day)) {
|
defaultSchedule = 60;
|
} else if (Constants.FIVE.equals(day)) {
|
defaultSchedule = 80;
|
} else {
|
defaultSchedule = 0;
|
}
|
// 根据五种学习计算进度
|
Integer listen = result.getListen();
|
if (!Constants.BURDEN_ONE.equals(listen)) {
|
defaultSchedule += (int) (((double) listen / 100) * 4);
|
}
|
Integer look = result.getLook();
|
if (!Constants.BURDEN_ONE.equals(look)) {
|
defaultSchedule += (int) (((double) look / 100) * 4);
|
}
|
Integer induction = result.getInduction();
|
if (!Constants.BURDEN_ONE.equals(induction)) {
|
defaultSchedule += (int) (((double) induction / 100) * 4);
|
}
|
Integer answer = result.getAnswer();
|
if (!Constants.BURDEN_ONE.equals(answer)) {
|
defaultSchedule += (int) (((double) answer / 100) * 4);
|
}
|
Integer pair = result.getPair();
|
if (!Constants.BURDEN_ONE.equals(pair)) {
|
defaultSchedule += (int) (((double) pair / 100) * 4);
|
}
|
}*/
|
return defaultSchedule;
|
}
|
|
@Override
|
public int computeTotalIntegral(List<String> studyIds, Integer type, Integer accuracy) {
|
int sum = 0;
|
if (Constants.ONE.equals(type)) {
|
List<TStudyListen> list = studyListenService.lambdaQuery().in(TStudyListen::getId, studyIds)
|
.eq(TStudyListen::getDisabled, 0).list();
|
Optional<TStudyListen> any = list.stream().findAny();
|
if (any.isPresent()) {
|
sum = any.get().getIntegral();
|
}
|
} else if (Constants.TWO.equals(type)) {
|
List<TStudyLook> list = studyLookService.lambdaQuery().in(TStudyLook::getId, studyIds)
|
.eq(TStudyLook::getDisabled, 0).list();
|
Optional<TStudyLook> any = list.stream().findAny();
|
if (any.isPresent()) {
|
sum = any.get().getIntegral();
|
}
|
} else if (Constants.THREE.equals(type)) {
|
List<TStudyInduction> list = studyInductionService.lambdaQuery().in(TStudyInduction::getId, studyIds)
|
.eq(TStudyInduction::getDisabled, 0).list();
|
Optional<TStudyInduction> any = list.stream().findAny();
|
if (any.isPresent()) {
|
sum = any.get().getIntegral();
|
}
|
} else if (Constants.FOUR.equals(type)) {
|
List<TStudyAnswer> list = studyAnswerService.lambdaQuery().in(TStudyAnswer::getId, studyIds)
|
.eq(TStudyAnswer::getDisabled, 0).list();
|
Optional<TStudyAnswer> any = list.stream().findAny();
|
if (any.isPresent()) {
|
sum = any.get().getIntegral();
|
}
|
} else if (Constants.FIVE.equals(type)) {
|
List<TStudyPair> list = studyPairService.lambdaQuery().in(TStudyPair::getId, studyIds)
|
.eq(TStudyPair::getDisabled, 0).list();
|
Optional<TStudyPair> any = list.stream().findAny();
|
if (any.isPresent()) {
|
sum = any.get().getIntegral();
|
}
|
} else {
|
throw new GlobalException("题目信息异常!");
|
}
|
if (accuracy >= 100) {
|
return sum;
|
} else {
|
return (int) (sum * ((double) accuracy / 100));
|
}
|
}
|
|
@Override
|
public int residueWeek(TUserStudy studyRecord, List<TStudy> studyList) {
|
// 已学习周目
|
int residueWeek = 0;
|
// 已学习到的周目
|
Integer studyWeek = studyRecord.getWeek();
|
// 根据季度分组封装
|
Map<Integer, List<TStudy>> itemMap = getIntegerListMap(studyList);
|
// 计算已学习周目
|
boolean v = false;
|
for (Map.Entry<Integer, List<TStudy>> map : itemMap.entrySet()) {
|
List<TStudy> list = map.getValue();
|
for (int i = 0; i < list.size(); i++) {
|
TStudy item = list.get(i);
|
if (item.getWeek().equals(studyWeek)) {
|
Integer listen = studyRecord.getListen();
|
Integer answer = studyRecord.getAnswer();
|
Integer look = studyRecord.getLook();
|
Integer induction = studyRecord.getInduction();
|
Integer pair = studyRecord.getPair();
|
Integer gameDifficulty = studyRecord.getGameDifficulty();
|
// 听音选图、看图选音、音图相配、有问有答、归纳排除的进度是否 100%,并且超级听力的游戏难度是否为2
|
boolean isStudy = Constants.ONE_HUNDRED.equals(listen) && Constants.ONE_HUNDRED.equals(look) &&
|
Constants.ONE_HUNDRED.equals(induction) && Constants.ONE_HUNDRED.equals(pair) &&
|
Constants.ONE_HUNDRED.equals(answer) && Constants.TWO.equals(gameDifficulty);
|
// 并且超级听力难度2已通过
|
TStudy study = this.lambdaQuery().eq(TStudy::getWeek, studyRecord.getWeek())
|
.eq(TStudy::getDisabled, 0)
|
.one();
|
TGame game = gameService.lambdaQuery()
|
.eq(TGame::getStudyId, study.getId())
|
.eq(TGame::getDisabled, 0)
|
.eq(TGame::getWeek, study.getWeek())
|
.one();
|
if (null != game) {
|
String rate = game.getRate().split(",")[2];
|
List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery()
|
.eq(TGameRecord::getGameDifficulty, Constants.TWO)
|
.ge(TGameRecord::getAccuracy, rate)
|
.eq(TGameRecord::getUserId, studyRecord.getUserId())
|
.eq(TGameRecord::getGameId, game.getId())
|
.list();
|
if (gameRecordList.isEmpty()) {
|
isStudy = false;
|
}
|
List<TGameRecord> recordList = gameRecordService.lambdaQuery()
|
.ge(TGameRecord::getAccuracy, game.getAnswerRate())
|
.eq(TGameRecord::getUserId, studyRecord.getUserId())
|
.eq(TGameRecord::getGameId, game.getId())
|
.last("and gameDifficulty is null")
|
.list();
|
if (recordList.isEmpty()) {
|
isStudy = false;
|
}
|
}
|
if (isStudy) {
|
residueWeek++;
|
}
|
v = true;
|
break;
|
} else {
|
residueWeek++;
|
}
|
}
|
if (v) {
|
break;
|
}
|
}
|
return studyList.size() - residueWeek;
|
}
|
|
private Map<Integer, List<TStudy>> getIntegerListMap(List<TStudy> studyList) {
|
Map<Integer, List<TStudy>> studyMap = new HashMap<>(8);
|
for (TStudy study : studyList) {
|
Integer quarter = study.getQuarter();
|
List<TStudy> itemList = studyMap.get(quarter);
|
if (null == itemList) {
|
itemList = new ArrayList<>();
|
}
|
itemList.add(study);
|
studyMap.put(quarter, itemList);
|
}
|
// 顺序排序
|
Map<Integer, List<TStudy>> itemMap = new HashMap<>(8);
|
List<Integer> keyList = new ArrayList<>();
|
for (Map.Entry<Integer, List<TStudy>> map : studyMap.entrySet()) {
|
Integer key = map.getKey();
|
keyList.add(key);
|
}
|
Collections.sort(keyList);
|
for (Integer key : keyList) {
|
List<TStudy> itemList = studyMap.get(key);
|
itemMap.put(key, itemList);
|
}
|
return itemMap;
|
}
|
|
@Override
|
public void checkClearance(TGame game, Integer userid) {
|
String rate = game.getRate().split(",")[Constants.TWO];
|
// 获取用户游戏进度
|
List<TGameRecord> list = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userid)
|
.eq(TGameRecord::getGameId, game.getId())
|
.ge(TGameRecord::getAccuracy, rate)
|
.eq(TGameRecord::getGameDifficulty, Constants.TWO).list();
|
if (list.isEmpty()) {
|
throw new GlobalException("超级听力暂未通关!");
|
}
|
}
|
|
}
|