change 4 år sedan
förälder
incheckning
fef29986f4

+ 12 - 0
zhongzheng-api/src/main/java/com/zhongzheng/controller/activity/PlanController.java

@@ -88,4 +88,16 @@ public class PlanController extends BaseController {
         bo.setUserId(loginUser.getUser().getUserId());
         return toAjax(userPlanService.updateGenerate(bo) ? 1 : 0);
     }
+
+
+    /**
+     * 获得用户学习计划
+     */
+    @ApiOperation("用户未完成任务重新更新任务")
+    @PostMapping("/editPlan")
+    public AjaxResult<Void> editPlan(@RequestBody UserPlanAddBo bo) throws ParseException {
+        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
+        bo.setUserId(loginUser.getUser().getUserId());
+        return toAjax(userPlanService.editPlan(bo) ? 1 : 0);
+    }
 }

+ 1 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/mapper/UserStudyRecordMapper.java

@@ -18,5 +18,5 @@ public interface UserStudyRecordMapper extends BaseMapper<UserStudyRecord> {
 
     List<UserStudyRecordVo> selectList(UserStudyRecordQueryBo bo);
 
-    List<UserStudyRecord> selectUserStudy(@Param("userId") Long userId, @Param("courseId") Integer[] courseId, @Param("startTime") int timesMorning, @Param("endTime") int timesNight);
+    List<UserStudyRecord> selectUserStudy(@Param("userId") Long userId, @Param("courseId") Integer courseId);
 }

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/IUserPlanService.java

@@ -65,4 +65,6 @@ public interface IUserPlanService extends IService<UserPlan> {
 	Boolean updateGenerate(UserPlanAddBo bo) throws ParseException;
 
 	UserPlanVo userPlanSeven(UserPlanQueryBo bo);
+
+	boolean editPlan(UserPlanAddBo bo);
 }

+ 1 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/IUserStudyRecordService.java

@@ -53,5 +53,5 @@ public interface IUserStudyRecordService extends IService<UserStudyRecord> {
 	 */
 	Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
 
-    List<UserStudyRecord> selectUserStudy(Long userId, Integer[] courseId, int timesMorning,int timesNight);
+    List<UserStudyRecord> selectUserStudy(Long userId, Integer courseId);
 }

+ 112 - 74
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/impl/UserPlanServiceImpl.java

@@ -253,6 +253,7 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public List<UserPlanVo> userPlan(UserPlanQueryBo bo) {
         List<UserPlan> userPlans = baseMapper.selectByUserPlan(bo);
         List<UserPlanVo> userPlanVos = new ArrayList<>();
@@ -305,66 +306,81 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                                 }
                             });
                 });
+            });
 
+            //更新当天学习节数是否已经完成
+            //代表前面是否有未完成课程
+            Long studyNum = 0L;
+            boolean goal = true;
+            for (CoursePlanVo b : coursePlanVo) {
+                if (goal == false) {
+                    break;
+                }
+                List<UserStudyRecord> studyCount = userStudyRecordService.selectUserStudy(bo.getUserId(), Convert.toInt(b.getCourseId()));
+                List<UserStudyRecord> myList = studyCount.stream().distinct().collect(Collectors.toList());
+                studyNum= studyNum+Convert.toLong(myList.size());
                 //更新当天学习节数是否已经完成
-                //代表前面是否有未完成课程
-                List<UserStudyRecord> studyCount = userStudyRecordService.selectUserStudy(bo.getUserId(), array, getTimesmorning(), getTimesnight());
-                boolean goal = true;
-                for (CoursePlanVo b : coursePlanVo) {
-                    if (goal == false) {
-                        break;
-                    }
-                    //更新当天学习节数是否已经完成
-                    List<UserStudyRecord> collect = studyCount.stream().filter(v -> v.getCourseId().equals(s.getCourseId())).collect(Collectors.toList());
-                    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) {
-                                            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);
-                                        }
-                                    });
-                        });
-                    } else {
-                        calendarStudyVos.stream().filter(c -> c.getMonth() == cal.get(Calendar.MONTH) + 1).forEach(c -> {
-                            for (DayStudyVo d : c.getDayStudyList()) {
+                if (b.getStudyGoal() != null && studyCount.size() >= b.getStudyGoal() ) {
+                    for (CalendarStudyVo calendarStudyVo : calendarStudyVos) {
+                        if (calendarStudyVo.getMonth() == cal.get(Calendar.MONTH) + 1) {
+                            for (DayStudyVo d : calendarStudyVo.getDayStudyList()) {
+                                if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate() == cal.get(Calendar.DAY_OF_MONTH) && d.getPerform() == 0) {
+                                    if (d.getPerform() == 1){
+                                        break;
+                                    }
+                                    Map<Long, Long> sectionIdMap = d.getSectionIdMap();
+                                    for (UserStudyRecord userStudyRecord : studyCount) {
+                                        sectionIdMap.remove(userStudyRecord.getSectionId());
+                                    }
+                                    if (sectionIdMap.isEmpty()) {
+                                        d.setPerform(1);
+                                    } else {
+                                        d.setPerform(0);
+                                        goal = false;
+                                    }
+                                }
                                 if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate() < cal.get(Calendar.DAY_OF_MONTH) && d.getPerform() == 0) {
                                     d.setPerform(2);
                                 }
-                                if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate() == cal.get(Calendar.DAY_OF_MONTH)) {
-                                    d.setPerform(0);
-                                }
                             }
-                        });
-                        goal = false;
+                        }
+
                     }
 
