From fbddf74600d036ba46b311147847be978904e002 Mon Sep 17 00:00:00 2001
From: sgj <1442489573@qq.com>
Date: 星期二, 10 三月 2026 10:32:58 +0800
Subject: [PATCH] 出入库详单,导入,时间格式兼容yy/mm/dd

---
 fzzy-igdss-core/src/main/java/com/fzzy/igds/service/ExportService.java |  613 +++++++++++++++++++++++++++++--------------------------
 1 files changed, 324 insertions(+), 289 deletions(-)

diff --git a/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/ExportService.java b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/ExportService.java
index b2a4ed9..985e08a 100644
--- a/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/ExportService.java
+++ b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/ExportService.java
@@ -15,6 +15,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -31,6 +32,329 @@
     @Resource
     private FileService fileService;
 
+    /**
+     * 瑙f瀽Excel鏁版嵁
+     *
+     * @param workbook
+     * @return
+     */
+    private static List<InoutRecord> parseExcel(Workbook workbook) throws Exception {
+        List<InoutRecord> resultDataList = new ArrayList<>();
+
+        // 瑙f瀽sheet
+        for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {
+            Sheet sheet = workbook.getSheetAt(sheetNum);
+
+            // 鏍¢獙sheet鏄惁鍚堟硶
+            if (sheet == null) {
+                continue;
+            }
+
+            // 鑾峰彇绗竴琛屾暟鎹�,涓嶇敤澶勭悊
+            int firstRowNum = sheet.getFirstRowNum();
+
+            // 瑙f瀽姣忎竴琛岀殑鏁版嵁锛屾瀯閫犳暟鎹璞�
+            int rowStart = firstRowNum + 2;
+            int rowEnd = sheet.getPhysicalNumberOfRows();
+
+            //瀹氫箟鍙橀噺,鐢ㄤ簬鍒ゆ柇鏁版嵁鏄惁瑙f瀽瀹�
+            boolean flag = false;
+
+            for (int rowNum = rowStart; rowNum < rowEnd; rowNum++) {
+                Row row = sheet.getRow(rowNum);
+
+                if (null == row) {
+                    //姝よ涓虹┖锛屽垯涔嬪悗涓嶅啀瑙f瀽锛屽垽瀹氫负瑙f瀽瀹屾垚
+                    flag = true;
+                    break;
+                }
+
+                InoutRecord resultData = convertRowToData(row);
+                resultDataList.add(resultData);
+            }
+            if (flag) {
+                break;
+            }
+        }
+        return resultDataList;
+    }
+
+    /**
+     * 鏍规嵁鏂囦欢鍚庣紑鍚嶇被鍨嬭幏鍙栧搴旂殑宸ヤ綔绨垮璞�
+     *
+     * @param inputStream 璇诲彇鏂囦欢鐨勮緭鍏ユ祦
+     * @param fileType    鏂囦欢鍚庣紑鍚嶇被鍨嬶紙xls鎴杧lsx锛�
+     * @return 鍖呭惈鏂囦欢鏁版嵁鐨勫伐浣滅翱瀵硅薄
+     * @throws IOException
+     */
+    public static Workbook getWorkbook(InputStream inputStream, String fileType) throws IOException {
+        Workbook workbook = null;
+        if (fileType.equalsIgnoreCase(XLS)) {
+            workbook = new HSSFWorkbook(inputStream);
+        } else if (fileType.equalsIgnoreCase(XLSX)) {
+            workbook = new XSSFWorkbook(inputStream);
+        }
+        return workbook;
+    }
+
+    /**
+     * 鎻愬彇姣忎竴琛屼腑闇�瑕佺殑鏁版嵁锛屾瀯閫犳垚涓轰竴涓粨鏋滄暟鎹璞�
+     *
+     * @param row
+     * @return
+     */
+    private static InoutRecord convertRowToData(Row row) throws Exception {
+        InoutRecord resultData = new InoutRecord();
+
+        Cell cell;
+        int cellNum = 0;
+
+        //绗竴鍒楀簭鍙凤紝涓嶅仛澶勭悊
+        cell = row.getCell(cellNum++);
+
+        //鏃ユ湡
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setCustomerName("");
+        } else {
+            cell.setCellType(CellType.STRING);
+            String time = cell.getStringCellValue().trim().replaceAll(" ", "");
+            if (StringUtils.isNotEmpty(time)) {
+
+                resultData.setRegisterTime(parseFlexibleDate(time));
+            }
+        }
+
+        //绫诲瀷
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setType("");
+        } else {
+            cell.setCellType(CellType.STRING);
+            String type = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(type)) {
+                resultData.setType(type);
+            }
+        }
+
+        //杞︾墝鍙�
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setPlateNum("");
+        } else {
+            cell.setCellType(CellType.STRING);
+            String plateNum = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(plateNum)) {
+                resultData.setPlateNum(plateNum);
+            }
+        }
+
+        //鎵胯繍浜�
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setUserName("");
+        } else {
+            cell.setCellType(CellType.STRING);
+            String userName = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(userName)) {
+                resultData.setUserName(userName);
+            }
+        }
+
+        //寰�鏉ュ崟浣�
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setCustomerName("");
+        } else {
+            cell.setCellType(CellType.STRING);
+            String customerName = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(customerName)) {
+                resultData.setCustomerName(customerName);
+            }
+        }
+
+        //閫氱煡鍗曠紪鐮�
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setNoticeId("");
+        } else {
+            cell.setCellType(CellType.STRING);
+            String noticeId = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(noticeId)) {
+                resultData.setNoticeId(noticeId);
+            }
+        }
+
+        //瑁呭嵏浠撳簱
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setDepotId("");
+        } else {
+            cell.setCellType(CellType.STRING);
+            String depotName = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(depotName)) {
+                resultData.setDepotId(depotName);
+            }
+        }
+
+        //绮鍝佺
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setFoodVariety("");
+        } else {
+            cell.setCellType(CellType.STRING);
+            String foodVariety = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(foodVariety)) {
+                resultData.setFoodVariety(FoodVariety.getCode(foodVariety.trim()));
+            }
+        }
+
+        //绮骞翠唤
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setFoodYear("");
+        } else {
+            cell.setCellType(CellType.STRING);
+            String year = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(year)) {
+                resultData.setFoodYear(year);
+            }
+        }
+
+        //婊¤溅閲嶉噺
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setFullWeight(0.0);
+        } else {
+            cell.setCellType(CellType.STRING);
+            String fullWeight = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(fullWeight)) {
+                resultData.setFullWeight(Double.valueOf(fullWeight));
+            }
+        }
+
+        //绌鸿溅閲嶉噺
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setEmptyWeight(0.0);
+        } else {
+            cell.setCellType(CellType.STRING);
+            String emptyWeight = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(emptyWeight)) {
+                resultData.setEmptyWeight(Double.valueOf(emptyWeight));
+            }
+        }
+
+        //鎵i噸
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setDeOther(0.0);
+        } else {
+            cell.setCellType(CellType.STRING);
+            String deOther = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(deOther)) {
+                resultData.setDeOther(Double.valueOf(deOther));
+            }
+        }
+
+        //缁撶畻閲嶉噺
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setSettleWeight(0.0);
+            resultData.setRecordWeight(0.0);
+        } else {
+            cell.setCellType(CellType.STRING);
+            String recordWeight = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(recordWeight)) {
+                resultData.setSettleWeight(Double.valueOf(recordWeight));
+                resultData.setRecordWeight(Double.valueOf(recordWeight));
+            }
+        }
+
+        //鍗曚环
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setPrice(0.0);
+        } else {
+            cell.setCellType(CellType.STRING);
+            String price = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(price)) {
+                resultData.setPrice(Double.valueOf(price));
+            }
+        }
+
+        //姘村垎
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setPerWet(0.0);
+        } else {
+            cell.setCellType(CellType.STRING);
+            String perWet = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(perWet)) {
+                resultData.setPerWet(Double.valueOf(perWet));
+            }
+        }
+
+        //鏉傝川
+        cell = row.getCell(cellNum++);
+        if (cell == null || cell.getCellType() == CellType.BLANK) {
+            resultData.setPerImpurity(0.0);
+        } else {
+            cell.setCellType(CellType.STRING);
+            String perImpurity = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(perImpurity)) {
+                resultData.setPerImpurity(Double.valueOf(perImpurity));
+            }
+        }
+
+        //澶囨敞
+        cell = row.getCell(cellNum++);
+        if (null == cell || cell.getCellType() == CellType.BLANK) {
+            resultData.setRemarks("");
+        } else {
+            cell.setCellType(CellType.STRING);
+            String remarks = cell.getStringCellValue().trim();
+            if (StringUtils.isNotEmpty(remarks)) {
+                resultData.setRemarks(remarks);
+            }
+        }
+
+        if (null != resultData.getFullWeight() && null != resultData.getEmptyWeight()) {
+            resultData.setNetWeight(resultData.getFullWeight() - resultData.getEmptyWeight());
+        }
+        return resultData;
+    }
+
+    /**
+     * 澶氱鏍煎紡瑙f瀽瀛楃涓叉棩鏈�
+     *
+     * @param dateStr 鏃ユ湡瀛楃涓�
+     * @author sgj
+     * @since 2026/03/10
+     */
+    private static Date parseFlexibleDate(String dateStr) {
+        if (StringUtils.isEmpty(dateStr)) {
+            return null;
+        }
+
+        // 瀹氫箟鏀寔鐨勬棩鏈熸牸寮�
+        String[] parsePatterns = new String[]{
+                "yyyy-MM-dd",      // 2026-01-06
+                "yyyy/MM/dd",      // 2026/01/06
+//                "yyyy骞碝M鏈坉d鏃�",   // 2026 骞� 01 鏈� 06 鏃�
+                "yyyy-MM-dd HH:mm:ss",  // 2026-01-06 12:00:00
+                "yyyy/MM/dd HH:mm:ss",  // 2026/01/06 12:00:00
+                "yyyy-MM-dd HH:mm",     // 2026-01-06 12:00
+                "yyyy/MM/dd HH:mm"      // 2026/01/06 12:00
+        };
+
+        try {
+            return DateUtils.parseDateStrictly(dateStr, parsePatterns);
+        } catch (Exception e) {
+            // 濡傛灉鎵�鏈夋牸寮忛兘瑙f瀽澶辫触锛岃繑鍥� null
+            return null;
+        }
+    }
 
     /**
      * 璇诲彇Excel鏂囦欢鍐呭
@@ -74,293 +398,4 @@
             }
         }
     }
-
-    /**
-     * 瑙f瀽Excel鏁版嵁
-     *
-     * @param workbook
-     * @return
-     */
-    private static List<InoutRecord> parseExcel(Workbook workbook) throws Exception{
-        List<InoutRecord> resultDataList = new ArrayList<>();
-
-        // 瑙f瀽sheet
-        for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {
-            Sheet sheet = workbook.getSheetAt(sheetNum);
-
-            // 鏍¢獙sheet鏄惁鍚堟硶
-            if (sheet == null) {
-                continue;
-            }
-
-            // 鑾峰彇绗竴琛屾暟鎹�,涓嶇敤澶勭悊
-            int firstRowNum = sheet.getFirstRowNum();
-
-            // 瑙f瀽姣忎竴琛岀殑鏁版嵁锛屾瀯閫犳暟鎹璞�
-            int rowStart = firstRowNum + 2;
-            int rowEnd = sheet.getPhysicalNumberOfRows();
-
-            //瀹氫箟鍙橀噺,鐢ㄤ簬鍒ゆ柇鏁版嵁鏄惁瑙f瀽瀹�
-            boolean flag = false;
-
-            for (int rowNum = rowStart; rowNum < rowEnd; rowNum++) {
-                Row row = sheet.getRow(rowNum);
-
-                if (null == row) {
-                    //姝よ涓虹┖锛屽垯涔嬪悗涓嶅啀瑙f瀽锛屽垽瀹氫负瑙f瀽瀹屾垚
-                    flag = true;
-                    break;
-                }
-
-                InoutRecord resultData = convertRowToData(row);
-                resultDataList.add(resultData);
-            }
-            if(flag){
-                break;
-            }
-        }
-        return resultDataList;
-    }
-
-    /**
-     * 鏍规嵁鏂囦欢鍚庣紑鍚嶇被鍨嬭幏鍙栧搴旂殑宸ヤ綔绨垮璞�
-     * @param inputStream 璇诲彇鏂囦欢鐨勮緭鍏ユ祦
-     * @param fileType 鏂囦欢鍚庣紑鍚嶇被鍨嬶紙xls鎴杧lsx锛�
-     * @return 鍖呭惈鏂囦欢鏁版嵁鐨勫伐浣滅翱瀵硅薄
-     * @throws IOException
-     */
-    public static Workbook getWorkbook(InputStream inputStream, String fileType) throws IOException {
-        Workbook workbook = null;
-        if (fileType.equalsIgnoreCase(XLS)) {
-            workbook = new HSSFWorkbook(inputStream);
-        } else if (fileType.equalsIgnoreCase(XLSX)) {
-            workbook = new XSSFWorkbook(inputStream);
-        }
-        return workbook;
-    }
-
-    /**
-     * 鎻愬彇姣忎竴琛屼腑闇�瑕佺殑鏁版嵁锛屾瀯閫犳垚涓轰竴涓粨鏋滄暟鎹璞�
-     *
-     * @param row
-     * @return
-     */
-    private static InoutRecord convertRowToData(Row row) throws Exception {
-        InoutRecord resultData = new InoutRecord();
-        
-        Cell cell;
-        int cellNum = 0;
-
-        //绗竴鍒楀簭鍙凤紝涓嶅仛澶勭悊
-        cell = row.getCell(cellNum++);
-
-        //鏃ユ湡
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setCustomerName("");
-        }else {
-            cell.setCellType(CellType.STRING);
-            String time = cell.getStringCellValue().trim().replaceAll(" ","");
-            if(StringUtils.isNotEmpty(time)){
-                resultData.setRegisterTime(DateUtils.parseDate(time,"yyyy-MM-dd"));
-            }
-        }
-
-        //绫诲瀷
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setType("");
-        }else {
-            cell.setCellType(CellType.STRING);
-            String type = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(type)){
-                resultData.setType(type);
-            }
-        }
-
-        //杞︾墝鍙�
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setPlateNum("");
-        }else {
-            cell.setCellType(CellType.STRING);
-            String plateNum = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(plateNum)){
-                resultData.setPlateNum(plateNum);
-            }
-        }
-
-        //鎵胯繍浜�
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setUserName("");
-        }else {
-            cell.setCellType(CellType.STRING);
-            String userName = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(userName)){
-                resultData.setUserName(userName);
-            }
-        }
-
-        //寰�鏉ュ崟浣�
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setCustomerName("");
-        }else {
-            cell.setCellType(CellType.STRING);
-            String customerName = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(customerName)){
-                resultData.setCustomerName(customerName);
-            }
-        }
-
-        //閫氱煡鍗曠紪鐮�
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setNoticeId("");
-        }else {
-            cell.setCellType(CellType.STRING);
-            String noticeId = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(noticeId)){
-                resultData.setNoticeId(noticeId);
-            }
-        }
-
-        //瑁呭嵏浠撳簱
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setDepotId("");
-        }else {
-            cell.setCellType(CellType.STRING);
-            String depotName = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(depotName)){
-                resultData.setDepotId(depotName);
-            }
-        }
-
-        //绮鍝佺
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setFoodVariety("");
-        }else {
-            cell.setCellType(CellType.STRING);
-            String foodVariety = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(foodVariety)){
-                resultData.setFoodVariety(FoodVariety.getCode(foodVariety.trim()));
-            }
-        }
-
-        //绮骞翠唤
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setFoodYear("");
-        }else {
-            cell.setCellType(CellType.STRING);
-            String year = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(year)){
-                resultData.setFoodYear(year);
-            }
-        }
-
-        //婊¤溅閲嶉噺
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setFullWeight(0.0);
-        }else {
-            cell.setCellType(CellType.STRING);
-            String fullWeight = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(fullWeight)){
-                resultData.setFullWeight(Double.valueOf(fullWeight));
-            }
-        }
-
-        //绌鸿溅閲嶉噺
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setEmptyWeight(0.0);
-        }else {
-            cell.setCellType(CellType.STRING);
-            String emptyWeight = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(emptyWeight)){
-                resultData.setEmptyWeight(Double.valueOf(emptyWeight));
-            }
-        }
-
-        //鎵i噸
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setDeOther(0.0);
-        }else {
-            cell.setCellType(CellType.STRING);
-            String deOther = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(deOther)){
-                resultData.setDeOther(Double.valueOf(deOther));
-            }
-        }
-
-        //缁撶畻閲嶉噺
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setSettleWeight(0.0);
-            resultData.setRecordWeight(0.0);
-        }else {
-            cell.setCellType(CellType.STRING);
-            String recordWeight = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(recordWeight)){
-                resultData.setSettleWeight(Double.valueOf(recordWeight));
-                resultData.setRecordWeight(Double.valueOf(recordWeight));
-            }
-        }
-
-        //鍗曚环
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setPrice(0.0);
-        }else {
-            cell.setCellType(CellType.STRING);
-            String price = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(price)){
-                resultData.setPrice(Double.valueOf(price));
-            }
-        }
-
-        //姘村垎
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setPerWet(0.0);
-        }else {
-            cell.setCellType(CellType.STRING);
-            String perWet = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(perWet)){
-                resultData.setPerWet(Double.valueOf(perWet));
-            }
-        }
-
-        //鏉傝川
-        cell = row.getCell(cellNum++);
-        if(cell == null || cell.getCellType() == CellType.BLANK){
-            resultData.setPerImpurity(0.0);
-        }else {
-            cell.setCellType(CellType.STRING);
-            String perImpurity = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(perImpurity)){
-                resultData.setPerImpurity(Double.valueOf(perImpurity));
-            }
-        }
-
-        //澶囨敞
-        cell = row.getCell(cellNum++);
-        if(null ==  cell || cell.getCellType() == CellType.BLANK){
-            resultData.setRemarks("");
-        }else {
-            cell.setCellType(CellType.STRING);
-            String remarks = cell.getStringCellValue().trim();
-            if(StringUtils.isNotEmpty(remarks)){
-                resultData.setRemarks(remarks);
-            }
-        }
-
-        return resultData;
-    }
-
 }

--
Gitblit v1.9.3