Procházet zdrojové kódy

feat: 车辆php页面请求日志入库定时任务增加过期秒数、过期时间字段

weijianghai před 1 rokem
rodič
revize
df7aeaea9a

+ 6 - 2
src/main/java/com/nokia/finance/tasks/dao/common/RequestLogDao.java

@@ -27,7 +27,9 @@ request_parameters,
 headers,
 app_id,
 time_stamp,
-token
+token,
+expire_time,
+expire_time_stamp
 )
 values
 <foreach collection="list" item="item" index="index" separator=",">
@@ -40,7 +42,9 @@ values
 #{item.headers},
 #{item.appId},
 #{item.timeStamp},
-#{item.token}
+#{item.token},
+#{item.expireTime},
+#{item.expireTimeStamp}
 )
 </foreach>
 </script>

+ 46 - 47
src/main/java/com/nokia/finance/tasks/jobs/car/procedure/CarPhpRequestLogJob.java

@@ -58,44 +58,55 @@ public class CarPhpRequestLogJob {
                 List<CarPhpRequestLogPo> carPhpRequestLogPoList = requestLogDao.listCarPhpRequestLog(startTime, endTime);
                 List<RequestLogPo> list = new ArrayList<>();
                 for (CarPhpRequestLogPo carPhpRequestLogPo : carPhpRequestLogPoList) {
-                    LocalDateTime requestTime = carPhpRequestLogPo.getRequestTime();
-                    String queryString = carPhpRequestLogPo.getQueryString();
-                    if (requestTime == null || !StringUtils.hasText(queryString)) {
-                        continue;
-                    }
-                    UriComponents uriComponents = UriComponentsBuilder.fromUriString("?" + queryString).build();
-                    MultiValueMap<String, String> queryParams = uriComponents.getQueryParams();
-                    Map<String, String> singleValueMap = queryParams.toSingleValueMap();
-                    String data = singleValueMap.get("data");
-                    if (!StringUtils.hasText(data)) {
-                        continue;
-                    }
-                    String urlDecodeToken = URLDecoder.decode(data, StandardCharsets.UTF_8);
-                    String decodeToken;
                     try {
-                        decodeToken = AESUtil.decrypt(urlDecodeToken);
+                        LocalDateTime requestTime = carPhpRequestLogPo.getRequestTime();
+                        String queryString = carPhpRequestLogPo.getQueryString();
+                        if (requestTime == null || !StringUtils.hasText(queryString)) {
+                            continue;
+                        }
+                        UriComponents uriComponents = UriComponentsBuilder.fromUriString("?" + queryString).build();
+                        MultiValueMap<String, String> queryParams = uriComponents.getQueryParams();
+                        Map<String, String> singleValueMap = queryParams.toSingleValueMap();
+                        String data = singleValueMap.get("data");
+                        if (!StringUtils.hasText(data)) {
+                            continue;
+                        }
+                        String urlDecodeToken = URLDecoder.decode(data, StandardCharsets.UTF_8);
+                        String decryptToken = AESUtil.decrypt(urlDecodeToken);
+                        Map<String, String> tokenMap = gson.fromJson(decryptToken, new TypeToken<Map<String, String>>() {
+                        }.getType());
+                        if (!"FINANCE".equals(tokenMap.get("APP_ID"))
+                                || !StringUtils.hasText(tokenMap.get("LOGIN_ID"))
+                                || !StringUtils.hasText(tokenMap.get("TIME_STAMP"))
+                                || !StringUtils.hasText(tokenMap.get("EXPIRE_TIME"))
+                        ) {
+                            continue;
+                        }
+                        LocalDateTime timeStamp = LocalDateTime.parse(tokenMap.get("TIME_STAMP"),
+                                DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+                        int expireTime = Integer.parseInt(tokenMap.get("EXPIRE_TIME"));
+                        LocalDateTime expireTimeStamp = timeStamp.plusSeconds(expireTime);
+                        String loginId = tokenMap.get("LOGIN_ID");
+                        String pageUrl = tokenMap.get("REQUEST_URL");
+                        String api = StringUtils.hasText(singleValueMap.get("type")) ? pageUrl + "?type=" + singleValueMap.get("type") : pageUrl;
+                        Map<String, String> requestParameters = new HashMap<>();
+                        requestParameters.put("request_parameters", gson.toJson(singleValueMap));
+                        String appId = tokenMap.get("APP_ID");
+                        RequestLogPo requestLogPo = new RequestLogPo();
+                        requestLogPo.setRequestTime(carPhpRequestLogPo.getRequestTime());
+                        requestLogPo.setLoginId(loginId);
+                        requestLogPo.setPageUrl(pageUrl);
+                        requestLogPo.setApi(api);
+                        requestLogPo.setRequestParameters(gson.toJson(requestParameters));
+                        requestLogPo.setAppId(appId);
+                        requestLogPo.setToken(urlDecodeToken);
+                        requestLogPo.setTimeStamp(timeStamp);
+                        requestLogPo.setExpireTime(expireTime);
+                        requestLogPo.setExpireTimeStamp(expireTimeStamp);
+                        list.add(requestLogPo);
                     } catch (Exception e) {
-                        log.error("token解密失败: {} -> {} -> {}", urlDecodeToken, queryString, e.getMessage(), e);
-                        continue;
+                        log.error("请求日志解析失败: {} -> {}", carPhpRequestLogPo, e.getMessage(), e);
                     }
-                    Map<String, String> tokenMap = gson.fromJson(decodeToken, new TypeToken<Map<String, String>>() {
-                    }.getType());
-                    String loginId = tokenMap.get("LOGIN_ID");
-                    String pageUrl = tokenMap.get("REQUEST_URL");
-                    String api = StringUtils.hasText(singleValueMap.get("type")) ? pageUrl + "?type=" + singleValueMap.get("type") : pageUrl;
-                    Map<String, String> requestParameters = new HashMap<>();
-                    requestParameters.put("request_parameters", gson.toJson(singleValueMap));
-                    String appId = tokenMap.get("APP_ID");
-                    RequestLogPo requestLogPo = new RequestLogPo();
-                    requestLogPo.setRequestTime(carPhpRequestLogPo.getRequestTime());
-                    requestLogPo.setLoginId(loginId);
-                    requestLogPo.setPageUrl(pageUrl);
-                    requestLogPo.setApi(api);
-                    requestLogPo.setRequestParameters(gson.toJson(requestParameters));
-                    requestLogPo.setAppId(appId);
-                    setTimeStamp(tokenMap, requestLogPo);
-                    requestLogPo.setToken(urlDecodeToken);
-                    list.add(requestLogPo);
                 }
                 if (CollectionUtils.isEmpty(list)) {
                     return;
@@ -109,16 +120,4 @@ public class CarPhpRequestLogJob {
             log.error(e.getMessage(), e);
         }
     }
-
-    private void setTimeStamp(Map<String, String> map, RequestLogPo requestLogPo) {
-        String timeStamp = map.get("TIME_STAMP");
-        if (StringUtils.hasText(timeStamp)) {
-            try {
-                requestLogPo.setTimeStamp(LocalDateTime.parse(map.get("TIME_STAMP"),
-                        DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
-            } catch (Exception e) {
-                log.warn("时间戳解析失败: {}", timeStamp);
-            }
-        }
-    }
 }

+ 8 - 0
src/main/java/com/nokia/finance/tasks/pojo/po/common/RequestLogPo.java

@@ -54,4 +54,12 @@ public class RequestLogPo {
      * 访问令牌
      */
     private String token;
+    /**
+     * 过期秒数,从token解密
+     */
+    private Integer expireTime;
+    /**
+     * 过期时间
+     */
+    private LocalDateTime expireTimeStamp;
 }