jiawuxian 1 жил өмнө
parent
commit
9e7297a637

+ 1 - 1
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteFileService.java

@@ -97,5 +97,5 @@ public interface RemoteFileService {
     void deletedZipFile();
 
     @PostMapping(value = "/file/readFile")
-    Response readFile(@RequestBody Map<String, String> data);
+    byte[] readFile(@RequestBody Map<String, String> data);
 }

+ 1 - 1
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/factory/RemoteFileFallbackFactory.java

@@ -93,7 +93,7 @@ public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileServ
             }
 
             @Override
-            public Response readFile(Map<String, String> data) {
+            public byte[] readFile(Map<String, String> data) {
                 throw new RuntimeException("读取文件超时,请稍后重试!");
             }
         };

+ 3 - 2
soc-modules/soc-modules-file/src/main/java/com/xunmei/file/controller/SysFileController.java

@@ -220,7 +220,8 @@ public class SysFileController {
     }
 
     @PostMapping(value = "/readFile")
-    void readFile(@RequestBody Map<String, String> data, HttpServletResponse response) throws IOException {
-        sysFileService.readFile(data.get("path"), response);
+    byte[] readFile(@RequestBody Map<String, String> data) throws IOException {
+        byte[] r = sysFileService.readFile(data.get("path"));
+        return r;
     }
 }

+ 1 - 1
soc-modules/soc-modules-file/src/main/java/com/xunmei/file/service/ISysFileService.java

@@ -78,5 +78,5 @@ public interface ISysFileService
 
     String generateOutInPdf(Map<String, Object> data)throws Exception;
 
-    void readFile(String path,HttpServletResponse response) throws IOException;
+    byte[] readFile(String path) throws IOException;
 }

+ 21 - 4
soc-modules/soc-modules-file/src/main/java/com/xunmei/file/service/LocalSysFileServiceImpl.java

@@ -3,6 +3,8 @@ package com.xunmei.file.service;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.core.util.ByteUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
@@ -33,6 +35,7 @@ import com.xunmei.system.api.domain.SafeCheckTaskRegisterBookVo;
 import com.xunmei.system.api.vo.SysOrgVO;
 import io.netty.util.internal.StringUtil;
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.text.StringEscapeUtils;
 import org.apache.tools.zip.ZipEntry;
@@ -941,7 +944,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
     }
 
     @Override
