feat(新增): 查询用户信息,设置枚举类按断传入id不为空
This commit is contained in:
parent
0717f7ae07
commit
2cb30d55a7
|
@ -17,4 +17,6 @@ public class MessageConstant {
|
||||||
public static final String PASSWORD_EDIT_FAILED = "密码修改失败";
|
public static final String PASSWORD_EDIT_FAILED = "密码修改失败";
|
||||||
public static final String ALREADY_EXISTS = "已存在";
|
public static final String ALREADY_EXISTS = "已存在";
|
||||||
public static final String REQUEST_NOT_EMPTY = "请求不为空";
|
public static final String REQUEST_NOT_EMPTY = "请求不为空";
|
||||||
|
public static final String UPDATE_ID_IS_NOT_EMPTY = "修改id不能为空";
|
||||||
|
public static final String DELETE_ID_IS_NOT_EMPTY = "修改id不能为空";
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.atguigu.spzx.manger.controller;
|
||||||
|
|
||||||
|
import com.atguigu.spzx.manger.service.SysUserService;
|
||||||
|
import com.atguigu.spzx.model.dto.system.SysUserDto;
|
||||||
|
import com.atguigu.spzx.model.entity.system.SysUser;
|
||||||
|
import com.atguigu.spzx.model.vo.result.Result;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Tag(name = "用户管理接口")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value = "/admin/system/sysUser")
|
||||||
|
public class SysUserController {
|
||||||
|
@Autowired
|
||||||
|
private SysUserService sysUserService;
|
||||||
|
|
||||||
|
@Operation(summary = "查询用户", description = "查询用户信息")
|
||||||
|
@GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
|
||||||
|
public Result<PageInfo<SysUser>> findByPage(SysUserDto sysUserDto,
|
||||||
|
@PathVariable(value = "pageNum") Integer pageNum,
|
||||||
|
@PathVariable(value = "pageSize") Integer pageSize) {
|
||||||
|
PageInfo<SysUser> userPageInfo = sysUserService.findByPage(sysUserDto, pageNum, pageSize);
|
||||||
|
return Result.success(userPageInfo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,11 @@
|
||||||
package com.atguigu.spzx.manger.mapper;
|
package com.atguigu.spzx.manger.mapper;
|
||||||
|
|
||||||
|
import com.atguigu.spzx.model.dto.system.SysUserDto;
|
||||||
import com.atguigu.spzx.model.entity.system.SysUser;
|
import com.atguigu.spzx.model.entity.system.SysUser;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface SysUserMapper {
|
public interface SysUserMapper {
|
||||||
/**
|
/**
|
||||||
|
@ -12,4 +15,12 @@ public interface SysUserMapper {
|
||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
SysUser selectByUsername(String username);
|
SysUser selectByUsername(String username);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户
|
||||||
|
*
|
||||||
|
* @param sysUserDto 用户请求参数实体类
|
||||||
|
* @return List<SysUser>
|
||||||
|
*/
|
||||||
|
List<SysUser> findByPage(SysUserDto sysUserDto);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package com.atguigu.spzx.manger.service;
|
package com.atguigu.spzx.manger.service;
|
||||||
|
|
||||||
import com.atguigu.spzx.model.dto.system.LoginDto;
|
import com.atguigu.spzx.model.dto.system.LoginDto;
|
||||||
|
import com.atguigu.spzx.model.dto.system.SysUserDto;
|
||||||
|
import com.atguigu.spzx.model.entity.system.SysUser;
|
||||||
import com.atguigu.spzx.model.vo.system.LoginVo;
|
import com.atguigu.spzx.model.vo.system.LoginVo;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
|
||||||
public interface SysUserService {
|
public interface SysUserService {
|
||||||
/**
|
/**
|
||||||
|
@ -18,4 +21,14 @@ public interface SysUserService {
|
||||||
* @param token token值
|
* @param token token值
|
||||||
*/
|
*/
|
||||||
void logout(String token);
|
void logout(String token);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户
|
||||||
|
*
|
||||||
|
* @param sysUserDto 用户请求体
|
||||||
|
* @param pageNum 当前页
|
||||||
|
* @param pageSize 一页大小
|
||||||
|
* @return 用户分页结果
|
||||||
|
*/
|
||||||
|
PageInfo<SysUser> findByPage(SysUserDto sysUserDto, Integer pageNum, Integer pageSize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package com.atguigu.spzx.manger.service.impl;
|
package com.atguigu.spzx.manger.service.impl;
|
||||||
|
|
||||||
|
import com.atguigu.constant.MessageConstant;
|
||||||
import com.atguigu.spzx.manger.mapper.SysRoleMapper;
|
import com.atguigu.spzx.manger.mapper.SysRoleMapper;
|
||||||
import com.atguigu.spzx.manger.service.SysRoleService;
|
import com.atguigu.spzx.manger.service.SysRoleService;
|
||||||
import com.atguigu.spzx.model.dto.system.SysRoleDto;
|
import com.atguigu.spzx.model.dto.system.SysRoleDto;
|
||||||
import com.atguigu.spzx.model.entity.system.SysRole;
|
import com.atguigu.spzx.model.entity.system.SysRole;
|
||||||
|
import com.atguigu.utils.StringEmptyUtil;
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
@ -16,6 +18,8 @@ import java.util.List;
|
||||||
public class SysRoleServiceImpl implements SysRoleService {
|
public class SysRoleServiceImpl implements SysRoleService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysRoleMapper sysRoleMapper;
|
private SysRoleMapper sysRoleMapper;
|
||||||
|
@Autowired
|
||||||
|
private StringEmptyUtil emptyUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询角色信息返回分页
|
* 查询角色信息返回分页
|
||||||
|
@ -51,6 +55,9 @@ public class SysRoleServiceImpl implements SysRoleService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void updateSysRole(SysRole sysRole) {
|
public void updateSysRole(SysRole sysRole) {
|
||||||
|
emptyUtil.isEmpty(sysRole.getId(), MessageConstant.UPDATE_ID_IS_NOT_EMPTY);
|
||||||
|
|
||||||
|
// 修改内容
|
||||||
sysRoleMapper.updateSysRole(sysRole);
|
sysRoleMapper.updateSysRole(sysRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +68,8 @@ public class SysRoleServiceImpl implements SysRoleService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void deleteById(Long roleId) {
|
public void deleteById(Long roleId) {
|
||||||
|
emptyUtil.isEmpty(roleId, MessageConstant.DELETE_ID_IS_NOT_EMPTY);
|
||||||
|
// 删除内容
|
||||||
sysRoleMapper.deleteById(roleId);
|
sysRoleMapper.deleteById(roleId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,18 @@ import com.atguigu.lib.MD5;
|
||||||
import com.atguigu.spzx.manger.mapper.SysUserMapper;
|
import com.atguigu.spzx.manger.mapper.SysUserMapper;
|
||||||
import com.atguigu.spzx.manger.service.SysUserService;
|
import com.atguigu.spzx.manger.service.SysUserService;
|
||||||
import com.atguigu.spzx.model.dto.system.LoginDto;
|
import com.atguigu.spzx.model.dto.system.LoginDto;
|
||||||
|
import com.atguigu.spzx.model.dto.system.SysUserDto;
|
||||||
import com.atguigu.spzx.model.entity.system.SysUser;
|
import com.atguigu.spzx.model.entity.system.SysUser;
|
||||||
import com.atguigu.spzx.model.vo.system.LoginVo;
|
import com.atguigu.spzx.model.vo.system.LoginVo;
|
||||||
import com.atguigu.utils.StringEmptyUtil;
|
import com.atguigu.utils.StringEmptyUtil;
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -79,4 +84,23 @@ public class SysUserServiceImpl implements SysUserService {
|
||||||
public void logout(String token) {
|
public void logout(String token) {
|
||||||
redisTemplate.delete(token);
|
redisTemplate.delete(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户
|
||||||
|
*
|
||||||
|
* @param sysUserDto 用户请求体
|
||||||
|
* @param pageNum 当前页
|
||||||
|
* @param pageSize 一页大小
|
||||||
|
* @return 用户分页结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageInfo<SysUser> findByPage(SysUserDto sysUserDto, Integer pageNum, Integer pageSize) {
|
||||||
|
Page<Object> startedPage = PageHelper.startPage(pageNum, pageSize);
|
||||||
|
|
||||||
|
// 查询用户
|
||||||
|
List<SysUser> sysUserList = sysUserMapper.findByPage(sysUserDto);
|
||||||
|
startedPage.close();
|
||||||
|
|
||||||
|
return new PageInfo<>(sysUserList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<sql id="columns">
|
<sql id="columns">
|
||||||
id,username userName ,password,name,phone,avatar,description,status,create_time,update_time,is_deleted
|
id,username userName ,password,name,phone,avatar,description,status,create_time,update_time,is_deleted
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<!-- 根据username查询用户信息 -->
|
<!-- 根据username查询用户信息 -->
|
||||||
<select id="selectByUsername" resultType="com.atguigu.spzx.model.entity.system.SysUser">
|
<select id="selectByUsername" resultType="com.atguigu.spzx.model.entity.system.SysUser">
|
||||||
select
|
select
|
||||||
|
@ -12,4 +13,24 @@
|
||||||
from sys_user
|
from sys_user
|
||||||
where username = #{username};
|
where username = #{username};
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 查询用户 -->
|
||||||
|
<select id="findByPage" resultType="com.atguigu.spzx.model.entity.system.SysUser">
|
||||||
|
select
|
||||||
|
<include refid="columns"/>
|
||||||
|
from sys_user
|
||||||
|
<where>
|
||||||
|
<if test="keyword != null and keyword != ''">
|
||||||
|
and username like CONCAT('%',#{keyword},'%')
|
||||||
|
</if>
|
||||||
|
<if test="createTimeBegin != null and createTimeBegin != ''">
|
||||||
|
and create_time >= #{createTimeBegin}
|
||||||
|
</if>
|
||||||
|
<if test="createTimeEnd != null and createTimeEnd != ''">
|
||||||
|
and create_time <= #{createTimeEnd}
|
||||||
|
</if>
|
||||||
|
and is_deleted = 0
|
||||||
|
</where>
|
||||||
|
order by id desc
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -5,6 +5,22 @@
|
||||||
<sql id="columns">
|
<sql id="columns">
|
||||||
id,username userName ,password,name,phone,avatar,description,status,create_time,update_time,is_deleted
|
id,username userName ,password,name,phone,avatar,description,status,create_time,update_time,is_deleted
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
<sql id="findPageWhere">
|
||||||
|
<where>
|
||||||
|
<if test="keyword != null and keyword != ''">
|
||||||
|
and username like CONCAT('%',#{keyword},'%')
|
||||||
|
</if>
|
||||||
|
<if test="createTimeBegin != null and createTimeBegin != ''">
|
||||||
|
and create_time >= #{createTimeBegin}
|
||||||
|
</if>
|
||||||
|
<if test="createTimeEnd != null and createTimeEnd != ''">
|
||||||
|
and create_time <= #{createTimeEnd}
|
||||||
|
</if>
|
||||||
|
and is_deleted = 0
|
||||||
|
</where>
|
||||||
|
</sql>
|
||||||
|
|
||||||
<!-- 根据username查询用户信息 -->
|
<!-- 根据username查询用户信息 -->
|
||||||
<select id="selectByUsername" resultType="com.atguigu.spzx.model.entity.system.SysUser">
|
<select id="selectByUsername" resultType="com.atguigu.spzx.model.entity.system.SysUser">
|
||||||
select
|
select
|
||||||
|
@ -12,4 +28,13 @@
|
||||||
from sys_user
|
from sys_user
|
||||||
where username = #{username};
|
where username = #{username};
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 查询用户 -->
|
||||||
|
<select id="findByPage" resultType="com.atguigu.spzx.model.entity.system.SysUser">
|
||||||
|
select
|
||||||
|
<include refid="columns"/>
|
||||||
|
from sys_user
|
||||||
|
<include refid="findPageWhere"/>
|
||||||
|
order by id desc
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue