From 4f0d9bde31a80f6279e26466250da7716eec627f Mon Sep 17 00:00:00 2001
From: zs <zhoushuai@zbooksoft.com>
Date: 星期四, 18 十二月 2025 09:15:05 +0800
Subject: [PATCH] 提交成果资料按钮调整
---
src/main/java/com/zbooksoft/gdmis/common/XmlUtil.java | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 151 insertions(+), 22 deletions(-)
diff --git a/src/main/java/com/zbooksoft/gdmis/common/XmlUtil.java b/src/main/java/com/zbooksoft/gdmis/common/XmlUtil.java
index 77ce0e6..7eff310 100644
--- a/src/main/java/com/zbooksoft/gdmis/common/XmlUtil.java
+++ b/src/main/java/com/zbooksoft/gdmis/common/XmlUtil.java
@@ -1,20 +1,20 @@
package com.zbooksoft.gdmis.common;
-import org.dom4j.*;
+import com.zbooksoft.gdmis.controller.ArchivesCustomConfigController;
+import org.dom4j.Document;
+import org.dom4j.Element;
+import org.dom4j.Node;
+import org.dom4j.XPath;
import org.dom4j.io.SAXReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.multipart.MultipartFile;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
+import java.io.*;
+import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
-
-import static gnu.cajo.utils.extra.TransparentItemProxy.handler;
/**
* @Description: 瑙f瀽xml宸ュ叿绫�
@@ -22,7 +22,21 @@
* @Date: 2024/8/6
**/
public class XmlUtil {
+ private static final Logger logger = LoggerFactory.getLogger(XmlUtil.class);
+
+ /**
+ * 閫氳繃 Node 鏌ユ壘瀛愯妭鐐�
+ *
+ * @param node Node
+ * @param path xpath琛ㄨ揪寮�
+ * @return Node鍏冪礌
+ * @throws Exception
+ */
+ public static Node getNode(Node node, String path) {
+ XPath xPath = node.createXPath(path);
+ return xPath.selectSingleNode(node);
+ }
public static Document getDocument(String path) throws Exception {
FileInputStream xmlStream = null;
@@ -33,7 +47,26 @@
Document document = saxReader.read(xmlStream);
return document;
} catch (Exception e) {
+ throw new Exception("瑙f瀽xml鏂囦欢澶辫触");
+ } finally {
xmlStream.close();
+ }
+ }
+
+ public static Document getDocument(MultipartFile file) throws Exception {
+ FileInputStream xmlStream = null;
+ try {
+ // 1. 鍒涘缓涓存椂鏂囦欢
+ File tempFile = File.createTempFile("temp_", ".tmp", new File(System.getProperty("java.io.tmpdir")));
+ file.transferTo(tempFile);
+ xmlStream = new FileInputStream(tempFile);
+ SAXReader saxReader = new SAXReader();
+ Document document = saxReader.read(xmlStream);
+ if (tempFile.exists()) {
+ tempFile.delete();
+ }
+ return document;
+ } catch (Exception e) {
throw new Exception("瑙f瀽xml鏂囦欢澶辫触");
} finally {
xmlStream.close();
@@ -81,21 +114,117 @@
}
}
+ public static Integer stringToInteger(String str) throws Exception {
+ try {
+ return Integer.valueOf(str);
+ } catch (NumberFormatException e) {
+ logger.info("瀛楃涓茶浆Integer寮傚父:{}", str);
+ return 0;
+ }
+ }
+
+ public static Double stringToDouble(String str) {
+ try {
+ return Double.valueOf(str);
+ } catch (NumberFormatException e) {
+ logger.info("瀛楃涓茶浆Double寮傚父:{}", str);
+ return 0.0;
+ }
+ }
+
+ public static Date stringToDate(String str) throws Exception {
+ try {
+
+ if (str == null || "".equals(str)) {
+ return null;
+ }
+ if (str.contains("/")) {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
+ return sdf.parse(str);
+ }
+ if (str.contains("-")) {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ return sdf.parse(str);
+ }
+ return null;
+ } catch (NumberFormatException e) {
+ logger.info("瀛楃涓茶浆鏃ユ湡寮傚父:{}", str);
+ return null;
+ }
+ }
+
+ public static String getFileType(String name) {
+
+ name = name.toUpperCase();
+ String newName = name;
+ switch (name) {
+ case "ZW":
+ newName = "姝f枃";
+ break;
+ case "SP":
+ newName = "瀹℃壒";
+ break;
+ case "FT":
+ newName = "闄勫浘";
+ break;
+ case "FB":
+ newName = "闄勮〃";
+ break;
+ case "FJ":
+ newName = "闄勪欢";
+ break;
+ case "DMT":
+ newName = "澶氬獟浣�";
+ break;
+ case "SJK":
+ newName = "鏁版嵁搴�";
+ break;
+ case "RJ":
+ newName = "杞欢";
+ break;
+ case "QT":
+ newName = "鍏朵粬";
+ break;
+ }
+ return newName;
+ }
+
+
+ public static Integer getSecurityCode(String security) {
+ Integer code = null;
+ switch (security) {
+ case "缁濆瘑":
+ code = 4;
+ break;
+ case "鏈哄瘑":
+ code = 3;
+ break;
+ case "绉樺瘑":
+ code = 2;
+ break;
+ case "鍐呴儴":
+ code = 1;
+ break;
+ case "涓嶆秹瀵�":
+ code = 0;
+ break;
+ }
+ return code;
+ }
+
+
public static void main(String[] args) {
try {
- System.out.println(new Date());
-// String path = "E:\\Desktop\\鏂板缓鏂囦欢澶� (4)\\鍦拌川璧勬枡鏂囦欢鐩綍.xml";
- String path = "E:\\Desktop\\鏂板缓鏂囦欢澶� (4)\\2023\\鍦拌川璧勬枡鏂�.xml";
- Document document = getDocument(path);
- Node wjjxxNode = getNode(document, "WJJXX");
- List<Node> cgwjjxxNodeList = getNodeList(wjjxxNode, "CGWJJXX/CGWJXX");
- for (Node cgwjjxxNode : cgwjjxxNodeList){
- String cgwjmc = getNodeText(cgwjjxxNode, "WJLB");
- System.out.println(cgwjmc);
+ String filePath = "E:\\Desktop\\鏂板缓鏂囦欢澶� (5)\\b01_0095.ml";
+ try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
+ String line;
+ while ((line = br.readLine()) != null) {
+ // 澶勭悊姣忎竴琛�
+ System.out.println(line);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
}
- System.out.println(new Date());
-
-
} catch (Exception e) {
System.out.println(e.getMessage());
}
--
Gitblit v1.9.1