package com.qmth.distributed.print.api;

import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.teachcloud.common.bean.params.SysRoleGroupMemberParams;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.entity.SysRoleGroupMember;
import com.qmth.teachcloud.common.service.SysRoleGroupMemberService;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 角色组成员表 前端控制器
 * </p>
 *
 * @author wangliang
 * @since 2022-03-08
 */
@Api(tags = "角色组成员Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.sys}/role/group")
@Validated
//@Aac(auth = BOOL.FALSE, strict = BOOL.FALSE)
public class SysRoleGroupMemberController {

    @Resource
    SysRoleGroupMemberService sysRoleGroupMemberService;

    @ApiOperation(value = "新增/修改")
    @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = ResultUtil.class)})
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(@Valid @RequestBody SysRoleGroupMemberParams roleGroupMemberParams, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultUtil.ok(sysRoleGroupMemberService.saveOrUpdate(roleGroupMemberParams));
    }

    @ApiOperation(value = "成员管理查询")
    @ApiResponses({@ApiResponse(code = 200, message = "角色组成员信息", response = SysRoleGroupMember.class)})
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result list(@ApiParam(value = "角色id", required = true) @RequestParam String roleId,
                       @ApiParam(value = "成员姓名", required = false) @RequestParam(required = false) String name) {
        return ResultUtil.ok(sysRoleGroupMemberService.findByRoleIdAndName(SystemConstant.convertIdToLong(roleId), name));
    }

//    @ApiOperation(value = "匹配查询")
//    @ApiResponses({@ApiResponse(code = 200, message = "用户信息", response = SysRoleGroupMemberMatchResult.class)})
//    @RequestMapping(value = "/match/list", method = RequestMethod.POST)
//    public Result matchList(@Valid @RequestBody SysRoleGroupMemberMatchParams roleGroupMemberMatchParams, BindingResult bindingResult) {
//        if (bindingResult.hasErrors()) {
//            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
//        }
//        return ResultUtil.ok(sysRoleGroupMemberService.matchList(roleGroupMemberMatchParams));
//    }
}
