spring boot+iview 前后端分离架构之用户管理的实现(三十)

65 篇文章 5 订阅
42 篇文章 2 订阅

公众号

在这里插入图片描述
大家可以直接微信扫描上面的二维码关注我的公众号,然后回复【bg30】 里面就会给到源代码的下载地址同时会附上相应的视频教程,并定期在我的公众号上给大家推送相应的技术文章,欢迎大家关注我的公众号。

用户管理

在上面一章我们完成了组织的维护,但是在我们操作组织用户的时候页面是有报错的,报错的原因就是我们还没有整合用户,因此本章我们将开始整合我们的用户模块。

相关工具类的实现

在我们开始编写用户管理的时候我们首先需要实现一些相关工具类以及部分实体的改造工作。

User实体改造

package com.github.bg.admin.core.entity;

import com.github.bg.admin.core.util.UuidGenId;
import tk.mybatis.mapper.annotation.KeySql;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;

@Table(name = "t_user")
public class User implements Serializable {

    private static final long serialVersionUID = -5809782578282943998L;

    /**
     * 用户流水ID
     */
    @Id
    @Column(name = "userId")
    @KeySql(genId = UuidGenId.class)
    private String userId;

    /**
     * 用户登录账号
     */
    @Column(name = "loginAccount")
    private String loginAccount;

    /**
     * 用户登录密码
     */
    @Column(name = "loginPassword")
    private String loginPassword;

    /**
     * 创建时间
     */
    @Column(name = "crtDate")
    private Date crtDate;

    /**
     * 真实姓名
     */
    @Column(name = "nickName")
    private String nickName;

    /**
     * 最后登录时间
     */
    @Column(name = "lastLoginDate")
    private Date lastLoginDate;

    /**
     * 登录的token
     */
    @Column(name = "token")
    private String token;

    /**
     * 用户头像图片地址
     */
    @Column(name = "headImg")
    private String headImg;

    /**
     * 用户所在省
     */
    @Column(name = "province")
    private String province;

    /**
     * 用户所在省名称
     */
    @Column(name = "provinceName")
    private String provinceName;

    /**
     * 用户所在市
     */
    @Column(name = "city")
    private String city;

    /**
     * 用户所在市名称
     */
    @Column(name = "cityName")
    private String cityName;

    /**
     * 用户所在区
     */
    @Column(name = "area")
    private String area;

    /**
     * 用户所在区名称
     */
    @Column(name = "areaName")
    private String areaName;

    /**
     * 具体地址
     */
    @Column(name = "address")
    private String address;
    // 省略set和get
}

UserOrg实体改造

@Table(name = "t_user_org")
public class UserOrg {
    /**
     * 用户组织关联流水ID
     */
    @Id
    @Column(name = "userOrgId")
    @KeySql(genId = UuidGenId.class)
    private String userOrgId;

    /**
     * 用户流水ID
     */
    @Column(name = "userId")
    private String userId;

    /**
     * 组织流水ID
     */
    @Column(name = "orgId")
    private Integer orgId;
    // 省略set和get
}

UserRole实体改造

@Table(name = "t_user_role")
public class UserRole {
    /**
     * 用户角色关联流水ID
     */
    @Id
    @Column(name = "userRoleId")
    @KeySql(genId = UuidGenId.class)
    private String userRoleId;

    /**
     * 用户ID
     */
    @Column(name = "userId")
    private String userId;

    /**
     * 角色ID
     */
    @Column(name = "roleId")
    private String roleId;
    // 省略set和get
}

UserRoleDao.xml实现

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.github.bg.admin.core.dao.UserRoleDao">
  <resultMap id="BaseResultMap" type="com.github.bg.admin.core.entity.UserRole">
    <id column="userRoleId" jdbcType="VARCHAR" property="userRoleId" />
    <result column="userId" jdbcType="VARCHAR" property="userId" />
    <result column="roleId" jdbcType="VARCHAR" property="roleId" />
  </resultMap>

  <!-- 根据用户ID来删除关联数据 -->
  <delete id="deleteUserRoleByUserId">
    delete from t_user_role where userId = #{userId}
  </delete>

  <!-- 根据用户ID来获取用户和角色的关联数据 -->
  <select id="getUserRoleByUserId" resultMap="BaseResultMap">
    select * from t_user_role where userId = #{userId}
  </select>

