Browse Source

fix 收藏题目列表

he2802 4 năm trước cách đây
mục cha
commit
e889d3a0c3

+ 2 - 1
zhongzheng-api/src/main/java/com/zhongzheng/controller/activity/PlanController.java

@@ -10,6 +10,7 @@ import com.zhongzheng.modules.activity.bo.ActivityTaskQueryBo;
 import com.zhongzheng.modules.activity.bo.ActivityTaskUserAddBo;
 import com.zhongzheng.modules.activity.service.IActivityTaskService;
 import com.zhongzheng.modules.activity.vo.ActivityTaskVo;
+import com.zhongzheng.modules.user.bo.UserPlanAddBo;
 import com.zhongzheng.modules.user.bo.UserPlanQueryBo;
 import com.zhongzheng.modules.user.domain.UserPlan;
 import com.zhongzheng.modules.user.entity.ClientLoginUser;
@@ -69,7 +70,7 @@ public class PlanController extends BaseController {
      */
     @ApiOperation("修改计划")
     @PostMapping("/updateGenerate")
-    public AjaxResult<Void> updateGenerate(UserPlanQueryBo bo) throws ParseException {
+    public AjaxResult<Void> updateGenerate(@RequestBody UserPlanAddBo bo) throws ParseException {
         ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
         bo.setUserId(loginUser.getUser().getUserId());
         return toAjax(userPlanService.updateGenerate(bo) ? 1 : 0);

+ 4 - 2
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/UserServiceImpl.java

@@ -169,7 +169,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
     @Override
     public RanKingUser rankingList(RanKingUserQuery query) {
         RanKingUser ranKingUser = new RanKingUser();
-
         Long time = System.currentTimeMillis(); //当前时间的时间戳
         if (query.getStatus() == 0) {
             long zero1 = time / (1000 * 3600 * 24) * (1000 * 3600 * 24) - TimeZone.getDefault().getRawOffset();
@@ -190,8 +189,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
             List<RanKingUser> ranKingUsers = baseMapper.selectByRanks(query);
             if (ranKingUsers != null && ranKingUsers.size() != 0) {
                 ranKingUser.setRanKingUsers(ranKingUsers);
+            }else {
+                ranKingUser.setRanKingUsers(new ArrayList<>());
             }
-
         }else {
             Calendar cal = Calendar.getInstance();
             int month = cal.get(Calendar.MONTH) + 1;
@@ -210,6 +210,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
             List<RanKingUser> ranKingUsers = baseMapper.selectByRanks(query);
             if (ranKingUsers != null && ranKingUsers.size() != 0) {
                 ranKingUser.setRanKingUsers(ranKingUsers);
+            }else {
+                ranKingUser.setRanKingUsers(new ArrayList<>());
             }
         }
         return ranKingUser;

+ 14 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/bo/UserPlanAddBo.java

@@ -29,7 +29,7 @@ public class UserPlanAddBo {
     private String reminderTime;
     /** 0周日  1周一 2周二 3周三 4周四 5周五 6周六 */
     @ApiModelProperty("0周日  1周一 2周二 3周三 4周四 5周五 6周六")
-    private Integer studyCount;
+    private Integer[] studyCount;
     /** 复习天数 */
     @ApiModelProperty("复习天数")
     private Long studyDay;
@@ -54,4 +54,17 @@ public class UserPlanAddBo {
     /** 已学习节数 */
     @ApiModelProperty("已学习节数")
     private Long studyNum;
+
+    /** 计划json格式 */
+    @ApiModelProperty("计划Id")
+    private Long planId;
+
+
+    /** 用户Id */
+    @ApiModelProperty("用户Id")
+    private Long userId;
+
+    /** 定制的课程 */
+    @ApiModelProperty("定制的课程")
+    private Integer[] courseId;
 }

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

@@ -28,4 +28,6 @@ public interface UserPlanMapper extends BaseMapper<UserPlan> {
     void insertSource(CoursePlanVo coursePlanVo);
 
     List<UserPlanCource> selectCourse(Long planId);
+
+    Integer selectCountCourse(UserPlanQueryBo bo);
 }

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

@@ -61,5 +61,5 @@ public interface IUserPlanService extends IService<UserPlan> {
 
 	List<UserPlanVo> userPlan(UserPlanQueryBo bo);
 
-	Boolean updateGenerate(UserPlanQueryBo bo) throws ParseException;
+	Boolean updateGenerate(UserPlanAddBo bo) throws ParseException;
 }

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

@@ -11,11 +11,13 @@ import com.google.gson.JsonArray;
 import com.zhongzheng.common.utils.DateUtils;
 import com.zhongzheng.modules.exam.vo.ExamArrangementTimeVo;
 import com.zhongzheng.modules.user.domain.UserPlanCource;
+import com.zhongzheng.modules.user.service.IUserPlanCourceService;
 import com.zhongzheng.modules.user.vo.CalendarStudyVo;
 import com.zhongzheng.modules.user.vo.CoursePlanVo;
 import com.zhongzheng.modules.user.vo.DayStudyVo;
 import io.micrometer.core.instrument.util.TimeUtils;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -45,6 +47,9 @@ import java.util.stream.Collectors;
 public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> implements IUserPlanService {
 
 
+    @Autowired
+    private IUserPlanCourceService userPlanCourceService;
+
     @Override
     public UserPlanVo queryById(Long userId){
         UserPlan db = this.baseMapper.selectById(userId);
@@ -123,14 +128,20 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
 
     @Override
     public UserPlanVo generate(UserPlanQueryBo bo) throws ParseException {
+        //判断是否课程已被生成过课程
+        Integer rank = baseMapper.selectCountCourse(bo);
+        if (rank > 0){
+            throw new IllegalArgumentException("您当前有课程的计划,请到计划修改上修改计划");
+        }
         //自定义学习计划,自动生成计划
         if (bo.getCourseId() != null && bo.getStudyCount() == null){
             UserPlanVo userPlanVo = generateSelf(bo);
             if (bo.getStatus() != null && bo.getStatus() == 1){
                 UserPlan userPlan = new UserPlan();
+
+
                 String s = JSON.toJSONString(userPlanVo.getCalendarStudyVo());
                 String s1 = JSON.toJSONString(userPlanVo.getStudyCount());
-
                 userPlan.setStudyDay(bo.getStudyDay());
                 userPlan.setStudyCount(s1);
                 userPlan.setUserId(bo.getUserId());
@@ -244,7 +255,8 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
     }
 
     @Override
-    public Boolean updateGenerate(UserPlanQueryBo bo) throws ParseException {
+    public Boolean updateGenerate(UserPlanAddBo bo) throws ParseException {
+        UserPlanQueryBo userPlanQueryBo = BeanUtil.toBean(bo, UserPlanQueryBo.class);
         if (bo.getStatus() == 0) {
             UserPlan userPlan = new UserPlan();
             userPlan.setPlanId(bo.getPlanId());
@@ -253,8 +265,8 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
         }else {
             //自定义学习计划,自动生成计划
             if (bo.getCourseId() != null && bo.getStudyCount() == null) {
-                UserPlanVo userPlanVo = generateSelf(bo);
-                if (bo.getStatus() != null && bo.getStatus() == 1) {
+                UserPlanVo userPlanVo = generateSelf(userPlanQueryBo);
+                if (bo.getStatus() != null) {
                     UserPlan userPlan = new UserPlan();
                     String s = JSON.toJSONString(userPlanVo.getCalendarStudyVo());
                     String s1 = JSON.toJSONString(userPlanVo.getStudyCount());
@@ -272,15 +284,26 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                     }
                     if (bo.getStatus() == 1) {
                         boolean save = this.save(userPlan);
+                        for (CoursePlanVo coursePlanVo : userPlanVo.getCoursePlanVo()) {
+                            coursePlanVo.setPlanId(userPlan.getPlanId());
+                            baseMapper.insertSource(coursePlanVo);
+                        }
                     }
                     if (bo.getStatus() == 2) {
                         userPlan.setPlanId(bo.getPlanId());
                         boolean save = this.updateById(userPlan);
+                        LambdaQueryWrapper<UserPlanCource> lqw = Wrappers.lambdaQuery();
+                        lqw.eq(bo.getPlanId() != null,UserPlanCource::getPlanId,bo.getPlanId());
+                        userPlanCourceService.remove(lqw);
+                        for (CoursePlanVo coursePlanVo : userPlanVo.getCoursePlanVo()) {
+                            coursePlanVo.setPlanId(userPlan.getPlanId());
+                            baseMapper.insertSource(coursePlanVo);
+                        }
                     }
                 }
             } else {
-                UserPlanVo userPlanVo = generateSelfBo(bo);
-                if (bo.getStatus() != null && bo.getStatus() == 1) {
+                UserPlanVo userPlanVo = generateSelfBo(userPlanQueryBo);
+                if (bo.getStatus() != null) {
                     UserPlan userPlan = new UserPlan();
                     String s = JSON.toJSONString(userPlanVo.getCalendarStudyVo());
                     String s1 = JSON.toJSONString(userPlanVo.getStudyCount());
@@ -303,10 +326,21 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                     }
                     if (bo.getStatus() == 1) {
                         boolean save = this.save(userPlan);
+                        for (CoursePlanVo coursePlanVo : userPlanVo.getCoursePlanVo()) {
+                            coursePlanVo.setPlanId(userPlan.getPlanId());
+                            baseMapper.insertSource(coursePlanVo);
+                        }
                     }
                     if (bo.getStatus() == 2) {
                         userPlan.setPlanId(bo.getPlanId());
                         boolean save = this.updateById(userPlan);
+                        LambdaQueryWrapper<UserPlanCource> lqw = Wrappers.lambdaQuery();
+                        lqw.eq(bo.getPlanId() != null,UserPlanCource::getPlanId,bo.getPlanId());
+                        userPlanCourceService.remove(lqw);
+                        for (CoursePlanVo coursePlanVo : userPlanVo.getCoursePlanVo()) {
+                            coursePlanVo.setPlanId(userPlan.getPlanId());
+                            baseMapper.insertSource(coursePlanVo);
+                        }
                     }
                 }
             }
@@ -363,28 +397,36 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                     if (Sec < sectionNum) {
                         dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec)+dayStudyVo.getStudyCourseKnob());
                         sectionNum = sectionNum-Sec;
+                        dayStudyVo.setPerform(0);
                     }else if (Sec >= sectionNum){
                         dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum)+dayStudyVo.getStudyCourseKnob());
                         sectionNum = 0;
+                        dayStudyVo.setPerform(0);
                     }
                 }else if(calendarStudyVo.getMonth() != (cal.get(Calendar.MONTH) + 1) && ifTrue(dayStudyVo.getStudyDay(),longs)){
                     if (Sec < sectionNum) {
                         dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec)+dayStudyVo.getStudyCourseKnob());
                         sectionNum = sectionNum-Sec;
+                        dayStudyVo.setPerform(0);
                     }else if (Sec >= sectionNum){
                         dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum)+dayStudyVo.getStudyCourseKnob());
                         sectionNum = 0;
+                        dayStudyVo.setPerform(0);
                     }
                 }
             }
         }
 
         //原有课程不满足课程节数则再创建课程
-        if (sectionNum == 0){
+        if (sectionNum != 0){
             while (sectionNum != 0 ) {
-                month++;
-                Long firstDayOfMonth = getFirstDayOfMonth(month+1);
-                Long lastDayOfMonth = getLastDayOfMonth(month+1);
+                if (CollectionUtils.isEmpty(userPlanVo1.getCalendarStudyVo())) {
+                    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) {
@@ -395,17 +437,21 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                         if (Sec < sectionNum) {
                             dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec));
                             sectionNum = sectionNum-Sec;
+                            dayStudyVo.setPerform(0);
                         }else if (Sec >= sectionNum){
                             dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum));
                             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;
+                            dayStudyVo.setPerform(0);
                         }else if (Sec >= sectionNum){
                             dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum));
                             sectionNum = 0;
