Commit d5f23c73 authored by tianbo's avatar tianbo

Merge branch 'developer' of http://172.16.10.76/moa/amos-boot-biz into developer

parents 2e94045e f9fa00de
......@@ -41,6 +41,8 @@ public class PushMsgParam {
* jpush发送类型:1:广播;2:标签;3:别名
*/
private String type = "3";
private String relationId;
public String getType() {
return type;
......@@ -90,5 +92,13 @@ public class PushMsgParam {
public void setEmails(String[] emails) {
this.emails = emails;
}
public String getRelationId() {
return relationId;
}
public void setRelationId(String relationId) {
this.relationId = relationId;
}
}
......@@ -147,8 +147,14 @@ public class MessageServiceImpl implements IMessageService {
}
}
//获取需要推送的app的用户
List<PushTargetBo> jpushUser = msgMapper.getPushUserBo("app", String.join(",", needUserIds), checkMsgBo.getRouteId(),getAppPushConfig(checkMsgBo.getStatus()));
//获取需要推送的app的用户 手机端暂时无订阅功能,暂时屏蔽
// List<PushTargetBo> jpushUser = msgMapper.getPushUserBo("app", String.join(",", needUserIds), checkMsgBo.getRouteId(),getAppPushConfig(checkMsgBo.getStatus()));
List<PushTargetBo> jpushUser = new ArrayList<>();
needUserIds.stream().forEach(action->{
PushTargetBo pb = new PushTargetBo();
pb.setUserId(action);
jpushUser.add(pb);
});
//获取需要推送的email的用户
List<PushTargetBo> emailUser = msgMapper.getPushUserBo("email", String.join(",", needUserIds), checkMsgBo.getRouteId(),getEmailPushConfig(checkMsgBo.getStatus()));
......@@ -157,7 +163,9 @@ public class MessageServiceImpl implements IMessageService {
List<PushTargetBo> tempList = new ArrayList<>();
tempList.addAll(jpushUser);
tempList.addAll(emailUser);
List<String> userIds=tempList.stream().map(PushTargetBo::getUserId).distinct().collect(Collectors.toList());
// 手机端暂时无订阅功能,暂时屏蔽
// List<String> userIds=tempList.stream().map(PushTargetBo::getUserId).distinct().collect(Collectors.toList());
Set<String> userIds = needUserIds;
List<AgencyUserModel> agencyUserModelList=remoteSecurityService.listUserByUserIds( toke,product,appKey,String.join(",", userIds));
try {
pushAppMsg(jpushUser,agencyUserModelList,pushMsgParam,checkMsgBo, toke, product, appKey);
......@@ -223,8 +231,8 @@ public class MessageServiceImpl implements IMessageService {
}
List<String> pushApps = jpushUser.stream()
.filter(bo->StringUtil.isNotEmpty(bo.getUsername()))
.map(PushTargetBo::getUsername).collect(Collectors.toList());
.filter(bo->StringUtil.isNotEmpty(bo.getUserId()))
.map(PushTargetBo::getUserId).collect(Collectors.toList());
pushApps = pushApps.stream().distinct().collect(Collectors.toList());
if(!pushApps.isEmpty()){
List<PushMsgParam> pmps = new ArrayList<PushMsgParam>();
......@@ -234,6 +242,7 @@ public class MessageServiceImpl implements IMessageService {
extras.put("type",MsgTypeEnum.CHECK.getCode());
extras.put("id",checkMsgBo.getCheckId()+"");
pushMsgParam.setExtras(extras);
pushMsgParam.setRelationId(checkMsgBo.getCheckId()+"");
pmps.add(pushMsgParam);
List<Msg> msgList =createMsg(jpushUser,checkMsgBo);
pushFeignServer.sendMessage( toke, product, appKey,pmps);
......@@ -302,13 +311,14 @@ public class MessageServiceImpl implements IMessageService {
}
@Override
public Msg pushMsg(String toke,String product,String appKey,Msg msg) {
public Msg pushMsgAndSave(String toke,String product,String appKey,Msg msg) {
List<PushMsgParam> pmps = new ArrayList<PushMsgParam>();
PushMsgParam pushMsg = new PushMsgParam();
pushMsg.setRecivers(Arrays.asList(msg.getTargetTel()));
pushMsg.setRecivers(Arrays.asList(msg.getUserId()));
pushMsg.setContent(ObjectUtils.isEmpty(msg.getPushBody()) ? msg.getBody() : msg.getPushBody());
pushMsg.setSubject(msg.getTitle());
pushMsg.setType(JPushTypeEnum.ALIAS.getCode());
pushMsg.setRelationId(msg.getRelationId()==null?"0":msg.getRelationId().toString());
Map<String, String> extras = new HashMap<String, String>();
extras.put("type",msg.getMsgType());
extras.put("id",msg.getRelationId()==null?"0":msg.getRelationId().toString());
......@@ -350,7 +360,7 @@ public class MessageServiceImpl implements IMessageService {
msg.setUserId(user.getUserId());
msg.setReciverName(user.getRealName());
if (isImmediately) { //立即发送
msg = pushMsg( toke, product, appKey,msg);
msg = pushMsgAndSave( toke, product, appKey,msg);
} else { //定时发送
msg.setStatus(0);
msg.setFixedTime(notice.getFixedTime());
......@@ -414,9 +424,17 @@ public class MessageServiceImpl implements IMessageService {
msg.setTargetTel(userNames);
msg.setUserId(userIds);
msg.setIsImmediately(isImmediately);
pushMsg( toke, product, appKey,msg);
pushMsgAndSave( toke, product, appKey,msg);
}
}
}
@Override
public void pushMsg(String toke, String product, String appKey, PushMsgParam pmsg) {
// TODO Auto-generated method stub
pushFeignServer.sendMessage( toke, product, appKey,pmsg);
}
}
......@@ -7,6 +7,7 @@ import org.springframework.data.domain.Page;
import com.yeejoin.amos.patrol.business.param.MsgInfoPageParam;
import com.yeejoin.amos.patrol.business.param.NoticePublishParam;
import com.yeejoin.amos.patrol.business.param.PushMsgParam;
import com.yeejoin.amos.patrol.business.vo.MsgVo;
import com.yeejoin.amos.patrol.dao.entity.Check;
import com.yeejoin.amos.patrol.dao.entity.Msg;
......@@ -48,6 +49,8 @@ public interface IMessageService {
* 消息公告推送
* @param msg
*/
public Msg pushMsg(String toke,String product,String appKey,Msg msg);
public Msg pushMsgAndSave(String toke,String product,String appKey,Msg msg);
public void pushMsg(String toke,String product,String appKey,PushMsgParam pmsg);
}
......@@ -66,37 +66,7 @@ public class AsyncTask {
private static final String TAB = "\r\n";
/**
* 邮件发送
* @param msgResponse
* @return
* @throws InterruptedException
*/
// @Async("asyncTaskExecutor")
// public Future<Boolean> sendEmail(PushMsgParam pmp) throws InterruptedException {
// long start = System.currentTimeMillis();
// iEmailService.sendSimpleEmail(pmp.getEmails(), pmp.getSubject(), pmp.getContent());
// long end = System.currentTimeMillis();
// log.info("=====邮件发送耗时:"+(end-start)+"======");
// return new AsyncResult<Boolean>(true);
// }
//
// /**
// * jpush 推送
// * @param pmps
// * @return
// * @throws InterruptedException
// */
// @Async("asyncTaskExecutor")
// public Future<Boolean> sendJpush(List<PushMsgParam> pmps) throws InterruptedException {
// long start = System.currentTimeMillis();
// appMessagePushService.sendMessage(pmps);
// long end = System.currentTimeMillis();
// //返回true,告诉此任务已完成
// log.info("=====Jpush发送耗时:"+(end-start)+"======");
// return new AsyncResult<Boolean>(true);
// }
/**
* 检查消息推送
* @param checkId
......@@ -231,6 +201,7 @@ public class AsyncTask {
msg.setIsImmediately(true);
msg.setSendTime(date);
msg.setCreateDate(date);
msg.setTargetTel(user.getString("username"));
msg.setReciverName(user.getString("realName"));
sendUserIds.add(user.getString("userId"));
msgs.add(msg);
......@@ -247,11 +218,12 @@ public class AsyncTask {
pushMsgParam.setContent(body);
pushMsgParam.setRecivers(Lists.newArrayList(sendUserIds));
pushMsgParam.setSubject(title);
pushMsgParam.setRelationId(String.valueOf(relationId));
pushMsgParam.setType(JPushTypeEnum.ALIAS.getCode());
pushMsgParam.setExtras(extras);
iMsgDao.saveAll(msgs);
appMessagePushService.sendMessage(pushMsgParam);
// log.info("极光推送成功====>" + sendUserIds);
Toke toke= remoteSecurityService.getServerToken();
messageService.pushMsg(toke.getToke(),toke.getProduct(),toke.getAppKey(),pushMsgParam);
}
}
......
package com.yeejoin.amos.patrol.feign;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -14,38 +15,57 @@ import com.yeejoin.amos.patrol.business.param.PushMsgParam;
import com.yeejoin.amos.patrol.business.util.CommonResponse;
import com.yeejoin.amos.patrol.business.util.CommonResponseUtil;
import com.yeejoin.amos.patrol.core.common.response.TaskInfoRespone;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.MessageModel;
@Service("pushFeignServer")
public class PushFeignServer {
@Autowired
private RestTemplate restTemplate;
@Value("${Push.fegin.name}")
private String RPushFeginName;
private static String sendMessage = "/api/user/sendMessage";
// @Autowired
// private RestTemplate restTemplate;
//
// @Value("${Push.fegin.name}")
// private String RPushFeginName;
// private static String sendMessage = "/api/user/sendMessage";
//
// public String geturls(String url){
// return "http://"+RPushFeginName+url;
// }
// public HttpHeaders getHeader(String toke,String product,String appKey){
// HttpHeaders headers = new HttpHeaders();
// headers.setContentType(MediaType.APPLICATION_JSON);
// headers.set("Content-Type", "application/json");
// headers.set("token", toke);
// headers.set("product",product);
// headers.set("appKey", appKey);
// return headers;
// }
public String geturls(String url){
return "http://"+RPushFeginName+url;
}
public HttpHeaders getHeader(String toke,String product,String appKey){
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Content-Type", "application/json");
headers.set("token", toke);
headers.set("product",product);
headers.set("appKey", appKey);
return headers;
}
public void sendMessage( String toke,String product,String appKey, List<PushMsgParam> pushMsgParam){
try {
pushMsgParam.forEach(action->{
sendJP(action);
});
} catch (Exception e) {
e.printStackTrace();
}
}
public CommonResponse sendMessage( String toke,String product,String appKey, List<PushMsgParam> pushMsgParam){
public void sendMessage( String toke,String product,String appKey, PushMsgParam pushMsgParam){
try {
HttpEntity httpEntity = new HttpEntity<>(pushMsgParam, getHeader( toke, product, appKey));
CommonResponse commonResponse1 = restTemplate.postForObject(geturls(sendMessage),httpEntity, CommonResponse.class);
return commonResponse1;
} catch (Exception e) {
sendJP(pushMsgParam);
} catch (Exception e) {
e.printStackTrace();
return CommonResponseUtil.failure("发送失败");
}
}
}
private void sendJP(PushMsgParam pushMsgParam){
MessageModel model = new MessageModel();
model.setRelationId(pushMsgParam.getRelationId());
model.setTitle(pushMsgParam.getSubject());
model.setBody(pushMsgParam.getContent());
model.setMsgType("patrolSystem");
model.setRecivers(pushMsgParam.getRecivers());
model.setExtras(pushMsgParam.getExtras());
Systemctl.messageClient.create(model);
}
}
......@@ -110,17 +110,17 @@ public class AppMessagePushService {
}
public void sendMessage(PushMsgParam response){
try {
if(null!=response && "true".equals(isPush)){
CommonResponse commonResponse = PushFeign.sendMessageone(response);
}
} catch (Exception e) {
log.error(e.getMessage(),e);
e.printStackTrace();
}
}
// public void sendMessage(PushMsgParam response){
//
// try {
// if(null!=response && "true".equals(isPush)){
// CommonResponse commonResponse = PushFeign.sendMessageone(response);
// }
// } catch (Exception e) {
// log.error(e.getMessage(),e);
// e.printStackTrace();
//
// }
// }
}
......@@ -521,7 +521,7 @@ public class JobService implements IJobService {
if (iMsgDao.existsById(msgId)) {
Msg msg = iMsgDao.findById(msgId).get();
Toke toke= remoteSecurityService.getServerToken();
messageService.pushMsg(toke.getToke(), toke.getProduct(), toke.getAppKey(),msg);
messageService.pushMsgAndSave(toke.getToke(), toke.getProduct(), toke.getAppKey(),msg);
}
removeJob(jobName);
}
......
......@@ -200,6 +200,16 @@
</exclusions>
</dependency>
<dependency>
<groupId>com.yeejoin</groupId>
<artifactId>amos-feign-privilege</artifactId>
<version>${amos.version}</version>
</dependency>
<dependency>
<groupId>com.yeejoin</groupId>
<artifactId>amos-feign-systemctl</artifactId>
<version>1.6.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.13</version>
......
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