From 64b14b0549344f13b191e2c26ed199f62655c43f Mon Sep 17 00:00:00 2001
From: chengf <cgf12138@163.com>
Date: 星期三, 25 二月 2026 10:12:46 +0800
Subject: [PATCH] 导入测试

---
 java110-bean/src/main/java/com/java110/dto/importData/Vtil.java |  201 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 197 insertions(+), 4 deletions(-)

diff --git a/java110-bean/src/main/java/com/java110/dto/importData/Vtil.java b/java110-bean/src/main/java/com/java110/dto/importData/Vtil.java
index 3d46854..26c9773 100644
--- a/java110-bean/src/main/java/com/java110/dto/importData/Vtil.java
+++ b/java110-bean/src/main/java/com/java110/dto/importData/Vtil.java
@@ -1,5 +1,6 @@
 package com.java110.dto.importData;
 
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.YearMonth;
@@ -8,6 +9,7 @@
 import java.time.format.ResolverStyle;
 import java.time.temporal.TemporalAdjusters;
 import java.util.Calendar;
+import java.util.Date;
 import java.util.Locale;
 
 public class Vtil {
@@ -84,8 +86,17 @@
         }
     }
 
-
-    public static String defaultValueToDate(Object o, String state) {
+    public static BigDecimal defaultNum(Object o) {
+        if (o == null || o.toString().isEmpty()) {
+            return new BigDecimal(0);
+        }
+        try {
+            return o == null ? new BigDecimal(0) : new BigDecimal(o.toString());
+        }catch (Exception e) {
+            throw new IllegalArgumentException("鏁板�艰浆鎹㈤敊璇紒锛�" + o.toString());
+        }
+    }
+    public static String defaultValueToDate(Object o, String state, Object value) {
         // 绌哄�肩洿鎺ヨ繑鍥瀗ull锛堝師鏈夐�昏緫锛�
         if (o == null || o.toString().isEmpty() || o.toString().equals("0")) {
             return null;
@@ -112,10 +123,192 @@
                 return lastDay.toString();
             }
         } catch (DateTimeParseException e) {
-            // 涓嶆槸20xx/01鏍煎紡锛屽拷鐣ヨВ鏋愬紓甯革紝鎵ц鍘熸湁閫昏緫
+            try {
+                ymFormatter = DateTimeFormatter.ofPattern("yyyy-M")
+                        .withLocale(Locale.CHINA)
+                        .withResolverStyle(ResolverStyle.LENIENT); // 瀹芥澗瑙f瀽锛屽吋瀹瑰悇绉嶅悎娉曟牸寮�
+
+                // 鍏堣В鏋愪负YearMonth锛堜笓闂ㄥ鐞嗗勾鏈堢殑绫伙紝涓嶄細缂哄皯鏃ユ湡缁村害锛�
+                YearMonth yearMonth = YearMonth.parse(input, ymFormatter);
+
+                // 鏍规嵁state鍙傛暟澶勭悊鏃ユ湡
+                if ("start".equals(state)) {
+                    // state涓簊tart鏃惰繑鍥炲綋鏈堢涓�澶�
+                    LocalDate firstDay = yearMonth.atDay(1);
+                    return firstDay.toString();
+                } else if ("end".equals(state)) {
+                    // state涓篹nd鏃惰繑鍥炲綋鏈堟渶鍚庝竴澶�
+                    LocalDate lastDay = yearMonth.atEndOfMonth();
+                    return lastDay.toString();
+                }
+            } catch (DateTimeParseException e1) {
+                try {
+                    ymFormatter = DateTimeFormatter.ofPattern("yyyy.M")
+                            .withLocale(Locale.CHINA)
+                            .withResolverStyle(ResolverStyle.LENIENT); // 瀹芥澗瑙f瀽锛屽吋瀹瑰悇绉嶅悎娉曟牸寮�
+
+                    // 鍏堣В鏋愪负YearMonth锛堜笓闂ㄥ鐞嗗勾鏈堢殑绫伙紝涓嶄細缂哄皯鏃ユ湡缁村害锛�
+                    YearMonth yearMonth = YearMonth.parse(input, ymFormatter);
+
+                    // 鏍规嵁state鍙傛暟澶勭悊鏃ユ湡
+                    if ("start".equals(state)) {
+                        // state涓簊tart鏃惰繑鍥炲綋鏈堢涓�澶�
+                        LocalDate firstDay = yearMonth.atDay(1);
+                        return firstDay.toString();
+                    } else if ("end".equals(state)) {
+                        // state涓篹nd鏃惰繑鍥炲綋鏈堟渶鍚庝竴澶�
+                        LocalDate lastDay = yearMonth.atEndOfMonth();
+                        return lastDay.toString();
+                    }
+                } catch (Exception e3) {
+                    try {
+                        try {
+                            // 灏濊瘯灏嗗璞¤浆鎹负鏁板瓧锛堝吋瀹笶xcel鏃ユ湡搴忓垪鍙凤紝濡�44747锛�
+                            double excelDateNum = Double.parseDouble(o.toString());
+
+                            // Excel 1900鏃ユ湡绯荤粺鍩哄噯锛堜慨姝i棸鏃ug锛屽疄闄呭熀鍑嗘槸1899-12-30锛�
+                            Calendar calendar = Calendar.getInstance();
+                            calendar.set(1899, 11, 30, 0, 0, 0); // 鏈堜唤浠�0寮�濮嬶紝11浠h〃12鏈�
+                            calendar.set(Calendar.MILLISECOND, 0);
+
+                            // 璁$畻瀵瑰簲鐨勫疄闄呮棩鏈�
+                            calendar.add(Calendar.DAY_OF_MONTH, (int) excelDateNum);
+
+                            // 鏍煎紡鍖栦负yyyy-MM-dd鐨勬棩鏈熷瓧绗︿覆
+                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+                            return sdf.format(calendar.getTime());
+                        } catch (NumberFormatException e6) {
+                            // 闈炴暟瀛楃被鍨嬶紝鎵ц鍘熸湁閫昏緫杩斿洖toString()
+                            return defaultValue(value, null);
+                        }
+                    } catch (Exception e2) {
+
+                    }
+                }
+            }
         }
 
         // 闈炵洰鏍囨牸寮忔垨state涓嶅尮閰嶆椂锛岃繑鍥炲師濮嬪瓧绗︿覆锛堝師鏈夐�昏緫锛�
-        return input;
+        return defaultValue(value, null);
+    }
+
+    public static String defaultValueToDate(Object o, String state) {
+        return defaultValueToDate(o, state, o);
+    }
+
+    /**
+     * 澶勭悊鏁板瓧瀛楃涓诧紝鎸夋寚瀹氬皬鏁颁綅鏁版埅鍙栵紝鐗规畩鍊艰繑鍥為粯璁ゅ��
+     * @param count 寰呭鐞嗙殑鏁板瓧瀛楃涓�
+     * @param i 淇濈暀鐨勫皬鏁颁綅鏁�
+     * @param value 榛樿杩斿洖鍊硷紙褰揷ount涓虹┖/涓簄ull/涓�0鏃讹級
+     * @return 澶勭悊鍚庣殑瀛楃涓�
+     */
+    public static String processCount(String count, Integer i, String value) {
+        // 1. 澶勭悊count涓虹┖銆乶ull鎴�"0"鐨勬儏鍐碉紝鐩存帴杩斿洖榛樿鍊紇alue
+        if (count == null || count.trim().isEmpty() || "0".equals(count.trim())) {
+            return value;
+        }
+
+        // 2. 澶勭悊淇濈暀灏忔暟浣嶆暟涓簄ull鎴栬礋鏁扮殑杈圭晫鎯呭喌锛堥粯璁や繚鐣�0浣嶅皬鏁帮級
+        int keepDecimalPlaces = (i == null || i < 0) ? 0 : i;
+
+        // 3. 鍒嗗壊鏁存暟閮ㄥ垎鍜屽皬鏁伴儴鍒�
+        String[] parts = count.split("\\.");
+        String integerPart = parts[0];
+        String decimalPart = parts.length > 1 ? parts[1] : "";
+
+        // 4. 鎴彇灏忔暟閮ㄥ垎鍒版寚瀹氶暱搴︼紙涓嶈冻鍒欒ˉ0锛岃秴杩囧垯鎴柇锛�
+        StringBuilder resultBuilder = new StringBuilder(integerPart);
+        if (keepDecimalPlaces > 0) {
+            resultBuilder.append(".");
+            // 鎴彇灏忔暟閮ㄥ垎锛岄暱搴︿笉瓒呰繃keepDecimalPlaces
+            String truncatedDecimal = decimalPart.length() >= keepDecimalPlaces
+                    ? decimalPart.substring(0, keepDecimalPlaces)
+                    : String.format("%-" + keepDecimalPlaces + "s", decimalPart).replace(' ', '0');
+            resultBuilder.append(truncatedDecimal);
+        }
+
+        return resultBuilder.toString();
+    }
+
+    /**
+     * 澧炲己鐗堟棩鏈熷鐞嗗伐鍏锋柟娉�
+     * @param date 鍘熷鏃ユ湡瀵硅薄锛堝彲涓簄ull鎴栨棤鏁堝璞★級
+     * @param test 鏍囪瘑锛歴tart-褰撴湀绗竴澶╋紱end-褰撴湀鏈�鍚庝竴澶╋紱绌�/null-鍘熸棩鏈�
+     * @param format 鐩爣鏃ユ湡鏍煎紡锛堝yyyy-MM-dd HH:mm:ss锛�
+     * @param timeText 鏃跺垎绉掓帶鍒讹細start-00:00:00锛沞nd-23:59:59锛堥�昏緫鍚宼est锛�
+     * @param configDate date寮傚父鏃惰繑鍥炵殑鍏滃簳鍊�
+     * @return 澶勭悊鍚庣殑鏃ユ湡瀛楃涓诧紙寮傚父鏃惰繑鍥瀋onfigDate锛�
+     */
+    public static String processDateEnhanced(Date date, String test, String format, String timeText, String configDate) {
+        // 1. 浼樺厛澶勭悊date涓虹┖/寮傚父鐨勬儏鍐碉紝鐩存帴杩斿洖鍏滃簳鍊糲onfigDate
+        if (date == null) {
+            return configDate;
+        }
+
+        // 2. 鏍¢獙鏍煎紡鍙傛暟锛岃嫢鏍煎紡涓虹┖/鏃犳晥锛屼篃杩斿洖鍏滃簳鍊�
+        if (format == null || format.trim().isEmpty()) {
+            return configDate;
+        }
+
+        Calendar calendar = null;
+        try {
+            // 3. 灏濊瘯鍒濆鍖朇alendar骞惰缃棩鏈燂紝鎹曡幏瑙f瀽/杞崲寮傚父
+            calendar = Calendar.getInstance();
+            calendar.setTime(date);
+        } catch (Exception e) {
+            // date鏃犳硶瑙f瀽锛堝闈炴爣鍑嗘棩鏈熷璞★級锛岃繑鍥炲厹搴曞��
+            return configDate;
+        }
+
+        // 4. 缁熶竴澶勭悊test鍜宼imeText鐨勫ぇ灏忓啓锛岄伩鍏嶅尮閰嶉棶棰�
+        String testNormalized = (test == null) ? "" : test.trim().toLowerCase();
+        String timeTextNormalized = (timeText == null) ? "" : timeText.trim().toLowerCase();
+
+        // 5. 璋冩暣鏃ユ湡锛坰tart/end锛�
+        if ("start".equals(testNormalized)) {
+            // start锛氬綋鏈堢涓�澶�
+            calendar.set(Calendar.DAY_OF_MONTH, 1);
+        } else if ("end".equals(testNormalized)) {
+            // end锛氬綋鏈堟渶鍚庝竴澶╋紙鑷姩閫傞厤澶у皬鏈�/2鏈堬級
+            calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
+        }
+        // test涓虹┖/鍏朵粬鍊硷細涓嶈皟鏁存棩鏈�
+
+        // 6. 璋冩暣鏃跺垎绉掞紙鍩轰簬timeText锛�
+        if ("start".equals(timeTextNormalized)) {
+            // start锛�00:00:00.000
+            calendar.set(Calendar.HOUR_OF_DAY, 0);
+            calendar.set(Calendar.MINUTE, 0);
+            calendar.set(Calendar.SECOND, 0);
+            calendar.set(Calendar.MILLISECOND, 0);
+        } else if ("end".equals(timeTextNormalized)) {
+            // end锛�23:59:59.999
+            calendar.set(Calendar.HOUR_OF_DAY, 23);
+            calendar.set(Calendar.MINUTE, 59);
+            calendar.set(Calendar.SECOND, 59);
+            calendar.set(Calendar.MILLISECOND, 999);
+        }
+        // timeText涓虹┖/鍏朵粬鍊硷細涓嶈皟鏁存椂鍒嗙
+
+        // 7. 鎸夋寚瀹氭牸寮忔牸寮忓寲鏃ユ湡骞惰繑鍥�
+        try {
+            SimpleDateFormat sdf = new SimpleDateFormat(format);
+            return sdf.format(calendar.getTime());
+        } catch (Exception e) {
+            // 鏍煎紡鍖栧け璐ワ紙濡傛牸寮忓瓧绗︿覆闈炴硶锛夛紝杩斿洖鍏滃簳鍊�
+            return configDate;
+        }
+    }
+
+    public static String getMonth(String month) {
+        try {
+            if (month.length() == 1) {
+                month = "0" + month;
+            }
+        } catch (Exception e) {
+            return month;
+        }
+        return month;
     }
 }

--
Gitblit v1.8.0