liujc 1 year ago
parent
commit
44c1b2c7d5

+ 20 - 31
.idea/httpRequests/http-requests-log.http

@@ -1,3 +1,23 @@
+GET http://127.0.0.1:9002/teacherCourseSchedule/findCourseAttendanceDetailHeadInfo?courseScheduleId=1701
+authorization: bearer 97fd8e85-bb3c-4967-8a07-47c44957f94a
+Content-Type: application/json
+Connection: Keep-Alive
+User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
+Accept-Encoding: br,deflate,gzip,x-gzip
+
+<> 2023-06-08T171149.200.json
+
+###
+
+GET http://127.0.0.1:8005/task/closeLiveCourseRoom
+Connection: Keep-Alive
+User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
+Accept-Encoding: br,deflate,gzip,x-gzip
+
+<> 2023-06-08T163756.200.json
+
+###
+
 GET http://127.0.0.1:9002/teacherCourseSchedule/findCourseAttendanceDetailHeadInfo?courseScheduleId=2002
 authorization: bearer 97fd8e85-bb3c-4967-8a07-47c44957f94a
 Content-Type: application/json
@@ -777,34 +797,3 @@ Accept-Encoding: br,deflate,gzip,x-gzip
 
 ###
 
-POST http://127.0.0.1:8005/studentManage/userPage
-Authorization: bearer 3f804d4e-b7f0-41ad-8dbf-119a0c54becc
-Content-Type: application/json
-coopId: 14
-Content-Length: 137
-Connection: Keep-Alive
-User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
-Accept-Encoding: br,deflate,gzip,x-gzip
-
-{
-//  "keyword": "一",
-//    "musicGroupId": 23050516201200001,
-  //  "subjectId": 2,
-  //  "vipFlag": true,
-//  "studentId": 2248340
-
-}
-
-<> 2023-06-02T194506.200.json
-
-###
-
-GET http://127.0.0.1:8005/schoolActivity/detail/16
-Connection: Keep-Alive
-User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
-Accept-Encoding: br,deflate,gzip,x-gzip
-
-<> 2023-06-02T182950.200.json
-
-###
-

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentAttendanceDao.java

@@ -395,4 +395,6 @@ public interface StudentAttendanceDao extends BaseDAO<Long, StudentAttendance> {
                                                                       @Param("queryDto") SchoolIndexStatWrapper.QueryDto queryDto);
 
     Integer getTruantStudentNum(Long courseScheduleId);
+
+    Integer getStudentNumByStatus(@Param("courseScheduleId") Long courseScheduleId, @Param("status") StudentAttendanceStatusEnum studentAttendanceStatusEnum);
 }

+ 2 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleServiceImpl.java

@@ -3916,7 +3916,8 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
         }
         CourseAttendanceDetailHeadInfoDto courseAttendanceDetailHeadInfoDto = courseScheduleDao.findByCourse(courseScheduleId);
         courseAttendanceDetailHeadInfoDto.setLatestAttendanceTime(studentAttendanceDao.findLatestAttendanceDate(courseScheduleId));
-        courseAttendanceDetailHeadInfoDto.setTruantStudentNum(studentAttendanceDao.getTruantStudentNum(courseScheduleId));
+        courseAttendanceDetailHeadInfoDto.setLeaveStudentNum(studentAttendanceDao.getStudentNumByStatus(courseScheduleId, StudentAttendanceStatusEnum.LEAVE));
+        courseAttendanceDetailHeadInfoDto.setTruantStudentNum(studentAttendanceDao.getStudentNumByStatus(courseScheduleId, StudentAttendanceStatusEnum.TRUANT));
         return courseAttendanceDetailHeadInfoDto;
     }
 

+ 74 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java

@@ -36,6 +36,8 @@ import com.ym.mec.util.string.MessageFormatter;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
@@ -50,9 +52,11 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
+import java.text.MessageFormat;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.concurrent.CompletableFuture;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -4980,6 +4984,76 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 
         // 更新通知状态
         courseScheduleDao.updateRemindStatus(ids);
