| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.client.RestTemplate; |
| | | import com.java110.core.context.Environment; |
| | | import com.java110.core.factory.Java110TransactionalFactory; |
| | | import com.java110.db.dao.IQueryServiceDAO; |
| | | import com.java110.dto.order.OrderItemDto; |
| | |
| | | import com.java110.utils.util.DateUtil; |
| | | import com.java110.utils.util.StringUtil; |
| | | import org.apache.ibatis.executor.Executor; |
| | | import org.apache.ibatis.mapping.BoundSql; |
| | | import org.apache.ibatis.mapping.MappedStatement; |
| | | import org.apache.ibatis.mapping.ParameterMapping; |
| | | import org.apache.ibatis.mapping.SqlCommandType; |
| | | import org.apache.ibatis.mapping.*; |
| | | import org.apache.ibatis.plugin.*; |
| | | import org.apache.ibatis.reflection.MetaObject; |
| | | 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; |
| | |
| | | Map<String, Object> sqlValue = new HashMap<>(); |
| | | //获取sql语句 |
| | | String sql = showSql(configuration, boundSql, sqlValue, sqlCommandType); |
| | | restTemplate = ApplicationContextFactory.getBean("restTemplate", RestTemplate.class); |
| | | if(Environment.isStartBootWay()){ |
| | | restTemplate = ApplicationContextFactory.getBean("outRestTemplate", RestTemplate.class); |
| | | }else { |
| | | restTemplate = ApplicationContextFactory.getBean("restTemplate", RestTemplate.class); |
| | | } |
| | | switch (sqlCommandType) { |
| | | case INSERT: |
| | | dealInsertSql(mappedStatement, parameter, sql, sqlValue); |
| | |
| | | */ |
| | | private void dealDeleteSql(MappedStatement mappedStatement, Object parameter, String sql, Map<String, Object> sqlValue) { |
| | | |
| | | String tmpTable = sql.substring(sql.indexOf("into") + 4, sql.indexOf("(")).trim(); |
| | | String tmpTable = sql.substring(sql.indexOf("from") + 4, sql.indexOf("where")).trim(); |
| | | String tmpTableHasT = tmpTable; |
| | | if(tmpTable.indexOf(" ") > 0){ |
| | | tmpTable = tmpTable.substring(0,tmpTable.indexOf(" ")); |
| | |
| | | String url = ServiceConstant.SERVICE_ORDER_URL + "/order/oIdApi/createOrderItem"; |
| | | HttpHeaders httpHeaders = new HttpHeaders(); |
| | | HttpEntity httpEntity = new HttpEntity(orderItemDto.toString(), httpHeaders); |
| | | if(Environment.isStartBootWay()){ |
| | | url = ServiceConstant.BOOT_SERVICE_ORDER_URL + "/order/oIdApi/createOrderItem"; |
| | | } |
| | | ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class); |
| | | |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | |
| | | 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")).trim(); |
| | | String tmpTable = sql.substring(sql.indexOf("update") + 6, sql.indexOf("set ")).trim(); |
| | | |
| | | String tmpTableHasT = tmpTable; |
| | | |
| | |
| | | String url = ServiceConstant.SERVICE_ORDER_URL + "/order/oIdApi/createOrderItem"; |
| | | HttpHeaders httpHeaders = new HttpHeaders(); |
| | | HttpEntity httpEntity = new HttpEntity(orderItemDto.toString(), httpHeaders); |
| | | ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class); |
| | | ResponseEntity<String> responseEntity = null; |
| | | if(Environment.isStartBootWay()){ |
| | | url = ServiceConstant.BOOT_SERVICE_ORDER_URL + "/order/oIdApi/createOrderItem"; |
| | | } |
| | | responseEntity = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class); |
| | | |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | throw new IllegalArgumentException("注册事务回滚日志失败" + responseEntity); |
| | |
| | | String url = ServiceConstant.SERVICE_ORDER_URL + "/order/oIdApi/createOrderItem"; |
| | | HttpHeaders httpHeaders = new HttpHeaders(); |
| | | HttpEntity httpEntity = new HttpEntity(orderItemDto.toString(), httpHeaders); |
| | | if(Environment.isStartBootWay()){ |
| | | url = ServiceConstant.BOOT_SERVICE_ORDER_URL + "/order/oIdApi/createOrderItem"; |
| | | } |
| | | ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class); |
| | | |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | |
| | | String propertyName = parameterMapping.getProperty(); |
| | | if (metaObject.hasGetter(propertyName)) { |
| | | Object obj = metaObject.getValue(propertyName); |
| | | sql = sql.replaceFirst("\\?", getParameterValue(obj)); |
| | | String value = getParameterValue(obj); |
| | | if(value.contains("${")){ |
| | | value = value.replace("${","\\${"); |
| | | } |
| | | sql = sql.replaceFirst("\\?", value); |
| | | values.add(getParameterValue(obj)); |
| | | } else if (boundSql.hasAdditionalParameter(propertyName)) { |
| | | Object obj = boundSql.getAdditionalParameter(propertyName); |
| | |
| | | String[] tmpKeys = tmpKey.split(","); |
| | | |
| | | // if (values.size() < tmpKeys.length) { |
| | | // throw new IllegalArgumentException("sql 错误 key 和value 个数不等" + sql); |
| | | // throw new IllegalArgumentException("sql 错误 key P和value 个数不等" + sql); |
| | | // } |
| | | for (int keyIndex = 0; keyIndex < tmpKeys.length; keyIndex++) { |
| | | String key = tmpKeys[keyIndex].trim(); |
| | |
| | | return sql; |
| | | } |
| | | |
| | | |
| | | private String getParameterValue(Object obj) { |
| | | String value = null; |
| | | if (obj instanceof String) { |
| | |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | String tmpTable = "product_label t"; |
| | | if(tmpTable.indexOf(" ") > 0){ |
| | | tmpTable = tmpTable.substring(0,tmpTable.indexOf(" ")); |
| | | } |
| | | System.out.printf(tmpTable); |
| | | } |
| | | |
| | | } |