|
@@ -0,0 +1,54 @@
|
|
|
+package cn.gygxzc.envir.core.orm.plugin
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.PluginUtils
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils
|
|
|
+import com.baomidou.mybatisplus.extension.handlers.AbstractSqlParserHandler
|
|
|
+import org.apache.ibatis.executor.statement.StatementHandler
|
|
|
+import org.apache.ibatis.mapping.MappedStatement
|
|
|
+import org.apache.ibatis.mapping.SqlCommandType
|
|
|
+import org.apache.ibatis.plugin.*
|
|
|
+import org.apache.ibatis.reflection.SystemMetaObject
|
|
|
+import java.sql.Connection
|
|
|
+import java.util.*
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author tuonina
|
|
|
+ * @createTime 2019/5/16
|
|
|
+ * 基于部门或者说是有层级结构的code编码实现数据权限
|
|
|
+ * 按照既定的规则进行数据权限
|
|
|
+ * 1、查询
|
|
|
+ * 2、更新
|
|
|
+ * 3、删除
|
|
|
+ * 4、添加
|
|
|
+ */
|
|
|
+@Intercepts(Signature(type = StatementHandler::class, method = "prepare", args = arrayOf(Connection::class, Int::class)))
|
|
|
+class OnDeptDataAuthority : AbstractSqlParserHandler(), Interceptor {
|
|
|
+
|
|
|
+
|
|
|
+ override fun intercept(invocation: Invocation): Any {
|
|
|
+ val statementHandler = PluginUtils.realTarget(invocation.target) as StatementHandler
|
|
|
+ val metaObject = SystemMetaObject.forObject(statementHandler)
|
|
|
+ // SQL 解析
|
|
|
+ this.sqlParser(metaObject)
|
|
|
+
|
|
|
+ // 先判断是不是SELECT操作
|
|
|
+ val mappedStatement = metaObject.getValue("delegate.mappedStatement") as MappedStatement
|
|
|
+ if (SqlCommandType.SELECT != mappedStatement.sqlCommandType) {
|
|
|
+ return invocation.proceed()
|
|
|
+ }
|
|
|
+ return invocation.proceed()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun setProperties(prop: Properties) {
|
|
|
+ val dialectType = prop.getProperty("dialectType")
|
|
|
+ val dialectClazz = prop.getProperty("dialectClazz")
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun plugin(target: Any): Any {
|
|
|
+ return if (target is StatementHandler) {
|
|
|
+ Plugin.wrap(target, this)
|
|
|
+ } else target
|
|
|
+ }
|
|
|
+}
|