Jelajahi Sumber

计划逻辑修改

change 4 tahun lalu
induk
melakukan
56992ed363

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/mapper/UserPlanMapper.java

@@ -30,4 +30,6 @@ public interface UserPlanMapper extends BaseMapper<UserPlan> {
     List<UserPlanCource> selectCourse(Long planId);
 
     Integer selectCountCourse(UserPlanQueryBo bo);
+
+    List<Long> selectByCourseId(Long courseId);
 }

+ 173 - 10
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/impl/UserPlanServiceImpl.java

@@ -31,6 +31,7 @@ import com.zhongzheng.modules.user.bo.UserPlanEditBo;
 import com.zhongzheng.modules.user.domain.UserPlan;
 import com.zhongzheng.modules.user.mapper.UserPlanMapper;
 import com.zhongzheng.modules.user.service.IUserPlanService;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.text.DateFormat;
 import java.text.ParseException;
@@ -134,6 +135,7 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public UserPlanVo generate(UserPlanQueryBo bo) throws ParseException {
         //判断是否课程已被生成过课程
         Integer rank = baseMapper.selectCountCourse(bo);
@@ -314,12 +316,18 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                     }
                     //更新当天学习节数是否已经完成
                     List<UserStudyRecord> collect = studyCount.stream().filter(v -> v.getCourseId().equals(s.getCourseId())).collect(Collectors.toList());
-                    if (s.getStudyGoal() != null &&collect.size() >= b.getStudyGoal()) {
+                    if (s.getStudyGoal() != null && collect.size() >= b.getStudyGoal() ) {
                         calendarStudyVos.stream().filter(c -> c.getMonth() == cal.get(Calendar.MONTH) + 1).forEach(c -> {
                             c.getDayStudyList().stream()
                                     .forEach(d -> {
                                         if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate() == cal.get(Calendar.DAY_OF_MONTH) && d.getPerform() == 0) {
-                                            d.setPerform(1);
+                                            Map<Long, Long> sectionIdMap = d.getSectionIdMap();
+                                            for (UserStudyRecord userStudyRecord : collect) {
+                                                sectionIdMap.remove(userStudyRecord.getSectionId());
+                                            }
+                                            if (sectionIdMap.isEmpty()) {
+                                                d.setPerform(1);
+                                            }
                                         }
                                         if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate() < cal.get(Calendar.DAY_OF_MONTH) && d.getPerform() == 0) {
                                             d.setPerform(2);
@@ -490,14 +498,20 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                 }
                 //更新当天学习节数是否已经完成
                 List<UserStudyRecord> collect = studyCount.stream().filter(v -> v.getCourseId().equals(s.getCourseId())).collect(Collectors.toList());
-                if (s.getStudyGoal() != null && collect.size() >= s.getStudyGoal()){
-                    calendarStudyVos.stream().filter(c -> c.getMonth()==cal.get(Calendar.MONTH) + 1).forEach(c -> {
+                if (s.getStudyGoal() != null && collect.size() >= s.getStudyGoal() ) {
+                    calendarStudyVos.stream().filter(c -> c.getMonth() == cal.get(Calendar.MONTH) + 1).forEach(c -> {
                         c.getDayStudyList().stream()
                                 .forEach(d -> {
-                                    if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate()== cal.get(Calendar.DAY_OF_MONTH) && d.getPerform() == 0){
-                                        d.setPerform(1);
+                                    if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate() == cal.get(Calendar.DAY_OF_MONTH) && d.getPerform() == 0) {
+                                        Map<Long, Long> sectionIdMap = d.getSectionIdMap();
+                                        for (UserStudyRecord userStudyRecord : collect) {
+                                            sectionIdMap.remove(userStudyRecord.getSectionId());
+                                        }
+                                        if (sectionIdMap.isEmpty()) {
+                                            d.setPerform(1);
+                                        }
                                     }
-                                    if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate()< cal.get(Calendar.DAY_OF_MONTH) && d.getPerform() == 0){
+                                    if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate() < cal.get(Calendar.DAY_OF_MONTH) && d.getPerform() == 0) {
                                         d.setPerform(2);
                                     }
                                 });
@@ -660,7 +674,8 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
         if(sectionNum <= 0){
             throw new IllegalArgumentException("该课程没有节数,无法生成计划");
         }
-
+        //查出节的ID
+        List<Long> listId= baseMapper.selectByCourseId(planVo.getCourseId());
         //获得今天日期,将每天节数写入
         Calendar cal = Calendar.getInstance();
         int year = cal.get(Calendar.YEAR);
@@ -681,6 +696,15 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                         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());
@@ -688,6 +712,12 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                         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)){
@@ -698,7 +728,15 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                         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());
@@ -706,7 +744,12 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                         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;
 
                     }
@@ -740,6 +783,18 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                             }
                             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));
@@ -749,6 +804,19 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                             }
                             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);
                         }
