DeviceAlarmServiceImplTest.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.genersoft.iot.vmp.service.impl;
  2. import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
  3. import com.genersoft.iot.vmp.service.IDeviceAlarmService;
  4. import com.genersoft.iot.vmp.utils.DateUtil;
  5. import org.junit.runner.RunWith;
  6. import org.springframework.boot.test.context.SpringBootTest;
  7. import org.springframework.test.context.junit4.SpringRunner;
  8. import javax.annotation.Resource;
  9. import java.util.Date;
  10. @SpringBootTest
  11. @RunWith(SpringRunner.class)
  12. class DeviceAlarmServiceImplTest {
  13. @Resource
  14. private IDeviceAlarmService deviceAlarmService;
  15. @org.junit.jupiter.api.Test
  16. void getAllAlarm() {
  17. // deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111",null,null,null, null, null);
  18. // System.out.println(deviceAlarmService.getAllAlarm(0, 10000, null, null, null, null,
  19. // null, null).getSize());
  20. //
  21. // System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", null, null, null,
  22. // null, null).getSize());
  23. //
  24. // System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", "1", null, null,
  25. // null, null).getSize());
  26. //
  27. // System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", "2", null, null,
  28. // null, null).getSize());
  29. //
  30. // System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", "3", null, null,
  31. // null, null).getSize());
  32. //
  33. // System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", "4", null, null,
  34. // null, null).getSize());
  35. //
  36. // System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", "5", null, null,
  37. // null, null).getSize());
  38. //
  39. // System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", null, "1", null,
  40. // null, null).getSize());
  41. // System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", null, "1", null,
  42. // null, null).getSize());
  43. }
  44. @org.junit.jupiter.api.Test
  45. void add() {
  46. for (int i = 0; i < 1000; i++) {
  47. DeviceAlarm deviceAlarm = new DeviceAlarm();
  48. deviceAlarm.setDeviceId("11111111111111111111");
  49. deviceAlarm.setAlarmDescription("test_" + i);
  50. /**
  51. * 报警方式 , 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警,
  52. * * 7其他报警;可以为直接组合如12为电话报警或 设备报警-
  53. */
  54. deviceAlarm.setAlarmMethod((int)(Math.random()*7 + 1) + "");
  55. Date date = randomDate("2021-01-01 00:00:00", "2021-06-01 00:00:00");
  56. deviceAlarm.setAlarmTime(DateUtil.format.format(date));
  57. /**
  58. * 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级 警情-
  59. */
  60. deviceAlarm.setAlarmPriority((int)(Math.random()*4 + 1) + "");
  61. deviceAlarm.setLongitude(116.325);
  62. deviceAlarm.setLatitude(39.562);
  63. deviceAlarmService.add(deviceAlarm);
  64. }
  65. }
  66. @org.junit.jupiter.api.Test
  67. void clearAlarmBeforeTime() {
  68. deviceAlarmService.clearAlarmBeforeTime(null,null, null);
  69. }
  70. private Date randomDate(String beginDate, String endDate) {
  71. try {
  72. Date start = DateUtil.format.parse(beginDate);//构造开始日期
  73. Date end = DateUtil.format.parse(endDate);//构造结束日期
  74. //getTime()表示返回自 1970 年 1 月 1 日 00:00:00 GMT 以来此 Date 对象表示的毫秒数。
  75. if (start.getTime() >= end.getTime()) {
  76. return null;
  77. }
  78. long date = random(start.getTime(), end.getTime());
  79. return new Date(date);
  80. } catch (Exception e) {
  81. e.printStackTrace();
  82. }
  83. return null;
  84. }
  85. private static long random(long begin, long end) {
  86. long rtn = begin + (long) (Math.random() * (end - begin));
  87. //如果返回的是开始时间和结束时间,则递归调用本函数查找随机值
  88. if (rtn == begin || rtn == end) {
  89. return random(begin, end);
  90. }
  91. return rtn;
  92. }
  93. }