|
|
@@ -0,0 +1,124 @@
|
|
|
+package cn.com.ctop.job.bytedance.data.service.impl;
|
|
|
+
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.ByteDanceFlowDetailsReportDaily;
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.ByteDanceFlowDetailsReportMapper;
|
|
|
+import cn.com.ctop.job.bytedance.data.service.IByteDanceFlowDetailsReportService;
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author lining
|
|
|
+ * @ClassName ByteDanceFlowDetailsReportServiceImpl
|
|
|
+ * @description: TODO
|
|
|
+ * @date 2025年04月16日
|
|
|
+ * @version: 1.0
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class ByteDanceFlowDetailsReportServiceImpl implements IByteDanceFlowDetailsReportService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ByteDanceFlowDetailsReportMapper byteDanceFlowDetailsReportMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getBytedanceFlowDetailsDailyReport(Long advertiserId, String accessToken, String accountType, String startDate, String endDate, Integer page) {
|
|
|
+ String url = "https://ad.oceanengine.com/open_api/2/advertiser/fund/daily_stat/";
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
+ paramsMap.put("advertiser_id", advertiserId);
|
|
|
+ paramsMap.put("start_date", startDate);
|
|
|
+ paramsMap.put("end_date", endDate);
|
|
|
+ /**
|
|
|
+ * 账户业务类型,可选值:
|
|
|
+ * AD AD广告主(默认)
|
|
|
+ * LOCAL 本地推
|
|
|
+ * STAR 星图
|
|
|
+ */
|
|
|
+ paramsMap.put("account_type", accountType);
|
|
|
+ paramsMap.put("page", page);
|
|
|
+ paramsMap.put("page_size", 100);
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ String s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
|
+ JSONObject result = JSONObject.parseObject(s);
|
|
|
+ if (Check.isNull(result)) {
|
|
|
+ log.info("账户id:{},广告流水详情请求结果返回为空", advertiserId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ByteDanceFlowDetailsReportDaily> dailies = new ArrayList<>();
|
|
|
+ Integer code = result.getInteger("code");
|
|
|
+ Integer totalPage = 1;
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject data = result.getJSONObject("data");
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
+ JSONArray list = data.getJSONArray("list");
|
|
|
+ totalPage = data.getJSONObject("page_info").getIntValue("total_page");
|
|
|
+ if (!Check.isNull(list)) {
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ JSONObject object = list.getJSONObject(i);
|
|
|
+ String advertiser_id = object.getString("advertiser_id");
|
|
|
+ String date = object.getString("date").replace("-", "");
|
|
|
+ BigDecimal balance = object.getBigDecimal("balance");
|
|
|
+ BigDecimal grant_balance = object.getBigDecimal("grant_balance");
|
|
|
+ BigDecimal non_grant_balance = object.getBigDecimal("non_grant_balance");
|
|
|
+ BigDecimal cash_cost = object.getBigDecimal("cash_cost");
|
|
|
+ BigDecimal cost = object.getBigDecimal("cost");
|
|
|
+ BigDecimal frozen = object.getBigDecimal("frozen");
|
|
|
+ BigDecimal income = object.getBigDecimal("income");
|
|
|
+ BigDecimal reward_cost = object.getBigDecimal("reward_cost");
|
|
|
+ BigDecimal shared_wallet_cost = object.getBigDecimal("shared_wallet_cost");
|
|
|
+ BigDecimal company_wallet_cost = object.getBigDecimal("company_wallet_cost");
|
|
|
+ BigDecimal transfer_in = object.getBigDecimal("transfer_in");
|
|
|
+ BigDecimal transfer_out = object.getBigDecimal("transfer_out");
|
|
|
+
|
|
|
+
|
|
|
+ ByteDanceFlowDetailsReportDaily daily = ByteDanceFlowDetailsReportDaily.builder()
|
|
|
+ .advertiserId(Long.parseLong(advertiser_id))
|
|
|
+ .statTimeDay(Integer.parseInt(date))
|
|
|
+ .balance(balance)
|
|
|
+ .grantBalance(grant_balance)
|
|
|
+ .nonGrantBalance(non_grant_balance)
|
|
|
+ .cashCost(cash_cost)
|
|
|
+ .cost(cost)
|
|
|
+ .frozen(frozen)
|
|
|
+ .income(income)
|
|
|
+ .rewardCost(reward_cost)
|
|
|
+ .sharedWalletCost(shared_wallet_cost)
|
|
|
+ .companyWalletCost(company_wallet_cost)
|
|
|
+ .transferIn(transfer_in)
|
|
|
+ .transferOut(transfer_out)
|
|
|
+ .build();
|
|
|
+ dailies.add(daily);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(dailies)) {
|
|
|
+ log.info("账户id:{},流水日报请求结果返回成功", advertiserId);
|
|
|
+ byteDanceFlowDetailsReportMapper.replaceDanceFlowDetailsReportDailies(dailies);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (page < totalPage) {
|
|
|
+ try {
|
|
|
+ Thread.sleep(500L);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ getBytedanceFlowDetailsDailyReport(advertiserId, accessToken, accountType, startDate, endDate, page + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|