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

io.github.wslxm.springbootplus2.manage.sys.controller.SysUserController Maven / Gradle / Ivy

The newest version!
package io.github.wslxm.springbootplus2.manage.sys.controller;

import io.github.wslxm.springbootplus2.core.base.controller.BaseController;
import io.github.wslxm.springbootplus2.core.base.model.BasePage;
import io.github.wslxm.springbootplus2.core.constant.BaseConstant;
import io.github.wslxm.springbootplus2.core.result.Result;
import io.github.wslxm.springbootplus2.core.utils.XjBeanUtil;
import io.github.wslxm.springbootplus2.manage.sys.model.dto.SysUserDTO;
import io.github.wslxm.springbootplus2.manage.sys.model.query.SysUserQuery;
import io.github.wslxm.springbootplus2.manage.sys.model.vo.SysUserVO;
import io.github.wslxm.springbootplus2.manage.sys.service.SysUserService;
import io.github.wslxm.springbootplus2.utils.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统用户
 *
 * @author 王松
 * @WX-QQ 1720696548
 * @date 2019/11/13 13:38
 */
@RestController
@RequestMapping(BaseConstant.Uri.API_ADMIN + "/sys/user")
@Api(value = "SysUserController", tags = "base--sys--用户管理")
public class SysUserController extends BaseController {


    @GetMapping(value = "/findPage")
    @ApiOperation(value = "列表查询")
    public Result> findPage(@ModelAttribute @Validated SysUserQuery query) {
        return Result.successFind(baseService.findPage(query));
    }


    @GetMapping(value = "/{id}")
    @ApiOperation(value = "ID查询")
    public Result findId(@PathVariable String id) {
        return Result.success(baseService.findId(id));
    }


    @PostMapping
    @ApiOperation(value = "添加")
    public Result insert(@RequestBody @Validated SysUserDTO dto) {
        return Result.successInsert(baseService.insert(dto));
    }


    @PutMapping(value = "/{id}")
    @ApiOperation("ID编辑")
    public Result upd(@PathVariable String id, @RequestBody SysUserDTO dto) {
        dto.setPassword(null);
        return Result.successUpdate(baseService.upd(id, dto));
    }


    @DeleteMapping(value = "/{id}")
    @ApiOperation(value = "ID删除")
    public Result del(@PathVariable String id) {
        return Result.successDelete(baseService.del(id));
    }


    @GetMapping(value = "/findUser")
    @ApiOperation("查询当前登录人的个人信息")
    public Result findUser() {
        return Result.successFind(XjBeanUtil.convert(baseService.findId(JwtUtil.getJwtUser(request).getUserId()), SysUserVO.class));
    }


    @GetMapping(value = "/findByRoleId")
    @ApiOperation(value = "获取指定角色的用户列表")
    @ApiImplicitParam(name = "roleId", value = "角色Id", required = false, paramType = "query")
    public Result> findByRoleId(@RequestParam String roleId) {
        return Result.success(XjBeanUtil.listVo(baseService.findByRoleId(roleId), SysUserVO.class));
    }


    @GetMapping(value = "/list/keyData")
    @ApiOperation(value = "查询所有-只返回关键数据(姓名/昵称/电话/id)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "searchName", value = "姓名or用户名", required = false, paramType = "query", example = ""),
    })
    public Result> listKeyData(@RequestParam(required = false) String searchName) {
        return Result.success(baseService.listKeyData(searchName));
    }


    @PutMapping(value = "/updUser")
    @ApiOperation(value = "修改当前登录人的信息")
    public Result updUser(@RequestBody SysUserDTO dto) {
        return Result.successUpdate(baseService.upd(JwtUtil.getJwtUser(request).getUserId(), dto));
    }


    @PutMapping(value = "/updByPassword")
    @ApiOperation(value = "修改当前登录人的密码", notes = "判断原密码是否正确,不正确返回错误信息msg ,正确直接修改,密码进行MD5加密 --> val(前端输入密码值)+盐(后端规则指定)=最终密码)")
    public Result updByPassword(@RequestParam String oldPassword, @RequestParam String password) {
        Result result = Result.successUpdate(baseService.updByPassword(oldPassword, password));
        result.setMsg("修改密码成功");
        return result;
    }


    @PutMapping(value = "/{id}/resetPassword")
    @ApiOperation(value = "重置任意用户密码")
    public Result updResetPassword(@PathVariable String id, @RequestParam String password) {
        Result result = Result.successUpdate(baseService.updResetPassword(id, password));
        result.setMsg("重置密码成功");
        return result;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy