feat(新增): 添加用户
This commit is contained in:
parent
2cb30d55a7
commit
598e1652a6
|
@ -18,7 +18,7 @@ public class SysRoleController {
|
|||
private SysRoleService sysRoleService;
|
||||
|
||||
@Operation(summary = "查询角色分页", description = "查询角色信息返回分页")
|
||||
@PostMapping("/findByPage/{pageNum}/{pageSize}")
|
||||
@PostMapping("findByPage/{pageNum}/{pageSize}")
|
||||
public Result<PageInfo<SysRole>> findByPage(@RequestBody SysRoleDto sysRoleDto,
|
||||
@PathVariable(value = "pageNum") Integer pageNum, @PathVariable(value = "pageSize") Integer pageSize) {
|
||||
PageInfo<SysRole> pageInfo = sysRoleService.findByPage(sysRoleDto, pageNum, pageSize);
|
||||
|
@ -26,21 +26,21 @@ public class SysRoleController {
|
|||
}
|
||||
|
||||
@Operation(summary = "添加角色", description = "添加角色相关内容")
|
||||
@PostMapping(value = "/saveSysRole")
|
||||
@PostMapping(value = "saveSysRole")
|
||||
public Result saveSysRole(@RequestBody SysRole sysRole) {
|
||||
sysRoleService.saveSysRole(sysRole);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "修改角色", description = "修改角色相关信息")
|
||||
@PutMapping(value = "/updateSysRole")
|
||||
@PutMapping(value = "updateSysRole")
|
||||
public Result updateSysRole(@RequestBody SysRole sysRole) {
|
||||
sysRoleService.updateSysRole(sysRole);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "根据角色id删除角色", description = "根据角色id删除角色信息")
|
||||
@DeleteMapping(value = "/deleteById/{roleId}")
|
||||
@DeleteMapping(value = "deleteById/{roleId}")
|
||||
public Result deleteById(@PathVariable(value = "roleId") Long roleId) {
|
||||
sysRoleService.deleteById(roleId);
|
||||
return Result.success();
|
||||
|
|
|
@ -8,10 +8,7 @@ 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;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "用户管理接口")
|
||||
@RestController
|
||||
|
@ -21,11 +18,18 @@ public class SysUserController {
|
|||
private SysUserService sysUserService;
|
||||
|
||||
@Operation(summary = "查询用户", description = "查询用户信息")
|
||||
@GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
|
||||
@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);
|
||||
}
|
||||
|
||||
@Operation(summary = "添加用户", description = "添加用户信息")
|
||||
@PostMapping(value = "saveSysUser")
|
||||
public Result saveSysUser(@RequestBody SysUser sysUser) {
|
||||
sysUserService.saveSysUser(sysUser);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -23,4 +23,11 @@ public interface SysUserMapper {
|
|||
* @return List<SysUser>
|
||||
*/
|
||||
List<SysUser> findByPage(SysUserDto sysUserDto);
|
||||
|
||||
/**
|
||||
* 添加用户
|
||||
*
|
||||
* @param sysUser 系统用户实体类
|
||||
*/
|
||||
void save(SysUser sysUser);
|
||||
}
|
||||
|
|
|
@ -31,4 +31,11 @@ public interface SysUserService {
|
|||
* @return 用户分页结果
|
||||
*/
|
||||
PageInfo<SysUser> findByPage(SysUserDto sysUserDto, Integer pageNum, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 添加用户
|
||||
*
|
||||
* @param sysUser 系统用户实体类
|
||||
*/
|
||||
void saveSysUser(SysUser sysUser);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.atguigu.spzx.manger.service.SysUserService;
|
|||
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.result.ResultCodeEnum;
|
||||
import com.atguigu.spzx.model.vo.system.LoginVo;
|
||||
import com.atguigu.utils.StringEmptyUtil;
|
||||
import com.github.pagehelper.Page;
|
||||
|
@ -103,4 +104,30 @@ public class SysUserServiceImpl implements SysUserService {
|
|||
|
||||
return new PageInfo<>(sysUserList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加用户
|
||||
*
|
||||
* @param sysUser 系统用户实体类
|
||||
*/
|
||||
@Override
|
||||
public void saveSysUser(SysUser sysUser) {
|
||||
// 判断用户名不能为空
|
||||
String username = sysUser.getUserName();
|
||||
stringEmptyUtil.isEmpty(username, "用户名不能为空");
|
||||
|
||||
SysUser dbUser = sysUserMapper.selectByUsername(sysUser.getUserName());
|
||||
// 如果用户已存在
|
||||
if (dbUser != null) {
|
||||
throw new BunnyException(ResultCodeEnum.USERNAME_IS_EXISTS);
|
||||
}
|
||||
// 设置密码加密
|
||||
String password = sysUser.getPassword();
|
||||
String encryptedPassword = MD5.encrypt(password);
|
||||
sysUser.setPassword(encryptedPassword);
|
||||
sysUser.setStatus(0);
|
||||
|
||||
// 插入数据
|
||||
sysUserMapper.save(sysUser);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,12 @@
|
|||
id,username userName ,password,name,phone,avatar,description,status,create_time,update_time,is_deleted
|
||||
</sql>
|
||||
|
||||
<!-- 添加用户 -->
|
||||
<insert id="save">
|
||||
insert into sys_user (id, username, password, name, phone, avatar, description, status)
|
||||
values (#{id}, #{userName}, #{password}, #{name}, #{phone}, #{avatar}, #{description}, #{status});
|
||||
</insert>
|
||||
|
||||
<!-- 根据username查询用户信息 -->
|
||||
<select id="selectByUsername" resultType="com.atguigu.spzx.model.entity.system.SysUser">
|
||||
select
|
||||
|
|
|
@ -15,7 +15,9 @@ public enum ResultCodeEnum {
|
|||
LOGIN_AUTH(208, "需要先登陆"),
|
||||
LOGIN_MOBLE_ERROR(208, "登录验证失败"),
|
||||
ACCOUNT_DEACTIVATION(208, "账户停用"),
|
||||
PERMISSION(209, "没有权限");
|
||||
PERMISSION(209, "没有权限"),
|
||||
USERNAME_IS_EXISTS(500, "用户名已存在"),
|
||||
;
|
||||
|
||||
private final Integer code;
|
||||
private final String message;
|
||||
|
|
Loading…
Reference in New Issue