Browse Source

Merge branch 'master' into text-ca

xiaochan 10 months ago
parent
commit
c70185058d

+ 17 - 0
src/main/java/thyyxxk/webserver/ScheduledTaskConfig.java

@@ -0,0 +1,17 @@
+package thyyxxk.webserver;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.SchedulingConfigurer;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
+
+@Configuration
+public class ScheduledTaskConfig implements SchedulingConfigurer {
+    @Override
+    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
+        ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
+        taskScheduler.setPoolSize(2);
+        taskScheduler.initialize();
+        taskRegistrar.setTaskScheduler(taskScheduler);
+    }
+}

+ 7 - 0
src/main/java/thyyxxk/webserver/controller/zhuyuanyizheng/emr/EmrController.java

@@ -14,6 +14,7 @@ import thyyxxk.webserver.entity.zhuyuanyisheng.emr.*;
 import thyyxxk.webserver.entity.zhuyuanyisheng.jianyanjiancha.YshYjReq;
 import thyyxxk.webserver.entity.zhuyuanyisheng.shoushu.OpRecord;
 import thyyxxk.webserver.service.zhuyuanyisheng.emr.EmrServer;
+import thyyxxk.webserver.utils.ResultVoUtil;
 import thyyxxk.webserver.utils.StringUtil;
 
 import java.util.List;
@@ -273,4 +274,10 @@ public class EmrController {
                                                     @RequestParam("times") Integer times) {
         return server.getOpRecordList(patNo, times);
     }
+
+    @GetMapping("/getEmrToken")
+    @PassToken
+    public ResultVo<String> getEmrToken() {
+        return ResultVoUtil.success(server.getEmrToken());
+    }
 }

+ 5 - 2
src/main/java/thyyxxk/webserver/service/externalhttp/emr/EmrEditor.java

@@ -3,9 +3,9 @@ package thyyxxk.webserver.service.externalhttp.emr;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.dtflys.forest.annotation.*;
+import thyyxxk.webserver.service.zhuyuanyisheng.emr.EmrServer;
 
-
-@BaseRequest(baseURL = "http://172.16.32.125:8001/emr/runtime/api/v1")
+@BaseRequest(baseURL = "http://172.16.32.125:8001/emr/runtime/api/v1", interceptor = EmrServer.EmrInterceptor.class)
 public interface EmrEditor {
 
     /**
@@ -72,5 +72,8 @@ public interface EmrEditor {
                                           @Var("codes") String codes);
 
 
+    @Post(url = "/oauth/token")
+    JSONObject getEmrToken(@Header JSONObject header, @FormBody JSONObject jsonObject);
+
 
 }

+ 39 - 5
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/emr/EmrServer.java

@@ -1,18 +1,23 @@
 package thyyxxk.webserver.service.zhuyuanyisheng.emr;
 
+import cn.hutool.core.codec.Base64;
+import cn.hutool.http.HttpRequest;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.alibaba.fastjson.TypeReference;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.dtflys.forest.http.ForestRequest;
+import com.dtflys.forest.interceptor.Interceptor;
+import com.dtflys.forest.reflection.ForestMethod;
+import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.ListUtils;
 import org.jetbrains.annotations.NotNull;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
-import org.yaml.snakeyaml.events.Event;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.constants.Capacity;
 import thyyxxk.webserver.constants.EmrType;
@@ -39,8 +44,8 @@ import thyyxxk.webserver.service.externalhttp.emr.EmrEditor;
 import thyyxxk.webserver.service.redislike.RedisLikeService;
 import thyyxxk.webserver.utils.*;
 
+import javax.annotation.PostConstruct;
 import java.util.*;
-import java.util.stream.Collector;
 import java.util.stream.Collectors;
 
 
@@ -51,7 +56,6 @@ public class EmrServer {
     private final EmrEditor emr;
     private final EmrFolderDao folderDao;
     private final RedisServer redisServer;
-
     private final PublicServer publicServer;
     private final LoginDao loginDao;
     private final RedisLikeService redisLikeService;
@@ -60,7 +64,33 @@ public class EmrServer {
     private static final Map<String, String> GROUP_MAP = new HashMap<>();
     private final String HOSPITAL_WIDE_FOLDER = "3b1655a006ff11edbc820dada413ba28";
 
-    public EmrServer(EmrPatientDao dao, EmrEditor emr, EmrFolderDao folderDao, RedisServer redisServer, PublicServer publicServer, LoginDao loginDao, RedisLikeService redisLikeService, WebSocketService socketService) {
+    private static String emrToken = null;
+
+    public static class EmrInterceptor implements Interceptor<String> {
+        @Override
+        public void onInvokeMethod(ForestRequest request, ForestMethod method, Object[] args) {
+            request.addHeader("emr-token", emrToken);
+        }
+    }
+
+    @PostConstruct
+    @Scheduled(cron = "* * */12 * * ?")
+    public void token() {
+        String result = HttpRequest.post("http://172.16.32.125:8001/emr/runtime/api/v1/oauth/token")
+                .header("Authorization", "Basic " + Base64.encode("user:dc71ccfec05b799ad52360c48d504019"))
+                .form("grant_type", "client_credentials").execute().body();
+        JSONObject data = JSONObject.parseObject(result);
+        emrToken = data.getString("access_token");
+    }
+
+    public EmrServer(EmrPatientDao dao,
+                     EmrEditor emr,
+                     EmrFolderDao folderDao,
+                     RedisServer redisServer,
+                     PublicServer publicServer,
+                     LoginDao loginDao,
+                     RedisLikeService redisLikeService,
+                     WebSocketService socketService) {
         this.dao = dao;
         this.emr = emr;
         this.folderDao = folderDao;
@@ -919,5 +949,9 @@ public class EmrServer {
         return ResultVoUtil.success(dao.getOpRecordList(patNo, times));
     }
 
+    public String getEmrToken() {
+        return emrToken;
+    }
+
 
 }