From 5304f70715f372a44a78488d2ea78a06da4a3feb Mon Sep 17 00:00:00 2001 From: inrgihc Date: Sat, 13 Jul 2024 23:59:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3issue:IA73GT=E5=8F=8D?= =?UTF-8?q?=E9=A6=88=E7=9A=84=E6=97=B6=E9=97=B4=E7=B1=BB=E5=9E=8B=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dbswitch/common/util/ObjectCastUtils.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/dbswitch-common/src/main/java/com/gitee/dbswitch/common/util/ObjectCastUtils.java b/dbswitch-common/src/main/java/com/gitee/dbswitch/common/util/ObjectCastUtils.java index 0dbd57cf..49796e6a 100644 --- a/dbswitch-common/src/main/java/com/gitee/dbswitch/common/util/ObjectCastUtils.java +++ b/dbswitch-common/src/main/java/com/gitee/dbswitch/common/util/ObjectCastUtils.java @@ -1,6 +1,8 @@ package com.gitee.dbswitch.common.util; import cn.hutool.core.codec.Base64; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; import cn.hutool.json.JSONUtil; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; @@ -487,8 +489,8 @@ public final class ObjectCastUtils { } } else if (in instanceof String || in instanceof Character) { try { - java.sql.Date date = java.sql.Date.valueOf(in.toString()); - LocalDate localDate = Instant.ofEpochMilli(date.getTime()) + DateTime dt = DateUtil.parse(in.toString()); + LocalDate localDate = Instant.ofEpochMilli(dt.toSqlDate().getTime()) .atZone(ZoneId.systemDefault()) .toLocalDate(); return localDate; @@ -502,8 +504,8 @@ public final class ObjectCastUtils { if (null == v) { return null; } - java.sql.Date date = java.sql.Date.valueOf(v); - LocalDate localDate = Instant.ofEpochMilli(date.getTime()) + DateTime dt = DateUtil.parse(in.toString()); + LocalDate localDate = Instant.ofEpochMilli(dt.toSqlDate().getTime()) .atZone(ZoneId.systemDefault()) .toLocalDate(); return localDate; @@ -576,8 +578,8 @@ public final class ObjectCastUtils { } } else if (in instanceof String || in instanceof Character) { try { - java.sql.Time date = java.sql.Time.valueOf(in.toString()); - return LocalTime.ofSecondOfDay(date.getTime()); + DateTime dt = DateUtil.parse(in.toString()); + return LocalTime.ofSecondOfDay(dt.toSqlDate().getTime()); } catch (IllegalArgumentException e) { throw new RuntimeException( String.format("无法将java.lang.String类型转换为java.sql.Time类型:%s", e.getMessage())); @@ -588,8 +590,8 @@ public final class ObjectCastUtils { if (null == v) { return null; } - java.sql.Time date = java.sql.Time.valueOf(v); - return LocalTime.ofSecondOfDay(date.getTime()); + DateTime dt = DateUtil.parse(in.toString()); + return LocalTime.ofSecondOfDay(dt.toSqlDate().getTime()); } catch (NumberFormatException e) { throw new RuntimeException( String.format("无法将java.sql.Clob类型转换为java.sql.Time类型:%s", e.getMessage())); @@ -671,9 +673,9 @@ public final class ObjectCastUtils { } } else if (in instanceof String || in instanceof Character) { try { - java.sql.Timestamp t = java.sql.Timestamp.valueOf(in.toString()); + DateTime dt = DateUtil.parse(in.toString()); LocalDateTime localDateTime = LocalDateTime - .ofInstant(t.toInstant(), ZoneId.systemDefault()); + .ofInstant(dt.toTimestamp().toInstant(), ZoneId.systemDefault()); return localDateTime; } catch (IllegalArgumentException e) { throw new RuntimeException( @@ -762,9 +764,9 @@ public final class ObjectCastUtils { } } else if (in instanceof String || in instanceof Character) { try { - java.sql.Timestamp t = java.sql.Timestamp.valueOf(in.toString()); + DateTime dt = DateUtil.parse(in.toString()); LocalDateTime localDateTime = LocalDateTime - .ofInstant(t.toInstant(), ZoneId.systemDefault()); + .ofInstant(dt.toTimestamp().toInstant(), ZoneId.systemDefault()); return Timestamp.valueOf(localDateTime); } catch (IllegalArgumentException e) { throw new RuntimeException(