|
@@ -1,121 +1,121 @@
|
|
-package com.nokia.finance.tasks.jobs.gdc.car;
|
|
|
|
-
|
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
-import com.fasterxml.jackson.databind.type.TypeFactory;
|
|
|
|
-import com.nokia.finance.tasks.dao.common.RequestLogDao;
|
|
|
|
-import com.nokia.finance.tasks.pojo.po.common.CarPhpRequestLogPo;
|
|
|
|
-import com.nokia.finance.tasks.pojo.po.common.RequestLogPo;
|
|
|
|
-import com.nokia.finance.tasks.utils.AESUtil;
|
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
-import org.springframework.util.MultiValueMap;
|
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
|
-import org.springframework.web.util.UriComponents;
|
|
|
|
-import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
-
|
|
|
|
-import java.net.URLDecoder;
|
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
|
-import java.time.ZoneOffset;
|
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.concurrent.CompletableFuture;
|
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 车辆php页面请求日志入库定时任务
|
|
|
|
- */
|
|
|
|
-@Slf4j
|
|
|
|
-@Service
|
|
|
|
-@RequiredArgsConstructor
|
|
|
|
-public class CarPhpRequestLogJob {
|
|
|
|
- private final RequestLogDao requestLogDao;
|
|
|
|
- private final ObjectMapper objectMapper;
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 执行任务
|
|
|
|
- */
|
|
|
|
- @Scheduled(cron = "0 30 * * * ?")
|
|
|
|
- public void runJob() {
|
|
|
|
- log.info("执行车辆php页面请求日志入库定时任务");
|
|
|
|
- try {
|
|
|
|
- CompletableFuture.runAsync(() -> {
|
|
|
|
-// LocalDateTime startLocalDateTime = LocalDateTime.of(2024, 3, 23, 0, 0);
|
|
|
|
-// LocalDateTime endLocalDateTime = LocalDateTime.of(2024, 3, 25, 18, 0);
|
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
|
- LocalDateTime startLocalDateTime = now.minusHours(1).withMinute(0).withSecond(0).withNano(0);
|
|
|
|
- LocalDateTime endLocalDateTime = startLocalDateTime.plusHours(1);
|
|
|
|
- Long startTime = startLocalDateTime.toEpochSecond(ZoneOffset.ofHours(8));
|
|
|
|
- Long endTime = endLocalDateTime.toEpochSecond(ZoneOffset.ofHours(8));
|
|
|
|
- List<CarPhpRequestLogPo> carPhpRequestLogPoList = requestLogDao.listCarPhpRequestLog(startTime, endTime);
|
|
|
|
- List<RequestLogPo> list = new ArrayList<>();
|
|
|
|
- for (CarPhpRequestLogPo carPhpRequestLogPo : carPhpRequestLogPoList) {
|
|
|
|
- try {
|
|
|
|
- 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 = objectMapper.readValue(decryptToken,
|
|
|
|
- TypeFactory.defaultInstance().constructMapType(Map.class, String.class, String.class));
|
|
|
|
- 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", objectMapper.writeValueAsString(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(objectMapper.writeValueAsString(requestParameters));
|
|
|
|
- requestLogPo.setAppId(appId);
|
|
|
|
- requestLogPo.setToken(urlDecodeToken);
|
|
|
|
- requestLogPo.setTimeStamp(timeStamp);
|
|
|
|
- requestLogPo.setExpireTime(expireTime);
|
|
|
|
- requestLogPo.setExpireTimeStamp(expireTimeStamp);
|
|
|
|
- list.add(requestLogPo);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("请求日志解析失败: {} -> {}", carPhpRequestLogPo, e, e);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (CollectionUtils.isEmpty(list)) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- requestLogDao.insertBatch(list);
|
|
|
|
- }).get(1, TimeUnit.MINUTES);
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
|
- log.error("线程中断: {}", e, e);
|
|
|
|
- Thread.currentThread().interrupt();
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error(e.toString(), e);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+//package com.nokia.finance.tasks.jobs.gdc.car;
|
|
|
|
+//
|
|
|
|
+//import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
+//import com.fasterxml.jackson.databind.type.TypeFactory;
|
|
|
|
+//import com.nokia.finance.tasks.dao.common.RequestLogDao;
|
|
|
|
+//import com.nokia.finance.tasks.pojo.po.common.CarPhpRequestLogPo;
|
|
|
|
+//import com.nokia.finance.tasks.pojo.po.common.RequestLogPo;
|
|
|
|
+//import com.nokia.finance.tasks.utils.AESUtil;
|
|
|
|
+//import lombok.RequiredArgsConstructor;
|
|
|
|
+//import lombok.extern.slf4j.Slf4j;
|
|
|
|
+//import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
+//import org.springframework.stereotype.Service;
|
|
|
|
+//import org.springframework.util.CollectionUtils;
|
|
|
|
+//import org.springframework.util.MultiValueMap;
|
|
|
|
+//import org.springframework.util.StringUtils;
|
|
|
|
+//import org.springframework.web.util.UriComponents;
|
|
|
|
+//import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
+//
|
|
|
|
+//import java.net.URLDecoder;
|
|
|
|
+//import java.nio.charset.StandardCharsets;
|
|
|
|
+//import java.time.LocalDateTime;
|
|
|
|
+//import java.time.ZoneOffset;
|
|
|
|
+//import java.time.format.DateTimeFormatter;
|
|
|
|
+//import java.util.ArrayList;
|
|
|
|
+//import java.util.HashMap;
|
|
|
|
+//import java.util.List;
|
|
|
|
+//import java.util.Map;
|
|
|
|
+//import java.util.concurrent.CompletableFuture;
|
|
|
|
+//import java.util.concurrent.TimeUnit;
|
|
|
|
+//
|
|
|
|
+///**
|
|
|
|
+// * 车辆php页面请求日志入库定时任务
|
|
|
|
+// */
|
|
|
|
+//@Slf4j
|
|
|
|
+//@Service
|
|
|
|
+//@RequiredArgsConstructor
|
|
|
|
+//public class CarPhpRequestLogJob {
|
|
|
|
+// private final RequestLogDao requestLogDao;
|
|
|
|
+// private final ObjectMapper objectMapper;
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 执行任务
|
|
|
|
+// */
|
|
|
|
+// @Scheduled(cron = "0 30 * * * ?")
|
|
|
|
+// public void runJob() {
|
|
|
|
+// log.info("执行车辆php页面请求日志入库定时任务");
|
|
|
|
+// try {
|
|
|
|
+// CompletableFuture.runAsync(() -> {
|
|
|
|
+//// LocalDateTime startLocalDateTime = LocalDateTime.of(2024, 3, 23, 0, 0);
|
|
|
|
+//// LocalDateTime endLocalDateTime = LocalDateTime.of(2024, 3, 25, 18, 0);
|
|
|
|
+// LocalDateTime now = LocalDateTime.now();
|
|
|
|
+// LocalDateTime startLocalDateTime = now.minusHours(1).withMinute(0).withSecond(0).withNano(0);
|
|
|
|
+// LocalDateTime endLocalDateTime = startLocalDateTime.plusHours(1);
|
|
|
|
+// Long startTime = startLocalDateTime.toEpochSecond(ZoneOffset.ofHours(8));
|
|
|
|
+// Long endTime = endLocalDateTime.toEpochSecond(ZoneOffset.ofHours(8));
|
|
|
|
+// List<CarPhpRequestLogPo> carPhpRequestLogPoList = requestLogDao.listCarPhpRequestLog(startTime, endTime);
|
|
|
|
+// List<RequestLogPo> list = new ArrayList<>();
|
|
|
|
+// for (CarPhpRequestLogPo carPhpRequestLogPo : carPhpRequestLogPoList) {
|
|
|
|
+// try {
|
|
|
|
+// 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 = objectMapper.readValue(decryptToken,
|
|
|
|
+// TypeFactory.defaultInstance().constructMapType(Map.class, String.class, String.class));
|
|
|
|
+// 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", objectMapper.writeValueAsString(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(objectMapper.writeValueAsString(requestParameters));
|
|
|
|
+// requestLogPo.setAppId(appId);
|
|
|
|
+// requestLogPo.setToken(urlDecodeToken);
|
|
|
|
+// requestLogPo.setTimeStamp(timeStamp);
|
|
|
|
+// requestLogPo.setExpireTime(expireTime);
|
|
|
|
+// requestLogPo.setExpireTimeStamp(expireTimeStamp);
|
|
|
|
+// list.add(requestLogPo);
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// log.error("请求日志解析失败: {} -> {}", carPhpRequestLogPo, e, e);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// if (CollectionUtils.isEmpty(list)) {
|
|
|
|
+// return;
|
|
|
|
+// }
|
|
|
|
+// requestLogDao.insertBatch(list);
|
|
|
|
+// }).get(1, TimeUnit.MINUTES);
|
|
|
|
+// } catch (InterruptedException e) {
|
|
|
|
+// log.error("线程中断: {}", e, e);
|
|
|
|
+// Thread.currentThread().interrupt();
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// log.error(e.toString(), e);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//}
|