数据修改推送队列

This commit is contained in:
yiyan
2019-04-10 17:33:03 +08:00
parent a7e8cb7884
commit c5dbae94d8
10 changed files with 428 additions and 13 deletions
@@ -0,0 +1,37 @@
package com.ifish.entity.event;
import com.alibaba.fastjson.JSONObject;
/**
* @author: yan.y
* @Description:
* @Date: Created in 16:58 2019-04-10
* @Modified by:
*/
public class QueueEventBody {
public QueueEventBody(String entity, JSONObject data) {
this.entity = entity;
this.data = data;
}
private String entity;
private JSONObject data;
public String getEntity() {
return entity;
}
public void setEntity(String entity) {
this.entity = entity;
}
public JSONObject getData() {
return data;
}
public void setData(JSONObject data) {
this.data = data;
}
}
@@ -0,0 +1,42 @@
package com.ifish.entity.event;
import com.alibaba.fastjson.JSONObject;
/**
* @author: yan.y
* @Description:
* @Date: Created in 16:46 2019-04-10
* @Modified by:
*/
public class QueueEventEntity {
private String eventProcess;
private String eventName;
private QueueEventBody eventBody;
public String getEventProcess() {
return eventProcess;
}
public void setEventProcess(String eventProcess) {
this.eventProcess = eventProcess;
}
public String getEventName() {
return eventName;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
public QueueEventBody getEventBody() {
return eventBody;
}
public void setEventBody(QueueEventBody eventBody) {
this.eventBody = eventBody;
}
}
@@ -4,7 +4,10 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import com.alibaba.fastjson.JSONObject;
import com.ifish.entity.*;
import com.ifish.entity.event.QueueEventBody;
import com.ifish.entity.event.QueueEventEntity;
import com.ifish.socketNew.model.receive.*;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
@@ -29,6 +32,10 @@ import com.ifish.socketNew.model.send.OrderFunctionCode9;
import com.ifish.socketNew.util.OrderModel;
import com.ifish.util.ByteUtil;
import com.ifish.util.IfishUtil;
import org.springframework.jms.core.JmsTemplate;
import javax.jms.Destination;
import javax.jms.Session;
/**
@@ -44,6 +51,12 @@ public class SomeServer {
private ScheduleJob scheduleJob;
@Autowired
private NeteaseIM neteaseIM;
@Autowired
private JmsTemplate jmsTemplate;
@Autowired
private Destination ifish7DataQueueDestination;
@Autowired
private Destination ifish7PushQueueDestination;
//是否回复心跳
public static boolean isReplay = true;
@@ -83,15 +96,31 @@ public class SomeServer {
BackFunctionCodeHeater heater = (BackFunctionCodeHeater) message;
String macAddress = ByteUtil.bytesToHexString(heater.getSrc());
String hour = String.valueOf(Calendar.getInstance().get(Calendar.HOUR_OF_DAY));
List<DeviceHeater> deviceHeaters = deviceService.getDeviceHeaterByProperty(hour, macAddress,IfishUtil.format1(new Date()));
if (deviceHeaters.size() > 0) {
DeviceHeater deviceHeater = deviceHeaters.get(0);
deviceHeater.setHeaterWaterTemperature(String.valueOf(heater.getWaterTemperature()));
deviceHeater.setHeaterPh(String.valueOf(heater.getPh()));
deviceService.update(deviceHeater);
} else {
deviceService.save(heater);
}
// List<DeviceHeater> deviceHeaters = deviceService.getDeviceHeaterByProperty(hour, macAddress,IfishUtil.format1(new Date()));
// if (deviceHeaters.size() > 0) {
// DeviceHeater deviceHeater = deviceHeaters.get(0);
// deviceHeater.setHeaterWaterTemperature(String.valueOf(heater.getWaterTemperature()));
// deviceHeater.setHeaterPh(String.valueOf(heater.getPh()));
// deviceService.update(deviceHeater);
// } else {
// deviceService.save(heater);
// }
JSONObject data = new JSONObject();
data.put("heaterMacAddress",macAddress);
data.put("heaterWaterTemperature",heater.getHeatingTemperature());
data.put("heaterPh",heater.getPh());
data.put("heaterGatheringDate",IfishUtil.format1(new Date()));
data.put("heaterGatheringTime",hour);
QueueEventEntity eventEntity = new QueueEventEntity();
eventEntity.setEventName("com.ifish7.mq.queues.event.IntelligentHeatingRodEvent");
eventEntity.setEventProcess("intelligentHeatingRodSaveOrUpdate");
QueueEventBody eventBody = new QueueEventBody("com.ifish7.mq.business.device.entity.TblDeviceHeater",data);
eventEntity.setEventBody(eventBody);
//智能加热棒数据更新及保存
sendDataQueueMessage(JSONObject.toJSONString(eventEntity));
//设备重新连接上,则移除延时推送的任务
JobGroup jobGroup = new JobGroup();
jobGroup.setJobName(macAddress);
@@ -151,6 +180,26 @@ public class SomeServer {
jobGroup.setTriggerName(strSrc);
scheduleJob.deleteJob(jobGroup);
try {
//macAddr地址
String stcMac = ByteUtil.bytesToHexString(model.getSrc());
//IP
byte[] log_Ip= receive.getLogin_ip();
StringBuilder ipStr = new StringBuilder();
for (int i = 0; i < log_Ip.length; i++) {
int v = log_Ip[i] & 0xff;
if(i==0){
ipStr.append(v);
}
else{
ipStr.append("."+v);
}
}
Integer version = receive.getVersion() & 0xff;
String factoryCode = ByteUtil.toHex(receive.getVendor());
factoryCode = factoryCode.equals("01")?"0a":factoryCode;
String typeCode = ByteUtil.toHex(receive.getHardware_type());
//更新设备信息
deviceService.update(receive);
// if(device==null){
@@ -376,4 +425,20 @@ public class SomeServer {
log.error("pushNotifcation error:macAddress:{},error msg:{}",strSrc,e.toString());
}
}
/**
* 推送Data消息队列
* @param json 内容
*/
private void sendDataQueueMessage(final String json){
jmsTemplate.send(ifish7DataQueueDestination,(Session session) -> session.createTextMessage(json));
}
/**
* 推送Push消息队列
* @param json 内容
*/
private void sendPushQueueMessage(final String json) {
jmsTemplate.send(ifish7PushQueueDestination,(Session session) -> session.createTextMessage(json));
}
}
@@ -0,0 +1,11 @@
package com.ifish.util;
/**
* @author: yan.y
* @Description: json工具
* @Date: Created in 16:46 2019-04-10
* @Modified by:
*/
public class QueueMessageJsonUtil {
}