|
@@ -9,15 +9,18 @@ import cn.com.ctop.common.module.service.IRuleDataUnitKuaishouService;
|
|
import cn.com.ctop.common.module.service.IRuleDatePlanKuaishouService;
|
|
import cn.com.ctop.common.module.service.IRuleDatePlanKuaishouService;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
import cn.com.ctop.common.module.utils.HttpUtils;
|
|
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.batch.entity.KuaiShouGroup;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
|
|
import cn.com.ctop.kuaishou.modules.report.service.IRuleKuaiShouPlanService;
|
|
import cn.com.ctop.kuaishou.modules.report.service.IRuleKuaiShouPlanService;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.xxl.job.core.context.XxlJobHelper;
|
|
import com.xxl.job.core.context.XxlJobHelper;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -38,14 +41,15 @@ public class RuleKuaiShouPlanServiceImpl implements IRuleKuaiShouPlanService {
|
|
@Autowired
|
|
@Autowired
|
|
IRuleDataUnitKuaishouService unitKuaishouService;
|
|
IRuleDataUnitKuaishouService unitKuaishouService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ IKuaiShouGroupService kuaiShouGroupService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
- public void cleanRuleDataPlan(Long accountId, String startDate, String endDate, int page) {
|
|
|
|
|
|
+ public void cleanRuleDataPlan(Long accountId, int page) {
|
|
JSONObject param = new JSONObject();
|
|
JSONObject param = new JSONObject();
|
|
param.put("advertiser_id", accountId);
|
|
param.put("advertiser_id", accountId);
|
|
param.put("page_size", 500);
|
|
param.put("page_size", 500);
|
|
param.put("page", page);
|
|
param.put("page", page);
|
|
- param.put("start_date", startDate);
|
|
|
|
- param.put("end_date", endDate);
|
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
headers.put("Access-Token", oauthTokenService.getTokenByAccountId(accountId).getAccessToken());
|
|
headers.put("Access-Token", oauthTokenService.getTokenByAccountId(accountId).getAccessToken());
|
|
@@ -67,7 +71,7 @@ public class RuleKuaiShouPlanServiceImpl implements IRuleKuaiShouPlanService {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
this.insertPlan(accountId, details);
|
|
this.insertPlan(accountId, details);
|
|
- cleanRuleDataPlan(accountId, startDate, endDate, page + 1);
|
|
|
|
|
|
+ cleanRuleDataPlan(accountId, page + 1);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -76,8 +80,8 @@ public class RuleKuaiShouPlanServiceImpl implements IRuleKuaiShouPlanService {
|
|
param.put("advertiser_id", accountId);
|
|
param.put("advertiser_id", accountId);
|
|
param.put("page_size", 500);
|
|
param.put("page_size", 500);
|
|
param.put("page", page);
|
|
param.put("page", page);
|
|
- param.put("start_date", startDate);
|
|
|
|
- param.put("end_date", endDate);
|
|
|
|
|
|
+ param.put("start_date",startDate);
|
|
|
|
+ param.put("end_date",endDate);
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
headers.put("Access-Token", oauthTokenService.getTokenByAccountId(accountId).getAccessToken());
|
|
headers.put("Access-Token", oauthTokenService.getTokenByAccountId(accountId).getAccessToken());
|
|
@@ -103,20 +107,17 @@ public class RuleKuaiShouPlanServiceImpl implements IRuleKuaiShouPlanService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void cleanRuleDataTarget(Long accountId, String startDate, String endDate, int page) {
|
|
|
|
- String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GROUP_LIST;
|
|
|
|
|
|
+ public void cleanRuleDataTarget(Long accountId, int page) {
|
|
JSONObject param = new JSONObject();
|
|
JSONObject param = new JSONObject();
|
|
param.put("advertiser_id", accountId);
|
|
param.put("advertiser_id", accountId);
|
|
param.put("page_size", 500);
|
|
param.put("page_size", 500);
|
|
param.put("page", page);
|
|
param.put("page", page);
|
|
- param.put("start_date", startDate);
|
|
|
|
- param.put("end_date", endDate);
|
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
headers.put("Access-Token", oauthTokenService.getTokenByAccountId(accountId).getAccessToken());
|
|
headers.put("Access-Token", oauthTokenService.getTokenByAccountId(accountId).getAccessToken());
|
|
headers.put("Content-Type", "application/json");
|
|
headers.put("Content-Type", "application/json");
|
|
|
|
|
|
- String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest("https://ad.e.kuaishou.com/rest/openapi/v1/ad_unit/list", param.toJSONString(), headers);
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
if (Check.isNull(resultJson)) {
|
|
if (Check.isNull(resultJson)) {
|
|
XxlJobHelper.log("获取广告组接口异常,advertiserId:{}", accountId);
|
|
XxlJobHelper.log("获取广告组接口异常,advertiserId:{}", accountId);
|
|
@@ -132,7 +133,7 @@ public class RuleKuaiShouPlanServiceImpl implements IRuleKuaiShouPlanService {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
this.insertTarget(accountId, details);
|
|
this.insertTarget(accountId, details);
|
|
- cleanRuleDataTarget(accountId, startDate, endDate, page + 1);
|
|
|
|
|
|
+ cleanRuleDataTarget(accountId, page + 1);
|
|
}
|
|
}
|
|
|
|
|
|
private void insertPlan(Long accountId, JSONArray details) {
|
|
private void insertPlan(Long accountId, JSONArray details) {
|
|
@@ -148,30 +149,39 @@ public class RuleKuaiShouPlanServiceImpl implements IRuleKuaiShouPlanService {
|
|
batch.add(plan);
|
|
batch.add(plan);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- planKuaishouService.saveOrUpdateBatch(batch);
|
|
|
|
|
|
+ if(!batch.isEmpty()) {
|
|
|
|
+ planKuaishouService.saveOrUpdateBatch(batch);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private void insertUnit(Long accountId, JSONArray details) {
|
|
private void insertUnit(Long accountId, JSONArray details) {
|
|
List<RuleDateUnitKuaishou> batch = new ArrayList<>();
|
|
List<RuleDateUnitKuaishou> batch = new ArrayList<>();
|
|
details.forEach(detail -> {
|
|
details.forEach(detail -> {
|
|
JSONObject unitDetail = (JSONObject) detail;
|
|
JSONObject unitDetail = (JSONObject) detail;
|
|
- RuleDateUnitKuaishou plan = new RuleDateUnitKuaishou();
|
|
|
|
- plan.setId(unitDetail.getLong("unit_id"));
|
|
|
|
- plan.setAccountId(accountId);
|
|
|
|
- plan.setUnitId(unitDetail.getLong("unit_id"));
|
|
|
|
- plan.setUnitName(unitDetail.getString("unit_name"));
|
|
|
|
- plan.setCharge(unitDetail.getBigDecimal("charge"));
|
|
|
|
-/* plan.setActivation(unitDetail.getBigDecimal("activation"));
|
|
|
|
- plan.setActivationCost(unitDetail.getBigDecimal("charge"));
|
|
|
|
- plan.setEventRegister(unitDetail.getBigDecimal("charge"));
|
|
|
|
- plan.setRegisterCost(unitDetail.getBigDecimal("charge"));
|
|
|
|
- plan.setFormCount(unitDetail.getBigDecimal("charge"));
|
|
|
|
- plan.setFormCost(unitDetail.getBigDecimal("charge"));
|
|
|
|
- plan.setEventPay(unitDetail.getBigDecimal("charge"));
|
|
|
|
- plan.setPayCost(unitDetail.getBigDecimal("charge"));*/
|
|
|
|
- batch.add(plan);
|
|
|
|
|
|
+ RuleDateUnitKuaishou unit = new RuleDateUnitKuaishou();
|
|
|
|
+ QueryWrapper<KuaiShouGroup> wrapper=new QueryWrapper<>();
|
|
|
|
+ wrapper.eq("unit_id",unitDetail.getLong("unit_id"));
|
|
|
|
+ KuaiShouGroup group = kuaiShouGroupService.getOne(wrapper);
|
|
|
|
+ if(group!=null){
|
|
|
|
+ unit.setId(unitDetail.getLong("unit_id"));
|
|
|
|
+ unit.setAccountId(accountId);
|
|
|
|
+ unit.setPlanId(unitDetail.getLong("campaign_id"));
|
|
|
|
+ unit.setUnitId(unitDetail.getLong("unit_id"));
|
|
|
|
+ unit.setUnitName(unitDetail.getString("unit_name"));
|
|
|
|
+ unit.setCharge(unitDetail.getBigDecimal("charge"));
|
|
|
|
+ if(group.getOcpxActionType()!=0){
|
|
|
|
+ unit.setConvertNum(handleConvertNum(group.getOcpxActionType(),unitDetail));
|
|
|
|
+ if(unit.getConvertNum()!=0){
|
|
|
|
+ unit.setConvertCost(unitDetail.getBigDecimal("charge").divide(BigDecimal.valueOf(unit.getConvertNum()), 2, RoundingMode.HALF_UP));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ batch.add(unit);
|
|
|
|
+ }
|
|
|
|
+
|
|
});
|
|
});
|
|
- unitKuaishouService.saveOrUpdateBatch(batch);
|
|
|
|
|
|
+ if(!batch.isEmpty()){
|
|
|
|
+ unitKuaishouService.saveOrUpdateBatch(batch);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private void insertTarget(Long accountId, JSONArray details) {
|
|
private void insertTarget(Long accountId, JSONArray details) {
|
|
@@ -183,19 +193,65 @@ public class RuleKuaiShouPlanServiceImpl implements IRuleKuaiShouPlanService {
|
|
unitDetail.getInteger("put_status") == 1) {
|
|
unitDetail.getInteger("put_status") == 1) {
|
|
target.setId(unitDetail.getLong("unit_id"));
|
|
target.setId(unitDetail.getLong("unit_id"));
|
|
target.setAccountId(accountId);
|
|
target.setAccountId(accountId);
|
|
|
|
+ target.setPlanId(unitDetail.getLong("campaign_id"));
|
|
target.setUnitId(unitDetail.getLong("unit_id"));
|
|
target.setUnitId(unitDetail.getLong("unit_id"));
|
|
- target.setSceneId(unitDetail.getJSONArray("scene_id").toString());
|
|
|
|
- target.setRegion(unitDetail.getJSONArray("region").toString());
|
|
|
|
- target.setGender(unitDetail.getInteger("gender"));
|
|
|
|
- target.setPlatformOs(unitDetail.getInteger("platform_os"));
|
|
|
|
- target.setDeviceBrand(unitDetail.getJSONArray("device_brand").toString());
|
|
|
|
- target.setDevicePrice(unitDetail.getJSONArray("device_price").toString());
|
|
|
|
- target.setFilterConvertedLevel(unitDetail.getString("filter_converted_level"));
|
|
|
|
- target.setIsOpen(unitDetail.getInteger("is_open"));
|
|
|
|
- target.setScheduleTime(unitDetail.getJSONArray("schedule_time").toString());
|
|
|
|
|
|
+ target.setSceneId(unitDetail.getJSONArray("scene_id")==null?"":unitDetail.getJSONArray("scene_id").toString());
|
|
|
|
+ target.setRegion(unitDetail.getJSONArray("region")==null?"":unitDetail.getJSONArray("region").toString());
|
|
|
|
+ target.setGender(unitDetail.getInteger("gender")==null?0:unitDetail.getInteger("gender"));
|
|
|
|
+ target.setPlatformOs(unitDetail.getInteger("platform_os")==null?0:unitDetail.getInteger("platform_os"));
|
|
|
|
+ target.setDeviceBrand(unitDetail.getJSONArray("device_brand")==null?"":unitDetail.getJSONArray("device_brand").toString());
|
|
|
|
+ target.setDevicePrice(unitDetail.getJSONArray("device_price")==null?"":unitDetail.getJSONArray("device_price").toString());
|
|
|
|
+ target.setFilterConvertedLevel(unitDetail.getInteger("filter_converted_level")==null?0:unitDetail.getInteger("filter_converted_level"));
|
|
|
|
+ target.setIsOpen(unitDetail.getInteger("is_open")==null?0:unitDetail.getInteger("is_open"));
|
|
|
|
+ target.setScheduleTime(unitDetail.getString("schedule_time")==null?"":unitDetail.getString("schedule_time"));
|
|
batch.add(target);
|
|
batch.add(target);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- targetKuaishouService.saveOrUpdateBatch(batch);
|
|
|
|
|
|
+ if (!batch.isEmpty()) {
|
|
|
|
+ targetKuaishouService.saveOrUpdateBatch(batch);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Long handleConvertNum(int ocpxActionType,JSONObject detail){
|
|
|
|
+ Long convertNum=null;
|
|
|
|
+ switch (ocpxActionType){
|
|
|
|
+ case 2:
|
|
|
|
+ convertNum=detail.getLong("submit");
|
|
|
|
+ break;
|
|
|
|
+ case 10:
|
|
|
|
+ convertNum=detail.getLong("show");
|
|
|
|
+ break;
|
|
|
|
+ case 11:
|
|
|
|
+ convertNum=detail.getLong("photo_click");
|
|
|
|
+ break;
|
|
|
|
+ case 31:
|
|
|
|
+ convertNum=detail.getLong("download_completed");
|
|
|
|
+ break;
|
|
|
|
+ case 53:
|
|
|
|
+ convertNum=detail.getLong("event_valid_clues");
|
|
|
|
+ break;
|
|
|
|
+ case 180:
|
|
|
|
+ convertNum=detail.getLong("activation");
|
|
|
|
+ break;
|
|
|
|
+ case 190:
|
|
|
|
+ convertNum=detail.getLong("event_pay");
|
|
|
|
+ break;
|
|
|
|
+ case 191:
|
|
|
|
+ convertNum=detail.getDouble("event_pay_first_day_roi").longValue();
|
|
|
|
+ break;
|
|
|
|
+ case 348:
|
|
|
|
+ convertNum=detail.getLong("event_valid_clues");
|
|
|
|
+ break;
|
|
|
|
+ case 383:
|
|
|
|
+ convertNum=detail.getLong("event_credit_grant_landing_page");
|
|
|
|
+ break;
|
|
|
|
+ case 384:
|
|
|
|
+ convertNum=detail.getLong("event_jin_jian_landing_page");
|
|
|
|
+ break;
|
|
|
|
+ case 715:
|
|
|
|
+ convertNum=detail.getLong("event_add_wechat");
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ return convertNum;
|
|
}
|
|
}
|
|
}
|
|
}
|