Commit bef419a6add516ac7e4ea8ba21d2ca9c573e69a3

Authored by 648540858
1 parent 724b2882

添加sql脚本

sql/mysql.sql
... ... @@ -60,6 +60,22 @@ create table device_channel
60 60 primary key (channelId, deviceId)
61 61 );
62 62  
  63 +create table device_alarm
  64 +(
  65 + id int auto_increment
  66 + primary key,
  67 + deviceId varchar(50) not null,
  68 + alarmPriority varchar(50) not null,
  69 + alarmMethod varchar(50),
  70 + alarmTime varchar(50) not null,
  71 + alarmDescription varchar(255),
  72 + longitude double null,
  73 + latitude double null,
  74 + alarmType varchar(50)
  75 +);
  76 +
  77 +
  78 +
63 79 create table device_mobile_position
64 80 (
65 81 deviceId varchar(50) not null,
... ...
src/test/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImplTest.java 0 → 100644
  1 +package com.genersoft.iot.vmp.service.impl;
  2 +
  3 +import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
  4 +import com.genersoft.iot.vmp.service.IDeviceAlarmService;
  5 +import org.junit.runner.RunWith;
  6 +import org.springframework.boot.test.context.SpringBootTest;
  7 +import org.springframework.test.context.junit4.SpringRunner;
  8 +
  9 +import javax.annotation.Resource;
  10 +import java.text.SimpleDateFormat;
  11 +import java.util.Date;
  12 +
  13 +
  14 +@SpringBootTest
  15 +@RunWith(SpringRunner.class)
  16 +class DeviceAlarmServiceImplTest {
  17 +
  18 + @Resource
  19 + private IDeviceAlarmService deviceAlarmService;
  20 +
  21 + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  22 +
  23 + @org.junit.jupiter.api.Test
  24 + void getAllAlarm() {
  25 +// deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111",null,null,null, null, null);
  26 +// System.out.println(deviceAlarmService.getAllAlarm(0, 10000, null, null, null, null,
  27 +// null, null).getSize());
  28 +//
  29 +// System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", null, null, null,
  30 +// null, null).getSize());
  31 +//
  32 +// System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", "1", null, null,
  33 +// null, null).getSize());
  34 +//
  35 +// System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", "2", null, null,
  36 +// null, null).getSize());
  37 +//
  38 +// System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", "3", null, null,
  39 +// null, null).getSize());
  40 +//
  41 +// System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", "4", null, null,
  42 +// null, null).getSize());
  43 +//
  44 +// System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", "5", null, null,
  45 +// null, null).getSize());
  46 +//
  47 +// System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", null, "1", null,
  48 +// null, null).getSize());
  49 +
  50 +// System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", null, "1", null,
  51 +// null, null).getSize());
  52 +
  53 + System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", null, null, null,
  54 + "2021-01-01 00:00:00", null).getSize());
  55 +
  56 + System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", null, null, null,
  57 + null, "2021-04-01 09:00:00").getSize());
  58 +
  59 + System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", null, null, null,
  60 + "2021-02-01 01:00:00", "2021-04-01 04:00:00").getSize());
  61 + }
  62 +
  63 +
  64 + @org.junit.jupiter.api.Test
  65 + void add() {
  66 + for (int i = 0; i < 1000; i++) {
  67 + DeviceAlarm deviceAlarm = new DeviceAlarm();
  68 + deviceAlarm.setDeviceId("11111111111111111111");
  69 + deviceAlarm.setAlarmDescription("test_" + i);
  70 +
  71 + /**
  72 + * 报警方式 , 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警,
  73 + * * 7其他报警;可以为直接组合如12为电话报警或 设备报警-
  74 + */
  75 + deviceAlarm.setAlarmMethod((int)(Math.random()*7 + 1) + "");
  76 + Date date = randomDate("2021-01-01 00:00:00", "2021-06-01 00:00:00");
  77 + deviceAlarm.setAlarmTime(format.format(date));
  78 + /**
  79 + * 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级 警情-
  80 + */
  81 + deviceAlarm.setAlarmPriority((int)(Math.random()*4 + 1) + "");
  82 + deviceAlarm.setLongitude(116.325);
  83 + deviceAlarm.setLatitude(39.562);
  84 + deviceAlarmService.add(deviceAlarm);
  85 + }
  86 +
  87 + }
  88 +
  89 + @org.junit.jupiter.api.Test
  90 + void clearAlarmBeforeTime() {
  91 + deviceAlarmService.clearAlarmBeforeTime(null,null, null);
  92 + }
  93 +
  94 +
  95 +
  96 +
  97 + private Date randomDate(String beginDate, String endDate) {
  98 + try {
  99 +
  100 + Date start = format.parse(beginDate);//构造开始日期
  101 + Date end = format.parse(endDate);//构造结束日期
  102 + //getTime()表示返回自 1970 年 1 月 1 日 00:00:00 GMT 以来此 Date 对象表示的毫秒数。
  103 + if (start.getTime() >= end.getTime()) {
  104 + return null;
  105 + }
  106 + long date = random(start.getTime(), end.getTime());
  107 + return new Date(date);
  108 + } catch (Exception e) {
  109 + e.printStackTrace();
  110 + }
  111 + return null;
  112 + }
  113 +
  114 + private static long random(long begin, long end) {
  115 + long rtn = begin + (long) (Math.random() * (end - begin));
  116 + //如果返回的是开始时间和结束时间,则递归调用本函数查找随机值
  117 + if (rtn == begin || rtn == end) {
  118 + return random(begin, end);
  119 + }
  120 + return rtn;
  121 + }
  122 +}
0 123 \ No newline at end of file
... ...