|
@@ -73,33 +73,7 @@ public class ProjectInterceptor implements InnerInterceptor {
|
|
|
|
|
|
|
|
|
|
|
|
-@Override
|
|
|
-public void beforeUpdate(Executor executor, MappedStatement ms, Object parameter) throws SQLException {
|
|
|
- if (ms.getSqlCommandType() == SqlCommandType.DELETE) {
|
|
|
- try {
|
|
|
-
|
|
|
- BoundSql boundSql = ms.getBoundSql(parameter);
|
|
|
- String originalSql = boundSql.getSql();
|
|
|
|
|
|
-
|
|
|
- Statement statement = CCJSqlParserUtil.parse(originalSql);
|
|
|
- if (statement instanceof Delete) {
|
|
|
- Delete delete = (Delete) statement;
|
|
|
-
|
|
|
- Update update = new Update();
|
|
|
- update.setTable(delete.getTable());
|
|
|
- update.setWhere(delete.getWhere());
|
|
|
- update.addUpdateSet(new Column("delete_flag"), new LongValue(1));
|
|
|
- Field sqlField = ReflectUtil.getField(BoundSql.class, "sql");
|
|
|
- ReflectUtil.setFieldValue(boundSql, sqlField, update.toString());
|
|
|
- System.out.println("转换后的 SQL: " + update.toString());
|
|
|
-
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- throw new SQLException("SQL转换失败", e);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
@Override
|
|
|
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
|
|
@@ -130,17 +104,13 @@ public void beforeUpdate(Executor executor, MappedStatement ms, Object parameter
|
|
|
EqualsTo projectEq = new EqualsTo();
|
|
|
projectEq.setLeftExpression(new Column("project"));
|
|
|
projectEq.setRightExpression(new StringValue(project));
|
|
|
- EqualsTo deleteFlag = new EqualsTo();
|
|
|
- deleteFlag.setLeftExpression(new Column("delete_flag"));
|
|
|
- deleteFlag.setRightExpression(new LongValue(0));
|
|
|
String plainSelectString = plainSelect.toString();
|
|
|
if (!plainSelectString.contains("project = ") && !plainSelectString.contains("delete_flag = ")) {
|
|
|
- AndExpression targetExpression = new AndExpression(projectEq, deleteFlag);
|
|
|
if (plainSelectString.contains("where") || plainSelectString.contains("WHERE")) {
|
|
|
- AndExpression andExpression = new AndExpression(where, targetExpression);
|
|
|
+ AndExpression andExpression = new AndExpression(projectEq,where);
|
|
|
plainSelect.setWhere(andExpression);
|
|
|
}else {
|
|
|
- plainSelect.setWhere(targetExpression);
|
|
|
+ plainSelect.setWhere(projectEq);
|
|
|
}
|
|
|
|
|
|
targetSql = plainSelect.toString();
|