ccjgmwz 3 anni fa
parent
commit
60b7dded8d

+ 37 - 2
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/util/XmlUtil.java

@@ -95,6 +95,41 @@ public class XmlUtil implements InitializingBean {
         }
         return "NG";
     }
+    //将字符串string类型转换成xml文件
+    public String strChangeXMLs(String str, String name) throws IOException {
+        SAXReader saxReader = new SAXReader();
+        Document document;
+        try {
+            document = DocumentHelper.parseText(str);
+            document.setXMLEncoding("GBK");
+            document.asXML();
+//            document = saxReader.read(new ByteArrayInputStream(str.getBytes("UTF-8")));
+            OutputFormat format = OutputFormat.createPrettyPrint();
+            format.setEncoding("GBK");
+//            File file = new File(new String(("templates" + File.separator + name + ".xml").getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8));
+//            if (!file.exists()) {
+//                boolean flag = file.mkdirs();
+//            }
+            Path path = FileSystems.getDefault().getPath(new File("templates" + File.separator + name + ".xml").getAbsoluteFile().getPath());
+            File file = new File(String.valueOf(path));
+            /** 将document中的内容写入文件中 */
+            OutputStream out = new FileOutputStream(file);
+            Writer wr = new OutputStreamWriter(out,"GBK");
+            XMLWriter writer = new XMLWriter(wr, format);
+            FileInputStream fileInputStream = new FileInputStream(String.valueOf(path));
+            writer.write(document);
+            writer.close();
+            out.close();
+            wr.close();
+            MultipartFile multipartFile = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
+            String returnFile = upload(multipartFile, name);
+            file.delete();
+            return returnFile;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return "NG";
+    }
 
     public String readXml(PaymentManagement paymentManagement) {
 
@@ -263,7 +298,7 @@ public class XmlUtil implements InitializingBean {
                 "<Spxx>\n" +
                 "\n" +
                 "\n" +
-                "-<Sph>\n" +
+                "<Sph>\n" +
                 "\n" +
                 "<Xh>1</Xh>\n" +
                 "\n" +
@@ -305,7 +340,7 @@ public class XmlUtil implements InitializingBean {
                 "\n" +
                 "</Kp>";
         try {
-            String returnFile = strChangeXML(s, paymentManagement.getId());
+            String returnFile = strChangeXMLs(s, paymentManagement.getId());
             return returnFile;
         } catch (Exception e) {
             e.printStackTrace();