Commit 86f108c2cc9c5f1bf7a8f13552545f2ad3b14c76

Authored by shiyang
1 parent 5df2699e73
Exists in master

update

Showing 7 changed files with 270 additions and 0 deletions

talkonlineweb/src/main/java/com/lyms/talkonlineweb/config/DataScopeInterceptor.java View file @ 86f108c
  1 +package com.lyms.talkonlineweb.config;
  2 +
  3 +import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
  4 +import com.baomidou.mybatisplus.extension.handlers.AbstractSqlParserHandler;
  5 +import lombok.AllArgsConstructor;
  6 +import lombok.extern.slf4j.Slf4j;
  7 +import org.apache.ibatis.executor.statement.StatementHandler;
  8 +import org.apache.ibatis.mapping.BoundSql;
  9 +import org.apache.ibatis.mapping.MappedStatement;
  10 +import org.apache.ibatis.mapping.SqlCommandType;
  11 +import org.apache.ibatis.plugin.*;
  12 +import org.apache.ibatis.reflection.MetaObject;
  13 +import org.apache.ibatis.reflection.SystemMetaObject;
  14 +import org.springframework.stereotype.Component;
  15 +
  16 +import javax.sql.DataSource;
  17 +import java.sql.Connection;
  18 +import java.util.Properties;
  19 +
  20 +//mybatis 自定义拦截器
  21 +@Slf4j
  22 +@AllArgsConstructor
  23 +@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
  24 +@Component
  25 +public class DataScopeInterceptor extends AbstractSqlParserHandler implements Interceptor {
  26 + private DataSource dataSource;
  27 +
  28 + @Override
  29 + public Object intercept(Invocation invocation) throws Throwable {
  30 + StatementHandler statementHandler = PluginUtils.realTarget(invocation.getTarget());
  31 + MetaObject metaObject = SystemMetaObject.forObject(statementHandler);
  32 + this.sqlParser(metaObject);
  33 + // 先判断是不是SELECT操作 不是直接过滤
  34 + MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
  35 + if (!SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) {
  36 + return invocation.proceed();
  37 + }
  38 + if (!SqlCommandType.INSERT.equals(mappedStatement.getSqlCommandType())) {
  39 + System.out.println("新增。。。。。。。。。。。。。。。。。。。。。。。。");
  40 + return invocation.proceed();
  41 + }
  42 + if (!SqlCommandType.UPDATE.equals(mappedStatement.getSqlCommandType())) {
  43 + System.out.println("修改。。。。。。。。。。。。。。。。。。。。。。。。");
  44 + return invocation.proceed();
  45 + }
  46 + if (!SqlCommandType.DELETE.equals(mappedStatement.getSqlCommandType())) {
  47 + System.out.println("删除。。。。。。。。。。。。。。。。。。。。。。。。");
  48 + return invocation.proceed();
  49 + }
  50 +// BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql");
  51 +// // 执行的SQL语句
  52 +// String originalSql = boundSql.getSql();
  53 +// // SQL语句的参数
  54 +// Object parameterObject = boundSql.getParameterObject();
  55 +//
  56 +// originalSql = "select * from (" + originalSql + ") temp_data_scope where temp_data_scope." + 1 + " in (" + 2 + ")";
  57 +// metaObject.setValue("delegate.boundSql.sql", originalSql);
  58 + return invocation.proceed();
  59 + }
  60 +
  61 + /**
  62 + * 生成拦截对象的代理
  63 + *
  64 + * @param target 目标对象
  65 + * @return 代理对象
  66 + */
  67 + @Override
  68 + public Object plugin(Object target) {
  69 + if (target instanceof StatementHandler) {
  70 + return Plugin.wrap(target, this);
  71 + }
  72 + return target;
  73 + }
  74 +
  75 + /**
  76 + * mybatis配置的属性
  77 + *
  78 + * @param properties mybatis配置的属性
  79 + */
  80 + @Override
  81 + public void setProperties(Properties properties) {
  82 +
  83 + }
  84 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/config/MyBatisConfigs.java View file @ 86f108c
... ... @@ -3,9 +3,12 @@
3 3 import com.baomidou.mybatisplus.annotation.DbType;
4 4 import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
5 5 import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
  6 +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
6 7 import org.springframework.context.annotation.Bean;
7 8 import org.springframework.context.annotation.Configuration;
8 9  
  10 +import javax.sql.DataSource;
  11 +
9 12 @Configuration
10 13 public class MyBatisConfigs {
11 14  
... ... @@ -14,6 +17,17 @@
14 17 MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
15 18 interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
16 19 return interceptor;
  20 + }
  21 +
  22 + /**
  23 + * 数据权限插件
  24 + *用于mybatis自定义拦截器
  25 + * @return DataScopeInterceptor
  26 + */
  27 + @Bean
  28 + @ConditionalOnMissingBean
  29 + public DataScopeInterceptor dataScopeInterceptor(DataSource dataSource) {
  30 + return new DataScopeInterceptor(dataSource);
17 31 }
18 32 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsLogsCrud.java View file @ 86f108c
  1 +package com.lyms.talkonlineweb.domain;
  2 +
  3 +import com.baomidou.mybatisplus.annotation.IdType;
  4 +import com.baomidou.mybatisplus.annotation.TableField;
  5 +import com.baomidou.mybatisplus.annotation.TableId;
  6 +import com.baomidou.mybatisplus.annotation.TableName;
  7 +import java.io.Serializable;
  8 +import java.util.Date;
  9 +import lombok.Data;
  10 +
  11 +/**
  12 + *
  13 + * @TableName lyms_logs_crud
  14 + */
  15 +@TableName(value ="lyms_logs_crud")
  16 +@Data
  17 +public class LymsLogsCrud implements Serializable {
  18 + /**
  19 + *
  20 + */
  21 + @TableId(value = "id", type = IdType.AUTO)
  22 + private Integer id;
  23 +
  24 + /**
  25 + * 操作用户id
  26 + */
  27 + @TableField(value = "uid")
  28 + private Integer uid;
  29 +
  30 + /**
  31 + * 1:增,2:删,3:改
  32 + */
  33 + @TableField(value = "crud")
  34 + private Integer crud;
  35 +
  36 + /**
  37 + * 医院id
  38 + */
  39 + @TableField(value = "hoid")
  40 + private Integer hoid;
  41 +
  42 + /**
  43 + * 科室id
  44 + */
  45 + @TableField(value = "hdid")
  46 + private Integer hdid;
  47 +
  48 + /**
  49 + * 操作时间
  50 + */
  51 + @TableField(value = "creatdata")
  52 + private Date creatdata;
  53 +
  54 + @TableField(exist = false)
  55 + private static final long serialVersionUID = 1L;
  56 +
  57 + @Override
  58 + public boolean equals(Object that) {
  59 + if (this == that) {
  60 + return true;
  61 + }
  62 + if (that == null) {
  63 + return false;
  64 + }
  65 + if (getClass() != that.getClass()) {
  66 + return false;
  67 + }
  68 + LymsLogsCrud other = (LymsLogsCrud) that;
  69 + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
  70 + && (this.getUid() == null ? other.getUid() == null : this.getUid().equals(other.getUid()))
  71 + && (this.getCrud() == null ? other.getCrud() == null : this.getCrud().equals(other.getCrud()))
  72 + && (this.getHoid() == null ? other.getHoid() == null : this.getHoid().equals(other.getHoid()))
  73 + && (this.getHdid() == null ? other.getHdid() == null : this.getHdid().equals(other.getHdid()))
  74 + && (this.getCreatdata() == null ? other.getCreatdata() == null : this.getCreatdata().equals(other.getCreatdata()));
  75 + }
  76 +
  77 + @Override
  78 + public int hashCode() {
  79 + final int prime = 31;
  80 + int result = 1;
  81 + result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
  82 + result = prime * result + ((getUid() == null) ? 0 : getUid().hashCode());
  83 + result = prime * result + ((getCrud() == null) ? 0 : getCrud().hashCode());
  84 + result = prime * result + ((getHoid() == null) ? 0 : getHoid().hashCode());
  85 + result = prime * result + ((getHdid() == null) ? 0 : getHdid().hashCode());
  86 + result = prime * result + ((getCreatdata() == null) ? 0 : getCreatdata().hashCode());
  87 + return result;
  88 + }
  89 +
  90 + @Override
  91 + public String toString() {
  92 + StringBuilder sb = new StringBuilder();
  93 + sb.append(getClass().getSimpleName());
  94 + sb.append(" [");
  95 + sb.append("Hash = ").append(hashCode());
  96 + sb.append(", id=").append(id);
  97 + sb.append(", uid=").append(uid);
  98 + sb.append(", crud=").append(crud);
  99 + sb.append(", hoid=").append(hoid);
  100 + sb.append(", hdid=").append(hdid);
  101 + sb.append(", creatdata=").append(creatdata);
  102 + sb.append(", serialVersionUID=").append(serialVersionUID);
  103 + sb.append("]");
  104 + return sb.toString();
  105 + }
  106 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsLogsCrudMapper.java View file @ 86f108c
  1 +package com.lyms.talkonlineweb.mapper;
  2 +
  3 +import com.lyms.talkonlineweb.domain.LymsLogsCrud;
  4 +import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  5 +
  6 +/**
  7 + * @Entity com.lyms.talkonlineweb.domain.LymsLogsCrud
  8 + */
  9 +public interface LymsLogsCrudMapper extends BaseMapper<LymsLogsCrud> {
  10 +
  11 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsLogsCrudService.java View file @ 86f108c
  1 +package com.lyms.talkonlineweb.service;
  2 +
  3 +import com.lyms.talkonlineweb.domain.LymsLogsCrud;
  4 +import com.baomidou.mybatisplus.extension.service.IService;
  5 +
  6 +/**
  7 + *
  8 + */
  9 +public interface LymsLogsCrudService extends IService<LymsLogsCrud> {
  10 +
  11 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsLogsCrudServiceImpl.java View file @ 86f108c
  1 +package com.lyms.talkonlineweb.service.impl;
  2 +
  3 +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4 +import com.lyms.talkonlineweb.domain.LymsLogsCrud;
  5 +import com.lyms.talkonlineweb.service.LymsLogsCrudService;
  6 +import com.lyms.talkonlineweb.mapper.LymsLogsCrudMapper;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +/**
  10 + *
  11 + */
  12 +@Service
  13 +public class LymsLogsCrudServiceImpl extends ServiceImpl<LymsLogsCrudMapper, LymsLogsCrud>
  14 + implements LymsLogsCrudService{
  15 +
  16 +}
talkonlineweb/src/main/resources/mapper/LymsLogsCrudMapper.xml View file @ 86f108c
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper
  3 + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5 +<mapper namespace="com.lyms.talkonlineweb.mapper.LymsLogsCrudMapper">
  6 +
  7 + <resultMap id="BaseResultMap" type="com.lyms.talkonlineweb.domain.LymsLogsCrud">
  8 + <id property="id" column="id" jdbcType="INTEGER"/>
  9 + <result property="uid" column="uid" jdbcType="INTEGER"/>
  10 + <result property="crud" column="crud" jdbcType="INTEGER"/>
  11 + <result property="hoid" column="hoid" jdbcType="INTEGER"/>
  12 + <result property="hdid" column="hdid" jdbcType="INTEGER"/>
  13 + <result property="creatdata" column="creatdata" jdbcType="TIMESTAMP"/>
  14 + </resultMap>
  15 +
  16 + <sql id="Base_Column_List">
  17 + id,uid,crud,
  18 + hoid,hdid,creatdata
  19 + </sql>
  20 +</mapper>