Browse Source

保存xml和json文件

lgs 1 year ago
parent
commit
51f8b6ae3d

+ 17 - 39
src/main/java/com/kexun/service/impl/FileServiceImpl.java

@@ -33,6 +33,11 @@ public class FileServiceImpl {
     @Value("${report.file.jsonTargetPath}")
     private String jsonTargetPath;
 
+    /**
+     * 上传文件
+     * @param context
+     * @param filename
+     */
     private void writeFile(String context, String filename) {
         try {
             IOUtils.write(context, new FileOutputStream(jsonTargetPath + filename), "UTF-8");
@@ -42,56 +47,29 @@ public class FileServiceImpl {
     }
 
     /**
-     * 保存XML文件
+     * 保存xml文件和json文件
      * @param reportInfo
-     * @param context
+     * @param xmlContext
+     * @param jsonContext
      * @param fileName
      */
-    public void saveAndWriteXMLFile(ReportInfo reportInfo,String context,String fileName){
+    public void saveAndWriteFile(ReportInfo reportInfo,String xmlContext,String jsonContext,String fileName){
         ReportFileEntity reportFileEntity = new ReportFileEntity();
         reportFileEntity.setFileNameXml(fileName+".xml");
-        saveAndWriteCommonFile(reportFileEntity,reportInfo,context,fileName);
-    }
-
-    /**
-     * 保存JSON文件
-     * @param reportInfo
-     * @param context
-     * @param fileName
-     */
-    public void saveAndWriteJsonFile(ReportInfo reportInfo,String context,String fileName){
-        ReportFileEntity reportFileEntity = new ReportFileEntity();
-        reportFileEntity.setFileNameTxt(fileName+".txt");
-        saveAndWriteCommonFile(reportFileEntity,reportInfo,context,fileName);
-    }
-
-    /**
-     * 保存模型文件
-     * @param reportInfo
-     * @param context
-     * @param fileName
-     */
-    private void saveAndWriteModelFile(ReportInfo reportInfo,String context,String fileName){
-        ReportFileEntity reportFileEntity = new ReportFileEntity();
-        reportFileEntity.setFileNameModel(fileName+".txt");
-        saveAndWriteCommonFile(reportFileEntity,reportInfo,context,fileName);
-    }
-    /**
-     * 保存文件信息到report_file表和上传文件到指定路径
-     * @param reportInfo
-     * @param context
-     * @param fileName
-     */
-    private void saveAndWriteCommonFile(ReportFileEntity reportFileEntity,ReportInfo reportInfo,String context,String fileName){
         reportFileEntity.setHeadInfId(reportInfo.getId());
         reportFileEntity.setRptNo(reportInfo.getRptNo());
         reportFileEntity.setBusinessId(reportInfo.getBusinessId());
         reportFileEntity.setBusinessNum(reportInfo.getBusinessNum());
-        reportFileEntity.setFileName(fileName);
+        reportFileEntity.setFileNameXml(fileName+".xml");
+        reportFileEntity.setFileNameTxt(fileName+".txt");
         //保存文件信息表
-        reportFileService.save(reportFileEntity);
+        reportFileService.saveOrUpdate(reportFileEntity);
         //上传文件到服务器的目录
-        writeFile(context,fileName);
+        writeFile(xmlContext,fileName+".xml");
+        writeFile(jsonContext,fileName+".txt");
     }
 
+
+
+
 }

+ 2 - 4
src/main/java/com/kexun/task/ReportParseJobHandler.java

@@ -83,10 +83,8 @@ public class ReportParseJobHandler {
                     //解析xml文件
                     fileName = fileName.substring(0, fileName.indexOf("."));
                     ReportParseDTO reportParseDTO = parseHandleService.parseHandle(xmlContext);
-                    //保存xml文件
-                    fileService.saveAndWriteXMLFile(reportInfo,xmlContext,fileName);
-                    //解析完成后,需要把解析文件放到对应的目录去,然后保存到数据库中,提供给模型使用。
-                    fileService.saveAndWriteJsonFile(reportInfo,xmlContext,fileName);
+                    //保存xml文件和解析文件
+                    fileService.saveAndWriteFile(reportInfo,xmlContext,reportParseDTO.getParseJson(),fileName);
                     //修改解析报文信息的状态
                     reportInfoDTO.setStatus(ReportStatusEnum.PRASE_FINISH.getValue());
                     //解析成功 状态为已解析