diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/config/DataScopeInterceptor.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/config/DataScopeInterceptor.java new file mode 100644 index 0000000..1496856 --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/config/DataScopeInterceptor.java @@ -0,0 +1,84 @@ +package com.lyms.talkonlineweb.config; + +import com.baomidou.mybatisplus.core.toolkit.PluginUtils; +import com.baomidou.mybatisplus.extension.handlers.AbstractSqlParserHandler; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.executor.statement.StatementHandler; +import org.apache.ibatis.mapping.BoundSql; +import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.mapping.SqlCommandType; +import org.apache.ibatis.plugin.*; +import org.apache.ibatis.reflection.MetaObject; +import org.apache.ibatis.reflection.SystemMetaObject; +import org.springframework.stereotype.Component; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.util.Properties; + +//mybatis 自定义拦截器 +@Slf4j +@AllArgsConstructor +@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})}) +@Component +public class DataScopeInterceptor extends AbstractSqlParserHandler implements Interceptor { + private DataSource dataSource; + + @Override + public Object intercept(Invocation invocation) throws Throwable { + StatementHandler statementHandler = PluginUtils.realTarget(invocation.getTarget()); + MetaObject metaObject = SystemMetaObject.forObject(statementHandler); + this.sqlParser(metaObject); + // 先判断是不是SELECT操作 不是直接过滤 + MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement"); + if (!SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) { + return invocation.proceed(); + } + if (!SqlCommandType.INSERT.equals(mappedStatement.getSqlCommandType())) { + System.out.println("新增。。。。。。。。。。。。。。。。。。。。。。。。"); + return invocation.proceed(); + } + if (!SqlCommandType.UPDATE.equals(mappedStatement.getSqlCommandType())) { + System.out.println("修改。。。。。。。。。。。。。。。。。。。。。。。。"); + return invocation.proceed(); + } + if (!SqlCommandType.DELETE.equals(mappedStatement.getSqlCommandType())) { + System.out.println("删除。。。。。。。。。。。。。。。。。。。。。。。。"); + return invocation.proceed(); + } +// BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql"); +// // 执行的SQL语句 +// String originalSql = boundSql.getSql(); +// // SQL语句的参数 +// Object parameterObject = boundSql.getParameterObject(); +// +// originalSql = "select * from (" + originalSql + ") temp_data_scope where temp_data_scope." + 1 + " in (" + 2 + ")"; +// metaObject.setValue("delegate.boundSql.sql", originalSql); + return invocation.proceed(); + } + + /** + * 生成拦截对象的代理 + * + * @param target 目标对象 + * @return 代理对象 + */ + @Override + public Object plugin(Object target) { + if (target instanceof StatementHandler) { + return Plugin.wrap(target, this); + } + return target; + } + + /** + * mybatis配置的属性 + * + * @param properties mybatis配置的属性 + */ + @Override + public void setProperties(Properties properties) { + + } +} \ No newline at end of file diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/config/MyBatisConfigs.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/config/MyBatisConfigs.java index 9fbb89a..7acfa27 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/config/MyBatisConfigs.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/config/MyBatisConfigs.java @@ -3,9 +3,12 @@ package com.lyms.talkonlineweb.config; import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import javax.sql.DataSource; + @Configuration public class MyBatisConfigs { @@ -15,4 +18,15 @@ public class MyBatisConfigs { interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); return interceptor; } + + /** + * 数据权限插件 + *用于mybatis自定义拦截器 + * @return DataScopeInterceptor + */ + @Bean + @ConditionalOnMissingBean + public DataScopeInterceptor dataScopeInterceptor(DataSource dataSource) { + return new DataScopeInterceptor(dataSource); + } } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsLogsCrud.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsLogsCrud.java new file mode 100644 index 0000000..feac92d --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsLogsCrud.java @@ -0,0 +1,106 @@ +package com.lyms.talkonlineweb.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + +/** + * + * @TableName lyms_logs_crud + */ +@TableName(value ="lyms_logs_crud") +@Data +public class LymsLogsCrud implements Serializable { + /** + * + */ + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + /** + * 操作用户id + */ + @TableField(value = "uid") + private Integer uid; + + /** + * 1:增,2:删,3:改 + */ + @TableField(value = "crud") + private Integer crud; + + /** + * 医院id + */ + @TableField(value = "hoid") + private Integer hoid; + + /** + * 科室id + */ + @TableField(value = "hdid") + private Integer hdid; + + /** + * 操作时间 + */ + @TableField(value = "creatdata") + private Date creatdata; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + LymsLogsCrud other = (LymsLogsCrud) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getUid() == null ? other.getUid() == null : this.getUid().equals(other.getUid())) + && (this.getCrud() == null ? other.getCrud() == null : this.getCrud().equals(other.getCrud())) + && (this.getHoid() == null ? other.getHoid() == null : this.getHoid().equals(other.getHoid())) + && (this.getHdid() == null ? other.getHdid() == null : this.getHdid().equals(other.getHdid())) + && (this.getCreatdata() == null ? other.getCreatdata() == null : this.getCreatdata().equals(other.getCreatdata())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getUid() == null) ? 0 : getUid().hashCode()); + result = prime * result + ((getCrud() == null) ? 0 : getCrud().hashCode()); + result = prime * result + ((getHoid() == null) ? 0 : getHoid().hashCode()); + result = prime * result + ((getHdid() == null) ? 0 : getHdid().hashCode()); + result = prime * result + ((getCreatdata() == null) ? 0 : getCreatdata().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", uid=").append(uid); + sb.append(", crud=").append(crud); + sb.append(", hoid=").append(hoid); + sb.append(", hdid=").append(hdid); + sb.append(", creatdata=").append(creatdata); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsLogsCrudMapper.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsLogsCrudMapper.java new file mode 100644 index 0000000..9d67b97 --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsLogsCrudMapper.java @@ -0,0 +1,15 @@ +package com.lyms.talkonlineweb.mapper; + +import com.lyms.talkonlineweb.domain.LymsLogsCrud; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + * @Entity com.lyms.talkonlineweb.domain.LymsLogsCrud + */ +public interface LymsLogsCrudMapper extends BaseMapper { + +} + + + + diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsLogsCrudService.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsLogsCrudService.java new file mode 100644 index 0000000..2978a1a --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsLogsCrudService.java @@ -0,0 +1,11 @@ +package com.lyms.talkonlineweb.service; + +import com.lyms.talkonlineweb.domain.LymsLogsCrud; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * + */ +public interface LymsLogsCrudService extends IService { + +} diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsLogsCrudServiceImpl.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsLogsCrudServiceImpl.java new file mode 100644 index 0000000..abb2eaa --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsLogsCrudServiceImpl.java @@ -0,0 +1,20 @@ +package com.lyms.talkonlineweb.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.lyms.talkonlineweb.domain.LymsLogsCrud; +import com.lyms.talkonlineweb.service.LymsLogsCrudService; +import com.lyms.talkonlineweb.mapper.LymsLogsCrudMapper; +import org.springframework.stereotype.Service; + +/** + * + */ +@Service +public class LymsLogsCrudServiceImpl extends ServiceImpl + implements LymsLogsCrudService{ + +} + + + + diff --git a/talkonlineweb/src/main/resources/mapper/LymsLogsCrudMapper.xml b/talkonlineweb/src/main/resources/mapper/LymsLogsCrudMapper.xml new file mode 100644 index 0000000..40b8414 --- /dev/null +++ b/talkonlineweb/src/main/resources/mapper/LymsLogsCrudMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + id,uid,crud, + hoid,hdid,creatdata + +