package ink.wgink.service.role.controller.api;

import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.dtos.department.DepartmentUserDTO;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResultList;
import ink.wgink.service.role.service.IRoleDepartmentUserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: RoleDepartmentUserController
 * @Description: 角色部门用户
 * @Author: wanggeng
 * @Date: 2021/11/3 3:04 下午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "角色部门用户")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/role/department/user")
public class RoleDepartmentUserController extends DefaultBaseController {

    @Autowired
    private IRoleDepartmentUserService roleDepartmentUserService;

    @ApiOperation(value = "用户列表（通过角色ID、地区编码）", notes = "获取指定地区下所有部门中指定角色的用户列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "path", dataType = "String", required = true),
            @ApiImplicitParam(name = "areaCode", value = "地区编码", paramType = "path", dataType = "String", required = true),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list-user/role-id/{roleId}/area-code/{areaCode}")
    public List<DepartmentUserDTO> listUserByRoleIdAndAreaCode(@PathVariable("roleId") String roleId,
                                                               @PathVariable("areaCode") String areaCode) {
        return roleDepartmentUserService.listUserByRoleIdAndAreaCode(roleId, areaCode);
    }

    @ApiOperation(value = "用户列表（通过部门ID、角色ID）", notes = "获取指定部门中指定角色的用户列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "path", dataType = "String", required = true),
            @ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "path", dataType = "String", required = true),
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String", required = true),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list-user/department-id/{departmentId}/role-id/{roleId}")
    public List<DepartmentUserDTO> listUserByDepartmentIdAndRoleId(@PathVariable("departmentId") String departmentId,
                                                                   @PathVariable("roleId") String roleId,
                                                                   @RequestParam(name = "keywords", required = false) String keywords) {
        return roleDepartmentUserService.listDepartmentUserByDepartmentIdAndRoleIdAndKeywords(departmentId, roleId, keywords);
    }

    @ApiOperation(value = "用户分页列表", notes = "通过部门ID、角色ID用户列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "path"),
            @ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "path"),
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage-user/department-id/{departmentId}/role-id/{roleId}")
    public SuccessResultList<List<DepartmentUserDTO>> listPageUserByDepartmentIdAndRoleId(@PathVariable("departmentId") String departmentId, @PathVariable("roleId") String roleId, ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return roleDepartmentUserService.listPageDepartmentUserByDepartmentIdAndRoleId(departmentId, roleId, page);
    }

}
