All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.didiglobal.logi.security.controller.v1.UserController Maven / Gradle / Ivy

Go to download

logi-security 提供项目大多都需要的一些基础功能(用户、角色、权限、登录、注册、操作记录)

There is a newer version: 2.10.19
Show newest version
package com.didiglobal.logi.security.controller.v1;

import com.didiglobal.logi.security.common.constant.Constants;
import com.didiglobal.logi.security.common.PagingData;
import com.didiglobal.logi.security.common.PagingResult;
import com.didiglobal.logi.security.common.Result;
import com.didiglobal.logi.security.common.dto.config.ConfigDTO;
import com.didiglobal.logi.security.common.dto.user.UserDTO;
import com.didiglobal.logi.security.common.vo.role.AssignInfoVO;
import com.didiglobal.logi.security.common.dto.user.UserQueryDTO;
import com.didiglobal.logi.security.common.vo.user.UserBriefVO;
import com.didiglobal.logi.security.common.vo.user.UserVO;
import com.didiglobal.logi.security.exception.LogiSecurityException;
import com.didiglobal.logi.security.service.UserService;
import com.didiglobal.logi.security.util.HttpRequestUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author cjm
 */
@RestController
@Api(value = "logi-security-user相关API接口", tags = "logi-security-用户相关API接口")
@RequestMapping(Constants.V1 + "/logi-security/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/{id}")
    @ApiOperation(value = "获取用户详情", notes = "根据用户id获取用户详情")
    @ApiImplicitParam(name = "id", value = "用户id", dataType = "int", required = true)
    public Result detail(@PathVariable Integer id) {
        try {
            UserVO userVo = userService.getUserDetailByUserId(id);
            return Result.success(userVo);
        } catch (LogiSecurityException e) {
            return Result.fail(e);
        }
    }

    @PostMapping("/page")
    @ApiOperation(value = "查询用户列表", notes = "分页和条件查询")
    public PagingResult page(@RequestBody UserQueryDTO queryDTO) {
        PagingData pageUser = userService.getUserPage(queryDTO);
        return PagingResult.success(pageUser);
    }

    @GetMapping("/list/dept/{deptId}")
    @ApiOperation(value = "根据部门id获取用户list", notes = "根据部门id获取用户简要信息list")
    @ApiImplicitParam(name = "deptId", value = "部门id", dataType = "int", required = true)
    public Result> listByDeptId(@PathVariable Integer deptId) {
        List userBriefVOList = userService.getUserBriefListByDeptId(deptId);
        return Result.success(userBriefVOList);
    }

    @GetMapping("/list/role/{roleId}")
    @ApiOperation(value = "根据角色id获取用户list", notes = "根据角色id获取用户简要信息list")
    @ApiImplicitParam(name = "roleId", value = "角色id", dataType = "int", required = true)
    public Result> listByRoleId(@PathVariable Integer roleId) {
        List userBriefVOList = userService.getUserBriefListByRoleId(roleId);
        return Result.success(userBriefVOList);
    }

    @GetMapping(value = "/assign/list/{userId}")
    @ApiOperation(value = "用户管理/分配角色/列表", notes = "查询所有角色列表,并根据用户id,标记该用户拥有哪些角色")
    @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int", required = true)
    public Result> assignList(@PathVariable Integer userId) {
        try {
            List assignInfoVOList = userService.getAssignDataByUserId(userId);
            return Result.success(assignInfoVOList);
        } catch (LogiSecurityException e) {
            e.printStackTrace();
            return Result.fail(e);
        }
    }

    @GetMapping(value = {"/list/{name}"})
    @ApiOperation(value = "根据账户名或用户实名查询", notes = "获取用户简要信息list,会分别以账户名和实名去模糊查询,返回两者的并集")
    @ApiImplicitParam(name = "name", value = "账户名或用户实名(为null,则获取全部用户)", dataType = "String")
    public Result> listByName(@PathVariable(required = false) String name) {
        List userBriefVOList = userService.getUserBriefListByUsernameOrRealName(name);
        return Result.success(userBriefVOList);
    }

    @PutMapping("/add")
    @ResponseBody
    @ApiOperation(value = "用户新增接口,暂时没有考虑权限", notes = "")
    public Result add(HttpServletRequest request, @RequestBody UserDTO param) {
        return userService.addUser(param, HttpRequestUtil.getOperator(request));
    }

    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation(value = "编辑用户接口,暂时没有考虑权限", notes = "")
    public Result edit(HttpServletRequest request, @RequestBody UserDTO param) {
        return userService.editUser(param, HttpRequestUtil.getOperator(request));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除用户", notes = "根据用户id删除用户")
    @ApiImplicitParam(name = "id", value = "用户id", dataType = "int", required = true)
    public Result del(@PathVariable Integer id) {
        return userService.deleteByUserId(id);
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy