From d17f430ec79254a01f645dd052a0aeac543351d6 Mon Sep 17 00:00:00 2001 From: liquanyu Date: Fri, 28 Apr 2017 09:26:55 +0800 Subject: [PATCH] update --- .../web/inteceptor/MybatisSqlInterceptor.java | 106 ++++++++++----------- 1 file changed, 52 insertions(+), 54 deletions(-) diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/MybatisSqlInterceptor.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/MybatisSqlInterceptor.java index 1b50ba7..bf4481c 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/MybatisSqlInterceptor.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/MybatisSqlInterceptor.java @@ -6,6 +6,7 @@ import java.text.DateFormat; import java.util.*; import com.lyms.platform.common.utils.DateUtil; +import com.lyms.platform.common.utils.ExceptionUtils; import com.lyms.platform.operate.web.utils.SendMysqlSyncDatUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; @@ -45,71 +46,68 @@ public class MybatisSqlInterceptor implements Interceptor { Object[] args = invocation.getArgs(); Object returnValue = null; - System.out.println("args===="+args.length); - if (args != null && args.length == 2) + System.out.println("args length = "+args.length); + try { - System.out.println("if===="+args.length); - MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0]; - Object parameter = null; - if (invocation.getArgs().length > 1) { - parameter = invocation.getArgs()[1]; - } - - try + if (args != null && args.length == 2) { - sqlId = mappedStatement.getId(); - System.out.println("sqlId"+sqlId); - BoundSql boundSql = mappedStatement.getBoundSql(parameter); - Configuration configuration = mappedStatement.getConfiguration(); - sqlCommandType = mappedStatement.getSqlCommandType().name(); - - System.out.println("1111"+sqlCommandType); - if ("update".equals(sqlCommandType.toLowerCase()) || "delete".equals(sqlCommandType.toLowerCase())) - { - sql = getSql(configuration, boundSql, sqlId); - if (!(sql.toUpperCase().contains("LIS_REPORT_TBL") || sql.toUpperCase().contains("RIS_REPORT_TBL"))) { - - System.out.println("update delete"+sqlCommandType); - - System.out.println("delete and update sync sql = " + sql); - //发送要同步的sql - SendMysqlSyncDatUtil.sendSql(sql, sqlId); - sql = null; - } - } - else if ("insert".equals(sqlCommandType.toLowerCase()) ) - { - sql = getSql(configuration, boundSql, sqlId); + MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0]; + Object parameter = null; + if (invocation.getArgs().length > 1) { + parameter = invocation.getArgs()[1]; } + sqlId = mappedStatement.getId(); + BoundSql boundSql = mappedStatement.getBoundSql(parameter); + Configuration configuration = mappedStatement.getConfiguration(); + sqlCommandType = mappedStatement.getSqlCommandType().name(); - System.out.println("sqlCommandType = "+sqlCommandType+":mysql sql =" + sql); - returnValue = invocation.proceed(); - }catch (Exception e) - { - System.out.println(e); + System.out.println("sqlCommandType = "+sqlCommandType); + if ("update".equals(sqlCommandType.toLowerCase()) || "delete".equals(sqlCommandType.toLowerCase())) + { + sql = getSql(configuration, boundSql, sqlId); + System.out.println("sql = "+sql); + if (!(sql.toUpperCase().contains("LIS_REPORT_TBL") || sql.toUpperCase().contains("RIS_REPORT_TBL"))) + { + + System.out.println("delete or update sync sql = " + sql); + //发送要同步的sql + SendMysqlSyncDatUtil.sendSql(sql, sqlId); + sql = null; + } + } + else if ("insert".equals(sqlCommandType.toLowerCase()) ) + { + if (!(sql.toUpperCase().contains("LIS_REPORT_TBL") || sql.toUpperCase().contains("RIS_REPORT_TBL"))) + { + sql = getSql(configuration, boundSql, sqlId); + System.out.println("sql = "+sql); + } + } + returnValue = invocation.proceed(); } - - } - else - { - System.out.println("else = "+sql); - returnValue = invocation.proceed(); - if (StringUtils.isNotEmpty(sql) && sqlCommandType != null && "insert".equals(sqlCommandType.toLowerCase())) + else { - if (returnValue != null && returnValue instanceof ArrayList) + returnValue = invocation.proceed(); + if (StringUtils.isNotEmpty(sql) && sqlCommandType != null && "insert".equals(sqlCommandType.toLowerCase())) { - List list = (ArrayList)returnValue; - if (CollectionUtils.isNotEmpty(list)) + if (returnValue != null && returnValue instanceof ArrayList) { - sql = sql.replaceFirst("\\(","(ID,"); - sql = sql.substring(0,sql.lastIndexOf("(")+1)+list.get(0)+","+sql.substring(sql.lastIndexOf("(")+1,sql.length()); - System.out.println("add sync sql = "+sql); - //发送要同步的sql - SendMysqlSyncDatUtil.sendSql(sql, sqlId); - sql = null; + List list = (ArrayList)returnValue; + if (CollectionUtils.isNotEmpty(list)) + { + sql = sql.replaceFirst("\\(","(ID,"); + sql = sql.substring(0,sql.lastIndexOf("(")+1)+list.get(0)+","+sql.substring(sql.lastIndexOf("(")+1,sql.length()); + System.out.println("add sync sql = "+sql); + //发送要同步的sql + SendMysqlSyncDatUtil.sendSql(sql, sqlId); + sql = null; + } } } } + }catch (Exception e) + { + ExceptionUtils.catchException(e," Mybatis Sql Interceptor exception"); } return returnValue; } -- 1.8.3.1