|
@@ -1,4 +1,4 @@
|
|
|
-package com.coffee.bus.his;
|
|
|
|
|
|
|
+package com.coffee.bus.hospital.his;
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
@@ -14,19 +14,18 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.coffee.bus.entity.BusClinicEntity;
|
|
import com.coffee.bus.entity.BusClinicEntity;
|
|
|
import com.coffee.bus.entity.BusHospitalEntity;
|
|
import com.coffee.bus.entity.BusHospitalEntity;
|
|
|
import com.coffee.bus.listener.event.bean.HisEvent;
|
|
import com.coffee.bus.listener.event.bean.HisEvent;
|
|
|
-import com.coffee.bus.script.DefaultParse;
|
|
|
|
|
-import com.coffee.bus.script.ExecuteResult;
|
|
|
|
|
-import com.coffee.bus.script.ScriptManager;
|
|
|
|
|
-import com.coffee.bus.script.ScriptParse;
|
|
|
|
|
|
|
+import com.coffee.bus.hospital.script.DefaultParse;
|
|
|
|
|
+import com.coffee.bus.hospital.script.ExecuteResult;
|
|
|
|
|
+import com.coffee.bus.hospital.script.ScriptManager;
|
|
|
|
|
+import com.coffee.bus.hospital.script.ScriptParse;
|
|
|
import com.coffee.bus.service.LocalBusClinicService;
|
|
import com.coffee.bus.service.LocalBusClinicService;
|
|
|
import com.coffee.bus.service.LocalBusHospitalService;
|
|
import com.coffee.bus.service.LocalBusHospitalService;
|
|
|
-import com.coffee.common.cache.ClusterConfigStorage;
|
|
|
|
|
|
|
+import com.coffee.common.cache.ConfigStorage;
|
|
|
|
|
+import com.coffee.common.cache.manager.ConfigStorageManager;
|
|
|
import com.coffee.common.cache.value.Value;
|
|
import com.coffee.common.cache.value.Value;
|
|
|
import com.coffee.common.exception.CustomException;
|
|
import com.coffee.common.exception.CustomException;
|
|
|
import com.coffee.common.result.R;
|
|
import com.coffee.common.result.R;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.redisson.api.RedissonClient;
|
|
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
import org.springframework.util.Assert;
|
|
|
import org.springframework.web.context.request.async.DeferredResult;
|
|
import org.springframework.web.context.request.async.DeferredResult;
|
|
|
import org.tio.core.ChannelContext;
|
|
import org.tio.core.ChannelContext;
|
|
@@ -54,35 +53,20 @@ public class HisScriptSession {
|
|
|
private ChannelContext channelContext;
|
|
private ChannelContext channelContext;
|
|
|
private ScriptManager scriptManager;
|
|
private ScriptManager scriptManager;
|
|
|
private LocalBusClinicService clinicService;
|
|
private LocalBusClinicService clinicService;
|
|
|
- private ClusterConfigStorage clusterConfigStorage;
|
|
|
|
|
|
|
+ private ConfigStorage clusterConfigStorage;
|
|
|
private LocalBusHospitalService hospitalService;
|
|
private LocalBusHospitalService hospitalService;
|
|
|
private Map<String,HisRequest> hisRequestMap=new ConcurrentHashMap<>();
|
|
private Map<String,HisRequest> hisRequestMap=new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
- public HisScriptSession(String hospitalId, ChannelContext channelContext, ScriptManager scriptManager,
|
|
|
|
|
- RedissonClient redissonClient, LocalBusClinicService clinicService, LocalBusHospitalService hospitalService) {
|
|
|
|
|
|
|
+ public HisScriptSession(String hospitalId, ScriptManager scriptManager, ConfigStorageManager configStorageManager, LocalBusClinicService clinicService, LocalBusHospitalService hospitalService) {
|
|
|
this.hospitalId = hospitalId;
|
|
this.hospitalId = hospitalId;
|
|
|
- this.channelContext = channelContext;
|
|
|
|
|
this.scriptManager = scriptManager;
|
|
this.scriptManager = scriptManager;
|
|
|
this.clinicService = clinicService;
|
|
this.clinicService = clinicService;
|
|
|
this.hospitalService=hospitalService;
|
|
this.hospitalService=hospitalService;
|
|
|
- init(redissonClient,hospitalId,hospitalService);
|
|
|
|
|
|
|
+ init(configStorageManager,hospitalId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public HisScriptSession(String hospitalId, ScriptManager scriptManager, RedissonClient redissonClient, LocalBusClinicService clinicService,LocalBusHospitalService hospitalService) {
|
|
|
|
|
- this.hospitalId = hospitalId;
|
|
|
|
|
- this.scriptManager = scriptManager;
|
|
|
|
|
- this.clinicService = clinicService;
|
|
|
|
|
- this.hospitalService=hospitalService;
|
|
|
|
|
- init(redissonClient,hospitalId,hospitalService);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void init(RedissonClient redissonClient, String hospitalId, LocalBusHospitalService hospitalService){
|
|
|
|
|
- BusHospitalEntity hospital = hospitalService.getById(hospitalId);
|
|
|
|
|
- if(hospital==null){
|
|
|
|
|
- throw new RuntimeException(String.format("医院{%s}不存在,获取医院脚本会话失败",hospitalId));
|
|
|
|
|
- }
|
|
|
|
|
- clusterConfigStorage=new ClusterConfigStorage(redissonClient,hospitalId);
|
|
|
|
|
- clusterConfigStorage.setConfig("info",hospital);
|
|
|
|
|
|
|
+ private void init(ConfigStorageManager configStorageManager, String hospitalId){
|
|
|
|
|
+ clusterConfigStorage = configStorageManager.getStorage(hospitalId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -127,7 +111,7 @@ public class HisScriptSession {
|
|
|
.sync(true)
|
|
.sync(true)
|
|
|
.timeout(timeout)
|
|
.timeout(timeout)
|
|
|
.timeUnit(unit)
|
|
.timeUnit(unit)
|
|
|
- .result(result)
|
|
|
|
|
|
|
+ .result(Arrays.asList(result))
|
|
|
.timestamp(new Date())
|
|
.timestamp(new Date())
|
|
|
.build();
|
|
.build();
|
|
|
sendRequest(channelContext,request);
|
|
sendRequest(channelContext,request);
|
|
@@ -164,7 +148,7 @@ public class HisScriptSession {
|
|
|
.sync(true)
|
|
.sync(true)
|
|
|
.timeout(timeout)
|
|
.timeout(timeout)
|
|
|
.timeUnit(unit)
|
|
.timeUnit(unit)
|
|
|
- .result(result)
|
|
|
|
|
|
|
+ .result(Arrays.asList(result))
|
|
|
.timestamp(new Date())
|
|
.timestamp(new Date())
|
|
|
.build();
|
|
.build();
|
|
|
result.onTimeout(()->{
|
|
result.onTimeout(()->{
|
|
@@ -256,6 +240,7 @@ public class HisScriptSession {
|
|
|
* @return void
|
|
* @return void
|
|
|
*/
|
|
*/
|
|
|
private ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
|
private ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
|
|
|
|
+
|
|
|
private void sendRequest(ChannelContext channelContext,HisRequest request){
|
|
private void sendRequest(ChannelContext channelContext,HisRequest request){
|
|
|
hisRequestMap.put(request.getMessageId(),request);
|
|
hisRequestMap.put(request.getMessageId(),request);
|
|
|
Tio.send(channelContext, WsResponse.fromText(JSONUtil.toJsonStr(request),"utf-8"));
|
|
Tio.send(channelContext, WsResponse.fromText(JSONUtil.toJsonStr(request),"utf-8"));
|
|
@@ -301,22 +286,30 @@ public class HisScriptSession {
|
|
|
Date requestTimestamp = hisRequest.getTimestamp();
|
|
Date requestTimestamp = hisRequest.getTimestamp();
|
|
|
long timeout = hisRequest.getTimeout();
|
|
long timeout = hisRequest.getTimeout();
|
|
|
TimeUnit timeUnit = hisRequest.getTimeUnit();
|
|
TimeUnit timeUnit = hisRequest.getTimeUnit();
|
|
|
- DeferredResult<R<BusClinicEntity>> result = hisRequest.getResult();
|
|
|
|
|
- if (requestTimestamp.getTime()+timeUnit.toMillis(timeout)>responseTimestamp.getTime()) {
|
|
|
|
|
- log.warn("请求[{}]已超时,请求时间[{}],响应时间[{}],是否为同步请求[{}]",messageId,requestTimestamp,responseTimestamp,sync);
|
|
|
|
|
- if(sync){
|
|
|
|
|
- result.setErrorResult("响应超时");
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ List<DeferredResult<R<BusClinicEntity>>> results = hisRequest.getResult();
|
|
|
|
|
+ if(CollectionUtil.isNotEmpty(results)){
|
|
|
|
|
+ results.parallelStream().forEach(result->{
|
|
|
|
|
+ if (requestTimestamp.getTime()+timeUnit.toMillis(timeout)>responseTimestamp.getTime()) {
|
|
|
|
|
+ log.warn("请求[{}]已超时,请求时间[{}],响应时间[{}],是否为同步请求[{}]",messageId,requestTimestamp,responseTimestamp,sync);
|
|
|
|
|
+ if(sync){
|
|
|
|
|
+ result.setErrorResult("响应超时");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //正常响应
|
|
|
|
|
+ BusClinicEntity clinic = handle(Value.simple(hisResponse.getContext()).asString(), hisResponse.getPatientCode());
|
|
|
|
|
+ result.setResult(R.success(clinic));
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
- //正常响应
|
|
|
|
|
- BusClinicEntity clinic = handle(Value.simple(hisResponse.getContext()).asString(), hisResponse.getPatientCode());
|
|
|
|
|
- result.setResult(R.success(clinic));
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}else {
|
|
}else {
|
|
|
if (hisRequest != null) {
|
|
if (hisRequest != null) {
|
|
|
log.warn("医院[{}]拉取信息失败,失败原因[{}]",hospitalId,hisResponse.getErrorMsg());
|
|
log.warn("医院[{}]拉取信息失败,失败原因[{}]",hospitalId,hisResponse.getErrorMsg());
|
|
|
- hisRequest.getResult().setResult(R.fail("更新失败,失败原因["+ hisResponse.getErrorMsg()+"]"));
|
|
|
|
|
|
|
+ List<DeferredResult<R<BusClinicEntity>>> results = hisRequest.getResult();
|
|
|
|
|
+ if(CollectionUtil.isNotEmpty(results)){
|
|
|
|
|
+ results.parallelStream().forEach(result-> result.setResult(R.fail("更新失败,失败原因["+ hisResponse.getErrorMsg()+"]")));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|