1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

user表role改为role_id;后台管理用户增删改查封装成component

This commit is contained in:
2023-03-28 22:13:59 +08:00
parent 880e4f8941
commit cf962a92da
33 changed files with 865 additions and 281 deletions

View File

@@ -82,6 +82,16 @@
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- 分页 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
</dependency>
<!-- 密码 Hash 加密 -->
<dependency>
<groupId>commons-codec</groupId>
@@ -89,11 +99,10 @@
</dependency>
<!-- 热部署 -->
<!--<dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-devtools</artifactId>-->
<!-- <version>2.7.5</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>

View File

@@ -1,25 +1,37 @@
package com.cxyxiaomo.epp.user.controller;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.cxyxiaomo.epp.common.enums.EditType;
import com.cxyxiaomo.epp.common.enums.SearchType;
import com.cxyxiaomo.epp.common.pojo.Role;
import com.cxyxiaomo.epp.common.pojo.User;
import com.cxyxiaomo.epp.common.query.PageQuery;
import com.cxyxiaomo.epp.common.response.Res;
import com.cxyxiaomo.epp.common.utils.PageTableFieldBuilder;
import com.cxyxiaomo.epp.common.utils.PageTableFieldMapperBuilder;
import com.cxyxiaomo.epp.common.vo.UserVO;
import com.cxyxiaomo.epp.user.service.UserServiceImpl;
import com.cxyxiaomo.epp.user.service.RoleService;
import com.cxyxiaomo.epp.user.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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.ResponseBody;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserServiceImpl userService;
private UserService userService;
@Autowired
private RoleService roleService;
/**
* 用户登录
@@ -58,6 +70,71 @@ public class UserController {
return userService.getUserById(id);
}
/**
* 获取用户列表
*
* @return
*/
@GetMapping("/manage/getUserList")
@ResponseBody
public Res getUserList(PageQuery pageQuery, UserVO userVO) {
// 查询分页数据
PageHelper.startPage(pageQuery.getPageIndex(), pageQuery.getPageSize());
List<User> userList = userService.getUserList(userVO);
PageInfo<User> userPageInfo = new PageInfo<>(userList);
List<User> list = userPageInfo.getList();
List<UserVO> voList = UserVO.convertFrom(list);
// 指定前端表格显示列
JSONArray columns = PageTableFieldBuilder.create()
.add("username", "username", "用户名",
true, SearchType.INPUT,
false, EditType.PLAIN_TEXT, null)
.add("roleId", "roleName", "角色",
true, SearchType.SELECT,
true, EditType.SELECT, 0)
.add("realname", "realname", "真实姓名",
true, SearchType.INPUT,
true, EditType.INPUT, "")
.add("phoneNumber", "phoneNumber", "电话",
true, SearchType.INPUT,
true, EditType.INPUT, "")
.add("idNumber", "idNumber", "身份证号",
true, SearchType.INPUT,
true, EditType.INPUT, "")
.add("buildingId", "buildingId", "门栋/单元号",
true, SearchType.INPUT,
true, EditType.INPUT, "")
.add("doorplate", "doorplate", "门牌号",
true, SearchType.INPUT,
true, EditType.INPUT, "")
.build();
// 指定需要翻译的字段
// role -> roleName
List<Role> roleList = roleService.getRoleList();
HashMap roleMap = new HashMap();
for (Role role : roleList) {
roleMap.put(role.getId(), role.getRoleName());
}
// build
JSONArray fieldMapper = PageTableFieldMapperBuilder.create()
.add("roleId", "roleName", roleMap)
.build();
// 拼装返回结果
JSONObject map = new JSONObject(2);
map.put("total", userPageInfo.getTotal());
map.put("list", voList);
map.put("columns", columns);
map.put("fieldMapper", fieldMapper);
// 返回结果
return Res.success(map);
}
@RequestMapping("/person")
@ResponseBody
public User person(String username) {

View File

@@ -0,0 +1,14 @@
package com.cxyxiaomo.epp.user.dao;
import com.cxyxiaomo.epp.common.pojo.Role;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper
@Repository
public interface RoleDao {
public List<Role> getRoleList();
}

View File

@@ -1,9 +1,12 @@
package com.cxyxiaomo.epp.user.dao;
import com.cxyxiaomo.epp.common.pojo.User;
import com.cxyxiaomo.epp.common.vo.UserVO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper
@Repository
public interface UserDao {
@@ -13,4 +16,6 @@ public interface UserDao {
public User getUserById(Long id);
User getUserByUsername(String username);
public List<User> getUserList(UserVO userVO);
}

View File

@@ -0,0 +1,20 @@
package com.cxyxiaomo.epp.user.service;
import com.cxyxiaomo.epp.common.pojo.Role;
import com.cxyxiaomo.epp.user.dao.RoleDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class RoleService {
@Autowired
private RoleDao roleDao;
public List<Role> getRoleList() {
List<Role> roleList = roleDao.getRoleList();
return roleList;
}
}

View File

@@ -1,10 +1,29 @@
package com.cxyxiaomo.epp.user.service;
import com.cxyxiaomo.epp.common.pojo.User;
import com.cxyxiaomo.epp.common.vo.UserVO;
import com.cxyxiaomo.epp.user.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
public interface UserService {
import java.util.List;
User getUserByUsername(String username);
@Service
public class UserService {
User getUserById(Long id);
@Autowired
private UserDao userDao;
public User getUserByUsername(String username) {
return userDao.getUserByUsername(username);
}
public User getUserById(Long id) {
return userDao.getUserById(id);
}
public List<User> getUserList(UserVO userVO) {
List<User> userList = userDao.getUserList(userVO);
return userList;
}
}

View File

@@ -1,23 +0,0 @@
package com.cxyxiaomo.epp.user.service;
import com.cxyxiaomo.epp.common.pojo.User;
import com.cxyxiaomo.epp.user.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Override
public User getUserByUsername(String username) {
return userDao.getUserByUsername(username);
}
@Override
public User getUserById(Long id) {
return userDao.getUserById(id);
}
}

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cxyxiaomo.epp.user.dao.RoleDao">
<select id="getRoleList" resultType="com.cxyxiaomo.epp.common.pojo.Role">
select * from role
</select>
</mapper>

View File

@@ -8,10 +8,39 @@
VALUES (#{username}, #{password})
</insert>
<select id="getUserById" parameterType="java.lang.Long" resultType="com.cxyxiaomo.epp.common.pojo.User">
SELECT * FROM user
SELECT *
FROM user
WHERE id = #{id}
</select>
<select id="getUserByUsername" resultType="com.cxyxiaomo.epp.common.pojo.User">
select * from user where username = #{username}
select *
from user
where username = #{username}
</select>
<select id="getUserList" resultType="com.cxyxiaomo.epp.common.pojo.User">
select *
from user
where 1 = 1
<if test="roleId != null">
AND role_id = #{roleId}
</if>
<if test="username != null &amp;&amp; username != ''">
AND username LIKE concat('%',#{username,jdbcType=VARCHAR},'%')
</if>
<if test="realname != null &amp;&amp; realname != ''">
AND realname LIKE concat('%',#{realname,jdbcType=VARCHAR},'%')
</if>
<if test="idNumber != null &amp;&amp; idNumber != ''">
AND id_number LIKE concat('%',#{idNumber,jdbcType=VARCHAR},'%')
</if>
<if test="phoneNumber != null &amp;&amp; phoneNumber != ''">
AND phone_number LIKE concat('%',#{phoneNumber,jdbcType=VARCHAR},'%')
</if>
<if test="buildingId != null &amp;&amp; buildingId != ''">
AND building_id LIKE concat('%',#{buildingId,jdbcType=VARCHAR},'%')
</if>
<if test="doorplate != null &amp;&amp; doorplate != ''">
AND doorplate LIKE concat('%',#{doorplate,jdbcType=VARCHAR},'%')
</if>
</select>
</mapper>