Pārlūkot izejas kodu

Merge branch 'bugfix-wxLogin' into dev

# Conflicts:
#	src/main/resources/bootstrap.yml
wangzeyu@tom.com 2 gadi atpakaļ
vecāks
revīzija
027df82439

+ 1 - 3
src/main/java/com/szwl/Application.java

@@ -17,6 +17,4 @@ public class Application{
     public static void main(String[] args) {
         SpringApplication.run(Application.class, args);
     }
-}
-
-
+}

+ 14 - 27
src/main/java/com/szwl/controller/TEquipmentController.java

@@ -22,6 +22,7 @@ import com.szwl.model.query.StatisticsParam;
 import com.szwl.model.utils.DateUtils;
 import com.szwl.model.utils.PushUtils;
 import com.szwl.service.*;
+import com.szwl.util.DownloadUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang.StringUtils;
@@ -36,6 +37,8 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.*;
 import java.net.URL;
 import java.net.URLConnection;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.Executors;
@@ -227,6 +230,9 @@ public class TEquipmentController {
             equipmentDTO.setCouponStatus(equipmentDesc.getCouponStatus());
             equipmentDTO.setInDoor(equipmentDesc.getInDoor());
             equipmentDTO.setOutDoor(equipmentDesc.getOutDoor());
+            if(equipmentDesc.getFlowers() != null) {
+                equipmentDTO.setFlowers(equipmentDesc.getFlowers());
+            }
         }
         String messageReceiver = equipment.getMessageReceiver();
         if (StringUtils.isNotEmpty(messageReceiver)) {
@@ -1491,9 +1497,9 @@ public class TEquipmentController {
     @GetMapping("/downloadLog")
     public ResponseModel<?> downloadLog(String equipmentId, String day, HttpServletResponse response) throws IOException, InterruptedException {
         // 1、发送MQ到安卓端上传日志
-        if(day.length()!=8){
+/*        if(day.length()!=8){
             return R.fail(A0001,"日期格式有误");
-        }
+        }*/
         if(StringUtils.isEmpty(equipmentId)) {
             return R.fail(A0001);
         }
@@ -1505,8 +1511,8 @@ public class TEquipmentController {
         String kind = day+"-"+clientId;
         String filepath = "/home/hboxs/log/"+kind+".txt";
         // 1.1 如果文件已存在,直接下载
-        if(new File(filepath).exists()) {
-            downloadFile(filepath, response);
+        if(Files.exists(Paths.get(filepath))) {
+            DownloadUtils.downloadFile(filepath, response);
             return R.ok();
         }
         String channel = tEquipment.getChannel();
@@ -1524,7 +1530,7 @@ public class TEquipmentController {
         long startTime = System.currentTimeMillis();
         ScheduledFuture<?> future = exec.schedule(() -> {
             // 超时处理逻辑
-            if (new File(filepath).exists()) {
+            if (Files.exists(Paths.get(filepath))) {
                 return null;
             } else {
                 throw new RuntimeException("找不到日志");
@@ -1532,13 +1538,13 @@ public class TEquipmentController {
         }, TIMEOUT, TimeUnit.MILLISECONDS);
 
         while (true) {
-            if (new File(filepath).exists()) {
+            if (Files.exists(Paths.get(filepath))) {
                 // 文件存在,取消定时器
                 future.cancel(false);
                 break;
             }else {
                 Thread.sleep(1000);
-                if (System.currentTimeMillis() - startTime >= 20000L) {
+                if (System.currentTimeMillis() - startTime >= TIMEOUT) {
                     // 超过最大等待时间,抛出异常
                     future.cancel(false);
                     throw new RuntimeException("等待文件生成超时");
@@ -1546,27 +1552,8 @@ public class TEquipmentController {
             }
         }
         // 3、从服务器下载文件
-        downloadFile(filepath, response);
+        DownloadUtils.downloadFile(filepath, response);
         return R.ok();
     }
-
-    // 从服务器下载文件
-    public void downloadFile(String filepath, HttpServletResponse response) throws IOException {
-        File logFile = new File(filepath);
-        response.setHeader("Content-Disposition", "attachment; filename=\"" + logFile.getName() + "\"");
-
-        FileInputStream fis = new FileInputStream(logFile);
-        OutputStream os = response.getOutputStream();
-
-        byte[] buffer = new byte[4096];
-        int length;
-        while ((length = fis.read(buffer)) > 0) {
-            os.write(buffer, 0, length);
-            os.flush();
-        }
-        os.close();
-        fis.close();
-        response.flushBuffer();
-    }
 }
 

+ 0 - 1
src/main/java/com/szwl/controller/TWechatController.java

@@ -79,7 +79,6 @@ public class TWechatController {
                     + "&state=" + adminId
                     + "#wechat_redirect";
             return R.ok(url);
-
         } catch (UnsupportedEncodingException e) {
             throw new RuntimeException(e);
         }

+ 35 - 0
src/main/java/com/szwl/util/DownloadUtils.java

@@ -0,0 +1,35 @@
+package com.szwl.util;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class DownloadUtils {
+
+    /**
+     * 从服务器下载文件
+     * @param filepath
+     * @param response
+     * @throws IOException
+     */
+    public static void downloadFile(String filepath, HttpServletResponse response) throws IOException {
+        File logFile = new File(filepath);
+        response.setContentType("text/plain; charset=utf-8");
+        response.setHeader("Content-Disposition", "attachment; filename=\"" + logFile.getName() + "\"");
+
+        FileInputStream fis = new FileInputStream(logFile);
+        OutputStream os = response.getOutputStream();
+
+        byte[] buffer = new byte[4096];
+        int length;
+        while ((length = fis.read(buffer)) > 0) {
+            os.write(buffer, 0, length);
+            os.flush();
+        }
+        os.close();
+        fis.close();
+        response.flushBuffer();
+    }
+}

+ 1 - 1
src/main/resources/bootstrap.yml

@@ -38,7 +38,7 @@ oauth:
 #    系统测试
 #    http: http://szwltest.sunzee.com.cn
 #    正式服务
-    http: https://szwlh.sunzee.com.cn
+    http: http://szwlh.sunzee.com.cn
 
 mybatis-plus:
   mapper-locations: classpath:com/szwl/mapper/xml/*.xml