|
@@ -1,7 +1,6 @@
|
|
|
package com.ruoyi.framework.mybatis.interceptor;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.druid.pool.DruidDataSource;
|
|
|
import com.alibaba.druid.stat.JdbcDataSourceStat;
|
|
@@ -21,7 +20,6 @@ import com.ruoyi.framework.mybatis.RemoveParam;
|
|
|
import com.ruoyi.framework.mybatis.holder.LogicHolder;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import net.sf.jsqlparser.JSQLParserException;
|
|
|
-import net.sf.jsqlparser.expression.Alias;
|
|
|
import net.sf.jsqlparser.expression.Expression;
|
|
|
import net.sf.jsqlparser.expression.LongValue;
|
|
|
import net.sf.jsqlparser.expression.StringValue;
|
|
@@ -94,7 +92,7 @@ public class LogicInterceptor extends BaseMultiTableInnerInterceptor implements
|
|
|
String sql = "SELECT table_name FROM information_schema.COLUMNS WHERE table_schema = ? AND column_name = ?";
|
|
|
// 执行sql找出不包含逻辑删除字段的表名
|
|
|
List<String> notContainsDelFlagTableNameList = new JdbcTemplate(v).queryForList(sql, String.class, dbName, delFlagName);
|
|
|
-
|
|
|
+
|
|
|
List<String> tempList = new ArrayList<>(notContainsDelFlagTableNameList);
|
|
|
tempList.forEach(item -> notContainsDelFlagTableNameList.add("`" + item + "`"));
|
|
|
|
|
@@ -117,11 +115,22 @@ public class LogicInterceptor extends BaseMultiTableInnerInterceptor implements
|
|
|
PluginUtils.MPStatementHandler mpSh = PluginUtils.mpStatementHandler(sh);
|
|
|
MappedStatement ms = mpSh.mappedStatement();
|
|
|
SqlCommandType sct = ms.getSqlCommandType();
|
|
|
- // 处理新增编辑
|
|
|
- if (sct == SqlCommandType.INSERT || sct == SqlCommandType.UPDATE) {
|
|
|
+
|
|
|
+ // 处理新增
|
|
|
+ if (Objects.equals(sct, SqlCommandType.INSERT)) {
|
|
|
PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql();
|
|
|
mpBs.sql(parserMulti(mpBs.sql(), null));
|
|
|
}
|
|
|
+
|
|
|
+ // 处理编辑
|
|
|
+ else if (Objects.equals(sct, SqlCommandType.UPDATE)) {
|
|
|
+ if (LogicHolder.getLogicHolder()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql();
|
|
|
+ mpBs.sql(parserMulti(mpBs.sql(), null));
|
|
|
+ }
|
|
|
+
|
|
|
// 处理删除
|
|
|
if (sct == SqlCommandType.DELETE) {
|
|
|
PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql();
|
|
@@ -291,31 +300,6 @@ public class LogicInterceptor extends BaseMultiTableInnerInterceptor implements
|
|
|
*/
|
|
|
private boolean isSkip(Table table) {
|
|
|
|
|
|
- LogicHolder logicHolder = LogicHolder.getLogicHolder();
|
|
|
- String name = table.getName();
|
|
|
-
|
|
|
- if (logicHolder != null) {
|
|
|
-
|
|
|
- String[] tableNames = logicHolder.getTableNames();
|
|
|
- String[] aliases = logicHolder.getAliases();
|
|
|
-
|
|
|
- if (ObjectUtil.isEmpty(tableNames) && ObjectUtil.isEmpty(aliases)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- if (ObjectUtil.isNotEmpty(tableNames) && Arrays.asList(tableNames).contains(name)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- Alias alias = table.getAlias();
|
|
|
- if (alias != null) {
|
|
|
- if (ObjectUtil.isNotEmpty(aliases) && Arrays.asList(aliases).contains(alias.getName())) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
// 执行sql的数据源名称
|
|
|
String dataSourceType = DynamicDataSourceContextHolder.peek();
|
|
|
if (StrUtil.isBlank(dataSourceType)) {
|
|
@@ -329,7 +313,7 @@ public class LogicInterceptor extends BaseMultiTableInnerInterceptor implements
|
|
|
}
|
|
|
|
|
|
// 如果不包涵则跳过拼接逻辑删除
|
|
|
- return !tableNameList.contains(name);
|
|
|
+ return !tableNameList.contains(table.getName());
|
|
|
}
|
|
|
|
|
|
|