Commit d17f430ec79254a01f645dd052a0aeac543351d6

Authored by liquanyu
1 parent afb0fbe7e9

update

Showing 1 changed file with 52 additions and 54 deletions

platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/MybatisSqlInterceptor.java View file @ d17f430
... ... @@ -6,6 +6,7 @@
6 6 import java.util.*;
7 7  
8 8 import com.lyms.platform.common.utils.DateUtil;
  9 +import com.lyms.platform.common.utils.ExceptionUtils;
9 10 import com.lyms.platform.operate.web.utils.SendMysqlSyncDatUtil;
10 11 import org.apache.commons.collections.CollectionUtils;
11 12 import org.apache.commons.lang.StringUtils;
12 13  
13 14  
14 15  
15 16  
16 17  
17 18  
18 19  
19 20  
20 21  
21 22  
... ... @@ -45,71 +46,68 @@
45 46  
46 47 Object[] args = invocation.getArgs();
47 48 Object returnValue = null;
48   - System.out.println("args===="+args.length);
49   - if (args != null && args.length == 2)
  49 + System.out.println("args length = "+args.length);
  50 + try
50 51 {
51   - System.out.println("if===="+args.length);
52   - MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
53   - Object parameter = null;
54   - if (invocation.getArgs().length > 1) {
55   - parameter = invocation.getArgs()[1];
56   - }
57   -
58   - try
  52 + if (args != null && args.length == 2)
59 53 {
60   - sqlId = mappedStatement.getId();
61   - System.out.println("sqlId"+sqlId);
62   - BoundSql boundSql = mappedStatement.getBoundSql(parameter);
63   - Configuration configuration = mappedStatement.getConfiguration();
64   - sqlCommandType = mappedStatement.getSqlCommandType().name();
  54 + MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
  55 + Object parameter = null;
  56 + if (invocation.getArgs().length > 1) {
  57 + parameter = invocation.getArgs()[1];
  58 + }
  59 + sqlId = mappedStatement.getId();
  60 + BoundSql boundSql = mappedStatement.getBoundSql(parameter);
  61 + Configuration configuration = mappedStatement.getConfiguration();
  62 + sqlCommandType = mappedStatement.getSqlCommandType().name();
65 63  
66   - System.out.println("1111"+sqlCommandType);
67   - if ("update".equals(sqlCommandType.toLowerCase()) || "delete".equals(sqlCommandType.toLowerCase()))
68   - {
69   - sql = getSql(configuration, boundSql, sqlId);
70   - if (!(sql.toUpperCase().contains("LIS_REPORT_TBL") || sql.toUpperCase().contains("RIS_REPORT_TBL"))) {
  64 + System.out.println("sqlCommandType = "+sqlCommandType);
  65 + if ("update".equals(sqlCommandType.toLowerCase()) || "delete".equals(sqlCommandType.toLowerCase()))
  66 + {
  67 + sql = getSql(configuration, boundSql, sqlId);
  68 + System.out.println("sql = "+sql);
  69 + if (!(sql.toUpperCase().contains("LIS_REPORT_TBL") || sql.toUpperCase().contains("RIS_REPORT_TBL")))
  70 + {
71 71  
72   - System.out.println("update delete"+sqlCommandType);
73   -
74   - System.out.println("delete and update sync sql = " + sql);
75   - //发送要同步的sql
76   - SendMysqlSyncDatUtil.sendSql(sql, sqlId);
77   - sql = null;
  72 + System.out.println("delete or update sync sql = " + sql);
  73 + //发送要同步的sql
  74 + SendMysqlSyncDatUtil.sendSql(sql, sqlId);
  75 + sql = null;
  76 + }
78 77 }
79   - }
80   - else if ("insert".equals(sqlCommandType.toLowerCase()) )
81   - {
82   - sql = getSql(configuration, boundSql, sqlId);
83   - }
84   -
85   - System.out.println("sqlCommandType = "+sqlCommandType+":mysql sql =" + sql);
86   - returnValue = invocation.proceed();
87   - }catch (Exception e)
88   - {
89   - System.out.println(e);
  78 + else if ("insert".equals(sqlCommandType.toLowerCase()) )
  79 + {
  80 + if (!(sql.toUpperCase().contains("LIS_REPORT_TBL") || sql.toUpperCase().contains("RIS_REPORT_TBL")))
  81 + {
  82 + sql = getSql(configuration, boundSql, sqlId);
  83 + System.out.println("sql = "+sql);
  84 + }
  85 + }
  86 + returnValue = invocation.proceed();
90 87 }
91   -
92   - }
93   - else
94   - {
95   - System.out.println("else = "+sql);
96   - returnValue = invocation.proceed();
97   - if (StringUtils.isNotEmpty(sql) && sqlCommandType != null && "insert".equals(sqlCommandType.toLowerCase()))
  88 + else
98 89 {
99   - if (returnValue != null && returnValue instanceof ArrayList)
  90 + returnValue = invocation.proceed();
  91 + if (StringUtils.isNotEmpty(sql) && sqlCommandType != null && "insert".equals(sqlCommandType.toLowerCase()))
100 92 {
101   - List<Integer> list = (ArrayList)returnValue;
102   - if (CollectionUtils.isNotEmpty(list))
  93 + if (returnValue != null && returnValue instanceof ArrayList)
103 94 {
104   - sql = sql.replaceFirst("\\(","(ID,");
105   - sql = sql.substring(0,sql.lastIndexOf("(")+1)+list.get(0)+","+sql.substring(sql.lastIndexOf("(")+1,sql.length());
106   - System.out.println("add sync sql = "+sql);
107   - //发送要同步的sql
108   - SendMysqlSyncDatUtil.sendSql(sql, sqlId);
109   - sql = null;
  95 + List<Integer> list = (ArrayList)returnValue;
  96 + if (CollectionUtils.isNotEmpty(list))
  97 + {
  98 + sql = sql.replaceFirst("\\(","(ID,");
  99 + sql = sql.substring(0,sql.lastIndexOf("(")+1)+list.get(0)+","+sql.substring(sql.lastIndexOf("(")+1,sql.length());
  100 + System.out.println("add sync sql = "+sql);
  101 + //发送要同步的sql
  102 + SendMysqlSyncDatUtil.sendSql(sql, sqlId);
  103 + sql = null;
  104 + }
110 105 }
111 106 }
112 107 }
  108 + }catch (Exception e)
  109 + {
  110 + ExceptionUtils.catchException(e," Mybatis Sql Interceptor exception");
113 111 }
114 112 return returnValue;
115 113 }