Merge branch 'v4.6.9'

# Conflicts:
#	src/main/java/com/ifish/entity/hbm/DeviceOffline.hbm.xml
#	src/main/java/com/ifish/quartz/ExecuteJob.java
#	src/main/java/com/ifish/socketNew/MinaServerHandler.java
#	src/main/java/com/ifish/socketNew/SomeServer.java
#	src/main/resources/mq.properties
This commit is contained in:
易焱 2019-06-02 22:38:44 +08:00
commit 5f6255d9dd
11 changed files with 306 additions and 313 deletions

View File

@ -9,7 +9,7 @@
<property name="offlineMacAddress" column="offline_mac_address" type="string" length="50"/>
<property name="offlineFactoryCode" column="offline_factory_code" type="string" length="10"/>
<property name="offlineDeviceType" column="offline_device_type" type="string" length="10"/>
<property name="offlineTime" column="offline_time" type="date" />
<property name="offlineTime" column="offline_time" type="timestamp" />
<property name="offlineSdkVersion" column="offline_sdk_version" type="string" length="20"/>
</class>
</hibernate-mapping>

View File

@ -1,40 +1,119 @@
package com.ifish.quartz;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ifish.entity.*;
import com.ifish.util.IfishUtil;
import org.apache.mina.core.session.IoSession;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.ifish.enums.BooleanEnum;
import com.ifish.enums.NeteaseEnum;
import com.ifish.entity.event.QueueEventBody;
import com.ifish.entity.event.QueueEventEntity;
import com.ifish.enums.PushTypeEnum;
import com.ifish.netease.NeteaseIM;
import com.ifish.service.DeviceService;
import com.ifish.service.UserService;
import com.ifish.socketNew.SomeServer;
import com.ifish.util.IfishUtil;
import org.apache.log4j.Logger;
import org.apache.mina.core.session.IoSession;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Session;
import java.util.List;
public class ExecuteJob implements Job {
private static Logger log = LoggerFactory.getLogger(ExecuteJob.class);
private static Logger log = Logger.getLogger(ExecuteJob.class);
@Autowired
private NeteaseIM neteaseIM;
@Autowired
private UserService userService;
@Autowired
private DeviceService deviceService;
@Autowired
private JmsTemplate jmsTemplate;
@Autowired
private Destination ifish7PushQueueDestination;
public void execute(JobExecutionContext context) throws JobExecutionException {
//任务传递的参数
JobDataMap dataMap = context.getJobDetail().getJobDataMap();
String macAddress = dataMap.getString("macAddress");
String timestamp = dataMap.getString("timestamp");
try {
log.info("离线时间 --> " + timestamp);
log.info("离线设备 --> " + macAddress);
//移除为null的连接
IoSession session_cz = SomeServer.sessions_cz.get(macAddress);
if(session_cz==null || session_cz.getRemoteAddress()==null){
SomeServer.sessions_cz.remove(macAddress);
}
//设备是否存在
Device device = deviceService.getUniqueByProperty("macAddress", macAddress);
if(device!=null){
//保存离线的设备信息
DeviceOffline deviceOffline = new DeviceOffline();
deviceOffline.setOfflineMacAddress(device.getMacAddress());
deviceOffline.setOfflineFactoryCode(device.getFactoryCode());
deviceOffline.setOfflineDeviceType(device.getHardwareType());
deviceOffline.setOfflineSdkVersion(String.valueOf(device.getSdkVersion()));
deviceOffline.setOfflineTime(IfishUtil.StrToDate1(timestamp));
deviceService.saveDeviceOffline(deviceOffline);
log.info("离线设备信息保存++++++++++++++++++++++++++++++++++++++++++");
List<DeviceUser> list = deviceService.getListByProperty(device.getDeviceId());
//是否被绑定
if(list!=null){
for (DeviceUser deviceUser : list) {
Integer userId = deviceUser.getPriId().getUserId();
String showName = deviceUser.getShowName();
String title = PushTypeEnum.offline_push.getValue();
String msg = ""+title+"】你的水族箱“"+showName+"”于"+timestamp+"离线,请及时查看!";
User user = userService.findById(userId);
if(user!=null){
//推送记录
PushList pushList = new PushList();
//记录推送
pushList.setUserId(userId);
pushList.setDeviceId(deviceUser.getPriId().getDeviceId());
pushList.setPhoneType("ALL");
pushList.setShowName(showName);
pushList.setPushType(PushTypeEnum.offline_push.getKey());
pushList.setPushTitle(title);
pushList.setPushContext(msg);
pushList.setNumber1(device.getNumber1());
pushList.setNumber2(device.getNumber2());
pushList.setNumber3(device.getNumber3());
pushList.setNumber4(device.getNumber4());
pushList.setNumber5(device.getNumber5());
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));
}
}
}
}
} catch (Exception e) {
log.error(e.getMessage(),e);
}
}
/**
* 推送Push消息队列
* @param json 内容
*/
private void sendPushQueueMessage(final String json) throws JMSException {
jmsTemplate.send(ifish7PushQueueDestination,(Session session) -> session.createTextMessage(json));
}
/*public void execute(JobExecutionContext context) throws JobExecutionException {
//任务传递的参数
JobDataMap dataMap = context.getJobDetail().getJobDataMap();
String macAddress = dataMap.getString("macAddress");
@ -56,7 +135,7 @@ public class ExecuteJob implements Job {
deviceOffline.setOfflineSdkVersion(String.valueOf(device.getSdkVersion()));
deviceOffline.setOfflineTime(IfishUtil.StrToDate1(timestamp));
deviceService.saveDeviceOffline(deviceOffline);
log.info("离线设备信息保存++++++++++++++++++++++++++++++++++++++++++");
//记录次数
Integer number1 = device.getNumber1();
Integer number2 = device.getNumber2();
@ -113,8 +192,8 @@ public class ExecuteJob implements Job {
}
}
} catch (Exception e) {
e.printStackTrace();
log.error("error msg:{}",e.toString());
log.error(e.getMessage(),e);
}
}
}*/
}

