|
@@ -1,11 +1,13 @@
|
|
|
package cn.com.ctop.kuaishou.modules.report.service.impl;
|
|
|
|
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
|
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
import cn.com.ctop.common.module.utils.HttpUtils;
|
|
|
import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
|
|
|
import cn.com.ctop.common.module.utils.PropertiesUtils;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.mapper.AiKuaishouCreativeLevelOperationRecordMapper;
|
|
|
import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily;
|
|
|
import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDailyAccount;
|
|
|
import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDailyAge;
|
|
@@ -37,6 +39,7 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -53,19 +56,19 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class KuaishouAudienceReportDailyServiceImpl extends ServiceImpl<KuaishouAudienceReportDailyMapper, KuaishouAudienceReportDaily> implements IKuaishouAudienceReportDailyService {
|
|
|
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private KuaishouAudienceReportDailyMapper kuaishouAudienceReportDailyMapper;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private KuaishouAudienceReportDailyProvinceMapper provinceMapper;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private KuaishouAudienceReportDailyAgeMapper ageMapper;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private KuaishouAudienceReportDailyCityMapper cityMapper;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private KuaishouAudienceReportDailyClientMapper clientMapper;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private KuaishouAudienceReportDailyBusinessMapper bussinessMapper;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private KuaishouAudienceReportDailyGenderMapper genderMapper;
|
|
|
@Autowired
|
|
|
private IKuaishouAudienceReportDailyAccountService dailyAccountService;
|
|
@@ -89,7 +92,7 @@ public class KuaishouAudienceReportDailyServiceImpl extends ServiceImpl<Kuaishou
|
|
|
* 人群分析报表入库
|
|
|
*
|
|
|
* @param type province: 省级地域分布, city: 地级地域分布,gender: 性别分布,ageSegment: 年龄分布clientId: 系统分布 businessInterestTags: 商业兴趣分布
|
|
|
- * @param accountId 广告主ID
|
|
|
+ * @param
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
@@ -211,5 +214,196 @@ public class KuaishouAudienceReportDailyServiceImpl extends ServiceImpl<Kuaishou
|
|
|
log.error("插入人群分析报表数据异常,数据维度:{}", type, e);
|
|
|
}
|
|
|
}
|
|
|
+ @Resource
|
|
|
+ cn.com.ctop.kuaishou.modules.ai.mapper.AiKuaishouCreativeLevelOperationRecordMapper creativeLevelOperationRecordMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ UserAllocationMapper userAllocationMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void crowdAnalysisReport2(CtopOauthToken token, String date, String type, Long plan, Long unit, Integer page, Integer pageSize) {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ try {
|
|
|
+ String url = urlPath + KuaishouInterfaceConstant.AUDIENCE_REPORT;
|
|
|
+ JSONArray reportDims = new JSONArray();
|
|
|
+ reportDims.add(type);
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ JSONObject requestJson = new JSONObject();
|
|
|
+ requestJson.put("advertiser_id", token.getAccountId());
|
|
|
+ requestJson.put("start_date", date);
|
|
|
+ requestJson.put("end_date", date);
|
|
|
+ requestJson.put("report_dims", reportDims);
|
|
|
+ requestJson.put("page", page);
|
|
|
+ requestJson.put("page_size", pageSize);
|
|
|
+ if (!Check.isNull(plan)) {
|
|
|
+ JSONArray plans = new JSONArray();
|
|
|
+ plans.add(plan);
|
|
|
+ requestJson.put("campaign_ids", plans);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(unit)) {
|
|
|
+ JSONArray units = new JSONArray();
|
|
|
+ units.add(unit);
|
|
|
+ requestJson.put("unit_ids", units);
|
|
|
+ }
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ if (!Check.isNull(resultJson)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject datas = resultJson.getJSONObject("data");
|
|
|
+ Integer totalCount = datas.getInteger("total_count");
|
|
|
+ JSONArray details = datas.getJSONArray("details");
|
|
|
+ if (!Check.isNull(details)) {
|
|
|
+ //账户级数据
|
|
|
+ if (Check.isNull(plan) && Check.isNull(unit)) {
|
|
|
+ List<KuaishouAudienceReportDailyAccount> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
+ JSONObject obj = details.getJSONObject(i);
|
|
|
+ KuaishouAudienceReportDailyAccount entity = JSONObject.toJavaObject(obj, KuaishouAudienceReportDailyAccount.class);
|
|
|
+ entity.setPhotoLike(obj.getLong("like"));
|
|
|
+ entity.setComments(obj.getLong("comment"));
|
|
|
+ entity.setPhotoShow(obj.getLong("show"));
|
|
|
+ entity.setShares(obj.getString("share"));
|
|
|
+ entity.setAccountId(Long.valueOf(token.getAccountId()));
|
|
|
+ entity.setAudienceType(type);
|
|
|
+ list.add(entity);
|
|
|
+ }
|
|
|
+ dailyAccountService.saveBatch(list);
|
|
|
+ } else {
|
|
|
+ List<KuaishouAudienceReportDailyProvince> provinceList = new ArrayList<>();
|
|
|
+ List<KuaishouAudienceReportDailyCity> cityList = new ArrayList<>();
|
|
|
+ List<KuaishouAudienceReportDailyGender> genderList = new ArrayList<>();
|
|
|
+ List<KuaishouAudienceReportDailyAge> ageList = new ArrayList<>();
|
|
|
+ List<KuaishouAudienceReportDailyClient> clientList = new ArrayList<>();
|
|
|
+ List<KuaishouAudienceReportDailyBusiness> businessList = new ArrayList<>();
|
|
|
+ //组级
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
+ JSONObject obj = details.getJSONObject(i);
|
|
|
+ KuaishouAudienceReportDaily entity = JSONObject.toJavaObject(obj, KuaishouAudienceReportDaily.class);
|
|
|
+ entity.setPhotoLike(obj.getLong("like"));
|
|
|
+ entity.setComments(obj.getLong("comment"));
|
|
|
+ entity.setPhotoShow(obj.getLong("show"));
|
|
|
+ entity.setShares(obj.getString("share"));
|
|
|
+ entity.setAccountId(Long.valueOf(token.getAccountId()));
|
|
|
+ entity.setPlanId(plan);
|
|
|
+ entity.setUnitId(unit);
|
|
|
+
|
|
|
+ String signature = creativeLevelOperationRecordMapper.selectSignatureByUnitId(unit);
|
|
|
+ if(!Check.isNull(signature)){
|
|
|
+ entity.setSignature(signature);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long projectId = userAllocationMapper.getProjectIdByAccountId(token.getAccountId());
|
|
|
+ if(!Check.isNull(projectId)){
|
|
|
+ entity.setProjectId(projectId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("province".equals(type)) {
|
|
|
+ KuaishouAudienceReportDailyProvince provinceEntity = new KuaishouAudienceReportDailyProvince();
|
|
|
+ BeanUtils.copyProperties(entity, provinceEntity);
|
|
|
+ provinceList.add(provinceEntity);
|
|
|
+ } else if ("city".equals(type)) {
|
|
|
+ KuaishouAudienceReportDailyCity cityEntity = new KuaishouAudienceReportDailyCity();
|
|
|
+ BeanUtils.copyProperties(entity, cityEntity);
|
|
|
+ cityList.add(cityEntity);
|
|
|
+ } else if ("gender".equals(type)) {
|
|
|
+ KuaishouAudienceReportDailyGender genderEntity = new KuaishouAudienceReportDailyGender();
|
|
|
+ BeanUtils.copyProperties(entity, genderEntity);
|
|
|
+ genderList.add(genderEntity);
|
|
|
+ } else if ("ageSegment".equals(type)) {
|
|
|
+ KuaishouAudienceReportDailyAge ageEntity = new KuaishouAudienceReportDailyAge();
|
|
|
+ BeanUtils.copyProperties(entity, ageEntity);
|
|
|
+ ageList.add(ageEntity);
|
|
|
+ } else if ("clientId".equals(type)) {
|
|
|
+ KuaishouAudienceReportDailyClient clientEntity = new KuaishouAudienceReportDailyClient();
|
|
|
+ BeanUtils.copyProperties(entity, clientEntity);
|
|
|
+ clientList.add(clientEntity);
|
|
|
+ } else if ("businessInterestTags".equals(type)) {
|
|
|
+ KuaishouAudienceReportDailyBusiness bussinessEntity = new KuaishouAudienceReportDailyBusiness();
|
|
|
+ BeanUtils.copyProperties(entity, bussinessEntity);
|
|
|
+ businessList.add(bussinessEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ("province".equals(type)) {
|
|
|
+ provinceMapper.replaceBatchNew(provinceList);
|
|
|
+ } else if ("city".equals(type)) {
|
|
|
+ cityMapper.replaceBatchNew(cityList);
|
|
|
+ } else if ("gender".equals(type)) {
|
|
|
+ genderMapper.replaceBatchNew(genderList);
|
|
|
+ } else if ("ageSegment".equals(type)) {
|
|
|
+ ageMapper.replaceBatchNew(ageList);
|
|
|
+ } else if ("clientId".equals(type)) {
|
|
|
+ clientMapper.replaceBatchNew(clientList);
|
|
|
+ } else if ("businessInterestTags".equals(type)) {
|
|
|
+ bussinessMapper.replaceBatchNew(businessList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Integer totalPage = (totalCount - 1) / pageSize + 1;
|
|
|
+ if (page < totalPage) {
|
|
|
+ crowdAnalysisReport2(token,date, type, plan, unit, page + 1, pageSize);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if(totalCount != 0){
|
|
|
+ log.error("-----------未查询到人群分析报表数据:unitId:{},日期:{}, 总量:{}", unit, date,totalCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if(code == 500000 || code == 400001){
|
|
|
+ System.out.print("》》5秒后重试,accountId:"+unit+",日期:"+date+"《《 "+resultJson);
|
|
|
+ try{Thread.sleep(5000);} catch (InterruptedException e){};
|
|
|
+ crowdAnalysisReport2(token,date, type, plan, unit, page, pageSize);
|
|
|
+ }else {
|
|
|
+ log.error("查询人群分析报表数据返回信息错误:unit:{},日期{},返回信息:{}", unit,date, resultJson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("插入人群分析报表数据异常,数据维度:{}", type, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void crowdAnalysisReport3(CtopOauthToken token, String date, String type, Long plan, JSONArray unit, Integer page, Integer pageSize) {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ try {
|
|
|
+ String url = urlPath + KuaishouInterfaceConstant.AUDIENCE_REPORT;
|
|
|
+ JSONArray reportDims = new JSONArray();
|
|
|
+ reportDims.add(type);
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ JSONObject requestJson = new JSONObject();
|
|
|
+ requestJson.put("advertiser_id", token.getAccountId());
|
|
|
+ requestJson.put("start_date", date);
|
|
|
+ requestJson.put("end_date", date);
|
|
|
+ requestJson.put("report_dims", reportDims);
|
|
|
+ requestJson.put("page", page);
|
|
|
+ requestJson.put("page_size", pageSize);
|
|
|
+ if (!Check.isNull(plan)) {
|
|
|
+ JSONArray plans = new JSONArray();
|
|
|
+ plans.add(plan);
|
|
|
+ requestJson.put("campaign_ids", plans);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(unit)) {
|
|
|
+ requestJson.put("unit_ids", unit);
|
|
|
+ }
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ if (!Check.isNull(resultJson)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject datas = resultJson.getJSONObject("data");
|
|
|
+ Integer totalCount = datas.getInteger("total_count");
|
|
|
+ JSONArray details = datas.getJSONArray("details");
|
|
|
+ System.out.println("datas"+datas.toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("插入人群分析报表数据异常,数据维度:{}", type, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|