添加推送
This commit is contained in:
parent
b53976cece
commit
4c8ea7b5d5
2
pom.xml
2
pom.xml
@ -11,7 +11,7 @@
|
||||
|
||||
<groupId>com.cm</groupId>
|
||||
<artifactId>system-inspection</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<name>system-inspection</name>
|
||||
<description>隐患排查系统</description>
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
package com.cm.inspection.runnable.taskcheck.v2;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cm.common.exception.SaveException;
|
||||
import com.cm.common.plugin.oauth.token.ClientTokenManager;
|
||||
import com.cm.common.utils.DateUtil;
|
||||
import com.cm.common.utils.HashMapUtil;
|
||||
import com.cm.common.utils.UUIDUtil;
|
||||
@ -20,10 +23,14 @@ import com.cm.inspection.service.industrycheckitem.v2.IIndustryCheckItemService;
|
||||
import com.cm.inspection.service.taskcheck.v2.ITaskCheckService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -51,6 +58,7 @@ public class TaskCheckSaveRunnable implements Runnable {
|
||||
private String modifier;
|
||||
private String taskId;
|
||||
private TaskCheckVO taskCheckVO;
|
||||
private String noticeUrl;
|
||||
|
||||
public TaskCheckSaveRunnable(String modifier, String taskId, TaskCheckVO taskCheckVO) {
|
||||
this.modifier = modifier;
|
||||
@ -360,6 +368,46 @@ public class TaskCheckSaveRunnable implements Runnable {
|
||||
}
|
||||
publishMsg.append("\n任务通知人数: " + checkUserIdSet.size());
|
||||
log.debug("任务通知人数:{}", checkUserIdSet.size());
|
||||
|
||||
if (StringUtils.isBlank(noticeUrl)) {
|
||||
log.debug("推送设置为空");
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject noticeJSONObject = new JSONObject();
|
||||
JSONArray noticeJSONArray = new JSONArray();
|
||||
JSONObject notice = new JSONObject();
|
||||
notice.put("userIds", checkUserIdSet);
|
||||
notice.put("title", "任务通知");
|
||||
notice.put("msg", "您有新的任务待处理,请点击查看");
|
||||
notice.put("target", "GO_TASK");
|
||||
noticeJSONArray.add(notice);
|
||||
noticeJSONObject.put("noticies", noticeJSONArray);
|
||||
|
||||
// 推送消息
|
||||
SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
|
||||
simpleClientHttpRequestFactory.setConnectTimeout(20 * 1000);
|
||||
simpleClientHttpRequestFactory.setReadTimeout(60 * 1000);
|
||||
RestTemplate restTemplate = new RestTemplate(simpleClientHttpRequestFactory);
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
||||
HttpEntity<JSONObject> httpEntity = new HttpEntity<>(noticeJSONObject, httpHeaders);
|
||||
|
||||
try {
|
||||
ResponseEntity<String> responseEntity = restTemplate.postForEntity(noticeUrl + "/resource/message/noticewithtarget?access_token={access_token}", httpEntity, String.class, ClientTokenManager.getInstance().getClientToken().getAccessToken());
|
||||
String responseBody = responseEntity.getBody();
|
||||
if (HttpStatus.OK.value() == responseEntity.getStatusCodeValue()) {
|
||||
log.debug("推送成功");
|
||||
}
|
||||
} catch (HttpClientErrorException e) {
|
||||
if (e.getRawStatusCode() == HttpStatus.BAD_REQUEST.value()) {
|
||||
log.error(e.getMessage(), e);
|
||||
return;
|
||||
}
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setTaskCheckDao(ITaskCheckDao taskCheckDao) {
|
||||
@ -385,4 +433,8 @@ public class TaskCheckSaveRunnable implements Runnable {
|
||||
public void setGridPersonnelService(IGridPersonnelService gridPersonnelService) {
|
||||
this.gridPersonnelService = gridPersonnelService;
|
||||
}
|
||||
|
||||
public void setNoticeUrl(String noticeUrl) {
|
||||
this.noticeUrl = noticeUrl;
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -83,6 +84,8 @@ public class TaskCheckServiceImpl extends BaseService implements ITaskCheckServi
|
||||
private DataSourceTransactionManager dataSourceTransactionManager;
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
@Value("${notice-url}")
|
||||
private String noticeUrl;
|
||||
|
||||
@Override
|
||||
public SuccessResult save(TaskCheckVO taskCheckVO) throws Exception {
|
||||
@ -105,6 +108,7 @@ public class TaskCheckServiceImpl extends BaseService implements ITaskCheckServi
|
||||
taskCheckSaveRunnable.setIndustryCheckItemService(industryCheckItemService);
|
||||
taskCheckSaveRunnable.setGridPersonnelService(gridPersonnelService);
|
||||
taskCheckSaveRunnable.setEnterpriseOfGridOperatorService(enterpriseOfGridOperatorService);
|
||||
taskCheckSaveRunnable.setNoticeUrl(noticeUrl);
|
||||
executorService.execute(taskCheckSaveRunnable);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user