用户管理代码提交
parent
1ea23760b5
commit
03ac6f6612
@ -0,0 +1,74 @@
|
|||||||
|
package com.supervision.manage.controller.system;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.supervision.exception.BusinessException;
|
||||||
|
import com.supervision.model.User;
|
||||||
|
import com.supervision.service.UserService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Api(tags = "用户管理")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("userManage")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class UserManager {
|
||||||
|
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
@ApiOperation("查询用户列表")
|
||||||
|
@GetMapping("queryUserPage")
|
||||||
|
public IPage<User> queryUserPage(String userName, Integer roleCode, Integer pageNum, Integer pageSize) {
|
||||||
|
return userService.lambdaQuery().like(StrUtil.isNotBlank(userName), User::getName, userName)
|
||||||
|
.eq(ObjectUtil.isNotEmpty(roleCode), User::getRoleCode, roleCode).page(new Page<>(pageNum, pageSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("保存用户")
|
||||||
|
@PostMapping("saveUser")
|
||||||
|
public void saveUser(@RequestBody User user) {
|
||||||
|
Assert.notBlank(user.getAccount(), "用户账户不能为空");
|
||||||
|
Assert.notBlank(user.getName(), "用户名不能为空");
|
||||||
|
Assert.notBlank(user.getPassword(), "用户密码不能为空");
|
||||||
|
Assert.notEmpty(user.getRoleCode(), "用户角色不能为空");
|
||||||
|
if (0 > userService.lambdaQuery().eq(User::getAccount, user.getAccount()).count()) {
|
||||||
|
throw new BusinessException("账户名已存在");
|
||||||
|
}
|
||||||
|
userService.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("更新用户")
|
||||||
|
@PostMapping("updateUser")
|
||||||
|
public void updateUser(@RequestBody User user) {
|
||||||
|
Assert.notBlank(user.getId(), "ID不能为空");
|
||||||
|
Assert.notBlank(user.getAccount(), "用户账户不能为空");
|
||||||
|
Assert.notBlank(user.getName(), "用户名不能为空");
|
||||||
|
Assert.notBlank(user.getPassword(), "用户密码不能为空");
|
||||||
|
Assert.notEmpty(user.getRoleCode(), "用户角色不能为空");
|
||||||
|
// 查询旧的
|
||||||
|
User old = Optional.ofNullable(userService.getById(user.getId())).orElseThrow(() -> new BusinessException("用户不存在"));
|
||||||
|
if (!StrUtil.equals(old.getAccount(), user.getAccount())) {
|
||||||
|
throw new BusinessException("账号不允许更改");
|
||||||
|
}
|
||||||
|
userService.updateById(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("停用用户")
|
||||||
|
@GetMapping("deactivateUser")
|
||||||
|
public User deactivateUser(String id) {
|
||||||
|
User old = Optional.ofNullable(userService.getById(id)).orElseThrow(() -> new BusinessException("用户不存在"));
|
||||||
|
if (old.getStatus() == 0) {
|
||||||
|
userService.lambdaUpdate().set(User::getStatus, 1).eq(User::getId, id).update();
|
||||||
|
} else {
|
||||||
|
userService.lambdaUpdate().set(User::getStatus, 0).eq(User::getId, id).update();
|
||||||
|
}
|
||||||
|
return userService.getById(id);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
-- 2.0之后的SQL变更
|
||||||
|
alter table vp_user
|
||||||
|
add status int default 0 null comment '账号状态 0正常 1停用' after role_code;
|
Loading…
Reference in New Issue