+        CompletableFuture.runAsync(() -> {
+            for (CourseSchedule courseSchedule : courseSchedules) {
+                createVipGroupLiveRoom(courseSchedule.getId().toString(), courseSchedule);
+            }
+        });
+
+
+    }
+
+
+    /**
+     * 创建网络课直播间
+     * @param roomId 课程房间编号
+     * @param courseSchedule 课程信息
+     * @return ImLiveBroadcastRoom
+     */
+    private void createVipGroupLiveRoom(String roomId, CourseSchedule courseSchedule) {
+        //记录用户实际选择的房间
+        if (courseSchedule.getGroupType() == GroupType.COMM) {
+            roomId = "I" + roomId;
+        } else {
+            roomId = "S" + roomId;
+        }
+        // 主动创建直播间
+        VipGroup vipGroup = vipGroupDao.get(Long.parseLong(courseSchedule.getMusicGroupId()));
+        if (Objects.isNull(vipGroup)) {
+            throw new BizException("直播课程组不存在");
+        }
+
+        if (StringUtils.isBlank(vipGroup.getLiveConfigJson())) {
+            throw new BizException("直播课程组未配置直播间");
+        }
+
+        ImLiveBroadcastRoom liveRoom = JSON.parseObject(vipGroup.getLiveConfigJson(), ImLiveBroadcastRoom.class);
+
+        if (StringUtils.isBlank(liveRoom.getServiceProvider())) {
+            //查询房间过期时间
+            String liveClient = sysConfigDao.findConfigValue("live_client");
+            liveRoom.setServiceProvider(liveClient);
+        }
+
+        String liveStartTime = MessageFormat.format("{0} {1}", DateUtil.format(courseSchedule.getClassDate(), DateUtil.DEFAULT_PATTERN),
+                DateUtil.format(courseSchedule.getStartClassTime(), DateUtil.EXPANDED_TIME_FORMAT));
+
+        DateTime time = DateTime.parse(liveStartTime, DateTimeFormat.forPattern(DateUtil.DEFAULT_PATTERN + " " + DateUtil.EXPANDED_TIME_FORMAT));
+
+        String roomUid = "LIVE-" + roomId + "-" + time.toDate().getTime();
+        liveRoom.setTenantId(TenantContextHolder.getTenantId());
+        liveRoom.setRoomUid(roomUid);
+        //liveRoom.setRoomConfig(liveRoom.getRoomConfig());
+        liveRoom.setLiveState(1);
+        liveRoom.setRoomState(0);
+        liveRoom.setGroupType("LIVE");
+        liveRoom.setCreatedBy(liveRoom.getSpeakerId());
+        liveRoom.setCreatedTime(DateTime.now().toDate());
+        liveRoom.setLiveStartTime(DateTime.now().toDate());
+        liveRoom.setTenantId(courseSchedule.getTenantId());
+
+        // 创建直播间
+        imLiveBroadcastRoomService.save(liveRoom);
+
+        // 开启直播间
+        imLiveBroadcastRoomService.createLiveRoom(liveRoom);
+
+        // 更新课程关联直播间
+        CourseSchedule schedule = new CourseSchedule();
+        schedule.setId(courseSchedule.getId());
+        schedule.setTenantId(courseSchedule.getTenantId());
+        schedule.setLiveRoomId(roomUid);
+        courseScheduleDao.update(schedule);
 
     }
 

+ 10 - 0
mec-biz/src/main/resources/config/mybatis/StudentAttendanceMapper.xml

@@ -751,4 +751,14 @@
         left join student_attendance sa on sa.course_schedule_id_ = cssp.course_schedule_id_ and sa.user_id_ = cssp.user_id_
         where cssp.course_schedule_id_ = #{courseId} and (sa.status_ = 'TRUANT' or sa.id_ is null)
     </select>
+
+    <select id="getStudentNumByStatus" resultType="java.lang.Integer">
+
+        select COUNT(cssp.user_id_) from course_schedule_student_payment cssp
+        left join student_attendance sa on sa.course_schedule_id_ = cssp.course_schedule_id_ and sa.user_id_ = cssp.user_id_
+        where cssp.course_schedule_id_ = #{courseScheduleId}
+        and (sa.status_ = #{status.name}
+            <if test="status.name == 'TRUANT'"> or sa.id_ is null </if>
+        )
+    </select>
 </mapper>

+ 5 - 0
mec-client-api/src/main/java/com/ym/mec/task/TaskRemoteService.java

@@ -307,4 +307,9 @@ public interface TaskRemoteService {
     // 直播课程提醒
     @GetMapping("task/liveCourseRemind")
     void liveCourseRemind() ;
+
+
+    // 直播课程提醒
+    @GetMapping("task/closeLiveCourseRoom")
+    void closeLiveCourseRoom() ;
 }

+ 5 - 0
mec-client-api/src/main/java/com/ym/mec/task/fallback/TaskRemoteServiceFallback.java

@@ -359,4 +359,9 @@ public class TaskRemoteServiceFallback implements TaskRemoteService {
     public void liveCourseRemind() {
         logger.error("直播课提醒失败");
     }
+
+    @Override
+    public void closeLiveCourseRoom() {
+        logger.error("关闭直播间失败");
+    }
 }

+ 41 - 31
mec-im/src/main/java/com/ym/service/Impl/RoomServiceImpl.java

@@ -363,43 +363,53 @@ public class RoomServiceImpl implements RoomService {
             throw new BizException("直播课程组未配置直播间");
         }
 