-                    UserPlan userPlan1 = new UserPlan();
-                    userPlan1.setPlanId(s.getPlanId());
-                    String calendar = JSON.toJSONString(calendarStudyVos);
-                    userPlan1.setSchedule(calendar);
-                    userPlan1.setUpdateTime(DateUtils.getNowTime());
-                    baseMapper.updateById(userPlan1);
+                } else {
+                    for (CalendarStudyVo calendarStudyVo : calendarStudyVos) {
+                        for (DayStudyVo d : calendarStudyVo.getDayStudyList()) {
+                            if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate() < cal.get(Calendar.DAY_OF_MONTH) && d.getPerform() == 0) {
+                                d.setPerform(2);
+                            }
+                            if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate() == cal.get(Calendar.DAY_OF_MONTH)) {
+                                d.setPerform(0);
+                            }
+                        }
+                    }
+                    goal = false;
                 }
 
-                userPlanVo.setCoursePlanVo(coursePlanVo);
+            }
+            UserPlan userPlan1 = new UserPlan();
+            userPlan1.setPlanId(userPlan.getPlanId());
+            String calendar = JSON.toJSONString(calendarStudyVos);
+            userPlan1.setSchedule(calendar);
+            userPlan1.setUpdateTime(DateUtils.getNowTime());
+            userPlan1.setStudyNum(studyNum);
+            int i = baseMapper.updateById(userPlan1);
+
+
+            userPlanVo.setCoursePlanVo(coursePlanVo);
                 userPlanVos.add(userPlanVo);
