feat(新增): 修改角色一些bug,用户管理CRUD完成

This commit is contained in:
bunny 2024-04-02 09:06:35 +08:00
parent e7784e7ae6
commit b321755bff
8 changed files with 123 additions and 35 deletions

View File

@ -8,7 +8,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -8,7 +8,7 @@ import lombok.Getter;
@Getter
public enum ResultCodeEnum {
SUCCESS(200, "成功"),
SUCCESS(200, "操作成功"),
FAIL(201, "失败"),
SERVICE_ERROR(2012, "服务异常"),
DATA_ERROR(204, "数据异常"),

48
pom.xml
View File

@ -123,28 +123,28 @@
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>nexus-aliyun</id>
<name>Nexus aliyun</name>
<layout>default</layout>
<url>https://maven.aliyun.com/repository/public</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>spring</id>
<url>https://maven.aliyun.com/repository/spring</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- <repositories> -->
<!-- <repository> -->
<!-- <id>nexus-aliyun</id> -->
<!-- <name>Nexus aliyun</name> -->
<!-- <layout>default</layout> -->
<!-- <url>https://maven.aliyun.com/repository/public</url> -->
<!-- <snapshots> -->
<!-- <enabled>false</enabled> -->
<!-- </snapshots> -->
<!-- <releases> -->
<!-- <enabled>true</enabled> -->
<!-- </releases> -->
<!-- </repository> -->
<!-- <repository> -->
<!-- <id>spring</id> -->
<!-- <url>https://maven.aliyun.com/repository/spring</url> -->
<!-- <releases> -->
<!-- <enabled>true</enabled> -->
<!-- </releases> -->
<!-- <snapshots> -->
<!-- <enabled>true</enabled> -->
<!-- </snapshots> -->
<!-- </repository> -->
<!-- </repositories> -->
</project>

View File

@ -1,12 +1,76 @@
package com.atguigu.ssyx.acl.controller;
import com.atguigu.ssyx.acl.service.AdminService;
import com.atguigu.ssyx.acl.service.RoleService;
import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.acl.Admin;
import com.atguigu.ssyx.vo.acl.AdminQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/admin/acl/user")
@Api(tags = "用户管理")
public class AdminController {
@Autowired
private AdminService adminService;
@Autowired
private RoleService roleService;
@ApiOperation(value = "获取管理用户分页列表")
@GetMapping("{page}/{limit}")
public Result<IPage<Admin>> index(
@ApiParam(name = "page", value = "当前页码", required = true)
@PathVariable Long page,
@ApiParam(name = "limit", value = "每页记录数", required = true)
@PathVariable Long limit,
@ApiParam(name = "userQueryVo", value = "查询对象")
AdminQueryVo userQueryVo
) {
IPage<Admin> pageModel = adminService.selectPage(page, limit, userQueryVo);
return Result.success(pageModel);
}
@ApiOperation(value = "获取管理用户")
@GetMapping("get/{id}")
public Result<Admin> get(@PathVariable Long id) {
Admin admin = adminService.getById(id);
return Result.success(admin);
}
@ApiOperation(value = "新增管理用户")
@PostMapping("save")
public Result<Admin> save(@RequestBody Admin admin) {
boolean isSuccess = adminService.save(admin);
return isSuccess ? Result.success() : Result.error();
}
@ApiOperation(value = "修改管理用户")
@PutMapping("update")
public Result<Admin> updateById(Admin admin) {
adminService.updateById(admin);
return Result.success();
}
@ApiOperation(value = "删除管理用户")
@DeleteMapping("remove/{id}")
public Result<Admin> remove(@PathVariable Long id) {
adminService.removeById(id);
return Result.success();
}
@ApiOperation(value = "根据id列表删除管理用户")
@DeleteMapping("batchRemove")
public Result<List<Long>> batchRemove(@PathVariable List<Long> ids) {
adminService.removeByIds(ids);
return Result.success();
}
}

View File

@ -46,10 +46,17 @@ public class RoleController {
@ApiOperation(value = "新增角色")
@PostMapping("save")
public Result<Role> saveRole(@RequestBody Role role) {
roleService.updateById(role);
roleService.save(role);
return Result.success();
}
@ApiOperation(value = "更新角色")
@PutMapping("update")
public Result<Role> updateRole(@RequestBody Role role) {
boolean isSuccess = roleService.updateById(role);
return isSuccess ? Result.success() : Result.error();
}
@ApiOperation(value = "删除角色")
@DeleteMapping("remove/{id}")
public Result<Role> removeRole(@PathVariable Long id) {

View File

@ -1,8 +1,11 @@
package com.atguigu.ssyx.acl.service;
import com.atguigu.ssyx.model.acl.Admin;
import com.atguigu.ssyx.vo.acl.AdminQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
public interface AdminService extends IService<Admin> {
IPage<Admin> selectPage(Long page, Long limit, AdminQueryVo userQueryVo);
}

View File

@ -3,15 +3,29 @@ package com.atguigu.ssyx.acl.service.impl;
import com.atguigu.ssyx.acl.mapper.AdminMapper;
import com.atguigu.ssyx.acl.service.AdminService;
import com.atguigu.ssyx.model.acl.Admin;
import com.atguigu.ssyx.vo.acl.AdminQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@Service
@Slf4j
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
@Override
public boolean save(Admin entity) {
return super.save(entity);
public IPage<Admin> selectPage(Long page, Long limit, AdminQueryVo vo) {
Page<Admin> pageParam = new Page<Admin>(page, limit);
String name = vo.getName();
String username = vo.getUsername();
// 封装条件进行返回
LambdaQueryWrapper<Admin> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(!StringUtils.isEmpty(username), Admin::getUsername, username);
wrapper.like(!StringUtils.isEmpty(name), Admin::getName, name);
return baseMapper.selectPage(pageParam, wrapper);
}
}

View File

@ -17,16 +17,16 @@ import org.springframework.stereotype.Service;
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
@Override
public IPage<Role> selectPage(Long page, Long limit, RoleQueryVo vo) {
Page<Role> rolePage = new Page<>(page, limit);
Page<Role> roleParam = new Page<>(page, limit);
// 获取条件值
String roleName = vo.getRoleName();
// 创建mp对象
LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>();
// 判断条件值是否为空
if (StringUtils.isEmpty(roleName)) {
wrapper.like(Role::getRoleName, rolePage);
if (!StringUtils.isEmpty(roleName)) {
wrapper.like(Role::getRoleName, roleParam);
}
// 调用犯法实现分页查询
return baseMapper.selectPage(rolePage, wrapper);
return baseMapper.selectPage(roleParam, wrapper);
}
}