GetDynamicShip.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package com.ruoyi.web.job;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.convert.Convert;
  4. import cn.hutool.core.date.DateUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import com.ruoyi.common.constant.ElasticConstants;
  7. import com.ruoyi.framework.config.ElasticSearchClient;
  8. import com.ruoyi.system.domain.IllegalInfo;
  9. import com.ruoyi.system.service.IAisInfoService;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Component;
  13. import java.util.ArrayList;
  14. import java.util.Date;
  15. import java.util.HashMap;
  16. import java.util.HashSet;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.Set;
  20. /**
  21. * @Description: TODO
  22. * @Author: huangcheng
  23. * @Date: 2021/11/1
  24. * @Version V1.0
  25. */
  26. @Component("getDynamicShip")
  27. @Slf4j
  28. public class GetDynamicShip {
  29. @Autowired
  30. private IAisInfoService aisInfoService;
  31. @Autowired
  32. private ElasticSearchClient client;
  33. private static final int SIZE = 50;
  34. public void get() {
  35. log.info("获取船舶实时位置任务开始!");
  36. // 拉取一天内需要获取经纬度的船舶
  37. Set<String> shipMmsi = new HashSet<>();
  38. Map<String, Object> equalsCondition = new HashMap<>();
  39. equalsCondition.put("illegalStatus", 2);
  40. List<String> orderBy = new ArrayList<>();
  41. orderBy.add("-createTime");
  42. Map<String, Object> rangeCondition = new HashMap<>();
  43. String startTime = DateUtil.formatDateTime(DateUtil.offsetDay(new Date(), -1));
  44. rangeCondition.put("createTime", StrUtil.concat(true, "[", startTime, ",", DateUtil.now(), "]"));
  45. Map<String, Object> xianyiMap = client.searchDocument(equalsCondition,
  46. rangeCondition,
  47. orderBy,
  48. 1,
  49. 500,
  50. ElasticConstants.AIS_ILLEGAL_SHIP,
  51. ElasticConstants.SO2_ALERT,
  52. ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  53. List<IllegalInfo> xianyiList = Convert.toList(IllegalInfo.class, xianyiMap.get("pageList"));
  54. for (IllegalInfo illegalInfo : xianyiList) {
  55. shipMmsi.add(StrUtil.isBlank(illegalInfo.getMmsi()) ? illegalInfo.getAisMmsi() : illegalInfo.getMmsi());
  56. }
  57. equalsCondition.put("illegalStatus", 3);
  58. Map<String, Object> weiguiMap = client.searchDocument(equalsCondition,
  59. rangeCondition,
  60. orderBy,
  61. 1,
  62. 100,
  63. ElasticConstants.AIS_ILLEGAL_SHIP,
  64. ElasticConstants.SO2_ALERT,
  65. ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  66. List<IllegalInfo> weiguiList = Convert.toList(IllegalInfo.class, xianyiMap.get("pageList"));
  67. for (IllegalInfo illegalInfo : weiguiList) {
  68. shipMmsi.add(StrUtil.isBlank(illegalInfo.getMmsi()) ? illegalInfo.getAisMmsi() : illegalInfo.getMmsi());
  69. }
  70. equalsCondition.put("illegalStatus", 1);
  71. rangeCondition.put("createTime", StrUtil.concat(true, "[", DateUtil.formatDateTime(DateUtil.offsetHour(new Date(), -2)), ",", DateUtil.now(), "]"));
  72. Map<String, Object> zhengchangMap = client.searchDocument(equalsCondition,
  73. rangeCondition,
  74. orderBy,
  75. 1,
  76. 50,
  77. ElasticConstants.AIS_ILLEGAL_SHIP,
  78. ElasticConstants.SO2_ALERT,
  79. ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  80. List<IllegalInfo> zhengchangList = Convert.toList(IllegalInfo.class, xianyiMap.get("pageList"));
  81. for (IllegalInfo illegalInfo : zhengchangList) {
  82. shipMmsi.add(StrUtil.isBlank(illegalInfo.getMmsi()) ? illegalInfo.getAisMmsi() : illegalInfo.getMmsi());
  83. }
  84. int startIndex = 0;
  85. int endIndex;
  86. int size = shipMmsi.size();
  87. while (startIndex < size) {
  88. //尾部的位置
  89. endIndex = startIndex + SIZE;
  90. //尾部位置不能超出范围,否则就取集合的长度
  91. endIndex = Math.min(endIndex, size);
  92. //截取
  93. List<String> subList = CollUtil.sub(shipMmsi, startIndex, endIndex);
  94. aisInfoService.getDynamicShipInfo(String.join(",", subList));
  95. //计算下次截取的开始位置
  96. startIndex = endIndex;
  97. }
  98. log.info("获取船舶实时位置任务结束!");
  99. }
  100. }