|
@@ -12,6 +12,10 @@ import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouDirectionalPackageMapper;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouDirectionalTemplateRelMapper;
|
|
|
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.entity.KuaiShouGroup;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouTemplateMapper;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouTemplateService;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -21,6 +25,7 @@ import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -51,6 +56,12 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
private IKuaishouDirectionalTemplateRelService relService;
|
|
|
@Autowired
|
|
|
private ICtopOauthTokenService oauthTokenService;
|
|
|
+ @Autowired
|
|
|
+ private KuaishouTemplateMapper templateMapper;
|
|
|
+ @Autowired
|
|
|
+ private IKuaiShouUpdateService updateService;
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouGroupMapper groupMapper;
|
|
|
|
|
|
static ExecutorService executorService = null;
|
|
|
|
|
@@ -74,7 +85,7 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public Result<Object> updateDirectionalPackage(JSONObject requestJson) {
|
|
|
+ public Result<Object> updateDirectionalPackage(JSONObject requestJson) throws InterruptedException {
|
|
|
KuaishouDirectionalPackage entity = packageMapper.selectById(requestJson.getString("id"));
|
|
|
if (Check.isNull(entity)) {
|
|
|
return Result.error("未获取到定向包");
|
|
@@ -87,49 +98,31 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
//获取本项目绑定该定向的账户
|
|
|
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();
|
|
|
+ for (JSONObject account : accounts) {
|
|
|
+ updateAccountsDirectionalPackage(requestJson, account);
|
|
|
+ }
|
|
|
}
|
|
|
+ Thread.sleep(300);
|
|
|
//获取本项目绑定该定向的广告组
|
|
|
- List<JSONObject> unitIds = relMapper.queryRelId(requestJson.getLong("projectId"), requestJson.getString("id"), "unit");
|
|
|
- if (!Check.isNull(unitIds)) {
|
|
|
+ List<JSONObject> units = relMapper.queryRelId(requestJson.getLong("projectId"), requestJson.getString("id"), "unit");
|
|
|
+ if (!Check.isNull(units)) {
|
|
|
Thread thread = new Thread() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
executorService = Executors.newFixedThreadPool(3);
|
|
|
- unitIds.forEach(unitId -> {
|
|
|
+ units.forEach(unit -> {
|
|
|
executorService.submit(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
try {
|
|
|
- //TODO
|
|
|
- System.out.println("修改广告组定向");
|
|
|
- // updateAccountsDirectionalPackage(requestJson, accountId);
|
|
|
+ updateUnitsDirectionalPackage(requestJson, unit);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
- log.info("快手物料数据同步完成");
|
|
|
+ log.info("修改广告组定向完成");
|
|
|
}
|
|
|
};
|
|
|
thread.start();
|
|
@@ -137,6 +130,218 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
return Result.ok("该项目下定向包已做同步修改");
|
|
|
}
|
|
|
|
|
|
+ private void updateUnitsDirectionalPackage(JSONObject requestJson, JSONObject unit) {
|
|
|
+ try {
|
|
|
+ Long unitId = unit.getLong("rel_id");
|
|
|
+ QueryWrapper<KuaiShouGroup> queryWrapper = new QueryWrapper();
|
|
|
+ queryWrapper.eq("unit_id", unitId);
|
|
|
+ queryWrapper.last("limit 1");
|
|
|
+ KuaiShouGroup kuaiShouGroup = groupMapper.selectOne(queryWrapper);
|
|
|
+ if (Check.isNull(kuaiShouGroup)) {
|
|
|
+ throw new Exception("未获取到组信息");
|
|
|
+ }
|
|
|
+ CtopOauthToken token = oauthTokenService.getTokenByAccountId(kuaiShouGroup.getAccountId());
|
|
|
+ String sceneId = kuaiShouGroup.getSceneId();
|
|
|
+ if (Check.isNull(sceneId)) {
|
|
|
+ throw new Exception("未获取资源位置");
|
|
|
+ }
|
|
|
+ Integer scene = (Integer) JSONArray.parseArray(sceneId).get(0);
|
|
|
+ JSONObject unitJson = new JSONObject();
|
|
|
+ unitJson.put("advertiser_id", token.getAccountId());
|
|
|
+ unitJson.put("unit_id", unitId);
|
|
|
+ // 广告组名称
|
|
|
+ unitJson.put("unit_name", kuaiShouGroup.getUnitName());
|
|
|
+ // 资源位置
|
|
|
+ unitJson.put("scene_id", JSONArray.parseArray(sceneId));
|
|
|
+ //投放开始时间
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
+ boolean beginTimeBoolean = DateUtils.compare(kuaiShouGroup.getBeginTime(), nowDate);
|
|
|
+ if (beginTimeBoolean) {
|
|
|
+ unitJson.put("begin_time", nowDate);
|
|
|
+ } else {
|
|
|
+ unitJson.put("begin_time", kuaiShouGroup.getBeginTime());
|
|
|
+ }
|
|
|
+ // 创意展现方式
|
|
|
+ unitJson.put("show_mode", kuaiShouGroup.getShowMode());
|
|
|
+ //投放方式
|
|
|
+ unitJson.put("speed", kuaiShouGroup.getSpeed());
|
|
|
+
|
|
|
+ // -----------------修改组非必填参数-----------
|
|
|
+ // 出价
|
|
|
+ if (!Check.isNull(kuaiShouGroup.getBid())) {
|
|
|
+ unitJson.put("bid", kuaiShouGroup.getBid());
|
|
|
+ }
|
|
|
+ // 深度转化出价
|
|
|
+ if (!Check.isNull(kuaiShouGroup.getCpaBid())) {
|
|
|
+ unitJson.put("cpa_bid", kuaiShouGroup.getCpaBid());
|
|
|
+ }
|
|
|
+ // 深度转化目标出价
|
|
|
+ if (!Check.isNull(kuaiShouGroup.getDeepConversionBid())) {
|
|
|
+ unitJson.put("deep_conversion_bid", kuaiShouGroup.getDeepConversionBid());
|
|
|
+ }
|
|
|
+ // 投放结束时间
|
|
|
+ if (!Check.isNull(kuaiShouGroup.getEndTime())) {
|
|
|
+ unitJson.put("end_time", kuaiShouGroup.getEndTime());
|
|
|
+ }
|
|
|
+ // 投放时间段
|
|
|
+ if (!Check.isNull(kuaiShouGroup.getScheduleTime())) {
|
|
|
+ unitJson.put("schedule_time", kuaiShouGroup.getScheduleTime());
|
|
|
+ }
|
|
|
+ // 广告组单日预算
|
|
|
+ if (!Check.isNull(kuaiShouGroup.getDayBudget())) {
|
|
|
+ unitJson.put("day_budget", kuaiShouGroup.getDayBudget());
|
|
|
+ }
|
|
|
+ // url类型
|
|
|
+ if (!Check.isNull(kuaiShouGroup.getUrlType())) {
|
|
|
+ unitJson.put("url_type", kuaiShouGroup.getUrlType());
|
|
|
+ }
|
|
|
+ // url
|
|
|
+ if (!Check.isNull(kuaiShouGroup.getUrl())) {
|
|
|
+ unitJson.put("url", kuaiShouGroup.getUrl());
|
|
|
+ }
|
|
|
+ // appId
|
|
|
+ if (!Check.isNull(kuaiShouGroup.getAppId())) {
|
|
|
+ unitJson.put("app_id", kuaiShouGroup.getAppId());
|
|
|
+ }
|
|
|
+ // 优先从系统应用商店下载
|
|
|
+ if (!Check.isNull(kuaiShouGroup.getUseAppMarket())) {
|
|
|
+ unitJson.put("use_app_market", kuaiShouGroup.getUseAppMarket());
|
|
|
+ }
|
|
|
+ // 应用商店列表
|
|
|
+ if (!Check.isNull(kuaiShouGroup.getAppStore())) {
|
|
|
+ unitJson.put("app_store", JSONArray.parseArray(kuaiShouGroup.getAppStore()));
|
|
|
+ }
|
|
|
+ // 转化目标
|
|
|
+ if (!Check.isNull(kuaiShouGroup.getConvertId())) {
|
|
|
+ unitJson.put("convert_id", kuaiShouGroup.getConvertId());
|
|
|
+ }
|
|
|
+ // -----------------用户定向-----------
|
|
|
+ JSONObject targetJson = new JSONObject();
|
|
|
+
|
|
|
+ // 地域
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("region"))) {
|
|
|
+ targetJson.put("region", requestJson.getJSONArray("region"));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 自定义年龄段
|
|
|
+
|
|
|
+ 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"));
|
|
|
+ targetJson.put("age", ageJson);
|
|
|
+ }
|
|
|
+ // 固定年龄段
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("agesRange"))) {
|
|
|
+ targetJson.put("ages_range", requestJson.getJSONArray("agesRange"));
|
|
|
+ }
|
|
|
+ // 性别
|
|
|
+ if (!Check.isNull(requestJson.getInteger("gender"))) {
|
|
|
+ targetJson.put("gender", requestJson.getInteger("gender"));
|
|
|
+ }
|
|
|
+ //操作系统
|
|
|
+ if (!Check.isNull(requestJson.getInteger("platformOs"))) {
|
|
|
+ targetJson.put("platform_os", requestJson.getInteger("platformOs"));
|
|
|
+ }
|
|
|
+ //Android版本
|
|
|
+ if (!Check.isNull(requestJson.getInteger("androidOsv"))) {
|
|
|
+ targetJson.put("android_osv", requestJson.getInteger("androidOsv"));
|
|
|
+ }
|
|
|
+ // iOS版本
|
|
|
+ if (!Check.isNull(requestJson.getInteger("iosOsv"))) {
|
|
|
+ targetJson.put("ios_osv", requestJson.getInteger("iosOsv"));
|
|
|
+ }
|
|
|
+ //网络环境
|
|
|
+ if (!Check.isNull(requestJson.getInteger("network"))) {
|
|
|
+ targetJson.put("network", requestJson.getInteger("network"));
|
|
|
+ }
|
|
|
+ // 设备品牌
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("deviceBrand"))) {
|
|
|
+ targetJson.put("device_brand", requestJson.getJSONArray("deviceBrand"));
|
|
|
+ }
|
|
|
+ // 设备价格
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("devicePrice"))) {
|
|
|
+ targetJson.put("device_price", requestJson.getJSONArray("devicePrice"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("appInterest"))) {
|
|
|
+ targetJson.put("app_interest", requestJson.getJSONArray("appInterest"));
|
|
|
+ }
|
|
|
+ // APP行为-按APP名称
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("appIds"))) {
|
|
|
+ targetJson.put("app_ids", requestJson.getJSONArray("appIds"));
|
|
|
+ }
|
|
|
+ // 人群包
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("population"))) {
|
|
|
+ targetJson.put("population", requestJson.getJSONArray("population"));
|
|
|
+ }
|
|
|
+ // 人群包排除
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
|
|
|
+ targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("thirdPlatformCode"))) {
|
|
|
+ targetJson.put("third_platform_code", requestJson.getJSONArray("thirdPlatformCode"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (scene != 5) {
|
|
|
+ if (!Check.isNull(requestJson.getInteger("filterConvertedLevel"))) {
|
|
|
+ targetJson.put("filter_converted_level", requestJson.getInteger("filterConvertedLevel"));
|
|
|
+ }
|
|
|
+ //商业兴趣类型
|
|
|
+ if (!Check.isNull(requestJson.getInteger("businessInterestType"))) {
|
|
|
+ targetJson.put("business_interest_type", requestJson.getInteger("businessInterestType"));
|
|
|
+ }
|
|
|
+ // 商业兴趣
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("businessInterest"))) {
|
|
|
+ targetJson.put("business_interest", requestJson.getJSONArray("businessInterest"));
|
|
|
+ }
|
|
|
+ //网红粉丝
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("fansStar"))) {
|
|
|
+ targetJson.put("fans_star", requestJson.getJSONArray("fansStar"));
|
|
|
+ }
|
|
|
+ //兴趣视频用户
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("interestVideo"))) {
|
|
|
+ targetJson.put("interest_video", requestJson.getJSONArray("interestVideo"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (scene != 5) {
|
|
|
+ JSONObject intelliExtendJson = new JSONObject();
|
|
|
+ // 开启智能扩量
|
|
|
+ if (!Check.isNull(requestJson.getInteger("isOpen"))) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ unitJson.put("target", targetJson);
|
|
|
+ JSONObject jsonObject = updateService.updateUnit(token.getAccessToken(), unitJson);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("修改广告组定向异常", e);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新帐户定向包
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return void
|
|
|
+ * @throws
|
|
|
+ * @author ZHAOXA
|
|
|
+ */
|
|
|
private void updateAccountsDirectionalPackage(JSONObject requestJson, JSONObject accounEntity) {
|
|
|
Long accountId = accounEntity.getLong("rel_id");
|
|
|
CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
|
|
@@ -298,9 +503,16 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
}
|
|
|
|
|
|
@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)));
|
|
|
+ public Result<Object> getRelatedAccountGroup(String id, Integer type,Long accountId, Integer pageNo, Integer pageSize) {
|
|
|
+ PageInfo pageInfo = null;
|
|
|
+ if (1 == type) {
|
|
|
+ PageHelper.startPage(pageNo, pageSize);
|
|
|
+ pageInfo = new PageInfo(packageMapper.getRelatedAccount(id));
|
|
|
+ } else {
|
|
|
+ PageHelper.startPage(pageNo, pageSize);
|
|
|
+ pageInfo = new PageInfo(packageMapper.getRelatedGroup(id,accountId));
|
|
|
+ }
|
|
|
+ return Result.ok(pageInfo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -494,7 +706,7 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public Result<Object> updatePopulation(JSONObject requestJson) {
|
|
|
+ public Result<Object> editPopulation(JSONObject requestJson) {
|
|
|
Long accountId = requestJson.getLong("accountId");
|
|
|
String message = "";
|
|
|
KuaishouDirectionalTemplateRel rel = new KuaishouDirectionalTemplateRel();
|
|
@@ -538,6 +750,10 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
kuaishouTemplateService.getTemplateByAccountId(requestJson.getLong("accountId"), oauthToken.getAccessToken(), 1);
|
|
|
JSONObject data = resultJson.getJSONObject("data");
|
|
|
relService.update(rel, queryWrapper);
|
|
|
+ List<JSONObject> units = relMapper.queryUnitIdByAccountId(requestJson.getString("id"), requestJson.getLong("accountId"));
|
|
|
+ for (JSONObject unit : units) {
|
|
|
+ updateUnitsDirectionalPackage(requestJson, unit);
|
|
|
+ }
|
|
|
return Result.ok("修改成功");
|
|
|
} else {
|
|
|
return Result.error("修改失败," + message);
|
|
@@ -558,4 +774,24 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
|
|
|
return Result.ok(new PageInfo<>(list));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void createUnitAndTemplate(JSONObject request) throws Exception {
|
|
|
+ JSONObject target = templateMapper.queryByTemplateId(request.getLong("templateId"));
|
|
|
+ if (Check.isNull(target)) {
|
|
|
+ throw new Exception("添加广告组和定向模板绑定关系失败");
|
|
|
+ }
|
|
|
+ KuaishouDirectionalTemplateRel relEntity = new KuaishouDirectionalTemplateRel();
|
|
|
+ relEntity.setDirId(target.getString("dir_id"));
|
|
|
+ relEntity.setProjectId(target.getLong("project_id"));
|
|
|
+ relEntity.setTemplateId(request.getLong("templateId"));
|
|
|
+ relEntity.setTemplateName(target.getString("template_name"));
|
|
|
+ relEntity.setDataStatus(1);
|
|
|
+ relEntity.setRelId(request.getLong("unitId"));
|
|
|
+ relEntity.setRelType("unit");
|
|
|
+ relEntity.setExcludePopulation(request.getString("excludePopulation"));
|
|
|
+ relEntity.setPopulation(request.getString("population"));
|
|
|
+ relEntity.setPaidAudience(request.getString("paidAudience"));
|
|
|
+ relService.save(relEntity);
|
|
|
+ }
|
|
|
+
|
|
|
}
|