|
@@ -1,7 +1,5 @@
|
|
|
package cn.com.ctop.kuaishou.modules.batch.service.impl;
|
|
|
|
|
|
-import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
-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;
|
|
@@ -9,16 +7,16 @@ import cn.com.ctop.common.module.utils.PropertiesUtils;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplate;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplateTarget;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouTemplateMapper;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouTemplateTargetMapper;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouTemplateService;
|
|
|
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouTemplateTargetService;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.jeecg.common.api.vo.Result;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -33,16 +31,16 @@ import java.util.Map;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMapper, KuaishouTemplate> implements IKuaishouTemplateService {
|
|
|
+
|
|
|
@Autowired
|
|
|
- private IKuaishouTemplateTargetService templateTargetService;
|
|
|
+ private KuaishouTemplateTargetMapper templateTargetMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private KuaishouTemplateMapper templateMapper;
|
|
|
- @Autowired
|
|
|
- private ICtopOauthTokenService tokenService;
|
|
|
|
|
|
@Override
|
|
|
- public List<JSONObject> getJsonArrByAccountId(Long accountId, Integer platformOs) {
|
|
|
- return templateMapper.getJsonArrByAccountId(accountId, platformOs);
|
|
|
+ public List<JSONObject> getJsonArrByAccountId(Long accountId, Integer platformOs, Boolean autoTarget) {
|
|
|
+ return templateMapper.getJsonArrByAccountId(accountId, platformOs, autoTarget);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -52,6 +50,7 @@ public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMap
|
|
|
param.put("advertiser_id", accountId);
|
|
|
param.put("page", page);
|
|
|
param.put("page_size", 500);
|
|
|
+
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
|
headers.put("Access-Token", accessToken);
|
|
|
headers.put("Content-Type", " application/json");
|
|
@@ -59,9 +58,6 @@ public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMap
|
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
if (!Check.isNull(resultJson)) {
|
|
|
Integer code = resultJson.getInteger("code");
|
|
|
- /* Map<String, Object> deleteMap = new HashMap<>();
|
|
|
- deleteMap.put("account_id", accountId);
|
|
|
- this.removeByMap(deleteMap);*/
|
|
|
if (code == 0) {
|
|
|
JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
if (Check.isNull(dataJson)) {
|
|
@@ -71,6 +67,9 @@ public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMap
|
|
|
if (Check.isNull(details)) {
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ List<KuaishouTemplate> templateList = new ArrayList<>();
|
|
|
+ List<KuaishouTemplateTarget> templateTargetList = new ArrayList<>();
|
|
|
for (int i = 0; i < details.size(); i++) {
|
|
|
JSONObject jsonObject = details.getJSONObject(i);
|
|
|
Long templateId = jsonObject.getLong("template_id");
|
|
@@ -80,9 +79,10 @@ public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMap
|
|
|
template.setTemplateId(templateId);
|
|
|
template.setTemplateName(jsonObject.getString("template_name"));
|
|
|
template.setUnitCount(jsonObject.getInteger("unit_count"));
|
|
|
+ template.setAutoTarget(jsonObject.getBoolean("auto_target"));
|
|
|
template.setCreateTime(jsonObject.getDate("create_time"));
|
|
|
template.setUpdateTime(jsonObject.getDate("updateTime"));
|
|
|
- this.saveOrUpdate(template);
|
|
|
+ templateList.add(template);
|
|
|
JSONObject targetJson = jsonObject.getJSONObject("target");
|
|
|
if (!Check.isNull(targetJson)) {
|
|
|
KuaishouTemplateTarget templateTarget = new KuaishouTemplateTarget();
|
|
@@ -171,10 +171,18 @@ public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMap
|
|
|
templateTarget.setNoAreaBreak(intelliExtendJson.getInteger("no_area_break"));
|
|
|
}
|
|
|
}
|
|
|
- templateTargetService.saveOrUpdate(templateTarget);
|
|
|
+
|
|
|
+
|
|
|
+ templateTarget.setCreateTime(jsonObject.getDate("create_time"));
|
|
|
+ templateTarget.setUpdateTime(jsonObject.getDate("updateTime"));
|
|
|
+ templateTargetList.add(templateTarget);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ if (!Check.isNull(templateList)) {
|
|
|
+ templateMapper.replaceBatch(templateList);
|
|
|
+ templateTargetMapper.templateTargetList(templateTargetList);
|
|
|
+ }
|
|
|
|
|
|
getTemplateByAccountId(accountId, accessToken, page + 1);
|
|
|
} else {
|
|
@@ -208,10 +216,12 @@ public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMap
|
|
|
if (Check.isNull(requestJson.getString("templateName"))) {
|
|
|
throw new Exception("定向模板名称为必传项");
|
|
|
}
|
|
|
-
|
|
|
JSONObject param = new JSONObject();
|
|
|
param.put("advertiser_id", accountId);
|
|
|
param.put("template_name", requestJson.getString("templateName"));
|
|
|
+ if (!Check.isNull(requestJson.getBoolean("autoTarget"))) {
|
|
|
+ param.put("auto_target", requestJson.getBoolean("autoTarget"));
|
|
|
+ }
|
|
|
JSONObject targetJson = new JSONObject();
|
|
|
if (!Check.isNull(requestJson.getJSONArray("region"))) {
|
|
|
targetJson.put("region", requestJson.getJSONArray("region"));
|
|
@@ -471,7 +481,6 @@ public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMap
|
|
|
headers.put("Access-Token", accessToken);
|
|
|
headers.put("Content-Type", " application/json");
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_UPDATE;
|
|
|
- log.info("入参:" + param);
|
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
if (!Check.isNull(resultJson)) {
|
|
@@ -499,83 +508,4 @@ public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMap
|
|
|
}
|
|
|
return returnJson;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询加速探索信息
|
|
|
- *
|
|
|
- * @param
|
|
|
- * @throws
|
|
|
- * @author ZHAOXA
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Result<Object> getbehaviorInterest(Long accountId) {
|
|
|
- try {
|
|
|
- CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
|
|
|
- String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.BEHAVIOR_INTEREST;
|
|
|
- Map<String, String> header = new HashMap<>();
|
|
|
- header.put("Access-Token", token.getAccessToken());
|
|
|
- header.put("Content-Type", "application/json");
|
|
|
- JSONObject params = new JSONObject();
|
|
|
- params.put("advertiser_id", accountId);
|
|
|
- String result = HttpUtils.httpPostRequest(url, params, header);
|
|
|
- JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
- if (!Check.isNull(resultJson)) {
|
|
|
- Integer code = resultJson.getInteger("code");
|
|
|
- if (code == 0) {
|
|
|
- return Result.ok(resultJson.getJSONObject("data"));
|
|
|
- } else {
|
|
|
- log.info(" 获取行为与兴趣类目失败,accountId:{},返回信息:{}", accountId, resultJson);
|
|
|
- return Result.error("获取行为与兴趣类目失败," + resultJson.getString("message"));
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("获取行为与兴趣类目失败", e);
|
|
|
- }
|
|
|
- return Result.error("获取行为与兴趣类目失败");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result<Object> getKeywordQuery(JSONObject data) {
|
|
|
- try {
|
|
|
- Long accountId = data.getLong("accountId");
|
|
|
- String query_str = data.getString("query_str");
|
|
|
- Integer type = data.getInteger("type");
|
|
|
- JSONArray ids = data.getJSONArray("ids");
|
|
|
- if (Check.isNull(accountId) || Check.isNull(type)) {
|
|
|
- return Result.error("缺失参数");
|
|
|
- }
|
|
|
- if (Check.isNull(query_str) && Check.isNull(ids)) {
|
|
|
- return Result.error("缺失参数");
|
|
|
- }
|
|
|
- CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
|
|
|
- String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.KEYWORD_QUERY;
|
|
|
- Map<String, String> header = new HashMap<>();
|
|
|
- header.put("Access-Token", token.getAccessToken());
|
|
|
- header.put("Content-Type", "application/json");
|
|
|
- JSONObject params = new JSONObject();
|
|
|
- params.put("advertiser_id", accountId);
|
|
|
- params.put("type", type);
|
|
|
- if (!Check.isNull(query_str)) {
|
|
|
- params.put("query_str", query_str);
|
|
|
- }
|
|
|
- if (!Check.isNull(ids)) {
|
|
|
- params.put("ids", ids);
|
|
|
- }
|
|
|
- String result = HttpUtils.httpPostRequest(url, params, header);
|
|
|
- JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
- if (!Check.isNull(resultJson)) {
|
|
|
- Integer code = resultJson.getInteger("code");
|
|
|
- if (code == 0) {
|
|
|
- return Result.ok(resultJson.getJSONObject("data"));
|
|
|
- } else {
|
|
|
- log.info("获取行为兴趣关键词失败,accountId:{},返回信息:{}", accountId, resultJson);
|
|
|
- return Result.error("获取行为兴趣关键词失败," + resultJson.getString("message"));
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("获取行为兴趣关键词失败", e);
|
|
|
- }
|
|
|
- return Result.error("获取行为兴趣关键词失败");
|
|
|
- }
|
|
|
-
|
|
|
}
|