xusl 3 anni fa
parent
commit
b26e236e41

+ 0 - 18
ipfcst-common/ipfcst-common-core/src/main/java/com/jiayue/ipfcst/common/core/constant/CommonConstants.java

@@ -1,18 +0,0 @@
-package com.jiayue.ipfcst.common.core.constant;
-
-/**
- * CommonConstants
- *
- * @author L.ym
- * @version 3.0
- **/
-public interface CommonConstants {
-    /**
-     * 成功标记
-     */
-    Integer SUCCESS = 0;
-    /**
-     * 失败标记
-     */
-    Integer FAIL = 1;
-}

+ 0 - 14
ipfcst-common/ipfcst-common-core/src/main/java/com/jiayue/ipfcst/common/core/constant/SecurityConstants.java

@@ -1,14 +0,0 @@
-package com.jiayue.ipfcst.common.core.constant;
-
-/**
- * SecurityConstants
- *
- * @author L.ym
- * @version 3.0
- **/
-public interface SecurityConstants {
-    /**
-     * 刷新
-     */
-    String REFRESH_TOKEN = "refresh_token";
-}

+ 1 - 1
ipfcst-common/ipfcst-common-data/src/main/java/com/jiayue/ipfcst/common/data/constant/enums/EquipmentTypeEnum.java

@@ -62,7 +62,7 @@ public enum EquipmentTypeEnum {
 			case 14 :return DZ;
 			case 15 :return JDDZ;
 			case 16 :return DXFDJ;
+			default :return null;
 		}
-		return null;
 	}
 }

+ 8 - 18
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/util/CreateConsoleSh.java

@@ -7,7 +7,6 @@ import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
 
 import java.io.FileOutputStream;
-import java.io.IOException;
 import java.io.StringWriter;
 import java.nio.charset.StandardCharsets;
 
