sgj
2026-03-10 fbddf74600d036ba46b311147847be978904e002
出入库详单,导入,时间格式兼容yy/mm/dd
已修改1个文件
122 ■■■■■ 文件已修改
fzzy-igdss-core/src/main/java/com/fzzy/igds/service/ExportService.java 122 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;
/**
@@ -30,50 +31,6 @@
    @Resource
    private FileService fileService;
    /**
     * 读取Excel文件内容
     *
     * @param
     * @return
     */
    public List<InoutRecord> readExcel(String fileName) {
        //获取文件后缀名并判断
        String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
        //获取保存路径
        String path = fileService.getFileSavePath("TEMP");
        path = path + fileName;
        Workbook workbook = null;
        FileInputStream inputStream = null;
        try {
            // 获取Excel文件
            File excelFile = new File(path);
            if (!excelFile.exists()) {
                return null;
            }
            // 获取Excel工作簿
            inputStream = new FileInputStream(excelFile);
            workbook = getWorkbook(inputStream, fileType);
            // 读取excel中的数据
            return parseExcel(workbook);
        } catch (Exception e) {
            return null;
        } finally {
            try {
                if (null != inputStream) {
                    inputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    /**
     * 解析Excel数据
@@ -124,6 +81,7 @@
    /**
     * 根据文件后缀名类型获取对应的工作簿对象
     *
     * @param inputStream 读取文件的输入流
     * @param fileType 文件后缀名类型(xls或xlsx)
     * @return 包含文件数据的工作簿对象
@@ -162,7 +120,8 @@
            cell.setCellType(CellType.STRING);
            String time = cell.getStringCellValue().trim().replaceAll(" ","");
            if(StringUtils.isNotEmpty(time)){
                resultData.setRegisterTime(DateUtils.parseDate(time,"yyyy-MM-dd"));
                resultData.setRegisterTime(parseFlexibleDate(time));
            }
        }
@@ -366,4 +325,77 @@
        return resultData;
    }
    /**
     * 多种格式解析字符串日期
     *
     * @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年MM月dd日",   // 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) {
            // 如果所有格式都解析失败,返回 null
            return null;
        }
    }
    /**
     * 读取Excel文件内容
     *
     * @param
     * @return
     */
    public List<InoutRecord> readExcel(String fileName) {
        //获取文件后缀名并判断
        String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
        //获取保存路径
        String path = fileService.getFileSavePath("TEMP");
        path = path + fileName;
        Workbook workbook = null;
        FileInputStream inputStream = null;
        try {
            // 获取Excel文件
            File excelFile = new File(path);
            if (!excelFile.exists()) {
                return null;
            }
            // 获取Excel工作簿
            inputStream = new FileInputStream(excelFile);
            workbook = getWorkbook(inputStream, fileType);
            // 读取excel中的数据
            return parseExcel(workbook);
        } catch (Exception e) {
            return null;
        } finally {
            try {
                if (null != inputStream) {
                    inputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}