|
@@ -22,6 +22,7 @@ import com.szwl.model.query.StatisticsParam;
|
|
import com.szwl.model.utils.DateUtils;
|
|
import com.szwl.model.utils.DateUtils;
|
|
import com.szwl.model.utils.PushUtils;
|
|
import com.szwl.model.utils.PushUtils;
|
|
import com.szwl.service.*;
|
|
import com.szwl.service.*;
|
|
|
|
+import com.szwl.util.DownloadUtils;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -36,6 +37,8 @@ import javax.servlet.http.HttpServletResponse;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.net.URLConnection;
|
|
import java.net.URLConnection;
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
+import java.nio.file.Paths;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.Executors;
|
|
@@ -216,6 +219,9 @@ public class TEquipmentController {
|
|
equipmentDTO.setCouponStatus(equipmentDesc.getCouponStatus());
|
|
equipmentDTO.setCouponStatus(equipmentDesc.getCouponStatus());
|
|
equipmentDTO.setInDoor(equipmentDesc.getInDoor());
|
|
equipmentDTO.setInDoor(equipmentDesc.getInDoor());
|
|
equipmentDTO.setOutDoor(equipmentDesc.getOutDoor());
|
|
equipmentDTO.setOutDoor(equipmentDesc.getOutDoor());
|
|
|
|
+ if(equipmentDesc.getFlowers() != null) {
|
|
|
|
+ equipmentDTO.setFlowers(equipmentDesc.getFlowers());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
String messageReceiver = equipment.getMessageReceiver();
|
|
String messageReceiver = equipment.getMessageReceiver();
|
|
if (StringUtils.isNotEmpty(messageReceiver)) {
|
|
if (StringUtils.isNotEmpty(messageReceiver)) {
|
|
@@ -1473,9 +1479,9 @@ public class TEquipmentController {
|
|
@GetMapping("/downloadLog")
|
|
@GetMapping("/downloadLog")
|
|
public ResponseModel<?> downloadLog(String equipmentId, String day, HttpServletResponse response) throws IOException, InterruptedException {
|
|
public ResponseModel<?> downloadLog(String equipmentId, String day, HttpServletResponse response) throws IOException, InterruptedException {
|
|
// 1、发送MQ到安卓端上传日志
|
|
// 1、发送MQ到安卓端上传日志
|
|
- if(day.length()!=8){
|
|
|
|
|
|
+/* if(day.length()!=8){
|
|
return R.fail(A0001,"日期格式有误");
|
|
return R.fail(A0001,"日期格式有误");
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
if(StringUtils.isEmpty(equipmentId)) {
|
|
if(StringUtils.isEmpty(equipmentId)) {
|
|
return R.fail(A0001);
|
|
return R.fail(A0001);
|
|
}
|
|
}
|
|
@@ -1487,8 +1493,8 @@ public class TEquipmentController {
|
|
String kind = day+"-"+clientId;
|
|
String kind = day+"-"+clientId;
|
|
String filepath = "/home/hboxs/log/"+kind+".txt";
|
|
String filepath = "/home/hboxs/log/"+kind+".txt";
|
|
// 1.1 如果文件已存在,直接下载
|
|
// 1.1 如果文件已存在,直接下载
|
|
- if(new File(filepath).exists()) {
|
|
|
|
- downloadFile(filepath, response);
|
|
|
|
|
|
+ if(Files.exists(Paths.get(filepath))) {
|
|
|
|
+ DownloadUtils.downloadFile(filepath, response);
|
|
return R.ok();
|
|
return R.ok();
|
|
}
|
|
}
|
|
String channel = tEquipment.getChannel();
|
|
String channel = tEquipment.getChannel();
|
|
@@ -1506,7 +1512,7 @@ public class TEquipmentController {
|
|
long startTime = System.currentTimeMillis();
|
|
long startTime = System.currentTimeMillis();
|
|
ScheduledFuture<?> future = exec.schedule(() -> {
|
|
ScheduledFuture<?> future = exec.schedule(() -> {
|
|
// 超时处理逻辑
|
|
// 超时处理逻辑
|
|
- if (new File(filepath).exists()) {
|
|
|
|
|
|
+ if (Files.exists(Paths.get(filepath))) {
|
|
return null;
|
|
return null;
|
|
} else {
|
|
} else {
|
|
throw new RuntimeException("找不到日志");
|
|
throw new RuntimeException("找不到日志");
|
|
@@ -1514,13 +1520,13 @@ public class TEquipmentController {
|
|
}, TIMEOUT, TimeUnit.MILLISECONDS);
|
|
}, TIMEOUT, TimeUnit.MILLISECONDS);
|
|
|
|
|
|
while (true) {
|
|
while (true) {
|
|
- if (new File(filepath).exists()) {
|
|
|
|
|
|
+ if (Files.exists(Paths.get(filepath))) {
|
|
// 文件存在,取消定时器
|
|
// 文件存在,取消定时器
|
|
future.cancel(false);
|
|
future.cancel(false);
|
|
break;
|
|
break;
|
|
}else {
|
|
}else {
|
|
Thread.sleep(1000);
|
|
Thread.sleep(1000);
|
|
- if (System.currentTimeMillis() - startTime >= 20000L) {
|
|
|
|
|
|
+ if (System.currentTimeMillis() - startTime >= TIMEOUT) {
|
|
// 超过最大等待时间,抛出异常
|
|
// 超过最大等待时间,抛出异常
|
|
future.cancel(false);
|
|
future.cancel(false);
|
|
throw new RuntimeException("等待文件生成超时");
|
|
throw new RuntimeException("等待文件生成超时");
|
|
@@ -1528,27 +1534,8 @@ public class TEquipmentController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 3、从服务器下载文件
|
|
// 3、从服务器下载文件
|
|
- downloadFile(filepath, response);
|
|
|
|
|
|
+ DownloadUtils.downloadFile(filepath, response);
|
|
return R.ok();
|
|
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();
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|