View File

@ -1,15 +1,7 @@
package com.ifish.quartz;
import org.apache.log4j.Logger;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.TriggerKey;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -35,7 +27,7 @@ public class ScheduleJob {
scheduler.setJobFactory(jobFactory);
scheduler.start();
} catch (SchedulerException e) {
log.error(String.format("start scheduler error:{%s}",e.toString()));
log.info(String.format("start scheduler error:{%s}",e.toString()));
}
}
/**
@ -60,7 +52,7 @@ public class ScheduleJob {
//添加触发器
scheduler.scheduleJob(jobDetail,trigger);
} catch (SchedulerException e) {
log.error(String.format("addJob error【macAddress:{%s},jobGroup:{%s},triggerGroup:{%s},errMsg:{%s}】",jobGroup.getMacAddress(),jobGroup.getJobName(),jobGroup.getTriggerGroup(),e.toString()));
log.info(String.format("addJob error【macAddress:{%s},jobGroup:{%s},triggerGroup:{%s},errMsg:{%s}】",jobGroup.getMacAddress(),jobGroup.getJobName(),jobGroup.getTriggerGroup(),e.toString()));
// log.error("addJob error【macAddress:{},jobGroup:{},triggerGroup:{},errMsg:{}】",jobGroup.getMacAddress(),jobGroup.getJobName(),jobGroup.getTriggerGroup(),e.toString());
}
}
@ -83,7 +75,7 @@ public class ScheduleJob {
//删除任务
scheduler.deleteJob(jobKey);
} catch (SchedulerException e) {
log.error(String.format("deleteJob error【macAddress:{%s},jobGroup:{%s},triggerGroup:{%s},errMsg:{%s}】",jobGroup.getMacAddress(),jobGroup.getJobName(),jobGroup.getTriggerGroup(),e.toString()));
log.info(String.format("deleteJob error【macAddress:{%s},jobGroup:{%s},triggerGroup:{%s},errMsg:{%s}】",jobGroup.getMacAddress(),jobGroup.getJobName(),jobGroup.getTriggerGroup(),e.toString()));
}
}
@ -95,7 +87,7 @@ public class ScheduleJob {
//关闭任务
scheduler.shutdown();
} catch (SchedulerException e) {
log.error(String.format("shutdown scheduler error:{%s}",e.toString()));
log.info(String.format("shutdown scheduler error:{%s}",e.toString()));
}
}

View File

@ -1,18 +1,16 @@
package com.ifish.socketNew;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.ifish.quartz.JobGroup;
import com.ifish.quartz.ScheduleJob;
import com.ifish.util.IfishUtil;
import org.apache.log4j.Logger;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;
/**
* mina服务器端事件处理
@ -23,7 +21,7 @@ public class MinaServerHandler extends IoHandlerAdapter {
private final AtomicInteger atomicInt = new AtomicInteger();
private static Logger log = LoggerFactory.getLogger(MinaServerHandler.class);
private static Logger log = Logger.getLogger(MinaServerHandler.class);
@Autowired
private SomeServer someServer;
@ -33,7 +31,7 @@ public class MinaServerHandler extends IoHandlerAdapter {
@Override
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
cause.printStackTrace();
log.error("{}服务器-客户端session异常:{}", session.getRemoteAddress(), cause.toString());
log.error(String.format("{%s}服务器-客户端session异常:", session.getRemoteAddress()), cause);
}
/**
@ -49,7 +47,7 @@ public class MinaServerHandler extends IoHandlerAdapter {
*/
@Override
public void sessionCreated(IoSession session) throws Exception {
log.info("{}:会话创建,在线数:{}", session.getRemoteAddress(), atomicInt.incrementAndGet());
log.info(String.format("{%s}:会话创建,在线数:{%s}", session.getRemoteAddress(), atomicInt.incrementAndGet()));
}
/**
@ -57,7 +55,7 @@ public class MinaServerHandler extends IoHandlerAdapter {
*/
@Override
public void sessionClosed(IoSession session) throws Exception {
log.info("{}:会话关闭,连接数:{}", session.getRemoteAddress(), atomicInt.decrementAndGet());
log.info(String.format("{%s}:会话关闭在线数:{%s}", session.getRemoteAddress(), atomicInt.incrementAndGet()));
//旧连接关闭,获取设备mac地址
String oldConnect = session.getRemoteAddress().toString();
String macAddress = SomeServer.remoteAddress.get(oldConnect);
@ -92,7 +90,8 @@ public class MinaServerHandler extends IoHandlerAdapter {
//离线时间
jobGroup.setTimestamp(IfishUtil.format(new Date()));
//10分钟后推送 update 30分钟
jobGroup.setStartTime(new Date(System.currentTimeMillis() + 600000L * 3));
// jobGroup.setStartTime(new Date(System.currentTimeMillis() + 600000L * 3));
jobGroup.setStartTime(new Date(System.currentTimeMillis() + 60000L));
scheduleJob.addJob(jobGroup);
}
@ -110,7 +109,7 @@ public class MinaServerHandler extends IoHandlerAdapter {
@Override
public void sessionIdle(IoSession session, IdleStatus status)
throws Exception {
log.info("空闲超时,服务器主动关闭连接{}", session.getRemoteAddress());
log.info(String.format("空闲超时,服务器主动关闭连接{%s}", session.getRemoteAddress()));
session.close(true);
}

View File

@ -2,10 +2,7 @@ package com.ifish.socketNew;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ifish.entity.Device;
import com.ifish.entity.DeviceUser;
import com.ifish.entity.PushList;
import com.ifish.entity.User;
import com.ifish.entity.*;
import com.ifish.entity.event.QueueEventBody;
import com.ifish.entity.event.QueueEventEntity;
import com.ifish.enums.BooleanEnum;
@ -29,10 +26,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@ -44,7 +43,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
* 这个类主要是通过spring注入给MinaServerHandler用的, 表示: mina在接收到信息后,该由主要业务类来处理 服务器处理类
**/
public class SomeServer {
@Autowired
private UserService userService;
@Autowired
@ -56,18 +55,16 @@ public class SomeServer {
@Autowired
private JmsTemplate jmsTemplate;
@Autowired
private Destination ifish7DataQueueDestination;
@Autowired
private Destination ifish7PushQueueDestination;
//是否回复心跳
public static boolean isReplay = true;
private static Logger log = LoggerFactory.getLogger(SomeServer.class);
public static final ConcurrentHashMap<String, String> remoteAddress = new ConcurrentHashMap<String, String>();
public static final ConcurrentHashMap<String, IoSession> sessions_cz = new ConcurrentHashMap<String, IoSession>();
private ConcurrentHashMap<String, CopyOnWriteArraySet<IoSession>> sessions_sjs = new ConcurrentHashMap<String, CopyOnWriteArraySet<IoSession>>();
/**
* 过滤收到的数据 服务器收到数据进行协议类型匹配如果不匹配则不执行相应操作
* @param session
@ -79,17 +76,16 @@ public class SomeServer {
byte[] bytes = (byte[]) message;
//长度
int length = bytes[14] & 0xff;
//mac地址
IoBuffer ioBuffer = ByteUtil.byteToIoBuffer(bytes, length);
//类型
byte type = ioBuffer.get();
// int Check_code = (int) ioBuffer.get();
//mac地址
byte[] srcByte = new byte[6];
for (int i = 2; i < 8; i++) {
srcByte[i-2] = bytes[i];
}
String strSrc = ByteUtil.bytesToHexString(srcByte);
//心跳
//如果为设备端返回 发送给app端
if(type == 1){
sendToApp(session,strSrc, message);
}
@ -101,31 +97,15 @@ 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);
// }
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));
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);
}
//设备重新连接上则移除延时推送的任务
JobGroup jobGroup = new JobGroup();
jobGroup.setJobName(macAddress);
@ -141,17 +121,7 @@ public class SomeServer {
try {
Integer Onoff = receive.getOnoff() & 0xff;
if(Onoff==1 || Onoff==0){
JSONObject data = new JSONObject();
data.put("onOff",Onoff);
data.put("macAddress",strDest);
QueueEventEntity eventEntity = new QueueEventEntity();
eventEntity.setEventName("com.ifish7.mq.queues.event.DeviceInfoEvent");
eventEntity.setEventProcess("updateWarnOnoff");
QueueEventBody eventBody = new QueueEventBody("com.ifish7.mq.business.device.entity.TblDevice",data);
eventEntity.setEventBody(eventBody);
//温度开关更新
sendDataQueueMessage(JSONObject.toJSONString(eventEntity));
// deviceService.updateWarnOnoff(strDest,Onoff.toString());
deviceService.updateWarnOnoff(strDest,Onoff.toString());
}
else{
log.error("error Onoff:{},macAddress:{}",Onoff,strDest);
@ -195,41 +165,8 @@ 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());
JSONObject data = new JSONObject();
data.put("macAddress",stcMac);
data.put("deviceIp",ipStr.toString());
data.put("factoryCode",factoryCode);
data.put("hardwareType",typeCode);
data.put("softwareVersion",version);
QueueEventEntity eventEntity = new QueueEventEntity();
eventEntity.setEventName("com.ifish7.mq.queues.event.DeviceInfoEvent");
eventEntity.setEventProcess("deviceLoginSaveOrUpdate");
QueueEventBody eventBody = new QueueEventBody("com.ifish7.mq.business.device.entity.TblDevice",data);
eventEntity.setEventBody(eventBody);
//温度开关更新
sendDataQueueMessage(JSONObject.toJSONString(eventEntity));
//更新设备信息
// deviceService.update(receive);
deviceService.update(receive);
// if(device==null){
// String HexDump = ByteUtil.toHex(receive.getType())+ByteUtil.toHex(receive.getCheck_code())+ByteUtil.bytesToHexString(receive.getSrc())+ByteUtil.bytesToHexString(destBytes)+ByteUtil.toHex(receive.getRemote_len())+ByteUtil.toHex(receive.getVendor())+ByteUtil.toHex(receive.getHardware_type())+ByteUtil.toHex(receive.getVersion())+ByteUtil.bytesToHexString(receive.getLogin_ip())+ByteUtil.bytesToHexString(receive.getCrc16_code());
// log.error("HexDump:{}",HexDump);
@ -237,21 +174,10 @@ public class SomeServer {
// }
// else{
//记录登录时间
JSONObject data1 = new JSONObject();
data1.put("macAddress",stcMac);
QueueEventEntity eventEntity1 = new QueueEventEntity();
eventEntity1.setEventName("com.ifish7.mq.queues.event.DeviceInfoEvent");
eventEntity1.setEventProcess("deviceLoginLogSave");
QueueEventBody eventBody1 = new QueueEventBody("com.ifish7.mq.business.device.entity.TblLoginRecord",data1);
eventEntity1.setEventBody(eventBody1);
//登录记录保存
sendDataQueueMessage(JSONObject.toJSONString(eventEntity1));
// LoginRecord loginRecord = new LoginRecord();
// loginRecord.setMacAddress(strSrc);
// loginRecord.setLoginTime(new Date());
// deviceService.save(loginRecord);
LoginRecord loginRecord = new LoginRecord();
loginRecord.setMacAddress(strSrc);
loginRecord.setLoginTime(new Date());
deviceService.save(loginRecord);
// }
} catch (Exception e) {
log.error("save device login error:macAddress:{},error msg:{}",strSrc,e.toString());
@ -301,34 +227,19 @@ public class SomeServer {
//查找设备
Device device = this.deviceService.getUniqueByProperty("macAddress", strSrc);
if(device!=null){
JSONObject data = new JSONObject();
data.put("macAddress",strSrc);
//是否升级
if(device.getIsUpgrade().equals(BooleanEnum.YES.getKey())){
data.put("isUpgrade",BooleanEnum.NO.getKey());
data.put("upgradeTime", LocalDateTime.now());
//
// device.setIsUpgrade(BooleanEnum.NO.getKey());
// device.setUpgradeTime(new Date());
device.setIsUpgrade(BooleanEnum.NO.getKey());
device.setUpgradeTime(new Date());
//升级版本
int upgradeVersion = device.getUpgradeVersion();
OrderFunctionCode15 model = OrderModel.OrderFunctionCode15(macBytes,upgradeVersion);
session.write(model);
}
data.put("sdkTime",IfishUtil.StrToDate(receive.getYear()+"-"+(receive.getMonth() & 0xff)+"-"+(receive.getDay() & 0xff)));
data.put("sdkVersion",receive.getVersion() & 0xff);
QueueEventEntity eventEntity = new QueueEventEntity();
eventEntity.setEventName("com.ifish7.mq.queues.event.DeviceInfoEvent");
eventEntity.setEventProcess("deviceSdkUpdate");
QueueEventBody eventBody = new QueueEventBody("com.ifish7.mq.business.device.entity.TblDevice",data);
eventEntity.setEventBody(eventBody);
//设备sdk更新
sendDataQueueMessage(JSONObject.toJSONString(eventEntity));
//记录参数
// device.setSdkVersion(receive.getVersion() & 0xff);
// device.setSdkTime(IfishUtil.StrToDate(receive.getYear()+"-"+(receive.getMonth() & 0xff)+"-"+(receive.getDay() & 0xff)));
// this.deviceService.update(device);
device.setSdkVersion(receive.getVersion() & 0xff);
device.setSdkTime(IfishUtil.StrToDate(receive.getYear()+"-"+(receive.getMonth() & 0xff)+"-"+(receive.getDay() & 0xff)));
this.deviceService.update(device);
}
} catch (Exception e) {
log.error("save device sdk version16 error:macAddress:{},error msg:{}",strSrc,e.toString());
@ -342,53 +253,32 @@ public class SomeServer {
try {
//查找设备
Device device = this.deviceService.getUniqueByProperty("macAddress", strSrc);
JSONObject data = new JSONObject();
data.put("macAddress",strSrc);
if(device!=null){
//是否升级
if(device.getIsUpgrade().equals(BooleanEnum.YES.getKey())){
data.put("isUpgrade",BooleanEnum.NO.getKey());
data.put("upgradeTime", LocalDateTime.now());
// device.setIsUpgrade(BooleanEnum.NO.getKey());
// device.setUpgradeTime(new Date());
device.setIsUpgrade(BooleanEnum.NO.getKey());
device.setUpgradeTime(new Date());
//升级版本
int upgradeVersion = device.getUpgradeVersion();
OrderFunctionCode15 model = OrderModel.OrderFunctionCode15(macBytes,upgradeVersion);
session.write(model);
}
data.put("sdkTime",IfishUtil.StrToDate(receive.getYear()+"-"+(receive.getMonth() & 0xff)+"-"+(receive.getDay() & 0xff)));
data.put("sdkVersion",receive.getVersion() & 0xff);
data.put("number1",receive.getNumber1());
data.put("number2",receive.getNumber2());
data.put("number3",receive.getNumber3());
data.put("number4",receive.getNumber4());
data.put("number5",receive.getNumber5());
QueueEventEntity eventEntity = new QueueEventEntity();
eventEntity.setEventName("com.ifish7.mq.queues.event.DeviceInfoEvent");
eventEntity.setEventProcess("deviceSdkUpdate");
QueueEventBody eventBody = new QueueEventBody("com.ifish7.mq.business.device.entity.TblDevice",data);
eventEntity.setEventBody(eventBody);
//设备sdk更新
sendDataQueueMessage(JSONObject.toJSONString(eventEntity));
//记录参数
// device.setSdkVersion(receive.getVersion() & 0xff);
// device.setSdkTime(IfishUtil.StrToDate(receive.getYear()+"-"+(receive.getMonth() & 0xff)+"-"+(receive.getDay() & 0xff)));
// device.setNumber1(receive.getNumber1());
// device.setNumber2(receive.getNumber2());
// device.setNumber3(receive.getNumber3());
// device.setNumber4(receive.getNumber4());
// device.setNumber5(receive.getNumber5());
// this.deviceService.update(device);
device.setSdkVersion(receive.getVersion() & 0xff);
device.setSdkTime(IfishUtil.StrToDate(receive.getYear()+"-"+(receive.getMonth() & 0xff)+"-"+(receive.getDay() & 0xff)));
device.setNumber1(receive.getNumber1());
device.setNumber2(receive.getNumber2());
device.setNumber3(receive.getNumber3());
device.setNumber4(receive.getNumber4());
device.setNumber5(receive.getNumber5());
this.deviceService.update(device);
}
} catch (Exception e) {
log.error("save device sdk version17 error:macAddress:{},error msg:{}",strSrc,e.toString());
}
}
}
/**
* 发送数据APP
* @param message 发送对象
@ -430,6 +320,12 @@ public class SomeServer {
session.write(model);
}
}
/**
* 温度预警推送
* @param strSrc
* @param title
* @param contont
*/
/**
* 温度预警推送
* @param strSrc
@ -453,27 +349,9 @@ public class SomeServer {
String msg = ""+title+"】你的水族箱“"+showName+"”在"+timestamp+contont;
User user = userService.findById(userId);
if(user!=null){
//云信推送
// boolean neteaseBln = false;
//极光推送
// boolean jpushIosBln = false;
// boolean jpushAndroidBln = false;
//发送云信消息
// Map<String, String> neteaseMap = neteaseIM.sendMsg("ifish", userId.toString(), msg);
// if(neteaseMap!=null){
// neteaseBln = neteaseMap.get("code").equals(NeteaseEnum.status200.getKey());
// }
// String loginType = user.getLoginType();
// if(loginType!=null){
//推送记录
//推送记录
PushList pushList = new PushList();
// Map<String,String> map = new HashMap<String, String>();
// map.put("device_id", deviceId.toString());
// map.put("device_name", showName);
// map.put("timestamp", timestamp);
// map.put("msg_type", PushTypeEnum.wendu_warn.getKey());
//记录推送
// if(jpushIosBln || jpushAndroidBln || neteaseBln){
pushList.setUserId(userId);
pushList.setDeviceId(deviceId);
pushList.setPhoneType("ALL");
@ -481,8 +359,6 @@ public class SomeServer {
pushList.setPushType(PushTypeEnum.wendu_warn.getKey());
pushList.setPushTitle(title);
pushList.setPushContext(msg);
// pushList.setNeteaseStatus(neteaseBln?BooleanEnum.YES.getKey():BooleanEnum.NO.getKey());
// pushList.setCreateTime(new Date());
pushList.setNumber1(device.getNumber1());
pushList.setNumber2(device.getNumber2());
pushList.setNumber3(device.getNumber3());
@ -496,12 +372,8 @@ public class SomeServer {
eventEntity.setEventBody(eventBody);
//推送至消息推送队列
sendPushQueueMessage(JSONObject.toJSONString(eventEntity));
// this.userService.save(pushList);
// }
// }
}
}
}
}
} catch (Exception e) {
@ -509,19 +381,76 @@ public class SomeServer {
}
}
/**
* 推送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) {
private void sendPushQueueMessage(final String json) throws JMSException{
jmsTemplate.send(ifish7PushQueueDestination,(Session session) -> session.createTextMessage(json));
}
/*public void pushNotifcation(String strSrc,String title,String contont){
try {
Device device = deviceService.getUniqueByProperty("macAddress", strSrc);
if(device!=null){
Integer deviceId = device.getDeviceId();
//是否开启预警
String onOff = device.getOnOff();
if(onOff!=null && onOff.equals(BooleanEnum.YES.getKey())){
//绑定设备的用户
List<DeviceUser> list = deviceService.getListByProperty(device.getDeviceId());
for (DeviceUser deviceUser : list) {
Integer userId = deviceUser.getPriId().getUserId();
String showName = deviceUser.getShowName();
String timestamp = IfishUtil.format(new Date());
String msg = ""+title+"】你的水族箱“"+showName+"”在"+timestamp+contont;
User user = userService.findById(userId);
if(user!=null){
//云信推送
boolean neteaseBln = false;
//极光推送
boolean jpushIosBln = false;
boolean jpushAndroidBln = false;
//发送云信消息
Map<String, String> neteaseMap = neteaseIM.sendMsg("ifish", userId.toString(), msg);
if(neteaseMap!=null){
neteaseBln = neteaseMap.get("code").equals(NeteaseEnum.status200.getKey());
}
String loginType = user.getLoginType();
if(loginType!=null){
//推送记录
PushList pushList = new PushList();
Map<String,String> map = new HashMap<String, String>();
map.put("device_id", deviceId.toString());
map.put("device_name", showName);
map.put("timestamp", timestamp);
map.put("msg_type", PushTypeEnum.wendu_warn.getKey());
//记录推送
if(jpushIosBln || jpushAndroidBln || neteaseBln){
pushList.setUserId(userId);
pushList.setDeviceId(deviceId);
pushList.setPhoneType(loginType.toLowerCase());
pushList.setShowName(showName);
pushList.setPushType(PushTypeEnum.wendu_warn.getKey());
pushList.setPushTitle(title);
pushList.setPushContext(msg);
pushList.setNeteaseStatus(neteaseBln?BooleanEnum.YES.getKey():BooleanEnum.NO.getKey());
pushList.setCreateTime(new Date());
pushList.setNumber1(device.getNumber1());
pushList.setNumber2(device.getNumber2());
pushList.setNumber3(device.getNumber3());
pushList.setNumber4(device.getNumber4());
pushList.setNumber5(device.getNumber5());
this.userService.save(pushList);
}
}
}
}
}
}
} catch (Exception e) {
log.error("pushNotifcation error:macAddress:{},error msg:{}",strSrc,e.toString());
}
}*/
}

View File

@ -1,11 +0,0 @@
package com.ifish.util;
/**
* @author: yan.y
* @Description: json工具
* @Date: Created in 16:46 2019-04-10
* @Modified by:
*/
public class QueueMessageJsonUtil {
}

View File

@ -3,7 +3,7 @@ log4j.rootLogger=INFO,CONSOLE,FILE,ROLLING_FILE
# Console Appender
###################
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.Threshold=INFO
log4j.appender.Threshold=DEBUG
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[ifish7Socket][%-5p]%d - (%F:%L) - %m%n
@ -11,7 +11,7 @@ log4j.appender.CONSOLE.layout.ConversionPattern=[ifish7Socket][%-5p]%d - (%F:%L)
# [INFO]Daily Rolling File
########################
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.Threshold=INFO
log4j.appender.FILE.Threshold=DEBUG
log4j.appender.FILE.File=/logs/ifishSocket/ifish7Socket_ALL.log
log4j.appender.FILE.Append=true
log4j.appender.FILE.ImmediateFlush = true
@ -31,7 +31,8 @@ log4j.appender.ROLLING_FILE.DatePattern='.'yyyy-MM-dd
log4j.appender.ROLLING_FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLLING_FILE.layout.ConversionPattern=[Ifish7][%-5p]%d - %c.%t(%F:%L) - %m%n
log4j.logger.com.ifish=DEBUG
log4j.logger.org.springframework=INFO
log4j.logger.com.hibernate=INFO
log4j.logger.java.sql=INFO
log4j.logger.java.sql=DEBUG

View File

@ -46,18 +46,21 @@
<level>WARN</level>
</filter>
</appender>
<!-- 记录设备连接数量-->
<logger name="com.ifish.socketNew.MinaServerHandler" level="INFO" additivity="false">
<appender-ref ref="file" />
<!-- <appender-ref ref="Console" /> -->
<logger name="com.hibernate" level="DEBUG" additivity="false">
<appender-ref ref="Console" />
</logger>
<logger name="org.springframework" level="DEBUG" additivity="false">
<appender-ref ref="Console" />
</logger>
<logger name="java.sql" level="DEBUG" additivity="false">
<appender-ref ref="Console" />
</logger>
<!-- 将级别为“info”及大于“info”的日志信息传递给root处理本身并不打印 -->
<root level="info">
<!-- root将级别为“INFO”及大于“INFO”的日志信息交给已经配置好的名为“Console”的appender处理“Console”appender将信息打印到Console -->
<appender-ref ref="file2" />
<!-- <appender-ref ref="Console" /> -->
<appender-ref ref="Console" />
<!-- 标识这个appender将会添加到这个logger -->
<!-- <appender-ref ref="File" /> -->
</root>

View File

@ -1,4 +1,5 @@
broker_url=tcp://test.ifish7.com:61616
#broker_url=tcp://test.ifish7.com:61616
broker_url=tcp://www.ifish7.com:61616
username=admin
#password=admin
password=adminifish7

View File

@ -5,7 +5,7 @@
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>

View File

@ -7,12 +7,12 @@ import com.ifish.util.IfishUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
//import org.springframework.jms.core.JmsTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.jms.Destination;
import javax.jms.Session;
//import javax.jms.Destination;
//import javax.jms.Session;
import java.util.Date;
/**
@ -21,55 +21,55 @@ import java.util.Date;
* @Date: Created in 16:20 2019-04-10
* @Modified by:
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:application-context.xml")
//@RunWith(SpringJUnit4ClassRunner.class)
//@ContextConfiguration(locations="classpath:application-context.xml")
public class SomeServerQueueTest {
@Autowired
private JmsTemplate jmsTemplate;
@Autowired
private Destination ifish7DataQueueDestination;
@Autowired
private Destination ifish7PushQueueDestination;
@Test
public void testDataMessageSend(){
String json = "this's a test message";
JSONObject data = new JSONObject();
data.put("heaterMacAddress","12345");
data.put("heaterWaterTemperature","130");
data.put("heaterPh","1200");
data.put("heaterGatheringDate", IfishUtil.format1(new Date()));
data.put("heaterGatheringTime","17");
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);
String eventEntityStr = JSONObject.toJSONString(eventEntity);
jmsTemplate.send(ifish7DataQueueDestination,(Session session) -> session.createTextMessage(eventEntityStr));
}
@Test
public void testPushMessageSend(){
String json = "this's a test message";
JSONObject data = new JSONObject();
data.put("heaterMacAddress","12345");
data.put("heaterWaterTemperature","130");
data.put("heaterPh","1200");
data.put("heaterGatheringDate", IfishUtil.format1(new Date()));
data.put("heaterGatheringTime","17");
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);
String eventEntityStr = JSONObject.toJSONString(eventEntity);
//智能加热棒数据更新及保存
jmsTemplate.send(ifish7PushQueueDestination,(Session session) -> session.createTextMessage(eventEntityStr));
}
// @Autowired
// private JmsTemplate jmsTemplate;
//
// @Autowired
// private Destination ifish7DataQueueDestination;
// @Autowired
// private Destination ifish7PushQueueDestination;
//
// @Test
// public void testDataMessageSend(){
// String json = "this's a test message";
// JSONObject data = new JSONObject();
// data.put("heaterMacAddress","12345");
// data.put("heaterWaterTemperature","130");
// data.put("heaterPh","1200");
// data.put("heaterGatheringDate", IfishUtil.format1(new Date()));
// data.put("heaterGatheringTime","17");
//
// 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);
//
// String eventEntityStr = JSONObject.toJSONString(eventEntity);
// //jmsTemplate.send(ifish7DataQueueDestination,(Session session) -> session.createTextMessage(eventEntityStr));
// }
//
// @Test
// public void testPushMessageSend(){
// String json = "this's a test message";
// JSONObject data = new JSONObject();
// data.put("heaterMacAddress","12345");
// data.put("heaterWaterTemperature","130");
// data.put("heaterPh","1200");
// data.put("heaterGatheringDate", IfishUtil.format1(new Date()));
// data.put("heaterGatheringTime","17");
//
// 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);
//
// String eventEntityStr = JSONObject.toJSONString(eventEntity);
// //智能加热棒数据更新及保存
// //jmsTemplate.send(ifish7PushQueueDestination,(Session session) -> session.createTextMessage(eventEntityStr));
// }
}