|
|
@@ -7,6 +7,7 @@ import cn.com.ctop.job.adq.data.mapper.AdqErrorLogMapper;
|
|
|
import cn.com.ctop.job.adq.data.service.IAdqAdIncomeService;
|
|
|
import cn.com.ctop.job.adq.data.utils.AlertUtils;
|
|
|
import cn.com.ctop.job.adq.data.utils.Check;
|
|
|
+import cn.com.ctop.job.adq.data.utils.DateUtils;
|
|
|
import cn.com.ctop.job.adq.data.utils.HttpUtils;
|
|
|
import cn.com.ctop.job.adq.utils.doris.sink.DorisMultiTableStreamLoadManager;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
@@ -342,4 +343,250 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ 查询流量主每日广告金收入
|
|
|
+ https://developers.weixin.qq.com/minigame/dev/guide/open-ability/ad/adq.html#_1%E3%80%81%E6%9F%A5%E8%AF%A2%E6%B5%81%E9%87%8F%E4%B8%BB%E6%AF%8F%E6%97%A5%E5%B9%BF%E5%91%8A%E9%87%91%E6%94%B6%E5%85%A5
|
|
|
+ */
|
|
|
+ public void getGameGiftList(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 = 500;
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
+ paramsMap.put("access_token", tokenObj.toString());
|
|
|
+ paramsMap.put("action", "general_action");
|
|
|
+ paramsMap.put("cmd", "get_game_gift_list");
|
|
|
+ paramsMap.put("ad_fund_type", "drama");
|
|
|
+ paramsMap.put("page", page);
|
|
|
+ paramsMap.put("page_size", pageSize);
|
|
|
+ paramsMap.put("begin_date", startDt.replace("-", ""));
|
|
|
+ paramsMap.put("end_date", endDt.replace("-", ""));
|
|
|
+ String s = HttpUtils.httpGet(url, paramsMap, null);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
+ int totalPage = 1;
|
|
|
+ ArrayList<JSONObject> reports = new ArrayList<>();
|
|
|
+ if (!Check.isNull(jsonObject)) {
|
|
|
+ Integer code = jsonObject.getInteger("ret");
|
|
|
+ JSONObject baseResp = jsonObject.getJSONObject("base_resp");
|
|
|
+ if (baseResp != null) {
|
|
|
+ code = baseResp.getInteger("ret");
|
|
|
+ }
|
|
|
+ if (2009 == code) {
|
|
|
+ return; //无效的流量主
|
|
|
+ }
|
|
|
+ if (code == 0) {
|
|
|
+ JSONArray list = jsonObject.getJSONArray("game_gift_detail");
|
|
|
+ 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("stat_date", dataJson.getString("date").replace("-", ""));
|
|
|
+ dataJson.put("app_id", appId);
|
|
|
+ reports.add(dataJson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("微小查询流量主每日广告金收入拉取失败,app_id:{} {}~{},返回信息:{}", appId, startDt, endDt, jsonObject);
|
|
|
+ insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_game_gift_list", 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_game_gift_list", startDt, endDt,
|
|
|
+ new JSONObject().fluentPut("app_id", appId).fluentPut("applet_id", appletId).fluentPut("msg", "返回为空").toJSONString());
|
|
|
+ }
|
|
|
+ if (!Check.isNull(reports)) {
|
|
|
+ adqAdIncomeMapper.insertAdqGameGiftList(reports);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (totalPage > page) {
|
|
|
+ getGameGiftList(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_game_gift_list");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("微小查询流量主每日广告金收入拉取失败,app_id:{} {}~{}。", appId, startDt, endDt, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ 查询流量主广告金账户余额
|
|
|
+ https://developers.weixin.qq.com/minigame/dev/guide/open-ability/ad/adq.html#_1%E3%80%81%E6%9F%A5%E8%AF%A2%E6%B5%81%E9%87%8F%E4%B8%BB%E6%AF%8F%E6%97%A5%E5%B9%BF%E5%91%8A%E9%87%91%E6%94%B6%E5%85%A5
|
|
|
+ */
|
|
|
+ public void getGameDiviceSave(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,appletId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int pageSize = 500;
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
+ paramsMap.put("access_token", tokenObj.toString());
|
|
|
+ paramsMap.put("action", "general_action");
|
|
|
+ paramsMap.put("cmd", "get_game_divice_save");
|
|
|
+ paramsMap.put("ad_fund_type", "drama");
|
|
|
+ paramsMap.put("sub_account", "GAME_DEVIDE");
|
|
|
+ paramsMap.put("page", page);
|
|
|
+ paramsMap.put("page_size", pageSize);
|
|
|
+ String s = HttpUtils.httpGet(url, paramsMap, null);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
+ int totalPage = 1;
|
|
|
+ ArrayList<JSONObject> reports = new ArrayList<>();
|
|
|
+ ArrayList<JSONObject> reportsDaily = new ArrayList<>();
|
|
|
+ if (!Check.isNull(jsonObject)) {
|
|
|
+ Integer code = jsonObject.getInteger("ret");
|
|
|
+ JSONObject baseResp = jsonObject.getJSONObject("base_resp");
|
|
|
+ if (baseResp != null) {
|
|
|
+ code = baseResp.getInteger("ret");
|
|
|
+ }
|
|
|
+ if (2009 == code) {
|
|
|
+ return; //无效的流量主
|
|
|
+ }
|
|
|
+ if (code == 0) {
|
|
|
+ Long expireBalance = jsonObject.getLong("expire_balance");
|
|
|
+ String expireTime = jsonObject.getString("expire_time");
|
|
|
+ Long totalBalance = jsonObject.getLong("total_balance");
|
|
|
+ reports.add(new JSONObject()
|
|
|
+ .fluentPut("stat_date", DateUtils.getNowDate("yyyyMMdd"))
|
|
|
+ .fluentPut("app_id", appId)
|
|
|
+ .fluentPut("expire_balance", expireBalance)
|
|
|
+ .fluentPut("expire_time", expireTime)
|
|
|
+ .fluentPut("total_balance", totalBalance));
|
|
|
+
|
|
|
+ JSONArray list = jsonObject.getJSONArray("game_save_detail");
|
|
|
+ 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);
|
|
|
+ JSONObject report = new JSONObject();
|
|
|
+ report.put("stat_date", DateUtils.dateFormatTransform(dataJson.getString("date"),"yyyy年MM月dd日","yyyyMMdd"));
|
|
|
+ report.put("app_id", appId);
|
|
|
+ report.put("game_save_detail_amt",dataJson.getLong("amt"));
|
|
|
+ report.put("game_save_detail_expire_time",dataJson.getString("expire_time"));
|
|
|
+ report.put("game_save_detail_sett_idx",dataJson.getLong("sett_idx"));
|
|
|
+ reportsDaily.add(report);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("查询流量主广告金账户余额拉取失败,app_id:{},返回信息:{}", appId,jsonObject);
|
|
|
+ insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_game_divice_save", "-", "-",
|
|
|
+ jsonObject.fluentPut("app_id", appId).fluentPut("applet_id", appletId).toJSONString());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("查询流量主广告金账户余额拉取失败,app_id:{},返回为空。", appId);
|
|
|
+ insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_game_divice_save","-","-",
|
|
|
+ new JSONObject().fluentPut("app_id", appId).fluentPut("applet_id", appletId).fluentPut("msg", "返回为空").toJSONString());
|
|
|
+ }
|
|
|
+ if (!Check.isNull(reports)) {
|
|
|
+ adqAdIncomeMapper.insertAdqGameDiviceSave(reports);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(reportsDaily)) {
|
|
|
+ adqAdIncomeMapper.insertAdqGameDiviceSaveDetail(reportsDaily);
|
|
|
+ }
|
|
|
+ if (totalPage > page) {
|
|
|
+ getGameDiviceSave(appId, appletId, page + 1, isLog, errId, isSend);
|
|
|
+ } else {
|
|
|
+ log.info("查询流量主广告金账户余额拉取完成,app_id:{} page:{}。", appId, page);
|
|
|
+ if (errId != null) {
|
|
|
+ adqErrorLogMapper.deleteInfoByErrorId(errId);
|
|
|
+ }
|
|
|
+ if (isSend != null && isSend == 1) {
|
|
|
+ AlertUtils.sendMessage(System.currentTimeMillis(), "-", "-", 3, "daily", 1, "adq_ma_game_divice_save");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询流量主广告金账户余额拉取失败,app_id:{}。", appId, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ 查询流量主广告金消耗记录
|
|
|
+ https://developers.weixin.qq.com/minigame/dev/guide/open-ability/ad/adq.html#_1%E3%80%81%E6%9F%A5%E8%AF%A2%E6%B5%81%E9%87%8F%E4%B8%BB%E6%AF%8F%E6%97%A5%E5%B9%BF%E5%91%8A%E9%87%91%E6%94%B6%E5%85%A5
|
|
|
+ */
|
|
|
+ public void getGameDiviceTransfer(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 = 500;
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
+ paramsMap.put("access_token", tokenObj.toString());
|
|
|
+ paramsMap.put("action", "general_action");
|
|
|
+ paramsMap.put("cmd", "get_game_divice_transfer");
|
|
|
+ paramsMap.put("ad_fund_type", "drama");
|
|
|
+ paramsMap.put("page", page);
|
|
|
+ paramsMap.put("page_size", pageSize);
|
|
|
+ paramsMap.put("begin_date", DateUtils.getTimestampFormat("yyyy-MM-dd HH:mm:ss", startDt+" 00:00:00"));
|
|
|
+ paramsMap.put("end_date", DateUtils.getTimestampFormat("yyyy-MM-dd HH:mm:ss", endDt+" 23:59:59"));
|
|
|
+ String s = HttpUtils.httpGet(url, paramsMap, null);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
+ int totalPage = 1;
|
|
|
+ ArrayList<JSONObject> reports = new ArrayList<>();
|
|
|
+ if (!Check.isNull(jsonObject)) {
|
|
|
+ Integer code = jsonObject.getInteger("ret");
|
|
|
+ JSONObject baseResp = jsonObject.getJSONObject("base_resp");
|
|
|
+ if (baseResp != null) {
|
|
|
+ code = baseResp.getInteger("ret");
|
|
|
+ }
|
|
|
+ if (2009 == code) {
|
|
|
+ return; //无效的流量主
|
|
|
+ }
|
|
|
+ if (code == 0) {
|
|
|
+ JSONArray list = jsonObject.getJSONArray("game_transfer_detail");
|
|
|
+ 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("stat_date", dataJson.getString("date").replace("-", ""));
|
|
|
+ dataJson.put("app_id", appId);
|
|
|
+ reports.add(dataJson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("微小查询流量主广告金消耗记录拉取失败,app_id:{} {}~{},返回信息:{}", appId, startDt, endDt, jsonObject);
|
|
|
+ insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_game_divice_transfer", 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_game_divice_transfer", startDt, endDt,
|
|
|
+ new JSONObject().fluentPut("app_id", appId).fluentPut("applet_id", appletId).fluentPut("msg", "返回为空").toJSONString());
|
|
|
+ }
|
|
|
+ if (!Check.isNull(reports)) {
|
|
|
+ adqAdIncomeMapper.insertAdqGameDiviceTransfer(reports);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (totalPage > page) {
|
|
|
+ getGameDiviceTransfer(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_game_divice_transfer");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("微小查询流量主广告金消耗记录拉取失败,app_id:{} {}~{}。", appId, startDt, endDt, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|