|
|
@@ -3,6 +3,7 @@ package com.zhongzheng.modules.user.service.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
import com.zhongzheng.modules.exam.vo.ExamArrangementTimeVo;
|
|
|
@@ -10,6 +11,8 @@ import com.zhongzheng.modules.user.vo.CalendarStudyVo;
|
|
|
import com.zhongzheng.modules.user.vo.CoursePlanVo;
|
|
|
import com.zhongzheng.modules.user.vo.DayStudyVo;
|
|
|
import io.micrometer.core.instrument.util.TimeUtils;
|
|
|
+import org.codehaus.jettison.json.JSONArray;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
@@ -120,6 +123,22 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
|
|
|
//自定义学习计划,自动生成计划
|
|
|
if (bo.getCourseId() != null && bo.getStudyCount() == null){
|
|
|
UserPlanVo userPlanVo = generateSelf(bo);
|
|
|
+ if (bo.getStatus() != null && bo.getStatus() == 1){
|
|
|
+ UserPlan userPlan = new UserPlan();
|
|
|
+ String s = JSON.toJSONString(userPlanVo.getCalendarStudyVo());
|
|
|
+ String s1 = JSON.toJSONString(userPlanVo);
|
|
|
+
|
|
|
+ userPlan.setStudyDay(bo.getStudyDay());
|
|
|
+ userPlan.setStudyCount(s1);
|
|
|
+ userPlan.setUserId(bo.getUserId());
|
|
|
+ userPlan.setSchedule(s);
|
|
|
+ userPlan.setPitchNum(userPlanVo.getPitchNum());
|
|
|
+ userPlan.setStudyNum(0L);
|
|
|
+ userPlan.setCreateTime(DateUtils.getNowTime());
|
|
|
+ userPlan.setUpdateTime(DateUtils.getNowTime());
|
|
|
+
|
|
|
+ boolean save = this.save(userPlan);
|
|
|
+ }
|
|
|
return userPlanVo;
|
|
|
}else{
|
|
|
UserPlanVo userPlanVo = generateSelfBo(bo);
|
|
|
@@ -128,20 +147,135 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
|
|
|
}
|
|
|
|
|
|
private UserPlanVo generateSelfBo(UserPlanQueryBo bo) throws ParseException {
|
|
|
+
|
|
|
+
|
|
|
//获得当前课程最近一个考试计划 考生考生计划或者最近考试计划
|
|
|
- CoursePlanVo coursePlanVo = baseMapper.selectByCourse(bo);
|
|
|
+ List<CoursePlanVo> coursePlanVo = baseMapper.selectByListCourse(bo);
|
|
|
+
|
|
|
+ UserPlanVo userPlanVo1 = new UserPlanVo();
|
|
|
+ for (CoursePlanVo planVo : coursePlanVo) {
|
|
|
+ if (userPlanVo1 == null) {
|
|
|
+ userPlanVo1 = generateList(bo, planVo);
|
|
|
+ }else {
|
|
|
+ userPlanVo1 = generateOr(bo,planVo,userPlanVo1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return userPlanVo1;
|
|
|
+ }
|
|
|
|
|
|
+ private UserPlanVo generateOr(UserPlanQueryBo bo, CoursePlanVo planVo, UserPlanVo userPlanVo1) throws ParseException {
|
|
|
//最近考试时间七天前到现在的天数,学习视频时长
|
|
|
Date date1 = new Date(bo.getExamDate()*1000L);
|
|
|
//获得相隔天数
|
|
|
Long[] longs =bo.getStudyCount();
|
|
|
- int dutyDays = getDutyDays(new Date(), date1,longs,bo.getStudyDay());
|
|
|
+ int dutyDays = getDutyDays(new Date(), date1,longs,7L);
|
|
|
+
|
|
|
+ //计算每天需要学习多少节课
|
|
|
+ int Sec = (int)Math.ceil((double)planVo.getSectionNum()/dutyDays);
|
|
|
+
|
|
|
+ //总节数
|
|
|
+ Integer sectionNum = planVo.getSectionNum();
|
|
|
+
|
|
|
+
|
|
|
+ //获得今天日期,将每天节数写入
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ int year = cal.get(Calendar.YEAR);
|
|
|
+ Integer month = 0;
|
|
|
+ //将原有的月份添加课程的节数
|
|
|
+ for (CalendarStudyVo calendarStudyVo : userPlanVo1.getCalendarStudyVo()) {
|
|
|
+ if (month < calendarStudyVo.getMonth()){
|
|
|
+ month = Convert.toInt(calendarStudyVo.getMonth());
|
|
|
+ }
|
|
|
+ for (DayStudyVo dayStudyVo : calendarStudyVo.getDayStudyList()) {
|
|
|
+ if (dayStudyVo.getDate() > Calendar.getInstance().get(Calendar.DAY_OF_MONTH) && calendarStudyVo.getMonth() == (cal.get(Calendar.MONTH) + 1) && ifTrue(dayStudyVo.getStudyDay(),longs)) {
|
|
|
+ if (sectionNum == 0){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (Sec < sectionNum) {
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec)+dayStudyVo.getStudyCourseKnob());
|
|
|
+ sectionNum = sectionNum-Sec;
|
|
|
+ }else if (Sec >= sectionNum){
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum)+dayStudyVo.getStudyCourseKnob());
|
|
|
+ sectionNum = 0;
|
|
|
+ }
|
|
|
+ }else if(calendarStudyVo.getMonth() != (cal.get(Calendar.MONTH) + 1) && ifTrue(dayStudyVo.getStudyDay(),longs)){
|
|
|
+ if (Sec < sectionNum) {
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec)+dayStudyVo.getStudyCourseKnob());
|
|
|
+ sectionNum = sectionNum-Sec;
|
|
|
+ }else if (Sec >= sectionNum){
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum)+dayStudyVo.getStudyCourseKnob());
|
|
|
+ sectionNum = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //原有课程不满足课程节数则再创建课程
|
|
|
+ if (sectionNum == 0){
|
|
|
+ while (sectionNum != 0 ) {
|
|
|
+ month++;
|
|
|
+ Long firstDayOfMonth = getFirstDayOfMonth(month+1);
|
|
|
+ Long lastDayOfMonth = getLastDayOfMonth(month+1);
|
|
|
+
|
|
|
+ List<DayStudyVo> dayStudyVos = getDays(firstDayOfMonth, lastDayOfMonth);
|
|
|
+ for (DayStudyVo dayStudyVo : dayStudyVos) {
|
|
|
+ if (dayStudyVo.getDate() > Calendar.getInstance().get(Calendar.DAY_OF_MONTH) && month == (cal.get(Calendar.MONTH) + 1) && ifTrue(dayStudyVo.getStudyDay(),longs)) {
|
|
|
+ if (sectionNum == 0){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (Sec < sectionNum) {
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec));
|
|
|
+ sectionNum = sectionNum-Sec;
|
|
|
+ }else if (Sec >= sectionNum){
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum));
|
|
|
+ sectionNum = 0;
|
|
|
+ }
|
|
|
+ }else if(month != (cal.get(Calendar.MONTH) + 1) && ifTrue(dayStudyVo.getStudyDay(),longs)){
|
|
|
+ if (Sec < sectionNum) {
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec));
|
|
|
+ sectionNum = sectionNum-Sec;
|
|
|
+ }else if (Sec >= sectionNum){
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum));
|
|
|
+ sectionNum = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CalendarStudyVo calendarStudyVo = new CalendarStudyVo();
|
|
|
+ calendarStudyVo.setYear(Convert.toLong(year));
|
|
|
+ calendarStudyVo.setMonth(Convert.toLong(month));
|
|
|
+ calendarStudyVo.setDayStudyList(dayStudyVos);
|
|
|
+ List<CalendarStudyVo> calendarStudyVo1 = userPlanVo1.getCalendarStudyVo();
|
|
|
+ calendarStudyVo1.add(calendarStudyVo);
|
|
|
+ userPlanVo1.setCalendarStudyVo(calendarStudyVo1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询是否解锁题库
|
|
|
+ userPlanVo1.setStudyCount(longs);
|
|
|
+ userPlanVo1.setUserId(bo.getUserId());
|
|
|
+ userPlanVo1.setStudyDay(0L);
|
|
|
+ userPlanVo1.setPitchNum(Convert.toLong(sectionNum)+userPlanVo1.getPitchNum());
|
|
|
+ userPlanVo1.setPitchNum(Convert.toLong(sectionNum)+userPlanVo1.getPitchNum());
|
|
|
+ return userPlanVo1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private UserPlanVo generateList(UserPlanQueryBo bo, CoursePlanVo coursePlanVo) throws ParseException {
|
|
|
+ UserPlanVo userPlanVo = new UserPlanVo();
|
|
|
+ //最近考试时间七天前到现在的天数,学习视频时长
|
|
|
+ Date date1 = new Date(bo.getStartTime()*1000L);
|
|
|
+ Date date = new Date(bo.getEndTime()*1000L);
|
|
|
+ Calendar ca = Calendar.getInstance();
|
|
|
+ ca.setTime(date1);
|
|
|
+
|
|
|
+ //获得相隔天数
|
|
|
+ Long[] longs =bo.getStudyCount();
|
|
|
+ int dutyDays = getDutyDays(date1, date,longs,0L);
|
|
|
|
|
|
//计算每天需要学习多少节课
|
|
|
int Sec = (int)Math.ceil((double)coursePlanVo.getSectionNum()/dutyDays);
|
|
|
|
|
|
//总节数
|
|
|
Integer sectionNum = coursePlanVo.getSectionNum();
|
|
|
+ userPlanVo.setPitchNum(Convert.toLong(sectionNum));
|
|
|
|
|
|
//获得今天日期,将每天节数写入
|
|
|
List<CalendarStudyVo> calendarStudyVos = new ArrayList<>();
|
|
|
@@ -166,19 +300,22 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
|
|
|
|
|
|
List<DayStudyVo> dayStudyVos = getDays(firstDayOfMonth, lastDayOfMonth);
|
|
|
for (DayStudyVo dayStudyVo : dayStudyVos) {
|
|
|
- if (dayStudyVo.getDate() > Calendar.getInstance().get(Calendar.DAY_OF_MONTH) && month == (cal.get(Calendar.MONTH) + 1) && ifTrue(dayStudyVo.getStudyDay(),longs)) {
|
|
|
- if (Sec > sectionNum) {
|
|
|
+ if (dayStudyVo.getDate() > ca.get(Calendar.DAY_OF_MONTH) && month == (cal.get(Calendar.MONTH) + 1) && ifTrue(dayStudyVo.getStudyDay(),longs)) {
|
|
|
+ if (sectionNum == 0){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (Sec < sectionNum) {
|
|
|
dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec));
|
|
|
sectionNum = sectionNum-Sec;
|
|
|
- }else if (Sec <= sectionNum){
|
|
|
+ }else if (Sec >= sectionNum){
|
|
|
dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum));
|
|
|
sectionNum = 0;
|
|
|
}
|
|
|
}else if(month != (cal.get(Calendar.MONTH) + 1) && ifTrue(dayStudyVo.getStudyDay(),longs)){
|
|
|
- if (Sec > sectionNum) {
|
|
|
+ if (Sec < sectionNum) {
|
|
|
dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec));
|
|
|
sectionNum = sectionNum-Sec;
|
|
|
- }else if (Sec <= sectionNum){
|
|
|
+ }else if (Sec >= sectionNum){
|
|
|
dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum));
|
|
|
sectionNum = 0;
|
|
|
}
|
|
|
@@ -193,9 +330,13 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
|
|
|
|
|
|
//查询是否解锁题库
|
|
|
|
|
|
- UserPlanVo userPlanVo = new UserPlanVo();
|
|
|
+
|
|
|
userPlanVo.setCalendarStudyVo(calendarStudyVos);
|
|
|
List<CoursePlanVo> coursePlanVos = new ArrayList<>();
|
|
|
+ userPlanVo.setStudyCount(longs);
|
|
|
+ userPlanVo.setUserId(bo.getUserId());
|
|
|
+
|
|
|
+ userPlanVo.setStudyDay(0L);
|
|
|
coursePlanVos.add(coursePlanVo);
|
|
|
userPlanVo.setCoursePlanVo(coursePlanVos);
|
|
|
return userPlanVo;
|