Compare commits
6 Commits
7b759baeed
...
36e627c461
Author | SHA1 | Date |
---|---|---|
|
36e627c461 | |
|
970a13bc5b | |
|
8f20d4c82f | |
|
08d0d6bd09 | |
|
241edbc2ea | |
|
49273d8055 |
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="guigu-oa@106.15.251.123" uuid="9d89e3b4-ae68-4e89-b7e1-1866250cab0a">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<imported>true</imported>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://106.15.251.123:3305/guigu-oa?serverTimezone=GMT</jdbc-url>
|
||||
<jdbc-additional-properties>
|
||||
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PublishConfigData" autoUpload="Always" remoteFilesAllowedToDisappearOnAutoupload="false" autoUploadExternalChanges="true">
|
||||
<option name="myAutoUpload" value="ALWAYS" />
|
||||
</component>
|
||||
</project>
|
|
@ -34,5 +34,11 @@
|
|||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>model</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.atguigu.common.utlis;
|
||||
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MenuHelper {
|
||||
/**
|
||||
* 构建树型结构
|
||||
*
|
||||
* @param sysMenuList 系统菜单列表
|
||||
* @return 菜单结构列表
|
||||
*/
|
||||
public static List<SysMenu> buildTree(List<SysMenu> sysMenuList) {
|
||||
ArrayList<SysMenu> tress = new ArrayList<>();
|
||||
// 把菜单数据进行遍历
|
||||
sysMenuList.forEach(sysMenu -> {
|
||||
if (sysMenu.getParentId() == 0) tress.add(getChildren(sysMenu, sysMenuList));
|
||||
});
|
||||
return tress;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建递归循环
|
||||
*
|
||||
* @param sysMenu 当前菜单对象
|
||||
* @param sysMenuList 全部菜单列表
|
||||
* @return 菜单
|
||||
*/
|
||||
private static SysMenu getChildren(SysMenu sysMenu, List<SysMenu> sysMenuList) {
|
||||
// 遍历所有菜单数据,判断id和parentID对应关系
|
||||
sysMenu.setChildren(new ArrayList<>());
|
||||
|
||||
sysMenuList.forEach(menu -> {
|
||||
if (menu.getChildren() == null) menu.setChildren(new ArrayList<>());
|
||||
if (sysMenu.getId().equals(menu.getParentId())) {
|
||||
sysMenu.getChildren().add(getChildren(menu, sysMenuList));
|
||||
}
|
||||
});
|
||||
|
||||
return sysMenu;
|
||||
}
|
||||
}
|
|
@ -18,8 +18,7 @@ public class CodeGet {
|
|||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
// TODO 需要修改路径名称
|
||||
gc.setOutputDir("G:\\java项目\\guigu-oa\\guigu-oa-parent\\service-oa" + "/src/main/java");
|
||||
|
||||
gc.setOutputDir("G:\\java项目\\guigu-oa\\guigu-oa\\service-oa" + "/src/main/java");
|
||||
gc.setServiceName("%sService"); // 去掉Service接口的首字母I
|
||||
gc.setAuthor("bunny");
|
||||
gc.setOpen(false);
|
||||
|
@ -56,7 +55,7 @@ public class CodeGet {
|
|||
private static StrategyConfig getStrategyConfig() {
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
// TODO 要生成的表
|
||||
strategy.setInclude("sys_user", "sys_role");
|
||||
strategy.setInclude("sys_menu", "sys_role_menu");
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);// 数据库表映射到实体的命名策略
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);// 数据库表字段映射到实体的命名策略
|
||||
strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
|
||||
|
|
|
@ -32,7 +32,5 @@ public class MessageConstant {
|
|||
public static final String LOGIN_DTO_IS_EMPTY = "登录参数不能为空";
|
||||
public static final String TOKEN_IS_EMPTY = "token为空";
|
||||
public static final String DATA_IS_EMPTY = "数据为空";
|
||||
public static final String STOCK_LESS = "库存不足";
|
||||
public static final String SKU_NUM_CANNOT_BE_LESS = "商品数量不能再少了";
|
||||
public static final String CART_IS_EMPTY = "购物车为空";
|
||||
public static final String DELETE_MENU_ERROR_HAS_MENUS = "有下级菜单";
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -102,3 +102,17 @@
|
|||
18:39:51:555 INFO 6652 --- [http-nio-8800-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
|
||||
18:40:02:303 INFO 6652 --- [http-nio-8800-exec-4] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
|
||||
18:40:02:498 INFO 6652 --- [http-nio-8800-exec-4] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
|
||||
17:35:19:249 INFO 12196 --- [main] com.atguigu.auth.ServiceAuthApplication : Starting ServiceAuthApplication on bunny with PID 12196 (G:\java项目\guigu-oa\guigu-oa\service-oa\target\classes started by 13199 in G:\java项目\guigu-oa\guigu-oa)
|
||||
17:35:19:250 INFO 12196 --- [main] com.atguigu.auth.ServiceAuthApplication : The following profiles are active: dev
|
||||
17:35:19:892 INFO 12196 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8800 (http)
|
||||
17:35:19:897 INFO 12196 --- [main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
|
||||
17:35:19:897 INFO 12196 --- [main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.39]
|
||||
17:35:19:938 INFO 12196 --- [main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
|
||||
17:35:19:938 INFO 12196 --- [main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 664 ms
|
||||
17:35:20:021 INFO 12196 --- [main] com.atguigu.config.MybatisPlusConfig : 注入MybatisPlus配置类...
|
||||
17:35:20:622 INFO 12196 --- [main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
|
||||
17:35:20:708 INFO 12196 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8800 (http) with context path ''
|
||||
17:35:20:847 INFO 12196 --- [main] com.atguigu.auth.ServiceAuthApplication : Started ServiceAuthApplication in 1.834 seconds (JVM running for 2.625)
|
||||
17:35:45:707 INFO 12196 --- [http-nio-8800-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
|
||||
17:35:45:707 INFO 12196 --- [http-nio-8800-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
|
||||
17:35:45:710 INFO 12196 --- [http-nio-8800-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 3 ms
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package com.atguigu.model.system;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class RoleByUser {
|
||||
private List<SysRole> assginRoleList;
|
||||
private List<SysRole> allRolesList;
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package com.atguigu.auth.controller;
|
||||
|
||||
|
||||
import com.atguigu.auth.service.SysMenuService;
|
||||
import com.atguigu.common.result.Result;
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import com.atguigu.vo.system.AssginMenuVo;
|
||||
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.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@Tag(name = "菜单管理")
|
||||
@RestController
|
||||
@RequestMapping("/admin/system/sysMenu")
|
||||
public class SysMenuController {
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
|
||||
@Operation(summary = "获取菜单", description = "获取菜单")
|
||||
@GetMapping("findNodes")
|
||||
public Result<List<SysMenu>> findNodes() {
|
||||
List<SysMenu> list = sysMenuService.findNodes();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "新增菜单", description = "新增菜单")
|
||||
@PostMapping("save")
|
||||
public Result<SysMenu> save(@RequestBody SysMenu permission) {
|
||||
sysMenuService.save(permission);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "修改菜单", description = "修改菜单")
|
||||
@PutMapping("update")
|
||||
public Result<SysMenu> updateById(@RequestBody SysMenu permission) {
|
||||
sysMenuService.updateById(permission);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "删除菜单", description = "删除菜单")
|
||||
@DeleteMapping("remove/{id}")
|
||||
public Result<SysMenu> remove(@PathVariable Long id) {
|
||||
sysMenuService.removeMenuById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "根据角色获取菜单", description = "根据角色获取菜单")
|
||||
@GetMapping("toAssign/{roleId}")
|
||||
public Result<List<SysMenu>> toAssign(@PathVariable Long roleId) {
|
||||
List<SysMenu> sysMenuList = sysMenuService.findSysMenuByRoleId(roleId);
|
||||
return Result.success(sysMenuList);
|
||||
}
|
||||
|
||||
@Operation(summary = "给角色分配权限", description = "给角色分配权限")
|
||||
@PostMapping("doAssign")
|
||||
public Result<AssginMenuVo> doAssign(@RequestBody AssginMenuVo assginMenuVo) {
|
||||
sysMenuService.doAssign(assginMenuVo);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,9 @@ package com.atguigu.auth.controller;
|
|||
|
||||
import com.atguigu.auth.service.SysRoleService;
|
||||
import com.atguigu.common.result.Result;
|
||||
import com.atguigu.model.system.RoleByUser;
|
||||
import com.atguigu.model.system.SysRole;
|
||||
import com.atguigu.vo.system.AssginRoleVo;
|
||||
import com.atguigu.vo.system.SysRoleQueryVo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
@ -12,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Tag(name = "角色管理接口")
|
||||
@RestController
|
||||
|
@ -62,4 +65,18 @@ public class SysRoleController {
|
|||
sysRoleService.removeByIds(idList);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据用户获取角色数据")
|
||||
@GetMapping("/toAssign/{userId}")
|
||||
public Result<RoleByUser> toAssign(@PathVariable Long userId) {
|
||||
RoleByUser roleMap = sysRoleService.findRoleByAdminId(userId);
|
||||
return Result.success(roleMap);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据用户分配角色")
|
||||
@PostMapping("/doAssign")
|
||||
public Result<AssginRoleVo> doAssign(@RequestBody AssginRoleVo assginRoleVo) {
|
||||
sysRoleService.doAssign(assginRoleVo);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
package mapper;
|
||||
package com.atguigu.auth.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色 前端控制器
|
||||
* 角色菜单 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-22
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/order/sys-role")
|
||||
public class SysRoleController {
|
||||
@RequestMapping("/auth/sys-role-menu")
|
||||
public class SysRoleMenuController {
|
||||
|
||||
}
|
||||
|
|
@ -71,5 +71,12 @@ public class SysUserController {
|
|||
sysUserService.removeByIds(idList);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "更新状态", description = "更新状态")
|
||||
@GetMapping("updateStatus/{id}/{status}")
|
||||
public Result<SysUser> updateStatus(@PathVariable Long id, @PathVariable Long status) {
|
||||
sysUserService.updateStatus(id, status);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
package mapper;
|
||||
package com.atguigu.auth.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表 前端控制器
|
||||
* 用户角色 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-22
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/order/sys-user")
|
||||
public class SysUserController {
|
||||
@RequestMapping("/auth/sys-user-role")
|
||||
public class SysUserRoleController {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.atguigu.auth.mapper;
|
||||
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
||||
|
||||
}
|
|
@ -2,6 +2,17 @@ package com.atguigu.auth.mapper;
|
|||
|
||||
import com.atguigu.model.system.SysRole;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysRoleMapper extends BaseMapper<SysRole> {
|
||||
/**
|
||||
* 根据用户id查询所有的角色
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> selectByUserId(Long userId);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.atguigu.auth.mapper;
|
||||
|
||||
import com.atguigu.model.system.SysRoleMenu;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenu> {
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.atguigu.auth.mapper;
|
||||
|
||||
import com.atguigu.model.system.SysUserRole;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户角色 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.atguigu.auth.service;
|
||||
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import com.atguigu.vo.system.AssginMenuVo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
public interface SysMenuService extends IService<SysMenu> {
|
||||
|
||||
/**
|
||||
* 获取菜单
|
||||
*
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> findNodes();
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id 菜单id
|
||||
*/
|
||||
void removeMenuById(Long id);
|
||||
|
||||
/**
|
||||
* 根据角色获取菜单
|
||||
*
|
||||
* @param roleId 角色id
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> findSysMenuByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 给角色分配权限
|
||||
*
|
||||
* @param assginMenuVo 分配条件
|
||||
*/
|
||||
void doAssign(AssginMenuVo assginMenuVo);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.atguigu.auth.service;
|
||||
|
||||
import com.atguigu.model.system.SysRoleMenu;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
public interface SysRoleMenuService extends IService<SysRoleMenu> {
|
||||
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package com.atguigu.auth.service;
|
||||
|
||||
import com.atguigu.model.system.RoleByUser;
|
||||
import com.atguigu.model.system.SysRole;
|
||||
import com.atguigu.vo.system.AssginRoleVo;
|
||||
import com.atguigu.vo.system.SysRoleQueryVo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
@ -15,5 +17,19 @@ public interface SysRoleService extends IService<SysRole> {
|
|||
* @return 分页结果
|
||||
*/
|
||||
IPage<SysRole> pageResult(Long page, Long limit, SysRoleQueryVo vo);
|
||||
|
||||
/**
|
||||
* 根据用户获取角色数据
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return 用户角色集合
|
||||
*/
|
||||
RoleByUser findRoleByAdminId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户分配角色
|
||||
* @param vo 分配条件
|
||||
*/
|
||||
void doAssign(AssginRoleVo vo);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.atguigu.auth.service;
|
||||
|
||||
import com.atguigu.model.system.SysUserRole;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户角色 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
public interface SysUserRoleService extends IService<SysUserRole> {
|
||||
|
||||
}
|
|
@ -24,4 +24,12 @@ public interface SysUserService extends IService<SysUser> {
|
|||
* @return 分页结果
|
||||
*/
|
||||
IPage<SysUser> getUserByPage(Long page, Long limit, SysUserQueryVo vo);
|
||||
|
||||
/**
|
||||
* 更新状态
|
||||
*
|
||||
* @param id 用户id
|
||||
* @param status 修改的状态
|
||||
*/
|
||||
void updateStatus(Long id, Long status);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
package com.atguigu.auth.service.impl;
|
||||
|
||||
import com.atguigu.auth.mapper.SysMenuMapper;
|
||||
import com.atguigu.auth.service.SysMenuService;
|
||||
import com.atguigu.common.utlis.MenuHelper;
|
||||
import com.atguigu.constant.MessageConstant;
|
||||
import com.atguigu.exception.BunnyException;
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import com.atguigu.vo.system.AssginMenuVo;
|
||||
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 bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@Service
|
||||
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
|
||||
|
||||
/**
|
||||
* 获取菜单
|
||||
*
|
||||
* @return 菜单列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findNodes() {
|
||||
return MenuHelper.buildTree(list());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id 菜单id
|
||||
*/
|
||||
@Override
|
||||
public void removeMenuById(Long id) {
|
||||
// 判断当前菜单是否有下级菜单
|
||||
LambdaQueryWrapper<SysMenu> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SysMenu::getParentId, id);
|
||||
|
||||
// 查询菜单列表
|
||||
List<SysMenu> sysMenuList = list(wrapper);
|
||||
|
||||
// 为空时可以删除
|
||||
if (sysMenuList == null) removeById(id);
|
||||
|
||||
// 如果不为空抛出异常
|
||||
throw new BunnyException(MessageConstant.DELETE_MENU_ERROR_HAS_MENUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色获取菜单
|
||||
*
|
||||
* @param roleId 角色id
|
||||
* @return 菜单列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findSysMenuByRoleId(Long roleId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给角色分配权限
|
||||
*
|
||||
* @param assginMenuVo 分配条件
|
||||
*/
|
||||
@Override
|
||||
public void doAssign(AssginMenuVo assginMenuVo) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.atguigu.auth.service.impl;
|
||||
|
||||
import com.atguigu.auth.mapper.SysRoleMenuMapper;
|
||||
import com.atguigu.auth.service.SysRoleMenuService;
|
||||
import com.atguigu.model.system.SysRoleMenu;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {
|
||||
|
||||
}
|
|
@ -1,18 +1,34 @@
|
|||
package com.atguigu.auth.service.impl;
|
||||
|
||||
|
||||
import com.atguigu.auth.mapper.SysRoleMapper;
|
||||
import com.atguigu.auth.mapper.SysUserRoleMapper;
|
||||
import com.atguigu.auth.service.SysRoleService;
|
||||
import com.atguigu.auth.service.SysUserRoleService;
|
||||
import com.atguigu.model.system.RoleByUser;
|
||||
import com.atguigu.model.system.SysRole;
|
||||
import com.atguigu.model.system.SysUserRole;
|
||||
import com.atguigu.vo.system.AssginRoleVo;
|
||||
import com.atguigu.vo.system.SysRoleQueryVo;
|
||||
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.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {
|
||||
@Autowired
|
||||
private SysUserRoleMapper sysUserRoleMapper;
|
||||
@Autowired
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
|
||||
/**
|
||||
* 角色条件分页查询
|
||||
*
|
||||
|
@ -31,4 +47,48 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
|
||||
return page(pageParam, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户获取角色数据
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return 用户角色集合
|
||||
*/
|
||||
@Override
|
||||
public RoleByUser findRoleByAdminId(Long userId) {
|
||||
// 查询所有角色
|
||||
List<SysRole> allRolesList = list();
|
||||
|
||||
// 根据用户id查询所有的角色
|
||||
List<SysRole> assginRoleList = baseMapper.selectByUserId(userId);
|
||||
return RoleByUser.builder().allRolesList(allRolesList).assginRoleList(assginRoleList).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户分配角色
|
||||
*
|
||||
* @param vo 分配条件
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public void doAssign(AssginRoleVo vo) {
|
||||
// 删除原有数据
|
||||
LambdaQueryWrapper<SysUserRole> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SysUserRole::getUserId, vo.getUserId());
|
||||
sysUserRoleService.remove(wrapper);
|
||||
|
||||
// 为用户分配角色
|
||||
ArrayList<SysUserRole> userRoleArrayList = new ArrayList<>();
|
||||
vo.getRoleIdList().forEach(roleId -> {
|
||||
if (!StringUtils.isEmpty(roleId)) {
|
||||
SysUserRole sysUserRole = new SysUserRole();
|
||||
sysUserRole.setUserId(vo.getUserId());
|
||||
sysUserRole.setRoleId(roleId);
|
||||
userRoleArrayList.add(sysUserRole);
|
||||
}
|
||||
});
|
||||
|
||||
// 批量插入用户角色信息
|
||||
sysUserRoleService.saveBatch(userRoleArrayList);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package com.atguigu.auth.service.impl;
|
||||
|
||||
import com.atguigu.auth.mapper.SysUserRoleMapper;
|
||||
import com.atguigu.auth.service.SysUserRoleService;
|
||||
import com.atguigu.model.system.SysUserRole;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户角色 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@Service
|
||||
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements SysUserRoleService {
|
||||
|
||||
}
|
|
@ -50,4 +50,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
|
||||
return page(pageParam, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新状态
|
||||
*
|
||||
* @param id 用户id
|
||||
* @param status 修改的状态
|
||||
*/
|
||||
@Override
|
||||
public void updateStatus(Long id, Long status) {
|
||||
SysUser sysUser = getById(id);
|
||||
if (status == 1) sysUser.setStatus(1);
|
||||
else sysUser.setStatus(0);
|
||||
|
||||
// 更新用户状态
|
||||
updateById(sysUser);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.auth.mapper.SysMenuMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,10 @@
|
|||
<?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.auth.mapper.SysRoleMapper">
|
||||
<!-- 根据用户id查询所有的角色 -->
|
||||
<select id="selectByUserId" resultType="com.atguigu.model.system.SysRole">
|
||||
SELECT *
|
||||
FROM sys_role
|
||||
WHERE id IN (SELECT role_id FROM sys_user_role WHERE user_id = #{user_id})
|
||||
</select>
|
||||
</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.auth.mapper.SysRoleMenuMapper">
|
||||
|
||||
</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.auth.mapper.SysUserMapper">
|
||||
|
||||
</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.auth.mapper.SysUserRoleMapper">
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue