package com.mosty.base.controller;

import com.mosty.base.model.vo.base.DeptInfoVo;
import com.mosty.base.service.UserDeptService;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.core.business.entity.vo.SysUserDeptVO;
import com.mosty.common.token.JwtSysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dw
 * @since 2022/8/8
 * 部门数据处理相关
 **/
@Api(tags = "用户信息处理相关")
@RestController
@AllArgsConstructor
@RequestMapping("/userDeptFeign")
public class UserDeptController {

    private final UserDeptService userDeptService;

    @ApiOperation("查询所有的用户数据（包含对应的部门信息）")
    @JwtSysUser
    @GetMapping("getUserAll/{deptid}")
    public ResponseResult<List<SysUserDeptVO>> getUserAll(@PathVariable("deptid") String deptid) {
        return ResponseResult.success(this.userDeptService.getUserAll(deptid));
    }

    @ApiOperation("查询部门下的总人数（包含子部门）")
    @JwtSysUser
    @GetMapping("getUserCount/{deptid}")
    public ResponseResult<Integer> getUserCount(@PathVariable("deptid") String deptid) {
        return ResponseResult.success(this.userDeptService.getUserCount(deptid));
    }

    @ApiOperation("查询部门下的人员信息，不包含子部门")
    @JwtSysUser
    @GetMapping("getUserList/{deptid}")
    public ResponseResult<List<SysUserDeptVO>> getUserList(@PathVariable("deptid") String deptid) {
        return ResponseResult.success(this.userDeptService.getUserList(deptid));
    }

    @ApiOperation("根据用户ID，获取用户部门信息")
    @JwtSysUser
    @GetMapping("getDeptInfoByUserId/{userId}")
    public ResponseResult<DeptInfoVo> getDeptInfoByUserId(@PathVariable("userId") String userId) {
        return ResponseResult.success(this.userDeptService.getDeptInfoByUserId(userId));
    }

    @ApiOperation("查询用户是否有该部门的数据权限")
    @JwtSysUser
    @GetMapping("getDataPermission")
    public ResponseResult<Boolean> getDataPermission(String sfz, String deptcode) {
        return ResponseResult.success(this.userDeptService.getDataPermission(sfz, deptcode));
    }


    @ApiOperation("根据用户身份证号，获取用户部门信息")
    @JwtSysUser
    @GetMapping("getDeptInfoBySfzh/{sfzh}")
    public ResponseResult<DeptInfoVo> getDeptInfoBySfzh(@PathVariable("sfzh") String sfzh) {
        return ResponseResult.success(this.userDeptService.getDeptInfoBySfzh(sfzh));
    }
}
