feat: 新增heritage-mybatisplus数据访问层模块
- 新增MyBatis Plus配置类,配置分页插件和自动填充 - 新增自定义ID生成器,使用雪花算法 - 新增系统相关Mapper接口:用户、角色、菜单、字典等 - 新增Mapper XML映射文件,定义SQL查询语句 - 配置@EnableMybatisPlus注解,启用MyBatis Plus功能
This commit is contained in:
parent
287add8e36
commit
6e36d9ab83
46
heritage-mybatisplus/pom.xml
Normal file
46
heritage-mybatisplus/pom.xml
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?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>org.leocoder.heritage</groupId>
|
||||||
|
<artifactId>heritage-backend</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
|
||||||
|
<name>coder-mybatis-plus</name>
|
||||||
|
<artifactId>heritage-mybatisplus</artifactId>
|
||||||
|
<description>MybatisPlus插件</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Mapper针对pojo,bo,vo,dto等依赖进来 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.leocoder.heritage</groupId>
|
||||||
|
<artifactId>heritage-model</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- MySQL数据库连接依赖[只有接口工程需要] -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Mapper会用到MyBatisPlus的类 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- MyBatisPlus PaginationInnerInterceptor分离插件 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-jsqlparser</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- p6spy SQL打印 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>p6spy</groupId>
|
||||||
|
<artifactId>p6spy</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
package org.leocoder.heritage.mybatisplus.anno;
|
||||||
|
|
||||||
|
import org.leocoder.heritage.mybatisplus.config.MyBatisPlusConfiguration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* @description [Mybatis-Plus插件开关]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
@Target({ElementType.TYPE})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
@Inherited
|
||||||
|
@Import({ MyBatisPlusConfiguration.class })
|
||||||
|
public @interface EnableMybatisPlus {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package org.leocoder.heritage.mybatisplus.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.ibatis.reflection.MetaObject;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [新增 或 修改数据给定默认值]
|
||||||
|
* @author Leocoder
|
||||||
|
* 如何使用?如下所示:
|
||||||
|
* @TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||||
|
* @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class CommonMetaObjectHandler implements MetaObjectHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertFill(MetaObject metaObject) {
|
||||||
|
this.setFieldValByName("createTime", LocalDateTime.now(), metaObject);
|
||||||
|
this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateFill(MetaObject metaObject) {
|
||||||
|
log.info("自动填充修改时间...");
|
||||||
|
this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,107 @@
|
|||||||
|
package org.leocoder.heritage.mybatisplus.config;
|
||||||
|
|
||||||
|
import cn.hutool.core.net.NetUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
|
||||||
|
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Leocoder
|
||||||
|
* @description [分页配置和自动填充]
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@EnableTransactionManagement
|
||||||
|
// 多包名使用 例如 org.leocoder.heritage.domain.**.mapper,com.xxx.**.mapper
|
||||||
|
@MapperScan("org.leocoder.**.mapper")
|
||||||
|
public class MyBatisPlusConfiguration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [MybatisPlus拦截器]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
// 分页插件
|
||||||
|
interceptor.addInnerInterceptor(paginationInnerInterceptor());
|
||||||
|
// 乐观锁插件
|
||||||
|
interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor());
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [自动填充创建时间和修改时间]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public CommonMetaObjectHandler commonMetaObjectHandler() {
|
||||||
|
return new CommonMetaObjectHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [乐观锁插件]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public OptimisticLockerInnerInterceptor optimisticLockerInterceptor() {
|
||||||
|
return new OptimisticLockerInnerInterceptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用网卡信息绑定雪花生成器
|
||||||
|
* 防止集群雪花ID重复
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public IdentifierGenerator idGenerator() {
|
||||||
|
return new DefaultIdentifierGenerator(NetUtil.getLocalhost());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [逻辑删除插件-yml进行配置过,这里不进行配置]
|
||||||
|
* @author Leocoder
|
||||||
|
*
|
||||||
|
* @TableLogic(value = "N",delval = "Y")
|
||||||
|
* @TableLogic(value = "0",delval = "1")
|
||||||
|
*/
|
||||||
|
// @Bean
|
||||||
|
// public GlobalConfig globalConfig() {
|
||||||
|
// GlobalConfig globalConfig = new GlobalConfig();
|
||||||
|
// GlobalConfig.DbConfig dbConfig = new GlobalConfig.DbConfig();
|
||||||
|
// dbConfig.setLogicDeleteValue("0");
|
||||||
|
// dbConfig.setLogicNotDeleteValue("1");
|
||||||
|
// globalConfig.setDbConfig(dbConfig);
|
||||||
|
// return globalConfig;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [乐观锁插件]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() {
|
||||||
|
return new OptimisticLockerInnerInterceptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [分页插件,自动识别数据库类型]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
public PaginationInnerInterceptor paginationInnerInterceptor() {
|
||||||
|
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
|
||||||
|
paginationInnerInterceptor.setOptimizeJoin(true);
|
||||||
|
// 设置最大单页限制数量,默认 500 条,-1 不受限制
|
||||||
|
paginationInnerInterceptor.setMaxLimit(500L);
|
||||||
|
paginationInnerInterceptor.setOverflow(false);
|
||||||
|
// 如果配置多个插件,切记分页最后添加
|
||||||
|
// paginationInnerInterceptor.setDbType(DbType.MYSQL);
|
||||||
|
// paginationInnerInterceptor.setDbType(DbType.ORACLE);
|
||||||
|
// 如果有多数据源可以不配具体类型,否则都建议配上具体的DbType[本项目已经使用多数据源,无需进行上方注释的配置]
|
||||||
|
return paginationInnerInterceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
package org.leocoder.heritage.mybatisplus.handler;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* @description [CustomIdGenerator]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
public class CustomIdGenerator implements IdentifierGenerator {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long nextId(Object entity) {
|
||||||
|
// 可以将当前传入的class全类名来作为bizKey,或者提取参数来生成bizKey进行分布式Id调用生成.
|
||||||
|
String bizKey = entity.getClass().getName();
|
||||||
|
// 根据bizKey调用分布式ID生成
|
||||||
|
long id = new Random().nextLong();
|
||||||
|
// 返回生成的id值即可.
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package org.leocoder.heritage.mybatisplus.mapper.system;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.leocoder.heritage.domain.pojo.system.SysDictData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Leocoder
|
||||||
|
* @description [字典数据表-数据库连接层]
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysDictDataMapper extends BaseMapper<SysDictData> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package org.leocoder.heritage.mybatisplus.mapper.system;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.leocoder.heritage.domain.pojo.system.SysDictType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Leocoder
|
||||||
|
* @description [字典类型表-数据库连接层]
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysDictTypeMapper extends BaseMapper<SysDictType> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package org.leocoder.heritage.mybatisplus.mapper.system;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.leocoder.heritage.domain.pojo.system.SysFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [文件资源表-数据库连接层]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysFileMapper extends BaseMapper<SysFile> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package org.leocoder.heritage.mybatisplus.mapper.system;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.leocoder.heritage.domain.pojo.system.SysJob;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Leocoder
|
||||||
|
* @description [定时任务数据访问层]
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysJobMapper extends BaseMapper<SysJob> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package org.leocoder.heritage.mybatisplus.mapper.system;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.leocoder.heritage.domain.pojo.system.SysLoginLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Leocoder
|
||||||
|
* @description [系统访问记录-数据库连接层]
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysLoginLogMapper extends BaseMapper<SysLoginLog> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
package org.leocoder.heritage.mybatisplus.mapper.system;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.leocoder.heritage.domain.model.vo.system.SysLoginUserVo;
|
||||||
|
import org.leocoder.heritage.domain.pojo.system.SysLoginUser;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Leocoder
|
||||||
|
* @description [系统用户-数据库连接层]
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysLoginUserMapper extends BaseMapper<SysLoginUser> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [用户表、部门表左连接查询]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
Page<SysLoginUser> listPage(Page<SysLoginUser> page, @Param("vo") SysLoginUserVo vo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [多条件数据导出]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
List<SysLoginUser> listLoginUser(@Param("vo") SysLoginUserVo vo);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
package org.leocoder.heritage.mybatisplus.mapper.system;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.leocoder.heritage.domain.model.bo.element.CascaderLongBo;
|
||||||
|
import org.leocoder.heritage.domain.model.bo.system.SysMenuBo;
|
||||||
|
import org.leocoder.heritage.domain.model.vo.system.SysMenuVo;
|
||||||
|
import org.leocoder.heritage.domain.pojo.system.SysMenu;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Leocoder
|
||||||
|
* @description [菜单权限表-数据库连接层]
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [查询菜单]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
List<SysMenu> listSysMenu(@Param("vo") SysMenuVo vo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [查询用户拥有的菜单权限-AOP]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
List<Long> listMenuIdData(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [菜单级联下拉框]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
List<CascaderLongBo> cascaderList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [根据用户ID查询当前角色所拥有的菜单列表]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
List<SysMenuBo> listMenuByUserId(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [超级管理员-全部菜单权限]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
List<SysMenuBo> listMenuAdmin();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [根据用户拥有的角色ID查询权限菜单]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
List<SysMenu> listMenuIdsByRoleId(Long roleId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [保存角色和菜单权限之间的关系]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
boolean saveRoleMenu(@Param("roleId") Long roleId, @Param("menuIds") List<Long> menuIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [删除该角色拥有的权限]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
boolean deleteMenuIdsByRoleId(Long roleId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [根据角色编码查询菜单权限-Sa-Token权限]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
List<String> listMenuAuth(String roleCode);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
package org.leocoder.heritage.mybatisplus.mapper.system;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
import org.leocoder.heritage.domain.pojo.system.SysOperLog;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Leocoder
|
||||||
|
* @description [操作日志Mapper接口]
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysOperLogMapper extends BaseMapper<SysOperLog> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [获取操作类型统计]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
@Select("SELECT oper_type as operType, COUNT(*) as count FROM sys_oper_log GROUP BY oper_type")
|
||||||
|
List<Map<String, Object>> getOperTypeStats();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [获取每日操作统计]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
@Select("SELECT DATE(oper_time) as date, COUNT(*) as count FROM sys_oper_log " +
|
||||||
|
"WHERE oper_time >= DATE_SUB(NOW(), INTERVAL 7 DAY) GROUP BY DATE(oper_time) ORDER BY date")
|
||||||
|
List<Map<String, Object>> getDailyStats();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [获取用户操作统计]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
@Select("SELECT oper_man as operMan, COUNT(*) as count FROM sys_oper_log " +
|
||||||
|
"WHERE oper_time >= DATE_SUB(NOW(), INTERVAL 1 DAY) GROUP BY oper_man " +
|
||||||
|
"ORDER BY count DESC LIMIT 10")
|
||||||
|
List<Map<String, Object>> getUserStats();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [获取错误操作统计]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
@Select("SELECT COUNT(*) as errorCount FROM sys_oper_log WHERE oper_status = '1'")
|
||||||
|
Long getErrorCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [获取操作统计信息]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
@Select("SELECT " +
|
||||||
|
"COUNT(*) as totalCount, " +
|
||||||
|
"COUNT(CASE WHEN oper_status = '0' THEN 1 END) as successCount, " +
|
||||||
|
"COUNT(CASE WHEN oper_status = '1' THEN 1 END) as failCount, " +
|
||||||
|
"COUNT(CASE WHEN DATE(oper_time) = CURDATE() THEN 1 END) as todayCount " +
|
||||||
|
"FROM sys_oper_log")
|
||||||
|
Map<String, Object> getOperationStats();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [批量插入操作日志]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
int batchInsert(@Param("list") List<SysOperLog> operLogs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [清理过期日志]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
int cleanExpiredLogs(@Param("expireTime") LocalDateTime expireTime);
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package org.leocoder.heritage.mybatisplus.mapper.system;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.leocoder.heritage.domain.pojo.system.SysPicture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [图库表-数据库连接层]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysPictureMapper extends BaseMapper<SysPicture> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
package org.leocoder.heritage.mybatisplus.mapper.system;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.leocoder.heritage.domain.model.bo.element.SelectLongBo;
|
||||||
|
import org.leocoder.heritage.domain.model.bo.element.TransferLongBo;
|
||||||
|
import org.leocoder.heritage.domain.model.vo.base.BaseVo;
|
||||||
|
import org.leocoder.heritage.domain.model.vo.system.SysRoleVo;
|
||||||
|
import org.leocoder.heritage.domain.pojo.system.SysRole;
|
||||||
|
import org.leocoder.heritage.domain.pojo.system.SysUserRole;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Leocoder
|
||||||
|
* @description [角色信息表-数据库连接层]
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysRoleMapper extends BaseMapper<SysRole> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [多条件分页查询]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
Page<SysRole> listPage(@Param("page") Page<SysRole> page, @Param("vo") SysRoleVo vo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [根据用户ID查询拥有的角色-AOP]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
List<Long> listRoleIdData(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [查询是否拥有超级管理员角色-AOP]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
List<SysUserRole> listSysUserRole(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [查询所有正常角色]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
List<TransferLongBo> listLeftRole();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [查询当前用户拥有角色-穿梭框右侧]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
List<Long> listRightRole(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [删除当前用户拥有的角色]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
void deleteUserRole(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [添加当前用户选中的角色]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
boolean batchAddUserRole(@Param("userId") Long userId, @Param("roleIds") List<Long> roleIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [查询用户拥有正常角色-Sa-Token角色权限]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
List<String> listAuthRoleCode(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [获取角色下拉框]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
List<SelectLongBo> listRoleElSelect(@Param("vo") BaseVo vo);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
<?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="org.leocoder.heritage.mybatisplus.mapper.system.SysDictDataMapper">
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
<?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="org.leocoder.heritage.mybatisplus.mapper.system.SysDictTypeMapper">
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
<?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="org.leocoder.heritage.mybatisplus.mapper.system.SysFileMapper">
|
||||||
|
|
||||||
|
|
||||||
|
</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="org.leocoder.heritage.mybatisplus.mapper.system.SysLoginLogMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@ -0,0 +1,88 @@
|
|||||||
|
<?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="org.leocoder.heritage.mybatisplus.mapper.system.SysLoginUserMapper">
|
||||||
|
|
||||||
|
<!-- 用户表、部门表左连接查询 -->
|
||||||
|
<select id="listPage" resultType="org.leocoder.heritage.domain.pojo.system.SysLoginUser">
|
||||||
|
SELECT
|
||||||
|
t1.user_id AS userId,
|
||||||
|
t1.login_name AS loginName,
|
||||||
|
t1.user_name AS userName,
|
||||||
|
t1.sex AS sex,
|
||||||
|
t1.phone AS phone,
|
||||||
|
t1.email AS email,
|
||||||
|
t1.avatar AS avatar,
|
||||||
|
t1.user_type AS userType,
|
||||||
|
t1.user_status AS userStatus,
|
||||||
|
t1.login_time AS loginTime,
|
||||||
|
t1.remark AS remark
|
||||||
|
FROM
|
||||||
|
sys_login_user AS t1
|
||||||
|
<where>
|
||||||
|
<if test="vo.loginName != null and vo.loginName != ''">
|
||||||
|
<bind name="loginNameLike" value="'%'+ vo.loginName +'%'"/>
|
||||||
|
AND t1.login_name LIKE #{loginNameLike}
|
||||||
|
</if>
|
||||||
|
<if test="vo.userName != null and vo.userName != ''">
|
||||||
|
<bind name="userNameLike" value="'%'+ vo.userName +'%'"/>
|
||||||
|
AND t1.user_name LIKE #{userNameLike}
|
||||||
|
</if>
|
||||||
|
<if test="vo.phone != null and vo.phone != ''">
|
||||||
|
<bind name="phoneLike" value="'%'+ vo.phone +'%'"/>
|
||||||
|
AND t1.phone LIKE #{phoneLike}
|
||||||
|
</if>
|
||||||
|
<if test="vo.beginTime != null and vo.beginTime != ''">
|
||||||
|
AND t1.login_time >= #{vo.beginTime}
|
||||||
|
</if>
|
||||||
|
<if test="vo.endTime != null and vo.endTime != ''">
|
||||||
|
AND t1.login_time <= #{vo.endTime}
|
||||||
|
</if>
|
||||||
|
<if test="vo.userStatus != null and vo.userStatus != ''">
|
||||||
|
AND t1.user_status = #{vo.userStatus}
|
||||||
|
</if>
|
||||||
|
AND
|
||||||
|
t1.user_id != 1
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 多条件数据导出 -->
|
||||||
|
<select id="listLoginUser" resultType="org.leocoder.heritage.domain.pojo.system.SysLoginUser">
|
||||||
|
SELECT
|
||||||
|
t1.user_id AS userId,
|
||||||
|
t1.login_name AS loginName,
|
||||||
|
t1.user_name AS userName,
|
||||||
|
t1.sex AS sex,
|
||||||
|
t1.phone AS phone,
|
||||||
|
t1.email AS email,
|
||||||
|
t1.avatar AS avatar,
|
||||||
|
t1.user_type AS userType,
|
||||||
|
t1.user_status AS userStatus,
|
||||||
|
t1.login_time AS loginTime,
|
||||||
|
t1.remark AS remark
|
||||||
|
FROM
|
||||||
|
sys_login_user AS t1
|
||||||
|
<where>
|
||||||
|
<if test="vo.loginName != null and vo.loginName != ''">
|
||||||
|
<bind name="loginNameLike" value="'%'+ vo.loginName +'%'"/>
|
||||||
|
AND t1.login_name LIKE #{loginNameLike}
|
||||||
|
</if>
|
||||||
|
<if test="vo.userName != null and vo.userName != ''">
|
||||||
|
<bind name="userNameLike" value="'%'+ vo.userName +'%'"/>
|
||||||
|
AND t1.user_name LIKE #{userNameLike}
|
||||||
|
</if>
|
||||||
|
<if test="vo.phone != null and vo.phone != ''">
|
||||||
|
<bind name="phoneLike" value="'%'+ vo.phone +'%'"/>
|
||||||
|
AND t1.phone LIKE #{phoneLike}
|
||||||
|
</if>
|
||||||
|
<if test="vo.beginTime != null and vo.beginTime != ''">
|
||||||
|
AND t1.login_time >= #{vo.beginTime}
|
||||||
|
</if>
|
||||||
|
<if test="vo.endTime != null and vo.endTime != ''">
|
||||||
|
AND t1.login_time <= #{vo.endTime}
|
||||||
|
</if>
|
||||||
|
<if test="vo.userStatus != null and vo.userStatus != ''">
|
||||||
|
AND t1.user_status = #{vo.userStatus}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
@ -0,0 +1,218 @@
|
|||||||
|
<?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="org.leocoder.heritage.mybatisplus.mapper.system.SysMenuMapper">
|
||||||
|
|
||||||
|
<!-- 查询菜单 -->
|
||||||
|
<select id="listSysMenu" resultType="org.leocoder.heritage.domain.pojo.system.SysMenu">
|
||||||
|
SELECT
|
||||||
|
t1.menu_id AS menuId,
|
||||||
|
t1.menu_name AS menuName,
|
||||||
|
t1.en_name AS enName,
|
||||||
|
t1.parent_id AS parentId,
|
||||||
|
t1.menu_type AS menuType,
|
||||||
|
t1.path AS path,
|
||||||
|
t1.`name`AS name,
|
||||||
|
t1.component AS component,
|
||||||
|
t1.icon AS icon,
|
||||||
|
t1.auth AS auth,
|
||||||
|
t1.menu_status AS menuStatus,
|
||||||
|
t1.is_spread AS isSpread,
|
||||||
|
t1.is_hide AS isHide,
|
||||||
|
t1.sorted AS sorted,
|
||||||
|
t1.create_by AS createBy,
|
||||||
|
t1.create_time AS createTime
|
||||||
|
FROM
|
||||||
|
sys_menu AS t1
|
||||||
|
<where>
|
||||||
|
<if test="vo.menuName != null and vo.menuName != ''">
|
||||||
|
<bind name="menuNameLike" value="'%'+ vo.menuName +'%'"/>
|
||||||
|
AND t1.menu_name LIKE #{menuNameLike}
|
||||||
|
</if>
|
||||||
|
<if test="vo.auth != null and vo.auth != ''">
|
||||||
|
<bind name="authLike" value="'%'+ vo.auth +'%'"/>
|
||||||
|
AND t1.auth LIKE #{authLike}
|
||||||
|
</if>
|
||||||
|
<if test="vo.menuStatus != null and vo.menuStatus != ''">
|
||||||
|
AND t1.menu_status = #{vo.menuStatus}
|
||||||
|
</if>
|
||||||
|
<if test="vo.params.menuDataScope != null and vo.params.menuDataScope != ''">
|
||||||
|
${vo.params.menuDataScope}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
ORDER BY
|
||||||
|
t1.sorted
|
||||||
|
ASC
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 查询用户拥有的菜单权限-AOP -->
|
||||||
|
<select id="listMenuIdData" resultType="java.lang.Long">
|
||||||
|
SELECT
|
||||||
|
menu_id AS menuId
|
||||||
|
FROM
|
||||||
|
sys_menu t1
|
||||||
|
WHERE
|
||||||
|
t1.menu_status = '0'
|
||||||
|
AND
|
||||||
|
t1.menu_id
|
||||||
|
IN (
|
||||||
|
SELECT DISTINCT
|
||||||
|
( t2.menu_id )
|
||||||
|
FROM
|
||||||
|
sys_role_menu t2
|
||||||
|
LEFT JOIN
|
||||||
|
sys_user_role t3
|
||||||
|
ON
|
||||||
|
t2.role_id = t3.role_id
|
||||||
|
WHERE
|
||||||
|
t3.user_id = #{userId}
|
||||||
|
AND
|
||||||
|
t3.role_id
|
||||||
|
IN
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
role_id
|
||||||
|
FROM
|
||||||
|
sys_role
|
||||||
|
WHERE
|
||||||
|
role_status = '0'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 菜单级联下拉框 -->
|
||||||
|
<select id="cascaderList" resultType="org.leocoder.heritage.domain.model.bo.element.CascaderLongBo">
|
||||||
|
SELECT
|
||||||
|
menu_name AS label,
|
||||||
|
menu_id AS value,
|
||||||
|
parent_id AS parentId
|
||||||
|
FROM
|
||||||
|
sys_menu
|
||||||
|
<where>
|
||||||
|
menu_status = 0
|
||||||
|
AND
|
||||||
|
menu_type < 3
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据用户ID查询当前角色所拥有的菜单列表 -->
|
||||||
|
<select id="listMenuByUserId" resultType="org.leocoder.heritage.domain.model.bo.system.SysMenuBo">
|
||||||
|
SELECT
|
||||||
|
DISTINCT(t1.menu_id) AS menuId,
|
||||||
|
t1.menu_name AS menuName,
|
||||||
|
t1.en_name AS enName,
|
||||||
|
t1.parent_id AS parentId,
|
||||||
|
t1.menu_type AS menuType,
|
||||||
|
t1.name AS name,
|
||||||
|
t1.path AS path,
|
||||||
|
t1.component AS component,
|
||||||
|
t1.icon AS icon,
|
||||||
|
t1.is_hide AS isHide,
|
||||||
|
t1.is_link AS isLink,
|
||||||
|
t1.is_keep_alive AS isKeepAlive,
|
||||||
|
t1.is_full AS isFull,
|
||||||
|
t1.is_affix AS isAffix,
|
||||||
|
t1.sorted AS sorted,
|
||||||
|
t1.active_menu AS activeMenu
|
||||||
|
FROM
|
||||||
|
sys_menu AS t1
|
||||||
|
INNER JOIN sys_role_menu AS t2 ON t1.menu_id = t2.menu_id
|
||||||
|
INNER JOIN sys_role AS t3 ON t3.role_id = t2.role_id
|
||||||
|
INNER JOIN sys_user_role AS t4 ON t4.role_id = t3.role_id
|
||||||
|
WHERE
|
||||||
|
t1.menu_status = '0'
|
||||||
|
AND
|
||||||
|
t3.role_status = '0'
|
||||||
|
AND
|
||||||
|
t1.menu_type IN ( '1', '2' )
|
||||||
|
AND
|
||||||
|
t4.user_id = #{userId}
|
||||||
|
ORDER BY
|
||||||
|
t1.sorted ASC
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 超级管理员-全部菜单权限 -->
|
||||||
|
<select id="listMenuAdmin" resultType="org.leocoder.heritage.domain.model.bo.system.SysMenuBo">
|
||||||
|
SELECT
|
||||||
|
menu_id AS menuId,
|
||||||
|
menu_name AS menuName,
|
||||||
|
en_name AS enName,
|
||||||
|
parent_id AS parentId,
|
||||||
|
menu_type AS menuType,
|
||||||
|
name AS name,
|
||||||
|
path AS path,
|
||||||
|
component AS component,
|
||||||
|
icon AS icon,
|
||||||
|
is_hide AS isHide,
|
||||||
|
is_link AS isLink,
|
||||||
|
is_keep_alive AS isKeepAlive,
|
||||||
|
is_full AS isFull,
|
||||||
|
is_affix AS isAffix,
|
||||||
|
sorted AS sorted,
|
||||||
|
active_menu AS activeMenu
|
||||||
|
FROM
|
||||||
|
sys_menu
|
||||||
|
WHERE
|
||||||
|
menu_status = '0'
|
||||||
|
AND
|
||||||
|
menu_type IN ( '1', '2' )
|
||||||
|
ORDER BY
|
||||||
|
sorted ASC
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据用户拥有的角色ID查询权限菜单 -->
|
||||||
|
<select id="listMenuIdsByRoleId" resultType="org.leocoder.heritage.domain.pojo.system.SysMenu">
|
||||||
|
SELECT
|
||||||
|
t1.menu_id AS menuId,
|
||||||
|
t1.parent_id AS parentId
|
||||||
|
FROM
|
||||||
|
sys_menu t1
|
||||||
|
INNER JOIN
|
||||||
|
sys_role_menu t2
|
||||||
|
ON
|
||||||
|
t1.menu_id = t2.menu_id
|
||||||
|
WHERE
|
||||||
|
t1.menu_status = '0'
|
||||||
|
AND
|
||||||
|
t2.role_id = #{roleId}
|
||||||
|
ORDER BY
|
||||||
|
t1.sorted ASC
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据角色编码查询菜单权限-Sa-Token权限 -->
|
||||||
|
<select id="listMenuAuth" resultType="java.lang.String">
|
||||||
|
SELECT
|
||||||
|
DISTINCT(t1.auth) AS auth
|
||||||
|
FROM
|
||||||
|
sys_menu AS t1
|
||||||
|
INNER JOIN sys_role_menu AS t2 ON t1.menu_id = t2.menu_id
|
||||||
|
INNER JOIN sys_role AS t3 ON t3.role_id = t2.role_id
|
||||||
|
INNER JOIN sys_user_role AS t4 ON t4.role_id = t3.role_id
|
||||||
|
WHERE
|
||||||
|
t1.menu_status = '0'
|
||||||
|
AND
|
||||||
|
t1.auth IS NOT NULL
|
||||||
|
AND
|
||||||
|
t3.role_status = '0'
|
||||||
|
AND
|
||||||
|
t3.role_code = #{roleCode}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 删除该角色拥有的权限 -->
|
||||||
|
<delete id="deleteMenuIdsByRoleId">
|
||||||
|
DELETE FROM
|
||||||
|
sys_role_menu
|
||||||
|
WHERE
|
||||||
|
role_id = #{roleId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<!-- 保存角色和菜单权限之间的关系 -->
|
||||||
|
<insert id="saveRoleMenu">
|
||||||
|
INSERT INTO
|
||||||
|
sys_role_menu (role_id, menu_id)
|
||||||
|
VALUES
|
||||||
|
<foreach collection="menuIds" item="menuId" separator=",">
|
||||||
|
(#{roleId}, #{menuId})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
<?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="org.leocoder.heritage.mybatisplus.mapper.system.SysOperLogMapper">
|
||||||
|
|
||||||
|
<!-- 基础字段映射 -->
|
||||||
|
<resultMap id="BaseResultMap" type="org.leocoder.heritage.domain.pojo.system.SysOperLog">
|
||||||
|
<id column="oper_id" property="operId" />
|
||||||
|
<result column="oper_name" property="operName" />
|
||||||
|
<result column="oper_type" property="operType" />
|
||||||
|
<result column="method_name" property="methodName" />
|
||||||
|
<result column="request_method" property="requestMethod" />
|
||||||
|
<result column="system_type" property="systemType" />
|
||||||
|
<result column="oper_man" property="operMan" />
|
||||||
|
<result column="oper_url" property="operUrl" />
|
||||||
|
<result column="oper_ip" property="operIp" />
|
||||||
|
<result column="oper_location" property="operLocation" />
|
||||||
|
<result column="oper_param" property="operParam" />
|
||||||
|
<result column="json_result" property="jsonResult" />
|
||||||
|
<result column="oper_status" property="operStatus" />
|
||||||
|
<result column="error_msg" property="errorMsg" />
|
||||||
|
<result column="oper_time" property="operTime" />
|
||||||
|
<result column="cost_time" property="costTime" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!-- 批量插入操作日志 -->
|
||||||
|
<insert id="batchInsert" parameterType="java.util.List">
|
||||||
|
INSERT INTO sys_oper_log (
|
||||||
|
oper_name, oper_type, method_name, request_method, system_type,
|
||||||
|
oper_man, oper_url, oper_ip, oper_location, oper_param,
|
||||||
|
json_result, oper_status, error_msg, oper_time, cost_time
|
||||||
|
) VALUES
|
||||||
|
<foreach collection="list" item="item" separator=",">
|
||||||
|
(
|
||||||
|
#{item.operName}, #{item.operType}, #{item.methodName},
|
||||||
|
#{item.requestMethod}, #{item.systemType}, #{item.operMan},
|
||||||
|
#{item.operUrl}, #{item.operIp}, #{item.operLocation},
|
||||||
|
#{item.operParam}, #{item.jsonResult}, #{item.operStatus},
|
||||||
|
#{item.errorMsg}, #{item.operTime}, #{item.costTime}
|
||||||
|
)
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!-- 清理过期日志 -->
|
||||||
|
<delete id="cleanExpiredLogs" parameterType="java.time.LocalDateTime">
|
||||||
|
DELETE FROM sys_oper_log WHERE oper_time < #{expireTime}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
<?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="org.leocoder.heritage.mybatisplus.mapper.system.SysPictureMapper">
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@ -0,0 +1,163 @@
|
|||||||
|
<?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="org.leocoder.heritage.mybatisplus.mapper.system.SysRoleMapper">
|
||||||
|
|
||||||
|
<!-- 多条件分页查询 -->
|
||||||
|
<select id="listPage" resultType="org.leocoder.heritage.domain.pojo.system.SysRole">
|
||||||
|
SELECT
|
||||||
|
t1.role_id AS roleId,
|
||||||
|
t1.role_name AS roleName,
|
||||||
|
t1.role_code AS roleCode,
|
||||||
|
t1.role_status AS roleStatus,
|
||||||
|
t1.sorted AS sorted,
|
||||||
|
t1.remark AS remark,
|
||||||
|
t1.create_by AS createBy,
|
||||||
|
t1.create_time AS createTime,
|
||||||
|
t1.update_by AS updateBy,
|
||||||
|
t1.update_time AS updateTime
|
||||||
|
FROM
|
||||||
|
sys_role AS t1
|
||||||
|
<where>
|
||||||
|
<if test="vo.roleName != null and vo.roleName != ''">
|
||||||
|
<bind name="roleNameLike" value="'%'+ vo.roleName +'%'"/>
|
||||||
|
AND t1.role_name LIKE #{roleNameLike}
|
||||||
|
</if>
|
||||||
|
<if test="vo.roleCode != null and vo.roleCode != ''">
|
||||||
|
<bind name="roleCodeLike" value="'%'+ vo.roleCode +'%'"/>
|
||||||
|
AND t1.role_code LIKE #{roleCodeLike}
|
||||||
|
</if>
|
||||||
|
<if test="vo.roleStatus != null and vo.roleStatus != ''">
|
||||||
|
AND t1.role_status = #{vo.roleStatus}
|
||||||
|
</if>
|
||||||
|
<if test="vo.beginTime != null and vo.beginTime != ''">
|
||||||
|
AND t1.create_time >= #{vo.beginTime}
|
||||||
|
</if>
|
||||||
|
<if test="vo.endTime != null and vo.endTime != ''">
|
||||||
|
AND t1.create_time <![CDATA[<=]]> #{vo.endTime}
|
||||||
|
</if>
|
||||||
|
<if test="vo.params.roleDataScope != null and vo.params.roleDataScope != ''">
|
||||||
|
${vo.params.roleDataScope}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据用户ID查询拥有的角色-AOP -->
|
||||||
|
<select id="listRoleIdData" resultType="java.lang.Long">
|
||||||
|
SELECT
|
||||||
|
role_id AS roleId
|
||||||
|
FROM
|
||||||
|
sys_role t1
|
||||||
|
WHERE
|
||||||
|
t1.role_status = '0'
|
||||||
|
AND
|
||||||
|
t1.role_id
|
||||||
|
IN (
|
||||||
|
SELECT
|
||||||
|
DISTINCT( t2.role_id )
|
||||||
|
FROM
|
||||||
|
sys_user_role t2
|
||||||
|
WHERE
|
||||||
|
t2.user_id = #{userId}
|
||||||
|
)
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据用户ID查询角色ID -->
|
||||||
|
<select id="listSysUserRole" resultType="org.leocoder.heritage.domain.pojo.system.SysUserRole">
|
||||||
|
SELECT
|
||||||
|
user_id AS userId,
|
||||||
|
role_id AS roleId
|
||||||
|
FROM
|
||||||
|
sys_user_role
|
||||||
|
WHERE
|
||||||
|
user_id = #{userId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 查询所有正常角色 -->
|
||||||
|
<select id="listLeftRole" resultType="org.leocoder.heritage.domain.model.bo.element.TransferLongBo">
|
||||||
|
SELECT
|
||||||
|
role_name AS label,
|
||||||
|
role_id AS value
|
||||||
|
FROM
|
||||||
|
sys_role
|
||||||
|
WHERE
|
||||||
|
role_status = '0'
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 查询当前用户拥有角色-穿梭框右侧 -->
|
||||||
|
<select id="listRightRole" resultType="java.lang.Long">
|
||||||
|
SELECT
|
||||||
|
role_id AS roleId
|
||||||
|
FROM
|
||||||
|
sys_role
|
||||||
|
WHERE
|
||||||
|
role_status = '0'
|
||||||
|
AND
|
||||||
|
role_id
|
||||||
|
IN (
|
||||||
|
SELECT
|
||||||
|
DISTINCT(role_id) AS roleId
|
||||||
|
FROM
|
||||||
|
sys_user_role
|
||||||
|
WHERE
|
||||||
|
user_id = #{userId}
|
||||||
|
)
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 查询用户拥有正常角色-Sa-Token角色权限 -->
|
||||||
|
<select id="listAuthRoleCode" resultType="java.lang.String">
|
||||||
|
SELECT DISTINCT
|
||||||
|
role_code AS roleCode
|
||||||
|
FROM
|
||||||
|
sys_role
|
||||||
|
WHERE
|
||||||
|
role_status = '0'
|
||||||
|
AND
|
||||||
|
role_id
|
||||||
|
IN (
|
||||||
|
SELECT
|
||||||
|
DISTINCT(role_id) AS roleId
|
||||||
|
FROM
|
||||||
|
sys_user_role
|
||||||
|
WHERE
|
||||||
|
user_id = #{userId}
|
||||||
|
)
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 删除当前用户拥有的角色 -->
|
||||||
|
<delete id="deleteUserRole">
|
||||||
|
DELETE FROM
|
||||||
|
sys_user_role
|
||||||
|
WHERE
|
||||||
|
user_id = #{userId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<!-- 添加当前用户选中的角色 -->
|
||||||
|
<insert id="batchAddUserRole">
|
||||||
|
INSERT INTO
|
||||||
|
sys_user_role
|
||||||
|
(
|
||||||
|
user_id,
|
||||||
|
role_id
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
<foreach collection="roleIds" item="roleId" separator=",">
|
||||||
|
(#{userId},#{roleId})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!-- 获取角色下拉框 -->
|
||||||
|
<select id="listRoleElSelect" resultType="org.leocoder.heritage.domain.model.bo.element.SelectLongBo">
|
||||||
|
SELECT
|
||||||
|
t1.role_name AS label,
|
||||||
|
t1.role_id AS value
|
||||||
|
FROM
|
||||||
|
sys_role AS t1
|
||||||
|
<where>
|
||||||
|
t1.role_status = '0'
|
||||||
|
<if test="vo.params.roleDataScope != null and vo.params.roleDataScope != ''">
|
||||||
|
${vo.params.roleDataScope}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in New Issue
Block a user