|
@@ -1,174 +0,0 @@
|
|
|
-package cn.com.ctop.job.live.service.impl;
|
|
|
-
|
|
|
-import cn.com.ctop.job.live.entity.KuaishouLiveAccountReportDaily;
|
|
|
-import cn.com.ctop.job.live.mapper.KuaishouLiveAccountReportDailyMapper;
|
|
|
-import cn.com.ctop.job.live.service.IKuaishouLiveAccountReportDailyService;
|
|
|
-import cn.com.ctop.job.live.utils.APIUtil;
|
|
|
-import cn.com.ctop.job.live.utils.Check;
|
|
|
-import cn.com.ctop.job.live.utils.DateUtils;
|
|
|
-import cn.com.ctop.job.live.utils.HttpUtil;
|
|
|
-import cn.com.ctop.job.live.utils.KuaishouAPIConstant;
|
|
|
-import cn.com.ctop.job.live.utils.Result;
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * 直播账户报Service业务层处理
|
|
|
- *
|
|
|
- * @author ruoyi
|
|
|
- * @date 2022-07-19
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-@Service
|
|
|
-public class KuaishouLiveAccountReportDailyServiceImpl implements IKuaishouLiveAccountReportDailyService {
|
|
|
-
|
|
|
- @Value("${report.start_ip_path}")
|
|
|
- private String startIpPath;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private KuaishouLiveAccountReportDailyMapper mapper;
|
|
|
-
|
|
|
- @Override
|
|
|
- public void getKuaishouAccountReport(Long accountId, String token) {
|
|
|
- try {
|
|
|
- String beforeYesterday = DateUtils.getSubtractTime(new Date(), 3);
|
|
|
- String yesterday = DateUtils.getSubtractTime(new Date(), 1);
|
|
|
- long startDate = DateUtils.timeToStamp(beforeYesterday + " 00:00:00");
|
|
|
- long endDate = DateUtils.timeToStamp(yesterday + " 23:59:59");
|
|
|
- getAccountReport(accountId, token, startDate, endDate, 1);
|
|
|
- Thread.sleep(2000);
|
|
|
- sendTips("daily", accountId, beforeYesterday, yesterday);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void getAccountReport(Long accountId, String token, long startDate, long endDate, int pageNum) {
|
|
|
- log.info("------getKuaishouAccountReport(获取直播账户日报)---账户:{},---page:{}", accountId, pageNum);
|
|
|
- Result<Object> result = new Result<>();
|
|
|
- Map<String, Object> param = new HashMap<String, Object>();
|
|
|
- param.put("advertiser_id", accountId);
|
|
|
- JSONObject params = new JSONObject();
|
|
|
- params.put("start_time", startDate);
|
|
|
- params.put("end_time", endDate);
|
|
|
- params.put("view_type", 1);
|
|
|
- params.put("group_type", 1);
|
|
|
- JSONObject pageInfo = new JSONObject();
|
|
|
- pageInfo.put("page", pageNum);
|
|
|
- pageInfo.put("page_size", 500);
|
|
|
- param.put("page_info", pageInfo);
|
|
|
- param.put("param", params);
|
|
|
- JSONObject apiResult = APIUtil.getApiResult(KuaishouAPIConstant.REPORT_LIST, token, param);
|
|
|
- System.out.println(params.toJSONString());
|
|
|
- if (apiResult.getInteger("code") == 0) {
|
|
|
- apiResult = apiResult.getJSONObject("data");
|
|
|
- JSONArray data = apiResult.getJSONArray("data");
|
|
|
- List<KuaishouLiveAccountReportDaily> list = new ArrayList<>();
|
|
|
- for (int i = 0; i < data.size(); i++) {
|
|
|
- JSONObject object = data.getJSONObject(i);
|
|
|
- KuaishouLiveAccountReportDaily accountReport = JSONObject.parseObject(object.toJSONString(), KuaishouLiveAccountReportDaily.class);
|
|
|
- accountReport.setAccountId(accountId);
|
|
|
- accountReport.setReportDate(Long.valueOf(DateUtils.timestampToStr(object.getLong("report_date"))));
|
|
|
- list.add(accountReport);
|
|
|
- }
|
|
|
- if (!Check.isNull(list)) {
|
|
|
- mapper.replaceBatch(list);
|
|
|
- }
|
|
|
- if (data.size() == 500) {
|
|
|
- getAccountReport(accountId, token, startDate, endDate, pageNum + 1);
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.error("获取直播账户报表,账户{},{}", accountId, apiResult.toJSONString());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void getKuaishouAccountHourReport(Long accountId, String token) {
|
|
|
- try {
|
|
|
- String beforeYesterday = DateUtils.getSubtractTime(new Date(), 2);
|
|
|
- long beforeYesterdayStartDate = DateUtils.timeToStamp(beforeYesterday + " 00:00:00");
|
|
|
- long beforeYesterdayEndDate = DateUtils.timeToStamp(beforeYesterday + " 23:59:59");
|
|
|
- getAccountReportHour(accountId, beforeYesterdayStartDate, beforeYesterdayEndDate, token, 1);
|
|
|
-
|
|
|
- String yesterday = DateUtils.getSubtractTime(new Date(), 1);
|
|
|
- long yesterdayStartDate = DateUtils.timeToStamp(yesterday + " 00:00:00");
|
|
|
- long yesterdayEndDate = DateUtils.timeToStamp(yesterday + " 23:59:59");
|
|
|
- getAccountReportHour(accountId, yesterdayStartDate, yesterdayEndDate, token, 1);
|
|
|
-
|
|
|
- String date = DateUtils.getDate();
|
|
|
- long endDate = new Date().getTime();
|
|
|
- long startDate = DateUtils.timeToStamp(date + " 00:00:00");
|
|
|
- getAccountReportHour(accountId, startDate, endDate, token, 1);
|
|
|
-
|
|
|
- Thread.sleep(1000);
|
|
|
- sendTips("hourly", accountId, beforeYesterday, date);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void getAccountReportHour(Long accountId, long startDate, long endDate, String token, int pageNum) {
|
|
|
- log.info("------getKuaishouAccountHourReport(获取直播账户时报)---账户:{},---page:{}", accountId, pageNum);
|
|
|
- Result<Object> result = new Result<>();
|
|
|
- Map<String, Object> param = new HashMap<String, Object>();
|
|
|
- param.put("advertiser_id", accountId);
|
|
|
- JSONObject params = new JSONObject();
|
|
|
- //当前小时数
|
|
|
- Integer hourNumber = DateUtils.getHourNumber();
|
|
|
- //当日当时整点时间
|
|
|
- params.put("start_time", startDate);
|
|
|
- params.put("end_time", endDate);
|
|
|
- params.put("view_type", 1);
|
|
|
- params.put("group_type", 2);
|
|
|
- JSONObject pageInfo = new JSONObject();
|
|
|
- pageInfo.put("page", pageNum);
|
|
|
- pageInfo.put("page_size", 500);
|
|
|
- param.put("page_info", pageInfo);
|
|
|
- param.put("param", params);
|
|
|
- JSONObject apiResult = APIUtil.getApiResult(KuaishouAPIConstant.REPORT_LIST, token, param);
|
|
|
- if (apiResult.getInteger("code") == 0) {
|
|
|
- apiResult = apiResult.getJSONObject("data");
|
|
|
- JSONArray data = apiResult.getJSONArray("data");
|
|
|
- List<KuaishouLiveAccountReportDaily> list = new ArrayList<>();
|
|
|
- for (int i = 0; i < data.size(); i++) {
|
|
|
- JSONObject object = data.getJSONObject(i);
|
|
|
- KuaishouLiveAccountReportDaily accountReport = JSONObject.parseObject(object.toJSONString(), KuaishouLiveAccountReportDaily.class);
|
|
|
- accountReport.setAccountId(accountId);
|
|
|
- accountReport.setHour(object.getInteger("report_hour"));
|
|
|
- accountReport.setReportDate(Long.valueOf(DateUtils.timestampToStr(object.getLong("report_date"))));
|
|
|
- list.add(accountReport);
|
|
|
- }
|
|
|
- if (!Check.isNull(list)) {
|
|
|
- mapper.replaceBatchHour(list);
|
|
|
- }
|
|
|
- if (data.size() == 500) {
|
|
|
- getAccountReportHour(accountId, startDate, endDate, token, pageNum + 1);
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.error("获取直播账户报表,账户{},{}", accountId, apiResult.toJSONString());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //发送提示给宇鹏服务,整理数据
|
|
|
- private void sendTips(String type, Long accountId, String startDate, String endDate) {
|
|
|
- /*更新达人数据*/
|
|
|
- Map<String, Object> param = new HashMap<>();
|
|
|
- param.put("account_id", accountId);
|
|
|
- param.put("start_date", startDate.replace("-", ""));
|
|
|
- param.put("end_date", endDate.replace("-", ""));
|
|
|
- param.put("date_type", type);
|
|
|
- Long startTime = System.currentTimeMillis();
|
|
|
- String url = startIpPath + "webhook/live_account_report";
|
|
|
- HttpUtil.httpPostRequest(url, param, null);
|
|
|
- }
|
|
|
-}
|