From 5c95d34006eb88138c92d3043efc3a0f8fd94147 Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Fri, 24 Sep 2021 16:15:28 +0800 Subject: [PATCH] =?UTF-8?q?oracle.sql.TIMESTAMP=20=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DataSourceServiceImpl.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasource/service/impl/DataSourceServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasource/service/impl/DataSourceServiceImpl.java index 77b53950..92af651a 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasource/service/impl/DataSourceServiceImpl.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasource/service/impl/DataSourceServiceImpl.java @@ -33,11 +33,9 @@ import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; @@ -243,7 +241,9 @@ public class DataSourceServiceImpl implements DataSourceService { columns.forEach(t -> { try { Object value = rs.getObject(t); - jo.put(t, value); + //数据类型转换 + Object result = dealResult(value); + jo.put(t, result); } catch (SQLException throwable) { log.error("error",throwable); throw BusinessExceptionBuilder.build(ResponseCode.EXECUTE_SQL_ERROR, throwable.getMessage()); @@ -267,6 +267,26 @@ public class DataSourceServiceImpl implements DataSourceService { } } + /** + * 解决sql返回值 类型问题 + * (through reference chain: java.util.HashMap["pageData"]->java.util.ArrayList[0]->java.util.HashMap["UPDATE_TIME"]->oracle.sql.TIMESTAMP["stream"]) + * @param result + * @return + * @throws SQLException + */ + private Object dealResult(Object result) throws SQLException { + if (null == result) { + return result; + } + String type = result.getClass().getName(); + if ("oracle.sql.TIMESTAMP".equals(type)) { + //oracle.sql.TIMESTAMP处理逻辑 + return new Date((Long) JSONObject.toJSON(result)); + } + + return result; + } + /** * http 执行获取数据 *