ElePostTimer.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package com.huimv.env.input.timer;
  2. import cn.hutool.core.date.DateTime;
  3. import cn.hutool.core.date.DateUtil;
  4. import com.huimv.env.input.entity.BasePigpen;
  5. import com.huimv.env.input.entity.Gateway;
  6. import com.huimv.env.input.entity.vo.AlarmInfoVO;
  7. import com.huimv.env.input.entity.vo.DataInfoVO;
  8. import com.huimv.env.input.entity.vo.HeartInfoVo;
  9. import com.huimv.env.input.service.IBaseFarmService;
  10. import com.huimv.env.input.service.IBasePigpenService;
  11. import com.huimv.env.input.service.IGatewayService;
  12. import com.huimv.env.input.service.IHeartInfoService;
  13. import com.huimv.env.input.utils.ElePostUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.context.annotation.Configuration;
  16. import org.springframework.scheduling.annotation.EnableScheduling;
  17. import org.springframework.scheduling.annotation.Scheduled;
  18. import org.springframework.web.bind.annotation.GetMapping;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RestController;
  21. import java.io.IOException;
  22. import java.util.Date;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. /**
  26. * @Project : huimv.shiwan
  27. * @Package : com.huimv.env.input
  28. * @Description : TODO
  29. * @Author : yuxuexuan
  30. * @Create : 2024/6/19 0019 14:49
  31. **/
  32. @Configuration
  33. @EnableScheduling
  34. //@RestController
  35. //@RequestMapping("/test")
  36. public class ElePostTimer {
  37. public static final String BASE_URL = "https://south.bowaniot.com";
  38. //网关信息
  39. public static final String GATEWAY_INFO_URL = "/airswitch/message/elec/gateway/info/import";
  40. //心跳信息
  41. public static final String TRACK_URL = "/airswitch/message/elec/track/import";
  42. //流水信息
  43. public static final String DATA_URL = "/airswitch/message/elec/data/import";
  44. //事件数据
  45. public static final String ALARM_URL = "/airswitch/message/elec/alarm/import";
  46. @Autowired
  47. private IBaseFarmService baseFarmService;
  48. @Autowired
  49. private IBasePigpenService basePigpenService;
  50. // @Scheduled(cron = "0 0 0/1 * * ? ")
  51. // @Scheduled(cron = "0 * * * * ? ")
  52. @GetMapping("/test")
  53. public void gateWayImport() throws IOException {
  54. System.out.println("----网关传输开始----");
  55. List<Gateway> gateways = baseFarmService.getUploadFarm();
  56. for (Gateway gateway : gateways) {
  57. BasePigpen byId = basePigpenService.getById(gateway.getLocationId());
  58. HashMap<String, Object> dataMap = new HashMap<>();
  59. dataMap.put("mode",null);
  60. dataMap.put("version","v1.0");
  61. dataMap.put("np",null);
  62. dataMap.put("heartbeat",null);
  63. dataMap.put("longitude",byId.getLng());
  64. dataMap.put("latitude",byId.getLat());
  65. dataMap.put("imsi",null);
  66. dataMap.put("iccid",null);
  67. System.out.println("result--->"+ElePostUtils.basePost(BASE_URL + GATEWAY_INFO_URL, gateway.getDeviceCode(), dataMap));
  68. }
  69. System.out.println("----网关传输结束----");
  70. }
  71. // @Scheduled(cron = "5 * * * * ? ")
  72. @GetMapping("/test1")
  73. public void trackImport() throws IOException {
  74. System.out.println("----心跳传输开始----");
  75. List<Gateway> gateways = baseFarmService.getUploadFarm();
  76. for (Gateway gateway : gateways) {
  77. DateTime dateTime = DateUtil.offsetMinute(new Date(), -1);
  78. List<HeartInfoVo> heartInfoVos = baseFarmService.trackImport(dateTime,gateway.getDeviceCode());
  79. System.out.println("result--->"+ElePostUtils.heartPost(BASE_URL + TRACK_URL, gateway.getDeviceCode(), heartInfoVos));
  80. }
  81. System.out.println("----心跳传输结束----");
  82. }
  83. // @Scheduled(cron = "10 * * * * ? ")
  84. @GetMapping("/test2")
  85. public void dataImport() throws IOException {
  86. System.out.println("----流水传输开始----");
  87. List<Gateway> gateways = baseFarmService.getUploadFarm();
  88. for (Gateway gateway : gateways) {
  89. DateTime dateTime = DateUtil.offsetMinute(new Date(), -1);
  90. List<DataInfoVO> dataInfoVOS = baseFarmService.dataImport(dateTime,gateway.getDeviceCode());
  91. System.out.println("result--->"+ElePostUtils.heartPost(BASE_URL + DATA_URL, gateway.getDeviceCode(), dataInfoVOS));
  92. }
  93. System.out.println("----流水传输结束----");
  94. }
  95. // @Scheduled(cron = "1 * * * * ? ")
  96. // public void alarmImport() throws IOException {
  97. // System.out.println("----事件传输开始----");
  98. // List<Gateway> gateways = baseFarmService.getUploadFarm();
  99. // for (Gateway gateway : gateways) {
  100. // DateTime dateTime = DateUtil.offsetMinute(new Date(), -1);
  101. // List<AlarmInfoVO> dataInfoVOS = baseFarmService.alarmImport(dateTime,gateway.getDeviceCode());
  102. // System.out.println("data--->"+dataInfoVOS.toString());
  103. // System.out.println("result--->"+ElePostUtils.heartPost(BASE_URL + ALARM_URL, gateway.getDeviceCode(), dataInfoVOS));
  104. // }
  105. // System.out.println("----事件传输结束----");
  106. //
  107. // }
  108. }