设备推送

This commit is contained in:
yiyan 2019-04-15 19:32:44 +08:00
parent 76c43c0f45
commit 70626f9b6f
2 changed files with 101 additions and 63 deletions

View File

@ -5,6 +5,10 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ifish.entity.event.QueueEventBody;
import com.ifish.entity.event.QueueEventEntity;
import org.apache.mina.core.session.IoSession; import org.apache.mina.core.session.IoSession;
import org.quartz.Job; import org.quartz.Job;
import org.quartz.JobDataMap; import org.quartz.JobDataMap;
@ -25,6 +29,10 @@ import com.ifish.netease.NeteaseIM;
import com.ifish.service.DeviceService; import com.ifish.service.DeviceService;
import com.ifish.service.UserService; import com.ifish.service.UserService;
import com.ifish.socketNew.SomeServer; import com.ifish.socketNew.SomeServer;
import org.springframework.jms.core.JmsTemplate;
import javax.jms.Destination;
import javax.jms.Session;
public class ExecuteJob implements Job { public class ExecuteJob implements Job {
@ -35,6 +43,10 @@ public class ExecuteJob implements Job {
private UserService userService; private UserService userService;
@Autowired @Autowired
private DeviceService deviceService; private DeviceService deviceService;
@Autowired
private JmsTemplate jmsTemplate;
@Autowired
private Destination ifish7PushQueueDestination;
public void execute(JobExecutionContext context) throws JobExecutionException { public void execute(JobExecutionContext context) throws JobExecutionException {
//任务传递的参数 //任务传递的参数
@ -65,42 +77,50 @@ public class ExecuteJob implements Job {
String title = PushTypeEnum.offline_push.getValue(); String title = PushTypeEnum.offline_push.getValue();
String msg = ""+title+"】你的水族箱“"+showName+"”于"+timestamp+"离线,请及时查看!"; String msg = ""+title+"】你的水族箱“"+showName+"”于"+timestamp+"离线,请及时查看!";
//发送云信消息 //发送云信消息
boolean neteaseBln = false; // boolean neteaseBln = false;
Map<String, String> neteaseMap = neteaseIM.sendMsg("ifish", userId.toString(), msg); // Map<String, String> neteaseMap = neteaseIM.sendMsg("ifish", userId.toString(), msg);
if(neteaseMap!=null){ // if(neteaseMap!=null){
neteaseBln = neteaseMap.get("code").equals(NeteaseEnum.status200.getKey()); // neteaseBln = neteaseMap.get("code").equals(NeteaseEnum.status200.getKey());
} // }
//IOS极光推送 //IOS极光推送
boolean jpushIosBln = false; // boolean jpushIosBln = false;
//推送记录 //推送记录
PushList pushList = new PushList(); PushList pushList = new PushList();
Integer deviceId = deviceUser.getPriId().getDeviceId(); Integer deviceId = deviceUser.getPriId().getDeviceId();
User user = userService.findById(userId); User user = userService.findById(userId);
if(user!=null){ if(user!=null){
String loginType = user.getLoginType(); // String loginType = user.getLoginType();
if(loginType!=null){ // if(loginType!=null){
Map<String,String> map = new HashMap<String, String>(); // Map<String,String> map = new HashMap<String, String>();
map.put("device_id", deviceId.toString()); // map.put("device_id", deviceId.toString());
map.put("device_name", showName); // map.put("device_name", showName);
map.put("timestamp", timestamp); // map.put("timestamp", timestamp);
map.put("msg_type", PushTypeEnum.offline_push.getKey()); // map.put("msg_type", PushTypeEnum.offline_push.getKey());
//推送记录 //推送记录
pushList.setUserId(userId); pushList.setUserId(userId);
pushList.setDeviceId(deviceId); pushList.setDeviceId(deviceId);
pushList.setPhoneType(loginType.toLowerCase()); pushList.setPhoneType("ALL");
pushList.setShowName(showName); pushList.setShowName(showName);
pushList.setPushType(PushTypeEnum.offline_push.getKey()); pushList.setPushType(PushTypeEnum.offline_push.getKey());
pushList.setNeteaseStatus(neteaseBln?BooleanEnum.YES.getKey():BooleanEnum.NO.getKey()); // pushList.setNeteaseStatus(neteaseBln?BooleanEnum.YES.getKey():BooleanEnum.NO.getKey());
pushList.setPushTitle(title); pushList.setPushTitle(title);
pushList.setPushContext(msg); pushList.setPushContext(msg);
pushList.setCreateTime(new Date()); // pushList.setCreateTime(new Date());
pushList.setNumber1(number1); pushList.setNumber1(number1);
pushList.setNumber2(number2); pushList.setNumber2(number2);
pushList.setNumber3(number3); pushList.setNumber3(number3);
pushList.setNumber4(number4); pushList.setNumber4(number4);
pushList.setNumber5(number5); pushList.setNumber5(number5);
this.userService.save(pushList); JSONObject data = JSON.parseObject(JSON.toJSONString(pushList));
} QueueEventEntity eventEntity = new QueueEventEntity();
eventEntity.setEventName("com.ifish7.mq.queues.event.PushNotifcationEvent");
eventEntity.setEventProcess("deviceNotifcationPlus");
QueueEventBody eventBody = new QueueEventBody("com.ifish7.mq.business.user.entity.TblPushList",data);
eventEntity.setEventBody(eventBody);
//推送至消息推送队列
sendPushQueueMessage(JSONObject.toJSONString(eventEntity));
// this.userService.save(pushList);
// }
} }
} }
} }
@ -110,4 +130,13 @@ public class ExecuteJob implements Job {
log.error("error msg:{}",e.toString()); log.error("error msg:{}",e.toString());
} }
} }
/**
* 推送Push消息队列
* @param json 内容
*/
private void sendPushQueueMessage(final String json) {
jmsTemplate.send(ifish7PushQueueDestination,(Session session) -> session.createTextMessage(json));
}
} }

