old mode 100644
new mode 100755
| | |
| | | import org.apache.ibatis.session.Configuration; |
| | | import org.apache.ibatis.type.TypeHandlerRegistry; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.java110.core.log.LoggerFactory; |
| | | import org.springframework.http.*; |
| | | |
| | | import java.sql.Timestamp; |
| | |
| | | */ |
| | | private void dealDeleteSql(MappedStatement mappedStatement, Object parameter, String sql, Map<String, Object> sqlValue) { |
| | | |
| | | String tmpTable = sql.substring(sql.indexOf("into") + 4, sql.indexOf("(")); |
| | | String tmpTable = sql.substring(sql.indexOf("into") + 4, sql.indexOf("(")).trim(); |
| | | String tmpTableHasT = tmpTable; |
| | | if(tmpTable.indexOf(" ") > 0){ |
| | | tmpTable = tmpTable.substring(0,tmpTable.indexOf(" ")); |
| | | } |
| | | String tmpWhere = sql.substring(sql.indexOf("where")); |
| | | //插入操作时之前的 没有数据 所以 preValue 为空对象 |
| | | JSONArray preValues = new JSONArray(); |
| | | |
| | | String execSql = "select * from " + tmpTable + " " + tmpWhere; |
| | | String execSql = "select * from " + tmpTableHasT + " " + tmpWhere; |
| | | |
| | | queryServiceDAOImpl = ApplicationContextFactory.getBean("queryServiceDAOImpl", IQueryServiceDAO.class); |
| | | List<Map<String, Object>> deleteDatas = queryServiceDAOImpl.executeSql(execSql, null); |
| | |
| | | private void dealUpdateSql(MappedStatement mappedStatement, Object parameter, String sql, Map<String, Object> sqlValue) { |
| | | //RestTemplate restTemplate = ApplicationContextFactory.getBean("restTemplate", RestTemplate.class); |
| | | |
| | | String tmpTable = sql.substring(sql.indexOf("update") + 6, sql.indexOf("set")); |
| | | String tmpTable = sql.substring(sql.indexOf("update") + 6, sql.indexOf("set")).trim(); |
| | | |
| | | String tmpTableHasT = tmpTable; |
| | | |
| | | if(tmpTable.indexOf(" ") > 0){ |
| | | tmpTable = tmpTable.substring(0,tmpTable.indexOf(" ")); |
| | | } |
| | | String tmpWhere = sql.substring(sql.indexOf("where")); |
| | | |
| | | //插入操作时之前的 没有数据 所以 preValue 为空对象 |
| | | JSONArray preValues = new JSONArray(); |
| | | JSONArray afterValues = new JSONArray(); |
| | | JSONObject afterVaule = null; |
| | | String execSql = "select * from " + tmpTable + " " + tmpWhere; |
| | | String execSql = "select * from " + tmpTableHasT + " " + tmpWhere; |
| | | queryServiceDAOImpl = ApplicationContextFactory.getBean("queryServiceDAOImpl", IQueryServiceDAO.class); |
| | | List<Map<String, Object>> deleteDatas = queryServiceDAOImpl.executeSql(execSql, null); |
| | | |
| | |
| | | |
| | | JSONArray afterValues = new JSONArray(); |
| | | |
| | | String tmpTable = sql.substring(sql.toLowerCase().indexOf("into") + 4, sql.indexOf("(")); |
| | | // String tmpKey = sql.substring(sql.indexOf("(") + 1, sql.indexOf(")")); |
| | | // String[] tmpKeys = tmpKey.split(","); |
| | | // int valuePos = 0; |
| | | // if (sql.contains("VALUES")) { |
| | | // valuePos = sql.indexOf("VALUES") + 6; |
| | | // } else { |
| | | // valuePos = sql.indexOf("values") + 6; |
| | | // } |
| | | // String sqlValues = sql.substring(valuePos); |
| | | // //说明批操作 |
| | | // |
| | | // String[] sqlVauleses = sqlValues.split("\\)"); |
| | | // JSONObject afterValue = null; |
| | | // for (String sqlV : sqlVauleses) { |
| | | // String tmpValue = sqlV.substring(sqlV.lastIndexOf("(") + 1); |
| | | // String[] tmpValues = tmpValue.split(","); |
| | | // afterValue = new JSONObject(); |
| | | // |
| | | // if (tmpKeys.length != tmpValues.length) { |
| | | // throw new IllegalArgumentException("sql 错误 key 和value 个数不等" + sql); |
| | | // } |
| | | // |
| | | // if (tmpKeys.length < 1) { |
| | | // throw new IllegalArgumentException("sql 错误 未找到key" + sql); |
| | | // } |
| | | // for (int keyIndex = 0; keyIndex < tmpKeys.length; keyIndex++) { |
| | | // if ("''".equals(tmpValues[keyIndex])) { |
| | | // continue; |
| | | // } |
| | | // afterValue.put(tmpKeys[keyIndex], tmpValues[keyIndex]); |
| | | // } |
| | | // afterValues.add(afterValue); |
| | | // } |
| | | String tmpTable = sql.substring(sql.toLowerCase().indexOf("into") + 4, sql.indexOf("(")).trim(); |
| | | |
| | | if(tmpTable.indexOf(" ") > 0){ |
| | | tmpTable = tmpTable.substring(0,tmpTable.indexOf(" ")); |
| | | } |
| | | |
| | | afterValues.add(sqlValue); |
| | | |
| | | JSONObject logText = new JSONObject(); |
| | | logText.put("preValue", preValues); |
| | | logText.put("afterValue", sqlValue); |
| | | logText.put("afterValue", afterValues); |
| | | |
| | | OrderItemDto orderItemDto = new OrderItemDto(); |
| | | orderItemDto.setbId("-1"); |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Object plugin(Object target) { |
| | |
| | | String tmpKey = orgSql.substring(orgSql.indexOf("(") + 1, orgSql.indexOf(")")); |
| | | String[] tmpKeys = tmpKey.split(","); |
| | | |
| | | if (values.size() < tmpKeys.length) { |
| | | throw new IllegalArgumentException("sql 错误 key 和value 个数不等" + sql); |
| | | } |
| | | // if (values.size() < tmpKeys.length) { |
| | | // throw new IllegalArgumentException("sql 错误 key 和value 个数不等" + sql); |
| | | // } |
| | | for (int keyIndex = 0; keyIndex < tmpKeys.length; keyIndex++) { |
| | | String key = tmpKeys[keyIndex].trim(); |
| | | String value = ""; |
| | | if (values.size() - 1 < keyIndex) { |
| | | continue; |
| | | } |
| | | value = values.get(keyIndex); |
| | | if ("''".equals(value)) { |
| | | continue; |
| | |
| | | } else if (sqlCommandType == SqlCommandType.UPDATE) { |
| | | String tmpKey = orgSql.substring(sql.indexOf("set") + 3, orgSql.indexOf("where")); |
| | | String[] tmpKeys = tmpKey.split(","); |
| | | if (values.size() < tmpKeys.length) { |
| | | throw new IllegalArgumentException("sql 错误 key 和value 个数不等" + sql); |
| | | } |
| | | // if (values.size() < tmpKeys.length) { |
| | | // throw new IllegalArgumentException("sql 错误 key 和value 个数不等" + sql); |
| | | // } |
| | | for (int keyIndex = 0; keyIndex < tmpKeys.length; keyIndex++) { |
| | | String tmpSetKey = tmpKeys[keyIndex]; |
| | | String[] keyValues = tmpSetKey.split("="); |
| | |
| | | key = keyValues[0].trim(); |
| | | } |
| | | String value = ""; |
| | | if (values.size() - 1 < keyIndex) { |
| | | continue; |
| | | } |
| | | value = values.get(keyIndex); |
| | | if ("''".equals(value)) { |
| | | continue; |
| | |
| | | |
| | | return sql; |
| | | } |
| | | |
| | | |
| | | private String getParameterValue(Object obj) { |
| | | String value = null; |
| | |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | String tmpKey = " prime_rate,detail_id,receivable_amount,cycles,remark,status_cd,received_amount,community_id,b_id,fee_id,state"; |
| | | String tmpValue = "'1.00','912020080411040001','1500.0','1.0',,'0','1500.0','7020181217000001','-1',,"; |
| | | String[] tmpKeys = tmpKey.split(","); |
| | | String[] tmpValues = tmpValue.split(","); |
| | | |
| | | if (tmpKeys.length != tmpValues.length) { |
| | | throw new IllegalArgumentException("sql 错误 key 和value 个数不等"); |
| | | String tmpTable = "" + |
| | | " id_card,open_id,link,remark,user_id,app_type,app_user_name,nickname,headimgurl,community_name,state,app_user_id,community_id,app_type_cd,member_id\n" + |
| | | " "; |
| | | String[] a = tmpTable.split(","); |
| | | for(String a1:a){ |
| | | System.out.println(a1); |
| | | } |
| | | } |
| | | } |