Browse Source

增加主动下架直播课程组功能

hgw 2 years ago
parent
commit
e63018b434

+ 2 - 5
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/CourseGroupDao.java

@@ -7,10 +7,7 @@ import com.yonge.cooleshow.biz.dal.dto.search.LiveCourseGroupSearch;
 import com.yonge.cooleshow.biz.dal.dto.search.LiveCourseGroupStudentCourseSearch;
 import com.yonge.cooleshow.biz.dal.dto.search.LiveCourseGroupStudentSearch;
 import com.yonge.cooleshow.biz.dal.entity.CourseGroup;
-import com.yonge.cooleshow.biz.dal.vo.LiveCourseGroupPlanVo;
-import com.yonge.cooleshow.biz.dal.vo.LiveCourseGroupStudentCourseVo;
-import com.yonge.cooleshow.biz.dal.vo.LiveCourseGroupStudentVo;
-import com.yonge.cooleshow.biz.dal.vo.LiveCourseGroupVo;
+import com.yonge.cooleshow.biz.dal.vo.*;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -29,7 +26,7 @@ public interface CourseGroupDao extends BaseMapper<CourseGroup> {
     /**
      * 分页查询课程组信息
      */
-    <T> IPage<T> queryTeacherCourseGroup(Page<T> page, @Param("param") Map<String, Object> param);
+    IPage<CourseGroupVo> queryTeacherCourseGroup(Page<CourseGroupVo> page, @Param("param") Map<String, Object> param);
 
     /**
      * 平台方 老师详情直播课列表

+ 0 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/CourseGroup.java

@@ -107,7 +107,6 @@ public class CourseGroup implements Serializable {
     @ApiModelProperty(value = "更新时间")
     private Date updatedTime;
 
-
     public Long getId() {
         return id;
     }

+ 7 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/CourseGroupService.java

@@ -52,6 +52,13 @@ public interface CourseGroupService extends IService<CourseGroup> {
     void addLiveCourse(LiveCourseGroupDto dto);
 
     /**
+     * 取消课程组-下架课程组
+     *
+     * @param groupId 课程组
+     */
+    void cancelCourseGroup(Long groupId);
+
+    /**
      * 创建直播课程组时将课时写到缓存当作锁定的时间
      */
     List<CourseTimeEntity> lockCourseToCache(CheckCourseTimeDto dto);

+ 34 - 2
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/CourseGroupServiceImpl.java

@@ -41,14 +41,13 @@ import org.springframework.transaction.annotation.Transactional;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Consumer;
 import java.util.function.Function;
+import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
 /**
@@ -113,6 +112,7 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
         result.setSalesStartDate(group.getSalesStartDate());
         result.setSalesEndDate(group.getSalesEndDate());
         result.setMixStudentNum(group.getMixStudentNum());
+        result.setImGroupId(group.getImGroupId());
         Optional.ofNullable(group.getTeacherId()).map(this::getSysUser)
                 .ifPresent(sysUser -> result.setTeacherName(sysUser.getRealName()));
         Optional.ofNullable(group.getSubjectId()).map(subjectService::get)
@@ -219,6 +219,38 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
     }
 
     /**
+     * 取消课程组-下架课程组
+     *
+     * @param groupId 课程组
+     */
+    public void cancelCourseGroup(Long groupId) {
+        //获取课程组
+        CourseGroup group = this.getOne(Wrappers.<CourseGroup>lambdaQuery().
+                eq(CourseGroup::getId, groupId));
+        Predicate<CourseGroupEnum> courseStateFunc = e -> group.getStatus().equalsIgnoreCase(e.getCode());
+        if (courseStateFunc.test(CourseGroupEnum.ING)) {
+            throw new BizException("课程组进行中,无法下架/取消课程组!");
+        } else if (courseStateFunc.test(CourseGroupEnum.APPLY)) {
+            //已上架没人买的课程可以下架
+            if (group.getPreStudentNum() > 0) {
+                throw new BizException("课程组已有学生购买,无法下架/取消课程组!");
+            }
+        } else if (courseStateFunc.test(CourseGroupEnum.COMPLETE)) {
+            throw new BizException("课程组已完结!");
+        } else if (courseStateFunc.test(CourseGroupEnum.DISSOLVE) || courseStateFunc.test(CourseGroupEnum.CANCEL)) {
+            throw new BizException("课程组已下架!");
+        }
+        //只剩下未开售状态和上架没人购买,可以直接修改
+        group.setStatus(CourseGroupEnum.CANCEL.getCode());
+        this.updateById(group);
+        //修改课程表
+        courseScheduleService.lambdaUpdate()
+                .eq(CourseSchedule::getCourseGroupId, groupId)
+                .set(CourseSchedule::getStatus, CourseScheduleEnum.CANCEL.getCode())
+                .update();
+    }
+
+    /**
      * 创建课时写到缓存锁定时间
      */
     public List<CourseTimeEntity> lockCourseToCache(CheckCourseTimeDto dto) {

+ 30 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/vo/LiveCourseInfoVo.java

@@ -25,12 +25,26 @@ public class LiveCourseInfoVo extends CourseGroupVo implements Serializable {
     @ApiModel(value = "PlanVo", description = "教学计划")
     public static class PlanVo extends CourseTimeEntity implements Serializable {
 
+        @ApiModelProperty(value = "教学计划id")
+        private Long planId;
+
         @ApiModelProperty(value = "课堂编号-第几堂课")
         private Integer classNum;
 
+        @ApiModelProperty(value = "课程id")
+        private Long courseId;
+
         @ApiModelProperty(value = "教学计划/最多200字")
         private String plan;
 
+        public Long getId() {
+            return planId;
+        }
+
+        public void setId(Long id) {
+            this.planId = id;
+        }
+
         public Integer getClassNum() {
             return classNum;
         }
@@ -39,6 +53,22 @@ public class LiveCourseInfoVo extends CourseGroupVo implements Serializable {
             this.classNum = classNum;
         }
 
+        public Long getPlanId() {
+            return planId;
+        }
+
+        public void setPlanId(Long planId) {
+            this.planId = planId;
+        }
+
+        public Long getCourseId() {
+            return courseId;
+        }
+
+        public void setCourseId(Long courseId) {
+            this.courseId = courseId;
+        }
+
         public String getPlan() {
             return plan;
         }

+ 4 - 1
cooleshow-user/user-biz/src/main/resources/config/mybatis/CoursePlanMapper.xml

@@ -24,8 +24,11 @@
     </insert>
 
     <select id="queryCoursePlanByGroupId" resultType="com.yonge.cooleshow.biz.dal.vo.LiveCourseInfoVo$PlanVo">
-        select a.plan_,
+        select
+               a.id_  as planId,
+               a.plan_ as plan,
                a.class_num_,
+               b.id_ as courseId,
                b.start_time_,
                b.end_time_
         from course_plan as a

+ 7 - 0
cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/controller/TeacherCourseGroupController.java

@@ -72,6 +72,13 @@ public class TeacherCourseGroupController extends BaseController {
         return succeed();
     }
 
+    @ApiOperation("取消课程组-下架课程组")
+    @GetMapping("/cancelCourseGroup")
+    public HttpResponseResult<Object> cancelCourseGroup(@RequestParam("groupId") Long groupId) {
+        courseGroupService.cancelCourseGroup(groupId);
+        return succeed();
+    }
+
     @ApiOperation("获取老师排直播课时锁定的课时")
     @GetMapping("/getLockCache")
     public HttpResponseResult<Object> getLockCache(@RequestParam("teacherId") Long teacherId) {