|
@@ -4,9 +4,15 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
import com.zhongzheng.modules.course.vo.CourseVo;
|
|
|
import com.zhongzheng.modules.goods.vo.GoodsVo;
|
|
|
+import com.zhongzheng.modules.user.vo.CalendarStudyVo;
|
|
|
+import com.zhongzheng.modules.user.vo.DaySectionVo;
|
|
|
+import com.zhongzheng.modules.user.vo.DayStudyVo;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
@@ -20,10 +26,10 @@ import com.zhongzheng.modules.user.mapper.UserPlanMapper;
|
|
|
import com.zhongzheng.modules.user.vo.UserPlanVo;
|
|
|
import com.zhongzheng.modules.user.service.IUserPlanService;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -37,8 +43,29 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
|
|
|
|
|
|
@Override
|
|
|
public UserPlanVo queryById(Long planId){
|
|
|
- UserPlan db = this.baseMapper.selectById(planId);
|
|
|
- return BeanUtil.toBean(db, UserPlanVo.class);
|
|
|
+ UserPlan userPlan = this.baseMapper.selectById(planId);
|
|
|
+ //得到日历日期
|
|
|
+ UserPlanVo userPlanVo = new UserPlanVo();
|
|
|
+ userPlanVo.setUserId(userPlan.getUserId());
|
|
|
+ userPlanVo.setExamDate(userPlan.getExamDate());
|
|
|
+ userPlanVo.setReminderTime(userPlan.getReminderTime());
|
|
|
+ userPlanVo.setStudyDay(userPlan.getStudyDay());
|
|
|
+ userPlanVo.setStartTime(userPlan.getStartTime());
|
|
|
+ userPlanVo.setEndTime(userPlan.getEndTime());
|
|
|
+ userPlanVo.setPitchNum(userPlan.getPitchNum());
|
|
|
+ userPlanVo.setStudyNum(userPlan.getStudyNum());
|
|
|
+ userPlanVo.setPlanId(userPlan.getPlanId());
|
|
|
+
|
|
|
+ //得到日历日期
|
|
|
+ List<CalendarStudyVo> calendarStudyVos = JSONObject.parseArray(userPlan.getSchedule(), CalendarStudyVo.class);
|
|
|
+ //得到学习的周
|
|
|
+ List<Long> cont = JSONObject.parseArray(userPlan.getStudyCount(), Long.class);
|
|
|
+ Long[] strings = new Long[cont.size()];
|
|
|
+ cont.toArray(strings);
|
|
|
+
|
|
|
+ userPlanVo.setCalendarStudyVo(calendarStudyVos);
|
|
|
+ userPlanVo.setStudyCount(strings);
|
|
|
+ return userPlanVo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -52,10 +79,36 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
|
|
|
lqw.eq(bo.getStudyDay() != null, UserPlan::getStudyDay, bo.getStudyDay());
|
|
|
lqw.eq(bo.getEndTime() != null, UserPlan::getEndTime, bo.getEndTime());
|
|
|
lqw.eq(bo.getStartTime() != null, UserPlan::getStartTime, bo.getStartTime());
|
|
|
- lqw.eq(bo.getStatus() != null, UserPlan::getStatus, bo.getStatus());
|
|
|
+ lqw.in(bo.getStatus() != null, UserPlan::getStatus, bo.getStatus());
|
|
|
lqw.eq(bo.getPitchNum() != null, UserPlan::getPitchNum, bo.getPitchNum());
|
|
|
lqw.eq(bo.getStudyNum() != null, UserPlan::getStudyNum, bo.getStudyNum());
|
|
|
- return entity2Vo(this.list(lqw));
|
|
|
+ List<UserPlan> userPlans = this.list(lqw);
|
|
|
+ List<UserPlanVo> userPlanVos = new ArrayList<>();
|
|
|
+ for (UserPlan userPlan : userPlans) {
|
|
|
+ UserPlanVo userPlanVo = new UserPlanVo();
|
|
|
+ userPlanVo.setUserId(userPlan.getUserId());
|
|
|
+ userPlanVo.setExamDate(userPlan.getExamDate());
|
|
|
+ userPlanVo.setReminderTime(userPlan.getReminderTime());
|
|
|
+ userPlanVo.setStudyDay(userPlan.getStudyDay());
|
|
|
+ userPlanVo.setStartTime(userPlan.getStartTime());
|
|
|
+ userPlanVo.setEndTime(userPlan.getEndTime());
|
|
|
+ userPlanVo.setPitchNum(userPlan.getPitchNum());
|
|
|
+ userPlanVo.setStudyNum(userPlan.getStudyNum());
|
|
|
+ userPlanVo.setPlanId(userPlan.getPlanId());
|
|
|
+
|
|
|
+ //得到日历日期
|
|
|
+ List<CalendarStudyVo> calendarStudyVos = JSONObject.parseArray(userPlan.getSchedule(), CalendarStudyVo.class);
|
|
|
+ //得到学习的周
|
|
|
+ List<Long> cont = JSONObject.parseArray(userPlan.getStudyCount(), Long.class);
|
|
|
+ Long[] strings = new Long[cont.size()];
|
|
|
+ cont.toArray(strings);
|
|
|
+
|
|
|
+ userPlanVo.setCalendarStudyVo(calendarStudyVos);
|
|
|
+ userPlanVo.setStudyCount(strings);
|
|
|
+ userPlanVos.add(userPlanVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return userPlanVos;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -79,20 +132,130 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean insertByAddBo(UserPlanAddBo bo) {
|
|
|
- UserPlan add = BeanUtil.toBean(bo, UserPlan.class);
|
|
|
- validEntityBeforeSave(add);
|
|
|
- add.setCreateTime(DateUtils.getNowTime());
|
|
|
- add.setUpdateTime(DateUtils.getNowTime());
|
|
|
- return this.save(add);
|
|
|
+ public Boolean insertByAddBo(UserPlanAddBo bo) throws ParseException {
|
|
|
+ UserPlan userPlan = new UserPlan();
|
|
|
+ List<CalendarStudyVo> clCalendarStudyVos = findDates(bo.getStartTime(),bo.getEndTime());
|
|
|
+ Long sumUp=0L;
|
|
|
+ for (Long aLong : bo.getGoodsId()) {
|
|
|
+ //最近考试时间七天前到现在的天数,学习视频时长
|
|
|
+ Date date1 = new Date(bo.getEndTime() * 1000L);
|
|
|
+ //获得相隔天数
|
|
|
+ int dutyDays = getDutyDays(new Date(), date1, bo.getStudyCount(), bo.getStudyDay());
|
|
|
+
|
|
|
+ List<Long> seLongs = baseMapper.selectGoods(aLong);
|
|
|
+ Long allNum = 0L;
|
|
|
+ for (Long seLong : seLongs) {
|
|
|
+ allNum += seLong;
|
|
|
+ }
|
|
|
+ sumUp += allNum;
|
|
|
+ //计算每天需要学习多少节课
|
|
|
+ int Sec = (int) Math.ceil((double) allNum / dutyDays);
|
|
|
+ for (CalendarStudyVo clCalendarStudyVo : clCalendarStudyVos) {
|
|
|
+ for (DayStudyVo dayStudyVo : clCalendarStudyVo.getDayStudyList()) {
|
|
|
+ if (Arrays.asList(bo.getStudyCount()).contains(dayStudyVo.getStudyDay())){
|
|
|
+ if (dayStudyVo.getStudyCourseKnob() != null) {
|
|
|
+ dayStudyVo.setStudyCourseKnob(dayStudyVo.getStudyCourseKnob() + Sec);
|
|
|
+ }else {
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec));
|
|
|
+ }
|
|
|
+ dayStudyVo.setPerform(0);
|
|
|
+ List<DaySectionVo> daySectionList = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(dayStudyVo.getDaySectionList())) {
|
|
|
+ daySectionList = dayStudyVo.getDaySectionList();
|
|
|
+ }
|
|
|
+ DaySectionVo daySectionVo = new DaySectionVo();
|
|
|
+ daySectionVo.setGoodsId(aLong);
|
|
|
+ daySectionVo.setStudyGoodsKnob(Convert.toLong(Sec));
|
|
|
+ daySectionVo.setGoodsPerform(0);
|
|
|
+ daySectionList.add(daySectionVo);
|
|
|
+ dayStudyVo.setDaySectionList(daySectionList);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String s = JSON.toJSONString(clCalendarStudyVos);
|
|
|
+ String s1 = JSON.toJSONString(bo.getStudyCount());
|
|
|
+ userPlan.setUserId(bo.getUserId());
|
|
|
+ userPlan.setSchedule(s);
|
|
|
+ userPlan.setStudyCount(s1);
|
|
|
+ userPlan.setPitchNum(sumUp);
|
|
|
+ userPlan.setStudyDay(bo.getStudyDay());
|
|
|
+ userPlan.setStudyNum(0L);
|
|
|
+ userPlan.setCreateTime(DateUtils.getNowTime());
|
|
|
+ userPlan.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ userPlan.setExamDate(bo.getExamDate());
|
|
|
+ userPlan.setStatus(1);
|
|
|
+ userPlan.setUserId(bo.getUserId());
|
|
|
+ userPlan.setStartTime(bo.getStartTime());
|
|
|
+ userPlan.setEndTime(bo.getEndTime());
|
|
|
+ userPlan.setReminderTime(bo.getReminderTime());
|
|
|
+ this.save(userPlan);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean updateByEditBo(UserPlanEditBo bo) {
|
|
|
- UserPlan update = BeanUtil.toBean(bo, UserPlan.class);
|
|
|
- validEntityBeforeSave(update);
|
|
|
- update.setUpdateTime(DateUtils.getNowTime());
|
|
|
- return this.updateById(update);
|
|
|
+ public Boolean updateByEditBo(UserPlanEditBo bo) throws ParseException {
|
|
|
+ UserPlan userPlan = new UserPlan();
|
|
|
+ List<CalendarStudyVo> clCalendarStudyVos = findDates(bo.getStartTime(),bo.getEndTime());
|
|
|
+ Long sumUp=0L;
|
|
|
+ for (Long aLong : bo.getGoodsId()) {
|
|
|
+ //最近考试时间七天前到现在的天数,学习视频时长
|
|
|
+ Date date1 = new Date(bo.getEndTime() * 1000L);
|
|
|
+ //获得相隔天数
|
|
|
+ int dutyDays = getDutyDays(new Date(), date1, bo.getStudyCount(), bo.getStudyDay());
|
|
|
+
|
|
|
+ List<Long> seLongs = baseMapper.selectGoods(aLong);
|
|
|
+ Long allNum = 0L;
|
|
|
+ for (Long seLong : seLongs) {
|
|
|
+ allNum += seLong;
|
|
|
+ }
|
|
|
+ sumUp += allNum;
|
|
|
+ //计算每天需要学习多少节课
|
|
|
+ int Sec = (int) Math.ceil((double) allNum / dutyDays);
|
|
|
+ for (CalendarStudyVo clCalendarStudyVo : clCalendarStudyVos) {
|
|
|
+ for (DayStudyVo dayStudyVo : clCalendarStudyVo.getDayStudyList()) {
|
|
|
+ if (Arrays.asList(bo.getStudyCount()).contains(dayStudyVo.getStudyDay())){
|
|
|
+ if (dayStudyVo.getStudyCourseKnob() != null) {
|
|
|
+ dayStudyVo.setStudyCourseKnob(dayStudyVo.getStudyCourseKnob() + Sec);
|
|
|
+ }else {
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec));
|
|
|
+ }
|
|
|
+ dayStudyVo.setPerform(0);
|
|
|
+ List<DaySectionVo> daySectionList = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(dayStudyVo.getDaySectionList())) {
|
|
|
+ daySectionList = dayStudyVo.getDaySectionList();
|
|
|
+ }
|
|
|
+ DaySectionVo daySectionVo = new DaySectionVo();
|
|
|
+ daySectionVo.setGoodsId(aLong);
|
|
|
+ daySectionVo.setStudyGoodsKnob(Convert.toLong(Sec));
|
|
|
+ daySectionVo.setGoodsPerform(0);
|
|
|
+ daySectionList.add(daySectionVo);
|
|
|
+ dayStudyVo.setDaySectionList(daySectionList);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String s = JSON.toJSONString(clCalendarStudyVos);
|
|
|
+ String s1 = JSON.toJSONString(bo.getStudyCount());
|
|
|
+ userPlan.setUserId(bo.getUserId());
|
|
|
+ userPlan.setSchedule(s);
|
|
|
+ userPlan.setStudyCount(s1);
|
|
|
+ userPlan.setPitchNum(sumUp);
|
|
|
+ userPlan.setStudyDay(bo.getStudyDay());
|
|
|
+ userPlan.setStudyNum(0L);
|
|
|
+ userPlan.setCreateTime(DateUtils.getNowTime());
|
|
|
+ userPlan.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ userPlan.setExamDate(bo.getExamDate());
|
|
|
+ userPlan.setStatus(1);
|
|
|
+ userPlan.setUserId(bo.getUserId());
|
|
|
+ userPlan.setStartTime(bo.getStartTime());
|
|
|
+ userPlan.setEndTime(bo.getEndTime());
|
|
|
+ userPlan.setReminderTime(bo.getReminderTime());
|
|
|
+ userPlan.setPlanId(bo.getPlanId());
|
|
|
+ this.updateById(userPlan);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -113,9 +276,123 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public UserPlanVo listPlan(UserPlanEditBo bo) {
|
|
|
+ public UserPlanVo listPlan(UserPlanEditBo bo) throws ParseException {
|
|
|
validEntityPlanBeforeSave(bo);
|
|
|
- return null;
|
|
|
+ UserPlanVo userPlanVo = new UserPlanVo();
|
|
|
+ List<CalendarStudyVo> clCalendarStudyVos = findDates(bo.getStartTime(),bo.getEndTime());
|
|
|
+ for (Long aLong : bo.getGoodsId()) {
|
|
|
+ //最近考试时间七天前到现在的天数,学习视频时长
|
|
|
+ Date date1 = new Date(bo.getEndTime() * 1000L);
|
|
|
+ //获得相隔天数
|
|
|
+ int dutyDays = getDutyDays(new Date(), date1, bo.getStudyCount(), bo.getStudyDay());
|
|
|
+
|
|
|
+ List<Long> seLongs = baseMapper.selectGoods(aLong);
|
|
|
+ Long allNum = 0L;
|
|
|
+ for (Long seLong : seLongs) {
|
|
|
+ allNum += seLong;
|
|
|
+ }
|
|
|
+ //计算每天需要学习多少节课
|
|
|
+ int Sec = (int) Math.ceil((double) allNum / dutyDays);
|
|
|
+ for (CalendarStudyVo clCalendarStudyVo : clCalendarStudyVos) {
|
|
|
+ for (DayStudyVo dayStudyVo : clCalendarStudyVo.getDayStudyList()) {
|
|
|
+ if (Arrays.asList(bo.getStudyCount()).contains(dayStudyVo.getStudyDay())){
|
|
|
+ if (dayStudyVo.getStudyCourseKnob() != null) {
|
|
|
+ dayStudyVo.setStudyCourseKnob(dayStudyVo.getStudyCourseKnob() + Sec);
|
|
|
+ }else {
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec));
|
|
|
+ }
|
|
|
+ dayStudyVo.setPerform(0);
|
|
|
+ List<DaySectionVo> daySectionList = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(dayStudyVo.getDaySectionList())) {
|
|
|
+ daySectionList = dayStudyVo.getDaySectionList();
|
|
|
+ }
|
|
|
+ DaySectionVo daySectionVo = new DaySectionVo();
|
|
|
+ daySectionVo.setGoodsId(aLong);
|
|
|
+ daySectionVo.setStudyGoodsKnob(Convert.toLong(Sec));
|
|
|
+ daySectionVo.setGoodsPerform(0);
|
|
|
+ daySectionList.add(daySectionVo);
|
|
|
+ dayStudyVo.setDaySectionList(daySectionList);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userPlanVo.setCalendarStudyVo(clCalendarStudyVos);
|
|
|
+ userPlanVo.setStudyCourseKnob(clCalendarStudyVos.get(0).getDayStudyList().get(0).getStudyCourseKnob());
|
|
|
+ return userPlanVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获得日历
|
|
|
+ public static List<CalendarStudyVo> findDates(Long dBegin, Long dEnd) throws ParseException, java.text.ParseException {
|
|
|
+ Long timeStamp = System.currentTimeMillis(); //获取当前时间戳
|
|
|
+ SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String dBeginS = sdf.format(new Date(Long.parseLong(String.valueOf(dBegin*1000)))); // 时间戳转换成时间
|
|
|
+ String dEndS = sdf.format(new Date(Long.parseLong(String.valueOf(dEnd*1000)))); // 时间戳转换成时间
|
|
|
+
|
|
|
+ //日期工具类准备
|
|
|
+ DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
+ //设置开始时间
|
|
|
+ Calendar calBegin = Calendar.getInstance();
|
|
|
+ calBegin.setTime(format.parse(dBeginS));
|
|
|
+
|
|
|
+ //设置结束时间
|
|
|
+ Calendar calEnd = Calendar.getInstance();
|
|
|
+ calEnd.setTime(format.parse(dEndS));
|
|
|
+
|
|
|
+ //装返回的日期集合容器
|
|
|
+ List<CalendarStudyVo> Datelist = new ArrayList<CalendarStudyVo>();
|
|
|
+
|
|
|
+ CalendarStudyVo calendarStudyVo = new CalendarStudyVo();
|
|
|
+ List<DayStudyVo> dayStudyList = new ArrayList<>();
|
|
|
+ // 每次循环给calBegin日期加一天,直到calBegin.getTime()时间等于dEnd
|
|
|
+ while (format.parse(dEndS).after(calBegin.getTime())) {
|
|
|
+ // 根据日历的规则,为给定的日历字段添加或减去指定的时间量
|
|
|
+ calBegin.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ if (calendarStudyVo.getMonth() == null){
|
|
|
+ calendarStudyVo.setMonth(Convert.toLong(calBegin.get(java.util.Calendar.MONTH)+1));
|
|
|
+ calendarStudyVo.setYear(Convert.toLong(calBegin.get(java.util.Calendar.YEAR)));
|
|
|
+ }
|
|
|
+ if (calendarStudyVo.getMonth() != null && calendarStudyVo.getMonth() != (calBegin.get(java.util.Calendar.MONTH)+1)){
|
|
|
+ calendarStudyVo.setDayStudyList(dayStudyList);
|
|
|
+ Datelist.add(calendarStudyVo);
|
|
|
+ calendarStudyVo = new CalendarStudyVo();
|
|
|
+ dayStudyList = new ArrayList<>();
|
|
|
+ calendarStudyVo.setMonth(Convert.toLong(calBegin.get(java.util.Calendar.MONTH)+1));
|
|
|
+ calendarStudyVo.setYear(Convert.toLong(calBegin.get(java.util.Calendar.YEAR)));
|
|
|
+ }
|
|
|
+ DayStudyVo dayStudyVo = new DayStudyVo();
|
|
|
+ dayStudyVo.setDate(Convert.toLong(calBegin.get(Calendar.DATE)));
|
|
|
+ dayStudyVo.setStudyDay(Convert.toLong(calBegin.get(Calendar.DAY_OF_WEEK)-1));
|
|
|
+ dayStudyList.add(dayStudyVo);
|
|
|
+ }
|
|
|
+ calendarStudyVo.setDayStudyList(dayStudyList);
|
|
|
+ Datelist.add(calendarStudyVo);
|
|
|
+ System.out.println(Datelist);
|
|
|
+ return Datelist;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获得可用学习天数
|
|
|
+ private static int getDutyDays(Date startDateStr, Date endDateStr,Long[] longs,Long studyDay) {
|
|
|
+ int result = 0;
|
|
|
+ Date endDate = endDateStr;
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
+ c.setTime(endDate);
|
|
|
+ c.add(Calendar.DATE, - Convert.toInt(studyDay));
|
|
|
+ endDate = c.getTime();
|
|
|
+
|
|
|
+ Date startDate = startDateStr;
|
|
|
+
|
|
|
+ while (startDate.compareTo(endDate) <= 0) {
|
|
|
+ for (Long integer : longs) {
|
|
|
+ if (startDate.getDay() != integer) {
|
|
|
+ result++;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ startDate.setDate(startDate.getDate() + 1);
|
|
|
+ }
|
|
|
+ return result-1;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -135,6 +412,5 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
|
|
|
if (rank > 0){
|
|
|
throw new IllegalArgumentException("此网课学习计划正在进行中,若想再次制定请将计划完成或删除");
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|