Selaa lähdekoodia

- 新增报警信息上传;

Gizmo 2 vuotta sitten
vanhempi
commit
f6102f6c62

+ 1 - 1
src/main/java/com/warewms/model/_MappingKit.java

@@ -19,7 +19,7 @@ public class _MappingKit {
 		arp.addMapping("accounts_users", "UserID", AccountsUsers.class);
 		arp.addMapping("bind_manage", "MANAGE_ID", BindManage.class);
 		arp.addMapping("bind_phone", "MANAGE_ID", BindPhone.class);
-		arp.addMapping("mach_alarm_records", "alarm_id", MachAlarmRecords.class);
+		arp.addMapping("mach_alarm_records", "alarm_id,mach_no", MachAlarmRecords.class);
 		arp.addMapping("message", "message_id", Message.class);
 		arp.addMapping("rt_device_alarm_flag", "alarm_id", RtDeviceAlarmFlag.class);
 		arp.addMapping("schedule_job", "job_id", ScheduleJob.class);

+ 24 - 0
src/main/java/com/warewms/model/base/BaseMachAlarmRecords.java

@@ -81,6 +81,14 @@ public abstract class BaseMachAlarmRecords<M extends BaseMachAlarmRecords<M>> ex
 		return getStr("alarm_level");
 	}
 
+	public void setAlarmMsg(java.lang.String alarmMsg) {
+		set("alarm_msg", alarmMsg);
+	}
+	
+	public java.lang.String getAlarmMsg() {
+		return getStr("alarm_msg");
+	}
+
 	public void setSysType(java.lang.String sysType) {
 		set("sys_type", sysType);
 	}
@@ -105,4 +113,20 @@ public abstract class BaseMachAlarmRecords<M extends BaseMachAlarmRecords<M>> ex
 		return getStr("img_url");
 	}
 
+	public void setUploadFlag(java.lang.String uploadFlag) {
+		set("upload_flag", uploadFlag);
+	}
+	
+	public java.lang.String getUploadFlag() {
+		return getStr("upload_flag");
+	}
+
+	public void setUploadTime(java.util.Date uploadTime) {
+		set("upload_time", uploadTime);
+	}
+	
+	public java.util.Date getUploadTime() {
+		return get("upload_time");
+	}
+
 }

+ 2 - 2
src/main/java/com/warewms/service/HeXunDataService.java

@@ -9,7 +9,7 @@ package com.warewms.service;
 public interface HeXunDataService {
 
     /**
-     * 按照传入的alarmId查询之后是否有新增的报警信息
+     * 定时上报报警信息
      */
-    void saveUnrecordedAlarm4MachineOne();
+    void uploadAlarmData();
 }

+ 12 - 0
src/main/java/com/warewms/service/MachAlarmRecordsService.java

@@ -3,4 +3,16 @@ package com.warewms.service;
 import com.warewms.model.MachAlarmRecords;
 
 public interface MachAlarmRecordsService extends BaseService<MachAlarmRecords> {
+
+    /**
+     * 查询之后是否有新增的报警信息,并进行存储
+     * 1号机器人
+     */
+    void saveUnrecordedAlarm4MachineOne();
+
+    /**
+     * 查询之后是否有新增的报警信息,并进行存储
+     * 2号机器人
+     */
+    void saveUnrecordedAlarm4MachineTwo();
 }

+ 32 - 55
src/main/java/com/warewms/service/impl/HeXunDataServiceImpl.java

@@ -1,5 +1,8 @@
 package com.warewms.service.impl;
 
+import com.warewms.common.utils.HttpRequest;
+import com.warewms.common.utils.JsonUtils;
+import com.warewms.model.HeXunAlarmData;
 import com.warewms.model.MachAlarmRecords;
 import com.warewms.service.HeXunDataService;
 import com.warewms.service.MachAlarmRecordsService;
