|
@@ -34,6 +34,7 @@ import org.jeecg.modules.adweb.dmp.service.IGACountryReportService;
|
|
|
import org.jeecg.modules.adweb.dmp.service.IGAPagePathReportService;
|
|
|
import org.jeecg.modules.adweb.dmp.service.IGASourceMediumReportService;
|
|
|
import org.jeecg.modules.adweb.dmp.service.IGoogleGTMService;
|
|
|
+import org.jeecg.modules.adweb.site.service.IAdwebSiteService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.ParameterizedTypeReference;
|
|
@@ -70,8 +71,8 @@ public class GAReportService {
|
|
|
@Value("${data-bridge.api.token}")
|
|
|
private String dataBridgeApiToken;
|
|
|
|
|
|
+ @Autowired private IAdwebSiteService adwebSiteService;
|
|
|
@Autowired private IGoogleGTMService googleGTMService;
|
|
|
-
|
|
|
@Autowired private IGACountryReportService gaCountryReportService;
|
|
|
@Autowired private IGASourceMediumReportService gaSourceMediumReportService;
|
|
|
@Autowired private IGAPagePathReportService gaPagePathReportService;
|
|
@@ -87,8 +88,15 @@ public class GAReportService {
|
|
|
|
|
|
/** 拉取并同步Google Analytics报表 */
|
|
|
public void syncGAReport() {
|
|
|
- // TODO: 判断网站状态
|
|
|
- List<GoogleGTM> googleGTMS = googleGTMService.list();
|
|
|
+ List<GoogleGTM> googleGTMS =
|
|
|
+ googleGTMService.list().stream()
|
|
|
+ // 判断网站状态
|
|
|
+ .filter(
|
|
|
+ googleGTM ->
|
|
|
+ adwebSiteService
|
|
|
+ .getAllActiveSiteCodes()
|
|
|
+ .contains(googleGTM.getSiteCode()))
|
|
|
+ .toList();
|
|
|
|
|
|
for (GoogleGTM googleGTM : googleGTMS) {
|
|
|
// 每个帐号同步更新三张报表
|
|
@@ -97,7 +105,7 @@ public class GAReportService {
|
|
|
this.syncGASourceMediumReport(googleGTM);
|
|
|
this.syncGAPagePathReport(googleGTM);
|
|
|
} catch (RuntimeException e) {
|
|
|
- log.warn("同步GA报表异常, siteId = {], error = {}", googleGTM.getSiteId(), e);
|
|
|
+ log.warn("同步GA报表异常, siteCode = {], error = {}", googleGTM.getSiteCode(), e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -109,7 +117,7 @@ public class GAReportService {
|
|
|
*/
|
|
|
private void syncGACountryReport(GoogleGTM googleGTM) {
|
|
|
// 1. 报表时间区间
|
|
|
- Date startDate = this.getReportStartDate(TABLE_GA_COUNTRY_REPORT, googleGTM.getSiteId());
|
|
|
+ Date startDate = this.getReportStartDate(TABLE_GA_COUNTRY_REPORT, googleGTM.getSiteCode());
|
|
|
Date endDate = new Date();
|
|
|
|
|
|
// 2. 构建GA报表请求参数
|
|
@@ -132,7 +140,7 @@ public class GAReportService {
|
|
|
List<GACountryReport> countryReport = Lists.newArrayList();
|
|
|
for (CustomReportData reportData : reportDataList) {
|
|
|
GACountryReport reportRow = new GACountryReport();
|
|
|
- reportRow.setSiteId(googleGTM.getSiteId());
|
|
|
+ reportRow.setSiteCode(googleGTM.getSiteCode());
|
|
|
reportRow.setDate(
|
|
|
DateUtils.str2Date(
|
|
|
reportData.get(ReportConstant.DIMENSION_DATE),
|
|
@@ -147,7 +155,7 @@ public class GAReportService {
|
|
|
// 3. 更新数据库 - 删除旧数据,插入新数据
|
|
|
gaCountryReportService.remove(
|
|
|
this.getRemoveQueryWrapper(
|
|
|
- GACountryReport.class, googleGTM.getSiteId(), startDate, endDate));
|
|
|
+ GACountryReport.class, googleGTM.getSiteCode(), startDate, endDate));
|
|
|
|
|
|
gaCountryReportService.saveBatch(countryReport, countryReport.size());
|
|
|
}
|
|
@@ -160,7 +168,7 @@ public class GAReportService {
|
|
|
private void syncGASourceMediumReport(GoogleGTM googleGTM) {
|
|
|
// 1. 报表时间区间
|
|
|
Date startDate =
|
|
|
- this.getReportStartDate(TABLE_GA_SOURCE_MEDIUM_REPORT, googleGTM.getSiteId());
|
|
|
+ this.getReportStartDate(TABLE_GA_SOURCE_MEDIUM_REPORT, googleGTM.getSiteCode());
|
|
|
Date endDate = new Date();
|
|
|
|
|
|
// 2. 构建GA报表请求参数
|
|
@@ -192,7 +200,7 @@ public class GAReportService {
|
|
|
List<GASourceMediumReport> sourceMediumReport = Lists.newArrayList();
|
|
|
for (CustomReportData reportData : reportDataList) {
|
|
|
GASourceMediumReport reportRow = new GASourceMediumReport();
|
|
|
- reportRow.setSiteId(googleGTM.getSiteId());
|
|
|
+ reportRow.setSiteCode(googleGTM.getSiteCode());
|
|
|
reportRow.setDate(
|
|
|
DateUtils.str2Date(
|
|
|
reportData.get(ReportConstant.DIMENSION_DATE),
|
|
@@ -217,7 +225,7 @@ public class GAReportService {
|
|
|
// 3. 更新数据库 - 删除旧数据,插入新数据
|
|
|
gaSourceMediumReportService.remove(
|
|
|
this.getRemoveQueryWrapper(
|
|
|
- GASourceMediumReport.class, googleGTM.getSiteId(), startDate, endDate));
|
|
|
+ GASourceMediumReport.class, googleGTM.getSiteCode(), startDate, endDate));
|
|
|
|
|
|
gaSourceMediumReportService.saveBatch(sourceMediumReport, sourceMediumReport.size());
|
|
|
}
|
|
@@ -229,7 +237,8 @@ public class GAReportService {
|
|
|
*/
|
|
|
private void syncGAPagePathReport(GoogleGTM googleGTM) {
|
|
|
// 1. 报表时间区间
|
|
|
- Date startDate = this.getReportStartDate(TABLE_GA_PAGE_PATH_REPORT, googleGTM.getSiteId());
|
|
|
+ Date startDate =
|
|
|
+ this.getReportStartDate(TABLE_GA_PAGE_PATH_REPORT, googleGTM.getSiteCode());
|
|
|
Date endDate = new Date();
|
|
|
|
|
|
// 2. 构建GA报表请求参数
|
|
@@ -256,7 +265,7 @@ public class GAReportService {
|
|
|
List<GAPagePathReport> pagePathReport = Lists.newArrayList();
|
|
|
for (CustomReportData reportData : reportDataList) {
|
|
|
GAPagePathReport reportRow = new GAPagePathReport();
|
|
|
- reportRow.setSiteId(googleGTM.getSiteId());
|
|
|
+ reportRow.setSiteCode(googleGTM.getSiteCode());
|
|
|
reportRow.setDate(
|
|
|
DateUtils.str2Date(
|
|
|
reportData.get(ReportConstant.DIMENSION_DATE),
|
|
@@ -276,7 +285,7 @@ public class GAReportService {
|
|
|
// 3. 更新数据库 - 删除旧数据,插入新数据
|
|
|
gaPagePathReportService.remove(
|
|
|
this.getRemoveQueryWrapper(
|
|
|
- GAPagePathReport.class, googleGTM.getSiteId(), startDate, endDate));
|
|
|
+ GAPagePathReport.class, googleGTM.getSiteCode(), startDate, endDate));
|
|
|
|
|
|
gaPagePathReportService.saveBatch(pagePathReport, pagePathReport.size());
|
|
|
}
|
|
@@ -325,8 +334,8 @@ public class GAReportService {
|
|
|
*
|
|
|
* <p>2. 表中最大时间减一天 - 如10月10号凌晨2点执行,最大时间可能是10号;同时9号数据GA侧有可能更新
|
|
|
*/
|
|
|
- private Date getReportStartDate(String tableName, int siteId) {
|
|
|
- Date maxDate = commonMapper.getMaxDate(tableName, "date", "site_id = " + siteId);
|
|
|
+ private Date getReportStartDate(String tableName, String siteCode) {
|
|
|
+ Date maxDate = commonMapper.getMaxDate(tableName, "date", "site_code = " + siteCode);
|
|
|
if (Objects.isNull(maxDate)) {
|
|
|
// 1. 一年前
|
|
|
return DateUtil.addDays(new Date(), -365);
|
|
@@ -337,9 +346,9 @@ public class GAReportService {
|
|
|
|
|
|
/** 生成{@link QueryWrapper}, 删除GA报表历史数据 */
|
|
|
private <T> QueryWrapper<T> getRemoveQueryWrapper(
|
|
|
- Class<T> entityClass, int siteId, Date startDate, Date endDate) {
|
|
|
+ Class<T> entityClass, String siteCode, Date startDate, Date endDate) {
|
|
|
QueryWrapper<T> queryWrapper = new QueryWrapper<>(entityClass);
|
|
|
- queryWrapper.eq("site_id", siteId);
|
|
|
+ queryWrapper.eq("site_code", siteCode);
|
|
|
queryWrapper.ge("date", startDate);
|
|
|
queryWrapper.le("date", endDate);
|
|
|
return queryWrapper;
|