View File

@ -5,6 +5,7 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ifish.entity.*; import com.ifish.entity.*;
import com.ifish.entity.event.QueueEventBody; import com.ifish.entity.event.QueueEventBody;
@ -450,43 +451,51 @@ public class SomeServer {
User user = userService.findById(userId); User user = userService.findById(userId);
if(user!=null){ if(user!=null){
//云信推送 //云信推送
boolean neteaseBln = false; // boolean neteaseBln = false;
//极光推送 //极光推送
boolean jpushIosBln = false; // boolean jpushIosBln = false;
boolean jpushAndroidBln = false; // boolean jpushAndroidBln = false;
//发送云信消息 //发送云信消息
Map<String, String> neteaseMap = neteaseIM.sendMsg("ifish", userId.toString(), msg); // Map<String, String> neteaseMap = neteaseIM.sendMsg("ifish", userId.toString(), msg);
if(neteaseMap!=null){ // if(neteaseMap!=null){
neteaseBln = neteaseMap.get("code").equals(NeteaseEnum.status200.getKey()); // neteaseBln = neteaseMap.get("code").equals(NeteaseEnum.status200.getKey());
} // }
String loginType = user.getLoginType(); // String loginType = user.getLoginType();
if(loginType!=null){ // if(loginType!=null){
//推送记录 //推送记录
PushList pushList = new PushList(); PushList pushList = new PushList();
Map<String,String> map = new HashMap<String, String>(); // Map<String,String> map = new HashMap<String, String>();
map.put("device_id", deviceId.toString()); // map.put("device_id", deviceId.toString());
map.put("device_name", showName); // map.put("device_name", showName);
map.put("timestamp", timestamp); // map.put("timestamp", timestamp);
map.put("msg_type", PushTypeEnum.wendu_warn.getKey()); // map.put("msg_type", PushTypeEnum.wendu_warn.getKey());
//记录推送 //记录推送
if(jpushIosBln || jpushAndroidBln || neteaseBln){ // if(jpushIosBln || jpushAndroidBln || neteaseBln){
pushList.setUserId(userId); pushList.setUserId(userId);
pushList.setDeviceId(deviceId); pushList.setDeviceId(deviceId);
pushList.setPhoneType(loginType.toLowerCase()); pushList.setPhoneType("ALL");
pushList.setShowName(showName); pushList.setShowName(showName);
pushList.setPushType(PushTypeEnum.wendu_warn.getKey()); pushList.setPushType(PushTypeEnum.wendu_warn.getKey());
pushList.setPushTitle(title); pushList.setPushTitle(title);
pushList.setPushContext(msg); pushList.setPushContext(msg);
pushList.setNeteaseStatus(neteaseBln?BooleanEnum.YES.getKey():BooleanEnum.NO.getKey()); // pushList.setNeteaseStatus(neteaseBln?BooleanEnum.YES.getKey():BooleanEnum.NO.getKey());
pushList.setCreateTime(new Date()); // pushList.setCreateTime(new Date());
pushList.setNumber1(device.getNumber1()); pushList.setNumber1(device.getNumber1());
pushList.setNumber2(device.getNumber2()); pushList.setNumber2(device.getNumber2());
pushList.setNumber3(device.getNumber3()); pushList.setNumber3(device.getNumber3());
pushList.setNumber4(device.getNumber4()); pushList.setNumber4(device.getNumber4());
pushList.setNumber5(device.getNumber5()); pushList.setNumber5(device.getNumber5());
this.userService.save(pushList); JSONObject data = JSON.parseObject(JSON.toJSONString(pushList));
} QueueEventEntity eventEntity = new QueueEventEntity();
} eventEntity.setEventName("com.ifish7.mq.queues.event.PushNotifcationEvent");
eventEntity.setEventProcess("deviceNotifcationPlus");
QueueEventBody eventBody = new QueueEventBody("com.ifish7.mq.business.user.entity.TblPushList",data);
eventEntity.setEventBody(eventBody);
//推送至消息推送队列
sendPushQueueMessage(JSONObject.toJSONString(eventEntity));
// this.userService.save(pushList);
// }
// }
} }
} }