+                            dayStudyVo.setPerform(0);
                         }
                     }
                 }
@@ -478,17 +524,21 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                     if (Sec < sectionNum) {
                         dayStudyVo.setStudyCourseKnob(Convert.toLong(Sec));
                         sectionNum = sectionNum-Sec;
+                        dayStudyVo.setPerform(0);
                     }else if (Sec >= sectionNum){
                         dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum));
                         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;
+                        dayStudyVo.setPerform(0);
                     }else if (Sec >= sectionNum){
                         dayStudyVo.setStudyCourseKnob(Convert.toLong(sectionNum));
                         sectionNum = 0;
+                        dayStudyVo.setPerform(0);
                     }
                 }
             }
@@ -576,6 +626,7 @@ public class UserPlanServiceImpl extends ServiceImpl<UserPlanMapper, UserPlan> i
                         sectionNum = 0;
                     }
                 }
+                dayStudyVo.setPerform(0);
             }
             CalendarStudyVo calendarStudyVo = new CalendarStudyVo();
             calendarStudyVo.setYear(Convert.toLong(year));

+ 1 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/vo/CalendarStudyVo.java

@@ -28,4 +28,5 @@ public class CalendarStudyVo {
     /** 月份天 */
     @ApiModelProperty("月份天")
     private List<DayStudyVo> dayStudyList;
+
 }

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

