From bfc221b9de8106630865f8a9daf91b56926e99b8 Mon Sep 17 00:00:00 2001 From: shijie <648688341@qq.com> Date: Wed, 24 Feb 2021 11:31:00 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=A7=92=E8=89=B2=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 13 ++ .../controller/SysPermissionController.java | 20 +++ .../tms/controller/SysRoleController.java | 20 +++ .../SysRolePermissionController.java | 20 +++ .../tms/controller/SysUserRoleController.java | 20 +++ .../com/msdw/tms/dao/SysPermissionMapper.java | 18 +++ .../java/com/msdw/tms/dao/SysRoleMapper.java | 18 +++ .../msdw/tms/dao/SysRolePermissionMapper.java | 18 +++ .../com/msdw/tms/dao/SysUserRoleMapper.java | 18 +++ .../com/msdw/tms/entity/SysPermission.java | 90 ++++++++++++++ .../java/com/msdw/tms/entity/SysRole.java | 60 +++++++++ .../msdw/tms/entity/SysRolePermission.java | 39 ++++++ .../java/com/msdw/tms/entity/SysUserRole.java | 39 ++++++ .../tms/service/ISysPermissionService.java | 16 +++ .../service/ISysRolePermissionService.java | 16 +++ .../com/msdw/tms/service/ISysRoleService.java | 16 +++ .../msdw/tms/service/ISysUserRoleService.java | 16 +++ .../impl/SysPermissionServiceImpl.java | 20 +++ .../impl/SysRolePermissionServiceImpl.java | 20 +++ .../tms/service/impl/SysRoleServiceImpl.java | 20 +++ .../service/impl/SysUserRoleServiceImpl.java | 20 +++ .../tms/util/MyBatisPlusCodeGenerator.java | 115 ++++++++++++++++++ .../mapper/tms/SysPermissionMapper.xml | 22 ++++ .../resources/mapper/tms/SysRoleMapper.xml | 16 +++ .../mapper/tms/SysRolePermissionMapper.xml | 12 ++ .../mapper/tms/SysUserRoleMapper.xml | 12 ++ 26 files changed, 714 insertions(+) create mode 100644 src/main/java/com/msdw/tms/controller/SysPermissionController.java create mode 100644 src/main/java/com/msdw/tms/controller/SysRoleController.java create mode 100644 src/main/java/com/msdw/tms/controller/SysRolePermissionController.java create mode 100644 src/main/java/com/msdw/tms/controller/SysUserRoleController.java create mode 100644 src/main/java/com/msdw/tms/dao/SysPermissionMapper.java create mode 100644 src/main/java/com/msdw/tms/dao/SysRoleMapper.java create mode 100644 src/main/java/com/msdw/tms/dao/SysRolePermissionMapper.java create mode 100644 src/main/java/com/msdw/tms/dao/SysUserRoleMapper.java create mode 100644 src/main/java/com/msdw/tms/entity/SysPermission.java create mode 100644 src/main/java/com/msdw/tms/entity/SysRole.java create mode 100644 src/main/java/com/msdw/tms/entity/SysRolePermission.java create mode 100644 src/main/java/com/msdw/tms/entity/SysUserRole.java create mode 100644 src/main/java/com/msdw/tms/service/ISysPermissionService.java create mode 100644 src/main/java/com/msdw/tms/service/ISysRolePermissionService.java create mode 100644 src/main/java/com/msdw/tms/service/ISysRoleService.java create mode 100644 src/main/java/com/msdw/tms/service/ISysUserRoleService.java create mode 100644 src/main/java/com/msdw/tms/service/impl/SysPermissionServiceImpl.java create mode 100644 src/main/java/com/msdw/tms/service/impl/SysRolePermissionServiceImpl.java create mode 100644 src/main/java/com/msdw/tms/service/impl/SysRoleServiceImpl.java create mode 100644 src/main/java/com/msdw/tms/service/impl/SysUserRoleServiceImpl.java create mode 100644 src/main/java/com/msdw/tms/util/MyBatisPlusCodeGenerator.java create mode 100644 src/main/resources/mapper/tms/SysPermissionMapper.xml create mode 100644 src/main/resources/mapper/tms/SysRoleMapper.xml create mode 100644 src/main/resources/mapper/tms/SysRolePermissionMapper.xml create mode 100644 src/main/resources/mapper/tms/SysUserRoleMapper.xml diff --git a/pom.xml b/pom.xml index 0d3ac1b..1888f60 100644 --- a/pom.xml +++ b/pom.xml @@ -225,6 +225,19 @@ pagehelper 5.1.2 + + + + com.baomidou + mybatis-plus-generator + 3.3.1 + + + org.freemarker + freemarker + 2.3.28 + compile + diff --git a/src/main/java/com/msdw/tms/controller/SysPermissionController.java b/src/main/java/com/msdw/tms/controller/SysPermissionController.java new file mode 100644 index 0000000..3828387 --- /dev/null +++ b/src/main/java/com/msdw/tms/controller/SysPermissionController.java @@ -0,0 +1,20 @@ +package com.msdw.tms.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 菜单权限表 前端控制器 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@RestController +@RequestMapping("/sys-permission") +public class SysPermissionController { + +} diff --git a/src/main/java/com/msdw/tms/controller/SysRoleController.java b/src/main/java/com/msdw/tms/controller/SysRoleController.java new file mode 100644 index 0000000..76cef81 --- /dev/null +++ b/src/main/java/com/msdw/tms/controller/SysRoleController.java @@ -0,0 +1,20 @@ +package com.msdw.tms.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 用户角色表 前端控制器 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@RestController +@RequestMapping("/sys-role") +public class SysRoleController { + +} diff --git a/src/main/java/com/msdw/tms/controller/SysRolePermissionController.java b/src/main/java/com/msdw/tms/controller/SysRolePermissionController.java new file mode 100644 index 0000000..c678b79 --- /dev/null +++ b/src/main/java/com/msdw/tms/controller/SysRolePermissionController.java @@ -0,0 +1,20 @@ +package com.msdw.tms.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 角色权限中间表 前端控制器 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@RestController +@RequestMapping("/sys-role-permission") +public class SysRolePermissionController { + +} diff --git a/src/main/java/com/msdw/tms/controller/SysUserRoleController.java b/src/main/java/com/msdw/tms/controller/SysUserRoleController.java new file mode 100644 index 0000000..fb47650 --- /dev/null +++ b/src/main/java/com/msdw/tms/controller/SysUserRoleController.java @@ -0,0 +1,20 @@ +package com.msdw.tms.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 用户角色中间表 前端控制器 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@RestController +@RequestMapping("/sys-user-role") +public class SysUserRoleController { + +} diff --git a/src/main/java/com/msdw/tms/dao/SysPermissionMapper.java b/src/main/java/com/msdw/tms/dao/SysPermissionMapper.java new file mode 100644 index 0000000..a3f94f8 --- /dev/null +++ b/src/main/java/com/msdw/tms/dao/SysPermissionMapper.java @@ -0,0 +1,18 @@ +package com.msdw.tms.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.msdw.tms.entity.SysPermission; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * 菜单权限表 Mapper 接口 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@Mapper +public interface SysPermissionMapper extends BaseMapper { + +} diff --git a/src/main/java/com/msdw/tms/dao/SysRoleMapper.java b/src/main/java/com/msdw/tms/dao/SysRoleMapper.java new file mode 100644 index 0000000..e30fa9d --- /dev/null +++ b/src/main/java/com/msdw/tms/dao/SysRoleMapper.java @@ -0,0 +1,18 @@ +package com.msdw.tms.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.msdw.tms.entity.SysRole; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * 用户角色表 Mapper 接口 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@Mapper +public interface SysRoleMapper extends BaseMapper { + +} diff --git a/src/main/java/com/msdw/tms/dao/SysRolePermissionMapper.java b/src/main/java/com/msdw/tms/dao/SysRolePermissionMapper.java new file mode 100644 index 0000000..e294523 --- /dev/null +++ b/src/main/java/com/msdw/tms/dao/SysRolePermissionMapper.java @@ -0,0 +1,18 @@ +package com.msdw.tms.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.msdw.tms.entity.SysRolePermission; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * 角色权限中间表 Mapper 接口 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@Mapper +public interface SysRolePermissionMapper extends BaseMapper { + +} diff --git a/src/main/java/com/msdw/tms/dao/SysUserRoleMapper.java b/src/main/java/com/msdw/tms/dao/SysUserRoleMapper.java new file mode 100644 index 0000000..a4a1339 --- /dev/null +++ b/src/main/java/com/msdw/tms/dao/SysUserRoleMapper.java @@ -0,0 +1,18 @@ +package com.msdw.tms.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.msdw.tms.entity.SysUserRole; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * 用户角色中间表 Mapper 接口 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@Mapper +public interface SysUserRoleMapper extends BaseMapper { + +} diff --git a/src/main/java/com/msdw/tms/entity/SysPermission.java b/src/main/java/com/msdw/tms/entity/SysPermission.java new file mode 100644 index 0000000..d769846 --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/SysPermission.java @@ -0,0 +1,90 @@ +package com.msdw.tms.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import java.util.Date; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * 菜单权限表 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@Data +@TableName("sys_permission") +public class SysPermission implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 权限标识符 + */ + private String code; + + /** + * 名称 + */ + private String name; + + /** + * 父权限id + */ + private Long parentId; + + /** + * 层级 + */ + private Integer level; + + /** + * 是否是菜单:1、是,0、不是(0目前为按钮) + */ + private Integer menuOrNot; + + /** + * 状态:0、启用,1、禁用 + */ + private Integer status; + + /** + * 路径 + */ + private String url; + + /** + * 页面路径 + */ + private String menuUrl; + + /** + * 排序 + */ + private Integer sort; + + /** + * 图标 + */ + private String icon; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新时间 + */ + private Date motifyTime; +} diff --git a/src/main/java/com/msdw/tms/entity/SysRole.java b/src/main/java/com/msdw/tms/entity/SysRole.java new file mode 100644 index 0000000..6a6ffac --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/SysRole.java @@ -0,0 +1,60 @@ +package com.msdw.tms.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import java.util.Date; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * 用户角色表 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@Data +@TableName("sys_role") +public class SysRole implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 角色名称 + */ + private String name; + + /** + * 角色描述 + */ + private String description; + + /** + * 是否删除:0、未删除,1、删除 + */ + private Integer delOrNot; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新时间 + */ + private Date motifyTime; + + /** + * 编码 + */ + private String code; +} diff --git a/src/main/java/com/msdw/tms/entity/SysRolePermission.java b/src/main/java/com/msdw/tms/entity/SysRolePermission.java new file mode 100644 index 0000000..b4add0e --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/SysRolePermission.java @@ -0,0 +1,39 @@ +package com.msdw.tms.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * 角色权限中间表 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@Data +@TableName("sys_role_permission") +public class SysRolePermission implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 角色id + */ + private Long roleId; + + /** + * 权限id + */ + private Long permissionId; +} diff --git a/src/main/java/com/msdw/tms/entity/SysUserRole.java b/src/main/java/com/msdw/tms/entity/SysUserRole.java new file mode 100644 index 0000000..aa886f5 --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/SysUserRole.java @@ -0,0 +1,39 @@ +package com.msdw.tms.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * 用户角色中间表 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@Data +@TableName("sys_user_role") +public class SysUserRole implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 用户id + */ + private Long userId; + + /** + * 角色id + */ + private Long roleId; +} diff --git a/src/main/java/com/msdw/tms/service/ISysPermissionService.java b/src/main/java/com/msdw/tms/service/ISysPermissionService.java new file mode 100644 index 0000000..0786537 --- /dev/null +++ b/src/main/java/com/msdw/tms/service/ISysPermissionService.java @@ -0,0 +1,16 @@ +package com.msdw.tms.service; + +import com.msdw.tms.entity.SysPermission; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 菜单权限表 服务类 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +public interface ISysPermissionService extends IService { + +} diff --git a/src/main/java/com/msdw/tms/service/ISysRolePermissionService.java b/src/main/java/com/msdw/tms/service/ISysRolePermissionService.java new file mode 100644 index 0000000..08bfc35 --- /dev/null +++ b/src/main/java/com/msdw/tms/service/ISysRolePermissionService.java @@ -0,0 +1,16 @@ +package com.msdw.tms.service; + +import com.msdw.tms.entity.SysRolePermission; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 角色权限中间表 服务类 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +public interface ISysRolePermissionService extends IService { + +} diff --git a/src/main/java/com/msdw/tms/service/ISysRoleService.java b/src/main/java/com/msdw/tms/service/ISysRoleService.java new file mode 100644 index 0000000..8d5af9c --- /dev/null +++ b/src/main/java/com/msdw/tms/service/ISysRoleService.java @@ -0,0 +1,16 @@ +package com.msdw.tms.service; + +import com.msdw.tms.entity.SysRole; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 用户角色表 服务类 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +public interface ISysRoleService extends IService { + +} diff --git a/src/main/java/com/msdw/tms/service/ISysUserRoleService.java b/src/main/java/com/msdw/tms/service/ISysUserRoleService.java new file mode 100644 index 0000000..dc900c5 --- /dev/null +++ b/src/main/java/com/msdw/tms/service/ISysUserRoleService.java @@ -0,0 +1,16 @@ +package com.msdw.tms.service; + +import com.msdw.tms.entity.SysUserRole; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 用户角色中间表 服务类 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +public interface ISysUserRoleService extends IService { + +} diff --git a/src/main/java/com/msdw/tms/service/impl/SysPermissionServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/SysPermissionServiceImpl.java new file mode 100644 index 0000000..30d305e --- /dev/null +++ b/src/main/java/com/msdw/tms/service/impl/SysPermissionServiceImpl.java @@ -0,0 +1,20 @@ +package com.msdw.tms.service.impl; + +import com.msdw.tms.dao.SysPermissionMapper; +import com.msdw.tms.entity.SysPermission; +import com.msdw.tms.service.ISysPermissionService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 菜单权限表 服务实现类 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@Service +public class SysPermissionServiceImpl extends ServiceImpl implements ISysPermissionService { + +} diff --git a/src/main/java/com/msdw/tms/service/impl/SysRolePermissionServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/SysRolePermissionServiceImpl.java new file mode 100644 index 0000000..713fac2 --- /dev/null +++ b/src/main/java/com/msdw/tms/service/impl/SysRolePermissionServiceImpl.java @@ -0,0 +1,20 @@ +package com.msdw.tms.service.impl; + +import com.msdw.tms.dao.SysRolePermissionMapper; +import com.msdw.tms.entity.SysRolePermission; +import com.msdw.tms.service.ISysRolePermissionService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 角色权限中间表 服务实现类 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@Service +public class SysRolePermissionServiceImpl extends ServiceImpl implements ISysRolePermissionService { + +} diff --git a/src/main/java/com/msdw/tms/service/impl/SysRoleServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/SysRoleServiceImpl.java new file mode 100644 index 0000000..58b4856 --- /dev/null +++ b/src/main/java/com/msdw/tms/service/impl/SysRoleServiceImpl.java @@ -0,0 +1,20 @@ +package com.msdw.tms.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.msdw.tms.dao.SysRoleMapper; +import com.msdw.tms.entity.SysRole; +import com.msdw.tms.service.ISysRoleService; +import org.springframework.stereotype.Service; + +/** + *

+ * 用户角色表 服务实现类 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@Service +public class SysRoleServiceImpl extends ServiceImpl implements ISysRoleService { + +} diff --git a/src/main/java/com/msdw/tms/service/impl/SysUserRoleServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/SysUserRoleServiceImpl.java new file mode 100644 index 0000000..336895a --- /dev/null +++ b/src/main/java/com/msdw/tms/service/impl/SysUserRoleServiceImpl.java @@ -0,0 +1,20 @@ +package com.msdw.tms.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.msdw.tms.dao.SysUserRoleMapper; +import com.msdw.tms.entity.SysUserRole; +import com.msdw.tms.service.ISysUserRoleService; +import org.springframework.stereotype.Service; + +/** + *

+ * 用户角色中间表 服务实现类 + *

+ * + * @author Qyq + * @since 2021-02-24 + */ +@Service +public class SysUserRoleServiceImpl extends ServiceImpl implements ISysUserRoleService { + +} diff --git a/src/main/java/com/msdw/tms/util/MyBatisPlusCodeGenerator.java b/src/main/java/com/msdw/tms/util/MyBatisPlusCodeGenerator.java new file mode 100644 index 0000000..e7f58ca --- /dev/null +++ b/src/main/java/com/msdw/tms/util/MyBatisPlusCodeGenerator.java @@ -0,0 +1,115 @@ +package com.msdw.tms.util; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.InjectionConfig; +import com.baomidou.mybatisplus.generator.config.*; +import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.baomidou.mybatisplus.generator.config.rules.DateType; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; + +import java.util.ArrayList; +import java.util.List; + +/** + * @Author: LvFang + * @Date: Created in 2019/6/11. + * @Description: + */ +public class MyBatisPlusCodeGenerator { + + //包名 + public static final String PACKAGE_NAME = "com.msdw.tms"; + + public static void main(String[] args) { + String[] tables = new String[] {"sys_role","sys_role_permission","sys_user_role"};//表名数组 + String[] tablePrefixs = new String[] {""};//去掉前缀 + executeCode(PACKAGE_NAME,tables,tablePrefixs); + } + + private static void executeCode(String pack, String[] tables, String[] tablePrefixs) { + // 代码生成器 + AutoGenerator mpg = new AutoGenerator(); + + // 全局配置 + GlobalConfig gc = new GlobalConfig(); + // 是否覆盖已有文件 + gc.setFileOverride(false); + // 生成文件的输出目录 + String projectPath = System.getProperty("user.dir");//user.dir 表示当前工程路径无需替换 + gc.setOutputDir(projectPath + "/src/main/java"); + //设置bean命名规范 + gc.setEntityName("%s"); + // 开发人员 + gc.setAuthor("Qyq"); + // 是否打开输出目录 + gc.setOpen(false); + // 开启 BaseResultMap + gc.setBaseResultMap(true); + // 指定生成的主键的ID类型 + gc.setIdType(IdType.ID_WORKER); + // 时间类型对应策略: 只使用 java.util.date 代替 + gc.setDateType(DateType.ONLY_DATE); + mpg.setGlobalConfig(gc); + + // 数据源配置 + DataSourceConfig config= new DataSourceConfig(); + // 从试图获取 + config.setUrl("jdbc:mysql://localhost:3306/msdw_tms?serverTimezone=UTC"); + config.setDriverName("com.mysql.cj.jdbc.Driver"); + config.setUsername("root"); + config.setPassword("root"); + mpg.setDataSource(config); + + // 包配置 + PackageConfig pc = new PackageConfig(); + // 父包名。如果为空,将下面子包名必须写全部, 否则就只需写子包名 + pc.setParent(pack); + // Entity包名 + pc.setEntity("entity"); + mpg.setPackageInfo(pc); + + // 自定义配置 + InjectionConfig cfg = new InjectionConfig() { + @Override + public void initMap() { + // to do nothing + } + }; + List focList = new ArrayList<>(); + focList.add(new FileOutConfig("/templates/mapper.xml.ftl") { + public String outputFile(TableInfo tableInfo) { + // 自定义输入文件名称 + if (StringUtils.isEmpty(pc.getModuleName())) { + return projectPath + "/src/main/resources/mapper/tms/" + tableInfo.getXmlName() + StringPool.DOT_XML; + }else { + return projectPath + "/src/main/resources/mapper/tms/" + pc.getModuleName() + "/" + tableInfo.getXmlName() + StringPool.DOT_XML; + } + } + }); + cfg.setFileOutConfigList(focList); + mpg.setCfg(cfg); + mpg.setTemplate(new TemplateConfig().setXml(null)); + + // 策略配置 + StrategyConfig strategy = new StrategyConfig(); + // 数据库表映射到实体的命名策略: 下划线转驼峰命名 + strategy.setNaming(NamingStrategy.underline_to_camel); + // 数据库表字段映射到实体的命名策略: 下划线转驼峰命名 + strategy.setColumnNaming(NamingStrategy.underline_to_camel); + // 【实体】是否为lombok模型(默认 false) + strategy.setEntityLombokModel(false); + // 需要包含的表名,允许正则表达式(与exclude二选一配置) + strategy.setInclude(tables); + // 驼峰转连字符 + strategy.setControllerMappingHyphenStyle(true); + // 表前缀 + strategy.setTablePrefix(tablePrefixs); + mpg.setStrategy(strategy); + mpg.setTemplateEngine(new FreemarkerTemplateEngine()); + mpg.execute(); + } +} diff --git a/src/main/resources/mapper/tms/SysPermissionMapper.xml b/src/main/resources/mapper/tms/SysPermissionMapper.xml new file mode 100644 index 0000000..806173d --- /dev/null +++ b/src/main/resources/mapper/tms/SysPermissionMapper.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mapper/tms/SysRoleMapper.xml b/src/main/resources/mapper/tms/SysRoleMapper.xml new file mode 100644 index 0000000..95f2bc5 --- /dev/null +++ b/src/main/resources/mapper/tms/SysRoleMapper.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mapper/tms/SysRolePermissionMapper.xml b/src/main/resources/mapper/tms/SysRolePermissionMapper.xml new file mode 100644 index 0000000..ebeb487 --- /dev/null +++ b/src/main/resources/mapper/tms/SysRolePermissionMapper.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/main/resources/mapper/tms/SysUserRoleMapper.xml b/src/main/resources/mapper/tms/SysUserRoleMapper.xml new file mode 100644 index 0000000..00527ea --- /dev/null +++ b/src/main/resources/mapper/tms/SysUserRoleMapper.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + From e3f48ad9b5dce8a2baacb3fd93ab339dbd41b7c9 Mon Sep 17 00:00:00 2001 From: shijie <648688341@qq.com> Date: Wed, 24 Feb 2021 17:17:50 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A7=92=E8=89=B2=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=8E=A5=E5=8F=A3=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SysPermissionController.java | 140 +++++++++++++++++- .../com/msdw/tms/dao/SysPermissionMapper.java | 4 + .../java/com/msdw/tms/dao/SysRoleMapper.java | 10 ++ .../msdw/tms/dao/SysRolePermissionMapper.java | 13 ++ .../com/msdw/tms/dao/SysUserRoleMapper.java | 4 + .../com/msdw/tms/entity/SysPermission.java | 10 ++ .../entity/request/RolePermissionRequest.java | 83 +++++++++++ .../msdw/tms/entity/response/CommonCode.java | 3 + .../response/RolePermissionResponse.java | 80 ++++++++++ .../tms/service/ISysPermissionService.java | 29 ++++ .../impl/SysPermissionServiceImpl.java | 107 +++++++++++++ src/main/resources/application.yml | 12 +- .../mapper/tms/SysPermissionMapper.xml | 16 +- .../resources/mapper/tms/SysRoleMapper.xml | 26 +++- .../mapper/tms/SysRolePermissionMapper.xml | 28 +++- .../mapper/tms/SysUserRoleMapper.xml | 9 +- 16 files changed, 562 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/msdw/tms/entity/request/RolePermissionRequest.java create mode 100644 src/main/java/com/msdw/tms/entity/response/RolePermissionResponse.java diff --git a/src/main/java/com/msdw/tms/controller/SysPermissionController.java b/src/main/java/com/msdw/tms/controller/SysPermissionController.java index 3828387..879d0a2 100644 --- a/src/main/java/com/msdw/tms/controller/SysPermissionController.java +++ b/src/main/java/com/msdw/tms/controller/SysPermissionController.java @@ -1,9 +1,24 @@ package com.msdw.tms.controller; -import org.springframework.web.bind.annotation.RequestMapping; +import com.msdw.tms.common.exception.ExceptionCast; +import com.msdw.tms.common.utils.PageUtils; +import com.msdw.tms.entity.SysPermission; +import com.msdw.tms.entity.SysRole; +import com.msdw.tms.entity.SysRolePermission; +import com.msdw.tms.entity.request.RolePermissionRequest; +import com.msdw.tms.entity.response.CommonCode; +import com.msdw.tms.entity.response.ResponseResult; +import com.msdw.tms.entity.response.RolePermissionResponse; +import com.msdw.tms.service.ISysPermissionService; +import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; -import org.springframework.web.bind.annotation.RestController; +import javax.validation.Valid; +import java.util.*; +import java.util.stream.Collectors; /** *

@@ -15,6 +30,127 @@ import org.springframework.web.bind.annotation.RestController; */ @RestController @RequestMapping("/sys-permission") +@Api(tags = {"角色权限管理"}) public class SysPermissionController { + @Autowired + private ISysPermissionService permissionService; + + /** + * 权限菜单树形列表展示 + * @return + */ + @GetMapping("/tree") + public ResponseResult tree(){ + List list = permissionService.listWithTree(); + return new ResponseResult>().SUCCESS(list); + } + + /** + * 新增角色权限 + */ + @Transactional + @PostMapping("/saveRolePermission") + public ResponseResult saveRolePermission(@Valid @RequestBody RolePermissionRequest rolePermission) { + Date date = new Date(); + rolePermission.setCreateTime(date); + rolePermission.setMotifyTime(date); + //此处要判重,新增的角色名称要唯一 + int count = permissionService.uniqueRoleName(rolePermission.getName()); + if(count >0){ + ExceptionCast.cast(CommonCode.ROLE_NAME_EXIST); + } + //新增角色到角色表 + int request = permissionService.addHrmsRole(rolePermission); + //根据选中的permissionId批量新增数据到hrms_role_permission + List asList = Arrays.asList(rolePermission.getPermissionIds()); + List rolePermissionList = getRolePermissionList(asList, rolePermission.getRoleId()); + boolean result = permissionService.addHrmsRolePermission(rolePermissionList); + + return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL(); + } + + private List getRolePermissionList(List asList, Long roleId) { + return asList.stream().map(permissionId -> { + RolePermissionRequest request = new RolePermissionRequest(); + request.setRoleId(roleId); + request.setPermissionId(permissionId); + return request; + }).collect(Collectors.toList()); + } + + /** + * 修改角色权限 + */ + @Transactional + @PostMapping("/updateRolePermission") + public ResponseResult updateRolePermission(@Valid @RequestBody RolePermissionRequest rolePermission) { + Date date = new Date(); + rolePermission.setMotifyTime(date); + //根据角色Id修改角色内容 + int request = permissionService.updateHrmsRole(rolePermission); + //删除该角色Id对应的所有权限 + List asList = Arrays.asList(rolePermission.getPermissionIds()); + permissionService.deleteHrmsRolePermission(rolePermission.getRoleId()); + //根据选中的permissionId批量新增数据到hrms_role_permission + List rolePermissionList = getRolePermissionList(asList, rolePermission.getRoleId()); + boolean result = permissionService.addHrmsRolePermission(rolePermissionList); + + return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL(); + } + + /** + * 删除用户角色权限 + */ + @Transactional + @PostMapping("/delRolePermission") + public ResponseResult delRolePermission(@RequestBody RolePermissionRequest rolePermission) { + //根据角色Id查询该角色是否有用户关联 + int count = permissionService.queryCountByRoleId(rolePermission.getRoleIds()); + if(count >0){ + ExceptionCast.cast(CommonCode.ROLE_EMP_EXIST); + } + //没有关联则根据roleId删除hrms_role表对应记录 + boolean b = permissionService.deleteHrmsRoleByRoleId(rolePermission.getRoleIds()); + //根据角色id删除对应所有权限 + boolean result = permissionService.deleteHrmsRolePermission(rolePermission.getRoleIds()); + + return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL(); + } + + /** + * 查看权限数组 + * @param roleId + * @return + */ + @GetMapping("/queryPermissionArrById") + public ResponseResult queryPermissionArrById(@RequestParam("roleId") Long roleId) { + List list = permissionService.queryPermissionArrById(roleId); + ArrayList sb = new ArrayList(); + for (SysRolePermission rolePermission:list) { + sb.add(rolePermission.getPermissionId().intValue()); + } + Integer[] ids = sb.toArray(new Integer[sb.size()]); + //根据roleId查询角色名称和角色描述 + SysRole roleMsg = permissionService.queryRoleMsg(roleId); + Map map = new HashMap(); + map.put("permissionIds",ids); + map.put("name",roleMsg.getName()); + map.put("description",roleMsg.getDescription()); + return new ResponseResult>().SUCCESS(map); + } + + /** + * 角色权限列表展示 + * @param page + * @param size + * @return + */ + @GetMapping("/rolePermissionList") + public ResponseResult rolePermissionList(@RequestParam("page") Integer page, + @RequestParam("size") Integer size,@RequestParam("name")String name) { + PageUtils data = permissionService.queryPage(page, size, name); + return new ResponseResult().SUCCESS(data); + } + } diff --git a/src/main/java/com/msdw/tms/dao/SysPermissionMapper.java b/src/main/java/com/msdw/tms/dao/SysPermissionMapper.java index a3f94f8..266a038 100644 --- a/src/main/java/com/msdw/tms/dao/SysPermissionMapper.java +++ b/src/main/java/com/msdw/tms/dao/SysPermissionMapper.java @@ -1,7 +1,10 @@ package com.msdw.tms.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.msdw.tms.entity.SysPermission; +import com.msdw.tms.entity.response.RolePermissionResponse; import org.apache.ibatis.annotations.Mapper; /** @@ -15,4 +18,5 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface SysPermissionMapper extends BaseMapper { + IPage pageByCondition(Page page,String name); } diff --git a/src/main/java/com/msdw/tms/dao/SysRoleMapper.java b/src/main/java/com/msdw/tms/dao/SysRoleMapper.java index e30fa9d..01c2c70 100644 --- a/src/main/java/com/msdw/tms/dao/SysRoleMapper.java +++ b/src/main/java/com/msdw/tms/dao/SysRoleMapper.java @@ -2,7 +2,11 @@ package com.msdw.tms.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.msdw.tms.entity.SysRole; +import com.msdw.tms.entity.request.RolePermissionRequest; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** *

@@ -15,4 +19,10 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface SysRoleMapper extends BaseMapper { + int addHrmsRole(RolePermissionRequest rolePermission); + + int updateHrmsRole(RolePermissionRequest rolePermission); + + boolean deleteHrmsRoleByRoleId(@Param("roleIds") List roleIds); + } diff --git a/src/main/java/com/msdw/tms/dao/SysRolePermissionMapper.java b/src/main/java/com/msdw/tms/dao/SysRolePermissionMapper.java index e294523..7cce2f8 100644 --- a/src/main/java/com/msdw/tms/dao/SysRolePermissionMapper.java +++ b/src/main/java/com/msdw/tms/dao/SysRolePermissionMapper.java @@ -2,7 +2,11 @@ package com.msdw.tms.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.msdw.tms.entity.SysRolePermission; +import com.msdw.tms.entity.request.RolePermissionRequest; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** *

@@ -15,4 +19,13 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface SysRolePermissionMapper extends BaseMapper { + int uniqueRoleName(String name); + + boolean addHrmsRolePermission(@Param("rolePermissionList") List rolePermissionList); + + boolean deleteHrmsRolePermission(@Param("roleIds") List roleIds); + + boolean deleteHrmsRolePermissionSingle(Long roleId); + + List queryPermissionArrById(Long roleId); } diff --git a/src/main/java/com/msdw/tms/dao/SysUserRoleMapper.java b/src/main/java/com/msdw/tms/dao/SysUserRoleMapper.java index a4a1339..b37ac13 100644 --- a/src/main/java/com/msdw/tms/dao/SysUserRoleMapper.java +++ b/src/main/java/com/msdw/tms/dao/SysUserRoleMapper.java @@ -3,6 +3,9 @@ package com.msdw.tms.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.msdw.tms.entity.SysUserRole; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** *

@@ -15,4 +18,5 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface SysUserRoleMapper extends BaseMapper { + int queryCountByRoleId(@Param("roleIds") List roleIds); } diff --git a/src/main/java/com/msdw/tms/entity/SysPermission.java b/src/main/java/com/msdw/tms/entity/SysPermission.java index d769846..cb3851e 100644 --- a/src/main/java/com/msdw/tms/entity/SysPermission.java +++ b/src/main/java/com/msdw/tms/entity/SysPermission.java @@ -1,12 +1,15 @@ package com.msdw.tms.entity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.IdType; import java.util.Date; import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Data; import java.io.Serializable; +import java.util.List; /** *

@@ -87,4 +90,11 @@ public class SysPermission implements Serializable { * 更新时间 */ private Date motifyTime; + + /** + * 子权限 + */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @TableField(exist = false) + private List children; } diff --git a/src/main/java/com/msdw/tms/entity/request/RolePermissionRequest.java b/src/main/java/com/msdw/tms/entity/request/RolePermissionRequest.java new file mode 100644 index 0000000..9354095 --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/request/RolePermissionRequest.java @@ -0,0 +1,83 @@ +package com.msdw.tms.entity.request; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * 记录菜单权限 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-09-07 17:12:14 + */ +@Data +public class RolePermissionRequest implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 角色id + */ + private Long roleId; + + /** + * 角色ids + */ + private Long[] roleIds; + /** + * 角色名称 + */ + private String name; + + /** + * 角色描述 + */ + private String description; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新时间 + */ + private Date motifyTime; + + /** + * 权限ids + */ + @NotEmpty(message = "权限至少选中一项!") + private Long[] permissionIds; + + private Long permissionId; + + /** + * 拥有权限名称 + */ + private String permissionName; + + /** + * 父级id + */ + private Long parentId; + + /** + * 子权限 + */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @TableField(exist = false) + private List children; + + /** + * 排序 + */ + private Integer sort; + +} diff --git a/src/main/java/com/msdw/tms/entity/response/CommonCode.java b/src/main/java/com/msdw/tms/entity/response/CommonCode.java index d3374b6..c8aa3ce 100644 --- a/src/main/java/com/msdw/tms/entity/response/CommonCode.java +++ b/src/main/java/com/msdw/tms/entity/response/CommonCode.java @@ -18,6 +18,9 @@ public enum CommonCode implements ResultCode { REPEAT_INEXCEL(false, 10010, "试题在excel表中重复!"), EVALUATION_QUESTION_NUM_INVALID(false, 10011, "当前测评题数设置为0,请先设置测评题数!"), FAIL(false, 11111, "操作失败!"), + + ROLE_NAME_EXIST(false,20001,"该角色名称已存在,请重新输入!"), + ROLE_EMP_EXIST(false,44001,"该角色有用户关联,不能删除!"), SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!"); //操作是否成功 boolean success; diff --git a/src/main/java/com/msdw/tms/entity/response/RolePermissionResponse.java b/src/main/java/com/msdw/tms/entity/response/RolePermissionResponse.java new file mode 100644 index 0000000..e3c9748 --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/response/RolePermissionResponse.java @@ -0,0 +1,80 @@ +package com.msdw.tms.entity.response; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 记录菜单权限 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-09-07 17:12:14 + */ +@Data +@TableName("hrms_permission") +public class RolePermissionResponse implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 角色id + */ + @ApiModelProperty("id") + private Long roleId; + /** + * 角色名称 + */ + @ApiModelProperty("名称") + private String name; + + /** + * 角色描述 + */ + @ApiModelProperty("角色描述") + private String description; + + /** + * 权限id + */ + @ApiModelProperty("权限id") + private Long permissionId; + + /** + * 拥有权限名称 + */ + @ApiModelProperty("权限名称") + private String permissionName; + + /** + * 父级id + */ + @ApiModelProperty("父级id") + private Long parentId; + + /** + * 子权限 + */ + @ApiModelProperty("子权限") + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @TableField(exist = false) + private List children; + + /** + * 排序 + */ + @ApiModelProperty("子权限") + private Integer sort; + + /** + * 权限标识 + */ + private String code; + + private boolean disabled=true; + +} diff --git a/src/main/java/com/msdw/tms/service/ISysPermissionService.java b/src/main/java/com/msdw/tms/service/ISysPermissionService.java index 0786537..eae3794 100644 --- a/src/main/java/com/msdw/tms/service/ISysPermissionService.java +++ b/src/main/java/com/msdw/tms/service/ISysPermissionService.java @@ -1,7 +1,13 @@ package com.msdw.tms.service; +import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.entity.SysPermission; import com.baomidou.mybatisplus.extension.service.IService; +import com.msdw.tms.entity.SysRole; +import com.msdw.tms.entity.SysRolePermission; +import com.msdw.tms.entity.request.RolePermissionRequest; + +import java.util.List; /** *

@@ -13,4 +19,27 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface ISysPermissionService extends IService { + List listWithTree(); + + int uniqueRoleName(String name); + + int addHrmsRole(RolePermissionRequest rolePermission); + + boolean addHrmsRolePermission(List rolePermissionList); + + int updateHrmsRole(RolePermissionRequest rolePermission); + + boolean deleteHrmsRolePermission(Long roleId); + + boolean deleteHrmsRolePermission(Long[] roleIds); + + int queryCountByRoleId(Long[] roleIds); + + boolean deleteHrmsRoleByRoleId(Long[] roleIds); + + List queryPermissionArrById(Long roleId); + + SysRole queryRoleMsg(Long roleId); + + PageUtils queryPage(Integer page, Integer size, String name); } diff --git a/src/main/java/com/msdw/tms/service/impl/SysPermissionServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/SysPermissionServiceImpl.java index 30d305e..465ea2d 100644 --- a/src/main/java/com/msdw/tms/service/impl/SysPermissionServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/SysPermissionServiceImpl.java @@ -1,11 +1,28 @@ package com.msdw.tms.service.impl; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.dao.SysPermissionMapper; +import com.msdw.tms.dao.SysRoleMapper; +import com.msdw.tms.dao.SysRolePermissionMapper; +import com.msdw.tms.dao.SysUserRoleMapper; import com.msdw.tms.entity.SysPermission; +import com.msdw.tms.entity.SysRole; +import com.msdw.tms.entity.SysRolePermission; +import com.msdw.tms.entity.request.RolePermissionRequest; +import com.msdw.tms.entity.response.RolePermissionResponse; import com.msdw.tms.service.ISysPermissionService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + /** *

* 菜单权限表 服务实现类 @@ -17,4 +34,94 @@ import org.springframework.stereotype.Service; @Service public class SysPermissionServiceImpl extends ServiceImpl implements ISysPermissionService { + @Resource + private SysRolePermissionMapper rolePermissionMapper; + + @Resource + private SysRoleMapper roleMapper; + + @Resource + private SysUserRoleMapper userRoleMapper; + + @Override + public List listWithTree() { +/* Listlist = this.getBaseMapper().queryPermissionTree(); + return getPermissionTreeList(list,0L);*/ + System.out.println("this.list()=================="+this.list()); + return getPermissionTreeList(this.list(), 0L); + } + + private List getPermissionTreeList(List list, Long parentId){ + return list.stream() + .filter(item -> parentId.equals(item.getParentId())) + .peek(item -> item.setChildren(getPermissionTreeList(list, item.getId()))) + .sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort()))) + .collect(Collectors.toList()); + } + + @Override + public int uniqueRoleName(String name) { + return rolePermissionMapper.uniqueRoleName(name); + } + + @Override + public int addHrmsRole(RolePermissionRequest rolePermission) { + int request = roleMapper.addHrmsRole(rolePermission); + return request; + } + + @Override + public boolean addHrmsRolePermission(List rolePermissionList) { + return rolePermissionMapper.addHrmsRolePermission(rolePermissionList); + } + + @Override + public int updateHrmsRole(RolePermissionRequest rolePermission) { + return roleMapper.updateHrmsRole(rolePermission); + } + + @Override + public boolean deleteHrmsRolePermission(Long roleId) { + return rolePermissionMapper.deleteHrmsRolePermissionSingle(roleId); + } + + @Override + public boolean deleteHrmsRolePermission(Long[] roleIds) { + return rolePermissionMapper.deleteHrmsRolePermission(Arrays.asList(roleIds)); + } + + @Override + public int queryCountByRoleId(Long[] roleIds) { + int count = userRoleMapper.queryCountByRoleId(Arrays.asList(roleIds)); + return count; + } + + @Override + public boolean deleteHrmsRoleByRoleId(Long[] roleIds) { + return roleMapper.deleteHrmsRoleByRoleId(Arrays.asList(roleIds)); + } + + @Override + public List queryPermissionArrById(Long roleId) { + return rolePermissionMapper.queryPermissionArrById(roleId); + } + + @Override + public SysRole queryRoleMsg(Long roleId) { + return roleMapper.selectById(roleId); + } + + @Override + public PageUtils queryPage(Integer page, Integer size, String name) { + //分页参数 + if (page <= 0) { + page = 1; + } + if (size <= 0) { + size = 10; + } + IPage systemLogVo = this.getBaseMapper().pageByCondition(new Page(page, size),name); + + return new PageUtils(systemLogVo); + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 5660afe..2893702 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -5,12 +5,12 @@ spring: # url: jdbc:mysql://www.liuwanr.cn:3306/huoran?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai # username: super # password: huoran888 - url: jdbc:mysql://rm-wz9y13wf7u8q8610fwo.mysql.rds.aliyuncs.com:3306/huoran?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai - username: super - password: huoran888 -# url: jdbc:mysql://localhost:3306/msdw_tms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai -# username: root -# password: root +# url: jdbc:mysql://rm-wz9y13wf7u8q8610fwo.mysql.rds.aliyuncs.com:3306/huoran?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai +# username: super +# password: huoran888 + url: jdbc:mysql://localhost:3306/msdw_tms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai + username: root + password: root driver-class-name: com.mysql.cj.jdbc.Driver # redis: # host: www.liuwanr.cn diff --git a/src/main/resources/mapper/tms/SysPermissionMapper.xml b/src/main/resources/mapper/tms/SysPermissionMapper.xml index 806173d..c7256e9 100644 --- a/src/main/resources/mapper/tms/SysPermissionMapper.xml +++ b/src/main/resources/mapper/tms/SysPermissionMapper.xml @@ -1,6 +1,6 @@ - + @@ -19,4 +19,18 @@ + + diff --git a/src/main/resources/mapper/tms/SysRoleMapper.xml b/src/main/resources/mapper/tms/SysRoleMapper.xml index 95f2bc5..050e8eb 100644 --- a/src/main/resources/mapper/tms/SysRoleMapper.xml +++ b/src/main/resources/mapper/tms/SysRoleMapper.xml @@ -1,6 +1,6 @@ - + @@ -13,4 +13,28 @@ + + INSERT INTO sys_role + (`name`,description,create_time,motify_time) + values (#{name},#{description},#{createTime},#{motifyTime}); + + + + UPDATE sys_role + + `name`=#{name}, + description=#{description}, + motify_time=#{motifyTime}, + + WHERE id = #{roleId} + + + + update sys_role set del_or_not = 1 where id IN + + #{item} + + + diff --git a/src/main/resources/mapper/tms/SysRolePermissionMapper.xml b/src/main/resources/mapper/tms/SysRolePermissionMapper.xml index ebeb487..17949cd 100644 --- a/src/main/resources/mapper/tms/SysRolePermissionMapper.xml +++ b/src/main/resources/mapper/tms/SysRolePermissionMapper.xml @@ -1,6 +1,6 @@ - + @@ -9,4 +9,30 @@ + + + + INSERT INTO sys_role_permission (role_id,permission_id) values + + (#{item.roleId},#{item.permissionId}) + + + + + delete from sys_role_permission where role_id in + + #{item} + + + + + delete from sys_role_permission where role_id=#{roleId} + + + + diff --git a/src/main/resources/mapper/tms/SysUserRoleMapper.xml b/src/main/resources/mapper/tms/SysUserRoleMapper.xml index 00527ea..b4f032e 100644 --- a/src/main/resources/mapper/tms/SysUserRoleMapper.xml +++ b/src/main/resources/mapper/tms/SysUserRoleMapper.xml @@ -1,6 +1,6 @@ - + @@ -9,4 +9,11 @@ + + From f70bd31d3902ea328016d76ecf6ee64e9c50fbff Mon Sep 17 00:00:00 2001 From: chen <1251790704@qq.com> Date: Thu, 25 Feb 2021 17:48:02 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExperimentalTeachingControllerApi.java | 4 +-- .../ExperimentalProjectController.java | 12 +-------- .../ExperimentalTeachingController.java | 25 +++++++++++-------- .../entity/ExperimentalTeachingEntity.java | 2 ++ .../tms/entity/vo/ExperimentalTeachingVO.java | 2 ++ .../impl/ExperimentalTeachingServiceImpl.java | 11 -------- 6 files changed, 21 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/msdw/tms/api/ExperimentalTeachingControllerApi.java b/src/main/java/com/msdw/tms/api/ExperimentalTeachingControllerApi.java index e5c9351..f6c28a0 100644 --- a/src/main/java/com/msdw/tms/api/ExperimentalTeachingControllerApi.java +++ b/src/main/java/com/msdw/tms/api/ExperimentalTeachingControllerApi.java @@ -2,12 +2,9 @@ package com.msdw.tms.api; import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.ExperimentalTeachingEntity; -import com.msdw.tms.entity.UserEntity; -import com.msdw.tms.entity.vo.ExperimentalTeachingEntityVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.GetMapping; import java.text.ParseException; @@ -20,6 +17,7 @@ public interface ExperimentalTeachingControllerApi { @ApiParam(name = "month", value = "月份:1、近一个月内 3、近三个月内 6、近六个月内", required = false) Integer month, @ApiParam(name = "type", value = "类型:1、手动发布 2、定时发布", required = false) Integer type, @ApiParam(name = "status", value = "状态:1、待开始 2、进行中 3、已结束", required = false) Integer status, + @ApiParam(name = "systemId", value = "系统id", required = false) Integer systemId, @ApiParam(name = "startTime", value = "开始时间", required = false) String startTime, @ApiParam(name = "stopTime", value = "结束时间", required = false) String stopTime, @ApiParam(name = "searchContent", value = "搜索内容", required = false) String searchContent, diff --git a/src/main/java/com/msdw/tms/controller/ExperimentalProjectController.java b/src/main/java/com/msdw/tms/controller/ExperimentalProjectController.java index 049eed6..31799c7 100644 --- a/src/main/java/com/msdw/tms/controller/ExperimentalProjectController.java +++ b/src/main/java/com/msdw/tms/controller/ExperimentalProjectController.java @@ -2,26 +2,16 @@ package com.msdw.tms.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.msdw.tms.api.ExperimentalProjectControllerApi; -import com.msdw.tms.api.ExperimentalTeachingControllerApi; -import com.msdw.tms.api.UserControllerApi; import com.msdw.tms.common.utils.Constant; import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.ExperimentalProjectEntity; -import com.msdw.tms.entity.ExperimentalTeachingEntity; -import com.msdw.tms.entity.UserEntity; import com.msdw.tms.entity.vo.ExperimentalProjectEntityVO; -import com.msdw.tms.entity.vo.ExperimentalTeachingEntityVO; -import com.msdw.tms.entity.vo.UserEntityVo; import com.msdw.tms.service.ExperimentalProjectService; -import com.msdw.tms.service.UserService; -import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Arrays; -import java.util.List; -import java.util.Map; @RestController @RequestMapping("tms/project") @@ -40,7 +30,7 @@ public class ExperimentalProjectController implements ExperimentalProjectControl return R.ok().put("experimental_project_name", one); } - /** + /**nm * 根据id查询实验班级详情 */ @GetMapping("/getById/{id}") diff --git a/src/main/java/com/msdw/tms/controller/ExperimentalTeachingController.java b/src/main/java/com/msdw/tms/controller/ExperimentalTeachingController.java index 7dd84ce..f070234 100644 --- a/src/main/java/com/msdw/tms/controller/ExperimentalTeachingController.java +++ b/src/main/java/com/msdw/tms/controller/ExperimentalTeachingController.java @@ -2,24 +2,20 @@ package com.msdw.tms.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.msdw.tms.api.ExperimentalTeachingControllerApi; -import com.msdw.tms.api.UserControllerApi; import com.msdw.tms.common.utils.Constant; import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.ExperimentalTeachingEntity; -import com.msdw.tms.entity.UserEntity; -import com.msdw.tms.entity.vo.ExperimentalTeachingEntityVO; import com.msdw.tms.entity.vo.ExperimentalTeachingVO; -import com.msdw.tms.entity.vo.UserEntityVo; import com.msdw.tms.service.ExperimentalTeachingService; -import com.msdw.tms.service.UserService; -import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; @RestController @RequestMapping("tms/exp") @@ -32,6 +28,7 @@ public class ExperimentalTeachingController implements ExperimentalTeachingContr /** * 根据id查询实验班级详情 */ + @Override @GetMapping("/getById/{id}") public R getById(@PathVariable("id") Integer id){ ExperimentalTeachingEntity et = experimentalTeachingService.getById(id); @@ -40,6 +37,7 @@ public class ExperimentalTeachingController implements ExperimentalTeachingContr /** * 根据邀请码查询 */ + @Override @GetMapping("/getInvitationCode") public R getInvitationCode(@RequestParam Integer invitationCode) { ExperimentalTeachingEntity one = experimentalTeachingService.getOne(new QueryWrapper().eq("invitation_code", invitationCode) @@ -49,15 +47,19 @@ public class ExperimentalTeachingController implements ExperimentalTeachingContr /** * 查询 */ + @Override @GetMapping("/list") - public R list(@RequestParam Integer page, - @RequestParam Integer size, - Integer month, Integer type, Integer status, String startTime, String stopTime, String searchContent,@RequestParam Integer schoolId){ + public R list(@RequestParam Integer page, @RequestParam Integer size, + Integer month, Integer type, Integer status,Integer systemId, String startTime, + String stopTime, String searchContent,@RequestParam Integer schoolId){ ExperimentalTeachingVO vo = new ExperimentalTeachingVO(); vo.setSchoolId(schoolId); if (month!=null){ vo.setMonth(month); } + if (systemId!=null){ + vo.setSystemId(systemId); + } if (type!=null){ vo.setType(type); } @@ -80,6 +82,7 @@ public class ExperimentalTeachingController implements ExperimentalTeachingContr /** * 保存 */ + @Override @PostMapping("/save") public R save(@RequestBody ExperimentalTeachingEntity experimentalTeachingEntity){ experimentalTeachingService.save(experimentalTeachingEntity); @@ -89,6 +92,7 @@ public class ExperimentalTeachingController implements ExperimentalTeachingContr /** * 修改 */ + @Override @PostMapping("/update") public R update(@RequestBody ExperimentalTeachingEntity experimentalTeachingEntity) throws ParseException { //添加实验结束时间 @@ -117,6 +121,7 @@ public class ExperimentalTeachingController implements ExperimentalTeachingContr /** * 删除 */ + @Override @PostMapping("/delete") public R delete(@RequestBody Integer[] ids){ experimentalTeachingService.removeByIds(Arrays.asList(ids)); diff --git a/src/main/java/com/msdw/tms/entity/ExperimentalTeachingEntity.java b/src/main/java/com/msdw/tms/entity/ExperimentalTeachingEntity.java index c6f3795..78033be 100644 --- a/src/main/java/com/msdw/tms/entity/ExperimentalTeachingEntity.java +++ b/src/main/java/com/msdw/tms/entity/ExperimentalTeachingEntity.java @@ -45,6 +45,8 @@ public class ExperimentalTeachingEntity { private Integer isCode; //绑定用户Id private Integer userId; + //绑定系统Id + private Integer systemId; //创建时间 private String creationTime; //实验倒计时 diff --git a/src/main/java/com/msdw/tms/entity/vo/ExperimentalTeachingVO.java b/src/main/java/com/msdw/tms/entity/vo/ExperimentalTeachingVO.java index 270246f..b3370c1 100644 --- a/src/main/java/com/msdw/tms/entity/vo/ExperimentalTeachingVO.java +++ b/src/main/java/com/msdw/tms/entity/vo/ExperimentalTeachingVO.java @@ -18,4 +18,6 @@ public class ExperimentalTeachingVO { private Integer status; //学校id private Integer schoolId; + //绑定系统Id + private Integer systemId; } diff --git a/src/main/java/com/msdw/tms/service/impl/ExperimentalTeachingServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/ExperimentalTeachingServiceImpl.java index 140fa2c..1265737 100644 --- a/src/main/java/com/msdw/tms/service/impl/ExperimentalTeachingServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/ExperimentalTeachingServiceImpl.java @@ -1,31 +1,20 @@ package com.msdw.tms.service.impl; -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 com.msdw.tms.common.utils.Constant; import com.msdw.tms.common.utils.PageUtils; -import com.msdw.tms.common.utils.Query; import com.msdw.tms.dao.ClassTeachingDao; import com.msdw.tms.dao.ExperimentalTeachingDao; -import com.msdw.tms.dao.UserDao; import com.msdw.tms.entity.ExperimentalTeachingEntity; -import com.msdw.tms.entity.UserEntity; -import com.msdw.tms.entity.vo.ExperimentalTeachingEntityVO; import com.msdw.tms.entity.vo.ExperimentalTeachingVO; import com.msdw.tms.entity.vo.ProjectRecordVo; -import com.msdw.tms.entity.vo.UserEntityVo; import com.msdw.tms.service.ExperimentalTeachingService; -import com.msdw.tms.service.UserService; import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; -import java.util.Map; - @Service("experimentalTeachingService") public class ExperimentalTeachingServiceImpl extends ServiceImpl implements ExperimentalTeachingService {