Browse Source

add:多健康码平台白名单添加

lileilei 2 years ago
parent
commit
ac4757d6f0

+ 1 - 0
health-code.iml

@@ -25,6 +25,7 @@
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" name="Maven: cn.hutool:hutool-all:5.7.0" level="project" />
     <orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:2.4.5" level="project" />
     <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.4.5" level="project" />
     <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.4.5" level="project" />

+ 8 - 1
src/main/java/com/yixin/ms/server/HealthServer.java

@@ -4,6 +4,7 @@ import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
 import com.yixin.ms.boot.restful.RestCode;
 import com.yixin.ms.boot.restful.RestResult;
+import com.yixin.ms.boot.restful.ServiceException;
 import com.yixin.ms.crypto.util.SzhzSm4Util;
 import com.yixin.ms.server.dto.HealthCodeDTO;
 import com.yixin.ms.server.vo.HealthCodeVO;
@@ -32,7 +33,13 @@ public class HealthServer {
      * @return
      */
     public RestResult<HealthCodeVO> queryInfoByBarCode(String barcode){
-        String body = HttpUtil.post(queryInfoByBarCodeUrl, JSON.toJSONString(new HealthCodeDTO().setAppKey(appKey).setAppSecret(appSecret).setBarCode(barcode)));
+        String body = null;
+        try {
+            body = HttpUtil.post(queryInfoByBarCodeUrl, JSON.toJSONString(new HealthCodeDTO().setAppKey(appKey).setAppSecret(appSecret).setBarCode(barcode)));
+        }catch (Exception e){
+            throw new ServiceException("barCode查询信息异常,请稍后重试");
+        }
+
         RestResult restResult = JSON.parseObject(body, RestResult.class);
         if(restResult.getCode() == RestCode.SUCCESS.getCode()){
             HealthCodeVO healthCodeVO = JSON.parseObject(JSON.toJSONString(restResult.getData()), HealthCodeVO.class);

+ 13 - 5
src/main/java/com/yixin/ms/server/ScenicServer.java

@@ -11,10 +11,8 @@ import com.yixin.ms.server.vo.ScenicConsumeVO;
 import com.yixin.ms.server.vo.ScenicVerifyVO;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
-import java.security.Security;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -39,14 +37,19 @@ public class ScenicServer {
         List<ScenicProperties.Config> configs = scenicProperties.getConfigs();
         Map<Integer, ScenicProperties.Config> configMap = configs.stream().collect(Collectors.toMap(ScenicProperties.Config::getAdminId, v -> v, (v1, v2) -> v1));
         ScenicProperties.Config config = configMap.get(adminId);
-        if(!config.getAdminId().equals(adminId)){
+        if(config == null || !config.getAdminId().equals(adminId)){
             throw new ServiceException("景区预约账号未配置,请检查");
         }
 
         dto.setTimestamp(String.valueOf(System.currentTimeMillis())).setAccount(config.getAccount());
         //签名
         dto.setSign(SecureUtil.md5(new StringBuilder().append(JSON.toJSONString(dto)).append(config.getKey()).toString()));
-        String body = HttpUtil.post(scenicProperties.getVerifyUrl(), JSON.toJSONString(dto));
+        String body = null;
+        try {
+            body = HttpUtil.post(scenicProperties.getVerifyUrl(), JSON.toJSONString(dto));
+        }catch (Exception e){
+            throw new ServiceException("景区预约服务系统异常,请稍后重试");
+        }
         log.info("根据预约码或者身份证查询是否预约,入参信息:{}, 响应信息:{}", JSON.toJSONString(dto),  body);
         ScenicVerifyVO verifyVO = JSON.parseObject(body, ScenicVerifyVO.class);
         return verifyVO;
@@ -68,7 +71,12 @@ public class ScenicServer {
         dto.setTimestamp(String.valueOf(System.currentTimeMillis())).setAccount(config.getAccount());
         //签名
         dto.setSign(SecureUtil.md5(new StringBuilder().append(JSON.toJSONString(dto)).append(config.getKey()).toString()));
-        String body = HttpUtil.post(scenicProperties.getConsumeUrl(), JSON.toJSONString(dto));
+        String body = null;
+        try {
+            body = HttpUtil.post(scenicProperties.getConsumeUrl(), JSON.toJSONString(dto));
+        }catch (Exception e){
+            throw new ServiceException("景区预约服务系统异常,请稍后重试");
+        }
         log.info("游客放行入参信息:{}, 推送响应内容:{}", JSON.toJSONString(dto), body);
         return JSON.parseObject(body, ScenicConsumeVO.class);
     }

+ 46 - 33
src/main/java/com/yixin/ms/service/impl/HealthCodeServiceImpl.java

@@ -62,28 +62,28 @@ public class HealthCodeServiceImpl implements HealthCodeService {
     @Autowired
     private Executor executor;
     //顺序
-    private static Integer index = 0;
-    private static List<HealthMockDTO> mockDTOList = Lists.newArrayList();
-
-    static {
-        if (CollectionUtil.isEmpty(mockDTOList)) {
-            mockDTOList.add(new HealthMockDTO().setIndex(0).setMzt("绿码").setNucleicExpirationTime(0));
-            mockDTOList.add(new HealthMockDTO().setIndex(1).setMzt("绿码").setNucleicExpirationTime(24));
-            mockDTOList.add(new HealthMockDTO().setIndex(2).setMzt("绿码").setNucleicExpirationTime(48));
-            mockDTOList.add(new HealthMockDTO().setIndex(3).setMzt("绿码").setNucleicExpirationTime(72));
-            mockDTOList.add(new HealthMockDTO().setIndex(4).setMzt("绿码").setNucleicExpirationTime(168));
-            mockDTOList.add(new HealthMockDTO().setIndex(5).setMzt("黄码").setNucleicExpirationTime(0));
-            mockDTOList.add(new HealthMockDTO().setIndex(6).setMzt("黄码").setNucleicExpirationTime(24));
-            mockDTOList.add(new HealthMockDTO().setIndex(7).setMzt("黄码").setNucleicExpirationTime(48));
-            mockDTOList.add(new HealthMockDTO().setIndex(8).setMzt("黄码").setNucleicExpirationTime(72));
-            mockDTOList.add(new HealthMockDTO().setIndex(9).setMzt("黄码").setNucleicExpirationTime(168));
-            mockDTOList.add(new HealthMockDTO().setIndex(10).setMzt("红码").setNucleicExpirationTime(0));
-            mockDTOList.add(new HealthMockDTO().setIndex(11).setMzt("红码").setNucleicExpirationTime(24));
-            mockDTOList.add(new HealthMockDTO().setIndex(12).setMzt("红码").setNucleicExpirationTime(48));
-            mockDTOList.add(new HealthMockDTO().setIndex(13).setMzt("红码").setNucleicExpirationTime(72));
-            mockDTOList.add(new HealthMockDTO().setIndex(14).setMzt("红码").setNucleicExpirationTime(168));
-        }
-    }
+//    private static Integer index = 0;
+//    private static List<HealthMockDTO> mockDTOList = Lists.newArrayList();
+
+//    static {
+//        if (CollectionUtil.isEmpty(mockDTOList)) {
+//            mockDTOList.add(new HealthMockDTO().setIndex(0).setMzt("绿码").setNucleicExpirationTime(0));
+//            mockDTOList.add(new HealthMockDTO().setIndex(1).setMzt("绿码").setNucleicExpirationTime(24));
+//            mockDTOList.add(new HealthMockDTO().setIndex(2).setMzt("绿码").setNucleicExpirationTime(48));
+//            mockDTOList.add(new HealthMockDTO().setIndex(3).setMzt("绿码").setNucleicExpirationTime(72));
+//            mockDTOList.add(new HealthMockDTO().setIndex(4).setMzt("绿码").setNucleicExpirationTime(168));
+//            mockDTOList.add(new HealthMockDTO().setIndex(5).setMzt("黄码").setNucleicExpirationTime(0));
+//            mockDTOList.add(new HealthMockDTO().setIndex(6).setMzt("黄码").setNucleicExpirationTime(24));
+//            mockDTOList.add(new HealthMockDTO().setIndex(7).setMzt("黄码").setNucleicExpirationTime(48));
+//            mockDTOList.add(new HealthMockDTO().setIndex(8).setMzt("黄码").setNucleicExpirationTime(72));
+//            mockDTOList.add(new HealthMockDTO().setIndex(9).setMzt("黄码").setNucleicExpirationTime(168));
+//            mockDTOList.add(new HealthMockDTO().setIndex(10).setMzt("红码").setNucleicExpirationTime(0));
+//            mockDTOList.add(new HealthMockDTO().setIndex(11).setMzt("红码").setNucleicExpirationTime(24));
+//            mockDTOList.add(new HealthMockDTO().setIndex(12).setMzt("红码").setNucleicExpirationTime(48));
+//            mockDTOList.add(new HealthMockDTO().setIndex(13).setMzt("红码").setNucleicExpirationTime(72));
+//            mockDTOList.add(new HealthMockDTO().setIndex(14).setMzt("红码").setNucleicExpirationTime(168));
+//        }
+//    }
 
     @Override
     public HealtCodeUserVO getShortTermCertificate(ShortTermDTO shortTermDTO) {
@@ -125,6 +125,7 @@ public class HealthCodeServiceImpl implements HealthCodeService {
 
     @Override
     public RestResult getShortTerm(ShortTermDTO shortTermDTO) {
+        log.info("");
         if (StrUtil.isEmpty(shortTermDTO.getHealthCode())) {
             if (StringUtils.isBlank(shortTermDTO.getIdNumber()) && StringUtils.isBlank(shortTermDTO.getName())) {
                 throw new ServiceException(701, "身份证和姓名为空哦");
@@ -176,6 +177,12 @@ public class HealthCodeServiceImpl implements HealthCodeService {
                 placeInfoVO = placeInfoResult.getData();
                 HealthResultVO<DeviceScanIdCardVO> scanIdCardResult = null;
                 if (StrUtil.isNotEmpty(shortTermDTO.getHealthCode())) {
+                    //非景区预约,通用健康码查询
+                    if (!placeInfoVO.getScenicFlag()) {
+                        scanIdCardResult = this.deviceScanCode(shortTermDTO);
+                    }
+
+                    //景区预约,走预约码查询
                     if (placeInfoVO.getScenicFlag() && NumberUtil.isNumber(shortTermDTO.getHealthCode())) {
                         ScenicVerifyVO verifyVO = scenicServer.verify(new ScenicVerifyDTO().setReservationCode(shortTermDTO.getHealthCode()), placeInfoVO.getAdminId());
                         if (!verifyVO.getReleaseStatus()) {
@@ -184,7 +191,10 @@ public class HealthCodeServiceImpl implements HealthCodeService {
                             shortTermDTO.setName(verifyVO.getUserName()).setIdNumber(verifyVO.getIdNumber());
                             scanIdCardResult = this.deviceScanIdCardEncrypt(shortTermDTO);
                         }
-                    } else {
+                    }
+
+                    //景区预约,走健康码查询
+                    if (placeInfoVO.getScenicFlag() && !NumberUtil.isNumber(shortTermDTO.getHealthCode())) {
                         RestResult<HealthCodeVO> restResult = healthServer.queryInfoByBarCode(shortTermDTO.getHealthCode());
                         HealthCodeVO healthCodeVO = null;
 
@@ -287,13 +297,13 @@ public class HealthCodeServiceImpl implements HealthCodeService {
             //用户健康码信息
             HealtCodeTypeVO codeTypeVO = userVO.getData().stream().findFirst().get();
             //TODO MOCK 测试 start
-            HealthMockDTO mockDTO = mockDTOList.get(index);
-            codeTypeVO.setMzt(mockDTO.getMzt());
-            nucleicExpirationTime = mockDTO.getNucleicExpirationTime();
-            index++;
-            if(index > 14){
-                index = 0;
-            }
+//            HealthMockDTO mockDTO = mockDTOList.get(index);
+//            codeTypeVO.setMzt(mockDTO.getMzt());
+//            nucleicExpirationTime = mockDTO.getNucleicExpirationTime();
+//            index++;
+//            if (index > 14) {
+//                index = 0;
+//            }
             //TODO MOCK 测试 end
 
             //用户核酸信息
@@ -307,6 +317,8 @@ public class HealthCodeServiceImpl implements HealthCodeService {
                 userVO.setBackgroundColor(ColorEnum.GREEN.getValue());
             }
 
+            //核酸过期标识
+            boolean nucleicExpirationFlag = false;
             /**
              * 开门规则判定校验:红黄码,核酸有效期
              */
@@ -322,12 +334,13 @@ public class HealthCodeServiceImpl implements HealthCodeService {
                     userVO.setBackgroundColor(ColorEnum.YELLOW.getValue());
                 }
             } else if (nucleicExpirationTime != null && !nucleicExpirationTime.equals(0) && (CollectionUtils.isEmpty(nucleinList) || DateUtil.betweenMs(nucleinList.stream().findFirst().get().getShowTime(), DateUtil.date()) > nucleicExpirationTime * 60 * 60 * 1000)) {
+                nucleicExpirationFlag = true;
                 userVO.setIsOpen(HealthOpenEnum.NO_THOROUGHFARE.getCode());
                 String openMsg;
                 if (nucleicExpirationTime <= NucleicRuleEnum.SEVENTY_TWO.getValue()) {
                     openMsg = new StringBuilder().append(nucleicExpirationTime).append("小时内无有效核酸阴性记录,禁止通行").toString();
                 } else {
-                    openMsg = new StringBuilder().append(nucleicExpirationTime).append("天内无有效核酸阴性记录,禁止通行").toString();
+                    openMsg = new StringBuilder().append((nucleicExpirationTime / 24) + 1).append("天内无有效核酸阴性记录,禁止通行").toString();
                 }
                 userVO.setOpenMsg(openMsg).setOpenVoiceMsg(openMsg);
             } else {
@@ -336,7 +349,7 @@ public class HealthCodeServiceImpl implements HealthCodeService {
 
             if (CollectionUtil.isNotEmpty(nucleinList)) {
                 HealtCodeNucleinVO nucleinVO = nucleinList.stream().findFirst().get();
-                nucleinVO.setTitle("核酸检测").setContentColor(ColorEnum.GREEN.getValue()).setIconUrl(NucleicStatusEnum.NEGATIVE.getUrl());
+                nucleinVO.setTitle("核酸检测").setContentColor(nucleicExpirationFlag ? ColorEnum.YELLOW.getValue() : ColorEnum.GREEN.getValue()).setIconUrl(nucleicExpirationFlag ? NucleicStatusEnum.NOT_AVAILABLE.getUrl() : NucleicStatusEnum.NEGATIVE.getUrl());
                 if (nucleinVO.getReportTime() != null && DateUtil.compare(nucleinVO.getChecktime(), nucleinVO.getReportTime()) > 0) {
                     nucleinVO.setContent(new StringBuilder().append(NucleicRuleEnum.TWENTY_FOUR.getValue()).append("H").append(" 结果未出").toString());
                 } else {
@@ -348,7 +361,7 @@ public class HealthCodeServiceImpl implements HealthCodeService {
                     } else if (betweenHour < NucleicRuleEnum.SEVENTY_TWO.getValue()) {
                         nucleinVO.setContent(new StringBuilder().append(NucleicRuleEnum.SEVENTY_TWO.getValue()).append(" ").append(nucleinVO.getResult()).toString());
                     } else {
-                        nucleinVO.setContent(new StringBuilder().append(DateUtil.betweenDay(nucleinVO.getShowTime(), DateUtil.date(), true)).append("天 ").append(nucleinVO.getResult()).toString());
+                        nucleinVO.setContent(new StringBuilder().append(DateUtil.betweenDay(nucleinVO.getShowTime(), DateUtil.date(), false) + 1).append("天 ").append(nucleinVO.getResult()).toString());
                     }
                 }
             } else {

+ 4 - 4
src/main/resources/application-prod.yml

@@ -140,10 +140,10 @@ irs:
 #皋亭山景区预约服务
 scenic:
   configs:
-    - adminId: 81
+    - adminId: 117
       account: 1510813918447009792
       key: 7e1c0f501eb711eda50a753d19fc4e7b
-  verifyUrl: https://test.d6.com.cn/data/notify/demo/verify
-  queryUrl: https://test.d6.com.cn/data/notify/demo/query
-  consumeUrl: https://test.d6.com.cn/data/notify/demo/consume
+  verifyUrl: https://api.d6.com.cn/openapi/v1/verify
+  queryUrl: https://api.d6.com.cn/openapi/v1/query
+  consumeUrl: https://api.d6.com.cn/openapi/v1/consume
 

+ 16 - 5
src/main/resources/application-test.yml

@@ -137,13 +137,24 @@ irs:
       AppKey: 36022dcb14f2f7d5
       queryInfoByBarCodeUrl: https://sql.hz.gov.cn/ESBWeb/servlets/33.1111.zjhz.kaEW1bjSV8.SynReq@1.0
 
+#皋亭山景区预约服务
+#scenic:
+#  configs:
+#    - adminId: 81
+#      account: 1447686702163296256
+#      key: 74d9aed80d7a4c7181ba9615fae0fc11
+#  verifyUrl: https://test.d6.com.cn/data/notify/demo/verify
+#  queryUrl: https://test.d6.com.cn/data/notify/demo/query
+#  consumeUrl: https://test.d6.com.cn/data/notify/demo/consume
+
+
 #皋亭山景区预约服务
 scenic:
   configs:
     - adminId: 81
-      account: 1447686702163296256
-      key: 74d9aed80d7a4c7181ba9615fae0fc11
-  verifyUrl: https://test.d6.com.cn/data/notify/demo/verify
-  queryUrl: https://test.d6.com.cn/data/notify/demo/query
-  consumeUrl: https://test.d6.com.cn/data/notify/demo/consume
+      account: 1510813918447009792
+      key: 7e1c0f501eb711eda50a753d19fc4e7b
+  verifyUrl: https://api.d6.com.cn/openapi/v1/verify
+  queryUrl: https://api.d6.com.cn/openapi/v1/query
+  consumeUrl: https://api.d6.com.cn/openapi/v1/consume
 

+ 1 - 1
src/main/resources/application.yml

@@ -1,3 +1,3 @@
 spring:
   profiles:
-    active: test
+    active: prod