|
@@ -4,9 +4,13 @@ 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.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,7 +24,9 @@ import com.zhongzheng.modules.user.mapper.UserPlanMapper;
|
|
|
import com.zhongzheng.modules.user.vo.UserPlanVo;
|
|
|
import com.zhongzheng.modules.user.service.IUserPlanService;
|
|
|
|
|
|
+import java.text.DateFormat;
|
|
|
import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -111,15 +117,15 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public UserPlanVo listPlan(UserPlanEditBo bo) {
|
|
|
+ public UserPlanVo listPlan(UserPlanEditBo bo) throws ParseException {
|
|
|
validEntityPlanBeforeSave(bo);
|
|
|
UserPlanVo userPlanVo = new UserPlanVo();
|
|
|
+ List<CalendarStudyVo> clCalendarStudyVos = findDates(bo.getStartTime(),bo.getEndTime());
|
|
|
for (Long aLong : bo.getGoodsId()) {
|
|
|
//最近考试时间七天前到现在的天数,学习视频时长
|
|
|
Date date1 = new Date(bo.getEndTime() * 1000L);
|
|
|
//获得相隔天数
|
|
|
- Long[] longs = {1L, 2L, 3L, 4L, 5L, 6L};
|
|
|
- int dutyDays = getDutyDays(new Date(), date1, longs, bo.getStudyDay());
|
|
|
+ int dutyDays = getDutyDays(new Date(), date1, bo.getStudyCount(), bo.getStudyDay());
|
|
|
|
|
|
List<Long> seLongs = baseMapper.selectGoods(aLong);
|
|
|
Long allNum = 0L;
|
|
@@ -128,10 +134,86 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
|
|
|
}
|
|
|
//计算每天需要学习多少节课
|
|
|
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);
|
|
|
}
|
|
|
- return null;
|
|
|
+ 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;
|