|
@@ -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());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|