@@ -20,8 +19,6 @@ import java.nio.charset.StandardCharsets;
 public class CreateConsoleSh {
   public static void main(String[] args) {
     System.out.println("==============执行console的启动sh文件生成=============");
-    FileOutputStream os = null;
-    try {
       VelocityEngine ve = new VelocityEngine();
       ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
       ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
@@ -31,21 +28,14 @@ public class CreateConsoleSh {
       ctx.put("version", args[0]);
       StringWriter sw = new StringWriter();
       t.merge(ctx, sw);
-      os = new FileOutputStream("../syjy/ipfcstV3/bin/start-console.sh");
-      // 采用UTF-8字符集
-      os.write(sw.toString().getBytes(StandardCharsets.UTF_8));
-      os.flush();
-    } catch (IOException e) {
-      e.printStackTrace();
-    } finally {
-      if (os != null) {
-        try {
-          os.close();
-        } catch (IOException e) {
-          //noinspection ThrowablePrintedToSystemOut
-          System.out.println(e);
-        }
+      try (FileOutputStream os = new FileOutputStream("../syjy/ipfcstV3/bin/start-console.sh");){
+        // 采用UTF-8字符集
+        os.write(sw.toString().getBytes(StandardCharsets.UTF_8));
+        os.flush();
+      }
+      catch (Exception e){
+        System.out.println("生成console启动脚本文件失败");
+        e.printStackTrace();
       }
-    }
   }
 }

+ 5 - 14
ipfcst-console/src/main/java/com/jiayue/ipfcst/fileupload/IEC102/Base102Service.java

@@ -179,16 +179,15 @@ public class Base102Service {
    * @return
    */
   public String createFileMessageHex(String filePath, String charsetName, Logger log) {
-    InputStreamReader isr = null;
+
     String fileMessageHex = "";
-    try {
-      isr = new InputStreamReader(new FileInputStream(filePath), StandardCharsets.UTF_8);
-      StringBuilder sb = new StringBuilder();
-      int len1;
+
+    try (InputStreamReader isr = new InputStreamReader(new FileInputStream(filePath), "UTF-8");){
+      StringBuffer sb = new StringBuffer("");
+      int len1 = 0;
       while ((len1 = isr.read()) != -1) {
         sb.append((char) len1);
       }
-      isr.close();
 
       String str = sb.toString();
       fileMessageHex = ByteUtil.Byte2String(str.getBytes(charsetName));
@@ -208,14 +207,6 @@ public class Base102Service {
 //      osw.close();
     } catch (Exception e) {
       log.error("读取本地文件失败", e);
-    } finally {
-      if (isr != null) {
-        try {
-          isr.close();
-        } catch (IOException e) {
-          e.printStackTrace();
-        }
-      }
     }
     return fileMessageHex;
   }

+ 2 - 10
ipfcst-console/src/main/java/com/jiayue/ipfcst/fileupload/service/BaseUploadFileService.java

@@ -114,9 +114,8 @@ public abstract class BaseUploadFileService extends BaseService {
    * @param uploadFileEndTime
    */
   protected void copyUploadFile(StringWriter writer, File file, String fileType, Long uploadFileEndTime, Date createTime, String stationCode) {
-    FileOutputStream os = null;
-    try {
-      os = new FileOutputStream(file);
+    try (
+      FileOutputStream os = new FileOutputStream(file);) {
       // 采用UTF-8字符集
       os.write(writer.toString().getBytes(StandardCharsets.UTF_8));
       os.flush();
@@ -125,13 +124,6 @@ public abstract class BaseUploadFileService extends BaseService {
     } catch (IOException e) {
       throw new RuntimeException(e);
     } finally {
-      if (os != null) {
-        try {
-          os.close();
-        } catch (IOException e) {
-          log.error("文件生成关闭流失败", e);
-        }
-      }
       try {
         FileUtils.forceDelete(file.getParentFile());
       } catch (IOException e) {

+ 23 - 41
ipfcst-console/src/main/java/com/jiayue/ipfcst/fileupload/service/FtpUploadTransactionService.java

@@ -53,19 +53,22 @@ public class FtpUploadTransactionService extends BaseUploadFileService {
     //明日凌晨
     logger.info("准备上报:" + srcPath);
     try {
-      InputStreamReader isr = null;
-      InputStream uploadFileIs = null;
+      String str = "";
+      try (
+        InputStreamReader isr = new InputStreamReader(new FileInputStream(srcPath), StandardCharsets.UTF_8);){
+        StringBuilder sb = new StringBuilder();
+        int len1;
+        while ((len1 = isr.read()) != -1) {
+          sb.append((char) len1);
+        }
+        str = sb.toString();
+      }
+      catch (Exception e){
+        logger.error("读取文件失败", e);
+      }
       if (ftp != null) {
-        try {
-          isr = new InputStreamReader(new FileInputStream(srcPath), StandardCharsets.UTF_8);
-          StringBuilder sb = new StringBuilder();
-          int len1;
-          while ((len1 = isr.read()) != -1) {
-            sb.append((char) len1);
-          }
-          isr.close();
-          String str = sb.toString();
-          uploadFileIs = new ByteArrayInputStream(str.getBytes(uploadObject.getUploadFileCharSetEnum().getMessage()));
+        try (
+          InputStream uploadFileIs = new ByteArrayInputStream(str.getBytes(uploadObject.getUploadFileCharSetEnum().getMessage()));){
           String uploadFileName = new String(new File(srcPath).getName().getBytes(StandardCharsets.UTF_8), uploadObject.getUploadFileCharSetEnum().getMessage());
           // 是否每个文件类型一个路径
           if (StrUtil.hasBlank(uploadFileChannel.getBackupC()) || "0".equals(uploadFileChannel.getBackupC())) {
@@ -76,28 +79,13 @@ public class FtpUploadTransactionService extends BaseUploadFileService {
             UploadURL uploadURL = uploadURLList.stream().filter(c -> c.getFileTypeEnum().name().equals(keys[1])).collect(Collectors.toList()).get(0);
             isSuccess = ftp.upload(uploadURL.getUploadURL(), uploadFileName, uploadFileIs);
           }
-        } catch (Exception e) {
-          logger.error("ftp上传失败", e);
-          throw e;
-        } finally {
-          if (isr != null) {
-            isr.close();
-          }
-          if (uploadFileIs != null) {
-            uploadFileIs.close();
-          }
+        }
+        catch (Exception e){
+          logger.error("读取文件失败", e);
         }
       } else {
-        try {
-          isr = new InputStreamReader(new FileInputStream(srcPath), StandardCharsets.UTF_8);
-          StringBuilder sb = new StringBuilder();
-          int len1;
-          while ((len1 = isr.read()) != -1) {
-            sb.append((char) len1);
-          }
-          isr.close();
-          String str = sb.toString();
-          uploadFileIs = new ByteArrayInputStream(str.getBytes(uploadObject.getUploadFileCharSetEnum().getMessage()));
+        try (
+          InputStream uploadFileIs = new ByteArrayInputStream(str.getBytes(uploadObject.getUploadFileCharSetEnum().getMessage()));){
           String uploadFileName = new String(new File(srcPath).getName().getBytes(StandardCharsets.UTF_8), uploadObject.getUploadFileCharSetEnum().getMessage());
 
           if (StrUtil.hasBlank(uploadFileChannel.getBackupC()) || "0".equals(uploadFileChannel.getBackupC())) {
@@ -108,23 +96,17 @@ public class FtpUploadTransactionService extends BaseUploadFileService {
             UploadURL uploadURL = uploadURLList.stream().filter(c -> c.getFileTypeEnum().name().equals(keys[1])).collect(Collectors.toList()).get(0);
             sftp.getClient().put(uploadFileIs, uploadURL.getUploadURL() + "/" + uploadFileName);
           }
-
           logger.info("上传远端put结束:" + keys[2]);
           isSuccess = true;
-        } finally {
-          if (isr != null) {
-            isr.close();
-          }
-          if (uploadFileIs != null) {
-            uploadFileIs.close();
-          }
+        }
+        catch (Exception e){
+          logger.error("读取文件失败", e);
         }
       }
     } catch (Exception e) {
       isSuccess = false;
       logger.error("上报通道:" + uploadFileChannel.getChannelName() + "," + keys[2] + "上报失败", e);
       Integer id = FileConstant.fileShouldMomentMap.get(entry.getKey());
-
       Optional<UploadFileLog> optional = uploadFileLogRepository.findById(id);
       UploadFileLog uploadFileLog = new UploadFileLog();
       if (optional.isPresent()) {