package ink.wgink.login.oauth2.client.controller.apis.department;

import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.login.oauth2.client.service.department.IDepartmentUserService;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.dtos.department.DepartmentDTO;
import ink.wgink.pojo.dtos.department.DepartmentUserDTO;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResultList;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: DepartmentUserController
 * @Description: 组织部门用户
 * @Author: wanggeng
 * @Date: 2021/1/28 4:19 下午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "组织部门用户")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/department/user")
public class DepartmentUserController extends DefaultBaseController {

    @Autowired
    private IDepartmentUserService departmentUserService;

    @ApiOperation(value = "组织部门用户列表", notes = "组织部门用户列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "departmentId", 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/{departmentId}")
    public SuccessResultList<List<DepartmentUserDTO>> listPage(@PathVariable("departmentId") String departmentId, ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return departmentUserService.listPage(departmentId, page);
    }

    @ApiOperation(value = "组织部门用户ID列表", notes = "组织部门用户ID列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "path"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listuserid/{departmentId}")
    public List<String> listUserId(@PathVariable("departmentId") String departmentId) {
        return departmentUserService.listUserId(departmentId);
    }

    @ApiOperation(value = "自己的部门列表", notes = "自己的部门列表接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list-department/self")
    public List<DepartmentDTO> listDepartmentBySelf() {
        return departmentUserService.listDepartmentBySelf();
    }

    @ApiOperation(value = "组织部门用户ID列表", notes = "组织部门用户ID列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "path"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list-department/user-id/{userId}")
    public List<DepartmentDTO> listDepartmentByUserId(@PathVariable("userId") String userId) {
        return departmentUserService.listDepartmentByUserId(userId);
    }

}
