diff --git a/ifishMQ.iml b/ifishMQ.iml
index c2d4d54..680dd2f 100644
--- a/ifishMQ.iml
+++ b/ifishMQ.iml
@@ -27,6 +27,7 @@
+
diff --git a/src/main/java/com/ifish7/mq/queues/event/DeviceInfoEvent.java b/src/main/java/com/ifish7/mq/queues/event/DeviceInfoEvent.java
new file mode 100644
index 0000000..9dc6e48
--- /dev/null
+++ b/src/main/java/com/ifish7/mq/queues/event/DeviceInfoEvent.java
@@ -0,0 +1,30 @@
+package com.ifish7.mq.queues.event;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ifish7.mq.business.device.entity.TblDevice;
+import com.ifish7.mq.business.device.service.ITblDeviceService;
+import com.ifish7.mq.business.device.service.impl.TblDeviceServiceImpl;
+import com.ifish7.mq.queues.event.support.EventSupport;
+import com.ifish7.mq.utils.AppBeans;
+import lombok.extern.log4j.Log4j;
+
+/**
+ * @author: yan.y
+ * @Description: 设备信息事件
+ * @Date: Created in 09:34 2019-04-10
+ * @Modified by:
+ */
+@Log4j
+public class DeviceInfoEvent extends EventSupport {
+
+
+ public void updateWarnOnoff() {
+ log.info("DeviceInfoEvent eventBody : " + eventBody);
+ TblDevice device = (TblDevice) this.eventEntity;
+ ITblDeviceService deviceService = AppBeans.getBean(TblDeviceServiceImpl.class);
+ TblDevice tblDevice = deviceService.getOne(new QueryWrapper().lambda().eq(TblDevice::getMacAddress, device.getMacAddress()));
+ tblDevice.setOnOff(device.getOnOff());
+ deviceService.updateById(tblDevice);
+ }
+
+}
diff --git a/src/main/java/com/ifish7/mq/queues/event/IntelligentHeatingRodEvent.java b/src/main/java/com/ifish7/mq/queues/event/IntelligentHeatingRodEvent.java
index 52ef057..19effba 100644
--- a/src/main/java/com/ifish7/mq/queues/event/IntelligentHeatingRodEvent.java
+++ b/src/main/java/com/ifish7/mq/queues/event/IntelligentHeatingRodEvent.java
@@ -1,7 +1,5 @@
package com.ifish7.mq.queues.event;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ifish7.mq.business.device.entity.TblDeviceHeater;
import com.ifish7.mq.business.device.service.ITblDeviceHeaterService;
@@ -32,16 +30,13 @@ public class IntelligentHeatingRodEvent extends EventSupport {
* "heaterGatheringTime": "08",
* "heaterGatheringDate": "2019-04-09"
* }
- ** }
+ * }
* }
- * @param eventBody
*/
- public void intelligentHeatingRodSaveOrUpdate(String eventBody){
- log.info("eventBody : " + eventBody);
- JSONObject json = JSON.parseObject(eventBody);
- String entity = json.getString("entity");
+ public void intelligentHeatingRodSaveOrUpdate(){
+ log.info("intelligentHeatingRodSaveOrUpdate eventBody : " + eventBody);
try {
- TblDeviceHeater deviceHeater = (TblDeviceHeater) JSON.parseObject(json.getString("data"), Class.forName(entity));
+ TblDeviceHeater deviceHeater = (TblDeviceHeater) super.eventEntity;
//获取service
ITblDeviceHeaterService deviceHeaterService = AppBeans.getBean(TblDeviceHeaterServiceImpl.class);
//查询
@@ -58,7 +53,7 @@ public class IntelligentHeatingRodEvent extends EventSupport {
//新增
deviceHeaterService.save(deviceHeater);
}
- } catch (ClassNotFoundException e) {
+ } catch (Exception e) {
log.info(e.getMessage(),e);
}
}
diff --git a/src/main/java/com/ifish7/mq/queues/event/support/EventSupport.java b/src/main/java/com/ifish7/mq/queues/event/support/EventSupport.java
index 4d9a07a..af98c43 100644
--- a/src/main/java/com/ifish7/mq/queues/event/support/EventSupport.java
+++ b/src/main/java/com/ifish7/mq/queues/event/support/EventSupport.java
@@ -1,5 +1,7 @@
package com.ifish7.mq.queues.event.support;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.extern.log4j.Log4j;
@@ -22,16 +24,32 @@ public class EventSupport {
//事件体
protected String eventBody;
+ //事件体对象
+ protected Object eventEntity;
+
//事件处理
public void process() {
try {
+ parseEventEntity();
Class> eventClazz = Class.forName(this.eventName);
- Method method = eventClazz.getMethod(this.eventProcess, Class.forName("java.lang.String"));
+ Method method = eventClazz.getMethod(this.eventProcess);
method.setAccessible(true);
- method.invoke(eventClazz.newInstance(),this.eventBody);
+ method.invoke(eventClazz.newInstance());
} catch (Exception e) {
log.info(e.getMessage(),e);
}
}
+ private void parseEventEntity(){
+ JSONObject json = JSON.parseObject(eventBody);
+ String entity = json.getString("entity");
+ try {
+ this.eventEntity = JSON.parseObject(json.getString("data"),Class.forName(entity));
+ } catch (Exception e) {
+ log.error(e.getMessage(),e);
+ }
+
+
+ }
+
}
diff --git a/src/main/resources/jdbc.properties b/src/main/resources/jdbc.properties
index 8362d6d..44c2fc2 100644
--- a/src/main/resources/jdbc.properties
+++ b/src/main/resources/jdbc.properties
@@ -1,12 +1,12 @@
jdbc.driver=com.mysql.jdbc.Driver
-jdbc.url=jdbc\:mysql\://localhost\:3306/myfishdb?characterEncoding\=UTF-8
-#jdbc.url=jdbc\:mysql\://139.196.24.156\:3306/myfishdb?characterEncoding\=UTF-8
-jdbc.username=root
-jdbc.password=123456
+#jdbc.url=jdbc\:mysql\://localhost\:3306/myfishdb?characterEncoding\=UTF-8
+jdbc.url=jdbc\:mysql\://139.196.24.156\:3306/myfishdb?characterEncoding\=UTF-8
+#jdbc.username=root
+#jdbc.password=123456
#jdbc.username=ifish
#jdbc.password=ifish7pwd
-#jdbc.username=root
-#jdbc.password=ifish7mysql
+jdbc.username=root
+jdbc.password=ifish7mysql
#jdbc.testWhileIdle=true
jdbc.validationQuery=SELECT * FROM DUAL
initialSize=1
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index b715903..fe97d65 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -17,7 +17,7 @@
contextConfigLocation
- classpath:spring-mq.xml
+ classpath:spring-main.xml