diff --git a/src/main/java/com/ann/demo/interfaces/impl/HomepageDictionaryImpl.java b/src/main/java/com/ann/demo/interfaces/impl/HomepageDictionaryImpl.java index f06b5db..17cdd75 100644 --- a/src/main/java/com/ann/demo/interfaces/impl/HomepageDictionaryImpl.java +++ b/src/main/java/com/ann/demo/interfaces/impl/HomepageDictionaryImpl.java @@ -15,12 +15,14 @@ import com.ann.demo.interfaces.HomepageDictionary; import com.ann.demo.repository.ArchiveMasterRepository; import com.ann.demo.repository.MessageScanningRepository; import com.ann.demo.service.*; +import com.ann.demo.utils.FileUtils; import com.ann.demo.utils.XMLUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import javax.jws.WebService; +import java.io.IOException; import java.util.Date; import java.util.Objects; @@ -154,13 +156,13 @@ public class HomepageDictionaryImpl implements HomepageDictionary { messageSubordinateService.save(new MessageSubordinate(messageLog.getId(), patientMainStr, JSON.toJSONString(messageLog))); } }catch (Exception e){ + // 生成一个临时文件 try { - logger.error("出错咯!错误信息为{},以及错误行数为:{}" ,e,e.getStackTrace()[0]); - return AnalysisService.getReturnResult(false,e.toString()); - } catch (Exception e1) { - logger.error("出错咯!错误信息为{},以及错误行数为:{}" ,e1,e1.getStackTrace()[0]); + logger.error("消息出错,请检查消息内容,错误详情:{},消息所在位置:{}",e.getMessage(), FileUtils.createFile("NurseData",null,xmlStr)); + } catch (IOException e1) { return outContent; } + return outContent; } return outContent; } @@ -260,12 +262,13 @@ public class HomepageDictionaryImpl implements HomepageDictionary { messageSubordinateService.save(new MessageSubordinate(messageLog.getId(), patientMainStr, JSON.toJSONString(messageLog))); } }catch (Exception e){ + // 生成一个临时文件 try { - logger.error("出错咯!错误信息为{},以及错误行数为:{}" ,e,e.getStackTrace()[0]); - return AnalysisService.getReturnResult(false,e.toString()); - } catch (Exception e1) { - logger.error("出错咯!错误信息为{},以及错误行数为:{}" ,e1,e1.getStackTrace()[0]); + logger.error("消息出错,请检查消息内容,错误详情:{},消息所在位置:{}",e.getMessage(), FileUtils.createFile("DoctorData",null,xmlStr)); + } catch (IOException e1) { + return outContent; } + return outContent; } return outContent; } diff --git a/src/main/java/com/ann/demo/utils/FileUtils.java b/src/main/java/com/ann/demo/utils/FileUtils.java index 3d01ba3..721bb63 100644 --- a/src/main/java/com/ann/demo/utils/FileUtils.java +++ b/src/main/java/com/ann/demo/utils/FileUtils.java @@ -4,10 +4,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import org.springframework.util.ObjectUtils; import java.io.*; import java.time.LocalDate; import java.util.Objects; +import java.util.UUID; /** * @Author: LeiJiaXin @@ -20,29 +22,36 @@ public class FileUtils { // pdf地址 public static String pdfPath; - @Value("${file.pdfPath}") public void setPdfPath(String pdfPath) { FileUtils.pdfPath = pdfPath; } - public static String getPdfPath() { return pdfPath; } // image地址 public static String imagePath; - @Value("${file.imagePath}") public void setImagePath(String imagePath) { FileUtils.imagePath = imagePath; } - public static String getImagePath() { return imagePath; } + // 错误文件地址 + public static String errorPath; + @Value("${file.errorPath}") + public void setErrorPath(String errorPath) { + FileUtils.errorPath = errorPath; + } + public static String getErrorPath() { + return errorPath; + } + + public static File createFile(String fileType, String inpNo, String visitId, String path) throws IOException { File localFile = null; try { @@ -82,6 +91,47 @@ public class FileUtils { } + public static String createFile(String interfaceName, String param,String message) throws IOException { + File localFile = null; + OutputStreamWriter write = null; + BufferedWriter writer = null; + try { + //生成文件地址 + LocalDate date = LocalDate.now(); + String fileDirName = null; + fileDirName = errorPath+"/" + date.getYear() + "/" + date.getMonthValue() + "/" + interfaceName; + // 如果参数不为空时,再增加一级目录 + if(!ObjectUtils.isEmpty(param)){ + fileDirName += "_" + param; + } + //判断是否有该文件夹 否则创建 + File fileDir = new File(fileDirName); + if (!fileDir.exists()) { + fileDir.mkdirs(); + } + String fileName = fileDir + "/" + UUID.randomUUID() + ".txt"; + localFile = new File(fileName); + if (!localFile.exists()) { + localFile.createNewFile(); + } + write = new OutputStreamWriter(new FileOutputStream(localFile)); + writer = new BufferedWriter(write); + writer.write(message); + writer.flush(); + } catch (IOException e) { + throw e; + }finally { + if(!ObjectUtils.isEmpty(write)){ + write.close(); + } + if(!ObjectUtils.isEmpty(writer)){ + writer.close(); + } + } + return localFile.getAbsolutePath(); + } + + public static void deleteImageFile(File file) { if (!file.exists()) { System.out.println(file.getAbsolutePath() + "文件不存在"); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8591daf..d5ac93e 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,26 +1,26 @@ spring: datasource: - # url: jdbc:mysql://localhost:3306/test - # # url: jdbc:mysql://10.6.1.127:3306/test - # username: root - # password: 123456 - # driver-class-name: com.mysql.jdbc.Driver - # jpa: - # database: mysql - # show-sql: false - # hibernate: - # ddl-auto: update - # database-platform: org.hibernate.dialect.MySQL5InnoDBDialect - # url: jdbc:sqlserver://120.27.212.36:1433;DatabaseName=emr_record - url: jdbc:sqlserver://10.6.1.127:1433;DatabaseName=DB_PrivilegeManagement_GYFY - username: sa - password: docus@702 - driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver + url: jdbc:mysql://localhost:3306/test + # url: jdbc:mysql://10.6.1.127:3306/test + username: root + password: 123456 + driver-class-name: com.mysql.jdbc.Driver jpa: - database: sql_server + database: mysql show-sql: false hibernate: - dialect: org.hibernate.dialect.SQLServer2008Dialect + ddl-auto: update + database-platform: org.hibernate.dialect.MySQL5InnoDBDialect +# url: jdbc:sqlserver://120.27.212.36:1433;DatabaseName=emr_record + # url: jdbc:sqlserver://10.6.1.127:1433;DatabaseName=DB_PrivilegeManagement_GYFY + # username: sa + # password: docus@702 + # driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver + # jpa: + # database: sql_server + # show-sql: false + # hibernate: + # dialect: org.hibernate.dialect.SQLServer2008Dialect hikari: #是否为只读数据库 read-only: false @@ -50,4 +50,5 @@ file: pdfPath: Z:/project_js/docus_scanningfile_20201216/ imagePath: Z:/images/docus_scanningfile_20201216/ scanningFilePath: D:\\1\scanningFile.properties + errorPath: D:/logs/errorMessage/