@@ -23,61 +26,35 @@ public class HeXunDataServiceImpl implements HeXunDataService {
     private MachAlarmRecordsService machAlarmRecordsService;
 
     @Override
-    public void saveUnrecordedAlarm4MachineOne() {
-
-        MachAlarmRecords latestRecord = new MachAlarmRecords();
-        List<MachAlarmRecords> recordsList = latestRecord.find("select * from warewms_message.mach_alarm_records order by alarm_id desc limit 1");
-        int latestAlarmId = recordsList.size() == 0 ? 0 : recordsList.get(0).getAlarmId();
-
-        log.info("latestAlarm:" + latestAlarmId);
-
-        MachAlarmRecords unrecordedAlarm = new MachAlarmRecords();
-        List<MachAlarmRecords> unrecordsList = unrecordedAlarm.find(
-                "SELECT * FROM (\n" +
-                    "select \n" +
-                        "\ta.alarm_id AS 'alarm_id',\n" +
-                        "\t'x521_1' AS 'mach_no', \n" +
-                        "\ta.alarm_mark AS 'alarm_mark',\n" +
-                        "\tSUBSTRING_INDEX(a.alarm_mark, ',', 1) AS 'x_coordinate',\n" +
-                        "\tSUBSTRING_INDEX(a.alarm_mark, ',', -1) AS 'y_coordinate',\n" +
-                        "\ta.alarm_date AS 'timestamp',\n" +
-                        "\t'N/A' AS 'video_url',\n" +
-                        "\tc.device_type AS 'device_type',\n" +
-                        "\ta.alarm_level AS 'alarm_level',\n" +
-                        "\tb.data_img_name AS 'alarm_msg',\n" +
-                        "\t'N/A' AS 'sys_type',\n" +
-                        "\tc.device_name AS 'device_name',\n" +
-                        "\tb.data_img_url AS 'img_url'\n" +
-                    "from x521_1.rt_device_alarm a, x521_1.rt_device_data_inf b, x521_1.rt_device c\n" +
-                    "where a.task_id = b.task_id and a.device_tag = b.device_tag \n" +
-                        "and a.alarm_date = b.data_date and a.device_tag = c.device_tag\n" +
-                    "union all\n" +
-                    "select \n" +
-                        "a.alarm_id AS 'alarm_id',\n" +
-                        "\t'x521_1' AS 'mach_no', \n" +
-                        "\ta.alarm_mark AS 'alarm_mark',\n" +
-                        "\tSUBSTRING_INDEX(a.alarm_mark, ',', 1) AS 'x_coordinate',\n" +
-                        "\tSUBSTRING_INDEX(a.alarm_mark, ',', -1) AS 'y_coordinate',\n" +
-                        "\ta.alarm_date AS 'timestamp',\n" +
-                        "\t'N/A' AS 'video_url',\n" +
-                        "\tc.device_type AS 'device_type',\n" +
-                        "\ta.alarm_level AS 'alarm_level',\n" +
-                        "\tb.data_img_name AS 'alarm_msg',\n" +
-                        "\t'N/A' AS 'sys_type',\n" +
-                        "\tc.device_name AS 'device_name',\n" +
-                        "\tb.data_img_url AS 'img_url'\n" +
-                    "from x521_1.rt_device_alarm a, x521_1.rt_device_data_ins b, x521_1.rt_device c\n" +
-                    "where a.task_id = b.task_id and a.device_tag = b.device_tag \n" +
-                        "and a.alarm_date = b.data_date and a.device_tag = c.device_tag) AS temp\n" +
-                "where temp.alarm_id > " + latestAlarmId);
-
-        log.info("一共有多少条:" + unrecordsList.size());
-
-        for (MachAlarmRecords machAlarmRecords : unrecordsList) {
-
-            machAlarmRecords.save();
-
-            log.info("保存成功:" + machAlarmRecords.getAlarmId());
+    public void uploadAlarmData() {
+
+        MachAlarmRecords queryRecord = new MachAlarmRecords();
+        queryRecord.setUploadFlag("0");
+        List<MachAlarmRecords> machAlarmRecordsList = machAlarmRecordsService.findByModel(queryRecord);
+        for (MachAlarmRecords machAlarmRecords : machAlarmRecordsList) {
+
+            HeXunAlarmData heXunAlarmData = new HeXunAlarmData();
+            heXunAlarmData.setPrivate_key("E46C9E1EB7");
+            heXunAlarmData.setRobotCode(machAlarmRecords.getMachNo());
+            heXunAlarmData.setMapOrientation(machAlarmRecords.getAlarmMark());
+            heXunAlarmData.setXCoord(machAlarmRecords.getXCoordinate());
+            heXunAlarmData.setYCoord(machAlarmRecords.getYCoordinate());
+            heXunAlarmData.setAddTime(machAlarmRecords.getTimestamp());
+            heXunAlarmData.setVideoAddress(machAlarmRecords.getVideoUrl());
+            heXunAlarmData.setAlarmType(machAlarmRecords.getDeviceType());
+            heXunAlarmData.setAlarmLevel(machAlarmRecords.getAlarmLevel());
+            heXunAlarmData.setAlarmContent(machAlarmRecords.getAlarmMsg());
+            heXunAlarmData.setSystemType(machAlarmRecords.getSysType());
+            heXunAlarmData.setDeviceCode(machAlarmRecords.getDeviceName());
+            heXunAlarmData.setAlarmImg(machAlarmRecords.getImgUrl());
+
+            try {
+
+                String response = HttpRequest.postData("http://hxetm.com:20974/Interface_JCHGJT/info/addAlarm.do", JsonUtils.toJson(heXunAlarmData));
+                log.info("http response:" + response);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         }
     }
 }

+ 122 - 0
src/main/java/com/warewms/service/impl/MachAlarmRecordsServiceImpl.java

@@ -3,8 +3,130 @@ package com.warewms.service.impl;
 import com.warewms.dao.MachAlarmRecordsDao;
 import com.warewms.model.MachAlarmRecords;
 import com.warewms.service.MachAlarmRecordsService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Service
+@Slf4j
 public class MachAlarmRecordsServiceImpl extends BaseServiceImpl<MachAlarmRecordsDao, MachAlarmRecords> implements MachAlarmRecordsService {
+
+    @Override
+    public void saveUnrecordedAlarm4MachineOne() {
+
+        MachAlarmRecords latestRecord = new MachAlarmRecords();
+        List<MachAlarmRecords> recordsList = latestRecord.find("select * from warewms_message.mach_alarm_records where mach_no = 'x521_1' order by alarm_id desc limit 1");
+        int latestAlarmId = recordsList.size() == 0 ? 0 : recordsList.get(0).getAlarmId();
+
+        log.info("1号机器人,latestAlarm:" + latestAlarmId);
+
+        MachAlarmRecords unrecordedAlarm = new MachAlarmRecords();
+        List<MachAlarmRecords> unrecordsList = unrecordedAlarm.find(
+                "SELECT * FROM (\n" +
+                        "select \n" +
+                        "\ta.alarm_id AS 'alarm_id',\n" +
+                        "\t'x521_1' AS 'mach_no', \n" +
+                        "\ta.alarm_mark AS 'alarm_mark',\n" +
+                        "\tSUBSTRING_INDEX(a.alarm_mark, ',', 1) AS 'x_coordinate',\n" +
+                        "\tSUBSTRING_INDEX(a.alarm_mark, ',', -1) AS 'y_coordinate',\n" +
+                        "\tUNIX_TIMESTAMP(a.alarm_date) * 1000 AS 'timestamp',\n" +
+                        "\t'N/A' AS 'video_url',\n" +
+                        "\tc.device_type AS 'device_type',\n" +
+                        "\ta.alarm_level AS 'alarm_level',\n" +
+                        "\tb.data_img_name AS 'alarm_msg',\n" +
+                        "\t'N/A' AS 'sys_type',\n" +
+                        "\tc.device_name AS 'device_name',\n" +
+                        "\tb.data_img_url AS 'img_url'\n" +
+                        "from x521_1.rt_device_alarm a, x521_1.rt_device_data_inf b, x521_1.rt_device c\n" +
+                        "where a.task_id = b.task_id and a.device_tag = b.device_tag \n" +
+                        "and a.alarm_date = b.data_date and a.device_tag = c.device_tag\n" +
+                        "union all\n" +
+                        "select \n" +
+                        "a.alarm_id AS 'alarm_id',\n" +
+                        "\t'x521_1' AS 'mach_no', \n" +
+                        "\ta.alarm_mark AS 'alarm_mark',\n" +
+                        "\tSUBSTRING_INDEX(a.alarm_mark, ',', 1) AS 'x_coordinate',\n" +
+                        "\tSUBSTRING_INDEX(a.alarm_mark, ',', -1) AS 'y_coordinate',\n" +
+                        "\tUNIX_TIMESTAMP(a.alarm_date) * 1000 AS 'timestamp',\n" +
+                        "\t'N/A' AS 'video_url',\n" +
+                        "\tc.device_type AS 'device_type',\n" +
+                        "\ta.alarm_level AS 'alarm_level',\n" +
+                        "\tb.data_img_name AS 'alarm_msg',\n" +
+                        "\t'N/A' AS 'sys_type',\n" +
+                        "\tc.device_name AS 'device_name',\n" +
+                        "\tb.data_img_url AS 'img_url'\n" +
+                        "from x521_1.rt_device_alarm a, x521_1.rt_device_data_ins b, x521_1.rt_device c\n" +
+                        "where a.task_id = b.task_id and a.device_tag = b.device_tag \n" +
+                        "and a.alarm_date = b.data_date and a.device_tag = c.device_tag) AS temp\n" +
+                        "where temp.alarm_id > " + latestAlarmId);
+
+        log.info("一号机器人,一共有多少条:" + unrecordsList.size());
+
+        for (MachAlarmRecords machAlarmRecords : unrecordsList) {
+
+            machAlarmRecords.save();
+
+            log.info("一号机器人,保存成功:" + machAlarmRecords.getAlarmId());
+        }
+    }
+
+    @Override
+    public void saveUnrecordedAlarm4MachineTwo() {
+
+        MachAlarmRecords latestRecord = new MachAlarmRecords();
+        List<MachAlarmRecords> recordsList = latestRecord.find("select * from warewms_message.mach_alarm_records where mach_no = 'x521_2' order by alarm_id desc limit 1");
+        int latestAlarmId = recordsList.size() == 0 ? 0 : recordsList.get(0).getAlarmId();
+
+        log.info("2号机器人,latestAlarm:" + latestAlarmId);
+
+        MachAlarmRecords unrecordedAlarm = new MachAlarmRecords();
+        List<MachAlarmRecords> unrecordsList = unrecordedAlarm.find(
+                "SELECT * FROM (\n" +
+                        "select \n" +
+                        "\ta.alarm_id AS 'alarm_id',\n" +
+                        "\t'x521_2' AS 'mach_no', \n" +
+                        "\ta.alarm_mark AS 'alarm_mark',\n" +
+                        "\tSUBSTRING_INDEX(a.alarm_mark, ',', 1) AS 'x_coordinate',\n" +
+                        "\tSUBSTRING_INDEX(a.alarm_mark, ',', -1) AS 'y_coordinate',\n" +
+                        "\tUNIX_TIMESTAMP(a.alarm_date) * 1000 AS 'timestamp',\n" +
+                        "\t'N/A' AS 'video_url',\n" +
+                        "\tc.device_type AS 'device_type',\n" +
+                        "\ta.alarm_level AS 'alarm_level',\n" +
+                        "\tb.data_img_name AS 'alarm_msg',\n" +
+                        "\t'N/A' AS 'sys_type',\n" +
+                        "\tc.device_name AS 'device_name',\n" +
+                        "\tb.data_img_url AS 'img_url'\n" +
+                        "from x521_2.rt_device_alarm a, x521_2.rt_device_data_inf b, x521_2.rt_device c\n" +
+                        "where a.task_id = b.task_id and a.device_tag = b.device_tag \n" +
+                        "and a.alarm_date = b.data_date and a.device_tag = c.device_tag\n" +
+                        "union all\n" +
+                        "select \n" +
+                        "a.alarm_id AS 'alarm_id',\n" +
+                        "\t'x521_2' AS 'mach_no', \n" +
+                        "\ta.alarm_mark AS 'alarm_mark',\n" +
+                        "\tSUBSTRING_INDEX(a.alarm_mark, ',', 1) AS 'x_coordinate',\n" +
+                        "\tSUBSTRING_INDEX(a.alarm_mark, ',', -1) AS 'y_coordinate',\n" +
+                        "\tUNIX_TIMESTAMP(a.alarm_date) * 1000 AS 'timestamp',\n" +
+                        "\t'N/A' AS 'video_url',\n" +
+                        "\tc.device_type AS 'device_type',\n" +
+                        "\ta.alarm_level AS 'alarm_level',\n" +
+                        "\tb.data_img_name AS 'alarm_msg',\n" +
+                        "\t'N/A' AS 'sys_type',\n" +
+                        "\tc.device_name AS 'device_name',\n" +
+                        "\tb.data_img_url AS 'img_url'\n" +
+                        "from x521_2.rt_device_alarm a, x521_2.rt_device_data_ins b, x521_2.rt_device c\n" +
+                        "where a.task_id = b.task_id and a.device_tag = b.device_tag \n" +
+                        "and a.alarm_date = b.data_date and a.device_tag = c.device_tag) AS temp\n" +
+                        "where temp.alarm_id > " + latestAlarmId);
+
+        log.info("二号机器人,一共有多少条:" + unrecordsList.size());
+
+        for (MachAlarmRecords machAlarmRecords : unrecordsList) {
+
+            machAlarmRecords.save();
+
+            log.info("二号机器人,保存成功:" + machAlarmRecords.getAlarmId());
+        }
+    }
 }

+ 0 - 1
src/test/java/com/warewms/dao/ProcTest.java

@@ -24,6 +24,5 @@ public class ProcTest {
     @Test
     public void doProc(){
 
-        heXunDataService.saveUnrecordedAlarm4MachineOne();
     }
 }