实现用户角色权限区域管理模块
This commit is contained in:
		
							
								
								
									
										82
									
								
								guigu-ssyx-parent/service/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								guigu-ssyx-parent/service/pom.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,82 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
 | 
			
		||||
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
			
		||||
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 | 
			
		||||
    <modelVersion>4.0.0</modelVersion>
 | 
			
		||||
    <parent>
 | 
			
		||||
        <groupId>com.atguigu</groupId>
 | 
			
		||||
        <artifactId>guigu-ssyx-parent</artifactId>
 | 
			
		||||
        <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </parent>
 | 
			
		||||
 | 
			
		||||
    <artifactId>service</artifactId>
 | 
			
		||||
    <packaging>pom</packaging>
 | 
			
		||||
    <modules>
 | 
			
		||||
        <module>service-acl</module>
 | 
			
		||||
        <module>service-sys</module>
 | 
			
		||||
    </modules>
 | 
			
		||||
 | 
			
		||||
    <dependencies>
 | 
			
		||||
        <!--依赖服务的工具类-->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.atguigu</groupId>
 | 
			
		||||
            <artifactId>service-util</artifactId>
 | 
			
		||||
            <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <!--数据载体-->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.atguigu</groupId>
 | 
			
		||||
            <artifactId>model</artifactId>
 | 
			
		||||
            <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <!--web 需要启动项目-->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework.boot</groupId>
 | 
			
		||||
            <artifactId>spring-boot-starter-web</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <!--mybatis-plus-->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.baomidou</groupId>
 | 
			
		||||
            <artifactId>mybatis-plus-boot-starter</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <!--mysql-->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>mysql</groupId>
 | 
			
		||||
            <artifactId>mysql-connector-java</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <!-- 服务注册 -->
 | 
			
		||||
        <!--        <dependency>-->
 | 
			
		||||
        <!--            <groupId>com.alibaba.cloud</groupId>-->
 | 
			
		||||
        <!--            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>-->
 | 
			
		||||
        <!--        </dependency>-->
 | 
			
		||||
 | 
			
		||||
        <!-- 服务调用feign -->
 | 
			
		||||
        <!--        <dependency>-->
 | 
			
		||||
        <!--            <groupId>org.springframework.cloud</groupId>-->
 | 
			
		||||
        <!--            <artifactId>spring-cloud-starter-openfeign</artifactId>-->
 | 
			
		||||
        <!--        </dependency>-->
 | 
			
		||||
 | 
			
		||||
        <!-- 流量控制 -->
 | 
			
		||||
        <!--        <dependency>-->
 | 
			
		||||
        <!--            <groupId>com.alibaba.cloud</groupId>-->
 | 
			
		||||
        <!--            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>-->
 | 
			
		||||
        <!--        </dependency>-->
 | 
			
		||||
 | 
			
		||||
        <!--开发者工具-->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework.boot</groupId>
 | 
			
		||||
            <artifactId>spring-boot-devtools</artifactId>
 | 
			
		||||
            <optional>true</optional>
 | 
			
		||||
        </dependency>
 | 
			
		||||
    </dependencies>
 | 
			
		||||
    <properties>
 | 
			
		||||
        <maven.compiler.source>8</maven.compiler.source>
 | 
			
		||||
        <maven.compiler.target>8</maven.compiler.target>
 | 
			
		||||
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
			
		||||
    </properties>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
							
								
								
									
										20
									
								
								guigu-ssyx-parent/service/service-acl/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								guigu-ssyx-parent/service/service-acl/pom.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
			
		||||
         xmlns="http://maven.apache.org/POM/4.0.0"
 | 
			
		||||
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 | 
			
		||||
    <modelVersion>4.0.0</modelVersion>
 | 
			
		||||
    <parent>
 | 
			
		||||
        <groupId>com.atguigu</groupId>
 | 
			
		||||
        <artifactId>service</artifactId>
 | 
			
		||||
        <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </parent>
 | 
			
		||||
 | 
			
		||||
    <artifactId>service-acl</artifactId>
 | 
			
		||||
 | 
			
		||||
    <properties>
 | 
			
		||||
        <maven.compiler.source>8</maven.compiler.source>
 | 
			
		||||
        <maven.compiler.target>8</maven.compiler.target>
 | 
			
		||||
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
			
		||||
    </properties>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,21 @@
 | 
			
		||||
package com.atguigu.ssyx;
 | 
			
		||||
 | 
			
		||||
import org.springframework.boot.SpringApplication;
 | 
			
		||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: ServiceAclApplication
 | 
			
		||||
 * Package: com.atguigu.ssyx
 | 
			
		||||
 * 权限管理模块启动类
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/13 17:38
 | 
			
		||||
 */
 | 
			
		||||
@SpringBootApplication
 | 
			
		||||
public class ServiceAclApplication {
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        SpringApplication.run(ServiceAclApplication.class, args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,135 @@
 | 
			
		||||
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.common.utils.MD5;
 | 
			
		||||
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.plugins.pagination.Page;
 | 
			
		||||
import io.swagger.annotations.Api;
 | 
			
		||||
import io.swagger.annotations.ApiOperation;
 | 
			
		||||
import io.swagger.annotations.ApiParam;
 | 
			
		||||
import org.apache.commons.lang3.StringUtils;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: AdminController
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.controller
 | 
			
		||||
 * 用户管理 前端控制器
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 10:38
 | 
			
		||||
 */
 | 
			
		||||
@RestController
 | 
			
		||||
@RequestMapping("/admin/acl/user")
 | 
			
		||||
@Api(tags = "用户管理")
 | 
			
		||||
@CrossOrigin
 | 
			
		||||
public class AdminController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private AdminService adminService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private RoleService roleService;
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "获取管理用户分页列表")
 | 
			
		||||
    @GetMapping("{page}/{limit}")
 | 
			