-        ImLiveBroadcastRoom liveRoom = JSON.parseObject(vipGroup.getLiveConfigJson(), ImLiveBroadcastRoom.class);
-
-        if (StringUtils.isBlank(liveRoom.getServiceProvider())) {
-            //查询房间过期时间
-            String liveClient = sysConfigDao.findConfigValue("live_client");
-            liveRoom.setServiceProvider(liveClient);
-        }
-
         String liveStartTime = MessageFormat.format("{0} {1}", DateUtil.format(courseSchedule.getClassDate(), DateUtil.DEFAULT_PATTERN),
                 DateUtil.format(courseSchedule.getStartClassTime(), DateUtil.EXPANDED_TIME_FORMAT));
 
         DateTime time = DateTime.parse(liveStartTime, DateTimeFormat.forPattern(DateUtil.DEFAULT_PATTERN + " " + DateUtil.EXPANDED_TIME_FORMAT));
 
         String roomUid = "LIVE-" + roomId + "-" + time.toDate().getTime();
-        liveRoom.setTenantId(TenantContextHolder.getTenantId());
-        liveRoom.setRoomUid(roomUid);
-        //liveRoom.setRoomConfig(liveRoom.getRoomConfig());
-        liveRoom.setLiveState(1);
-        liveRoom.setRoomState(0);
-        liveRoom.setGroupType("LIVE");
-        liveRoom.setCreatedBy(liveRoom.getSpeakerId());
-        liveRoom.setCreatedTime(DateTime.now().toDate());
-        liveRoom.setLiveStartTime(DateTime.now().toDate());
-        liveRoom.setTenantId(courseSchedule.getTenantId());
-
-        // 创建直播间
-        imLiveBroadcastRoomService.save(liveRoom);
-
-        // 开启直播间
-        imLiveBroadcastRoomService.createLiveRoom(liveRoom);
-
-        // 更新课程关联直播间
-        CourseSchedule schedule = new CourseSchedule();
-        schedule.setId(courseSchedule.getId());
-        schedule.setTenantId(courseSchedule.getTenantId());
-        schedule.setLiveRoomId(roomUid);
-        courseScheduleDao.update(schedule);
+        ImLiveBroadcastRoom liveRoom = JSON.parseObject(vipGroup.getLiveConfigJson(), ImLiveBroadcastRoom.class);
+
+        try {
+
+
+            if (StringUtils.isBlank(liveRoom.getServiceProvider())) {
+                //查询房间过期时间
+                String liveClient = sysConfigDao.findConfigValue("live_client");
+                liveRoom.setServiceProvider(liveClient);
+            }
+
+            liveRoom.setTenantId(TenantContextHolder.getTenantId());
+            liveRoom.setRoomUid(roomUid);
+            //liveRoom.setRoomConfig(liveRoom.getRoomConfig());
+            liveRoom.setLiveState(1);
+            liveRoom.setRoomState(0);
+            liveRoom.setGroupType("LIVE");
+            liveRoom.setCreatedBy(liveRoom.getSpeakerId());
+            liveRoom.setCreatedTime(DateTime.now().toDate());
+            liveRoom.setLiveStartTime(DateTime.now().toDate());
+            liveRoom.setTenantId(courseSchedule.getTenantId());
+
+            // 创建直播间
+            imLiveBroadcastRoomService.save(liveRoom);
+
+            // 开启直播间
+            imLiveBroadcastRoomService.createLiveRoom(liveRoom);
+
+            // 更新课程关联直播间
+            CourseSchedule schedule = new CourseSchedule();
+            schedule.setId(courseSchedule.getId());
+            schedule.setTenantId(courseSchedule.getTenantId());
+            schedule.setLiveRoomId(roomUid);
+            courseScheduleDao.update(schedule);
+        }catch (Exception e) {
+            log.error("创建直播间失败", e);
+            liveRoom = imLiveBroadcastRoomService.lambdaQuery()
+                    .eq(ImLiveBroadcastRoom::getRoomUid, roomUid)
+                    .last("LIMIT 1")
+                    .one();
+        }
 
         // 返回直播间信息
         return liveRoom;

+ 19 - 0
mec-task/src/main/java/com/ym/mec/task/jobs/CloseLiveCourseRoomTask.java

@@ -0,0 +1,19 @@
+package com.ym.mec.task.jobs;
+
+import com.ym.mec.task.TaskRemoteService;
+import com.ym.mec.task.core.BaseTask;
+import com.ym.mec.task.core.TaskException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CloseLiveCourseRoomTask extends BaseTask {
+
+	@Autowired
+	private TaskRemoteService taskRemoteService;
+
+	@Override
+	public void execute() throws TaskException {
+		taskRemoteService.closeLiveCourseRoom();
+	}
+}