-            });
+
         }
 
         return userPlanVos;
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Boolean updateGenerate(UserPlanAddBo bo) throws ParseException {
         UserPlanQueryBo userPlanQueryBo = BeanUtil.toBean(bo, UserPlanQueryBo.class);
         if (bo.getStatus() == 0) {
@@ -463,6 +479,7 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public UserPlanVo userPlanSeven(UserPlanQueryBo bo) {
         List<UserPlan> userPlans = baseMapper.selectByUserPlan(bo);
         UserPlanVo userPlanVos = new UserPlanVo();
@@ -489,36 +506,48 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
             List<DayStudyVo> dayStudyVos = new ArrayList<>();
             List<DayStudyVo> finalDayStudyVos = dayStudyVos;
 
+            //更新当天学习节数是否已经完成
             //代表前面是否有未完成课程
-            List<UserStudyRecord> studyCount = userStudyRecordService.selectUserStudy(bo.getUserId(),array,getTimesmorning(),getTimesnight());
+            Long studyNum = 0L;
             boolean goal = true;
-            for (CoursePlanVo s : coursePlanVo) {
-                if (goal == false){
+            for (CoursePlanVo b : coursePlanVo) {
+                if (goal == false) {
                     break;
                 }
+                List<UserStudyRecord> studyCount = userStudyRecordService.selectUserStudy(bo.getUserId(), Convert.toInt(b.getCourseId()));
+                List<UserStudyRecord> myList = studyCount.stream().distinct().collect(Collectors.toList());
+                studyNum= studyNum+Convert.toLong(myList.size());
                 //更新当天学习节数是否已经完成
-                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 -> {
-                        c.getDayStudyList().stream()
-                                .forEach(d -> {
-                                    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 (b.getStudyGoal() != null && studyCount.size() >= b.getStudyGoal() ) {
+                    for (CalendarStudyVo calendarStudyVo : calendarStudyVos) {
+                        if (calendarStudyVo.getMonth() == cal.get(Calendar.MONTH) + 1) {
+                            for (DayStudyVo d : calendarStudyVo.getDayStudyList()) {
+                                if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate() == cal.get(Calendar.DAY_OF_MONTH) && d.getPerform() == 0) {
+                                    if (d.getPerform() == 1){
+                                        break;
                                     }
-                                    if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate() < cal.get(Calendar.DAY_OF_MONTH) && d.getPerform() == 0) {
-                                        d.setPerform(2);
+                                    Map<Long, Long> sectionIdMap = d.getSectionIdMap();
+                                    for (UserStudyRecord userStudyRecord : studyCount) {
+                                        sectionIdMap.remove(userStudyRecord.getSectionId());
                                     }
-                                });
-                    });
-                }else {
-                    calendarStudyVos.stream().filter(c -> c.getMonth()==cal.get(Calendar.MONTH) + 1).forEach(c -> {
-                        for (DayStudyVo d : c.getDayStudyList()) {
+                                    if (sectionIdMap.isEmpty()) {
+                                        d.setPerform(1);
+                                    } else {
+                                        d.setPerform(0);
+                                        goal = false;
+                                    }
+                                }
+                                if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate() < cal.get(Calendar.DAY_OF_MONTH) && d.getPerform() == 0) {
+                                    d.setPerform(2);
+                                }
+                            }
+                        }
+
+                    }
+
+                } else {
+                    for (CalendarStudyVo calendarStudyVo : calendarStudyVos) {
+                        for (DayStudyVo d : calendarStudyVo.getDayStudyList()) {
                             if (d.getStudyCourseKnob() != null && d.getStudyCourseKnob() != 0 && d.getDate() < cal.get(Calendar.DAY_OF_MONTH) && d.getPerform() == 0) {
                                 d.setPerform(2);
                             }
@@ -526,17 +555,21 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                                 d.setPerform(0);
                             }
                         }
-                    });
-                    goal=false;
+                    }
+                    goal = false;
                 }
-                UserPlan userPlan1 = new UserPlan();
-                userPlan1.setPlanId(s.getPlanId());
-                String calendar = JSON.toJSONString(calendarStudyVos);
-                userPlan1.setSchedule(calendar);
-                userPlan1.setUpdateTime(DateUtils.getNowTime());
-                baseMapper.updateById(userPlan1);
+
             }
 
+            UserPlan userPlan1 = new UserPlan();
+            userPlan1.setPlanId(userPlan.getPlanId());
+            String calendar = JSON.toJSONString(calendarStudyVos);
+            userPlan1.setSchedule(calendar);
+            userPlan1.setUpdateTime(DateUtils.getNowTime());
+            userPlan1.setStudyNum(studyNum);
+            int i = baseMapper.updateById(userPlan1);
+
+
             calendarStudyVos.stream().filter(c -> c.getMonth() == (cal.get(Calendar.MONTH)+1))
                    .forEach(c -> {
                        finalDayStudyVos.addAll(c.getDayStudyList().stream()
@@ -640,6 +673,11 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
         return userPlanVos;
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean editPlan(UserPlanAddBo bo) {
+        return true;
+    }
 
 
     private UserPlanVo generateSelfBo(UserPlanQueryBo bo) throws ParseException {

+ 2 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/impl/UserStudyRecordServiceImpl.java

@@ -133,7 +133,7 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
     }
 
     @Override
-    public List<UserStudyRecord> selectUserStudy(Long userId, Integer[] courseId, int timesMorning, int timesNight) {
-        return baseMapper.selectUserStudy(userId,courseId,timesMorning,timesNight);
+    public List<UserStudyRecord> selectUserStudy(Long userId, Integer courseId) {
+        return baseMapper.selectUserStudy(userId,courseId);
     }
 }

+ 1 - 7
zhongzheng-system/src/main/resources/mapper/modules/user/UserStudyRecordMapper.xml

@@ -41,13 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             and user_id =#{userId}
         </if>
         <if test="courseId != null and courseId !=''">
-            and course_id in
-            <foreach collection="courseId" open="(" separator="," close=")" item="courseId">
-                #{courseId}
-            </foreach>
-        </if>
-        <if test="startTime != null and startTime != ''">
-        and create_time BETWEEN #{startTime} and #{endTime}
+            and course_id = #{courseId}
         </if>
         and study_duration > 360
     </select>