@@ -762,6 +830,19 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                             }
                             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));
@@ -772,6 +853,19 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                             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);
                         }
                     }
@@ -817,6 +911,8 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
             throw new IllegalArgumentException("该课程没有节数,无法生成计划");
         }
         userPlanVo.setPitchNum(Convert.toLong(sectionNum));
+        //查出节的ID
+        List<Long> listId= baseMapper.selectByCourseId(coursePlanVo.getCourseId());
 
         //获得今天日期,将每天节数写入
         List<CalendarStudyVo> calendarStudyVos = new ArrayList<>();
@@ -851,6 +947,15 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                         Map<Long,Long> studyDstudyVo = new HashMap<Long, Long>();
                         studyDstudyVo.put(coursePlanVo.getCourseId(),Convert.toLong(Sec));
                         dayStudyVo.setCourseDayMap(studyDstudyVo);
+                        //添加课程学习节ID
+                        Map<Long,Long> sectionIdMap = new HashMap<>();
+                        for (int i = 0; i < Sec; i++) {
+                            if (listId.size() >= Sec) {
+                                sectionIdMap.put(listId.get(0),coursePlanVo.getCourseId());
+                                listId.remove(0);
+                            }
+                        }
+                        dayStudyVo.setSectionIdMap(sectionIdMap);
                         dayStudyVo.setPerform(0);
                     }else if (Sec >= sectionNum){
                         dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum));
@@ -858,6 +963,12 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                         Map<Long,Long> studyDstudyVo = new HashMap<Long, Long>();
                         studyDstudyVo.put(coursePlanVo.getCourseId(),Convert.toLong(Sec));
                         dayStudyVo.setCourseDayMap(studyDstudyVo);
+                        //添加课程学习节ID
+                        Map<Long,Long> sectionIdMap = new HashMap<>();
+                        for (Long aLong : listId) {
+                            sectionIdMap.put(aLong,coursePlanVo.getCourseId());
+                        }
+                        dayStudyVo.setSectionIdMap(sectionIdMap);
                         dayStudyVo.setPerform(0);
                     }
                 }else if(month != (cal.get(Calendar.MONTH) + 1) && ifTrue(dayStudyVo.getStudyDay(),longs)){
@@ -867,6 +978,15 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                         Map<Long,Long> studyDstudyVo = new HashMap<Long, Long>();
                         studyDstudyVo.put(coursePlanVo.getCourseId(),Convert.toLong(Sec));
                         dayStudyVo.setCourseDayMap(studyDstudyVo);
+                        //添加课程学习节ID
+                        Map<Long,Long> sectionIdMap = new HashMap<>();
+                        for (int i = 0; i < Sec; i++) {
+                            if (listId.size() >= Sec) {
+                                sectionIdMap.put(listId.get(0),coursePlanVo.getCourseId());
+                                listId.remove(0);
+                            }
+                        }
+                        dayStudyVo.setSectionIdMap(sectionIdMap);
                         dayStudyVo.setPerform(0);
                     }else if (Sec >= sectionNum){
                         dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum));
@@ -874,6 +994,12 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                         Map<Long,Long> studyDstudyVo = new HashMap<Long, Long>();
                         studyDstudyVo.put(coursePlanVo.getCourseId(),Convert.toLong(Sec));
                         dayStudyVo.setCourseDayMap(studyDstudyVo);
+                        //添加课程学习节ID
+                        Map<Long,Long> sectionIdMap = new HashMap<>();
+                        for (Long aLong : listId) {
+                            sectionIdMap.put(aLong,coursePlanVo.getCourseId());
+                        }
+                        dayStudyVo.setSectionIdMap(sectionIdMap);
                         dayStudyVo.setPerform(0);
                     }
                 }
@@ -925,6 +1051,9 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
         }
         userPlanVo.setPitchNum(Convert.toLong(sectionNum));
 
+        //查出节的ID
+        List<Long> listId= baseMapper.selectByCourseId(coursePlanVo.getCourseId());
+
         //获得今天日期,将每天节数写入
         List<CalendarStudyVo> calendarStudyVos = new ArrayList<>();
         Calendar cal = Calendar.getInstance();
