hgw 3 лет назад
Родитель
Сommit
70f4ea23cb

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/ImLiveBroadcastRoomService.java

@@ -29,6 +29,8 @@ public interface ImLiveBroadcastRoomService extends IService<ImLiveBroadcastRoom
 
     void update(ImLiveBroadcastRoomDto dto);
 
+    void whetherChat(Integer id, Integer whetherChat);
+
     void roomDestroy(Integer id);
 
     void delete(Integer id);

+ 29 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImLiveBroadcastRoomServiceImpl.java

@@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.io.Serializable;
 import java.util.*;
@@ -150,6 +151,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
      * @param dto 直播间信息
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void add(ImLiveBroadcastRoomDto dto) {
         SysUser sysUser = getSysUser(dto.getSpeakerId());
         ImLiveBroadcastRoom obj = new ImLiveBroadcastRoom();
@@ -173,6 +175,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
      * @param dto
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void update(ImLiveBroadcastRoomDto dto) {
         ImLiveBroadcastRoom obj = this.getById(dto.getId());
         if (obj.getLiveState() == 1) {
@@ -188,11 +191,31 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
     }
 
     /**
+     * 是否禁言
+     *
+     * @param id          房间id
+     * @param whetherChat 是否允许聊天互动  0允许 1不允许
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void whetherChat(Integer id, Integer whetherChat) {
+        ImLiveBroadcastRoom obj = this.getById(id);
+        ImLiveBroadcastRoomDto.RoomConfig roomConfig = getRoomConfig(obj.getRoomConfig()).orElse(null);
+        if (Objects.isNull(roomConfig)) {
+            return;
+        }
+        roomConfig.setWhether_chat(whetherChat);
+        obj.setRoomConfig(JSONObject.toJSONString(roomConfig));
+        this.updateById(obj);
+    }
+
+    /**
      * 删除直播间
      *
      * @param id 直播间id
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void delete(Integer id) {
         ImLiveBroadcastRoom obj = this.getById(id);
         if (obj.getLiveState() == 1) {
@@ -620,8 +643,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 
             //查询房间信息是否允许录像
             ImLiveBroadcastRoom one = this.getOne(new QueryWrapper<ImLiveBroadcastRoom>().eq("room_uid_", room.getRoomUid()));
-            boolean video = Optional.ofNullable(one.getRoomConfig())
-                    .map(c -> JSON.parseObject(c, ImLiveBroadcastRoomDto.RoomConfig.class))
+            boolean video = getRoomConfig(one.getRoomConfig())
                     .filter(c -> Objects.nonNull(c.getWhether_video()))
                     .map(c -> c.getWhether_video() == 0)
                     .orElse(false);
@@ -651,6 +673,11 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         }
     }
 
+    private Optional<ImLiveBroadcastRoomDto.RoomConfig> getRoomConfig(String roomConfig) {
+        return Optional.ofNullable(roomConfig)
+                .map(c -> JSON.parseObject(c, ImLiveBroadcastRoomDto.RoomConfig.class));
+    }
+
     private void getRoomData(ImLiveBroadcastRoomVo roomVo) {
         //点赞数
         Object like = redissonClient.getBucket(LIVE_ROOM_LIKE.replace(ROOM_UID, roomVo.getRoomUid())).get();

+ 18 - 4
mec-web/src/main/java/com/ym/mec/web/controller/ImLiveBroadcastRoomController.java

@@ -11,6 +11,7 @@ import com.ym.mec.common.entity.ImUserState;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.WrapperUtil;
 import io.swagger.annotations.*;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -63,7 +64,7 @@ public class ImLiveBroadcastRoomController extends BaseController {
 
     @ApiOperation("创建直播间")
     @PostMapping("/add")
-//    @PreAuthorize("@pcs.hasPermissions('imLiveBroadcastRoom/add')")
+    @PreAuthorize("@pcs.hasPermissions('imLiveBroadcastRoom/add')")
     public HttpResponseResult add(@Valid @RequestBody ImLiveBroadcastRoomDto dto) {
         imLiveBroadcastRoomService.add(dto);
         return succeed();
@@ -71,20 +72,33 @@ public class ImLiveBroadcastRoomController extends BaseController {
 
     @ApiOperation("修改直播间信息-已开播无法修改")
     @PostMapping("/update")
-//    @PreAuthorize("@pcs.hasPermissions('imLiveBroadcastRoom/update')")
+    @PreAuthorize("@pcs.hasPermissions('imLiveBroadcastRoom/update')")
     public HttpResponseResult update(@Valid @RequestBody ImLiveBroadcastRoomDto dto) {
         imLiveBroadcastRoomService.update(dto);
         return succeed();
     }
 
     /**
+     * 修改是否禁言
+     *
+     * @param id          房间表id
+     * @param whetherChat 是否允许聊天互动 0允许 1不允许
+     */
+    @ApiOperation("修改是否禁言")
+    @GetMapping(value = "/whetherChat/{id}")
+    public HttpResponseResult whetherChat(@ApiParam(value = "房间表id", required = true) @PathVariable("id") Integer id,
+                                          @ApiParam(value = "是否允许聊天互动 0允许 1不允许", required = true) Integer whetherChat) {
+        imLiveBroadcastRoomService.whetherChat(id, whetherChat);
+        return succeed();
+    }
+
+    /**
      * 关闭直播间
      *
      * @param id 房间表id
      */
     @ApiOperation("关闭直播间")
     @GetMapping(value = "/roomDestroy/{id}")
-//    @PreAuthorize("@pcs.hasPermissions('imLiveBroadcastRoom/roomDestroy')")
     public HttpResponseResult roomDestroy(@ApiParam(value = "房间表id", required = true) @PathVariable("id") Integer id) {
         imLiveBroadcastRoomService.roomDestroy(id);
         return succeed();
@@ -95,7 +109,7 @@ public class ImLiveBroadcastRoomController extends BaseController {
     })
     @ApiOperation("删除直播间信息-已开播无法删除")
     @PostMapping("/delete")
-//    @PreAuthorize("@pcs.hasPermissions('imLiveBroadcastRoom/delete')")
+    @PreAuthorize("@pcs.hasPermissions('imLiveBroadcastRoom/delete')")
     public HttpResponseResult delete(@RequestBody Map<String, Object> param) {
         Integer id = WrapperUtil.toInt(param, "id", "请传入房间id");
         imLiveBroadcastRoomService.delete(id);