|
@@ -1,15 +1,25 @@
|
|
|
package org.jeecg.modules.adweb.dmp.service.google;
|
|
|
|
|
|
+import com.google.common.annotations.VisibleForTesting;
|
|
|
+
|
|
|
import jakarta.annotation.PostConstruct;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
+import org.apache.commons.lang3.reflect.TypeUtils;
|
|
|
+import org.jeecg.common.util.FastJsonUtil;
|
|
|
import org.jeecg.modules.adweb.common.util.RestTemplateUtil;
|
|
|
-import org.jeecg.modules.adweb.dmp.entity.GoogleGTM;
|
|
|
+import org.jeecg.modules.adweb.dmp.dto.OpenAPIRequest;
|
|
|
+import org.jeecg.modules.adweb.dmp.dto.OpenAPIResponse;
|
|
|
+import org.jeecg.modules.adweb.dmp.dto.google.analytics.report.GAReportRequestDTO;
|
|
|
+import org.jeecg.modules.adweb.dmp.dto.google.analytics.report.data.GAReportDataDTO;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.core.ParameterizedTypeReference;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* Google Analytics数据同步 - http://data-bridge.v3.adwebcloud.com:9002/swagger-ui/index.html
|
|
|
*
|
|
@@ -34,17 +44,44 @@ public class GAReportService {
|
|
|
this.restTemplate = RestTemplateUtil.getRestTemplate(30, 30, dataBridgeApiToken);
|
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
-// * 拉取Google Analytics国家报表
|
|
|
-// *
|
|
|
-// * @param googleGTM
|
|
|
-// */
|
|
|
-// private void queryGARegionReport(GoogleGTM googleGTM) {}
|
|
|
-//
|
|
|
+ // /**
|
|
|
+ // * 拉取Google Analytics国家报表
|
|
|
+ // *
|
|
|
+ // * @param googleGTM
|
|
|
+ // */
|
|
|
+ // private void queryGARegionReport(GoogleGTM googleGTM) {}
|
|
|
+ //
|
|
|
|
|
|
+ /**
|
|
|
+ * 请求Google Analytics报表,http://data-bridge.v3.adwebcloud.com:9002/swagger-ui/index.html
|
|
|
+ *
|
|
|
+ * @param gaReportRequest
|
|
|
+ * @param reportDataType
|
|
|
+ * @return
|
|
|
+ * @param <T>
|
|
|
+ */
|
|
|
+ @VisibleForTesting
|
|
|
+ <T extends GAReportDataDTO> List<T> runGAReport(
|
|
|
+ GAReportRequestDTO gaReportRequest, Class<T> reportDataType) {
|
|
|
+ log.info("runGAReport: {}", FastJsonUtil.toJSONString(gaReportRequest));
|
|
|
|
|
|
- private void runGAReport(GARe) {
|
|
|
+ // 1. 创建API request
|
|
|
+ OpenAPIRequest<GAReportRequestDTO> openAPIRequest = new OpenAPIRequest<>();
|
|
|
+ openAPIRequest.setRequestServer(this.getClass().getSimpleName());
|
|
|
+ openAPIRequest.setRequestTime(System.currentTimeMillis());
|
|
|
+ openAPIRequest.setData(gaReportRequest);
|
|
|
|
|
|
- }
|
|
|
+ // 2. 请求API接口
|
|
|
+ OpenAPIResponse<List<T>> openAPIResponse =
|
|
|
+ RestTemplateUtil.postForObject(
|
|
|
+ restTemplate,
|
|
|
+ dataBridgeApiHost + DATA_BRIDGE_GA_REPORT_PATH,
|
|
|
+ openAPIRequest,
|
|
|
+ ParameterizedTypeReference.forType(
|
|
|
+ TypeUtils.parameterize(
|
|
|
+ OpenAPIResponse.class,
|
|
|
+ TypeUtils.parameterize(List.class, reportDataType))));
|
|
|
|
|
|
+ return openAPIResponse.getData();
|
|
|
+ }
|
|
|
}
|