| | |
| | | package com.ruoyi.study.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.study.domain.TStudy; |
| | | import com.ruoyi.study.domain.TUserStudy; |
| | | import com.ruoyi.study.dto.CompleteStudyDTO; |
| | | import com.ruoyi.study.mapper.TUserStudyMapper; |
| | | import com.ruoyi.study.service.ITUserStudyService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class TUserStudyServiceImpl extends ServiceImpl<TUserStudyMapper, TUserStudy> implements ITUserStudyService { |
| | | |
| | | /** |
| | | * 所属day map |
| | | */ |
| | | private static final Map<String, Integer> DAY_MAP = new HashMap<>(12); |
| | | |
| | | static { |
| | | DAY_MAP.put(Constants.ONE_STR, Constants.TWO); |
| | | DAY_MAP.put(Constants.TWO_STR, Constants.THREE); |
| | | DAY_MAP.put(Constants.THREE_STR, Constants.FOUR); |
| | | DAY_MAP.put(Constants.FOUR_STR, Constants.FIVE); |
| | | DAY_MAP.put(Constants.FIVE_STR, Constants.ONE); |
| | | // DAY_MAP.put(Constants.SIX_STR, Constants.SEVEN); |
| | | // DAY_MAP.put(Constants.SEVEN_STR, Constants.ONE); |
| | | } |
| | | |
| | | @Override |
| | | public TUserStudy studySchedule(String userId, Integer week, Integer day) { |
| | | return lambdaQuery().eq(TUserStudy::getUserId, userId) |
| | | .eq(TUserStudy::getDay, day).eq(TUserStudy::getWeek, week) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | public TUserStudy studySchedule(String userId, Integer week) { |
| | | LambdaQueryChainWrapper<TUserStudy> wrapper = lambdaQuery().eq(TUserStudy::getUserId, userId); |
| | | wrapper = null != week ? wrapper.eq(TUserStudy::getWeek, week) : wrapper; |
| | | return wrapper.eq(TUserStudy::getDisabled, 0).one(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | break; |
| | | default: |
| | | } |
| | | // 自旋重试 |
| | | int number = 0; |
| | | boolean update = this.updateBatchById(list); |
| | | while (!update) { |
| | |
| | | number++; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Boolean exchangeStudyRecord(List<TStudy> studyList, Integer userId, CompleteStudyDTO completeStudy) { |
| | | Integer studyTime = completeStudy.getStudyTime(); |
| | | // 学习记录 |
| | | TUserStudy userStudyRecord = lambdaQuery().eq(TUserStudy::getUserId, userId) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | Integer type = completeStudy.getType(); |
| | | if (Constants.ONE.equals(type)) { |
| | | userStudyRecord.setListen(Constants.ONE_HUNDRED); |
| | | } else if (Constants.TWO.equals(type)) { |
| | | userStudyRecord.setLook(Constants.ONE_HUNDRED); |
| | | } else if (Constants.THREE.equals(type)) { |
| | | userStudyRecord.setInduction(Constants.ONE_HUNDRED); |
| | | } else if (Constants.FOUR.equals(type)) { |
| | | userStudyRecord.setAnswer(Constants.ONE_HUNDRED); |
| | | } else if (Constants.FIVE.equals(type)) { |
| | | // 类型五,说明当前day已经全部完成,更新学习记录的 day |
| | | Integer nextDay = DAY_MAP.get(String.valueOf(userStudyRecord.getDay())); |
| | | userStudyRecord.setDay(nextDay); |
| | | // 学习day已切换更新学习进度及学习时长 |
| | | userStudyRecord.setListen(Constants.ZERO); |
| | | userStudyRecord.setLook(Constants.ZERO); |
| | | userStudyRecord.setInduction(Constants.ZERO); |
| | | userStudyRecord.setAnswer(Constants.ZERO); |
| | | userStudyRecord.setPair(Constants.ZERO); |
| | | // 下一day为 1说明该周目已完成,应更改为下一周目 |
| | | if (Constants.ONE.equals(nextDay)) { |
| | | // 获取下一周目信息 |
| | | int index = -1; |
| | | for (int i = 0; i < studyList.size(); i++) { |
| | | if (studyList.get(i).getWeek().equals(userStudyRecord.getWeek())) { |
| | | index = i; |
| | | break; |
| | | } |
| | | } |
| | | int nextIndex = (index + 1) % studyList.size(); |
| | | TStudy nextStudy = studyList.get(nextIndex); |
| | | // 更新学习进度及学习时长 |
| | | userStudyRecord.setWeek(nextStudy.getWeek()); |
| | | } |
| | | } |
| | | // 更新学习时长 |
| | | userStudyRecord.setTotalStudy(userStudyRecord.getTotalStudy() + studyTime); |
| | | userStudyRecord.setTodayStudy(userStudyRecord.getTodayStudy() + studyTime); |
| | | userStudyRecord.setWeekStudy(userStudyRecord.getWeekStudy() + studyTime); |
| | | userStudyRecord.setMonthStudy(userStudyRecord.getMonthStudy() + studyTime); |
| | | // 更新学习进度及学习时长 |
| | | return this.updateById(userStudyRecord); |
| | | } |
| | | |
| | | } |