|
@@ -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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|