package ink.wgink.service.position.controller.resources;

import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.exceptions.ParamsException;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.dtos.position.PositionUserDTO;
import ink.wgink.pojo.pos.PositionPO;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResultList;
import ink.wgink.pojo.vos.IdsVO;
import ink.wgink.service.position.service.IPositionUserService;
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;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: PositionUserController
 * @Description: 职位用户
 * @Author: wanggeng
 * @Date: 2021/2/16 11:31 上午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_RESOURCE_PREFIX + "职位用户")
@RestController
@RequestMapping(ISystemConstant.RESOURCE_PREFIX + "/position/user")
public class PositionUserResourceController extends DefaultBaseController {

    @Autowired
    private IPositionUserService positionUserService;

    @ApiOperation(value = "人员ID列表", notes = "通过职位获取人员ID列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "positionId", value = "职位ID", paramType = "path"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list-userid/{positionId}")
    public List<String> listUserId(@PathVariable("positionId") String positionId) {
        return positionUserService.listUserId(positionId);
    }

    @ApiOperation(value = "人员ID列表", notes = "通过职位获取人员ID列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "positionId", value = "职位ID", paramType = "path"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list-userid/position-ids")
    public List<String> listUserIdByPositionIds(@RequestBody IdsVO idsVO) {
        return positionUserService.listUserId(idsVO.getIds());
    }

    @ApiOperation(value = "组人员列表", notes = "组人员列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "positionId", value = "组ID", paramType = "path", dataType = "String"),
            @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", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage/{positionId}")
    public SuccessResultList<List<PositionUserDTO>> listPage(@PathVariable("positionId") String positionId, ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return positionUserService.listPage(positionId, page);
    }

    @ApiOperation(value = "职位列表", notes = "通过用户ID获取职位列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "positionId", value = "组ID", paramType = "path", dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list-position-po/userid/{userId}")
    public List<PositionPO> listPositionPOByUserId(@PathVariable("userId") String userId) {
        return positionUserService.listPositionPOByUserId(userId);
    }

    @ApiOperation(value = "职位列表", notes = "通过用户ID列表获取职位列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "positionId", value = "组ID", paramType = "path", dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list-position-po/user-ids")
    public List<PositionPO> listPositionPOByUserId(@RequestBody IdsVO idsVO) {
        return positionUserService.listPositionPOByUserIds(idsVO.getIds());
    }

    @ApiOperation(value = "用户ID列表", notes = "通过职位ID和用户ID列表获取用户ID列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "path", dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("list-user-id/position-id/{positionId}/user-ids")
    public List<String> listUserIdByPositionIdAndUserIds(@PathVariable("positionId") String positionId, @RequestBody IdsVO idsVO) {
        if (idsVO.getIds().isEmpty()) {
            throw new ParamsException("id列表不能为空");
        }
        return positionUserService.listUserIdByPositionIdAndUserIds(positionId, idsVO.getIds());
    }

    @ApiOperation(value = "用户ID列表", notes = "通过职位ID列表和用户ID列表获取用户ID列表")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("list-user-id/position-ids/user-ids")
    public List<String> listUserIdByPositionIdAndUserIds(@RequestBody IdsVO idsVO) {
        if (idsVO.getIds().isEmpty()) {
            throw new ParamsException("id列表不能为空");
        }
        if (idsVO.getIds2().isEmpty()) {
            throw new ParamsException("id2列表不能为空");
        }
        return positionUserService.listUserIdByPositionIdsAndUserIds(idsVO.getIds(), idsVO.getIds2());
    }

    @ApiOperation(value = "职位ID列表", notes = "通过用户ID获取职位ID列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path", dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list-position-id/user-id/{userId}")
    public List<String> listPositionIdByUserId(@PathVariable("userId") String userId) {
        return positionUserService.listPositionIdByUserId(userId);
    }

    @ApiOperation(value = "职位ID列表", notes = "通过用户ID列表获取职位ID列表")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("list-position-id/user-ids")
    public List<String> listPositionIdByUserIds(@RequestBody IdsVO idsVO) {
        if (idsVO.getIds().isEmpty()) {
            throw new ParamsException("id列表不能为空");
        }
        return positionUserService.listPositionIdByUserIds(idsVO.getIds());
    }

}