-    public void readFile(String path, HttpServletResponse response) throws IOException {
+    public byte[] readFile(String path) throws IOException {
         if (ObjectUtil.isEmpty(path)) {
             throw new RuntimeException("文件地址无效");
         }
@@ -953,15 +956,29 @@ public class LocalSysFileServiceImpl implements ISysFileService {
         conn.setRequestMethod("GET");
         conn.setConnectTimeout(5 * 1000);
         InputStream stream = conn.getInputStream();
+//        FileUtil.del("d:\\1111.jpg");
+//FileUtil.writeFromStream(stream,"d:\\1111.jpg");
+
+        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
         try (BufferedInputStream bis = new BufferedInputStream(stream)) {
             // 设置响应类型
-            response.setContentType("image/*");
-            response.setHeader("Content-Length", String.valueOf(stream.available()));
+//            response.setContentType("image/*");
+//            response.setHeader("Content-Length", String.valueOf(stream.available()));
             // 将文件流发送给前端
             byte[] buffer = new byte[1024];
             int bytesRead;
             while ((bytesRead = bis.read(buffer)) != -1) {
-                response.getOutputStream().write(buffer, 0, bytesRead);
+                outStream.write(buffer, 0, bytesRead);
+            }
+
+            byte[] r = outStream.toByteArray();
+            if (r[0] == 10) {
+                byte[] r1 = new byte[r.length - 1];
+
+                ArrayUtil.copy(r, 1, r1, 0, r1.length);
+                return r1;
+            } else {
+                return r;
             }
         }
     }

+ 22 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/controller/VideoDiagnosisController.java

@@ -10,11 +10,18 @@ import com.xunmei.iot.vo.videoDiagnosis.VideoDiagnosisAppPageVo;
 import com.xunmei.iot.vo.videoDiagnosis.VideoDiagnosisIntegrityVo;
 import com.xunmei.iot.vo.videoDiagnosis.VideoDiagnosisWebPageVo;
 import com.xunmei.iot.vo.videoDiagnosis.VideoDiagnosisWebVo;
+import com.xunmei.system.api.RemoteFileService;
+import feign.Response;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
 import java.text.SimpleDateFormat;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * 录像诊断
@@ -29,6 +36,9 @@ public class VideoDiagnosisController {
     @Autowired
     private VideoDiagnosisService videoDiagnosisService;
 
+    @Resource
+    private RemoteFileService fileService;
+
     @PostMapping("/web/page")
     public TableDataInfo<VideoDiagnosisWebPageVo> webPage(@RequestBody VideoDiagnosisWebPageDto pageDto) {
         TableDataInfo<VideoDiagnosisWebPageVo> page = this.videoDiagnosisService.getPageData(pageDto);
@@ -61,6 +71,18 @@ public class VideoDiagnosisController {
         return AjaxResult.success(count);
     }
 
+    @ApiOperation("有异常的硬盘数量")
+    @GetMapping({"/img"})
+    void getImg(String path, HttpServletResponse response) throws IOException {
+        Map<String, String> param = new HashMap<>();
+        param.put("path", path);
+        byte[] result = fileService.readFile(param);
+        OutputStream bufferedOutputStream = response.getOutputStream();
+        bufferedOutputStream.write(result,0,result.length);
+        response.setContentType("image/*");
+        bufferedOutputStream.flush();
+        bufferedOutputStream.close();
+    }
 //    @PostMapping("/app/detail/{hostCode}/{channelCode}")
 //    public TableDataInfo<VideoDiagnosisAppPageVo> appInfo(@PathVariable("hostCode") String hostCode, @PathVariable("channelCode") String channelCode) {
 //        TableDataInfo<VideoDiagnosisAppPageVo> page = this.videoDiagnosisService.getAppPageData(pageDto);

+ 21 - 21
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/controller/DataController.java

@@ -178,25 +178,25 @@ public class DataController {
     @Resource
     private RemoteFileService fileService;
 
-    @ApiOperation("传感器通用设备信息同步")
-    @GetMapping({"/api/test"})
-    public void test(@RequestBody Map<String, String> data, HttpServletResponse response) throws IOException {
-        Response result = fileService.readFile(data);
-        Response.Body body = result.body();
-        InputStream inputStream = body.asInputStream();
-        System.out.println(inputStream.available());
-        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
-        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
-        int length = 0;
-        byte[] temp = new byte[1024 * 10];
-        while ((length = bufferedInputStream.read(temp)) != -1) {
-            bufferedOutputStream.write(temp, 0, length);
-        }
-        bufferedOutputStream.flush();
-        bufferedOutputStream.close();
-        bufferedInputStream.close();
-        inputStream.close();
-
-
-    }
+//    @ApiOperation("传感器通用设备信息同步")
+//    @GetMapping({"/api/test"})
+//    public void test(@RequestBody Map<String, String> data, HttpServletResponse response) throws IOException {
+//        Response result = fileService.readFile(data);
+//        Response.Body body = result.body();
+//        InputStream inputStream = body.asInputStream();
+//        System.out.println(inputStream.available());
+//        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
+//        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
+//        int length = 0;
+//        byte[] temp = new byte[1024 * 10];
+//        while ((length = bufferedInputStream.read(temp)) != -1) {
+//            bufferedOutputStream.write(temp, 0, length);
+//        }
+//        bufferedOutputStream.flush();
+//        bufferedOutputStream.close();
+//        bufferedInputStream.close();
+//        inputStream.close();
+//
+//
+//    }
 }