		||||
    public Result index(@ApiParam(name = "page", value = "当前页码", required = true) @PathVariable Long page,
 | 
			
		||||
                        @ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable Long limit,
 | 
			
		||||
                        @ApiParam(name = "userQueryVo", value = "查询对象", required = false) AdminQueryVo userQueryVo) {
 | 
			
		||||
        try {
 | 
			
		||||
            Page<Admin> pageParam = new Page<>(page, limit);
 | 
			
		||||
            IPage<Admin> pageModel = adminService.selectPage(pageParam, userQueryVo);
 | 
			
		||||
            return Result.ok(pageModel);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("获取管理用户分页列表异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "获取管理用户")
 | 
			
		||||
    @GetMapping("get/{id}")
 | 
			
		||||
    public Result get(@PathVariable Long id) {
 | 
			
		||||
        try {
 | 
			
		||||
            Admin user = adminService.getById(id);
 | 
			
		||||
            return Result.ok(user);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("获取管理用户异常", e);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "新增管理用户")
 | 
			
		||||
    @PostMapping("save")
 | 
			
		||||
    public Result save(@RequestBody Admin user) {
 | 
			
		||||
        try {
 | 
			
		||||
            //对密码进行MD5处理
 | 
			
		||||
            user.setPassword(MD5.encrypt(user.getPassword()));
 | 
			
		||||
            boolean result = adminService.save(user);
 | 
			
		||||
            return result ? Result.ok(null) : Result.fail(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("新增管理用户异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "修改管理用户")
 | 
			
		||||
    @PutMapping("update")
 | 
			
		||||
    public Result updateById(@RequestBody Admin user) {
 | 
			
		||||
        try {
 | 
			
		||||
            boolean result = adminService.updateById(user);
 | 
			
		||||
            return result ? Result.ok(null) : Result.fail(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("修改管理用户异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "删除管理用户")
 | 
			
		||||
    @DeleteMapping("remove/{id}")
 | 
			
		||||
    public Result remove(@PathVariable Long id) {
 | 
			
		||||
        try {
 | 
			
		||||
            boolean result = adminService.removeById(id);
 | 
			
		||||
            return result ? Result.ok(null) : Result.fail(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("删除管理用户异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "根据id列表删除管理用户")
 | 
			
		||||
    @DeleteMapping("batchRemove")
 | 
			
		||||
    public Result batchRemove(@RequestBody List<Long> idList) {
 | 
			
		||||
        try {
 | 
			
		||||
            boolean result = adminService.removeByIds(idList);
 | 
			
		||||
            return result ? Result.ok(null) : Result.fail(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("根据id列表删除管理用户异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "根据用户获取角色数据")
 | 
			
		||||
    @GetMapping("/toAssign/{adminId}")
 | 
			
		||||
    public Result toAssign(@PathVariable Long adminId) {
 | 
			
		||||
        try {
 | 
			
		||||
            Map<String, Object> roleMap = roleService.findRoleByUserId(adminId);
 | 
			
		||||
            return StringUtils.isNotEmpty(roleMap.toString()) ? Result.ok(roleMap) : Result.fail(roleMap);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("根据用户获取角色数据异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "根据用户分配角色")
 | 
			
		||||
    @PostMapping("/doAssign")
 | 
			
		||||
    public Result doAssign(@RequestParam Long adminId, @RequestParam Long[] roleId) {
 | 
			
		||||
        try {
 | 
			
		||||
            roleService.saveUserRoleRealtionShip(adminId, roleId);
 | 
			
		||||
            return Result.ok(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("根据用户分配角色异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,52 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.controller;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.common.result.Result;
 | 
			
		||||
import io.swagger.annotations.Api;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: IndexController
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.controller
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/13 18:00
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@Api(tags = "登录接口")
 | 
			
		||||
@RestController
 | 
			
		||||
@RequestMapping("/admin/acl/index")
 | 
			
		||||
@CrossOrigin     //跨域
 | 
			
		||||
public class IndexController {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 1、请求登陆的login
 | 
			
		||||
     */
 | 
			
		||||
    @PostMapping("login")
 | 
			
		||||
    public Result login() {
 | 
			
		||||
        Map<String, Object> map = new HashMap<>();
 | 
			
		||||
        map.put("token", "admin-token");
 | 
			
		||||
        return Result.ok(map);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 2 获取用户信息
 | 
			
		||||
     */
 | 
			
		||||
    @GetMapping("info")
 | 
			
		||||
    public Result info() {
 | 
			
		||||
        Map<String, Object> map = new HashMap<>();
 | 
			
		||||
        map.put("name", "atguigu");
 | 
			
		||||
        map.put("avatar", "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
 | 
			
		||||
        return Result.ok(map);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 3 退出
 | 
			
		||||
     */
 | 
			
		||||
    @PostMapping("logout")
 | 
			
		||||
    public Result logout() {
 | 
			
		||||
        return Result.ok(null);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,74 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.controller;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.acl.service.PermissionService;
 | 
			
		||||
import com.atguigu.ssyx.common.result.Result;
 | 
			
		||||
import com.atguigu.ssyx.model.acl.Permission;
 | 
			
		||||
import io.swagger.annotations.Api;
 | 
			
		||||
import io.swagger.annotations.ApiOperation;
 | 
			
		||||
import org.apache.commons.lang3.StringUtils;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: PermissionController
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.controller
 | 
			
		||||
 * 菜单服务
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 14:03
 | 
			
		||||
 */
 | 
			
		||||
@RestController
 | 
			
		||||
@RequestMapping("/admin/acl/permission")
 | 
			
		||||
@Api(tags = "菜单服务")
 | 
			
		||||
@CrossOrigin
 | 
			
		||||
public class PermissionController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private PermissionService permissionService;
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "获取菜单")
 | 
			
		||||
    @GetMapping
 | 
			
		||||
    public Result index() {
 | 
			
		||||
        try {
 | 
			
		||||
            List<Permission> list = permissionService.queryAllMenu();
 | 
			
		||||
            return StringUtils.isNotEmpty(list.toString()) ? Result.ok(list) : Result.fail(list);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("获取菜单异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "新增菜单")
 | 
			
		||||
    @PostMapping("save")
 | 
			
		||||
    public Result save(@RequestBody Permission permission) {
 | 
			
		||||
        try {
 | 
			
		||||
            boolean result = permissionService.save(permission);
 | 
			
		||||
            return result ? Result.ok(null) : Result.fail(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("新增菜单异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "修改菜单")
 | 
			
		||||
    @PutMapping("update")
 | 
			
		||||
    public Result updateById(@RequestBody Permission permission) {
 | 
			
		||||
        try {
 | 
			
		||||
            boolean result = permissionService.updateById(permission);
 | 
			
		||||
            return result ? Result.ok(null) : Result.fail(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("修改菜单异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "递归删除菜单")
 | 
			
		||||
    @DeleteMapping("remove/{id}")
 | 
			
		||||
    public Result remove(@PathVariable Long id) {
 | 
			
		||||
        try {
 | 
			
		||||
            boolean result = permissionService.removeChildById(id);
 | 
			
		||||
            return result ? Result.ok(null) : Result.fail(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("递归删除菜单异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,128 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.controller;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.acl.service.PermissionService;
 | 
			
		||||
import com.atguigu.ssyx.acl.service.RoleService;
 | 
			
		||||
import com.atguigu.ssyx.common.result.Result;
 | 
			
		||||
import com.atguigu.ssyx.model.acl.Role;
 | 
			
		||||
import com.atguigu.ssyx.vo.acl.RoleQueryVo;
 | 
			
		||||
import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
			
		||||
import io.swagger.annotations.Api;
 | 
			
		||||
import io.swagger.annotations.ApiOperation;
 | 
			
		||||
import io.swagger.annotations.ApiParam;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: RoleController
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.controller
 | 
			
		||||
 * 角色管理 前端控制器
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 09:09
 | 
			
		||||
 */
 | 
			
		||||
@RestController
 | 
			
		||||
@RequestMapping("/admin/acl/role")
 | 
			
		||||
@Api(tags = "角色管理")
 | 
			
		||||
@CrossOrigin
 | 
			
		||||
@Slf4j
 | 
			
		||||
public class RoleController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private RoleService roleService;
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private PermissionService permissionService;
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "获取角色分页列表")
 | 
			
		||||
    @GetMapping("{page}/{limit}")
 | 
			
		||||
    public Result index(@ApiParam(name = "page", value = "当前页码", required = true)
 | 
			
		||||
                        @PathVariable Long page, @ApiParam(name = "limit", value = "每页记录数", required = true)
 | 
			
		||||
                        @PathVariable Long limit, @ApiParam(name = "roleQueryVo", value = "查询对象", required = false)
 | 
			
		||||
                        RoleQueryVo roleQueryVo) {
 | 
			
		||||
        try {
 | 
			
		||||
            Page<Role> pageParam = new Page<>(page, limit);
 | 
			
		||||
            IPage<Role> pageModel = roleService.selectPage(pageParam, roleQueryVo);
 | 
			
		||||
            return Result.ok(pageModel);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            // 处理异常,例如记录日志或者抛出自定义异常
 | 
			
		||||
            throw new RuntimeException("获取角色分页列表异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "获取角色")
 | 
			
		||||
    @GetMapping("get/{id}")
 | 
			
		||||
    public Result get(@PathVariable Long id) {
 | 
			
		||||
        try {
 | 
			
		||||
            Role role = roleService.getById(id);
 | 
			
		||||
            return Result.ok(role);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("获取角色异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "新增角色")
 | 
			
		||||
    @PostMapping("save")
 | 
			
		||||
    public Result save(@RequestBody Role role) {
 | 
			
		||||
        try {
 | 
			
		||||
            boolean result = roleService.save(role);
 | 
			
		||||
            return result ? Result.ok(null) : Result.fail(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            // 处理异常,例如记录日志或者抛出自定义异常
 | 
			
		||||
            throw new RuntimeException("新增角色异常" + role.toString(), e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "修改角色")
 | 
			
		||||
    @PutMapping("update")
 | 
			
		||||
    public Result updateById(@RequestBody Role role) {
 | 
			
		||||
        try {
 | 
			
		||||
            boolean result = roleService.updateById(role);
 | 
			
		||||
            return result ? Result.ok(null) : Result.fail(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            // 处理异常,例如记录日志或者抛出自定义异常
 | 
			
		||||
            throw new RuntimeException("修改角色异常" + role.toString(), e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "删除角色")
 | 
			
		||||
    @DeleteMapping("remove/{id}")
 | 
			
		||||
    public Result remove(@PathVariable Long id) {
 | 
			
		||||
        try {
 | 
			
		||||
            boolean result = roleService.removeById(id);
 | 
			
		||||
            return result ? Result.ok(null) : Result.fail(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            // 处理异常,例如记录日志或者抛出自定义异常
 | 
			
		||||
            throw new RuntimeException("删除角色异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "根据id列表删除角色")
 | 
			
		||||
    @DeleteMapping("batchRemove")
 | 
			
		||||
    public Result batchRemove(@RequestBody List<Long> idList) {
 | 
			
		||||
        //        TODO
 | 
			
		||||
        try {
 | 
			
		||||
            boolean result = roleService.removeByIds(idList);
 | 
			
		||||
            return result ? Result.ok(null) : Result.fail(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            // 处理异常,例如记录日志或者抛出自定义异常
 | 
			
		||||
            throw new RuntimeException("根据id列表删除角色异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "获取一个角色的所有权限列表")
 | 
			
		||||
    @GetMapping("toAssign/{id}")
 | 
			
		||||
    public Result toAssign(@PathVariable Long id) {
 | 
			
		||||
//        TODO
 | 
			
		||||
        try {
 | 
			
		||||
            Map<String, Object> result = permissionService.getPermissionById(id);
 | 
			
		||||
            return Result.ok(result);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            // 处理异常,例如记录日志或者抛出自定义异常
 | 
			
		||||
            throw new RuntimeException("获取一个角色的所有权限列表异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,18 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.mapper;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.acl.Admin;
 | 
			
		||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 | 
			
		||||
import org.springframework.stereotype.Repository;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: AdminMapper
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.mapper
 | 
			
		||||
 * 用户管理
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 10:45
 | 
			
		||||
 */
 | 
			
		||||
@Repository
 | 
			
		||||
public interface AdminMapper extends BaseMapper<Admin> {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,16 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.mapper;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.acl.AdminRole;
 | 
			
		||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 | 
			
		||||
import org.springframework.stereotype.Repository;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: AdminRoleMapper
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.mapper
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 11:15
 | 
			
		||||
 */
 | 
			
		||||
@Repository
 | 
			
		||||
public interface AdminRoleMapper extends BaseMapper<AdminRole> {
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,18 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.mapper;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.acl.Permission;
 | 
			
		||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 | 
			
		||||
import org.springframework.stereotype.Repository;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: PermissionMapper
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.mapper
 | 
			
		||||
 * 菜单Mapper接口
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 13:59
 | 
			
		||||
 */
 | 
			
		||||
@Repository
 | 
			
		||||
public interface PermissionMapper extends BaseMapper<Permission> {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,18 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.mapper;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.acl.Role;
 | 
			
		||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 | 
			
		||||
import org.springframework.stereotype.Repository;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: RoleMapper
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.mapper
 | 
			
		||||
 * 角色管理
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 09:11
 | 
			
		||||
 */
 | 
			
		||||
@Repository
 | 
			
		||||
public interface RoleMapper extends BaseMapper<Role> {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,14 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.mapper;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.acl.RolePermission;
 | 
			
		||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: RolePermissionMapper
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.mapper
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 15:07
 | 
			
		||||
 */
 | 
			
		||||
public interface RolePermissionMapper extends BaseMapper<RolePermission> {
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,14 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.service;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.acl.AdminRole;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.IService;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: AdminRoleService
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.service
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 11:15
 | 
			
		||||
 */
 | 
			
		||||
public interface AdminRoleService extends IService<AdminRole> {
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,28 @@
 | 
			
		||||
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.plugins.pagination.Page;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.IService;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: AdminService
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.service
 | 
			
		||||
 * 用户管理
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 10:44
 | 
			
		||||
 */
 | 
			
		||||
public interface AdminService extends IService<Admin> {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 用户分页列表
 | 
			
		||||
     *
 | 
			
		||||
     * @param pageParam
 | 
			
		||||
     * @param userQueryVo
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    IPage<Admin> selectPage(Page<Admin> pageParam, AdminQueryVo userQueryVo);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,26 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.service;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.acl.Permission;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.IService;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: PermissionService
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.service
 | 
			
		||||
 * 权限服务
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 14:01
 | 
			
		||||
 */
 | 
			
		||||
public interface PermissionService extends IService<Permission> {
 | 
			
		||||
 | 
			
		||||
    //获取所有菜单列表
 | 
			
		||||
    List<Permission> queryAllMenu();
 | 
			
		||||
 | 
			
		||||
    //递归删除
 | 
			
		||||
    boolean removeChildById(Long id);
 | 
			
		||||
 | 
			
		||||
    Map<String, Object> getPermissionById(Long id);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,28 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.service;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.acl.Role;
 | 
			
		||||
import com.atguigu.ssyx.vo.acl.RoleQueryVo;
 | 
			
		||||
import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.IService;
 | 
			
		||||
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: RoleService
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.service
 | 
			
		||||
 * 用户管理
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 09:10
 | 
			
		||||
 */
 | 
			
		||||
public interface RoleService extends IService<Role> {
 | 
			
		||||
 | 
			
		||||
    //角色分页列表
 | 
			
		||||
    IPage<Role> selectPage(Page<Role> pageParam, RoleQueryVo roleQueryVo);
 | 
			
		||||
 | 
			
		||||
    Map<String, Object> findRoleByUserId(Long adminId);
 | 
			
		||||
 | 
			
		||||
    void saveUserRoleRealtionShip(Long adminId, Long[] roleId);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,20 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.service.impl;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.acl.mapper.AdminRoleMapper;
 | 
			
		||||
import com.atguigu.ssyx.acl.service.AdminRoleService;
 | 
			
		||||
import com.atguigu.ssyx.model.acl.AdminRole;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: AdminRoleServiceImpl
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.service.impl
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 11:15
 | 
			
		||||
 */
 | 
			
		||||
@Service
 | 
			
		||||
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole>
 | 
			
		||||
        implements AdminRoleService {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,47 @@
 | 
			
		||||
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.acl.service.RoleService;
 | 
			
		||||
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 org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.util.StringUtils;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: AdminServiceImpl
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.service.impl
 | 
			
		||||
 * 用户管理
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 10:44
 | 
			
		||||
 */
 | 
			
		||||
@Service
 | 
			
		||||
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private AdminMapper userMapper;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private RoleService roleService;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public IPage<Admin> selectPage(Page<Admin> pageParam, AdminQueryVo userQueryVo) {
 | 
			
		||||
        //获取用户名称条件值
 | 
			
		||||
        String name = userQueryVo.getName();
 | 
			
		||||
        //创建条件构造器
 | 
			
		||||
        LambdaQueryWrapper<Admin> wrapper = new LambdaQueryWrapper<>();
 | 
			
		||||
        if (!StringUtils.isEmpty(name)) {
 | 
			
		||||
            //封装条件
 | 
			
		||||
            wrapper.like(Admin::getName, name);
 | 
			
		||||
        }
 | 
			
		||||
        //调用mapper方法
 | 
			
		||||
        IPage<Admin> pageModel = baseMapper.selectPage(pageParam, wrapper);
 | 
			
		||||
        return pageModel;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,78 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.service.impl;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.acl.mapper.PermissionMapper;
 | 
			
		||||
import com.atguigu.ssyx.acl.service.PermissionService;
 | 
			
		||||
import com.atguigu.ssyx.acl.utils.PermissionHelper;
 | 
			
		||||
import com.atguigu.ssyx.model.acl.Permission;
 | 
			
		||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: PermissionServiceImpl
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.service.impl
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 14:02
 | 
			
		||||
 */
 | 
			
		||||
@Service
 | 
			
		||||
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements PermissionService {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取所有菜单
 | 
			
		||||
     *
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Permission> queryAllMenu() {
 | 
			
		||||
        //获取全部权限数据
 | 
			
		||||
        List<Permission> allPermissionList = baseMapper.selectList(new QueryWrapper<Permission>().orderByAsc("CAST(id AS SIGNED)"));
 | 
			
		||||
 | 
			
		||||
        //把权限数据构建成树形结构数据
 | 
			
		||||
        return PermissionHelper.bulid(allPermissionList);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 递归删除菜单
 | 
			
		||||
     *
 | 
			
		||||
     * @param id
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean removeChildById(Long id) {
 | 
			
		||||
        List<Long> idList = new ArrayList<>();
 | 
			
		||||
        this.selectChildListById(id, idList);
 | 
			
		||||
        idList.add(id);
 | 
			
		||||
        baseMapper.deleteBatchIds(idList);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Map<String, Object> getPermissionById(Long id) {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 递归获取子节点
 | 
			
		||||
     *
 | 
			
		||||
     * @param id
 | 
			
		||||
     * @param idList
 | 
			
		||||
     */
 | 
			
		||||
    private void selectChildListById(Long id, List<Long> idList) {
 | 
			
		||||
        List<Permission> childList = baseMapper.selectList(new QueryWrapper<Permission>()
 | 
			
		||||
                .eq("pid", id)
 | 
			
		||||
                .select("id"));
 | 
			
		||||
        childList.forEach(item -> {
 | 
			
		||||
            idList.add(item.getId());
 | 
			
		||||
            this.selectChildListById(item.getId(), idList);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,114 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.service.impl;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.acl.mapper.RoleMapper;
 | 
			
		||||
import com.atguigu.ssyx.acl.service.AdminRoleService;
 | 
			
		||||
import com.atguigu.ssyx.acl.service.RoleService;
 | 
			
		||||
import com.atguigu.ssyx.model.acl.AdminRole;
 | 
			
		||||
import com.atguigu.ssyx.model.acl.Role;
 | 
			
		||||
import com.atguigu.ssyx.vo.acl.RoleQueryVo;
 | 
			
		||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
			
		||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 | 
			
		||||
import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.transaction.annotation.Transactional;
 | 
			
		||||
import org.springframework.util.StringUtils;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: RoleServiceImpl
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.service.impl
 | 
			
		||||
 * 角色管理
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 09:11
 | 
			
		||||
 */
 | 
			
		||||
@Service
 | 
			
		||||
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private AdminRoleService adminRoleService;
 | 
			
		||||
 | 
			
		||||
    //角色分页列表
 | 
			
		||||
    @Override
 | 
			
		||||
    public IPage<Role> selectPage(Page<Role> pageParam, RoleQueryVo roleQueryVo) {
 | 
			
		||||
        //获取条件值:角色名称
 | 
			
		||||
        String roleName = roleQueryVo.getRoleName();
 | 
			
		||||
        //创建条件构造器对象
 | 
			
		||||
        LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>();
 | 
			
		||||
        //判断条件值是否为空
 | 
			
		||||
        if (!StringUtils.isEmpty(roleName)) {
 | 
			
		||||
            //封装条件
 | 
			
		||||
            wrapper.like(Role::getRoleName, roleName);
 | 
			
		||||
        }
 | 
			
		||||
        //调用mapper方法实现条件分页查询
 | 
			
		||||
        IPage<Role> pageModel = baseMapper.selectPage(pageParam, wrapper);
 | 
			
		||||
        return pageModel;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 分配角色
 | 
			
		||||
     *
 | 
			
		||||
     * @param adminId
 | 
			
		||||
     * @param roleIds
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public void saveUserRoleRealtionShip(Long adminId, Long[] roleIds) {
 | 
			
		||||
        //删除用户分配的角色数据
 | 
			
		||||
        adminRoleService.remove(new QueryWrapper<AdminRole>().eq("admin_id", adminId));
 | 
			
		||||
 | 
			
		||||
        //分配新的角色
 | 
			
		||||
        List<AdminRole> userRoleList = new ArrayList<>();
 | 
			
		||||
        for (Long roleId : roleIds) {
 | 
			
		||||
            if (StringUtils.isEmpty(roleId)) continue;
 | 
			
		||||
            AdminRole userRole = new AdminRole();
 | 
			
		||||
            userRole.setAdminId(adminId);
 | 
			
		||||
            userRole.setRoleId(roleId);
 | 
			
		||||
            userRoleList.add(userRole);
 | 
			
		||||
        }
 | 
			
		||||
        adminRoleService.saveBatch(userRoleList);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据用户获取角色数据
 | 
			
		||||
     *
 | 
			
		||||
     * @param adminId
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public Map<String, Object> findRoleByUserId(Long adminId) {
 | 
			
		||||
        //查询所有的角色
 | 
			
		||||
        List<Role> allRolesList = baseMapper.selectList(null);
 | 
			
		||||
 | 
			
		||||
        //拥有的角色id
 | 
			
		||||
        List<AdminRole> existUserRoleList = adminRoleService.list(new QueryWrapper<AdminRole>()
 | 
			
		||||
                .eq("admin_id", adminId)
 | 
			
		||||
                .select("role_id"));
 | 
			
		||||
        List<Long> existRoleList = existUserRoleList
 | 
			
		||||
                .stream()
 | 
			
		||||
                .map(AdminRole::getRoleId)
 | 
			
		||||
                .collect(Collectors.toList());
 | 
			
		||||
 | 
			
		||||
        //对角色进行分类
 | 
			
		||||
        List<Role> assignRoles = new ArrayList<Role>();
 | 
			
		||||
        for (Role role : allRolesList) {
 | 
			
		||||
            //已分配
 | 
			
		||||
            if (existRoleList.contains(role.getId())) {
 | 
			
		||||
                assignRoles.add(role);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Map<String, Object> roleMap = new HashMap<>();
 | 
			
		||||
        roleMap.put("assignRoles", assignRoles);
 | 
			
		||||
        roleMap.put("allRolesList", allRolesList);
 | 
			
		||||
        return roleMap;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,62 @@
 | 
			
		||||
package com.atguigu.ssyx.acl.utils;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.acl.Permission;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: PermissionHelper
 | 
			
		||||
 * Package: com.atguigu.ssyx.acl.utils
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 14:23
 | 
			
		||||
 */
 | 
			
		||||
public class PermissionHelper {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 使用递归方法建菜单
 | 
			
		||||
     *
 | 
			
		||||
     * @param treeNodes
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static List<Permission> bulid(List<Permission> treeNodes) {
 | 
			
		||||
        List<Permission> trees = new ArrayList<>();
 | 
			
		||||
        for (Permission treeNode : treeNodes) {
 | 
			
		||||
            if (treeNode.getPid() == 0) {
 | 
			
		||||
                treeNode.setLevel(1);
 | 
			
		||||
                trees.add(findChildren(treeNode, treeNodes));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return trees;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 递归查找子节点
 | 
			
		||||
     *
 | 
			
		||||
     * @param treeNodes
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static Permission findChildren(Permission treeNode, List<Permission> treeNodes) {
 | 
			
		||||
        treeNode.setChildren(new ArrayList<Permission>());
 | 
			
		||||
 | 
			
		||||
        for (Permission it : treeNodes) {
 | 
			
		||||
            if (treeNode
 | 
			
		||||
                    .getId()
 | 
			
		||||
                    .longValue() == it
 | 
			
		||||
                    .getPid()
 | 
			
		||||
                    .longValue()) {
 | 
			
		||||
                int level = treeNode.getLevel() + 1;
 | 
			
		||||
                it.setLevel(level);
 | 
			
		||||
                if (treeNode.getChildren() == null) {
 | 
			
		||||
                    treeNode.setChildren(new ArrayList<>());
 | 
			
		||||
                }
 | 
			
		||||
                treeNode
 | 
			
		||||
                        .getChildren()
 | 
			
		||||
                        .add(findChildren(it, treeNodes));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return treeNode;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,18 @@
 | 
			
		||||
server:
 | 
			
		||||
  port: 8201
 | 
			
		||||
 | 
			
		||||
mybatis-plus:
 | 
			
		||||
  configuration:
 | 
			
		||||
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 | 
			
		||||
 | 
			
		||||
spring:
 | 
			
		||||
  datasource:
 | 
			
		||||
    type: com.zaxxer.hikari.HikariDataSource
 | 
			
		||||
    driver-class-name: com.mysql.cj.jdbc.Driver
 | 
			
		||||
    url: jdbc:mysql://82.157.68.223:3306/shequ-acl?characterEncoding=utf-8&useSSL=false
 | 
			
		||||
    username: shequ-acl
 | 
			
		||||
    password: shequ-acl
 | 
			
		||||
 | 
			
		||||
  jackson:
 | 
			
		||||
    date-format: yyyy-MM-dd HH:mm:ss
 | 
			
		||||
    time-zone: GMT+8
 | 
			
		||||
@@ -0,0 +1,5 @@
 | 
			
		||||
spring:
 | 
			
		||||
  application:
 | 
			
		||||
    name: service-acl
 | 
			
		||||
  profiles:
 | 
			
		||||
    active: dev
 | 
			
		||||
							
								
								
									
										20
									
								
								guigu-ssyx-parent/service/service-sys/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								guigu-ssyx-parent/service/service-sys/pom.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
			
		||||
         xmlns="http://maven.apache.org/POM/4.0.0"
 | 
			
		||||
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 | 
			
		||||
    <modelVersion>4.0.0</modelVersion>
 | 
			
		||||
    <parent>
 | 
			
		||||
        <groupId>com.atguigu</groupId>
 | 
			
		||||
        <artifactId>service</artifactId>
 | 
			
		||||
        <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </parent>
 | 
			
		||||
 | 
			
		||||
    <artifactId>service-sys</artifactId>
 | 
			
		||||
 | 
			
		||||
    <properties>
 | 
			
		||||
        <maven.compiler.source>8</maven.compiler.source>
 | 
			
		||||
        <maven.compiler.target>8</maven.compiler.target>
 | 
			
		||||
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
			
		||||
    </properties>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,23 @@
 | 
			
		||||
package com.atguigu.ssyx.sys;
 | 
			
		||||
 | 
			
		||||
import org.mybatis.spring.annotation.MapperScan;
 | 
			
		||||
import org.springframework.boot.SpringApplication;
 | 
			
		||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
			
		||||
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: ServiceSysApplication
 | 
			
		||||
 * Package: com.atguigu.ssyx.sys
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/14 15:36
 | 
			
		||||
 */
 | 
			
		||||
@SpringBootApplication
 | 
			
		||||
@EnableSwagger2WebMvc
 | 
			
		||||
@MapperScan(value = "com.atguigu.ssyx.*.mapper")
 | 
			
		||||
public class ServiceSysApplication {
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        SpringApplication.run(ServiceSysApplication.class, args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,45 @@
 | 
			
		||||
package com.atguigu.ssyx.sys.controller;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.common.result.Result;
 | 
			
		||||
import com.atguigu.ssyx.model.sys.Region;
 | 
			
		||||
import com.atguigu.ssyx.sys.service.RegionService;
 | 
			
		||||
import io.swagger.annotations.Api;
 | 
			
		||||
import io.swagger.annotations.ApiOperation;
 | 
			
		||||
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 java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
 * 地区表 前端控制器
 | 
			
		||||
 * </p>
 | 
			
		||||
 *
 | 
			
		||||
 * @author atguigu
 | 
			
		||||
 * @since 2023-09-14
 | 
			
		||||
 */
 | 
			
		||||
@Api(value = "地区接口", tags = "地区接口")
 | 
			
		||||
@RestController
 | 
			
		||||
@RequestMapping("/admin/sys/region")
 | 
			
		||||
//@CrossOrigin
 | 
			
		||||
public class RegionController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private RegionService regionService;
 | 
			
		||||
 | 
			
		||||
    @ApiOperation("根据区域关键字查询区域列表信息")
 | 
			
		||||
    @GetMapping("findRegionByKeyword/{keyword}")
 | 
			
		||||
    public Result findRegionByKeyword(@PathVariable("keyword") String keyword) {
 | 
			
		||||
        try {
 | 
			
		||||
            List<Region> list = regionService.getRegionByKeyword(keyword);
 | 
			
		||||
            return Result.ok(list);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("根据区域关键字查询区域列表信息异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,85 @@
 | 
			
		||||
package com.atguigu.ssyx.sys.controller;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.common.result.Result;
 | 
			
		||||
import com.atguigu.ssyx.model.sys.RegionWare;
 | 
			
		||||
import com.atguigu.ssyx.sys.service.RegionWareService;
 | 
			
		||||
import com.atguigu.ssyx.vo.sys.RegionWareQueryVo;
 | 
			
		||||
import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
			
		||||
import io.swagger.annotations.Api;
 | 
			
		||||
import io.swagger.annotations.ApiOperation;
 | 
			
		||||
import io.swagger.annotations.ApiParam;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Resource;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
 * 城市仓库关联表 前端控制器
 | 
			
		||||
 * </p>
 | 
			
		||||
 *
 | 
			
		||||
 * @author atguigu
 | 
			
		||||
 * @since 2023-09-14
 | 
			
		||||
 */
 | 
			
		||||
@Api(value = "开通区域接口", tags = "开通区域接口")
 | 
			
		||||
@RestController
 | 
			
		||||
@RequestMapping(value = "/admin/sys/regionWare")
 | 
			
		||||
@CrossOrigin
 | 
			
		||||
public class RegionWareController {
 | 
			
		||||
    @Resource
 | 
			
		||||
    private RegionWareService regionWareService;
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "获取开通区域列表")
 | 
			
		||||
    @GetMapping("{page}/{limit}")
 | 
			
		||||
    public Result index(
 | 
			
		||||
            @ApiParam(name = "page", value = "当前页码", required = true)
 | 
			
		||||
            @PathVariable Long page,
 | 
			
		||||
            @ApiParam(name = "limit", value = "每页记录数", required = true)
 | 
			
		||||
            @PathVariable Long limit,
 | 
			
		||||
            @ApiParam(name = "regionWareVo", value = "查询对象", required = false)
 | 
			
		||||
            RegionWareQueryVo regionWareQueryVo) {
 | 
			
		||||
        try {
 | 
			
		||||
            Page<RegionWare> pageParam = new Page<>(page, limit);
 | 
			
		||||
            IPage<RegionWare> pageModel = regionWareService.selectPage(pageParam, regionWareQueryVo);
 | 
			
		||||
            return Result.ok(pageModel);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("获取开通区域列表异常", e);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "新增开通区域")
 | 
			
		||||
    @PostMapping("save")
 | 
			
		||||
    public Result save(@RequestBody RegionWare regionWare) {
 | 
			
		||||
        try {
 | 
			
		||||
            regionWareService.saveRegionWare(regionWare);
 | 
			
		||||
            return Result.ok(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("新增开通区域异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "删除开通区域")
 | 
			
		||||
    @DeleteMapping("remove/{id}")
 | 
			
		||||
    public Result remove(@PathVariable Long id) {
 | 
			
		||||
        try {
 | 
			
		||||
            boolean result = regionWareService.removeById(id);
 | 
			
		||||
            return result ? Result.ok(null) : Result.fail(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("删除开通区域异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "取消开通区域")
 | 
			
		||||
    @PostMapping("updateStatus/{id}/{status}")
 | 
			
		||||
    public Result updateStatus(@PathVariable Long id, @PathVariable Integer status) {
 | 
			
		||||
        try {
 | 
			
		||||
            regionWareService.updateStatus(id, status);
 | 
			
		||||
            return Result.ok(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("删除开通区域异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,45 @@
 | 
			
		||||
package com.atguigu.ssyx.sys.controller;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.common.result.Result;
 | 
			
		||||
import com.atguigu.ssyx.model.sys.Ware;
 | 
			
		||||
import com.atguigu.ssyx.sys.service.WareService;
 | 
			
		||||
import io.swagger.annotations.Api;
 | 
			
		||||
import io.swagger.annotations.ApiOperation;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.web.bind.annotation.CrossOrigin;
 | 
			
		||||
import org.springframework.web.bind.annotation.GetMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RestController;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
 * 仓库表 前端控制器
 | 
			
		||||
 * </p>
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @since 2023-09-14
 | 
			
		||||
 */
 | 
			
		||||
@Api(value = "仓库接口", tags = "仓库接口")
 | 
			
		||||
@RestController
 | 
			
		||||
@RequestMapping("/admin/sys/ware")
 | 
			
		||||
@CrossOrigin
 | 
			
		||||
public class WareController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private WareService wareService;
 | 
			
		||||
 | 
			
		||||
    @ApiOperation("查询所有仓库列表")
 | 
			
		||||
    @GetMapping("findAllList")
 | 
			
		||||
    public Result findAllList() {
 | 
			
		||||
        try {
 | 
			
		||||
            List<Ware> list = wareService.list();
 | 
			
		||||
            return Result.ok(list);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("查询所有仓库列表异常", e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,18 @@
 | 
			
		||||
package com.atguigu.ssyx.sys.mapper;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.sys.Region;
 | 
			
		||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 | 
			
		||||
import org.mapstruct.Mapper;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
 * 地区表 Mapper 接口
 | 
			
		||||
 * </p>
 | 
			
		||||
 *
 | 
			
		||||
 * @author atguigu
 | 
			
		||||
 * @since 2023-09-14
 | 
			
		||||
 */
 | 
			
		||||
@Mapper
 | 
			
		||||
public interface RegionMapper extends BaseMapper<Region> {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,18 @@
 | 
			
		||||
package com.atguigu.ssyx.sys.mapper;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.sys.RegionWare;
 | 
			
		||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 | 
			
		||||
import org.mapstruct.Mapper;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
 * 城市仓库关联表 Mapper 接口
 | 
			
		||||
 * </p>
 | 
			
		||||
 *
 | 
			
		||||
 * @author atguigu
 | 
			
		||||
 * @since 2023-09-14
 | 
			
		||||
 */
 | 
			
		||||
@Mapper
 | 
			
		||||
public interface RegionWareMapper extends BaseMapper<RegionWare> {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,19 @@
 | 
			
		||||
package com.atguigu.ssyx.sys.mapper;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.sys.Ware;
 | 
			
		||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 | 
			
		||||
import org.mapstruct.Mapper;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
 * 仓库表 Mapper 接口
 | 
			
		||||
 * </p>
 | 
			
		||||
 *
 | 
			
		||||
 * @author atguigu
 | 
			
		||||
 * @since 2023-09-14
 | 
			
		||||
 */
 | 
			
		||||
@Mapper
 | 
			
		||||
public interface WareMapper extends BaseMapper<Ware> {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,5 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 | 
			
		||||
<mapper namespace="com.atguigu.ssyx.sys.mapper.RegionMapper">
 | 
			
		||||
 | 
			
		||||
</mapper>
 | 
			
		||||
@@ -0,0 +1,5 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 | 
			
		||||
<mapper namespace="com.atguigu.ssyx.sys.mapper.RegionWareMapper">
 | 
			
		||||
 | 
			
		||||
</mapper>
 | 
			
		||||
@@ -0,0 +1,5 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 | 
			
		||||
<mapper namespace="com.atguigu.ssyx.sys.mapper.WareMapper">
 | 
			
		||||
 | 
			
		||||
</mapper>
 | 
			
		||||
@@ -0,0 +1,20 @@
 | 
			
		||||
package com.atguigu.ssyx.sys.service;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.sys.Region;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.IService;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
 * 地区表 服务类
 | 
			
		||||
 * </p>
 | 
			
		||||
 *
 | 
			
		||||
 * @author atguigu
 | 
			
		||||
 * @since 2023-09-14
 | 
			
		||||
 */
 | 
			
		||||
public interface RegionService extends IService<Region> {
 | 
			
		||||
 | 
			
		||||
    List<Region> getRegionByKeyword(String keyword);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,25 @@
 | 
			
		||||
package com.atguigu.ssyx.sys.service;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.sys.RegionWare;
 | 
			
		||||
import com.atguigu.ssyx.vo.sys.RegionWareQueryVo;
 | 
			
		||||
import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.IService;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
 * 城市仓库关联表 服务类
 | 
			
		||||
 * </p>
 | 
			
		||||
 *
 | 
			
		||||
 * @author atguigu
 | 
			
		||||
 * @since 2023-09-14
 | 
			
		||||
 */
 | 
			
		||||
public interface RegionWareService extends IService<RegionWare> {
 | 
			
		||||
 | 
			
		||||
    IPage<RegionWare> selectPage(Page<RegionWare> pageParam, RegionWareQueryVo regionWareQueryVo);
 | 
			
		||||
 | 
			
		||||
    void saveRegionWare(RegionWare regionWare);
 | 
			
		||||
 | 
			
		||||
    void updateStatus(Long id, Integer status);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,17 @@
 | 
			
		||||
package com.atguigu.ssyx.sys.service;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.sys.Ware;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.IService;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
 * 仓库表 服务类
 | 
			
		||||
 * </p>
 | 
			
		||||
 *
 | 
			
		||||
 * @author atguigu
 | 
			
		||||
 * @since 2023-09-14
 | 
			
		||||
 */
 | 
			
		||||
public interface WareService extends IService<Ware> {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,28 @@
 | 
			
		||||
package com.atguigu.ssyx.sys.service.impl;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.sys.Region;
 | 
			
		||||
import com.atguigu.ssyx.sys.mapper.RegionMapper;
 | 
			
		||||
import com.atguigu.ssyx.sys.service.RegionService;
 | 
			
		||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
 * 地区表 服务实现类
 | 
			
		||||
 * </p>
 | 
			
		||||
 *
 | 
			
		||||
 * @author atguigu
 | 
			
		||||
 * @since 2023-09-14
 | 
			
		||||
 */
 | 
			
		||||
@Service
 | 
			
		||||
public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> implements RegionService {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Region> getRegionByKeyword(String keyword) {
 | 
			
		||||
        return baseMapper.selectList(new LambdaQueryWrapper<Region>().like(Region::getName, keyword));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,65 @@
 | 
			
		||||
package com.atguigu.ssyx.sys.service.impl;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.common.exception.SsyxException;
 | 
			
		||||
import com.atguigu.ssyx.common.result.ResultCodeEnum;
 | 
			
		||||
import com.atguigu.ssyx.model.sys.RegionWare;
 | 
			
		||||
import com.atguigu.ssyx.sys.mapper.RegionWareMapper;
 | 
			
		||||
import com.atguigu.ssyx.sys.service.RegionWareService;
 | 
			
		||||
import com.atguigu.ssyx.vo.sys.RegionWareQueryVo;
 | 
			
		||||
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 org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.util.StringUtils;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Resource;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
 * 城市仓库关联表 服务实现类
 | 
			
		||||
 * </p>
 | 
			
		||||
 *
 | 
			
		||||
 * @author atguigu
 | 
			
		||||
 * @since 2023-09-14
 | 
			
		||||
 */
 | 
			
		||||
@Service
 | 
			
		||||
public class RegionWareServiceImpl extends ServiceImpl<RegionWareMapper, RegionWare> implements RegionWareService {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    RegionWareMapper regionWareMapper;
 | 
			
		||||
 | 
			
		||||
    //开通区域列表
 | 
			
		||||
    @Override
 | 
			
		||||
    public IPage<RegionWare> selectPage(Page<RegionWare> pageParam, RegionWareQueryVo regionWareQueryVo) {
 | 
			
		||||
        String keyword = regionWareQueryVo.getKeyword();
 | 
			
		||||
        LambdaQueryWrapper<RegionWare> wrapper = new LambdaQueryWrapper<>();
 | 
			
		||||
        if (!StringUtils.isEmpty(keyword)) {
 | 
			
		||||
            wrapper
 | 
			
		||||
                    .like(RegionWare::getRegionName, keyword)
 | 
			
		||||
                    .or()
 | 
			
		||||
                    .like(RegionWare::getWareName, keyword);
 | 
			
		||||
        }
 | 
			
		||||
        return baseMapper.selectPage(pageParam, wrapper);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //添加开通区域
 | 
			
		||||
    @Override
 | 
			
		||||
    public void saveRegionWare(RegionWare regionWare) {
 | 
			
		||||
        LambdaQueryWrapper<RegionWare> queryWrapper = new LambdaQueryWrapper();
 | 
			
		||||
        queryWrapper.eq(RegionWare::getRegionId, regionWare.getRegionId());
 | 
			
		||||
        Integer count = regionWareMapper.selectCount(queryWrapper);
 | 
			
		||||
        if (count > 0) {
 | 
			
		||||
            throw new SsyxException(ResultCodeEnum.REGION_OPEN);
 | 
			
		||||
        }
 | 
			
		||||
        baseMapper.insert(regionWare);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void updateStatus(Long id, Integer status) {
 | 
			
		||||
        RegionWare regionWare = baseMapper.selectById(id);
 | 
			
		||||
        regionWare.setStatus(status);
 | 
			
		||||
        baseMapper.updateById(regionWare);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,20 @@
 | 
			
		||||
package com.atguigu.ssyx.sys.service.impl;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.sys.Ware;
 | 
			
		||||
import com.atguigu.ssyx.sys.mapper.WareMapper;
 | 
			
		||||
import com.atguigu.ssyx.sys.service.WareService;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
 * 仓库表 服务实现类
 | 
			
		||||
 * </p>
 | 
			
		||||
 *
 | 
			
		||||
 * @author atguigu
 | 
			
		||||
 * @since 2023-09-14
 | 
			
		||||
 */
 | 
			
		||||
@Service
 | 
			
		||||
public class WareServiceImpl extends ServiceImpl<WareMapper, Ware> implements WareService {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,18 @@
 | 
			
		||||
server:
 | 
			
		||||
  port: 8202
 | 
			
		||||
 | 
			
		||||
mybatis-plus:
 | 
			
		||||
  configuration:
 | 
			
		||||
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 | 
			
		||||
 | 
			
		||||
spring:
 | 
			
		||||
  datasource:
 | 
			
		||||
    type: com.zaxxer.hikari.HikariDataSource
 | 
			
		||||
    driver-class-name: com.mysql.cj.jdbc.Driver
 | 
			
		||||
    url: jdbc:mysql://82.157.68.223:3306/shequ-sys?characterEncoding=utf-8&useSSL=false
 | 
			
		||||
    username: shequ-sys
 | 
			
		||||
    password: shequ-sys
 | 
			
		||||
 | 
			
		||||
  jackson:
 | 
			
		||||
    date-format: yyyy-MM-dd HH:mm:ss
 | 
			
		||||
    time-zone: GMT+8
 | 
			
		||||
@@ -0,0 +1,5 @@
 | 
			
		||||
spring:
 | 
			
		||||
  application:
 | 
			
		||||
    name: service-sys
 | 
			
		||||
  profiles:
 | 
			
		||||
    active: dev
 | 
			
		||||
		Reference in New Issue
	
	Block a user