feat(新增): 修改角色一些bug,用户管理CRUD完成
This commit is contained in:
parent
e7784e7ae6
commit
b321755bff
|
@ -8,7 +8,7 @@
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</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" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
|
@ -8,7 +8,7 @@ import lombok.Getter;
|
||||||
@Getter
|
@Getter
|
||||||
public enum ResultCodeEnum {
|
public enum ResultCodeEnum {
|
||||||
|
|
||||||
SUCCESS(200, "成功"),
|
SUCCESS(200, "操作成功"),
|
||||||
FAIL(201, "失败"),
|
FAIL(201, "失败"),
|
||||||
SERVICE_ERROR(2012, "服务异常"),
|
SERVICE_ERROR(2012, "服务异常"),
|
||||||
DATA_ERROR(204, "数据异常"),
|
DATA_ERROR(204, "数据异常"),
|
||||||
|
|
48
pom.xml
48
pom.xml
|
@ -123,28 +123,28 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
<repositories>
|
<!-- <repositories> -->
|
||||||
<repository>
|
<!-- <repository> -->
|
||||||
<id>nexus-aliyun</id>
|
<!-- <id>nexus-aliyun</id> -->
|
||||||
<name>Nexus aliyun</name>
|
<!-- <name>Nexus aliyun</name> -->
|
||||||
<layout>default</layout>
|
<!-- <layout>default</layout> -->
|
||||||
<url>https://maven.aliyun.com/repository/public</url>
|
<!-- <url>https://maven.aliyun.com/repository/public</url> -->
|
||||||
<snapshots>
|
<!-- <snapshots> -->
|
||||||
<enabled>false</enabled>
|
<!-- <enabled>false</enabled> -->
|
||||||
</snapshots>
|
<!-- </snapshots> -->
|
||||||
<releases>
|
<!-- <releases> -->
|
||||||
<enabled>true</enabled>
|
<!-- <enabled>true</enabled> -->
|
||||||
</releases>
|
<!-- </releases> -->
|
||||||
</repository>
|
<!-- </repository> -->
|
||||||
<repository>
|
<!-- <repository> -->
|
||||||
<id>spring</id>
|
<!-- <id>spring</id> -->
|
||||||
<url>https://maven.aliyun.com/repository/spring</url>
|
<!-- <url>https://maven.aliyun.com/repository/spring</url> -->
|
||||||
<releases>
|
<!-- <releases> -->
|
||||||
<enabled>true</enabled>
|
<!-- <enabled>true</enabled> -->
|
||||||
</releases>
|
<!-- </releases> -->
|
||||||
<snapshots>
|
<!-- <snapshots> -->
|
||||||
<enabled>true</enabled>
|
<!-- <enabled>true</enabled> -->
|
||||||
</snapshots>
|
<!-- </snapshots> -->
|
||||||
</repository>
|
<!-- </repository> -->
|
||||||
</repositories>
|
<!-- </repositories> -->
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,12 +1,76 @@
|
||||||
package com.atguigu.ssyx.acl.controller;
|
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 io.swagger.annotations.Api;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/admin/acl/user")
|
@RequestMapping("/admin/acl/user")
|
||||||
@Api(tags = "用户管理")
|
@Api(tags = "用户管理")
|
||||||
public class AdminController {
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -46,10 +46,17 @@ public class RoleController {
|
||||||
@ApiOperation(value = "新增角色")
|
@ApiOperation(value = "新增角色")
|
||||||
@PostMapping("save")
|
@PostMapping("save")
|
||||||
public Result<Role> saveRole(@RequestBody Role role) {
|
public Result<Role> saveRole(@RequestBody Role role) {
|
||||||
roleService.updateById(role);
|
roleService.save(role);
|
||||||
return Result.success();
|
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 = "删除角色")
|
@ApiOperation(value = "删除角色")
|
||||||
@DeleteMapping("remove/{id}")
|
@DeleteMapping("remove/{id}")
|
||||||
public Result<Role> removeRole(@PathVariable Long id) {
|
public Result<Role> removeRole(@PathVariable Long id) {
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package com.atguigu.ssyx.acl.service;
|
package com.atguigu.ssyx.acl.service;
|
||||||
|
|
||||||
import com.atguigu.ssyx.model.acl.Admin;
|
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;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
public interface AdminService extends IService<Admin> {
|
public interface AdminService extends IService<Admin> {
|
||||||
|
|
||||||
|
IPage<Admin> selectPage(Long page, Long limit, AdminQueryVo userQueryVo);
|
||||||
}
|
}
|
|
@ -3,15 +3,29 @@ package com.atguigu.ssyx.acl.service.impl;
|
||||||
import com.atguigu.ssyx.acl.mapper.AdminMapper;
|
import com.atguigu.ssyx.acl.mapper.AdminMapper;
|
||||||
import com.atguigu.ssyx.acl.service.AdminService;
|
import com.atguigu.ssyx.acl.service.AdminService;
|
||||||
import com.atguigu.ssyx.model.acl.Admin;
|
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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
|
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
|
||||||
@Override
|
@Override
|
||||||
public boolean save(Admin entity) {
|
public IPage<Admin> selectPage(Long page, Long limit, AdminQueryVo vo) {
|
||||||
return super.save(entity);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,16 +17,16 @@ import org.springframework.stereotype.Service;
|
||||||
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
|
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
|
||||||
@Override
|
@Override
|
||||||
public IPage<Role> selectPage(Long page, Long limit, RoleQueryVo vo) {
|
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();
|
String roleName = vo.getRoleName();
|
||||||
// 创建mp对象
|
// 创建mp对象
|
||||||
LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>();
|
||||||
// 判断条件值是否为空
|
// 判断条件值是否为空
|
||||||
if (StringUtils.isEmpty(roleName)) {
|
if (!StringUtils.isEmpty(roleName)) {
|
||||||
wrapper.like(Role::getRoleName, rolePage);
|
wrapper.like(Role::getRoleName, roleParam);
|
||||||
}
|
}
|
||||||
// 调用犯法实现分页查询
|
// 调用犯法实现分页查询
|
||||||
return baseMapper.selectPage(rolePage, wrapper);
|
return baseMapper.selectPage(roleParam, wrapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue