Ver código fonte

首页日历

change 4 anos atrás
pai
commit
eebcdb82cc

+ 108 - 19
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/impl/UserPlanServiceImpl.java

@@ -386,43 +386,132 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
     public UserPlanVo userPlanSeven(UserPlanQueryBo bo) {
         List<UserPlan> userPlans = baseMapper.selectByUserPlan(bo);
         UserPlanVo userPlanVos = new UserPlanVo();
+        Calendar cal = Calendar.getInstance();
         if (!CollectionUtils.isEmpty(userPlans)) {
             UserPlan userPlan = userPlans.get(0);
-            Calendar cal = Calendar.getInstance();
 
             //得到日历日期
             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);
+            //获得计划的课程
+            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);
 
             userPlanVos.setCoursePlanVo(coursePlanVo);
             List<DayStudyVo> dayStudyVos = new ArrayList<>();
-            calendarStudyVos.stream().filter(c -> c.getMonth() == cal.get(Calendar.MONTH + 1)).forEach(c -> {
-                List<DayStudyVo> collect = c.getDayStudyList().stream()
-                        .filter(v -> v.getDate() < 7 + cal.get(Calendar.DAY_OF_MONTH) || v.getDate() > cal.get(Calendar.DAY_OF_MONTH) - 7)
-                        .collect(Collectors.toList());
+            List<DayStudyVo> finalDayStudyVos = dayStudyVos;
+            calendarStudyVos.stream().filter(c -> c.getMonth() == (cal.get(Calendar.MONTH)+1))
+                   .forEach(c -> {
+                       finalDayStudyVos.addAll(c.getDayStudyList().stream()
+                        .filter(v -> v.getDate() < 7 + cal.get(Calendar.DAY_OF_MONTH) && v.getDate() > cal.get(Calendar.DAY_OF_MONTH) - 7)
+                        .collect(Collectors.toList()));
+            });
+            switch (cal.get(Calendar.DAY_OF_WEEK)- 1){
+                case 0:
+                    dayStudyVos=finalDayStudyVos.stream()
+                            .filter(v -> v.getDate() <= cal.get(Calendar.DAY_OF_MONTH) + 7)
+                            .collect(Collectors.toList());
+                    break;
+                case 1:
+                    dayStudyVos=finalDayStudyVos.stream()
+                            .filter(v ->  v.getDate() < 6 + cal.get(Calendar.DAY_OF_MONTH) && v.getDate() >= cal.get(Calendar.DAY_OF_MONTH) -1)
+                            .collect(Collectors.toList());
+                    break;
+                case 2:
+                    dayStudyVos=finalDayStudyVos.stream()
+                            .filter(v ->  v.getDate() < 5 + cal.get(Calendar.DAY_OF_MONTH) && v.getDate() >= cal.get(Calendar.DAY_OF_MONTH) - 2)
+                            .collect(Collectors.toList());
+                    break;
+                case 3:
+                    dayStudyVos=finalDayStudyVos.stream()
+                            .filter(v ->  v.getDate() < 4 + cal.get(Calendar.DAY_OF_MONTH) && v.getDate() > cal.get(Calendar.DAY_OF_MONTH) - 3)
+                            .collect(Collectors.toList());
+                    break;
+                case 4:
+                    dayStudyVos=finalDayStudyVos.stream()
+                            .filter(v ->  v.getDate() < 3 + cal.get(Calendar.DAY_OF_MONTH) && v.getDate() > cal.get(Calendar.DAY_OF_MONTH) - 4)
+                            .collect(Collectors.toList());
+                    break;
+                case 5:
+                    dayStudyVos=finalDayStudyVos.stream()
+                            .filter(v ->  v.getDate() < 2 + cal.get(Calendar.DAY_OF_MONTH) && v.getDate() > cal.get(Calendar.DAY_OF_MONTH) - 5)
+                            .collect(Collectors.toList());
+                    break;
+                case 6:
+                    dayStudyVos=finalDayStudyVos.stream()
+                            .filter(v ->  v.getDate() < 1 + cal.get(Calendar.DAY_OF_MONTH) && v.getDate() > cal.get(Calendar.DAY_OF_MONTH) - 6)
+                            .collect(Collectors.toList());
+                    break;
+            }
+            List<DayStudyVo> finalDayStudyVos1 = dayStudyVos;
+            calendarStudyVos.stream().forEach(c -> {
+                c.setDayStudyList(finalDayStudyVos1);
             });
             userPlanVos.setCalendarStudyVo(calendarStudyVos);
+        }else {
+            //得到日历日期
+            List<CalendarStudyVo> calendarStudyVos = new ArrayList<>();
+            Long firstDayOfMonth = getFirstDayOfMonth(cal.get(Calendar.MONTH)+1);
+            Long lastDayOfMonth = getLastDayOfMonth(cal.get(Calendar.MONTH)+1);
+            List<DayStudyVo> dayStudyVos = getDays(firstDayOfMonth,lastDayOfMonth);
+            switch (cal.get(Calendar.DAY_OF_WEEK)- 1){
+                case 0:
+                    dayStudyVos=dayStudyVos.stream()
+                            .filter(v -> v.getDate() <= cal.get(Calendar.DAY_OF_MONTH) + 7)
+                            .collect(Collectors.toList());
+                    break;
+                case 1:
+                    dayStudyVos=dayStudyVos.stream()
+                            .filter(v ->  v.getDate() < 6 + cal.get(Calendar.DAY_OF_MONTH) && v.getDate() >= cal.get(Calendar.DAY_OF_MONTH) -1)
+                            .collect(Collectors.toList());
+                    break;
+                case 2:
+                    dayStudyVos=dayStudyVos.stream()
+                            .filter(v ->  v.getDate() < 5 + cal.get(Calendar.DAY_OF_MONTH) && v.getDate() >= cal.get(Calendar.DAY_OF_MONTH) - 2)
+                            .collect(Collectors.toList());
+                    break;
+                case 3:
+                    dayStudyVos=dayStudyVos.stream()
+                            .filter(v ->  v.getDate() < 4 + cal.get(Calendar.DAY_OF_MONTH) && v.getDate() > cal.get(Calendar.DAY_OF_MONTH) - 3)
+                            .collect(Collectors.toList());
+                    break;
+                case 4:
+                    dayStudyVos=dayStudyVos.stream()
+                            .filter(v ->  v.getDate() < 3 + cal.get(Calendar.DAY_OF_MONTH) && v.getDate() > cal.get(Calendar.DAY_OF_MONTH) - 4)
+                            .collect(Collectors.toList());
+                    break;
+                case 5:
+                    dayStudyVos=dayStudyVos.stream()
+                            .filter(v ->  v.getDate() < 2 + cal.get(Calendar.DAY_OF_MONTH) && v.getDate() > cal.get(Calendar.DAY_OF_MONTH) - 5)
+                            .collect(Collectors.toList());
+                    break;
+                case 6:
+                    dayStudyVos=dayStudyVos.stream()
+                            .filter(v ->  v.getDate() < 1 + cal.get(Calendar.DAY_OF_MONTH) && v.getDate() > cal.get(Calendar.DAY_OF_MONTH) - 6)
+                            .collect(Collectors.toList());
+                    break;
+            }
+            CalendarStudyVo calendarStudyVo = new CalendarStudyVo();
+            calendarStudyVo.setDayStudyList(dayStudyVos);
+            calendarStudyVo.setYear(Convert.toLong(cal.get(Calendar.YEAR)));
+            calendarStudyVo.setMonth(Convert.toLong(cal.get(Calendar.MONTH)+1));
+            calendarStudyVos.add(calendarStudyVo);
+            userPlanVos.setCalendarStudyVo(calendarStudyVos);
         }
 
         
         return userPlanVos;
     }
 
