|
@@ -1,6 +1,8 @@
|
|
|
package com.tzld.longarticle.recommend.server.service.exterior.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.aliyun.odps.data.Record;
|
|
|
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
import com.tzld.longarticle.recommend.server.common.enums.SecretEnum;
|
|
|
import com.tzld.longarticle.recommend.server.common.enums.cgi.ReplyStrategyServiceEnum;
|
|
|
import com.tzld.longarticle.recommend.server.common.response.CommonResponse;
|
|
@@ -12,9 +14,12 @@ import com.tzld.longarticle.recommend.server.model.cgi.MsgData;
|
|
|
import com.tzld.longarticle.recommend.server.model.cgi.ReplyBucketData;
|
|
|
import com.tzld.longarticle.recommend.server.model.param.PushMessageParam;
|
|
|
import com.tzld.longarticle.recommend.server.model.vo.PushMessageVo;
|
|
|
+import com.tzld.longarticle.recommend.server.model.vo.ReportUvVo;
|
|
|
import com.tzld.longarticle.recommend.server.service.exterior.AccessTokenService;
|
|
|
import com.tzld.longarticle.recommend.server.service.exterior.ThirdPartyService;
|
|
|
import com.tzld.longarticle.recommend.server.service.strategy.reply.ReplyStrategyService;
|
|
|
+import com.tzld.longarticle.recommend.server.util.DateUtils;
|
|
|
+import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -22,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+import com.tzld.longarticle.recommend.server.remote.ODPSManager;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.ArrayList;
|
|
@@ -38,6 +44,12 @@ public class ThirdPartyServiceImpl implements ThirdPartyService {
|
|
|
@Autowired
|
|
|
private AccessTokenService accessTokenService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ODPSManager odpsManager;
|
|
|
+
|
|
|
+ @ApolloJsonValue("${canViewReportDate:2024-10-31}")
|
|
|
+ private String canViewReportDate;
|
|
|
+
|
|
|
private Map<String, ReplyStrategyService> strategyServiceMap;
|
|
|
|
|
|
@PostConstruct
|
|
@@ -85,6 +97,44 @@ public class ThirdPartyServiceImpl implements ThirdPartyService {
|
|
|
return CommonResponse.success(pushMessageVoList);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public CommonResponse<List<ReportUvVo>> getReportUv(String date, String accessToken) {
|
|
|
+ if (StringUtils.isEmpty(date) || !DateUtils.isValidDate(date) || StringUtils.isEmpty(accessToken)) {
|
|
|
+ return CommonResponse.create(ExceptionCodeEnum.PARAM_ERROR, "参数错误");
|
|
|
+ }
|
|
|
+ if (!accessTokenService.validateAccessToken(accessToken)) {
|
|
|
+ return CommonResponse.create(ExceptionCodeEnum.PARAM_ERROR, "accessToken错误或者已失效");
|
|
|
+ }
|
|
|
+ SecretEnum secretEnum = accessTokenService.getSecretEnum(accessToken);
|
|
|
+ if (secretEnum == null) {
|
|
|
+ return CommonResponse.create(ExceptionCodeEnum.PARAM_ERROR, "获取secret失败");
|
|
|
+ }
|
|
|
+ if (!DateUtils.isValidDate(canViewReportDate)) {
|
|
|
+ return CommonResponse.create(ExceptionCodeEnum.PARAM_ERROR, "系统异常");
|
|
|
+ }
|
|
|
+ String channel = secretEnum.channel;
|
|
|
+ long targetTime = DateUtils.dateStrToTimestamp(date, "yyyy-MM-dd");
|
|
|
+ long limitTime = DateUtils.dateStrToTimestamp(canViewReportDate, "yyyy-MM-dd");
|
|
|
+ if (targetTime > limitTime) {
|
|
|
+ return CommonResponse.create(500, "数据不存在");
|
|
|
+ }
|
|
|
+ String dt = date.replace("-", "").substring(0, 8);
|
|
|
+ String sql = String.format("SELECT * FROM alg_growth_3rd_gh_reply_uv_report WHERE dt = %s AND channel = '%s';",
|
|
|
+ dt, channel);
|
|
|
+ List<ReportUvVo> res = new ArrayList<>();
|
|
|
+ List<Record> recordList = odpsManager.query(sql);
|
|
|
+ if (CollectionUtils.isEmpty(recordList)) {
|
|
|
+ return CommonResponse.success(res);
|
|
|
+ }
|
|
|
+ for (Record record : recordList) {
|
|
|
+ ReportUvVo reportUvVo = new ReportUvVo();
|
|
|
+ reportUvVo.setGhId(record.getString(0));
|
|
|
+ reportUvVo.setUv(record.getBigint(1));
|
|
|
+ res.add(reportUvVo);
|
|
|
+ }
|
|
|
+ return CommonResponse.success(res);
|
|
|
+ }
|
|
|
+
|
|
|
private ReplyBucketData getPushMessageData(PushMessageParam param, String channel) {
|
|
|
log.info("strategyServiceMap={}", JSON.toJSONString(strategyServiceMap));
|
|
|
for (Map.Entry<String, ReplyStrategyService> stringReplyStrategyServiceEntry : strategyServiceMap.entrySet()) {
|