Browse Source

身份信息持久化,保存证件照片
返回时间控制

FanQun 2 years ago
parent
commit
78cef4336a

+ 6 - 2
src/main/java/com/rshy/project/hy/manager/impl/RshyJkManagerImpl.java

@@ -78,7 +78,7 @@ public class RshyJkManagerImpl implements RshyJkManager {
     public Future<RshyVo> getRshyInfo(RshyParam rshyParam) {
         // timeout 转成毫秒 这里考虑到网络传输延时等原因,减去300ms
         rshyParam.setTimeout((int) TimeUnit.MILLISECONDS.convert(rshyParam.getTimeout(), TimeUnit.SECONDS));
-        int jkmTimeout = rshyParam.getTimeout() - 300;
+        int jkmTimeout = rshyParam.getTimeout() - 500;
         RshyVo rshyVo = new RshyVo();
         PctgkryDTO gkryDTO = new PctgkryDTO();
         ResultDTO resultDTO = new ResultDTO();
@@ -113,6 +113,8 @@ public class RshyJkManagerImpl implements RshyJkManager {
             if (rshyParam.getIdentity() != null) {
                 rshyVo.setXm(rshyParam.getIdentity().getName());
                 rshyVo.setPhone(rshyParam.getIdentity().getPhone());
+                rshyVo.setAddress(rshyParam.getIdentity().getAddress());
+                rshyVo.setPhoto(rshyParam.getIdentity().getPhoto());
             } else {
                 saveBarcode2DB(StrUtil.EMPTY, rshyParam.getSfzh());
             }
@@ -120,7 +122,7 @@ public class RshyJkManagerImpl implements RshyJkManager {
         int jkmUsedTime = (int) DateUtil.between(beginDate, DateTime.now(), DateUnit.MS);
         System.out.println("健康码接口用时: " + jkmUsedTime + "毫秒");
 
-        rshyParam.setTimeout(rshyParam.getTimeout() - jkmUsedTime - 400);
+        rshyParam.setTimeout(rshyParam.getTimeout() - jkmUsedTime - 600);
         //剩余时间不到50ms,直接返回
         if (rshyParam.getTimeout() <= 50) {
             return new AsyncResult<>(rshyVo);
@@ -142,6 +144,7 @@ public class RshyJkManagerImpl implements RshyJkManager {
                     add(() -> resultDTO.setPctzjzpResultDTO(itfwServer.getPctzjzp(rshyParam.getSfzh(), rshyParam.getTimeout())));
                 } else {
                     add(() -> itfwServer.savePhoto2DB(rshyParam.getSfzh(), rshyParam.getPhoto()));
+                    rshyVo.setPhoto(null);
                 }
             }
         };
@@ -321,6 +324,7 @@ public class RshyJkManagerImpl implements RshyJkManager {
         identity.setName(rshyVo.getXm());
         identity.setAddress(rshyVo.getAddress());
         identity.setPhone(rshyVo.getPhone());
+        //identity.setPhoto(rshyVo.getPhoto());
         identityService.saveOK(identity);
     }
 

+ 2 - 0
src/main/java/com/rshy/project/hy/model/entity/Identity.java

@@ -32,6 +32,8 @@ public class Identity implements Serializable {
 
     private String phone;
 
+    private String photo;
+
     @Override
     public String toString() {
         return "Identity{" +

+ 5 - 0
src/main/java/com/rshy/project/hy/service/impl/IdentityServiceImpl.java

@@ -11,6 +11,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.cache.annotation.CachePut;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -27,6 +29,7 @@ import java.util.Map;
 @Service
 @EnableCaching
 @Slf4j
+@EnableAsync
 public class IdentityServiceImpl extends ServiceImpl<IdentityMapper, Identity> implements IdentityService {
 
     @Resource
@@ -51,6 +54,7 @@ public class IdentityServiceImpl extends ServiceImpl<IdentityMapper, Identity> i
     }
 
     @Override
+    @Async("hstTaskExecutor")
     @CachePut(value = "identity", key = "#p0.idNum", unless = "#result.name == null")
     public Identity saveOK(Identity identity) {
         if (super.saveOrUpdate(identity)) {
@@ -62,6 +66,7 @@ public class IdentityServiceImpl extends ServiceImpl<IdentityMapper, Identity> i
     }
 
     @Override
+    @Async("hstTaskExecutor")
     public void savePhoto(String idNum, String photo) {
         log.info("保存证件照片到数据库, 身份证号码: {}", idNum);
         if (StrUtil.isBlank(idNum)) return;

+ 3 - 2
src/main/java/com/rshy/project/hy/web/controller/RshyController.java

@@ -71,6 +71,8 @@ public class RshyController {
 
         DateTime time1 = DateTime.now();
 
+        rshyParam.setTimeout(5);
+
         log.info("普通核验接口请求参数:{}", StrUtil.brief(JSON.toJSONString(rshyParam), WebConstant.DISPLAY_MAX_LENGTH));
 
         RshyVo rshyVo = new RshyVo().setPassStatus(PassStatusEnum.NORMAL_TRAFFIC);
@@ -86,11 +88,10 @@ public class RshyController {
                 rshyParam.setIdentity(identity);
             }
         }
-        rshyParam.setTimeout(5);
         try {
             //RshyVo rshyVo = rshyJkManager.getRshyInfo(rshyParam);
             Future<RshyVo> future = rshyJkManager.getRshyInfo(rshyParam);
-            rshyVo = future.get(rshyParam.getTimeout() * 1000 - 100, TimeUnit.MILLISECONDS);
+            rshyVo = future.get(rshyParam.getTimeout() * 1000 - 300, TimeUnit.MILLISECONDS);
         } catch (InterruptedException | ExecutionException e) {
             log.error("普通核验接口异常: {}", e.getMessage());
             //e.printStackTrace();

+ 1 - 0
src/main/resources/mapper/IdentityMapper.xml

@@ -9,6 +9,7 @@
         <result column="name" property="name"/>
         <result column="address" property="address"/>
         <result column="phone" property="phone"/>
+        <result column="photo" property="photo"/>
     </resultMap>
 
     <select id="getIdNum" resultType="string">