|
@@ -41,6 +41,9 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void getAdqAdIncome(String startDt, String endDt, String appId, Long appletId, Integer page, Integer isLog, Long errId, Integer isSend) {
|
|
public void getAdqAdIncome(String startDt, String endDt, String appId, Long appletId, Integer page, Integer isLog, Long errId, Integer isSend) {
|
|
|
|
|
+ if (page == 1) {
|
|
|
|
|
+ getAdqAdIncomeCover(startDt, endDt, appId, appletId, page, isLog, errId, isSend);
|
|
|
|
|
+ }
|
|
|
try {
|
|
try {
|
|
|
String url = "https://api.weixin.qq.com/publisher/stat";
|
|
String url = "https://api.weixin.qq.com/publisher/stat";
|
|
|
Object tokenObj = redis2Template_db5.opsForValue().get("wechat-applet-access-token-key-" + appletId);
|
|
Object tokenObj = redis2Template_db5.opsForValue().get("wechat-applet-access-token-key-" + appletId);
|
|
@@ -100,7 +103,7 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
|
|
|
if (totalPage > page) {
|
|
if (totalPage > page) {
|
|
|
getAdqAdIncome(startDt, endDt, appId, appletId, page + 1, isLog, errId, isSend);
|
|
getAdqAdIncome(startDt, endDt, appId, appletId, page + 1, isLog, errId, isSend);
|
|
|
} else {
|
|
} else {
|
|
|
- log.info("微小广告细分数据拉取完成,app_id:{} {}~{} page:{}。", appId, startDt, endDt,page);
|
|
|
|
|
|
|
+ log.info("微小广告细分数据拉取完成,app_id:{} {}~{} page:{}。", appId, startDt, endDt, page);
|
|
|
if (errId != null) {
|
|
if (errId != null) {
|
|
|
adqErrorLogMapper.deleteInfoByErrorId(errId);
|
|
adqErrorLogMapper.deleteInfoByErrorId(errId);
|
|
|
}
|
|
}
|
|
@@ -113,6 +116,83 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void getAdqAdIncomeCover(String startDt, String endDt, String appId, Long appletId, Integer page, Integer isLog, Long errId, Integer isSend) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String url = "https://api.weixin.qq.com/publisher/stat";
|
|
|
|
|
+ Object tokenObj = redis2Template_db5.opsForValue().get("wechat-applet-access-token-key-" + appletId);
|
|
|
|
|
+ if (tokenObj == null) {
|
|
|
|
|
+ log.error("微小广告封面广告数据拉取获取token为空 [{}] {}~{} {}", appId, startDt, endDt, appletId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ int pageSize = 90;
|
|
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
+ paramsMap.put("access_token", tokenObj.toString());
|
|
|
|
|
+ paramsMap.put("action", "publisher_adpos_general");
|
|
|
|
|
+ paramsMap.put("ad_slot", "SLOT_ID_WEAPP_COVER");
|
|
|
|
|
+ paramsMap.put("page", page);
|
|
|
|
|
+ paramsMap.put("page_size", pageSize);
|
|
|
|
|
+ paramsMap.put("start_date", startDt);
|
|
|
|
|
+ paramsMap.put("end_date", endDt);
|
|
|
|
|
+ String s = HttpUtils.httpGet(url, paramsMap, null);
|
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
+ List<AdqPublisherAdunitGeneral> reports = new ArrayList<>();
|
|
|
|
|
+ int totalPage = 1;
|
|
|
|
|
+ if (!Check.isNull(jsonObject)) {
|
|
|
|
|
+ Integer code = jsonObject.getInteger("ret");
|
|
|
|
|
+ JSONObject baseResp = jsonObject.getJSONObject("base_resp");
|
|
|
|
|
+ if (baseResp != null) {
|
|
|
|
|
+ code = baseResp.getInteger("ret");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (code == 2009) {
|
|
|
|
|
+ return; //无效的流量主
|
|
|
|
|
+ }
|
|
|
|
|
+ if (code == 0) {
|
|
|
|
|
+ JSONArray list = jsonObject.getJSONArray("list");
|
|
|
|
|
+ Integer totalNum = jsonObject.getInteger("total_num");
|
|
|
|
|
+ totalPage = (int) Math.ceil(totalNum * 1.0 / pageSize);
|
|
|
|
|
+ if (!Check.isNull(list)) {
|
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
+ JSONObject dataJson = list.getJSONObject(i);
|
|
|
|
|
+ dataJson.put("ad_unit_id", "SLOT_ID_WEAPP_COVER");
|
|
|
|
|
+ dataJson.put("ad_unit_name", "封面广告");
|
|
|
|
|
+ AdqPublisherAdunitGeneral report = JSONObject.parseObject(dataJson.toJSONString(), AdqPublisherAdunitGeneral.class);
|
|
|
|
|
+ report.setAppId(appId);
|
|
|
|
|
+ report.setStatDate(Integer.valueOf(report.getDate().replace("-", "")));
|
|
|
|
|
+ //System.out.println(report);
|
|
|
|
|
+ reports.add(report);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.error("微小广告封面广告数据拉取失败,app_id:{} {}~{},返回信息:{}", appId, startDt, endDt, jsonObject);
|
|
|
|
|
+ insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_ad_income", startDt, endDt,
|
|
|
|
|
+ jsonObject.fluentPut("app_id", appId).fluentPut("applet_id", appletId).toJSONString());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.error("微小广告封面广告数据拉取失败,app_id:{} {}~{},返回为空。", appId, startDt, endDt);
|
|
|
|
|
+ insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_ad_income", startDt, endDt,
|
|
|
|
|
+ new JSONObject().fluentPut("app_id", appId).fluentPut("applet_id", appletId).fluentPut("msg", "返回为空").toJSONString());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Check.isNull(reports)) {
|
|
|
|
|
+ adqAdIncomeMapper.insertAdqAdIncome(reports);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (totalPage > page) {
|
|
|
|
|
+ getAdqAdIncomeCover(startDt, endDt, appId, appletId, page + 1, isLog, errId, isSend);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("微小广告封面广告数据拉取完成,app_id:{} {}~{} page:{}。", appId, startDt, endDt, page);
|
|
|
|
|
+ if (errId != null) {
|
|
|
|
|
+ adqErrorLogMapper.deleteInfoByErrorId(errId);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isSend != null && isSend == 1) {
|
|
|
|
|
+ AlertUtils.sendMessage(System.currentTimeMillis(), startDt, endDt, 3, "daily", 1, "adq_ma_ad_income");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("微小广告封面广告数据拉取失败,app_id:{} {}~{}。", appId, startDt, endDt, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void insertErrorLog(Integer isLog, Long advertiserId, String dataDimension, String startDate, String endDate, String msg) {
|
|
private void insertErrorLog(Integer isLog, Long advertiserId, String dataDimension, String startDate, String endDate, String msg) {
|
|
|
if (isLog != null && isLog == 1) {
|
|
if (isLog != null && isLog == 1) {
|
|
|
AdqErrorLog errorInfo = new AdqErrorLog();
|
|
AdqErrorLog errorInfo = new AdqErrorLog();
|