@@ -955,32 +1084,66 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                     if (Sec < sectionNum) {
                         dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec));
                         dayStudyVo.setPerform(0);
+                        //添加课程节数
                         Map<Long,Long> studyDstudyVo = new HashMap<Long, Long>();
                         studyDstudyVo.put(coursePlanVo.getCourseId(),Convert.toLong(Sec));
                         dayStudyVo.setCourseDayMap(studyDstudyVo);
+                        //添加课程学习节ID
+                        Map<Long,Long> sectionIdMap = new HashMap<>();
+                        for (int i = 0; i < Sec; i++) {
+                            if (listId.size() >= Sec) {
+                                sectionIdMap.put(listId.get(0),coursePlanVo.getCourseId());
+                                listId.remove(0);
+                            }
+                        }
+                        dayStudyVo.setSectionIdMap(sectionIdMap);
                         sectionNum = sectionNum-Sec;
                     }else if (Sec >= sectionNum){
                         dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum));
                         dayStudyVo.setPerform(0);
+                        //添加课程节数
                         Map<Long,Long> studyDstudyVo = new HashMap<Long, Long>();
                         studyDstudyVo.put(coursePlanVo.getCourseId(),Convert.toLong(Sec));
                         dayStudyVo.setCourseDayMap(studyDstudyVo);
+                        //添加课程学习节ID
+                        Map<Long,Long> sectionIdMap = new HashMap<>();
+                        for (Long aLong : listId) {
+                            sectionIdMap.put(aLong,coursePlanVo.getCourseId());
+                        }
+                        dayStudyVo.setSectionIdMap(sectionIdMap);
                         sectionNum = 0;
                     }
                 }else if(month != (cal.get(Calendar.MONTH) + 1) && ifTrue(dayStudyVo.getStudyDay(),longs)){
                     if (Sec < sectionNum) {
                         dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec));
                         dayStudyVo.setPerform(0);
+                        //添加课程节数
                         Map<Long,Long> studyDstudyVo = new HashMap<Long, Long>();
                         studyDstudyVo.put(coursePlanVo.getCourseId(),Convert.toLong(Sec));
                         dayStudyVo.setCourseDayMap(studyDstudyVo);
+                        //添加课程学习节ID
+                        Map<Long,Long> sectionIdMap = new HashMap<>();
+                        for (int i = 0; i < Sec; i++) {
+                            if (listId.size() >= Sec) {
+                                sectionIdMap.put(listId.get(0),coursePlanVo.getCourseId());
+                                listId.remove(0);
+                            }
+                        }
+                        dayStudyVo.setSectionIdMap(sectionIdMap);
                         sectionNum = sectionNum-Sec;
                     }else if (Sec >= sectionNum){
                         dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum));
                         dayStudyVo.setPerform(0);
+                        //添加课程节数
                         Map<Long,Long> studyDstudyVo = new HashMap<Long, Long>();
                         studyDstudyVo.put(coursePlanVo.getCourseId(),Convert.toLong(Sec));
                         dayStudyVo.setCourseDayMap(studyDstudyVo);
+                        //添加课程学习节ID
+                        Map<Long,Long> sectionIdMap = new HashMap<>();
+                        for (Long aLong : listId) {
+                            sectionIdMap.put(aLong,coursePlanVo.getCourseId());
+                        }
+                        dayStudyVo.setSectionIdMap(sectionIdMap);
                         sectionNum = 0;
                     }
                 }

+ 6 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/vo/DayStudyVo.java

@@ -39,6 +39,12 @@ public class DayStudyVo {
     private Map<Long,Long> courseDayMap;
 
 
+
+    /** 完成相应课节数 */
+    @ApiModelProperty("完成相应课节数ID")
+    private Map<Long,Long> sectionIdMap;
+
+
 }
 
 

+ 16 - 0
zhongzheng-system/src/main/resources/mapper/modules/user/UserPlanMapper.xml

@@ -191,4 +191,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             and u.user_id = #{userId}
         </if>
     </select>
+
+
+    <select id="selectByCourseId" parameterType="map"  resultType="long">
+        SELECT
+        s.section_id
+        FROM
+        course_section s
+        LEFT JOIN course_chapter r ON  s.chapter_id = r.chapter_id
+        LEFT JOIN course c ON c.course_id = r.course_id
+        WHERE
+        1 = 1
+        <if test="courseId != null and courseId !=''">
+            AND c.course_id =#{courseId}
+        </if>
+        ORDER BY r.sort,s.sort ASC
+    </select>
 </mapper>