@@ -25,4 +25,8 @@ public class DayStudyVo {
 
     @ApiModelProperty("当天学习节数")
     private Long studyCourseKnob;
+
+    /** 是否完成任务  0未完成  1完成 */
+    @ApiModelProperty("是否完成任务  0未完成  1完成")
+    private Integer perform;
 }

+ 44 - 7
zhongzheng-system/src/main/resources/mapper/modules/user/UserPlanMapper.xml

@@ -80,13 +80,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
 
     <select id="selectByListCourse" 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.price,
+        rs.start_time,
+        rs.end_time,
+        rs.cover_url,
+        rs.create_time,
+        rs.update_time,
+        rs.STATUS,
+        rs.teacher_ids,
+        rs.course_name,
+        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
         <if test="courseId != null and courseId !=''">
             and c.course_id in
             <foreach collection="courseId" open="(" separator="," close=")" item="courseId">
@@ -120,4 +142,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         SELECT * FROM user_plan_cource where 1=1 AND plan_id=#{planId}
     </select>
 
+
+    <select id="selectCountCourse" parameterType="com.zhongzheng.modules.user.bo.UserPlanQueryBo"  resultType="int">
+        SELECT COUNT(c.source_id)
+        FROM user_plan_cource c LEFT JOIN user_plan u ON u.plan_id = c.plan_id
+        WHERE 1=1
+        <if test="courseId != null and courseId !=''">
+            and c.source_id in
+            <foreach collection="courseId" open="(" separator="," close=")" item="courseId">
+                #{courseId}
+            </foreach>
+        </if>
+        <if test="userId != null and userId !=''">
+            and u.user_id = #{userId}
+        </if>
+    </select>
 </mapper>