</mapper>

UserRoleDao实现

package com.github.bg.admin.core.dao;

import com.github.bg.admin.core.entity.UserRole;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface UserRoleDao extends Mapper<UserRole> {

    /**
     * 功能描述:根据用户ID来删除关联数据
     * @param userId 用户ID
     * @return 返回删除结果
     */
    int deleteUserRoleByUserId(@Param("userId") String userId);

    /**
     * 功能描述:根据用户ID来获取用户和角色的关联数据
     *
     * @param userId 用户ID
     * @return 返回查询结果
     */
    List<UserRole> getUserRoleByUserId(@Param("userId") String userId);

}

用户管理的实现

UserDao.xml的实现

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.github.bg.admin.core.dao.UserDao">
    <resultMap id="BaseResultMap" type="com.github.bg.admin.core.entity.User">
        <id column="userId" jdbcType="VARCHAR" property="userId"/>
        <result column="loginAccount" jdbcType="VARCHAR" property="loginAccount"/>
        <result column="loginPassword" jdbcType="VARCHAR" property="loginPassword"/>
        <result column="crtDate" jdbcType="TIMESTAMP" property="crtDate"/>
        <result column="nickName" jdbcType="VARCHAR" property="nickName"/>
        <result column="lastLoginDate" jdbcType="TIMESTAMP" property="lastLoginDate"/>
        <result column="token" jdbcType="VARCHAR" property="token"/>
        <result column="headImg" jdbcType="VARCHAR" property="headImg"/>
        <result column="province" jdbcType="VARCHAR" property="province"/>
        <result column="provinceName" jdbcType="VARCHAR" property="provinceName"/>
        <result column="city" jdbcType="VARCHAR" property="city"/>
        <result column="cityName" jdbcType="VARCHAR" property="cityName"/>
        <result column="area" jdbcType="VARCHAR" property="area"/>
        <result column="areaName" jdbcType="VARCHAR" property="areaName"/>
        <result column="address" jdbcType="VARCHAR" property="address"/>
    </resultMap>

    <!-- 根据token和旧的密码来更新新的密码 -->
    <update id="changePassword">
        update t_user set loginPassword = #{newPassword} where token = #{token} and loginPassword = #{oldPassword}
    </update>

    <!-- 根据token来获取用户数据 -->
    <select id="getUserInfo" resultMap="BaseResultMap">
         select * from t_user where token = #{token}
    </select>

    <!-- 实现用户登陆 -->
    <select id="login" resultMap="BaseResultMap">
        select * from t_user where loginAccount = #{loginAccount} and loginPassword = #{loginPassword}
    </select>

    <!-- 验证这个账户是否已经创建过了 -->
    <select id="checkLoginAccount" resultType="java.lang.Integer">
        select count(*) from t_user where loginAccount = #{loginAccount}
    </select>

    <!-- 查询用户的数据 -->
    <select id="queryUserList" resultMap="BaseResultMap">
        select tu.* from t_user tu left join t_user_org tuo on tu.userId = tuo.userId left join t_org tg on tuo.orgId = tg.orgId where 1=1
        <if test="search != null  and search!='' ">
            and (
            tu.loginAccount like concat('%',#{search},'%') or
            tu.nickName like concat('%',#{search},'%')
            )
        </if>
        <if test="fullPath!= null  and fullPath!=''">
            and tg.fullPath like concat(#{fullPath},'%')
        </if>
    </select>

</mapper>

UserDao的实现

package com.github.bg.admin.core.dao;

import com.github.bg.admin.core.entity.User;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author linzf
 * @since 2019-07-05
 * 类描述:用户的dao
 */
public interface UserDao extends Mapper<User> {

    /**
     * 功能描述:根据token和旧的密码来更新新的密码
     * @param token 登录的token
     * @param oldPassword 旧的密码
     * @param newPassword 新的密码
     * @return 返回更新结果
     */
    int changePassword(@Param("token")String token,@Param("oldPassword")String oldPassword,@Param("newPassword")String newPassword);

    /**
     * 功能描述:根据token来获取用户数据
     * @param token token的值
     * @return 返回获取的结果
     */
    User getUserInfo(@Param("token")String token);

    /**
     * 功能描述:实现用户的登陆
     * @param loginAccount 用户账号
     * @param loginPassword 用户密码
     * @return 返回登陆结果
     */
    User login(@Param("loginAccount")String loginAccount,@Param("loginPassword")String loginPassword);

    /**
     * 功能描述:验证这个账户是否已经创建过了
     * @param loginAccount 用户账号
     * @return 返回验证结果
     */
    int checkLoginAccount(@Param("loginAccount")String loginAccount);

    /**
     * 功能描述:查询用户的数据
     * @param search 根据账号和名称来模糊查询
     * @param fullPath 父组织架构的匹配路径
     * @return 返回查询结果
     */
    List<User> queryUserList(@Param("search") String search, @Param("fullPath") String fullPath);

}

UserService的实现

package com.github.bg.admin.core.service;


import com.github.bg.admin.core.auth.Auth;
import com.github.bg.admin.core.constant.SystemStaticConst;
import com.github.bg.admin.core.dao.*;
import com.github.bg.admin.core.entity.*;
import com.github.bg.admin.core.util.JsonUtils;
import com.github.bg.admin.core.util.PageUtil;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author linzf
 * @since 2019/4/25
 * 类描述:用户的service类的实现
 */
@Service
@Transactional(rollbackFor = {IllegalArgumentException.class})
public class UserService {

    @Autowired
    private UserDao userDao;

    @Autowired
    private UserRoleDao userRoleDao;

    @Autowired
    private UserOrgDao userOrgDao;

    @Autowired
    private RoleDao roleDao;

    @Autowired
    private OrgDao orgDao;

    @Autowired
    private TreeDao treeDao;

    @Autowired
    private Auth authProvider;

    /**
     * 功能描述:根据token和旧的密码来更新新的密码
     *
     * @param token       登录的token
     * @param oldPassword 旧的密码
     * @param newPassword 新的密码
     * @return 返回更新结果
     */
    public ReturnInfo changePassword(String token, String oldPassword, String newPassword) {
        if (userDao.changePassword(token, oldPassword, newPassword) > 0) {
            return new ReturnInfo(SystemStaticConst.SUCCESS, "更新用户密码成功");
        } else {
            return new ReturnInfo(SystemStaticConst.FAIL, "密码不正确,更新失败!");
        }
    }

    /**
     * 功能描述:删除用户
     *
     * @param userId 用户ID
     * @return 返回删除结果
     */
    public ReturnInfo deleteUser(String userId) {
        if (userDao.deleteByPrimaryKey(userId) > 0) {
            // 根据用户ID删除角色表和组织架构表的关联数据
            userRoleDao.deleteUserRoleByUserId(userId);
            userOrgDao.deleteUserOrgByUserId(userId);
            return new ReturnInfo(SystemStaticConst.SUCCESS, "删除用户数据成功");
        } else {
            return new ReturnInfo(SystemStaticConst.FAIL, "查无此用户数据");
        }
    }

    /**
     * 功能描述:更新用户
     *
     * @param userId       用户ID
     * @param nickName     真实姓名
     * @param headImg      头像地址
     * @param province     所在省
     * @param provinceName 所在省名称
     * @param city         所在市
     * @param cityName     所在市名称
     * @param area         所在区
     * @param areaName     所在区名称
     * @param address      地址
     * @param orgIds       组织架构ID
     * @param roles        角色集合
     * @return 返回数据新增的结果
     */
    public ReturnInfo updateUser(@RequestParam(name = "userId") String userId,
                                 @RequestParam(name = "nickName") String nickName,
                                 @RequestParam(name = "headImg") String headImg,
                                 @RequestParam(name = "province") String province,
                                 @RequestParam(name = "provinceName") String provinceName,
                                 @RequestParam(name = "city") String city,
                                 @RequestParam(name = "cityName") String cityName,
                                 @RequestParam(name = "area") String area,
                                 @RequestParam(name = "areaName") String areaName,
                                 @RequestParam(name = "address") String address,
                                 @RequestParam(name = "orgIds") String[] orgIds,
                                 @RequestParam(name = "roles") String[] roles) {
        User user = userDao.selectByPrimaryKey(userId);
        if (user == null) {
            return new ReturnInfo(SystemStaticConst.FAIL, "查无此用户数据");
        }
        user.setNickName(nickName);
        user.setHeadImg(headImg);
        user.setCrtDate(new Date());
        user.setProvince(province);
        user.setProvinceName(provinceName);
        user.setCity(city);
        user.setCityName(cityName);
        user.setArea(area);
        user.setAreaName(areaName);
        user.setAddress(address);
        userDao.updateByPrimaryKey(user);
        // 根据用户ID删除角色表和组织架构表的关联数据
        userRoleDao.deleteUserRoleByUserId(userId);
        userOrgDao.deleteUserOrgByUserId(userId);
        // 增加用户和角色的关联的数据
        UserRole userRole;
        for (String role : roles) {
            userRole = new UserRole();
            userRole.setRoleId(role);
            userRole.setUserId(user.getUserId());
            userRoleDao.insert(userRole);
        }
        String orgId = orgIds[orgIds.length - 1];
        UserOrg userOrg = new UserOrg();
        userOrg.setOrgId(Integer.parseInt(orgId));
        userOrg.setUserId(user.getUserId());
        userOrgDao.insert(userOrg);
        return new ReturnInfo(SystemStaticConst.SUCCESS, "用户更新成功");
    }


    /**
     * 功能描述:根据用户流水ID来获取用户数据
     *
     * @param userId 用户流水ID
     * @return 返回获取结果
     */
    public ReturnInfo getUserByUserId(String userId) {
        User user = userDao.selectByPrimaryKey(userId);
        if (user == null) {
            return new ReturnInfo(SystemStaticConst.SUCCESS, "查无此用户数据");
        }
        Map<String, Object> result = JsonUtils.objToMap(user);
        List<UserRole> userRoleList = userRoleDao.getUserRoleByUserId(userId);
        String[] roleIds = new String[userRoleList.size()];
        for (int i = 0; i < userRoleList.size(); i++) {
            roleIds[i] = userRoleList.get(i).getRoleId();
        }
        result.put("roles", roleIds);
        // 获取组织架构的数据数据
        result.put("orgIds", orgDao.getOrgByUserId(userId).getFullPath().split("\\."));
        return new ReturnInfo(SystemStaticConst.SUCCESS, "加载用户信息成功", result);
    }

    /**
     * 功能描述:加载所有的角色数据
     *
     * @return 返回加载结果
     */
    public ReturnInfo loadAllRole() {
        return new ReturnInfo(SystemStaticConst.SUCCESS, "加载所有的角色成功", roleDao.selectAll());
    }

    /**
     * 功能描述:创建用户
     *
     * @param loginAccount 用户账号
     * @param nickName     真实姓名
     * @param headImg      头像地址
     * @param province     所在省
     * @param provinceName 所在省名称
     * @param city         所在市
     * @param cityName     所在市名称
     * @param area         所在区
     * @param areaName     所在区名称
     * @param address      地址
     * @param orgIds       组织架构ID
     * @param roles        角色集合
     * @return 返回数据新增的结果
     */
    public ReturnInfo createUser(String loginAccount, String nickName,
                                 String headImg, String province,
                                 String provinceName, String city,
                                 String cityName, String area,
                                 String areaName, String address,
                                 String[] orgIds, String[] roles) {
        if (userDao.checkLoginAccount(loginAccount) > 0) {
            return new ReturnInfo(SystemStaticConst.SUCCESS, "账号已经存在,请修改以后再进行提交!");
        }
        User user = new User();
        user.setLoginAccount(loginAccount);
        user.setNickName(nickName);
        user.setHeadImg(headImg);
        user.setLoginPassword("123456");
        user.setCrtDate(new Date());
        user.setProvince(province);
        user.setProvinceName(provinceName);
        user.setCity(city);
        user.setCityName(cityName);
        user.setArea(area);
        user.setAreaName(areaName);
        user.setAddress(address);
        userDao.insert(user);
        // 增加用户和角色的关联的数据
        UserRole userRole;
        for (String role : roles) {
            userRole = new UserRole();
            userRole.setRoleId(role);
            userRole.setUserId(user.getUserId());
            userRoleDao.insert(userRole);
        }
        String orgId = orgIds[orgIds.length - 1];
        UserOrg userOrg = new UserOrg();
        userOrg.setOrgId(Integer.parseInt(orgId));
        userOrg.setUserId(user.getUserId());
        userOrgDao.insert(userOrg);
        return new ReturnInfo(SystemStaticConst.SUCCESS, "用户创建成功");
    }

    /**
     * 功能描述:验证这个账户是否已经创建过了
     *
     * @param loginAccount 用户账号
     * @return 返回验证结果
     */
    public ReturnInfo checkLoginAccount(String loginAccount) {
        Map<String, Object> result = new HashMap<>(1);
        if (userDao.checkLoginAccount(loginAccount) > 0) {
            result.put("success", "unPass");
        } else {
            result.put("success", "pass");
        }
        return new ReturnInfo(SystemStaticConst.SUCCESS, "验证请求发送成功", result);
    }

    /**
     * 功能描述:获取用户列表
     *
     * @param fullPath     父组织架构的匹配路径
     * @param search       根据账号和名称来模糊查询
     * @param pageSize     每页显示的记录的条数
     * @param current      当前访问第几页
     * @param orderKey     排序字段
     * @param orderByValue 排序方式,降序还是升序
     * @return 返回查询结果
     */
    public ReturnInfo queryUserList(String fullPath, String search, int pageSize, int current, String orderKey, String orderByValue) {
        PageHelper.startPage(current, (pageSize > 0 && pageSize <= 500) ? pageSize : 20, (orderKey != null && !"".equals(orderKey)) ? ((orderByValue != null && !"".equals(orderByValue)) ? (orderKey + " " + orderByValue) : orderKey) : "");
        HashMap<String, Object> res = PageUtil.getResult(userDao.queryUserList(search, fullPath));
        return new ReturnInfo(SystemStaticConst.SUCCESS, "获取用户列表数据成功!", new Page(pageSize, current, (long) res.get("total"), (List) res.get("rows")));
    }

    /**
     * 功能描述:实现重新刷新token
     *
     * @param refreshToken token的值
     * @return 返回刷新结果
     */
    public ReturnInfo refreshToken(String refreshToken) {
        return authProvider.refreshToken(refreshToken);
    }


    /**
     * 功能描述:实现用户登陆
     *
     * @param loginAccount  用户账号
     * @param loginPassword 用户密码
     * @return 返回登陆结果
     */
    public ReturnInfo login(String loginAccount, String loginPassword) {
        return authProvider.login(loginAccount, loginPassword);
    }

    /**
     * 功能描述:根据token来获取用户数据
     *
     * @param token token的值
     * @return 返回获取的结果
     */
    public ReturnInfo getUserInfo(String token) {
        User user = userDao.getUserInfo(token);
        if (user == null) {
            return new ReturnInfo(SystemStaticConst.FAIL, "获取账号信息错误");
        }
        user.setLoginPassword(null);
        List<Tree> treeList = treeDao.getLoginUserTree(user.getUserId());
        String[] access = new String[treeList.size()];
        for (int i = 0; i < treeList.size(); i++) {
            access[i] = treeList.get(i).getTreeCode();
        }
        Map<String, Object> result = JsonUtils.objToMap(user);
        result.put("access", access);
        return new ReturnInfo(SystemStaticConst.SUCCESS, "登陆成功", result);
    }


}

UserController的实现

package com.github.bg.admin.core.controller;


import com.github.bg.admin.core.entity.ReturnInfo;
import com.github.bg.admin.core.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author linzf
 * @since 2019/4/25
 * 类描述:
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 功能描述:根据token和旧的密码来更新新的密码
     *
     * @param oldPassword 旧的密码
     * @param newPassword 新的密码
     * @return 返回更新结果
     */
    @ApiOperation(value = "根据token和旧的密码来更新新的密码")
    @PostMapping("changePassword")
    public ReturnInfo changePassword(@RequestParam(name = "oldPassword") String oldPassword,
                                     @RequestParam(name = "newPassword") String newPassword) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String token = request.getHeader("x-access-token");
        return userService.changePassword(token, oldPassword, newPassword);
    }

    /**
     * 功能描述:删除用户
     *
     * @param userId 用户ID
     * @return 返回删除结果
     */
    @ApiOperation(value = "删除用户")
    @PostMapping("deleteUser")
    public ReturnInfo deleteUser(@RequestParam(name = "userId") String userId) {
        return userService.deleteUser(userId);
    }

    /**
     * 功能描述:更新用户
     *
     * @param userId       用户ID
     * @param nickName     真实姓名
     * @param headImg      头像地址
     * @param province     所在省
     * @param provinceName 所在省名称
     * @param city         所在市
     * @param cityName     所在市名称
     * @param area         所在区
     * @param areaName     所在区名称
     * @param address      地址
     * @param orgIds       组织架构ID
     * @param roles        角色集合
     * @return 返回数据新增的结果
     */
    @ApiOperation(value = "更新用户")
    @PostMapping("updateUser")
    public ReturnInfo updateUser(@RequestParam(name = "userId") String userId,
                                 @RequestParam(name = "nickName") String nickName,
                                 @RequestParam(name = "headImg") String headImg,
                                 @RequestParam(name = "province") String province,
                                 @RequestParam(name = "provinceName") String provinceName,
                                 @RequestParam(name = "city") String city,
                                 @RequestParam(name = "cityName") String cityName,
                                 @RequestParam(name = "area") String area,
                                 @RequestParam(name = "areaName") String areaName,
                                 @RequestParam(name = "address") String address,
                                 @RequestParam(name = "orgIds") String[] orgIds,
                                 @RequestParam(name = "roles") String[] roles) {
        return userService.updateUser(userId, nickName, headImg, province, provinceName, city, cityName, area, areaName, address, orgIds, roles);
    }

    /**
     * 功能描述:根据用户流水ID来获取用户数据
     *
     * @param userId 用户流水ID
     * @return 返回获取结果
     */
    @ApiOperation(value = "根据用户流水ID来获取用户数据")
    @PostMapping("getUserByUserId")
    public ReturnInfo getUserByUserId(@RequestParam(name = "userId") String userId) {
        return userService.getUserByUserId(userId);
    }

    /**
     * 功能描述:加载所有的角色数据
     *
     * @return 返回加载结果
     */
    @ApiOperation(value = "加载所有的角色数据")
    @PostMapping("loadAllRole")
    public ReturnInfo loadAllRole() {
        return userService.loadAllRole();
    }


    /**
     * 功能描述:创建用户
     *
     * @param loginAccount 用户账号
     * @param nickName     真实姓名
     * @param headImg      头像地址
     * @param province     所在省
     * @param provinceName 所在省名称
     * @param city         所在市
     * @param cityName     所在市名称
     * @param area         所在区
     * @param areaName     所在区名称
     * @param address      地址
     * @param orgIds       组织架构ID
     * @param roles        角色集合
     * @return 返回数据新增的结果
     */
    @ApiOperation(value = "创建用户")
    @PostMapping("createUser")
    public ReturnInfo createUser(@RequestParam(name = "loginAccount") String loginAccount,
                                 @RequestParam(name = "nickName") String nickName,
                                 @RequestParam(name = "headImg") String headImg,
                                 @RequestParam(name = "province") String province,
                                 @RequestParam(name = "provinceName") String provinceName,
                                 @RequestParam(name = "city") String city,
                                 @RequestParam(name = "cityName") String cityName,
                                 @RequestParam(name = "area") String area,
                                 @RequestParam(name = "areaName") String areaName,
                                 @RequestParam(name = "address") String address,
                                 @RequestParam(name = "orgIds") String[] orgIds,
                                 @RequestParam(name = "roles") String[] roles) {
        return userService.createUser(loginAccount, nickName, headImg, province, provinceName, city, cityName, area, areaName, address, orgIds, roles);
    }

    /**
     * 功能描述:验证这个账户是否已经创建过了
     *
     * @param loginAccount 用户账号
     * @return 返回验证结果
     */
    @ApiOperation(value = "验证这个账户是否已经创建过了")
    @PostMapping("checkLoginAccount")
    public ReturnInfo checkLoginAccount(@RequestParam(name = "loginAccount") String loginAccount) {
        return userService.checkLoginAccount(loginAccount);
    }

    /**
     * 功能描述:获取用户列表
     *
     * @param fullPath     父组织架构的匹配路径
     * @param search       根据账号和名称来模糊查询
     * @param pageSize     每页显示的记录的条数
     * @param current      当前访问第几页
     * @param orderKey     排序字段
     * @param orderByValue 排序方式,降序还是升序
     * @return 返回查询结果
     */
    @ApiOperation(value = "获取用户列表")
    @PostMapping("queryUserList")
    public ReturnInfo queryUserList(@RequestParam(name = "fullPath") String fullPath, @RequestParam(name = "search") String search,
                                    @RequestParam(name = "pageSize") int pageSize, @RequestParam(name = "current") int current,
                                    @RequestParam(name = "orderKey") String orderKey, @RequestParam(name = "orderByValue") String orderByValue) {
        return userService.queryUserList(fullPath, search, pageSize, current, orderKey, orderByValue);
    }

    /**
     * 功能描述:实现重新刷新token
     *
     * @param refreshToken token的值
     * @return 返回刷新结果
     */
    @ApiOperation(value = "实现刷新用户的token")
    @PostMapping("refreshToken")
    public ReturnInfo refreshToken(@RequestParam(name = "refreshToken") String refreshToken) {
        return userService.refreshToken(refreshToken);
    }

    /**
     * 功能描述:实现用户登陆
     *
     * @param loginAccount  用户账号
     * @param loginPassword 用户密码
     * @return 返回登陆结果
     */
    @ApiOperation(value = "实现用户登陆")
    @PostMapping("login")
    public ReturnInfo login(@RequestParam(name = "loginAccount") String loginAccount, @RequestParam(name = "loginPassword") String loginPassword) {
        return userService.login(loginAccount, loginPassword);
    }


    /**
     * 功能描述:根据token来获取用户数据
     *
     * @param token token的值
     * @return 返回获取的结果
     */
    @ApiOperation(value = "根据token来获取用户数据")
    @PostMapping("getUserInfo")
    public ReturnInfo getUserInfo(@RequestParam(name = "token") String token) {
        return userService.getUserInfo(token);
    }

}

运行项目

最后我们重新编译我们的项目,记得一定要重新编译,因为我们引入了mapper,不重新编译是会报错的,然后我们使用账号:admin密码:123456登录系统操作我们的用户组织模块,可以看到我们已经可以正常的操作我们的用户组织模块了。
在这里插入图片描述
上一篇文章地址:spring boot+iview 前后端分离架构之组织管理的实现(二十九)
下一篇文章地址:spring boot+iview 前后端分离架构之文件上传的实现(三十一)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

笨_鸟_不_会_飞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值