-    public static void main(String[] args) {
-        Calendar cal = Calendar.getInstance();
-        System.out.println();
-    }
+
 
     private UserPlanVo generateSelfBo(UserPlanQueryBo bo) throws ParseException {
 

+ 40 - 10
zhongzheng-system/src/main/resources/mapper/modules/user/UserPlanMapper.xml

@@ -46,22 +46,52 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <select id="selectByCourse" parameterType="com.zhongzheng.modules.user.bo.UserPlanQueryBo"  resultMap="CourseResult">
-        SELECT rs.*,sum(section_num) as section_num,count(chapter_id)
-        as chapter_num,mc.category_name,mc.category_id,sum(total_time) as duration from
-        (SELECT c.*,count(cs.section_id) as section_num,cs.chapter_id,IFNULL(sum(cs.video_time),0) as total_time
-        FROM course c LEFT JOIN course_chapter cc on c.course_id = cc.course_id
-        LEFT JOIN course_section cs
-        on cc.chapter_id = cs.chapter_id
-        WHERE 1=1
+        SELECT
+        rs.course_id,
+        rs.category_id,
+        rs.price,
+        rs.duration,
+        rs.start_time,
+        rs.end_time,
+        rs.cover_url,
+        rs.introduction,
+        rs.create_time,
+        rs.update_time,
+        rs.STATUS,
+        rs.teacher_ids,
+        rs.course_name,
+        sum( rs.section_num ) AS section_num,
+        count( rs.chapter_id ) AS chapter_num,
+        mc.category_name,
+        mc.category_id,
+        sum( rs.total_time ) AS duration
+        FROM
+        (
+        SELECT
+        c.*,
+        count( cs.section_id ) AS section_num,
+        cs.chapter_id,
+        IFNULL( sum( cs.video_time ), 0 ) AS total_time
+        FROM
+        course c
+        LEFT JOIN course_chapter cc ON c.course_id = cc.course_id
+        LEFT JOIN course_section cs ON cc.chapter_id = cs.chapter_id
+        WHERE
+        1 = 1
         <if test="courseId != null and courseId !=''">
             and c.course_id in
             <foreach collection="courseId" open="(" separator="," close=")" item="courseId">
                 #{courseId}
             </foreach>
         </if>
-        GROUP BY cs.chapter_id,c.course_id)rs LEFT JOIN major_category mc on rs.category_id = mc.category_id
-        GROUP BY course_id
-        limit 1
+        GROUP BY
+        cs.chapter_id,
+        c.course_id
+        ) rs
+        LEFT JOIN major_category mc ON rs.category_id = mc.category_id
+        GROUP BY
+        course_id
+        LIMIT 1
     </select>
 
     <select id="selectByExam" parameterType="Long"  resultMap="ExamArrangementTimeResult">