|
@@ -13,6 +13,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.rshy.project.hy.manager.RshyJkManager;
|
|
|
import com.rshy.project.hy.model.constant.ItfwConstant;
|
|
|
import com.rshy.project.hy.model.dto.NucleicAcidDTO;
|
|
|
+import com.rshy.project.hy.model.entity.Identity;
|
|
|
import com.rshy.project.hy.model.enums.*;
|
|
|
import com.rshy.project.hy.server.ItfwServer;
|
|
|
import com.rshy.project.hy.server.VIIDServer;
|
|
@@ -23,13 +24,17 @@ import com.rshy.project.hy.server.param.RshyQuickParam;
|
|
|
import com.rshy.project.hy.server.vo.RetrievaResultVO;
|
|
|
import com.rshy.project.hy.server.vo.RetrievalRepositoryVO;
|
|
|
import com.rshy.project.hy.server.vo.RshyVo;
|
|
|
+import com.rshy.project.hy.service.IdentityService;
|
|
|
import com.rshy.project.hy.util.ObjectUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.context.annotation.DependsOn;
|
|
|
+import org.springframework.core.task.support.ExecutorServiceAdapter;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.AsyncResult;
|
|
|
+import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -37,6 +42,8 @@ import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Future;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
@@ -50,6 +57,7 @@ import java.util.stream.Collectors;
|
|
|
@Component
|
|
|
@Slf4j
|
|
|
@DependsOn("itfwServer")
|
|
|
+@EnableAsync
|
|
|
public class RshyJkManagerImpl implements RshyJkManager {
|
|
|
@Resource
|
|
|
private YituFaceServer yituFaceServer;
|
|
@@ -59,13 +67,17 @@ public class RshyJkManagerImpl implements RshyJkManager {
|
|
|
private VIIDServer viidServer;
|
|
|
@Resource
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
+ @Resource
|
|
|
+ private ThreadPoolTaskExecutor poolTaskExecutor;
|
|
|
+ @Resource
|
|
|
+ private IdentityService identityService;
|
|
|
|
|
|
@Override
|
|
|
@Async("hstTaskExecutor")
|
|
|
public Future<RshyVo> getRshyInfo(RshyParam rshyParam) {
|
|
|
// timeout 转成毫秒 这里考虑到网络传输延时等原因,减去300ms
|
|
|
- rshyParam.setTimeout((int) TimeUnit.MILLISECONDS.convert(rshyParam.getTimeout(), TimeUnit.SECONDS) - 300);
|
|
|
- int jkmTimeout = rshyParam.getTimeout();
|
|
|
+ rshyParam.setTimeout((int) TimeUnit.MILLISECONDS.convert(rshyParam.getTimeout(), TimeUnit.SECONDS));
|
|
|
+ int jkmTimeout = rshyParam.getTimeout() - 300;
|
|
|
RshyVo rshyVo = new RshyVo();
|
|
|
PctgkryDTO gkryDTO = new PctgkryDTO();
|
|
|
ResultDTO resultDTO = new ResultDTO();
|
|
@@ -73,7 +85,8 @@ public class RshyJkManagerImpl implements RshyJkManager {
|
|
|
DateTime beginDate = DateTime.now();
|
|
|
PctjkmInfoDTO jkmInfo = null;
|
|
|
|
|
|
- if (StringUtils.isNotBlank(rshyParam.getBarCode()) || StringUtils.isNotBlank(rshyParam.getSfzh())) {
|
|
|
+ // 刷健康码或场所码
|
|
|
+ if (StringUtils.isNotBlank(rshyParam.getBarCode()) && StringUtils.isBlank(rshyParam.getSfzh())) {
|
|
|
try {
|
|
|
//查询健康码信息
|
|
|
jkmInfo = itfwServer.getPctjkm(rshyParam.getBarCode(), rshyParam.getSfzh(), jkmTimeout);
|
|
@@ -90,21 +103,31 @@ public class RshyJkManagerImpl implements RshyJkManager {
|
|
|
if (jkmInfo != null) {
|
|
|
rshyParam.setSfzh(jkmInfo.getId_num());
|
|
|
rshyVo.setSfzh(jkmInfo.getId_num()).setXm(jkmInfo.getUser_name()).setHealthCode(jkmInfo.getColor_code_label()).setPhone(jkmInfo.getPn());
|
|
|
+ saveIdentity(rshyParam.getBarCode(), rshyVo);
|
|
|
} else {
|
|
|
rshyVo.setSfzh(rshyParam.getSfzh());
|
|
|
+ if (rshyParam.getIdentity() != null) {
|
|
|
+ rshyVo.setXm(rshyParam.getIdentity().getName());
|
|
|
+ rshyVo.setPhone(rshyParam.getIdentity().getPhone());
|
|
|
+ }
|
|
|
}
|
|
|
int jkmUsedTime = (int) DateUtil.between(beginDate, DateTime.now(), DateUnit.MS);
|
|
|
System.out.println("健康码接口用时: " + jkmUsedTime + "毫秒");
|
|
|
|
|
|
- rshyParam.setTimeout(rshyParam.getTimeout() - jkmUsedTime - 300);
|
|
|
- //剩余时间不到10ms,直接返回
|
|
|
- if (rshyParam.getTimeout() <= 10) {
|
|
|
+ rshyParam.setTimeout(rshyParam.getTimeout() - jkmUsedTime - 400);
|
|
|
+ //剩余时间不到50ms,直接返回
|
|
|
+ if (rshyParam.getTimeout() <= 50) {
|
|
|
return new AsyncResult<>(rshyVo);
|
|
|
}
|
|
|
|
|
|
+ log.info(rshyParam.toString());
|
|
|
+
|
|
|
AtomicReference<RshyVo> quickRshyVo = new AtomicReference<>(new RshyVo());
|
|
|
List<Runnable> taskList = new ArrayList<Runnable>() {
|
|
|
{
|
|
|
+ if (StrUtil.isBlank(rshyParam.getBarCode())) {
|
|
|
+ add(() -> resultDTO.setPctjkmInfoDTO(itfwServer.getPctjkm("", rshyParam.getSfzh(), rshyParam.getTimeout())));
|
|
|
+ }
|
|
|
add(() -> resultDTO.setPctsfzResult(itfwServer.getPctsfz(rshyParam.getSfzh(), rshyParam.getTimeout())));
|
|
|
add(() -> resultDTO.setPctymDataDTOS(itfwServer.getPctym(rshyParam.getSfzh(), rshyParam.getTimeout())));
|
|
|
add(() -> resultDTO.setPcthsResultDTO(itfwServer.getPcths(rshyParam.getSfzh(), rshyParam.getTimeout())));
|
|
@@ -134,16 +157,28 @@ public class RshyJkManagerImpl implements RshyJkManager {
|
|
|
//}
|
|
|
|
|
|
//异步流并发处理
|
|
|
- taskList.parallelStream().forEach(v -> {
|
|
|
- try {
|
|
|
- v.run();
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("异常信息:{}", e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- });
|
|
|
+// taskList.parallelStream().forEach(v -> {
|
|
|
+// try {
|
|
|
+// v.run();
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("异常信息:{}", e.getMessage());
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// });
|
|
|
+
|
|
|
+ try {
|
|
|
+ log.info("{}个任务, 用时 {}毫秒", taskList.size(), startTaskAllInOnce(taskList, rshyParam.getTimeout() + 100));
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.error("异常信息:{}", e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
|
|
|
log.info("IT服务平台接口调用完成");
|
|
|
+ //用身份证号码获取到健康码信息
|
|
|
+ if (resultDTO.getPctjkmInfoDTO() != null) {
|
|
|
+ jkmInfo = resultDTO.getPctjkmInfoDTO();
|
|
|
+ rshyVo.setXm(resultDTO.getPctjkmInfoDTO().getUser_name()).setHealthCode(resultDTO.getPctjkmInfoDTO().getColor_code_label()).setPhone(resultDTO.getPctjkmInfoDTO().getPn());
|
|
|
+ }
|
|
|
//今日进站次数
|
|
|
rshyVo.setTimes(times(rshyVo.getSfzh()));
|
|
|
//疫苗
|
|
@@ -221,9 +256,56 @@ public class RshyJkManagerImpl implements RshyJkManager {
|
|
|
}
|
|
|
|
|
|
//System.out.println(JSONObject.toJSONString(resultDTO));
|
|
|
+ saveIdentity(StrUtil.EMPTY, rshyVo);
|
|
|
+
|
|
|
return new AsyncResult<>(rshyVo);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 并行执行任务
|
|
|
+ *
|
|
|
+ * @param task 任务列表
|
|
|
+ * @return 用时,毫秒
|
|
|
+ * @throws InterruptedException
|
|
|
+ */
|
|
|
+ protected long startTaskAllInOnce(List<Runnable> task, long timeout) throws InterruptedException {
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ System.out.println(startTime + " [" + Thread.currentThread() + "] All thread is ready, concurrent going...");
|
|
|
+ final CountDownLatch latch = new CountDownLatch(task.size());
|
|
|
+ ExecutorService executorService = new ExecutorServiceAdapter(poolTaskExecutor);
|
|
|
+ for (Runnable r : task) {
|
|
|
+ executorService.submit(() -> {
|
|
|
+ try {
|
|
|
+ r.run();
|
|
|
+ } finally {
|
|
|
+ latch.countDown();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ latch.await(timeout, TimeUnit.MILLISECONDS);
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ System.out.println(endTime + " [" + Thread.currentThread() + "] All thread is completed.");
|
|
|
+ return endTime - startTime;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Async
|
|
|
+ protected void saveIdentity(String barCode, RshyVo rshyVo) {
|
|
|
+ log.info("save identity ");
|
|
|
+ Identity identity = new Identity();
|
|
|
+ if (StrUtil.isNotBlank(barCode)) {
|
|
|
+ identity.setBarCode(barCode);
|
|
|
+ }
|
|
|
+ identity.setIdNum(rshyVo.getSfzh());
|
|
|
+ identity.setName(rshyVo.getXm());
|
|
|
+ identity.setAddress(rshyVo.getAddress());
|
|
|
+ identity.setPhone(rshyVo.getPhone());
|
|
|
+ identity.setPhoto(rshyVo.getPhoto());
|
|
|
+ identityService.saveOrUpdate(identity);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 组装返回的核酸信息
|
|
|
*
|