package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.dto.SysUserDto;
import com.ym.mec.biz.dal.entity.ImGroup;
import com.ym.mec.biz.service.ImLiveRoomPurviewService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.common.page.PageInfo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 直播间的观看权限表(ImLiveRoomPurview)表控制层
 *
 * @author hgw
 * @since 2022-06-08 09:43:47
 */
@RestController
@RequestMapping("/imLiveRoomPurview")
public class ImLiveRoomPurviewController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ImLiveRoomPurviewService imLiveRoomPurviewService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "search", dataType = "String", value = "模糊查询关键字"),
            @ApiImplicitParam(name = "subjectId", dataType = "String", value = "声部ID"),
            @ApiImplicitParam(name = "organIds", dataType = "String", value = "分部ID"),
            @ApiImplicitParam(name = "groupIds", dataType = "String", value = "群聊ID"),
            @ApiImplicitParam(name = "teamIds", dataType = "String", value = "乐团ID"),
            @ApiImplicitParam(name = "schoolIds", dataType = "String", value = "学校id/合作单位id"),
            @ApiImplicitParam(name = "roomUid", dataType = "String", value = "直播间UID", required = true)
    })
    @ApiOperation("批量添加/根据查询条件添加房间观看权限")
    @PostMapping("/addByCondition")
    @PreAuthorize("@pcs.hasPermissions('imLiveRoomPurview/addByCondition')")
    public HttpResponseResult<Object> addByCondition(@RequestBody Map<String, Object> param) {
        imLiveRoomPurviewService.addByCondition(param);
        return succeed();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", dataType = "String", value = "学员id逗号分开", required = true),
            @ApiImplicitParam(name = "roomUid", dataType = "String", value = "直播间UID", required = true),
    })
    @ApiOperation("指定多个学员id添加观看权限数据")
    @GetMapping("/add")
    @PreAuthorize("@pcs.hasPermissions('imLiveRoomPurview/add')")
    public HttpResponseResult<Object> add(String ids, String roomUid) {
        imLiveRoomPurviewService.add(ids, roomUid);
        return succeed();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", dataType = "String", value = "删除的id，学员id，群id， 逗号分开", required = true),
            @ApiImplicitParam(name = "roomUid", dataType = "String", value = "直播间UID", required = true),
    })
    @ApiOperation("删除观看权限数据")
    @GetMapping("/delete")
    @PreAuthorize("@pcs.hasPermissions('imLiveRoomPurview/delete')")
    public HttpResponseResult<Object> delete(String ids, String roomUid) {
        imLiveRoomPurviewService.delete(ids, roomUid);
        return succeed();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "search", dataType = "String", value = "模糊查询关键字"),
            @ApiImplicitParam(name = "subjectId", dataType = "String", value = "声部ID"),
            @ApiImplicitParam(name = "organIds", dataType = "String", value = "分部ID"),
            @ApiImplicitParam(name = "groupIds", dataType = "String", value = "群聊ID"),
            @ApiImplicitParam(name = "teamIds", dataType = "String", value = "乐团ID"),
            @ApiImplicitParam(name = "schoolIds", dataType = "String", value = "学校id/合作单位id"),
            @ApiImplicitParam(name = "roomUid", dataType = "String", value = "直播间UID", required = true),
            @ApiImplicitParam(name = "page", dataType = "Integer", value = "页数"),
            @ApiImplicitParam(name = "rows", dataType = "Integer", value = "每页数量"),
    })
    @ApiOperation("查询当前直播间观看权限-学员列表")
    @PostMapping("/queryStudent")
    @PreAuthorize("@pcs.hasPermissions('imLiveRoomPurview/queryStudent')")
    public HttpResponseResult<PageInfo<SysUserDto>> queryStudent(@RequestBody Map<String, Object> param) {
        return succeed(imLiveRoomPurviewService.queryStudent(param));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "search", dataType = "String", value = "模糊查询关键字"),
            @ApiImplicitParam(name = "subjectId", dataType = "String", value = "声部ID"),
            @ApiImplicitParam(name = "organIds", dataType = "String", value = "分部ID"),
            @ApiImplicitParam(name = "groupIds", dataType = "String", value = "群聊ID"),
            @ApiImplicitParam(name = "teamIds", dataType = "String", value = "乐团ID"),
            @ApiImplicitParam(name = "schoolIds", dataType = "String", value = "学校id/合作单位id"),
            @ApiImplicitParam(name = "roomUid", dataType = "String", value = "直播间UID", required = true),
            @ApiImplicitParam(name = "page", dataType = "Integer", value = "页数"),
            @ApiImplicitParam(name = "rows", dataType = "Integer", value = "每页数量"),
    })
    @ApiOperation("选择列表-观看权限-学员列表")
    @PostMapping("/selectRoomPurviewStudent")
    @PreAuthorize("@pcs.hasPermissions('imLiveRoomPurview/selectRoomPurviewStudent')")
    public HttpResponseResult<PageInfo<SysUserDto>> selectRoomPurviewStudent(@RequestBody Map<String, Object> param) {
        return succeed(imLiveRoomPurviewService.selectRoomPurviewStudent(param));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "search", dataType = "String", value = "模糊查询关键字"),
            @ApiImplicitParam(name = "groupType", dataType = "String", value = "群类型"),
            @ApiImplicitParam(name = "page", dataType = "Integer", value = "页数"),
            @ApiImplicitParam(name = "rows", dataType = "Integer", value = "每页数量"),
    })
    @ApiOperation("选择列表-观看权限-群聊列表")
    @PostMapping("/selectRoomPurviewGroup")
    @PreAuthorize("@pcs.hasPermissions('imLiveRoomPurview/selectRoomPurviewGroup')")
    public HttpResponseResult<PageInfo<ImGroup>> selectRoomPurviewGroup(@RequestBody Map<String, Object> param) {
        return succeed(imLiveRoomPurviewService.selectRoomPurviewGroup(param));
    }

    @ApiOperation(value = "导入观看权限-人员")
    @PostMapping(value = "/importPurviewUser")
    public HttpResponseResult<String> importPurviewUser(@RequestParam("file") MultipartFile file, String roomUid) throws Exception {
        String msg = imLiveRoomPurviewService.importPurviewUser(file, roomUid);
        HttpResponseResult<String> succeed = succeed();
        succeed.setMsg(msg);
        return succeed;
    }

}

