Просмотр исходного кода

病理报告图片地址加密

lighter 1 год назад
Родитель
Сommit
7564a22a6c

+ 1 - 1
pom.xml

@@ -10,7 +10,7 @@
     </parent>
     <groupId>thyyxxk</groupId>
     <artifactId>wxservice-server</artifactId>
-    <version>12.1.2</version>
+    <version>12.1.3</version>
     <name>wxservice-server</name>
     <description>server for wxservice-web</description>
 

+ 7 - 0
src/main/java/thyyxxk/wxservice_server/controller/InspectionsController.java

@@ -1,7 +1,9 @@
 package thyyxxk.wxservice_server.controller;
 
+import cn.hutool.http.server.HttpServerResponse;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
 import thyyxxk.wxservice_server.entity.ResultVo;
 import thyyxxk.wxservice_server.entity.inspections.request.CheckExamParam;
 import thyyxxk.wxservice_server.entity.inspections.request.QueryReportDetail;
@@ -54,4 +56,9 @@ public class InspectionsController {
         request.setReqEndTime(request.getReqEndTime().replaceAll("-", ""));
         return ResultVoUtil.success(service.checkPathologyIndex(request));
     }
+
+    @PostMapping("/checkPathologyDetail")
+    public StreamingResponseBody checkPathologyDetail(@RequestBody QueryReportDetail request) {
+        return service.checkPathologyDetail(request);
+    }
 }

+ 0 - 11
src/main/java/thyyxxk/wxservice_server/factory/pathology/model/PathologyIndex.java

@@ -2,7 +2,6 @@ package thyyxxk.wxservice_server.factory.pathology.model;
 
 import com.alibaba.fastjson.annotation.JSONField;
 import lombok.Data;
-import thyyxxk.wxservice_server.utils.StringUtil;
 
 @Data
 public class PathologyIndex {
@@ -30,14 +29,4 @@ public class PathologyIndex {
 
     @JSONField(name = "检查结论")
     private String conclusion;
-
-    private String nginxUrl;
-
-    public String getNginxUrl() {
-        if (StringUtil.isBlank(reportUrl)) {
-            return null;
-        }
-        return reportUrl.replace("http://172.16.32.192:801",
-                "https://staticweb.hnthyy.cn/pathologyReport");
-    }
 }

+ 22 - 0
src/main/java/thyyxxk/wxservice_server/service/InspectionsService.java

@@ -3,6 +3,7 @@ package thyyxxk.wxservice_server.service;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
 import thyyxxk.wxservice_server.config.exception.BizException;
 import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
 import thyyxxk.wxservice_server.dao.InspectionsDao;
@@ -20,7 +21,13 @@ import thyyxxk.wxservice_server.factory.pathology.model.PathologyRequest;
 import thyyxxk.wxservice_server.factory.thmz.ThmzService;
 import thyyxxk.wxservice_server.utils.*;
 
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
 import java.util.*;
+import java.util.List;
 
 /**
  * @author light
@@ -127,8 +134,23 @@ public class InspectionsService {
         PathologyService pathologyService = new PathologyService();
         request.setSocialNo(dao.getPatSocialNo(request.getPatientId()));
         List<PathologyIndex> list = pathologyService.queryOutpatientPathologyIndex(request);
+        list.forEach(item ->
+                item.setReportUrl(EncryptDecryptUtil.encrypt(request.getPatientId(), item.getReportUrl()))
+        );
         list.sort(Comparator.comparing(PathologyIndex::getApplyDate).reversed());
         return list;
     }
 
+    public StreamingResponseBody checkPathologyDetail(QueryReportDetail request) {
+        String reportUrl = EncryptDecryptUtil.decrypt(request.getPatientId(), request.getReportId());
+        return outputStream -> {
+            URL imageUrl = new URL(reportUrl);
+            InputStream in = imageUrl.openStream();
+            Path tempFile = Files.createTempFile("image", ".jpg");
+            Files.copy(in, tempFile, StandardCopyOption.REPLACE_EXISTING);
+            Files.copy(tempFile, outputStream);
+            outputStream.close();
+            in.close();
+        };
+    }
 }

+ 42 - 0
src/main/java/thyyxxk/wxservice_server/utils/EncryptDecryptUtil.java

@@ -0,0 +1,42 @@
+package thyyxxk.wxservice_server.utils;
+
+import lombok.val;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import java.util.Base64;
+
+public class EncryptDecryptUtil {
+    public static String encrypt(String key, String targetString) {
+        try {
+            val secretKeySpec = new SecretKeySpec(extendKey(key), "AES");
+            Cipher cipher = Cipher.getInstance("AES");
+            cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
+            byte[] encryptedBytes = cipher.doFinal(targetString.getBytes());
+            return Base64.getEncoder().encodeToString(encryptedBytes);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static String decrypt(String key, String encryptedString) {
+        try {
+            SecretKeySpec secretKeySpec = new SecretKeySpec(extendKey(key), "AES");
+            Cipher cipher = Cipher.getInstance("AES");
+            cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
+            byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(encryptedString));
+            return new String(decryptedBytes);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static byte[] extendKey(String key) {
+        byte[] extendedKey = new byte[16];
+        byte[] keyBytes = key.getBytes();
+        for (int i = 0; i < 16; i++) {
+            extendedKey[i] = keyBytes[i % keyBytes.length];
+        }
+        return extendedKey;
+    }
+}