|
|
@@ -42,9 +42,12 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
|
|
|
ReportsAdPushMapper reportsAdPushMapper;
|
|
|
public static final String ERROR_HOOK_URL="https://open.feishu.cn/open-apis/bot/v2/hook/a0fcfb57-c053-47bd-b1e7-b826f44841e4";
|
|
|
|
|
|
+ public static final String FEISHU_TEMPLATE_ID="AAq2UGaOU2L1l";
|
|
|
+ public static final String FEISHU_TEMPLATE_VERSION="1.0.4";
|
|
|
+
|
|
|
@Override
|
|
|
public void test() {
|
|
|
- run(15L);
|
|
|
+ run(30021L);
|
|
|
};
|
|
|
|
|
|
@Override
|
|
|
@@ -140,6 +143,8 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
|
|
|
Long startDateLong = Long.parseLong(startDate.replaceAll("-", ""));
|
|
|
requestParams.put("startDate", startDateLong);
|
|
|
requestParams.put("endDate", startDateLong);
|
|
|
+ }else {
|
|
|
+ FeishuRobotUtil.sendTextToWebhook("智投助手任务失败:判断条件配置错误,策略ID: "+policyId, ERROR_HOOK_URL);
|
|
|
}
|
|
|
}else {
|
|
|
if (taskTimeType == 11){
|
|
|
@@ -152,6 +157,8 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
|
|
|
int H = lastHour.getHour(); // 0-23,不补零
|
|
|
requestParams.put("date", date);
|
|
|
requestParams.put("hour", H);
|
|
|
+ }else {
|
|
|
+ FeishuRobotUtil.sendTextToWebhook("智投助手任务失败:判断条件配置错误,策略ID: "+policyId, ERROR_HOOK_URL);
|
|
|
}
|
|
|
}
|
|
|
for (int index = 0; index < policy.getTargetResIds().size(); ) {
|
|
|
@@ -334,16 +341,42 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
|
|
|
continue;
|
|
|
}
|
|
|
//飞书通知所有的一起发送,但是记录可以分开记录
|
|
|
- StringBuffer feishuMessageTextSb = new StringBuffer();
|
|
|
- feishuMessageTextSb.append("智投助手触发预警\n");
|
|
|
- feishuMessageTextSb.append("触发策略名称:").append(policy.getName()).append("\n");
|
|
|
- feishuMessageTextSb.append("触发预警广告账号:\n");
|
|
|
- for (String executeTarget : executeTargetList){
|
|
|
- feishuMessageTextSb.append(executeTarget+"\n");
|
|
|
+
|
|
|
+ JSONObject fsTemplateMessage = new JSONObject();
|
|
|
+ List<String> businessLineName = ztPolicyConfigMapper.businessLineName(policy.getBusinessLine());
|
|
|
+ fsTemplateMessage.put("businessLineName", String.join(",", businessLineName));
|
|
|
+ String targetRangeText = "巨量的";
|
|
|
+ if (policy.getManagedDimension() == 1){
|
|
|
+ targetRangeText += "广告账号";
|
|
|
+ }else if (policy.getManagedDimension() == 2){
|
|
|
+ targetRangeText += "广告项目";
|
|
|
+ }else if (policy.getManagedDimension() == 3){
|
|
|
+ targetRangeText += "广告计划";
|
|
|
}
|
|
|
- String fsMessage = feishuMessageTextSb.toString();
|
|
|
- Integer fsSendType = action.getActionRuleJsonObject().getInteger("fsSendType");//1飞书应用单发 2群机器人
|
|
|
+ fsTemplateMessage.put("targetRangeText", targetRangeText);
|
|
|
+ fsTemplateMessage.put("targetCount", executeTargetList.size());
|
|
|
+ List<String> cText = policy.getConditions().stream().map(ZtPolicyCondition::getDescriptionZh).collect(Collectors.toList());
|
|
|
+ fsTemplateMessage.put("conditions", String.join(",", cText));
|
|
|
+ List<JSONObject> fsExecuteTargetList = new ArrayList<>();
|
|
|
+ //最多发送前一百条
|
|
|
+ List<String> subTargetIds = executeTargetList.subList(0, Math.min(99, executeTargetList.size()));
|
|
|
+ if (policy.getManagedDimension() == 1){
|
|
|
+ fsExecuteTargetList = ztPolicyConfigMapper.advertiserTargetNameInfo(subTargetIds);
|
|
|
+ }else if (policy.getManagedDimension() == 2){
|
|
|
+ fsExecuteTargetList = ztPolicyConfigMapper.projectTargetNameInfo(subTargetIds);
|
|
|
+ }else if (policy.getManagedDimension() == 3){
|
|
|
+ fsExecuteTargetList = ztPolicyConfigMapper.promotionTargetNameInfo(subTargetIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ fsTemplateMessage.put("executeTargetList", fsExecuteTargetList);
|
|
|
+ fsTemplateMessage.put("policyName", policy.getName());
|
|
|
+ fsTemplateMessage.put("dataDate", DateUtils.getNowDate("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ //todo 这个上线时候要换成线上的!!
|
|
|
+ fsTemplateMessage.put("runActionLogUrl", "http://test.deepthink.artlinkworld.cn/authorization/assistant/triggerRecord?runId="+runId);
|
|
|
+// fsTemplateMessage.put("runActionLogUrl", "https://deepthink.artlinkworld.cn/authorization/assistant/triggerRecord?runId="+runId);
|
|
|
|
|
|
+
|
|
|
+ Integer fsSendType = action.getActionRuleJsonObject().getInteger("fsSendType");//1飞书应用单发 2群机器人
|
|
|
recordOperation(policyId, "0", action.getId(), operateFreqCircle);//频控记录
|
|
|
if (fsSendType == 1){//单发,发给策略的创建人
|
|
|
Long userId = policy.getCreateUserId();
|
|
|
@@ -361,7 +394,12 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
|
|
|
if (!phonenumbers.isEmpty()){
|
|
|
Map<String, String> phoneUseridMap = FeishuRobotUtil.getFsUserIds(FeishuRobotUtil.getFsZtTenantToken(), phonenumbers);
|
|
|
if (phoneUseridMap != null) {
|
|
|
- FeishuRobotUtil.sendTextToDt(fsMessage, new ArrayList<>(phoneUseridMap.values()));
|
|
|
+ String token = FeishuRobotUtil.getFsZtTenantToken();
|
|
|
+ for (String fsUserId: phoneUseridMap.values()){
|
|
|
+ FeishuRobotUtil.sendTemplateMessageToFeishuUser(FEISHU_TEMPLATE_ID, FEISHU_TEMPLATE_VERSION,
|
|
|
+ token, fsTemplateMessage, fsUserId
|
|
|
+ );
|
|
|
+ }
|
|
|
recordActionSuccess(actionLog);
|
|
|
}else {
|
|
|
recordActionError(actionLog, "未找到飞书用户ID信息");
|
|
|
@@ -376,14 +414,13 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
|
|
|
}
|
|
|
recordActionError(actionLog, message);
|
|
|
}
|
|
|
- // 整理这里可能遇到的错误点,写入action_log
|
|
|
|
|
|
}else {
|
|
|
// 频次、时间段拦截, 频次拦截key: policyId_targetId
|
|
|
List<String> fsHookUrls = action.getActionRuleJsonObject().getJSONArray("fsHookUrls").toJavaList(String.class);
|
|
|
for (String hookUrl : fsHookUrls){
|
|
|
try {
|
|
|
- FeishuRobotUtil.sendTextToWebhook(fsMessage, hookUrl);
|
|
|
+ FeishuRobotUtil.sendTemplateMessageToFeishuWebhook(FEISHU_TEMPLATE_ID, FEISHU_TEMPLATE_VERSION, fsTemplateMessage, hookUrl);
|
|
|
recordActionSuccess(actionLog);
|
|
|
}catch (Exception e){
|
|
|
String message = e.getMessage();
|
|
|
@@ -548,7 +585,7 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
|
|
|
ZtPolicy policy = null;
|
|
|
if (policyId != null){
|
|
|
policy = ztPolicyConfigMapper.getPolicyDetail(policyId);
|
|
|
- if (policy.getManagedDimension()==1 && policy.getTargetScope()==1){
|
|
|
+ if (policy.getTargetScope()==1){
|
|
|
List<ZtPolicyTargetFilter> filterList = ztPolicyConfigMapper.getTargetFilters(policyId);
|
|
|
Map<Integer, List<ZtPolicyTargetFilter>> scopeFilterMap =
|
|
|
filterList.stream().collect(Collectors.groupingBy(ZtPolicyTargetFilter::getFilterKey));
|
|
|
@@ -558,8 +595,7 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
|
|
|
if (key == 1){
|
|
|
policy.setAppId(value.stream().map(ZtPolicyTargetFilter::getFilterValue).collect(Collectors.toList()));
|
|
|
}else if (key == 2){
|
|
|
- Integer businessLine = Integer.parseInt(value.get(0).getFilterValue());
|
|
|
- policy.setBusinessLine(businessLine);
|
|
|
+ policy.setBusinessLine(value.stream().map(f -> Integer.valueOf(f.getFilterValue())).collect(Collectors.toList()));
|
|
|
}else if (key == 3){
|
|
|
policy.setBusinessMethod(value.stream().map(ZtPolicyTargetFilter::getFilterValue).collect(Collectors.toList()));
|
|
|
}else if (key == 4){
|
|
|
@@ -575,9 +611,33 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- List<String> resIds = ztPolicyConfigMapper.advFilterList(policy.getAppId(), policy.getBusinessLine(),
|
|
|
- policy.getBusinessMethod(), policy.getOptimizerId(), policy.getDeptId(), policy.getMovieId());
|
|
|
- policy.setTargetResIds(resIds);
|
|
|
+ Map<String, String> targetFromAdvertiserId = new HashMap<>();
|
|
|
+ List<String> rList = new ArrayList<>();
|
|
|
+ List<JSONObject> resIds = Collections.emptyList();
|
|
|
+ if (policy.getManagedDimension() == 1){
|
|
|
+ resIds = ztPolicyConfigMapper.advFilterList(policy.getAppId(), policy.getBusinessLine(),
|
|
|
+ policy.getBusinessMethod(), policy.getOptimizerId(), policy.getDeptId(), policy.getMovieId());
|
|
|
+ for (JSONObject resId : resIds) {
|
|
|
+ rList.add(resId.getString("advertiser_id"));
|
|
|
+ targetFromAdvertiserId.put(resId.getString("advertiser_id"), resId.getString("advertiser_id"));
|
|
|
+ }
|
|
|
+ }else if (policy.getManagedDimension() == 2){
|
|
|
+ resIds = ztPolicyConfigMapper.adProjFilterList(policy.getAppId(), policy.getBusinessLine(),
|
|
|
+ policy.getBusinessMethod(), policy.getOptimizerId(), policy.getDeptId(), policy.getMovieId());
|
|
|
+ for (JSONObject resId : resIds) {
|
|
|
+ rList.add(resId.getString("a_id"));
|
|
|
+ targetFromAdvertiserId.put(resId.getString("a_id"), resId.getString("advertiser_id"));
|
|
|
+ }
|
|
|
+ }else if (policy.getManagedDimension() == 3){
|
|
|
+ resIds = ztPolicyConfigMapper.adPromFilterList(policy.getAppId(), policy.getBusinessLine(),
|
|
|
+ policy.getBusinessMethod(), policy.getOptimizerId(), policy.getDeptId(), policy.getMovieId());
|
|
|
+ for (JSONObject resId : resIds) {
|
|
|
+ rList.add(resId.getString("ad_id"));
|
|
|
+ targetFromAdvertiserId.put(resId.getString("ad_id"), resId.getString("advertiser_id"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ policy.setTargetResIds(rList);
|
|
|
+ policy.setTargetFromAdvertiserId(targetFromAdvertiserId);
|
|
|
}else {
|
|
|
List<ZtPolicyTargetIds> ids = ztPolicyConfigMapper.getTargetIds(policyId);
|
|
|
policy.setTargetScopeIds(ids.stream().map(ZtPolicyTargetIds::getTargetId).collect(Collectors.toList()));
|