|
|
@@ -675,7 +675,278 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public boolean editPlan(UserPlanAddBo bo) {
|
|
|
+ public boolean editPlan(UserPlanQueryBo bo) throws ParseException {
|
|
|
+ List<UserPlan> userPlans = baseMapper.selectByUserPlan(bo);
|
|
|
+ if (CollectionUtils.isEmpty(userPlans)){
|
|
|
+ throw new IllegalArgumentException("没有该计划");
|
|
|
+ }
|
|
|
+ UserPlan userPlan = userPlans.get(0);
|
|
|
+
|
|
|
+ //得到日历日期
|
|
|
+ List<CalendarStudyVo> calendarStudyVos = JSONObject.parseArray(userPlan.getSchedule(), CalendarStudyVo.class);
|
|
|
+
|
|
|
+ //获得计划的课程
|
|
|
+ List<UserPlanCource> userPlanClsList = baseMapper.selectCourse(userPlan.getPlanId());
|
|
|
+ //初始化需要得到的数组
|
|
|
+ Integer[] array = new Integer[userPlanClsList.size()];
|
|
|
+ //使用for循环得到数组
|
|
|
+ for (int i = 0; i < userPlanClsList.size(); i++) {
|
|
|
+ array[i] = Convert.toInt(userPlanClsList.get(i).getSourceId());
|
|
|
+ }
|
|
|
+ bo.setCourseId(array);
|
|
|
+ List<CoursePlanVo> coursePlanVo = baseMapper.selectByListCourse(bo);
|
|
|
+
|
|
|
+ for (CoursePlanVo planVo : coursePlanVo) {
|
|
|
+ List<UserStudyRecord> studyCount = userStudyRecordService.selectUserStudy(bo.getUserId(), Convert.toInt(planVo.getCourseId()));
|
|
|
+ List<UserStudyRecord> myList = studyCount.stream().distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<Long> listId= baseMapper.selectByCourseId(planVo.getCourseId());
|
|
|
+ Map<Long,Long> listMap = new HashMap<>();
|
|
|
+ for (Long aLong : listId) {
|
|
|
+ listMap.put(aLong,planVo.getCourseId());
|
|
|
+ }
|
|
|
+ for (UserStudyRecord userStudyRecord : myList) {
|
|
|
+ listMap.remove(userStudyRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //最近考试时间七天前到现在的天数,学习视频时长
|
|
|
+ Date date1 = new Date(bo.getExamDate()*1000L);
|
|
|
+ //获得相隔天数
|
|
|
+ //得到学习的周
|
|
|
+ List<Long> cont = JSONObject.parseArray(userPlan.getStudyCount(), Long.class);
|
|
|
+ Long[] longs = new Long[cont.size()];
|
|
|
+ cont.toArray(longs);
|
|
|
+
|
|
|
+ int dutyDays = getDutyDays(new Date(), date1,longs,7L);
|
|
|
+
|
|
|
+ //计算每天需要学习多少节课
|
|
|
+
|
|
|
+ int Sec = (int)Math.ceil((double)listMap.size()/dutyDays);
|
|
|
+
|
|
|
+ //总节数
|
|
|
+ Integer sectionNum = listMap.size();
|
|
|
+ if(sectionNum <= 0){
|
|
|
+ throw new IllegalArgumentException("该课程没有节数,无法生成计划");
|
|
|
+ }
|
|
|
+
|
|
|
+ //key和value都循环
|
|
|
+ for(Map.Entry<Long,Long> entry : listMap.entrySet()) {
|
|
|
+ listId.add(entry.getKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ //获得今天日期,将每天节数写入
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ int year = cal.get(Calendar.YEAR);
|
|
|
+ Integer month = 0;
|
|
|
+ //将原有的月份添加课程的节数
|
|
|
+ for (CalendarStudyVo calendarStudyVo : calendarStudyVos) {
|
|
|
+ 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;
|
|
|
+ Map<Long, Long> courseDayMap = dayStudyVo.getCourseDayMap();
|
|
|
+ courseDayMap.put(planVo.getCourseId(),Convert.toLong(Sec));
|
|
|
+ dayStudyVo.setCourseDayMap(courseDayMap);
|
|
|
+ //添加课程学习节ID
|
|
|
+ Map<Long,Long> sectionIdMap = new HashMap<>();
|
|
|
+ for (int i = 0; i < Sec; i++) {
|
|
|
+ if (listId.size() >= Sec) {
|
|
|
+ sectionIdMap.put(listId.get(0),planVo.getCourseId());
|
|
|
+ listId.remove(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dayStudyVo.setSectionIdMap(sectionIdMap);
|
|
|
+ dayStudyVo.setPerform(0);
|
|
|
+ }else if (Sec >= sectionNum){
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum)+dayStudyVo.getStudyCourseKnob());
|
|
|
+ sectionNum = 0;
|
|
|
+ dayStudyVo.setPerform(0);
|
|
|
+ Map<Long, Long> courseDayMap = dayStudyVo.getCourseDayMap();
|
|
|
+ courseDayMap.put(planVo.getCourseId(),Convert.toLong(Sec));
|
|
|
+ //添加课程学习节ID
|
|
|
+ Map<Long,Long> sectionIdMap = new HashMap<>();
|
|
|
+ for (Long aLong : listId) {
|
|
|
+ sectionIdMap.put(aLong,planVo.getCourseId());
|
|
|
+ }
|
|
|
+ dayStudyVo.setSectionIdMap(sectionIdMap);
|
|
|
+ dayStudyVo.setCourseDayMap(courseDayMap);
|
|
|
+ }
|
|
|
+ }else if(calendarStudyVo.getMonth() != (cal.get(Calendar.MONTH) + 1) && ifTrue(dayStudyVo.getStudyDay(),longs)){
|
|
|
+ if (Sec < sectionNum) {
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec)+dayStudyVo.getStudyCourseKnob());
|
|
|
+
|
|
|
+ Map<Long, Long> courseDayMap = dayStudyVo.getCourseDayMap();
|
|
|
+ courseDayMap.put(planVo.getCourseId(),Convert.toLong(Sec));
|
|
|
+ dayStudyVo.setCourseDayMap(courseDayMap);
|
|
|
+ dayStudyVo.setPerform(0);
|
|
|
+ //添加课程学习节ID
|
|
|
+ Map<Long,Long> sectionIdMap = new HashMap<>();
|
|
|
+ for (int i = 0; i < Sec; i++) {
|
|
|
+ if (listId.size() >= Sec) {
|
|
|
+ sectionIdMap.put(listId.get(0),planVo.getCourseId());
|
|
|
+ listId.remove(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dayStudyVo.setSectionIdMap(sectionIdMap);
|
|
|
+ sectionNum = sectionNum-Sec;
|
|
|
+ }else if (Sec >= sectionNum){
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum)+dayStudyVo.getStudyCourseKnob());
|
|
|
+ Map<Long, Long> courseDayMap = dayStudyVo.getCourseDayMap();
|
|
|
+ courseDayMap.put(planVo.getCourseId(),Convert.toLong(Sec));
|
|
|
+ dayStudyVo.setCourseDayMap(courseDayMap);
|
|
|
+ dayStudyVo.setPerform(0);
|
|
|
+ //添加课程学习节ID
|
|
|
+ Map<Long,Long> sectionIdMap = new HashMap<>();
|
|
|
+ for (Long aLong : listId) {
|
|
|
+ sectionIdMap.put(aLong,planVo.getCourseId());
|
|
|
+ }
|
|
|
+ dayStudyVo.setSectionIdMap(sectionIdMap);
|
|
|
+ sectionNum = 0;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //原有课程不满足课程节数则再创建课程
|
|
|
+ if (sectionNum != 0){
|
|
|
+ while (sectionNum != 0 ) {
|
|
|
+ if (CollectionUtils.isEmpty(calendarStudyVos)) {
|
|
|
+ month = cal.get(Calendar.MONTH)+1;
|
|
|
+ }else {
|
|
|
+ ++month;
|
|
|
+ }
|
|
|
+ Long firstDayOfMonth = getFirstDayOfMonth(month);
|
|
|
+ Long lastDayOfMonth = getLastDayOfMonth(month);
|
|
|
+
|
|
|
+ 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;
|
|
|
+ Map<Long, Long> courseDayMap = dayStudyVo.getCourseDayMap();
|
|
|
+ if (courseDayMap == null) {
|
|
|
+ courseDayMap = new HashMap<>();
|
|
|
+ }
|
|
|
+ courseDayMap.put(planVo.getCourseId(),Convert.toLong(Sec));
|
|
|
+ dayStudyVo.setCourseDayMap(courseDayMap);
|
|
|
+ //添加课程学习节ID
|
|
|
+ Map<Long,Long> sectionIdMap = dayStudyVo.getSectionIdMap();
|
|
|
+ if (sectionIdMap == null) {
|
|
|
+ courseDayMap = new HashMap<>();
|
|
|
+ }
|
|
|
+ for (int i = 0; i < Sec; i++) {
|
|
|
+ if (listId.size() >= Sec) {
|
|
|
+ sectionIdMap.put(listId.get(0),planVo.getCourseId());
|
|
|
+ listId.remove(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dayStudyVo.setSectionIdMap(sectionIdMap);
|
|
|
+ dayStudyVo.setPerform(0);
|
|
|
+ }else if (Sec >= sectionNum){
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum));
|
|
|
+ Map<Long, Long> courseDayMap = dayStudyVo.getCourseDayMap();
|
|
|
+ if (courseDayMap == null) {
|
|
|
+ courseDayMap = new HashMap<>();
|
|
|
+ }
|
|
|
+ courseDayMap.put(planVo.getCourseId(),Convert.toLong(Sec));
|
|
|
+ dayStudyVo.setCourseDayMap(courseDayMap);
|
|
|
+
|
|
|
+ //添加课程学习节ID
|
|
|
+ Map<Long,Long> sectionIdMap = dayStudyVo.getSectionIdMap();
|
|
|
+ if (sectionIdMap == null) {
|
|
|
+ courseDayMap = new HashMap<>();
|
|
|
+ }
|
|
|
+ for (int i = 0; i < Sec; i++) {
|
|
|
+ if (listId.size() >= Sec) {
|
|
|
+ sectionIdMap.put(listId.get(0),planVo.getCourseId());
|
|
|
+ listId.remove(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dayStudyVo.setSectionIdMap(sectionIdMap);
|
|
|
+ sectionNum = 0;
|
|
|
+ dayStudyVo.setPerform(0);
|
|
|
+ }
|
|
|
+ }else if(month != (cal.get(Calendar.MONTH) + 1) && ifTrue(dayStudyVo.getStudyDay(),longs)){
|
|
|
+ if (Sec < sectionNum) {
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec));
|
|
|
+ sectionNum = sectionNum-Sec;
|
|
|
+ Map<Long, Long> courseDayMap = dayStudyVo.getCourseDayMap();
|
|
|
+ if (courseDayMap == null) {
|
|
|
+ courseDayMap = new HashMap<>();
|
|
|
+ }
|
|
|
+ courseDayMap.put(planVo.getCourseId(),Convert.toLong(Sec));
|
|
|
+ dayStudyVo.setCourseDayMap(courseDayMap);
|
|
|
+
|
|
|
+ //添加课程学习节ID
|
|
|
+ Map<Long,Long> sectionIdMap = dayStudyVo.getSectionIdMap();
|
|
|
+ if (sectionIdMap == null) {
|
|
|
+ courseDayMap = new HashMap<>();
|
|
|
+ }
|
|
|
+ for (int i = 0; i < Sec; i++) {
|
|
|
+ if (listId.size() >= Sec) {
|
|
|
+ sectionIdMap.put(listId.get(0),planVo.getCourseId());
|
|
|
+ listId.remove(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dayStudyVo.setSectionIdMap(sectionIdMap);
|
|
|
+ dayStudyVo.setPerform(0);
|
|
|
+ }else if (Sec >= sectionNum){
|
|
|
+ dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum));
|
|
|
+ Map<Long, Long> courseDayMap = dayStudyVo.getCourseDayMap();
|
|
|
+ if (courseDayMap == null) {
|
|
|
+ courseDayMap = new HashMap<>();
|
|
|
+ }
|
|
|
+ courseDayMap.put(planVo.getCourseId(),Convert.toLong(Sec));
|
|
|
+ dayStudyVo.setCourseDayMap(courseDayMap);
|
|
|
+ sectionNum = 0;
|
|
|
+
|
|
|
+ //添加课程学习节ID
|
|
|
+ Map<Long,Long> sectionIdMap = dayStudyVo.getSectionIdMap();
|
|
|
+ if (sectionIdMap == null) {
|
|
|
+ courseDayMap = new HashMap<>();
|
|
|
+ }
|
|
|
+ for (int i = 0; i < Sec; i++) {
|
|
|
+ if (listId.size() >= Sec) {
|
|
|
+ sectionIdMap.put(listId.get(0),planVo.getCourseId());
|
|
|
+ listId.remove(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dayStudyVo.setSectionIdMap(sectionIdMap);
|
|
|
+ dayStudyVo.setPerform(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CalendarStudyVo calendarStudyVo = new CalendarStudyVo();
|
|
|
+ calendarStudyVo.setYear(Convert.toLong(year));
|
|
|
+ calendarStudyVo.setMonth(Convert.toLong(month));
|
|
|
+ calendarStudyVo.setDayStudyList(dayStudyVos);
|
|
|
+ List<CalendarStudyVo> calendarStudyVo1 = calendarStudyVos;
|
|
|
+ calendarStudyVo1.add(calendarStudyVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ UserPlan userPlan1 = new UserPlan();
|
|
|
+ userPlan1.setPlanId(userPlan.getPlanId());
|
|
|
+ String calendar = JSON.toJSONString(calendarStudyVos);
|
|
|
+ userPlan1.setSchedule(calendar);
|
|
|
+ userPlan1.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ int i = baseMapper.updateById(userPlan1);
|
|
|
+
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|