Commit 07de9d2b authored by renandong's avatar renandong 🇨🇳

1,保存推送日志截取

2,增加别名批量推送接口
3,增加推送消息撤回
parent 180b4039
...@@ -300,7 +300,7 @@ public class GeTuiService { ...@@ -300,7 +300,7 @@ public class GeTuiService {
public CommonResult listPush(InformForm informForm) { public CommonResult listPush(InformForm informForm) {
try { try {
String type = informForm.getEquipmentType(); String type = informForm.getEquipmentType();
if ("kkwj".equals(type)){ if ("kkwj".equals(type)) {
return CommonResult.success("暂未开放推送"); return CommonResult.success("暂未开放推送");
} }
String appId = getAppId(type); String appId = getAppId(type);
...@@ -318,6 +318,7 @@ public class GeTuiService { ...@@ -318,6 +318,7 @@ public class GeTuiService {
String url = GE_TUI_BASE_URL + appId + "/push/all"; String url = GE_TUI_BASE_URL + appId + "/push/all";
log.info("执行群推"); log.info("执行群推");
String result = generalPost(url, pushToken, map); String result = generalPost(url, pushToken, map);
log.error("个推群推结果:{}", result);
if (result == null) { if (result == null) {
return CommonResult.failed(); return CommonResult.failed();
} }
...@@ -497,6 +498,54 @@ public class GeTuiService { ...@@ -497,6 +498,54 @@ public class GeTuiService {
return null; return null;
} }
/**
* 撤回下发消息
*
* @param taskId 任务id
* @return 执行结果
*/
public String revokeTask(String taskId, String equipmentType) {
String appId = getAppId(equipmentType);
String pushToken = getPushToken(equipmentType);
Map<String, Object> map = new HashMap<>();
map.put("request_id", String.valueOf(SnowIdUtil.nextId()));
map.put("audience", "all");
Map<String, Object> push_message = new HashMap<>();
HashMap<String, Object> revoke = new HashMap<>();
revoke.put("old_task_id", "RASA_0607_cca1c0bbccb4eccc9b102eee15708989");
revoke.put("force", false);
push_message.put("revoke", revoke);
map.put("push_message", push_message);
String revokePush = GeTuiService.GE_TUI_BASE_URL + appId + "/push/all";
String s = generalPost(revokePush, pushToken, map);
log.error("推送撤回消息:{}", s);
if (StringUtils.isBlank(pushToken)) {
return null;
}
String revokeDel = GE_TUI_BASE_URL + appId + "/task/" + taskId;
String token = HttpRequest.delete(revokeDel).header("token", pushToken).header("content-type", "application/json;charset=utf-8").execute().body();
log.error("停止下发:{}", token);
return token;
}
/**
* 获取推送下发实时结果 注意:该接口需要开通权限,如需开通,请联系对应的商务同学开通
*
* @param taskId 任务id
* @param equipmentType 推送app
* @return 下发结果
*/
public String getReportByTaskId(String taskId, String equipmentType) {
String prefix = String.format("/report/push/task/%s/detail", taskId);
String appId = getAppId(equipmentType);
String pushToken = getPushToken(equipmentType);
String url = GE_TUI_BASE_URL + appId + prefix;
String token = HttpRequest.get(url).header("token", pushToken).header("content-type", "application/json;charset=utf-8").execute().body();
log.error("推送下发结果:{}", token);
return token;
}
/** /**
* 将内容转为推送模板 * 将内容转为推送模板
* *
......
...@@ -12,6 +12,7 @@ import com.weface.dto.MsgDTO; ...@@ -12,6 +12,7 @@ import com.weface.dto.MsgDTO;
import com.weface.dto.PushDTO; import com.weface.dto.PushDTO;
import com.weface.service.PushService; import com.weface.service.PushService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -43,17 +44,22 @@ public class PushController { ...@@ -43,17 +44,22 @@ public class PushController {
return pushService.pushSingle(param); return pushService.pushSingle(param);
} }
/**
* 群推
*/
@PostMapping("/all") @PostMapping("/all")
public CommonResult pushAll(InformForm informForm) { public CommonResult pushAll(InformForm informForm) {
log.error("群推内容:{}", JSONObject.toJSONString(informForm)); log.error("群推内容:{}", JSONObject.toJSONString(informForm));
ValidatorUtils.validateEntity(informForm, InformForm.PushValid.class); ValidatorUtils.validateEntity(informForm, InformForm.PushValid.class);
if(informForm.getEquipmentType().equals("kksh")) if (informForm.getEquipmentType().equals("kksh")) {
{
mobPushService.mobPush(informForm, Constant.PushTarget.RADIO); mobPushService.mobPush(informForm, Constant.PushTarget.RADIO);
} }
return geTuiService.listPush(informForm); return geTuiService.listPush(informForm);
} }
/**
* 别名单推
*/
@PostMapping("/single/alias") @PostMapping("/single/alias")
public CommonResult pushSingleAlias(@RequestBody InformForm informForm) { public CommonResult pushSingleAlias(@RequestBody InformForm informForm) {
ValidatorUtils.validateEntity(informForm, InformForm.PushValid.class); ValidatorUtils.validateEntity(informForm, InformForm.PushValid.class);
...@@ -68,6 +74,9 @@ public class PushController { ...@@ -68,6 +74,9 @@ public class PushController {
return geTuiService.pushSingleAlias(informForm); return geTuiService.pushSingleAlias(informForm);
} }
/**
* cid单推
*/
@PostMapping("/single/cid") @PostMapping("/single/cid")
public CommonResult pushSingleCid(@RequestBody InformForm informForm) { public CommonResult pushSingleCid(@RequestBody InformForm informForm) {
ValidatorUtils.validateEntity(informForm, InformForm.PushValid.class); ValidatorUtils.validateEntity(informForm, InformForm.PushValid.class);
...@@ -81,4 +90,18 @@ public class PushController { ...@@ -81,4 +90,18 @@ public class PushController {
} }
return geTuiService.pushSingleCid(informForm); return geTuiService.pushSingleCid(informForm);
} }
/**
* 别名批量推送
*/
@PostMapping("/list/alias")
public CommonResult pushListMessage(@RequestBody InformForm informForm) {
ValidatorUtils.validateEntity(informForm, InformForm.PushValid.class);
String result = geTuiService.pushListMessage(informForm, true);
if (StringUtils.isEmpty(result)) {
return CommonResult.failed("推送失败");
} else {
return CommonResult.success(result, "推送成功");
}
}
} }
...@@ -77,8 +77,11 @@ public class PushLogServiceImpl extends ServiceImpl<PushLogDao, PushLogEntity> i ...@@ -77,8 +77,11 @@ public class PushLogServiceImpl extends ServiceImpl<PushLogDao, PushLogEntity> i
pushLogEntity.setId(id); pushLogEntity.setId(id);
pushLogEntity.setAppName(informForm.getEquipmentType()); pushLogEntity.setAppName(informForm.getEquipmentType());
pushLogEntity.setPushType(pushType); pushLogEntity.setPushType(pushType);
if (StringUtils.isNotEmpty(taskId) && taskId.length() > 200) {
taskId = taskId.substring(0, 200);
}
pushLogEntity.setTaskId(taskId); pushLogEntity.setTaskId(taskId);
if (result.length() > 200) { if (StringUtils.isNotEmpty(result) && result.length() > 200) {
result = result.substring(0, 200); result = result.substring(0, 200);
} }
pushLogEntity.setResult(result); pushLogEntity.setResult(result);
...@@ -91,8 +94,24 @@ public class PushLogServiceImpl extends ServiceImpl<PushLogDao, PushLogEntity> i ...@@ -91,8 +94,24 @@ public class PushLogServiceImpl extends ServiceImpl<PushLogDao, PushLogEntity> i
if (messageTemplate != null) { if (messageTemplate != null) {
pushLogEntity.setMessageTemplate(messageTemplate); pushLogEntity.setMessageTemplate(messageTemplate);
} }
pushLogEntity.setPushTarget(informForm.getCid() == null ? "all" : informForm.getCid()); String cid = informForm.getCid();
pushLogEntity.setPushContent(informForm.getBody()); String pushTarget;
if (StringUtils.isEmpty(cid)) {
pushTarget = "all";
} else {
int length = cid.length();
if (length <= 200) {
pushTarget = cid.substring(0, 200);
} else {
pushTarget = "toListMessage";
}
}
pushLogEntity.setPushTarget(pushTarget);
String body = informForm.getBody();
if (StringUtils.isNotEmpty(body) && body.length() > 200) {
body = body.substring(0, 200);
}
pushLogEntity.setPushContent(body);
pushLogEntity.setArriveStatus(1001); pushLogEntity.setArriveStatus(1001);
pushLogEntity.setUpdateTime(new Date()); pushLogEntity.setUpdateTime(new Date());
return pushLogEntity; return pushLogEntity;
......
...@@ -75,6 +75,7 @@ public class UserTagsTask { ...@@ -75,6 +75,7 @@ public class UserTagsTask {
*/ */
@Scheduled(cron = "0 0 8 1,15 * ?") @Scheduled(cron = "0 0 8 1,15 * ?")
public void timingPush() { public void timingPush() {
log.error("开始推送1,15号");
//判断当前是否为当月1/15号 //判断当前是否为当月1/15号
if (DateUtils.isToday(1) || DateUtils.isToday(15)) { if (DateUtils.isToday(1) || DateUtils.isToday(15)) {
//获取推送配置信息 //获取推送配置信息
...@@ -116,6 +117,7 @@ public class UserTagsTask { ...@@ -116,6 +117,7 @@ public class UserTagsTask {
//个推批量推送 //个推批量推送
geTuiService.pushListMessage(form, true); geTuiService.pushListMessage(form, true);
} }
log.error("本次推送目标数:{}", list.size());
} }
} }
} }
......
...@@ -111,19 +111,17 @@ class PushMessageApplicationTests { ...@@ -111,19 +111,17 @@ class PushMessageApplicationTests {
@Test @Test
void testRevoke() { void testRevoke() {
Map<String, Object> map = new HashMap<>(); String taskId = "RASA_0726_e51c93e787d103e072e4cd2cd43e8500";
map.put("request_id", String.valueOf(SnowIdUtil.nextId())); String equipmentType = "kksh";
map.put("audience", "all"); String s = geTuiService.revokeTask(taskId, equipmentType);
System.out.println(s);
}
Map<String, Object> push_message = new HashMap<>(); @Test
HashMap<String, Object> revoke = new HashMap<>(); void testPushResult(){
revoke.put("old_task_id", "RASA_0127_011f801354c5236738787cdda86cf232"); String taskId = "RASA_0726_e51c93e787d103e072e4cd2cd43e8500";
revoke.put("force", false); String equipmentType = "kksh";
push_message.put("revoke", revoke); String s = geTuiService.getReportByTaskId(taskId, equipmentType);
map.put("push_message", push_message);
String url = GeTuiService.GE_TUI_BASE_URL + geTuiService.getAppId("kksh") + "/push/all";
String kk_sh_token_ge_tui = geTuiService.getAuthToken("kk_sh_token_ge_tui");
String s = geTuiService.generalPost(url, kk_sh_token_ge_tui, map);
System.out.println(s); System.out.println(s);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment