|
@@ -13,7 +13,6 @@ import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouDirectionalTemplateRelMapp
|
|
|
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.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -28,6 +27,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;
|
|
|
|
|
|
/**
|
|
|
* 自动投放-定向包详情
|
|
@@ -51,6 +52,8 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
@Autowired
|
|
|
private ICtopOauthTokenService oauthTokenService;
|
|
|
|
|
|
+ static ExecutorService executorService = null;
|
|
|
+
|
|
|
@Override
|
|
|
public Result<Object> createDirectionalPackage(JSONObject requestJson) {
|
|
|
KuaishouDirectionalPackage entity = packageMapper.queryEntity(requestJson);
|
|
@@ -58,7 +61,9 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
return Result.error("该账户下定向包名已存在");
|
|
|
}
|
|
|
KuaishouDirectionalPackage kuaishouDirectionalPackage = JSONObject.toJavaObject(requestJson, KuaishouDirectionalPackage.class);
|
|
|
- kuaishouDirectionalPackage.setKeyword(JSONObject.toJSONString(requestJson.getJSONArray("keyword")));
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("keyword"))) {
|
|
|
+ kuaishouDirectionalPackage.setKeyword(JSONObject.toJSONString(requestJson.getJSONArray("keyword")));
|
|
|
+ }
|
|
|
kuaishouDirectionalPackage.setDataStatus(1);
|
|
|
boolean save = this.save(kuaishouDirectionalPackage);
|
|
|
if (save) {
|
|
@@ -69,14 +74,76 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public Result<Object> updateDirectionalPackage(String accessToken, JSONObject requestJson) {
|
|
|
- JSONObject returnJson = new JSONObject();
|
|
|
- String message = "";
|
|
|
- int flag = -1;
|
|
|
+ public Result<Object> updateDirectionalPackage(JSONObject requestJson) {
|
|
|
+ KuaishouDirectionalPackage entity = packageMapper.selectById(requestJson.getString("id"));
|
|
|
+ if (Check.isNull(entity)) {
|
|
|
+ return Result.error("未获取到定向包");
|
|
|
+ }
|
|
|
+ KuaishouDirectionalPackage kuaishouDirectionalPackage = JSONObject.toJavaObject(requestJson, KuaishouDirectionalPackage.class);
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("keyword"))) {
|
|
|
+ kuaishouDirectionalPackage.setKeyword(JSONObject.toJSONString(requestJson.getJSONArray("keyword")));
|
|
|
+ }
|
|
|
+ this.saveOrUpdate(kuaishouDirectionalPackage);
|
|
|
+ //获取本项目绑定该定向的账户
|
|
|
+ List<JSONObject> accounts = relMapper.queryRelId(requestJson.getLong("projectId"), requestJson.getString("id"), "account");
|
|
|
+ if (!Check.isNull(accounts)) {
|
|
|
+ Thread thread = new Thread() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ executorService = Executors.newFixedThreadPool(3);
|
|
|
+ accounts.forEach(accountEntity -> {
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ updateAccountsDirectionalPackage(requestJson, accountEntity);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ log.info("快手物料数据同步完成");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ thread.start();
|
|
|
+ }
|
|
|
+ //获取本项目绑定该定向的广告组
|
|
|
+ List<JSONObject> unitIds = relMapper.queryRelId(requestJson.getLong("projectId"), requestJson.getString("id"), "unit");
|
|
|
+ if (!Check.isNull(unitIds)) {
|
|
|
+ Thread thread = new Thread() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ executorService = Executors.newFixedThreadPool(3);
|
|
|
+ unitIds.forEach(unitId -> {
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ //TODO
|
|
|
+ System.out.println("修改广告组定向");
|
|
|
+ // updateAccountsDirectionalPackage(requestJson, accountId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ log.info("快手物料数据同步完成");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ thread.start();
|
|
|
+ }
|
|
|
+ return Result.ok("该项目下定向包已做同步修改");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateAccountsDirectionalPackage(JSONObject requestJson, JSONObject accounEntity) {
|
|
|
+ Long accountId = accounEntity.getLong("rel_id");
|
|
|
+ CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
|
|
|
try {
|
|
|
JSONObject param = new JSONObject();
|
|
|
- param.put("template_id", requestJson.getLong("templateId"));
|
|
|
- param.put("advertiser_id", requestJson.getLong("accountId"));
|
|
|
+ param.put("template_id", accounEntity.getLong("template_id"));
|
|
|
+ param.put("advertiser_id", accountId);
|
|
|
if (!Check.isNull(requestJson.getString("templateName"))) {
|
|
|
param.put("template_name", requestJson.getString("templateName"));
|
|
|
}
|
|
@@ -152,8 +219,6 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
|
|
|
targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
if (!Check.isNull(requestJson.getInteger("isOpen"))) {
|
|
|
JSONObject intelliExtendJson = new JSONObject();
|
|
|
intelliExtendJson.put("is_open", requestJson.getInteger("isOpen"));
|
|
@@ -205,35 +270,23 @@ 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 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;
|
|
|
- JSONObject data = resultJson.getJSONObject("data");
|
|
|
+ kuaishouTemplateService.getTemplateByAccountId(accountId, oauthToken.getAccessToken(), 1);
|
|
|
}
|
|
|
}
|
|
|
- KuaishouDirectionalPackage kuaishouDirectionalPackage = JSONObject.toJavaObject(requestJson, KuaishouDirectionalPackage.class);
|
|
|
- this.saveOrUpdate(kuaishouDirectionalPackage);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- returnJson.put("code", -1);
|
|
|
- returnJson.put("message", e.getMessage());
|
|
|
- }
|
|
|
- if (flag == 0) {
|
|
|
- return Result.ok(message);
|
|
|
- } else {
|
|
|
- return Result.error(message);
|
|
|
+ log.error("修改账户定向包异常,账户Id:{}", accountId, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public Result<Object> queryList(KuaishouDirectionalPackage directionalPackage, Integer pageNo, Integer pageSize) {
|
|
|
Long total = packageMapper.queryListTotal(directionalPackage);
|