From 1d8f1272627d899c7eb75c443b1b49434763c9f6 Mon Sep 17 00:00:00 2001 From: yiyan Date: Mon, 15 Apr 2019 21:50:00 +0800 Subject: [PATCH] =?UTF-8?q?v4.6.9=E7=89=88=E6=9C=ACBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ifish/quartz/ExecuteJob.java | 113 +++---- .../java/com/ifish/socketNew/SomeServer.java | 294 +++++------------- .../socketNew/codeFactory/ServerDecode.java | 10 +- src/main/resources/application-context.xml | 14 +- src/main/resources/jdbc.properties | 12 +- src/main/resources/property.properties | 2 +- 6 files changed, 139 insertions(+), 306 deletions(-) diff --git a/src/main/java/com/ifish/quartz/ExecuteJob.java b/src/main/java/com/ifish/quartz/ExecuteJob.java index efd1143..7b281e6 100644 --- a/src/main/java/com/ifish/quartz/ExecuteJob.java +++ b/src/main/java/com/ifish/quartz/ExecuteJob.java @@ -5,10 +5,6 @@ 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.event.QueueEventBody; -import com.ifish.entity.event.QueueEventEntity; import org.apache.mina.core.session.IoSession; import org.quartz.Job; import org.quartz.JobDataMap; @@ -29,13 +25,9 @@ import com.ifish.netease.NeteaseIM; import com.ifish.service.DeviceService; import com.ifish.service.UserService; import com.ifish.socketNew.SomeServer; -import org.springframework.jms.core.JmsTemplate; - -import javax.jms.Destination; -import javax.jms.Session; public class ExecuteJob implements Job { - + private static Logger log = LoggerFactory.getLogger(ExecuteJob.class); @Autowired private NeteaseIM neteaseIM; @@ -43,26 +35,22 @@ public class ExecuteJob implements Job { 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 { - //移除为null的连接 - IoSession session_cz = SomeServer.sessions_cz.get(macAddress); + public void execute(JobExecutionContext context) throws JobExecutionException { + //任务传递的参数 + JobDataMap dataMap = context.getJobDetail().getJobDataMap(); + String macAddress = dataMap.getString("macAddress"); + String timestamp = dataMap.getString("timestamp"); + try { + //移除为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){ - //记录次数 + //设备是否存在 + Device device = deviceService.getUniqueByProperty("macAddress", macAddress); + if(device!=null){ + //记录次数 Integer number1 = device.getNumber1(); Integer number2 = device.getNumber2(); Integer number3 = device.getNumber3(); @@ -77,50 +65,42 @@ public class ExecuteJob implements Job { String title = PushTypeEnum.offline_push.getValue(); String msg = "【"+title+"】你的水族箱“"+showName+"”于"+timestamp+"离线,请及时查看!"; //发送云信消息 -// boolean neteaseBln = false; -// Map neteaseMap = neteaseIM.sendMsg("ifish", userId.toString(), msg); -// if(neteaseMap!=null){ -// neteaseBln = neteaseMap.get("code").equals(NeteaseEnum.status200.getKey()); -// } + boolean neteaseBln = false; + Map neteaseMap = neteaseIM.sendMsg("ifish", userId.toString(), msg); + if(neteaseMap!=null){ + neteaseBln = neteaseMap.get("code").equals(NeteaseEnum.status200.getKey()); + } //IOS极光推送 -// boolean jpushIosBln = false; + boolean jpushIosBln = false; //推送记录 PushList pushList = new PushList(); Integer deviceId = deviceUser.getPriId().getDeviceId(); User user = userService.findById(userId); if(user!=null){ -// String loginType = user.getLoginType(); -// if(loginType!=null){ -// Map map = new HashMap(); -// map.put("device_id", deviceId.toString()); -// map.put("device_name", showName); -// map.put("timestamp", timestamp); -// map.put("msg_type", PushTypeEnum.offline_push.getKey()); + String loginType = user.getLoginType(); + if(loginType!=null){ + Map map = new HashMap(); + map.put("device_id", deviceId.toString()); + map.put("device_name", showName); + map.put("timestamp", timestamp); + map.put("msg_type", PushTypeEnum.offline_push.getKey()); //推送记录 - pushList.setUserId(userId); - pushList.setDeviceId(deviceId); - pushList.setPhoneType("ALL"); - pushList.setShowName(showName); - pushList.setPushType(PushTypeEnum.offline_push.getKey()); -// pushList.setNeteaseStatus(neteaseBln?BooleanEnum.YES.getKey():BooleanEnum.NO.getKey()); - pushList.setPushTitle(title); - pushList.setPushContext(msg); -// pushList.setCreateTime(new Date()); - pushList.setNumber1(number1); - pushList.setNumber2(number2); - pushList.setNumber3(number3); - pushList.setNumber4(number4); - pushList.setNumber5(number5); - 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); -// } + pushList.setUserId(userId); + pushList.setDeviceId(deviceId); + pushList.setPhoneType(loginType.toLowerCase()); + pushList.setShowName(showName); + pushList.setPushType(PushTypeEnum.offline_push.getKey()); + pushList.setNeteaseStatus(neteaseBln?BooleanEnum.YES.getKey():BooleanEnum.NO.getKey()); + pushList.setPushTitle(title); + pushList.setPushContext(msg); + pushList.setCreateTime(new Date()); + pushList.setNumber1(number1); + pushList.setNumber2(number2); + pushList.setNumber3(number3); + pushList.setNumber4(number4); + pushList.setNumber5(number5); + this.userService.save(pushList); + } } } } @@ -129,14 +109,5 @@ public class ExecuteJob implements Job { e.printStackTrace(); log.error("error msg:{}",e.toString()); } - } - - /** - * 推送Push消息队列 - * @param json 内容 - */ - private void sendPushQueueMessage(final String json) { - jmsTemplate.send(ifish7PushQueueDestination,(Session session) -> session.createTextMessage(json)); } - } \ No newline at end of file diff --git a/src/main/java/com/ifish/socketNew/SomeServer.java b/src/main/java/com/ifish/socketNew/SomeServer.java index 164c5f8..656189d 100644 --- a/src/main/java/com/ifish/socketNew/SomeServer.java +++ b/src/main/java/com/ifish/socketNew/SomeServer.java @@ -1,16 +1,12 @@ package com.ifish.socketNew; -import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArraySet; -import com.alibaba.fastjson.JSON; -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.buffer.IoBuffer; import org.apache.mina.core.session.IoSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,17 +30,13 @@ 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; /** * 这个类主要是通过spring注入给MinaServerHandler用的, 表示: mina在接收到信息后,该由主要业务类来处理 服务器处理类 **/ public class SomeServer { - + @Autowired private UserService userService; @Autowired @@ -53,21 +45,15 @@ 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; - + private static Logger log = LoggerFactory.getLogger(SomeServer.class); public static final ConcurrentHashMap remoteAddress = new ConcurrentHashMap(); public static final ConcurrentHashMap sessions_cz = new ConcurrentHashMap(); private ConcurrentHashMap> sessions_sjs = new ConcurrentHashMap>(); - + /** * 过滤收到的数据 服务器收到数据,进行协议类型匹配,如果不匹配,则不执行相应操作。 * @param session @@ -76,18 +62,20 @@ public class SomeServer { public void doSome(IoSession session, Object message) { //通配字符串 if(message instanceof byte[]){ - byte[] bytes = (byte[]) message; //长度 int length = bytes[14] & 0xff; + 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); - //心跳 - if(length>=28){ + //如果为设备端返回 发送给app端 + if(type == 1){ sendToApp(session,strSrc, message); } else{ @@ -98,31 +86,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 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 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); @@ -138,17 +110,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); @@ -192,41 +154,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); @@ -234,21 +163,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()); @@ -298,34 +216,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()); @@ -339,53 +242,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 发送对象 @@ -451,74 +333,50 @@ public class SomeServer { User user = userService.findById(userId); if(user!=null){ //云信推送 -// boolean neteaseBln = false; + boolean neteaseBln = false; //极光推送 -// boolean jpushIosBln = false; -// boolean jpushAndroidBln = false; + boolean jpushIosBln = false; + boolean jpushAndroidBln = false; //发送云信消息 -// Map 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){ + Map 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 map = new HashMap(); -// 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"); - 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()); - 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); -// } -// } + PushList pushList = new PushList(); + Map map = new HashMap(); + 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()); } } - - /** - * 推送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)); - } } diff --git a/src/main/java/com/ifish/socketNew/codeFactory/ServerDecode.java b/src/main/java/com/ifish/socketNew/codeFactory/ServerDecode.java index 06b2276..274f1cc 100644 --- a/src/main/java/com/ifish/socketNew/codeFactory/ServerDecode.java +++ b/src/main/java/com/ifish/socketNew/codeFactory/ServerDecode.java @@ -71,6 +71,7 @@ public class ServerDecode implements ProtocolDecoder { private void getValid(IoSession session, IoBuffer buf, ProtocolDecoderOutput out){ int limit = buf.remaining(); int check_code = buf.position(1).get() & 0xff; + int length = buf.position(14).get() & 0xff; buf.position(0); //计算包长度 @@ -101,11 +102,10 @@ public class ServerDecode implements ProtocolDecoder { //crc16校验 //boolean bln = CRC16.calcCrc16(ByteUtil.hexStringToBytes(hexDump)); switch (length) { - //长度为22 case 31: { functionBackHeater(bytes,buf, out); break; - } + }//长度为22 case 22:{ //设置报警温度 if(check_code==5){ @@ -128,6 +128,8 @@ public class ServerDecode implements ProtocolDecoder { case 24:{ if(check_code==1){ functionCode1(buf, out); + } else { + out.write(bytes); } break; } @@ -135,6 +137,8 @@ public class ServerDecode implements ProtocolDecoder { case 25:{ if(check_code==0){ functionCode0(buf, out); + } else { + out.write(bytes); } break; } @@ -142,6 +146,8 @@ public class ServerDecode implements ProtocolDecoder { case 42:{ if(check_code==17){ functionCode17(buf, out); + } else { + out.write(bytes); } break; } diff --git a/src/main/resources/application-context.xml b/src/main/resources/application-context.xml index f4d8376..2885616 100644 --- a/src/main/resources/application-context.xml +++ b/src/main/resources/application-context.xml @@ -90,24 +90,22 @@ - + - - + - - + \ No newline at end of file diff --git a/src/main/resources/jdbc.properties b/src/main/resources/jdbc.properties index 730b740..57b078a 100644 --- a/src/main/resources/jdbc.properties +++ b/src/main/resources/jdbc.properties @@ -1,10 +1,10 @@ c3p0.driverClassName=com.mysql.jdbc.Driver -c3p0.url=jdbc\:mysql\://localhost\:3306/myfishdb?characterEncoding\=UTF-8 -#c3p0.url=jdbc\:mysql\://139.196.24.156\:3306/myfishdb?characterEncoding\=UTF-8 -c3p0.username=ifish -c3p0.password=ifish7pwd -#c3p0.username=root -#c3p0.password=ifish7mysql +#c3p0.url=jdbc\:mysql\://localhost\:3306/myfishdb?characterEncoding\=UTF-8 +c3p0.url=jdbc\:mysql\://139.196.24.156\:3306/myfishdb?characterEncoding\=UTF-8 +#c3p0.username=ifish +#c3p0.password=ifish7pwd +c3p0.username=root +c3p0.password=ifish7mysql #c3p0.username=root #c3p0.password=123456 diff --git a/src/main/resources/property.properties b/src/main/resources/property.properties index 117e57f..336e3d6 100644 --- a/src/main/resources/property.properties +++ b/src/main/resources/property.properties @@ -1,5 +1,5 @@ #\u672c\u5730 -#ifish.ip=192.168.31.83 +#ifish.ip=192.168.1.13 #\u6d4b\u8bd5\u4e91 #ifish.ip=139.196.24.156 #\u6b63\u5f0f\u4e91