|
@@ -81,15 +81,15 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
|
|
|
JSONObject data = getNewCampaigns(token.getAccessToken(), copyData);
|
|
|
data.put("copyData", copyData);
|
|
|
//根据被复制的组数据和模板、预算和排期数据调用快手创建组接口
|
|
|
- createCopyUnits(token, data);
|
|
|
+ boolean isSuccess = createCopyUnits(token, data);
|
|
|
//更新成功,修改状态并发送通知
|
|
|
- updateState(copyData.getId(), NoEn.NO2.valueStr(), "复制成功");
|
|
|
- sendNotification(copyData.getOldCampaignName(), copyData.getCreaterId(), NoEn.NO2.valueStr());
|
|
|
+ if (isSuccess) {
|
|
|
+ sendNotification(copyData.getId(), copyData.getOldCampaignName(), copyData.getCreaterId(), NoEn.NO2.valueStr(), "复制成功");
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
log.error("复制广告计划异常", e);
|
|
|
//复制过程中失败,更新状态并发送预警
|
|
|
- updateState(copyData.getId(), NoEn.NO3.valueStr(), e.getMessage());
|
|
|
- sendNotification(copyData.getOldCampaignName(), copyData.getCreaterId(), NoEn.NO3.valueStr());
|
|
|
+ sendNotification(copyData.getId(), copyData.getOldCampaignName(), copyData.getCreaterId(), NoEn.NO3.valueStr(), e.getMessage());
|
|
|
}
|
|
|
|
|
|
|
|
@@ -133,8 +133,7 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
|
|
|
List<KuaiShouGroup> kuaiShouGroups = kuaiShouGroupService.queryUnitInfoByCampaignId(copyData.getAccountId(), campaignId);
|
|
|
if (Check.isNull(kuaiShouGroups)) {
|
|
|
//获取广告组失败,更新状态并发送通知
|
|
|
- updateState(copyData.getId(), NoEn.NO3.valueStr(), "被复制的计划更新广告组失败");
|
|
|
- sendNotification(copyData.getOldCampaignName(), copyData.getCreaterId(), NoEn.NO3.valueStr());
|
|
|
+ sendNotification(copyData.getId(), copyData.getOldCampaignName(), copyData.getCreaterId(), NoEn.NO3.valueStr(), "被复制的计划更新广告组失败");
|
|
|
}
|
|
|
for (KuaiShouGroup kuaiShouGroup : kuaiShouGroups) {
|
|
|
kuaiShouGroup.setTarget(kuaiShouGroupTargetService.queryTargetInfoByunitId(copyData.getAccountId(), kuaiShouGroup.getUnitId()));
|
|
@@ -158,11 +157,13 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
|
|
|
* @throws
|
|
|
* @author ZHAOXA
|
|
|
*/
|
|
|
- private void createCopyUnits(CtopOauthToken token, JSONObject data) throws Exception {
|
|
|
- try {
|
|
|
- JSONArray groups = data.getJSONArray("groups");
|
|
|
- JSONObject copyData = data.getJSONObject("copyData");
|
|
|
- for (int i = 0; i < groups.size(); i++) {
|
|
|
+ private boolean createCopyUnits(CtopOauthToken token, JSONObject data) throws Exception {
|
|
|
+ int count = 0;
|
|
|
+ String msg = "";
|
|
|
+ JSONArray groups = data.getJSONArray("groups");
|
|
|
+ JSONObject copyData = data.getJSONObject("copyData");
|
|
|
+ for (int i = 0; i < groups.size(); i++) {
|
|
|
+ try {
|
|
|
JSONObject group = groups.getJSONObject(i);
|
|
|
JSONObject unitJson = new JSONObject();
|
|
|
unitJson.put("campaign_id", copyData.getLong("newCampaignId"));
|
|
@@ -175,14 +176,17 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
|
|
|
// 资源创作方式
|
|
|
unitJson.put("unit_type", group.getInteger("unitType"));
|
|
|
// 转化目标id
|
|
|
- unitJson.put("convert_id", group.getInteger("convertId"));
|
|
|
-
|
|
|
+ if (!Check.isNull(group.getInteger("convertId"))) {
|
|
|
+ unitJson.put("convert_id", group.getInteger("convertId"));
|
|
|
+ }
|
|
|
// 优先从系统应用商店下载
|
|
|
- unitJson.put("use_app_market", group.getInteger("useAppMarket"));
|
|
|
-
|
|
|
+ if (!Check.isNull(group.getInteger("useAppMarket"))) {
|
|
|
+ unitJson.put("use_app_market", group.getInteger("useAppMarket"));
|
|
|
+ }
|
|
|
// 应用商店列表
|
|
|
- unitJson.put("app_store", group.getJSONArray("appStore"));
|
|
|
-
|
|
|
+ if (!Check.isNull(group.getJSONArray("appStore"))) {
|
|
|
+ unitJson.put("app_store", group.getJSONArray("appStore"));
|
|
|
+ }
|
|
|
//投放开始时间
|
|
|
String beginTime = copyData.getString("beginTime");
|
|
|
if (Check.isNull(beginTime)) {
|
|
@@ -361,43 +365,53 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
|
|
|
unitJson.put("target", targetJson);
|
|
|
}
|
|
|
// 出价
|
|
|
- String bid = copyData.getString("bid");
|
|
|
+ Long bid = copyData.getLong("bid");
|
|
|
if (Check.isNull(bid)) {
|
|
|
- bid = group.getString("bid");
|
|
|
+ bid = group.getLong("bid");
|
|
|
+ }
|
|
|
+ if (!Check.isNull(bid)) {
|
|
|
+ unitJson.put("bid", bid);
|
|
|
}
|
|
|
- unitJson.put("bid", bid);
|
|
|
// 出价类型
|
|
|
- String bidType = copyData.getString("bidType");
|
|
|
+ Integer bidType = copyData.getInteger("bidType");
|
|
|
if (Check.isNull(bidType)) {
|
|
|
- bidType = group.getString("bidType");
|
|
|
+ bidType = group.getInteger("bidType");
|
|
|
+ }
|
|
|
+ if (!Check.isNull(bidType)) {
|
|
|
+ unitJson.put("bid_type", bidType);
|
|
|
}
|
|
|
- unitJson.put("bid_type", bidType);
|
|
|
// 深度转化出价
|
|
|
- String cpaBid = copyData.getString("cpaBid");
|
|
|
+ Long cpaBid = copyData.getLong("cpaBid");
|
|
|
if (Check.isNull(cpaBid)) {
|
|
|
- cpaBid = group.getString("cpaBid");
|
|
|
+ cpaBid = group.getLong("cpaBid");
|
|
|
+ }
|
|
|
+ if (!Check.isNull(cpaBid)) {
|
|
|
+ unitJson.put("cpa_bid", cpaBid);
|
|
|
}
|
|
|
- unitJson.put("cpa_bid", cpaBid);
|
|
|
// 深度转化目标出价
|
|
|
- String deepConversionBid = copyData.getString("deepConversionBid");
|
|
|
+ Long deepConversionBid = copyData.getLong("deepConversionBid");
|
|
|
if (Check.isNull(deepConversionBid)) {
|
|
|
- deepConversionBid = group.getString("deepConversionBid");
|
|
|
+ deepConversionBid = group.getLong("deepConversionBid");
|
|
|
}
|
|
|
if (!Check.isNull(deepConversionBid)) {
|
|
|
unitJson.put("deep_conversion_bid", deepConversionBid);
|
|
|
}
|
|
|
// 深度转化目标
|
|
|
- String deepConversionType = copyData.getString("deepConversionType");
|
|
|
+ Integer deepConversionType = copyData.getInteger("deepConversionType");
|
|
|
if (Check.isNull(deepConversionType)) {
|
|
|
- deepConversionType = group.getString("deepConversionType");
|
|
|
+ deepConversionType = group.getInteger("deepConversionType");
|
|
|
+ }
|
|
|
+ if (!Check.isNull(deepConversionType)) {
|
|
|
+ unitJson.put("deep_conversion_type", deepConversionType);
|
|
|
}
|
|
|
- unitJson.put("deep_conversion_type", deepConversionType);
|
|
|
// 优化目标
|
|
|
- String ocpxActionType = copyData.getString("ocpxActionType");
|
|
|
+ Integer ocpxActionType = copyData.getInteger("ocpxActionType");
|
|
|
if (Check.isNull(ocpxActionType)) {
|
|
|
- ocpxActionType = group.getString("ocpxActionType");
|
|
|
+ ocpxActionType = group.getInteger("ocpxActionType");
|
|
|
+ }
|
|
|
+ if (!Check.isNull(ocpxActionType)) {
|
|
|
+ unitJson.put("ocpx_action_type", ocpxActionType);
|
|
|
}
|
|
|
- unitJson.put("ocpx_action_type", ocpxActionType);
|
|
|
|
|
|
//快手广告组名
|
|
|
String unitName = group.getString("unitName");
|
|
@@ -424,23 +438,30 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
|
|
|
batchService.copyCreative(token.getAccountId(), unitId, group.getLong("unitId"), null);
|
|
|
} catch (Exception e) {
|
|
|
log.error("复制创建广告创意异常", e);
|
|
|
- updateState(copyData.getLong("id"), NoEn.NO3.valueStr(), "复制创建广告创意异常");
|
|
|
- sendNotification(copyData.getString("oldCampaignName"), copyData.getString("createrId"), NoEn.NO3.valueStr());
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
thread.start();
|
|
|
+ } else {
|
|
|
+ count++;
|
|
|
+ msg = (String) returnUnitMap.get("message");
|
|
|
}
|
|
|
} else {
|
|
|
- updateState(copyData.getLong("id"), NoEn.NO3.valueStr(), (String) returnUnitMap.get("message"));
|
|
|
- sendNotification(copyData.getString("oldCampaignName"), copyData.getString("createrId"), NoEn.NO3.valueStr());
|
|
|
+ count++;
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ count++;
|
|
|
+ log.error("复制过程调用快手接口异常", e);
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("复制过程调用快手接口异常", e);
|
|
|
- throw new Exception("复制过程调用快手接口异常");
|
|
|
}
|
|
|
+ //全部失败
|
|
|
|
|
|
+ if (count == 0) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ sendNotification(copyData.getLong("id"), copyData.getString("oldCampaignName"), copyData.getString("createrId"), NoEn.NO3.valueStr(), msg);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -464,24 +485,13 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
|
|
|
* @throws
|
|
|
* @author ZHAOXA
|
|
|
*/
|
|
|
- private void sendNotification(String name, String userId, String state) {
|
|
|
- String msg = messageTemplate.getCopyCampaignMessage(name, state);
|
|
|
- sendMessageService.sendMessage(userId, msg);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 更新预复制数据状态
|
|
|
- *
|
|
|
- * @param
|
|
|
- * @return void
|
|
|
- * @throws
|
|
|
- * @author ZHAOXA
|
|
|
- */
|
|
|
- private void updateState(Long id, String state, String StateDetail) {
|
|
|
+ private void sendNotification(Long id, String name, String userId, String state, String StateDetail) {
|
|
|
KuaishouCampaignCopyData copyData = new KuaishouCampaignCopyData();
|
|
|
copyData.setId(id);
|
|
|
copyData.setState(state);
|
|
|
copyData.setStateDetail(StateDetail);
|
|
|
this.updateById(copyData);
|
|
|
+ String msg = messageTemplate.getCopyCampaignMessage(name, state);
|
|
|
+ sendMessageService.sendMessage(userId, msg);
|
|
|
}
|
|
|
}
|