package com.yonge.cooleshow.student.controller;


import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.dto.ImGroupResultDto;
import com.yonge.cooleshow.biz.dal.dto.ImGroupSearchDto;
import com.yonge.cooleshow.biz.dal.entity.ImGroup;
import com.yonge.cooleshow.biz.dal.service.ImGroupService;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.mybatis.page.PageInfo;
import com.yonge.toolset.utils.validator.ValidationKit;
import io.swagger.annotations.*;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 即时通讯群组(ImGroup)表控制层
 *
 * @author zx
 * @since 2022-03-22 10:45:56
 */
@Api(tags = "即时通讯群组")
@RestController
@RequestMapping("/imGroup")
public class ImGroupController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ImGroupService imGroupService;
    @Resource
    private SysUserFeignService sysUserFeignService;

    @ApiOperation("获取群详情")
    @PostMapping(value = "/getDetail/{groupId}")
    public HttpResponseResult<ImGroup> getDetail(@ApiParam(value = "群编号", required = true) @PathVariable("groupId") Long groupId) throws Exception {
        return succeed(imGroupService.getById(groupId));
    }

    @ApiOperation("群列表")
    @PostMapping(value = "/queryAll")
    public HttpResponseResult<List<ImGroup>> queryAll(@Valid @RequestBody ImGroupSearchDto imGroupSearchDto, BindingResult bindingResult) throws Exception {
        ValidationKit.ignoreFields(bindingResult,"createUserId");
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        imGroupSearchDto.setUserId(sysUser.getId());
        return succeed(imGroupService.queryAll(imGroupSearchDto));
    }

    @ApiOperation("获取指定用户的群列表")
    @PostMapping(value = "/queryTeacherGroup")
    public HttpResponseResult<List<ImGroupResultDto>> queryTeacherGroup(@RequestBody ImGroupSearchDto imGroupSearchDto) throws Exception {
        return succeed(imGroupService.queryTeacherFun(imGroupSearchDto));
    }
}

