|
@@ -1,12 +1,16 @@
|
|
|
package cn.com.ctop.kuaishou.modules.ai.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;
|
|
|
import cn.com.ctop.common.module.utils.PropertiesUtils;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouDirectionalPackage;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouDirectionalTemplateRel;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouDirectionalPackageMapper;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouDirectionalPackageService;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouDirectionalTemplateRelService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouTemplateService;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -21,6 +25,8 @@ import org.springframework.stereotype.Service;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
|
/**
|
|
|
* 自动投放-定向包详情
|
|
@@ -37,16 +43,40 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
private IKuaishouTemplateService kuaishouTemplateService;
|
|
|
@Autowired
|
|
|
private KuaishouDirectionalPackageMapper packageMapper;
|
|
|
+ @Autowired
|
|
|
+ private IKuaishouDirectionalTemplateRelService relService;
|
|
|
+ @Autowired
|
|
|
+ private ICtopOauthTokenService oauthTokenService;
|
|
|
+ static ExecutorService executorService = null;
|
|
|
|
|
|
@Override
|
|
|
public Result<Object> createDirectionalPackage(String accessToken, JSONObject requestJson) {
|
|
|
+ KuaishouDirectionalPackage entity = packageMapper.queryEntity(requestJson);
|
|
|
+ if (!Check.isNull(entity)) {
|
|
|
+ return Result.error("该账户下人群包名已存在");
|
|
|
+ }
|
|
|
+ KuaishouDirectionalPackage kuaishouDirectionalPackage = JSONObject.toJavaObject(requestJson, KuaishouDirectionalPackage.class);
|
|
|
+ kuaishouDirectionalPackage.setDataStatus(1);
|
|
|
+ boolean save = this.save(kuaishouDirectionalPackage);
|
|
|
+ if (save) {
|
|
|
+ return Result.ok("创建成功");
|
|
|
+ }
|
|
|
+ return Result.error("创建失败,定向包存储失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Object> updateDirectionalPackage(String accessToken, JSONObject requestJson) {
|
|
|
JSONObject returnJson = new JSONObject();
|
|
|
String message = "";
|
|
|
int flag = -1;
|
|
|
try {
|
|
|
JSONObject param = new JSONObject();
|
|
|
+ param.put("template_id", requestJson.getLong("templateId"));
|
|
|
param.put("advertiser_id", requestJson.getLong("accountId"));
|
|
|
- param.put("template_name", requestJson.getString("templateName"));
|
|
|
+ if (!Check.isNull(requestJson.getString("templateName"))) {
|
|
|
+ param.put("template_name", requestJson.getString("templateName"));
|
|
|
+ }
|
|
|
JSONObject targetJson = new JSONObject();
|
|
|
if (!Check.isNull(requestJson.getJSONArray("region"))) {
|
|
|
targetJson.put("region", requestJson.getJSONArray("region"));
|
|
@@ -61,14 +91,10 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
targetJson.put("ages_range", requestJson.getJSONArray("agesRange"));
|
|
|
}
|
|
|
|
|
|
- JSONObject ageJson = new JSONObject();
|
|
|
- if (!Check.isNull(requestJson.getInteger("min"))) {
|
|
|
+ if (!Check.isNull(requestJson.getInteger("min")) && !Check.isNull(requestJson.getInteger("max"))) {
|
|
|
+ JSONObject ageJson = new JSONObject();
|
|
|
ageJson.put("min", requestJson.getInteger("min"));
|
|
|
- }
|
|
|
- if (!Check.isNull(requestJson.getInteger("max"))) {
|
|
|
ageJson.put("max", requestJson.getInteger("max"));
|
|
|
- }
|
|
|
- if (!Check.isNull(ageJson)) {
|
|
|
targetJson.put("age", ageJson);
|
|
|
}
|
|
|
|
|
@@ -123,22 +149,24 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
|
|
|
targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
|
|
|
}
|
|
|
- JSONObject intelliExtendJson = new JSONObject();
|
|
|
+
|
|
|
|
|
|
if (!Check.isNull(requestJson.getInteger("isOpen"))) {
|
|
|
+ JSONObject intelliExtendJson = new JSONObject();
|
|
|
intelliExtendJson.put("is_open", requestJson.getInteger("isOpen"));
|
|
|
- }
|
|
|
- if (!Check.isNull(requestJson.getInteger("noAgeBreak"))) {
|
|
|
- intelliExtendJson.put("no_age_break", requestJson.getInteger("noAgeBreak"));
|
|
|
- }
|
|
|
- if (!Check.isNull(requestJson.getInteger("noGenderBreak"))) {
|
|
|
- intelliExtendJson.put("no_gender_break", requestJson.getInteger("noGenderBreak"));
|
|
|
- }
|
|
|
- if (!Check.isNull(requestJson.getInteger("noAreaBreak"))) {
|
|
|
- intelliExtendJson.put("no_area_break", requestJson.getInteger("noAreaBreak"));
|
|
|
- }
|
|
|
- if (!Check.isNull(intelliExtendJson)) {
|
|
|
- targetJson.put("intelli_extend", intelliExtendJson);
|
|
|
+
|
|
|
+ if (!Check.isNull(requestJson.getInteger("noAgeBreak"))) {
|
|
|
+ intelliExtendJson.put("no_age_break", requestJson.getInteger("noAgeBreak"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("noGenderBreak"))) {
|
|
|
+ intelliExtendJson.put("no_gender_break", requestJson.getInteger("noGenderBreak"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("noAreaBreak"))) {
|
|
|
+ intelliExtendJson.put("no_area_break", requestJson.getInteger("noAreaBreak"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(intelliExtendJson)) {
|
|
|
+ targetJson.put("intelli_extend", intelliExtendJson);
|
|
|
+ }
|
|
|
}
|
|
|
if (!Check.isNull(targetJson)) {
|
|
|
param.put("target", targetJson);
|
|
@@ -176,7 +204,8 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
|
headers.put("Access-Token", accessToken);
|
|
|
headers.put("Content-Type", " application/json");
|
|
|
- String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_CREATE;
|
|
|
+ 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)) {
|
|
@@ -186,18 +215,10 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
kuaishouTemplateService.getTemplateByAccountId(requestJson.getLong("accountId"), accessToken, 1);
|
|
|
flag = code;
|
|
|
JSONObject data = resultJson.getJSONObject("data");
|
|
|
- requestJson.put("templateId", data.getLong("template_id"));
|
|
|
- requestJson.put("dataStatus", 1);
|
|
|
- } else {
|
|
|
- requestJson.put("dataStatus", 0);
|
|
|
}
|
|
|
- } else {
|
|
|
- requestJson.put("dataStatus", 0);
|
|
|
- message = "返回结果为空";
|
|
|
}
|
|
|
- requestJson.put("message", message);
|
|
|
KuaishouDirectionalPackage kuaishouDirectionalPackage = JSONObject.toJavaObject(requestJson, KuaishouDirectionalPackage.class);
|
|
|
- this.save(kuaishouDirectionalPackage);
|
|
|
+ this.saveOrUpdate(kuaishouDirectionalPackage);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
returnJson.put("code", -1);
|
|
@@ -211,107 +232,148 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result<Object> updateDirectionalPackage(String accessToken, JSONObject requestJson) {
|
|
|
- JSONObject returnJson = new JSONObject();
|
|
|
+ public Result<Object> queryList(KuaishouDirectionalPackage directionalPackage, Integer pageNo, Integer pageSize) {
|
|
|
+ Long total = packageMapper.queryListTotal(directionalPackage);
|
|
|
+ PageHelper.startPage(pageNo, pageSize, false);
|
|
|
+ List<JSONObject> list = packageMapper.queryList(directionalPackage);
|
|
|
+ PageInfo pageInfo = new PageInfo(list);
|
|
|
+ pageInfo.setTotal(total);
|
|
|
+ return Result.ok(pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Object> getRelatedAccountGroup(String id, Integer type, Integer pageNo, Integer pageSize) {
|
|
|
+ PageHelper.startPage(pageNo, pageSize);
|
|
|
+ return Result.ok(new PageInfo(packageMapper.getRelatedAccountGroup(id, type)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Object> pushDirectionalPackage(String id, JSONArray accountIds) {
|
|
|
+ KuaishouDirectionalPackage directionalPackage = packageMapper.selectById(id);
|
|
|
+ if (Check.isNull(directionalPackage)) {
|
|
|
+ return Result.error("未找到定向包");
|
|
|
+ }
|
|
|
+ Thread thread = new Thread() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ executorService = Executors.newFixedThreadPool(3);
|
|
|
+ for (int i = 0; i < accountIds.size(); i++) {
|
|
|
+ Long accountId = accountIds.getLong(i);
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ createDirectionalPackage(directionalPackage, accountId);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ thread.start();
|
|
|
+ return Result.ok("推送成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createDirectionalPackage(KuaishouDirectionalPackage directionalPackage, Long accountId) {
|
|
|
+ CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
|
|
|
String message = "";
|
|
|
- int flag = -1;
|
|
|
try {
|
|
|
JSONObject param = new JSONObject();
|
|
|
- param.put("template_id", requestJson.getLong("templateId"));
|
|
|
- param.put("advertiser_id", requestJson.getLong("accountId"));
|
|
|
- if (!Check.isNull(requestJson.getString("templateName"))) {
|
|
|
- param.put("template_name", requestJson.getString("templateName"));
|
|
|
- }
|
|
|
+ param.put("advertiser_id", accountId);
|
|
|
+ param.put("template_name", directionalPackage.getTemplateName());
|
|
|
JSONObject targetJson = new JSONObject();
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("region"))) {
|
|
|
- targetJson.put("region", requestJson.getJSONArray("region"));
|
|
|
+ if (!Check.isNull(directionalPackage.getRegion())) {
|
|
|
+ targetJson.put("region", directionalPackage.getRegion());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("districtIds"))) {
|
|
|
- targetJson.put("district_ids", requestJson.getJSONArray("districtIds"));
|
|
|
+ if (!Check.isNull(directionalPackage.getDistrictIds())) {
|
|
|
+ targetJson.put("district_ids", directionalPackage.getDistrictIds());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getInteger("userType"))) {
|
|
|
- targetJson.put("user_type", requestJson.getInteger("userType"));
|
|
|
+ if (!Check.isNull(directionalPackage.getUserType())) {
|
|
|
+ targetJson.put("user_type", directionalPackage.getUserType());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("agesRange"))) {
|
|
|
- targetJson.put("ages_range", requestJson.getJSONArray("agesRange"));
|
|
|
+ if (!Check.isNull(directionalPackage.getAgesRange())) {
|
|
|
+ targetJson.put("ages_range", directionalPackage.getAgesRange());
|
|
|
}
|
|
|
|
|
|
- if (!Check.isNull(requestJson.getInteger("min")) && !Check.isNull(requestJson.getInteger("max"))) {
|
|
|
- JSONObject ageJson = new JSONObject();
|
|
|
- ageJson.put("min", requestJson.getInteger("min"));
|
|
|
- ageJson.put("max", requestJson.getInteger("max"));
|
|
|
+ JSONObject ageJson = new JSONObject();
|
|
|
+ if (!Check.isNull(directionalPackage.getMin())) {
|
|
|
+ ageJson.put("min", directionalPackage.getMin());
|
|
|
+ }
|
|
|
+ if (!Check.isNull(directionalPackage.getMax())) {
|
|
|
+ ageJson.put("max", directionalPackage.getMax());
|
|
|
+ }
|
|
|
+ if (!Check.isNull(ageJson)) {
|
|
|
targetJson.put("age", ageJson);
|
|
|
}
|
|
|
-
|
|
|
- if (!Check.isNull(requestJson.getInteger("gender"))) {
|
|
|
- targetJson.put("gender", requestJson.getInteger("gender"));
|
|
|
+ if (!Check.isNull(directionalPackage.getGender())) {
|
|
|
+ targetJson.put("gender", directionalPackage.getGender());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getInteger("platformOs"))) {
|
|
|
- targetJson.put("platform_os", requestJson.getInteger("platformOs"));
|
|
|
+ if (!Check.isNull(directionalPackage.getPlatformOs())) {
|
|
|
+ targetJson.put("platform_os", directionalPackage.getPlatformOs());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getInteger("androidOsv"))) {
|
|
|
- targetJson.put("android_osv", requestJson.getInteger("androidOsv"));
|
|
|
+ if (!Check.isNull(directionalPackage.getAndroidOsv())) {
|
|
|
+ targetJson.put("android_osv", directionalPackage.getAndroidOsv());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getInteger("iosOsv"))) {
|
|
|
- targetJson.put("ios_osv", requestJson.getInteger("iosOsv"));
|
|
|
+ if (!Check.isNull(directionalPackage.getIosOsv())) {
|
|
|
+ targetJson.put("ios_osv", directionalPackage.getIosOsv());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getInteger("network"))) {
|
|
|
- targetJson.put("network", requestJson.getInteger("network"));
|
|
|
+ if (!Check.isNull(directionalPackage.getNetwork())) {
|
|
|
+ targetJson.put("network", directionalPackage.getNetwork());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getInteger("filterConvertedLevel"))) {
|
|
|
- targetJson.put("filter_converted_level", requestJson.getInteger("filterConvertedLevel"));
|
|
|
+ if (!Check.isNull(directionalPackage.getFilterConvertedLevel())) {
|
|
|
+ targetJson.put("filter_converted_level", directionalPackage.getFilterConvertedLevel());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("deviceBrand"))) {
|
|
|
- targetJson.put("device_brand", requestJson.getJSONArray("deviceBrand"));
|
|
|
+ if (!Check.isNull(directionalPackage.getDeviceBrand())) {
|
|
|
+ targetJson.put("device_brand", directionalPackage.getDeviceBrand());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("devicePrice"))) {
|
|
|
- targetJson.put("device_price", requestJson.getJSONArray("devicePrice"));
|
|
|
+ if (!Check.isNull(directionalPackage.getDevicePrice())) {
|
|
|
+ targetJson.put("device_price", directionalPackage.getDevicePrice());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getInteger("businessInterestType"))) {
|
|
|
- targetJson.put("business_interest_type", requestJson.getInteger("businessInterestType"));
|
|
|
+ if (!Check.isNull(directionalPackage.getBusinessInterestType())) {
|
|
|
+ targetJson.put("business_interest_type", directionalPackage.getBusinessInterestType());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("businessInterest"))) {
|
|
|
- targetJson.put("business_interest", requestJson.getJSONArray("businessInterest"));
|
|
|
+ if (!Check.isNull(directionalPackage.getBusinessInterest())) {
|
|
|
+ targetJson.put("business_interest", directionalPackage.getBusinessInterest());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("fansStar"))) {
|
|
|
- targetJson.put("fans_star", requestJson.getJSONArray("fansStar"));
|
|
|
+ if (!Check.isNull(directionalPackage.getFansStar())) {
|
|
|
+ targetJson.put("fans_star", directionalPackage.getFansStar());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("interestVideo"))) {
|
|
|
- targetJson.put("interest_video", requestJson.getJSONArray("interestVideo"));
|
|
|
+ if (!Check.isNull(directionalPackage.getInterestVideo())) {
|
|
|
+ targetJson.put("interest_video", directionalPackage.getInterestVideo());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("appInterest"))) {
|
|
|
- targetJson.put("app_interest", requestJson.getJSONArray("appInterest"));
|
|
|
+ if (!Check.isNull(directionalPackage.getAppInterest())) {
|
|
|
+ targetJson.put("app_interest", directionalPackage.getAppInterest());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("appIds"))) {
|
|
|
- targetJson.put("app_ids", requestJson.getJSONArray("appIds"));
|
|
|
+ if (!Check.isNull(directionalPackage.getAppIds())) {
|
|
|
+ targetJson.put("app_ids", directionalPackage.getAppIds());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("population"))) {
|
|
|
- targetJson.put("population", requestJson.getJSONArray("population"));
|
|
|
+ if (!Check.isNull(directionalPackage.getPopulation())) {
|
|
|
+ targetJson.put("population", directionalPackage.getPopulation());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("paidAudience"))) {
|
|
|
- targetJson.put("paid_audience", requestJson.getJSONArray("paidAudience"));
|
|
|
+ if (!Check.isNull(directionalPackage.getPaidAudience())) {
|
|
|
+ targetJson.put("paid_audience", directionalPackage.getPaidAudience());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
|
|
|
- targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
|
|
|
+ if (!Check.isNull(directionalPackage.getExcludePopulation())) {
|
|
|
+ targetJson.put("exclude_population", directionalPackage.getExcludePopulation());
|
|
|
}
|
|
|
+ JSONObject intelliExtendJson = new JSONObject();
|
|
|
|
|
|
-
|
|
|
- if (!Check.isNull(requestJson.getInteger("isOpen"))) {
|
|
|
- JSONObject intelliExtendJson = new JSONObject();
|
|
|
- intelliExtendJson.put("is_open", requestJson.getInteger("isOpen"));
|
|
|
-
|
|
|
- if (!Check.isNull(requestJson.getInteger("noAgeBreak"))) {
|
|
|
- intelliExtendJson.put("no_age_break", requestJson.getInteger("noAgeBreak"));
|
|
|
- }
|
|
|
- if (!Check.isNull(requestJson.getInteger("noGenderBreak"))) {
|
|
|
- intelliExtendJson.put("no_gender_break", requestJson.getInteger("noGenderBreak"));
|
|
|
- }
|
|
|
- if (!Check.isNull(requestJson.getInteger("noAreaBreak"))) {
|
|
|
- intelliExtendJson.put("no_area_break", requestJson.getInteger("noAreaBreak"));
|
|
|
- }
|
|
|
- if (!Check.isNull(intelliExtendJson)) {
|
|
|
- targetJson.put("intelli_extend", intelliExtendJson);
|
|
|
- }
|
|
|
+ if (!Check.isNull(directionalPackage.getIsOpen())) {
|
|
|
+ intelliExtendJson.put("is_open", directionalPackage.getIsOpen());
|
|
|
+ }
|
|
|
+ if (!Check.isNull(directionalPackage.getNoAgeBreak())) {
|
|
|
+ intelliExtendJson.put("no_age_break", directionalPackage.getNoAgeBreak());
|
|
|
+ }
|
|
|
+ if (!Check.isNull(directionalPackage.getNoGenderBreak())) {
|
|
|
+ intelliExtendJson.put("no_gender_break", directionalPackage.getNoGenderBreak());
|
|
|
+ }
|
|
|
+ if (!Check.isNull(directionalPackage.getNoAreaBreak())) {
|
|
|
+ intelliExtendJson.put("no_area_break", directionalPackage.getNoAreaBreak());
|
|
|
+ }
|
|
|
+ if (!Check.isNull(intelliExtendJson)) {
|
|
|
+ targetJson.put("intelli_extend", intelliExtendJson);
|
|
|
}
|
|
|
if (!Check.isNull(targetJson)) {
|
|
|
param.put("target", targetJson);
|
|
@@ -319,23 +381,23 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
JSONObject behaviorInterest = new JSONObject();
|
|
|
JSONObject behavior = new JSONObject();
|
|
|
JSONObject interest = new JSONObject();
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("keyword"))) {
|
|
|
- behavior.put("keyword", requestJson.getJSONArray("keyword"));
|
|
|
+ if (!Check.isNull(directionalPackage.getKeyword())) {
|
|
|
+ behavior.put("keyword", directionalPackage.getKeyword());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("label"))) {
|
|
|
- behavior.put("label", requestJson.getJSONArray("label"));
|
|
|
+ if (!Check.isNull(directionalPackage.getLabel())) {
|
|
|
+ behavior.put("label", directionalPackage.getLabel());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getInteger("strengthType"))) {
|
|
|
- behavior.put("strength_type", requestJson.getInteger("strengthType"));
|
|
|
+ if (!Check.isNull(directionalPackage.getStrengthType())) {
|
|
|
+ behavior.put("strength_type", directionalPackage.getStrengthType());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getInteger("timeType"))) {
|
|
|
- behavior.put("time_type", requestJson.getInteger("timeType"));
|
|
|
+ if (!Check.isNull(directionalPackage.getTimeType())) {
|
|
|
+ behavior.put("time_type", directionalPackage.getTimeType());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("sceneType"))) {
|
|
|
- behavior.put("scene_type", requestJson.getJSONArray("sceneType"));
|
|
|
+ if (!Check.isNull(directionalPackage.getSceneType())) {
|
|
|
+ behavior.put("scene_type", directionalPackage.getSceneType());
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("interestLabel"))) {
|
|
|
- interest.put("label", requestJson.getJSONArray("interestLabel"));
|
|
|
+ if (!Check.isNull(directionalPackage.getInterestLabel())) {
|
|
|
+ interest.put("label", directionalPackage.getInterestLabel());
|
|
|
}
|
|
|
if (!Check.isNull(behavior)) {
|
|
|
behaviorInterest.put("behavior", behavior);
|
|
@@ -347,62 +409,53 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
param.put("behavior_interest", behaviorInterest);
|
|
|
}
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
|
- headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Access-Token", oauthToken.getAccessToken());
|
|
|
headers.put("Content-Type", " application/json");
|
|
|
- String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_UPDATE;
|
|
|
- log.info("入参:" + param);
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_CREATE;
|
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
if (!Check.isNull(resultJson)) {
|
|
|
Integer code = resultJson.getInteger("code");
|
|
|
message = resultJson.getString("message");
|
|
|
if (code == 0) {
|
|
|
- kuaishouTemplateService.getTemplateByAccountId(requestJson.getLong("accountId"), accessToken, 1);
|
|
|
- flag = code;
|
|
|
+ kuaishouTemplateService.getTemplateByAccountId(accountId, oauthToken.getAccessToken(), 1);
|
|
|
JSONObject data = resultJson.getJSONObject("data");
|
|
|
+ KuaishouDirectionalTemplateRel rel = new KuaishouDirectionalTemplateRel();
|
|
|
+ rel.setDirId(directionalPackage.getId());
|
|
|
+ rel.setRelId(accountId);
|
|
|
+ rel.setRelType("account");
|
|
|
+ rel.setProjectId(directionalPackage.getProjectId());
|
|
|
+ rel.setTemplateId(data.getLong("template_id"));
|
|
|
+ rel.setTemplateName(directionalPackage.getTemplateName());
|
|
|
+ rel.setMessage(message);
|
|
|
+ relService.save(rel);
|
|
|
+ } else {
|
|
|
+ log.error("创建定向包失败," + message);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ message = "创建定向包失败,返回结果为空";
|
|
|
}
|
|
|
- KuaishouDirectionalPackage kuaishouDirectionalPackage = JSONObject.toJavaObject(requestJson, KuaishouDirectionalPackage.class);
|
|
|
- this.saveOrUpdate(kuaishouDirectionalPackage);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- returnJson.put("code", -1);
|
|
|
- returnJson.put("message", e.getMessage());
|
|
|
+ log.error("创建定向包出现异常", e);
|
|
|
}
|
|
|
- if (flag == 0) {
|
|
|
- return Result.ok(message);
|
|
|
- } else {
|
|
|
- return Result.error(message);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result<Object> queryList(KuaishouDirectionalPackage directionalPackage, Integer pageNo, Integer pageSize) {
|
|
|
- Long total = packageMapper.queryListTotal(directionalPackage);
|
|
|
- PageHelper.startPage(pageNo, pageSize, false);
|
|
|
- List<JSONObject> list = packageMapper.queryList(directionalPackage);
|
|
|
- PageInfo pageInfo = new PageInfo(list);
|
|
|
- pageInfo.setTotal(total);
|
|
|
- return Result.ok(pageInfo);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result<Object> getRelatedAccountGroup(Long projectId, Long templateId, Integer type, Integer pageNo, Integer pageSize) {
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result<Object> pushDirectionalPackage(Long accountId, Long templateId, JSONArray ids) {
|
|
|
+ public Result<Object> getHistory(Long projectId, Long templateId, Integer pageNo, Integer pageSize) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result<Object> getHistory(Long projectId, Long templateId, Integer pageNo, Integer pageSize) {
|
|
|
+ public Result<Object> getAccountByProjectId(Long projectId, Integer pageNo, Integer pageSize) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result<Object> getAccountByProjectId(Long projectId, Integer pageNo, Integer pageSize) {
|
|
|
- return null;
|
|
|
+ public Result<Object> delete(Long accountId, Long templateId) {
|
|
|
+ int delete = packageMapper.delete(accountId, templateId);
|
|
|
+ if (delete > 0) {
|
|
|
+ return Result.ok("删除成功");
|
|
|
+ }
|
|
|
+ return Result.error("删除失败");
|
|
|
}
|
|
|
}
|