From ee4d1b668d1666cdec803b037ce8181763154bb6 Mon Sep 17 00:00:00 2001
From: chengf <2156125618@qq.com>
Date: 星期五, 25 七月 2025 18:25:07 +0800
Subject: [PATCH] 费用导入逻辑变更2025/07/25

---
 java110-utils/src/main/java/com/java110/utils/util/Java110Converter.java |   62 ++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 5 deletions(-)

diff --git a/java110-utils/src/main/java/com/java110/utils/util/Java110Converter.java b/java110-utils/src/main/java/com/java110/utils/util/Java110Converter.java
old mode 100644
new mode 100755
index bd88b74..7821979
--- a/java110-utils/src/main/java/com/java110/utils/util/Java110Converter.java
+++ b/java110-utils/src/main/java/com/java110/utils/util/Java110Converter.java
@@ -6,6 +6,9 @@
 import java.sql.Timestamp;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
 import java.util.Date;
 
 /**
@@ -17,7 +20,7 @@
  * add by wuxw 2020/1/28
  **/
 public class Java110Converter implements Converter {
-    static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
 
     @Override
     public Object convert(Object value, Class target, Object context) {
@@ -26,17 +29,24 @@
     }
 
     public static Object getValue(Object value, Class target) {
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+        if (value == null) {
+            return value;
+        }
         //1.0 String 杞� Date
         if (value instanceof String && target == Date.class) {
             String date = (String) value;
             Date newDate = null;
+            SimpleDateFormat strdf = null;
             if (date.contains(":")) {
-                //sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
+                strdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
             } else {
-                sdf = new SimpleDateFormat("yyyy-MM-dd");
+                strdf = new SimpleDateFormat("yyyy-MM-dd");
             }
             try {
-                newDate = sdf.parse(date);
+                newDate = strdf.parse(date);
             } catch (ParseException e) {
                 e.printStackTrace();
             }
@@ -47,6 +57,15 @@
         if (value instanceof Date && target == Date.class) {
             return value;
         }
+
+        //2.0 Date 杞� Date
+        if (value instanceof LocalDateTime && target == Date.class) {
+            ZoneId zoneId = ZoneId.systemDefault();
+            ZonedDateTime zonedDateTime = ((LocalDateTime)value).atZone(zoneId);
+            Date date = Date.from(zonedDateTime.toInstant());
+            return date;
+        }
+
 
         // 3.0 Date 杞� String
         if (value instanceof Date && target == String.class) {
@@ -59,8 +78,19 @@
             }
             return newDate;
         }
+        // 3.0 Timestamp 杞� String
+        if (value instanceof Timestamp && target == String.class) {
+            Date date = new Date(((Timestamp) value).getTime());
+            String newDate = null;
+            try {
+                newDate = sdf.format(date);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            return newDate;
+        }
 
-        if (value instanceof BigDecimal) {
+        if (value instanceof BigDecimal && target == String.class) {
             BigDecimal bd = (BigDecimal) value;
             return bd.toPlainString();
         }
@@ -69,17 +99,39 @@
         }
 
         if (target == int.class || target == Integer.class) {
+            if(StringUtil.isNullOrNone(value)){
+                return 0;
+            }
             return Integer.parseInt(String.valueOf(value));
         }
 
         if (target == long.class || target == Long.class) {
+            if(StringUtil.isNullOrNone(value)){
+                return 0;
+            }
             return Long.parseLong(String.valueOf(value));
         }
 
         if (target == double.class || target == Double.class) {
+            if(StringUtil.isNullOrNone(value)){
+                return 0;
+            }
             return Double.parseDouble(String.valueOf(value));
         }
 
+        if (target == String[].class) {
+            return String.valueOf(value).split(",");
+        }
+
+        //1.0 String 杞� Date
+        if (value instanceof String && target == boolean.class) {
+            String bl = (String) value;
+            if ("true".equals(bl)) {
+                return true;
+            }
+            return false;
+        }
+
         return value;
     }
 }

--
Gitblit v1.8.0