Browse Source

【奥维-赛力斯】

DINGYL 2 weeks ago
parent
commit
1e7264963a

+ 16 - 5
src/main/java/com/uas/eis/serviceImpl/SERESServiceImpl.java

@@ -53,8 +53,18 @@ public class SERESServiceImpl implements SERESService {
         long nowMs = System.currentTimeMillis();
         // 无token 或 距离过期不足1分钟,重新拉取
         if (accessToken == null ) {
-            logger.info("token 为空重新获取");
-            accessToken=refreshToken();
+            SqlRowList rs = baseDao.queryForRowSet("select access_token,EXP_  from (select * from AW_ZHJK.SERES_TOKEN_LOG where EXP_>"+(nowMs+REFRESH_ADVANCE_MS)+" order by EXP_ desc) where rownum=1");
+            if(rs.next()){
+                String token=rs.getString("access_token");
+                int exp=rs.getInt("exp_");
+                logger.info("从数据库获取上次有效token {}",token);
+                accessToken=token.toString();
+                TokenManager.setToken(seresTokenKey,accessToken,exp);
+            }else{
+                logger.info("token 为空重新获取");
+                accessToken=refreshToken();
+            }
+
         }
         return accessToken;
     }
@@ -73,14 +83,13 @@ public class SERESServiceImpl implements SERESService {
         reqBody.put("client_id", clientId);
         reqBody.put("client_secret", clientSecret);
         reqBody.put("exp", expTs);
-        System.out.println(expTs);
          // 发送POST
         CloseableHttpClient httpClient = HttpClients.createDefault();
         HttpPost httpPost = new HttpPost(tokenUrl);
         httpPost.setHeader("Content-Type", "application/json");
         StringEntity entity = new StringEntity(reqBody.toString(), "UTF-8");
         httpPost.setEntity(entity);
-
+        logger.info("reqBody {}", JSON.toJSONString(reqBody));
         try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
             String respJson = EntityUtils.toString(response.getEntity(), "UTF-8");
             JSONObject respObj = JSON.parseObject(respJson);
@@ -88,8 +97,9 @@ public class SERESServiceImpl implements SERESService {
                 throw new RuntimeException("获取Token失败,响应:" + respJson);
             }
             accessToken = respObj.getString("access_token");
-            TokenManager.setToken(seresTokenKey,respObj.getString("access_token"),expTs);
+            TokenManager.setToken(seresTokenKey,accessToken,expTs);
             logger.info("token {}",accessToken);
+            baseDao.execute("insert into AW_ZHJK.SERES_TOKEN_LOG(access_token,exp_) VALUES('"+accessToken+"',"+expTs+")");
             System.out.println("Token刷新成功,有效期:" + respObj.get("expires_in") + "秒");
         } finally {
             httpClient.close();
@@ -137,6 +147,7 @@ public class SERESServiceImpl implements SERESService {
                     modelMap.put("message",queryRes.getMessage());
                     modelMap.put("count",queryRes.getData().getTotalCount());
                     modelMap.put("data",queryRes.getData().getList());
+                    modelMap.put("success", true);
                 }else{
                     modelMap.put("message",queryRes.getMessage());
                 }

File diff suppressed because it is too large
+ 3 - 16
src/test/java/com/uas/eis/UasEisApplicationTests.java


Some files were not shown because too many files changed in this diff