浏览代码

- 添加未报警数据同步功能;

Gizmo 2 年之前
父节点
当前提交
fef9278be7

+ 2 - 2
src/main/java/com/warewms/common/utils/_JFCodeGenerator.java

@@ -405,8 +405,8 @@ public class _JFCodeGenerator {
     public void generate(){
         DataSource dataSource = _JFinalGenerator.getDataSource();
 
-//        _MetaBuilder metaBuilder = new _MetaBuilder(dataSource);
-        MyMetaBuilder metaBuilder = new MyMetaBuilder(dataSource);
+        _MetaBuilder metaBuilder = new _MetaBuilder(dataSource);
+//        MyMetaBuilder metaBuilder = new MyMetaBuilder(dataSource);
         metaBuilder.setDialect(new MysqlDialect());
         metaBuilder.addExcludedTable(_JFinalGenerator.excludedTable);
         List<TableMeta> tableMetas = metaBuilder.build();

+ 2 - 2
src/main/java/com/warewms/common/utils/_JFinalGenerator.java

@@ -60,8 +60,8 @@ public class _JFinalGenerator {
 		Generator gernerator = new Generator(getDataSource(), baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir);
 
 		//生成特定表
-//		_MetaBuilder metaBuilder = new _MetaBuilder(getDataSource());
-		MetaBuilder metaBuilder = new MetaBuilder(getDataSource());
+		_MetaBuilder metaBuilder = new _MetaBuilder(getDataSource());
+//		MetaBuilder metaBuilder = new MetaBuilder(getDataSource());
 
 		metaBuilder.addExcludedTable(excludedTable);
 

+ 1 - 1
src/main/java/com/warewms/common/utils/_MetaBuilder.java

@@ -17,7 +17,7 @@ public class _MetaBuilder extends MetaBuilder {
 
     @Override
     protected boolean isSkipTable(String tableName) {
-        String[] tableArray = {"rt_device_alarm","rt_device_data_inf","rt_device_data_ins"};//此处填入需要生成model的表
+        String[] tableArray = {"mach_alarm_records"};//此处填入需要生成model的表
         for(int i=0;i<tableArray.length;i++){
             if(tableName.equals(tableArray[i])){
                 return false;

+ 11 - 0
src/main/java/com/warewms/dao/MachAlarmRecordsDao.java

@@ -0,0 +1,11 @@
+package com.warewms.dao;
+
+import com.warewms.model.MachAlarmRecords;
+import org.springframework.stereotype.Component;
+
+@Component
+public class MachAlarmRecordsDao extends BaseDao<MachAlarmRecords> {
+    public MachAlarmRecordsDao() {
+        super(MachAlarmRecords.class);
+    }
+}

+ 78 - 0
src/main/java/com/warewms/model/HeXunAlarmData.java

@@ -0,0 +1,78 @@
+package com.warewms.model;
+
+import lombok.Data;
+
+/**
+ * PackageName:com.warewms.model
+ * Description:
+ * Author:Gizmo
+ * Date:2022/9/30
+ */
+@Data
+public class HeXunAlarmData {
+
+    /**
+     * 固定密钥
+     */
+    private String private_key;
+
+    /**
+     * 机器人编号
+     */
+    private String robotCode;
+
+    /**
+     * 地图位置
+     */
+    private String mapOrientation;
+
+    /**
+     * X坐标
+     */
+    private String xCoord;
+
+    /**
+     * Y坐标
+     */
+    private String yCoord;
+
+    /**
+     * 时间戳(毫秒)
+     */
+    private String addTime;
+
+    /**
+     * 视频地址
+     */
+    private String videoAddress;
+
+    /**
+     * 报警类型
+     */
+    private String alarmType;
+
+    /**
+     * 报警等级
+     */
+    private String alarmLevel;
+
+    /**
+     * 报警内容
+     */
+    private String alarmContent;
+
+    /**
+     * 系统类型
+     */
+    private String systemType;
+
+    /**
+     * 设备编码
+     */
+    private String deviceCode;
+
+    /**
+     * 报警图片
+     */
+    private String alarmImg;
+}

+ 11 - 0
src/main/java/com/warewms/model/MachAlarmRecords.java

@@ -0,0 +1,11 @@
+package com.warewms.model;
+
+import com.warewms.model.base.BaseMachAlarmRecords;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class MachAlarmRecords extends BaseMachAlarmRecords<MachAlarmRecords> {
+	public static final MachAlarmRecords dao = new MachAlarmRecords().dao();
+}

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

@@ -19,6 +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("message", "message_id", Message.class);
 		arp.addMapping("rt_device_alarm_flag", "alarm_id", RtDeviceAlarmFlag.class);
 		arp.addMapping("schedule_job", "job_id", ScheduleJob.class);

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

@@ -0,0 +1,108 @@
+package com.warewms.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseMachAlarmRecords<M extends BaseMachAlarmRecords<M>> extends Model<M> implements IBean {
+
+	public void setAlarmId(java.lang.Integer alarmId) {
+		set("alarm_id", alarmId);
+	}
+	
+	public java.lang.Integer getAlarmId() {
+		return getInt("alarm_id");
+	}
+
+	public void setMachNo(java.lang.String machNo) {
+		set("mach_no", machNo);
+	}
+	
+	public java.lang.String getMachNo() {
+		return getStr("mach_no");
+	}
+
+	public void setAlarmMark(java.lang.String alarmMark) {
+		set("alarm_mark", alarmMark);
+	}
+	
+	public java.lang.String getAlarmMark() {
+		return getStr("alarm_mark");
+	}
+
+	public void setXCoordinate(java.lang.String xCoordinate) {
+		set("x_coordinate", xCoordinate);
+	}
+	
+	public java.lang.String getXCoordinate() {
+		return getStr("x_coordinate");
+	}
+
+	public void setYCoordinate(java.lang.String yCoordinate) {
+		set("y_coordinate", yCoordinate);
+	}
+	
+	public java.lang.String getYCoordinate() {
+		return getStr("y_coordinate");
+	}
+
+	public void setTimestamp(java.lang.String timestamp) {
+		set("timestamp", timestamp);
+	}
+	
+	public java.lang.String getTimestamp() {
+		return getStr("timestamp");
+	}
+
+	public void setVideoUrl(java.lang.String videoUrl) {
+		set("video_url", videoUrl);
+	}
+	
+	public java.lang.String getVideoUrl() {
+		return getStr("video_url");
+	}
+
+	public void setDeviceType(java.lang.String deviceType) {
+		set("device_type", deviceType);
+	}
+	
+	public java.lang.String getDeviceType() {
+		return getStr("device_type");
+	}
+
+	public void setAlarmLevel(java.lang.String alarmLevel) {
+		set("alarm_level", alarmLevel);
+	}
+	
+	public java.lang.String getAlarmLevel() {
+		return getStr("alarm_level");
+	}
+
+	public void setSysType(java.lang.String sysType) {
+		set("sys_type", sysType);
+	}
+	
+	public java.lang.String getSysType() {
+		return getStr("sys_type");
+	}
+
+	public void setDeviceName(java.lang.String deviceName) {
+		set("device_name", deviceName);
+	}
+	
+	public java.lang.String getDeviceName() {
+		return getStr("device_name");
+	}
+
+	public void setImgUrl(java.lang.String imgUrl) {
+		set("img_url", imgUrl);
+	}
+	
+	public java.lang.String getImgUrl() {
+		return getStr("img_url");
+	}
+
+}

+ 5 - 0
src/main/java/com/warewms/service/HeXunDataService.java

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

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

@@ -0,0 +1,6 @@
+package com.warewms.service;
+
+import com.warewms.model.MachAlarmRecords;
+
+public interface MachAlarmRecordsService extends BaseService<MachAlarmRecords> {
+}

+ 71 - 0
src/main/java/com/warewms/service/impl/HeXunDataServiceImpl.java

@@ -1,6 +1,13 @@
 package com.warewms.service.impl;
 
+import com.warewms.model.MachAlarmRecords;
 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
@@ -8,5 +15,69 @@ import com.warewms.service.HeXunDataService;
  * Author:Gizmo
  * Date:2022/9/30
  */
+@Slf4j
+@Service
 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());
+        }
+    }
 }

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

@@ -0,0 +1,10 @@
+package com.warewms.service.impl;
+
+import com.warewms.dao.MachAlarmRecordsDao;
+import com.warewms.model.MachAlarmRecords;
+import com.warewms.service.MachAlarmRecordsService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class MachAlarmRecordsServiceImpl extends BaseServiceImpl<MachAlarmRecordsDao, MachAlarmRecords> implements MachAlarmRecordsService {
+}

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

@@ -0,0 +1,29 @@
+package com.warewms.dao;
+
+import com.warewms.service.HeXunDataService;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: andy.qu
+ * Date: 2019/8/24
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@Slf4j
+public class ProcTest {
+
+    @Autowired
+    HeXunDataService heXunDataService;
+
+    @Test
+    public void doProc(){
+
+        heXunDataService.saveUnrecordedAlarm4MachineOne();
+    }
+}

二进制
target/classes/com/warewms/common/utils/_JFCodeGenerator.class


二进制
target/classes/com/warewms/common/utils/_JFinalGenerator.class


二进制
target/classes/com/warewms/common/utils/_MetaBuilder.class


二进制
target/classes/com/warewms/model/_MappingKit.class