|
@@ -1,6 +1,13 @@
|
|
package com.warewms.service.impl;
|
|
package com.warewms.service.impl;
|
|
|
|
|
|
|
|
+import com.warewms.model.MachAlarmRecords;
|
|
import com.warewms.service.HeXunDataService;
|
|
import com.warewms.service.HeXunDataService;
|
|
|
|
+import com.warewms.service.MachAlarmRecordsService;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
* PackageName:com.warewms.service.impl
|
|
* PackageName:com.warewms.service.impl
|
|
@@ -8,5 +15,69 @@ import com.warewms.service.HeXunDataService;
|
|
* Author:Gizmo
|
|
* Author:Gizmo
|
|
* Date:2022/9/30
|
|
* Date:2022/9/30
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
public class HeXunDataServiceImpl implements HeXunDataService {
|
|
public class HeXunDataServiceImpl implements HeXunDataService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ 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());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|