Browse Source

网络教室伴奏

zouxuan 4 năm trước cách đây
mục cha
commit
74c11948ea

+ 9 - 12
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleStudentPaymentDao.java

@@ -317,6 +317,14 @@ public interface CourseScheduleStudentPaymentDao extends BaseDAO<Long, CourseSch
     String getMidiByCourseIdAndUserId(@Param("courseScheduleId") String courseScheduleId, @Param("userId") String userId);
 
     /**
+     * 获取单个用户的examDownloadJson
+     * @param courseScheduleId
+     * @param userId
+     * @return
+     */
+    String getExamJsonByCourseIdAndUserId(@Param("courseScheduleId") Long courseScheduleId, @Param("userId") Integer userId);
+
+    /**
      * @describe 统计课程组下的课程单价
      * @author Joburgess
      * @date 2020.06.11
@@ -353,18 +361,7 @@ public interface CourseScheduleStudentPaymentDao extends BaseDAO<Long, CourseSch
      * @author zouxuan
      * @param roomId
      */
-    void adjustExamSong(@Param("roomId") Long roomId, @Param("userId") Integer userId, @Param("examSongJson") String examSongJson);
-
-    /**
-     * 获取学员的曲目下载状态
-     * @author zouxuan
-     * @param roomId
-     * @param userId
-     * @return
-     */
-    String getExamSongDownloadStatus(@Param("roomId") Long roomId,
-                                      @Param("userId") String userId);
-
+    int adjustExamSong(@Param("roomId") Long roomId, @Param("userId") Integer userId, @Param("examSongJson") String examSongJson);
 
     /**
      * @describe 统计学员通过双十一活动排课的数量

+ 4 - 9
mec-biz/src/main/resources/config/mybatis/CourseScheduleStudentPaymentMapper.xml

@@ -159,15 +159,6 @@
 			AND user_id_ = #{userId}
 		</if>
 	</update>
-	<select id="getExamSongDownloadStatus" resultType="String">
-		SELECT exam_song_download_json_
-		FROM course_schedule_student_payment
-		WHERE course_schedule_id_ = #{roomId}
-		<if test="userId != null">
-			AND user_id_ = #{userId}
-		</if>
-	</select>
-
 	<!-- 根据主键删除一条记录 -->
 	<delete id="delete" >
 		DELETE FROM course_schedule_student_payment WHERE id_ = #{id} 
@@ -497,6 +488,10 @@
 		SELECT cssp.open_play_midi_ FROM course_schedule_student_payment cssp
 		WHERE cssp.user_id_ = #{userId} AND cssp.course_schedule_id_ = #{courseScheduleId}
 	</select>
+	<select id="getExamJsonByCourseIdAndUserId" resultType="java.lang.String">
+		SELECT cssp.exam_song_download_json_ FROM course_schedule_student_payment cssp
+		WHERE cssp.user_id_ = #{userId} AND cssp.course_schedule_id_ = #{courseScheduleId}
+	</select>
 
     <select id="findGroupCoursesUnitPrice" resultType="java.util.Map">
 		SELECT

+ 8 - 6
mec-im/src/main/java/com/ym/controller/RoomController.java

@@ -48,6 +48,12 @@ public class RoomController{
         return new BaseResponse<>();
     }
 
+    @RequestMapping(value = "pushDownloadExamSongMsg", method = RequestMethod.POST)
+    public Object pushDownloadExamSongMsg(@RequestBody ExamSongData examSongData) throws Exception {
+        roomService.pushDownloadExamSongMsg(examSongData.getRoomId(),examSongData.getExamSongId());
+        return new BaseResponse<>();
+    }
+
     @RequestMapping(value = "/statusSync")
     public void statusSync(@RequestBody String body) throws Exception {
         ChannelStateNotify notify = JSONObject.parseObject(body, ChannelStateNotify.class);
@@ -138,18 +144,14 @@ public class RoomController{
             result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.MusicMode, data.getMusicModeOn());
         } else if (data.getHandUpOn() != null) {
             result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.HandUp, data.getHandUpOn());
+        }else if (data.getPlaySongOn() != null) {
+            result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.PlaySong, data.getPlaySongOn());
         } else {
             throw new ApiException(ErrorEnum.ERR_REQUEST_PARA_ERR);
         }
         return new BaseResponse<>(result);
     }
 
-    @RequestMapping(value = "pushDownloadExamSongMsg", method = RequestMethod.POST)
-    public Object pushDownloadExamSongMsg(@RequestBody ExamSongData examSongData) throws Exception {
-        roomService.pushDownloadExamSongMsg(examSongData.getRoomId(),examSongData.getExamSongId());
-        return new BaseResponse<>();
-    }
-
     @RequestMapping(value = "adjustExamSong", method = RequestMethod.POST)
     public Object adjustExamSong(@RequestBody ExamSongData examSongData) throws Exception {
         roomService.adjustExamSong(examSongData.getRoomId(),examSongData.getStatus(),examSongData.getExamSongId());

+ 8 - 5
mec-im/src/main/java/com/ym/mec/im/message/ExamSongDownloadMessageMessage.java

@@ -2,12 +2,15 @@ package com.ym.mec.im.message;
 
 import com.ym.mec.im.BaseMessage;
 import com.ym.pojo.ExamSongMessage;
-import org.apache.commons.lang3.StringUtils;
 
 public class ExamSongDownloadMessageMessage extends BaseMessage {
     private ExamSongMessage content;
     private static final transient String TYPE = "DY:examSongDownloadMessage";
 
+    public ExamSongDownloadMessageMessage(ExamSongMessage content) {
+        this.content = content;
+    }
+
     public ExamSongMessage getContent() {
         return content;
     }
@@ -18,10 +21,10 @@ public class ExamSongDownloadMessageMessage extends BaseMessage {
 
     @Override
     public String toString() {
-        return "{\"url\":" + content.getUrl() +
-                ", \"songName\":" + content.getSongName() +
-                ", \"songId\":" + content.getSongId() +
-                '}';
+        return "{\"songName\":\"" + content.getSongName() +
+                "\", \"songId\":\"" + content.getSongId() +
+                "\", \"url\":\"" + content.getUrl() +
+                "\"}";
     }
 
     @Override

+ 21 - 0
mec-im/src/main/java/com/ym/mec/im/message/ExamSongDownloadStatusMessage.java

@@ -0,0 +1,21 @@
+package com.ym.mec.im.message;
+
+import com.ym.mec.im.BaseMessage;
+import lombok.Getter;
+import lombok.Setter;
+
+public class ExamSongDownloadStatusMessage extends BaseMessage {
+    private @Setter @Getter Integer status;
+
+    private @Setter @Getter Integer studentId;
+
+    public ExamSongDownloadStatusMessage(Integer status,Integer studentId) {
+        this.status = status;
+        this.studentId = studentId;
+    }
+
+    @Override
+    public String getObjectName() {
+        return "DY:DSMsg";
+    }
+}

+ 1 - 2
mec-im/src/main/java/com/ym/pojo/DeviceTypeEnum.java

@@ -8,6 +8,5 @@ public enum DeviceTypeEnum {
     Camera,
     MusicMode,
     HandUp,
-    ExamSong,
-    PlayMidi,
+    PlaySong,
 }

+ 9 - 0
mec-im/src/main/java/com/ym/pojo/ExamSongData.java

@@ -28,4 +28,13 @@ public class ExamSongData {
 	public void setExamSongId(Integer examSongId) {
 		this.examSongId = examSongId;
 	}
+
+	@Override
+	public String toString() {
+		return "ExamSongData{" +
+				"roomId='" + roomId + '\'' +
+				", examSongId=" + examSongId +
+				", status=" + status +
+				'}';
+	}
 }

+ 9 - 10
mec-im/src/main/java/com/ym/pojo/ExamSongDownloadData.java

@@ -5,6 +5,15 @@ public class ExamSongDownloadData {
 	private String url;
 	private String songName;
 	private Integer songId;
+	private Boolean enable = false;
+
+	public Boolean getEnable() {
+		return enable;
+	}
+
+	public void setEnable(Boolean enable) {
+		this.enable = enable;
+	}
 
 	public Integer getSongId() {
 		return songId;
@@ -37,14 +46,4 @@ public class ExamSongDownloadData {
 	public void setSongName(String songName) {
 		this.songName = songName;
 	}
-
-	@Override
-	public String toString() {
-		return "{" +
-				"status=" + status +
-				", url='" + url + '\'' +
-				", songName='" + songName + '\'' +
-				", songId='" + songId + '\'' +
-				'}';
-	}
 }

+ 1 - 17
mec-im/src/main/java/com/ym/pojo/ExamSongMessage.java

@@ -1,9 +1,6 @@
 package com.ym.pojo;
 
-import io.rong.messages.BaseMessage;
-import org.apache.commons.lang3.StringUtils;
-
-public class ExamSongMessage extends BaseMessage {
+public class ExamSongMessage{
     private String url;
     private String songName;
     private Integer songId;
@@ -31,17 +28,4 @@ public class ExamSongMessage extends BaseMessage {
     public void setSongName(String songName) {
         this.songName = songName;
     }
-
-    @Override
-    public String getType() {
-        return "DY:examSongDownloadMessage";
-    }
-
-    @Override
-    public String toString() {
-        return "{\"url\":" + url +
-                ", \"songName\":" + songName +
-                ", \"songId\":" + songId +
-                '}';
-    }
 }

+ 36 - 0
mec-im/src/main/java/com/ym/pojo/ReqDeviceControlData.java

@@ -11,9 +11,45 @@ public class ReqDeviceControlData {
 	private Boolean microphoneOn;
 	private Boolean musicModeOn;
 	private Boolean handUpOn;
+	private Boolean downloadSongStatusOn;
+	private Boolean playSongOn;
 	private String roomId;
 	private String userId;
 	private String ticket;
+	private Integer status;
+	private Integer examSongId;
+
+	public Boolean getDownloadSongStatusOn() {
+		return downloadSongStatusOn;
+	}
+
+	public void setDownloadSongStatusOn(Boolean downloadSongStatusOn) {
+		this.downloadSongStatusOn = downloadSongStatusOn;
+	}
+
+	public Boolean getPlaySongOn() {
+		return playSongOn;
+	}
+
+	public void setPlaySongOn(Boolean playSongOn) {
+		this.playSongOn = playSongOn;
+	}
+
+	public Integer getStatus() {
+		return status;
+	}
+
+	public void setStatus(Integer status) {
+		this.status = status;
+	}
+
+	public Integer getExamSongId() {
+		return examSongId;
+	}
+
+	public void setExamSongId(Integer examSongId) {
+		this.examSongId = examSongId;
+	}
 
 	public Boolean getMusicModeOn() {
 		return musicModeOn;

+ 54 - 29
mec-im/src/main/java/com/ym/service/Impl/RoomServiceImpl.java

@@ -202,7 +202,7 @@ public class RoomServiceImpl implements RoomService {
             display = "display://type=0?userId=" + userId + "?uri=";
         }else {
             //获取学员曲目下载状态
-            userResult.setExamSongDownloadJson(courseScheduleStudentPaymentDao.getExamSongDownloadStatus(courseId,userId));
+            userResult.setExamSongDownloadJson(courseScheduleStudentPaymentDao.getExamJsonByCourseIdAndUserId(courseId,sysUser.getId()));
             Room room = roomDao.findByRid(roomId);
             if (room != null) {
                 display = room.getDisplay();
@@ -727,6 +727,17 @@ public class RoomServiceImpl implements RoomService {
                 roomMemberDao.updateMicByRidAndUid(roomId, userId, false);
             } else if (typeEnum.equals(DeviceTypeEnum.HandUp)){
                 roomMemberDao.updateHandByRidAndUid(roomId, userId, false);
+            } else if (typeEnum.equals(DeviceTypeEnum.PlaySong)){
+                long scheduleId = Long.parseLong(roomId.substring(1));
+                ExamSongDownloadData msg;
+                String examJson = courseScheduleStudentPaymentDao.getExamJsonByCourseIdAndUserId(scheduleId, authUser.getId());
+                if(StringUtils.isEmpty(examJson)){
+                    throw new BizException("学员伴奏信息异常");
+                }else {
+                    msg = JSON.parseObject(examJson, ExamSongDownloadData.class);
+                    msg.setEnable(enable);
+                }
+                courseScheduleStudentPaymentDao.adjustExamSong(scheduleId,authUser.getId(),JSON.toJSONString(msg));
             }else {
                 roomMemberDao.updateMusicByRidAndUid(roomId, userId, false);
             }
@@ -827,19 +838,26 @@ public class RoomServiceImpl implements RoomService {
         String userId = authUser.getId().toString();
 
         int result;
-        DeviceStateChangedMessage deviceResourceMessage;
+        DeviceStateChangedMessage deviceResourceMessage = new DeviceStateChangedMessage(type.ordinal(), enable);
         if (type.equals(DeviceTypeEnum.Camera)) {
             result = roomMemberDao.updateCameraByRidAndUid(roomId, userId, enable);
-            deviceResourceMessage = new DeviceStateChangedMessage(type.ordinal(), enable);
         } else if (type.equals(DeviceTypeEnum.Microphone)){
             result = roomMemberDao.updateMicByRidAndUid(roomId, userId, enable);
-            deviceResourceMessage = new DeviceStateChangedMessage(type.ordinal(), enable);
         } else if (type.equals(DeviceTypeEnum.HandUp)){
             result = roomMemberDao.updateHandByRidAndUid(roomId, userId, enable);
-            deviceResourceMessage = new DeviceStateChangedMessage(type.ordinal(), enable);
+        } else if (type.equals(DeviceTypeEnum.PlaySong)){
+            long scheduleId = Long.parseLong(roomId.substring(1));
+            ExamSongDownloadData msg;
+            String examJson = courseScheduleStudentPaymentDao.getExamJsonByCourseIdAndUserId(scheduleId, authUser.getId());
+            if(StringUtils.isEmpty(examJson)){
+                throw new BizException("学员伴奏信息异常");
+            }else {
+                msg = JSON.parseObject(examJson, ExamSongDownloadData.class);
+                msg.setEnable(enable);
+            }
+            result = courseScheduleStudentPaymentDao.adjustExamSong(scheduleId,authUser.getId(),JSON.toJSONString(msg));
         }else {
             result = roomMemberDao.updateMusicByRidAndUid(roomId, userId, enable);
-            deviceResourceMessage = new DeviceStateChangedMessage(type.ordinal(), enable);
         }
         deviceResourceMessage.setUserId(userId);
         imHelper.publishMessage(userId, roomId, deviceResourceMessage, 1);
@@ -1276,25 +1294,14 @@ public class RoomServiceImpl implements RoomService {
     }
 
     @Override
-    public List<RongyunBasicUserDto> queryNoJoinStu(String roomId) {
-        return courseScheduleStudentPaymentDao.queryNoJoinStu(roomId,roomId.substring(1));
-    }
-
-    @Override
     @Transactional(rollbackFor = Exception.class)
     public void pushDownloadExamSongMsg(String roomId, Integer examSongId) throws Exception {
         SysUser authUser = sysUserFeignService.queryUserInfo();
-        ExamSongDownloadMessageMessage msg = new ExamSongDownloadMessageMessage();
+
         SysExamSong sysExamSong = sysExamSongDao.get(examSongId);
         if(sysExamSong == null){
             throw new BizException("曲目信息不存在");
         }
-        ExamSongMessage examSongMessage = new ExamSongMessage();
-        examSongMessage.setSongName(sysExamSong.getName());
-        examSongMessage.setUrl(sysExamSong.getUrl());
-        examSongMessage.setSongId(examSongId);
-        msg.setContent(examSongMessage);
-        imHelper.publishMessage(authUser.getId().toString(), roomId, msg, 0);
         //学员曲目下载状态改为未下载
         ExamSongDownloadData json = new ExamSongDownloadData();
         json.setSongName(sysExamSong.getName());
@@ -1302,6 +1309,18 @@ public class RoomServiceImpl implements RoomService {
         json.setStatus(0);
         json.setSongId(examSongId);
         courseScheduleStudentPaymentDao.adjustExamSong(Long.parseLong(roomId.substring(1)),null, JSON.toJSONString(json));
+
+        ExamSongMessage examSongMessage = new ExamSongMessage();
+        examSongMessage.setSongName(sysExamSong.getName());
+        examSongMessage.setUrl(sysExamSong.getUrl());
+        examSongMessage.setSongId(examSongId);
+        ExamSongDownloadMessageMessage msg = new ExamSongDownloadMessageMessage(examSongMessage);
+        imHelper.publishMessage(authUser.getId().toString(), roomId, msg, 0);
+    }
+
+    @Override
+    public List<RongyunBasicUserDto> queryNoJoinStu(String roomId) {
+        return courseScheduleStudentPaymentDao.queryNoJoinStu(roomId,roomId.substring(1));
     }
 
     @Override
@@ -1312,23 +1331,29 @@ public class RoomServiceImpl implements RoomService {
         }
         SysUser authUser = sysUserFeignService.queryUserInfo();
         long scheduleId = Long.parseLong(roomId.substring(1));
-        CourseSchedule courseSchedule = courseScheduleDao.get(scheduleId);
-
-        //给老师发送学员曲目下载状态
-        DeviceStateChangedMessage deviceResourceMessage = new DeviceStateChangedMessage(DeviceTypeEnum.ExamSong.ordinal(), status==0?false:true);
-        deviceResourceMessage.setUserId(courseSchedule.getActualTeacherId().toString());
-        imHelper.publishMessage(authUser.getId().toString(), roomId, deviceResourceMessage, 1);
 
         SysExamSong sysExamSong = sysExamSongDao.get(examSongId);
         if(sysExamSong == null){
             throw new BizException("曲目信息不存在");
         }
-        ExamSongDownloadData msg = new ExamSongDownloadData();
-        msg.setSongName(sysExamSong.getName());
-        msg.setUrl(sysExamSong.getUrl());
-        msg.setStatus(status);
-        msg.setSongId(examSongId);
+        ExamSongDownloadData msg;
+        String examJson = courseScheduleStudentPaymentDao.getExamJsonByCourseIdAndUserId(scheduleId, authUser.getId());
+        if(StringUtils.isEmpty(examJson)){
+            msg = new ExamSongDownloadData();
+            msg.setSongName(sysExamSong.getName());
+            msg.setUrl(sysExamSong.getUrl());
+            msg.setStatus(status);
+            msg.setSongId(examSongId);
+        }else {
+            msg = JSON.parseObject(examJson, ExamSongDownloadData.class);
+            msg.setStatus(status);
+        }
         courseScheduleStudentPaymentDao.adjustExamSong(scheduleId,authUser.getId(),JSON.toJSONString(msg));
+
+        //给老师发送学员曲目下载状态
+        CourseSchedule courseSchedule = courseScheduleDao.get(scheduleId);
+        ExamSongDownloadStatusMessage deviceResourceMessage = new ExamSongDownloadStatusMessage(status,authUser.getId());
+        imHelper.publishMessage(authUser.getId().toString(),courseSchedule.getActualTeacherId().toString(), roomId, deviceResourceMessage);
     }
 
     public void updateDisplay(String roomId, String senderId, String display, Integer isIncludeSender) throws Exception {