123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- package com.ruoyi.web.job;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.convert.Convert;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.util.StrUtil;
- import com.ruoyi.common.constant.ElasticConstants;
- import com.ruoyi.framework.config.ElasticSearchClient;
- import com.ruoyi.system.domain.IllegalInfo;
- import com.ruoyi.system.service.IAisInfoService;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- /**
- * @Description: TODO
- * @Author: huangcheng
- * @Date: 2021/11/1
- * @Version V1.0
- */
- @Component("getDynamicShip")
- @Slf4j
- public class GetDynamicShip {
- @Autowired
- private IAisInfoService aisInfoService;
- @Autowired
- private ElasticSearchClient client;
- private static final int SIZE = 50;
- public void get() {
- log.info("获取船舶实时位置任务开始!");
- // 拉取一天内需要获取经纬度的船舶
- Set<String> shipMmsi = new HashSet<>();
- Map<String, Object> equalsCondition = new HashMap<>();
- equalsCondition.put("illegalStatus", 2);
- List<String> orderBy = new ArrayList<>();
- orderBy.add("-createTime");
- Map<String, Object> rangeCondition = new HashMap<>();
- String startTime = DateUtil.formatDateTime(DateUtil.offsetDay(new Date(), -1));
- rangeCondition.put("createTime", StrUtil.concat(true, "[", startTime, ",", DateUtil.now(), "]"));
- Map<String, Object> xianyiMap = client.searchDocument(equalsCondition,
- rangeCondition,
- orderBy,
- 1,
- 500,
- ElasticConstants.AIS_ILLEGAL_SHIP,
- ElasticConstants.SO2_ALERT,
- ElasticConstants.HEIYAN_SHIP_RECOGNITION);
- List<IllegalInfo> xianyiList = Convert.toList(IllegalInfo.class, xianyiMap.get("pageList"));
- for (IllegalInfo illegalInfo : xianyiList) {
- shipMmsi.add(StrUtil.isBlank(illegalInfo.getMmsi()) ? illegalInfo.getAisMmsi() : illegalInfo.getMmsi());
- }
- equalsCondition.put("illegalStatus", 3);
- Map<String, Object> weiguiMap = client.searchDocument(equalsCondition,
- rangeCondition,
- orderBy,
- 1,
- 100,
- ElasticConstants.AIS_ILLEGAL_SHIP,
- ElasticConstants.SO2_ALERT,
- ElasticConstants.HEIYAN_SHIP_RECOGNITION);
- List<IllegalInfo> weiguiList = Convert.toList(IllegalInfo.class, xianyiMap.get("pageList"));
- for (IllegalInfo illegalInfo : weiguiList) {
- shipMmsi.add(StrUtil.isBlank(illegalInfo.getMmsi()) ? illegalInfo.getAisMmsi() : illegalInfo.getMmsi());
- }
- equalsCondition.put("illegalStatus", 1);
- rangeCondition.put("createTime", StrUtil.concat(true, "[", DateUtil.formatDateTime(DateUtil.offsetHour(new Date(), -2)), ",", DateUtil.now(), "]"));
- Map<String, Object> zhengchangMap = client.searchDocument(equalsCondition,
- rangeCondition,
- orderBy,
- 1,
- 50,
- ElasticConstants.AIS_ILLEGAL_SHIP,
- ElasticConstants.SO2_ALERT,
- ElasticConstants.HEIYAN_SHIP_RECOGNITION);
- List<IllegalInfo> zhengchangList = Convert.toList(IllegalInfo.class, xianyiMap.get("pageList"));
- for (IllegalInfo illegalInfo : zhengchangList) {
- shipMmsi.add(StrUtil.isBlank(illegalInfo.getMmsi()) ? illegalInfo.getAisMmsi() : illegalInfo.getMmsi());
- }
- int startIndex = 0;
- int endIndex;
- int size = shipMmsi.size();
- while (startIndex < size) {
- //尾部的位置
- endIndex = startIndex + SIZE;
- //尾部位置不能超出范围,否则就取集合的长度
- endIndex = Math.min(endIndex, size);
- //截取
- List<String> subList = CollUtil.sub(shipMmsi, startIndex, endIndex);
- aisInfoService.getDynamicShipInfo(String.join(",", subList));
- //计算下次截取的开始位置
- startIndex = endIndex;
- }
- log.info("获取船舶实时位置任务结束!");
- }
- }
|