|
@@ -1,11 +1,12 @@
|
|
package com.nokia.finance.tasks.jobs.gdc.car;
|
|
package com.nokia.finance.tasks.jobs.gdc.car;
|
|
|
|
|
|
-import com.google.gson.Gson;
|
|
|
|
-import com.google.gson.reflect.TypeToken;
|
|
|
|
|
|
+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.dao.common.RequestLogDao;
|
|
import com.nokia.finance.tasks.pojo.po.common.CarPhpRequestLogPo;
|
|
import com.nokia.finance.tasks.pojo.po.common.CarPhpRequestLogPo;
|
|
import com.nokia.finance.tasks.pojo.po.common.RequestLogPo;
|
|
import com.nokia.finance.tasks.pojo.po.common.RequestLogPo;
|
|
import com.nokia.finance.tasks.utils.AESUtil;
|
|
import com.nokia.finance.tasks.utils.AESUtil;
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -32,12 +33,10 @@ import java.util.concurrent.TimeUnit;
|
|
*/
|
|
*/
|
|
@Slf4j
|
|
@Slf4j
|
|
@Service
|
|
@Service
|
|
|
|
+@RequiredArgsConstructor
|
|
public class CarPhpRequestLogJob {
|
|
public class CarPhpRequestLogJob {
|
|
private final RequestLogDao requestLogDao;
|
|
private final RequestLogDao requestLogDao;
|
|
-
|
|
|
|
- public CarPhpRequestLogJob(RequestLogDao requestLogDao) {
|
|
|
|
- this.requestLogDao = requestLogDao;
|
|
|
|
- }
|
|
|
|
|
|
+ private final ObjectMapper objectMapper;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 执行任务
|
|
* 执行任务
|
|
@@ -47,7 +46,6 @@ public class CarPhpRequestLogJob {
|
|
log.info("执行车辆php页面请求日志入库定时任务");
|
|
log.info("执行车辆php页面请求日志入库定时任务");
|
|
try {
|
|
try {
|
|
CompletableFuture.runAsync(() -> {
|
|
CompletableFuture.runAsync(() -> {
|
|
- Gson gson = new Gson();
|
|
|
|
// LocalDateTime startLocalDateTime = LocalDateTime.of(2024, 3, 23, 0, 0);
|
|
// LocalDateTime startLocalDateTime = LocalDateTime.of(2024, 3, 23, 0, 0);
|
|
// LocalDateTime endLocalDateTime = LocalDateTime.of(2024, 3, 25, 18, 0);
|
|
// LocalDateTime endLocalDateTime = LocalDateTime.of(2024, 3, 25, 18, 0);
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
@@ -73,8 +71,8 @@ public class CarPhpRequestLogJob {
|
|
}
|
|
}
|
|
String urlDecodeToken = URLDecoder.decode(data, StandardCharsets.UTF_8);
|
|
String urlDecodeToken = URLDecoder.decode(data, StandardCharsets.UTF_8);
|
|
String decryptToken = AESUtil.decrypt(urlDecodeToken);
|
|
String decryptToken = AESUtil.decrypt(urlDecodeToken);
|
|
- Map<String, String> tokenMap = gson.fromJson(decryptToken, new TypeToken<Map<String, String>>() {
|
|
|
|
- }.getType());
|
|
|
|
|
|
+ Map<String, String> tokenMap = objectMapper.readValue(decryptToken,
|
|
|
|
+ TypeFactory.defaultInstance().constructMapType(Map.class, String.class, String.class));
|
|
if (!"FINANCE".equals(tokenMap.get("APP_ID"))
|
|
if (!"FINANCE".equals(tokenMap.get("APP_ID"))
|
|
|| !StringUtils.hasText(tokenMap.get("LOGIN_ID"))
|
|
|| !StringUtils.hasText(tokenMap.get("LOGIN_ID"))
|
|
|| !StringUtils.hasText(tokenMap.get("TIME_STAMP"))
|
|
|| !StringUtils.hasText(tokenMap.get("TIME_STAMP"))
|
|
@@ -90,14 +88,14 @@ public class CarPhpRequestLogJob {
|
|
String pageUrl = tokenMap.get("REQUEST_URL");
|
|
String pageUrl = tokenMap.get("REQUEST_URL");
|
|
String api = StringUtils.hasText(singleValueMap.get("type")) ? pageUrl + "?type=" + singleValueMap.get("type") : pageUrl;
|
|
String api = StringUtils.hasText(singleValueMap.get("type")) ? pageUrl + "?type=" + singleValueMap.get("type") : pageUrl;
|
|
Map<String, String> requestParameters = new HashMap<>();
|
|
Map<String, String> requestParameters = new HashMap<>();
|
|
- requestParameters.put("request_parameters", gson.toJson(singleValueMap));
|
|
|
|
|
|
+ requestParameters.put("request_parameters", objectMapper.writeValueAsString(singleValueMap));
|
|
String appId = tokenMap.get("APP_ID");
|
|
String appId = tokenMap.get("APP_ID");
|
|
RequestLogPo requestLogPo = new RequestLogPo();
|
|
RequestLogPo requestLogPo = new RequestLogPo();
|
|
requestLogPo.setRequestTime(carPhpRequestLogPo.getRequestTime());
|
|
requestLogPo.setRequestTime(carPhpRequestLogPo.getRequestTime());
|
|
requestLogPo.setLoginId(loginId);
|
|
requestLogPo.setLoginId(loginId);
|
|
requestLogPo.setPageUrl(pageUrl);
|
|
requestLogPo.setPageUrl(pageUrl);
|
|
requestLogPo.setApi(api);
|
|
requestLogPo.setApi(api);
|
|
- requestLogPo.setRequestParameters(gson.toJson(requestParameters));
|
|
|
|
|
|
+ requestLogPo.setRequestParameters(objectMapper.writeValueAsString(requestParameters));
|
|
requestLogPo.setAppId(appId);
|
|
requestLogPo.setAppId(appId);
|
|
requestLogPo.setToken(urlDecodeToken);
|
|
requestLogPo.setToken(urlDecodeToken);
|
|
requestLogPo.setTimeStamp(timeStamp);
|
|
requestLogPo.setTimeStamp(timeStamp);
|
|
@@ -105,7 +103,7 @@ public class CarPhpRequestLogJob {
|
|
requestLogPo.setExpireTimeStamp(expireTimeStamp);
|
|
requestLogPo.setExpireTimeStamp(expireTimeStamp);
|
|
list.add(requestLogPo);
|
|
list.add(requestLogPo);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("请求日志解析失败: {} -> {}", carPhpRequestLogPo, e.toString(), e);
|
|
|
|
|
|
+ log.error("请求日志解析失败: {} -> {}", carPhpRequestLogPo, e, e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
@@ -114,7 +112,7 @@ public class CarPhpRequestLogJob {
|
|
requestLogDao.insertBatch(list);
|
|
requestLogDao.insertBatch(list);
|
|
}).get(1, TimeUnit.MINUTES);
|
|
}).get(1, TimeUnit.MINUTES);
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
- log.error("线程中断: {}", e.toString(), e);
|
|
|
|
|
|
+ log.error("线程中断: {}", e, e);
|
|
Thread.currentThread().interrupt();
|
|
Thread.currentThread().interrupt();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error(e.toString(), e);
|
|
log.error(e.toString(), e);
|