|
@@ -4,7 +4,9 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.shanghaigeography.Util.DateUtils;
|
|
|
+import com.shcd.boat.config.RedisCache;
|
|
|
import com.shcd.boat.config.RedisUtilTemplate;
|
|
|
import com.shcd.boat.config.SnowConfig;
|
|
|
import com.shcd.boat.entity.*;
|
|
@@ -15,6 +17,7 @@ import com.shcd.boat.mapper.ShipSealOffPointsMapper;
|
|
|
import com.shcd.boat.mapper.ShipSealOffSpaceMapper;
|
|
|
import com.shcd.boat.service.IShipSealOffInfoService;
|
|
|
import com.shcd.boat.service.ShipSealOffService;
|
|
|
+import com.shcd.boat.sms.MASSMSService;
|
|
|
import com.shcd.boat.utils.GhjgRpcUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -43,6 +46,8 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MASSMSService massmsService;
|
|
|
|
|
|
* 获取市港航数据
|
|
|
* @return
|
|
@@ -124,7 +129,7 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
@Resource
|
|
|
private ShipSealOffPointsMapper offPointsMapper;
|
|
|
@Autowired
|
|
|
- private RedisUtilTemplate redisUtilTemplate;
|
|
|
+ private RedisCache redisUtilTemplate;
|
|
|
|
|
|
|
|
|
* 分析点位
|
|
@@ -157,16 +162,12 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
log.info("== 2.3 右部区域符合点位个数:"+rightPoints.size());
|
|
|
aisInfosAll.addAll(rightPoints);
|
|
|
}
|
|
|
- log.info("== 全部区域符合点位个数:"+aisInfosAll.size());
|
|
|
- List<Boolean>booleans= shipSealOffSpaceMapper.getAllInOut(aisInfosAll);
|
|
|
- for (int i=0;i<booleans.size()-1;i++)
|
|
|
- {
|
|
|
- GHAisInfo ghAisInfo= aisInfosAll.get(i);
|
|
|
- ghAisInfo.setInAll(booleans.get(i));
|
|
|
- }
|
|
|
- List<GHAisInfo> inAll=aisInfosAll.stream().filter(i->i.getInAll()!=null && i.getInAll()).collect(Collectors.toList());
|
|
|
+ log.info("== 2.4 全部区域符合点位个数:"+aisInfosAll.size());
|
|
|
+ List<GHAisInfo> newAisInfosAll= shipSealOffSpaceMapper.getAllInOut(aisInfosAll);
|
|
|
+ log.info("== 2.5 所在范围情况:"+newAisInfosAll.toString());
|
|
|
+ List<GHAisInfo> inAll=newAisInfosAll.stream().filter(i->i.getInAll()!=null && i.getInAll()).collect(Collectors.toList());
|
|
|
|
|
|
- List<GHAisInfo> notInAll=aisInfosAll.stream().filter(i->i.getInAll()!=null && !i.getInAll()).collect(Collectors.toList());
|
|
|
+ List<GHAisInfo> notInAll=newAisInfosAll.stream().filter(i->i.getInAll()!=null && !i.getInAll()).collect(Collectors.toList());
|
|
|
if (inAll!=null && inAll.size()>0)
|
|
|
{
|
|
|
log.info("== 3.处理在区域范围内的船舶个数:"+inAll.size());
|
|
@@ -174,11 +175,13 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
}
|
|
|
if (notInAll!=null && notInAll.size()>0)
|
|
|
{
|
|
|
- log.info("== 4.处理不在区域范围内的船舶个数:"+inAll.size());
|
|
|
+ log.info("== 4.处理不在区域范围内的船舶个数:"+notInAll.size());
|
|
|
saveAllNotData(notInAll);
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Autowired
|
|
@@ -222,8 +225,10 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
List<ShipSealOffInfo> insertNeedList =new ArrayList<>();
|
|
|
List<ShipSealOffInfo> updateNeedList =new ArrayList<>();
|
|
|
List<ShipSealOffPoints> sealOffPoints=new ArrayList<>();
|
|
|
+ Map<String,BoatInfoEntity> redisDataMap=new HashMap<>();
|
|
|
+
|
|
|
mapAll.keySet().forEach(i-> {
|
|
|
- Object result = redisUtilTemplate.get(i);
|
|
|
+ Object result = redisUtilTemplate.getCacheObject(i);
|
|
|
if (!ObjectUtils.isEmpty(result)) {
|
|
|
|
|
|
|
|
@@ -234,12 +239,13 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
if (redisData.getLastAisTime().hashCode() != thisGpsTime.hashCode())
|
|
|
{
|
|
|
|
|
|
- if (!redisData.getIsWarning() && redisData.getPointWarningNum() > 2 && thisAisPoint.getVelocity().compareTo(new BigDecimal("1")) > 0) {
|
|
|
+ if (!redisData.getIsWarning() && redisData.getPointWarningNum() > 1 && thisAisPoint.getVelocity().compareTo(new BigDecimal("1")) > 0) {
|
|
|
ShipSealOffInfo info = new ShipSealOffInfo();
|
|
|
info.setSealId(redisData.getId());
|
|
|
info.setMmsi(i);
|
|
|
info.setWarningVerifyStatus("待核实");
|
|
|
info.setWarningTime(new Date());
|
|
|
+ redisData.setWarningChannel(getInChannelForThisAIS(thisAisPoint));
|
|
|
info.setWarningChannel(redisData.getInChannel());
|
|
|
info.setShipBreadth(thisAisPoint.getShipBreadth());
|
|
|
info.setShipLength(thisAisPoint.getShipLength());
|
|
@@ -248,8 +254,8 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
info.setWarningStatus("航行中");
|
|
|
redisData.setCunState("航行中");
|
|
|
} else {
|
|
|
- info.setWarningStatus("已停舶");
|
|
|
- redisData.setCunState("已停舶");
|
|
|
+ info.setWarningStatus("已停泊");
|
|
|
+ redisData.setCunState("已停泊");
|
|
|
}
|
|
|
info.setStartWarning(redisData.getBeginTime());
|
|
|
insertNeedList.add(info);
|
|
@@ -289,8 +295,8 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
info.setWarningStatus("航行中");
|
|
|
redisData.setCunState("航行中");
|
|
|
} else {
|
|
|
- info.setWarningStatus("已停舶");
|
|
|
- redisData.setCunState("已停舶");
|
|
|
+ info.setWarningStatus("已停泊");
|
|
|
+ redisData.setCunState("已停泊");
|
|
|
}
|
|
|
info.getWarningStatus();
|
|
|
updateNeedList.add(info);
|
|
@@ -317,8 +323,9 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
redisData.setPointNum((redisData.getPointNum() + 1));
|
|
|
String dtoJSON = JSON.toJSONString(redisData);
|
|
|
|
|
|
- redisUtilTemplate.set(i, dtoJSON);
|
|
|
+ redisUtilTemplate.setCacheObject(i, dtoJSON);
|
|
|
}
|
|
|
+ redisDataMap.put(i,redisData);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -330,6 +337,7 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
thisAis.setPointNum(1);
|
|
|
thisAis.setBeginTime(thisAisPoint.getGpsTime());
|
|
|
thisAis.setPointWarningNum(1);
|
|
|
+ thisAis.setIsWarning(false);
|
|
|
|
|
|
thisAis.setInChannel(getInChannelForThisAIS(thisAisPoint));
|
|
|
List<GHAisInfo> aisInfos = new ArrayList<>();
|
|
@@ -337,7 +345,8 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
aisInfos.add(thisAisPoint);
|
|
|
thisAis.setAisData(aisInfos);
|
|
|
String dtoJSON = JSON.toJSONString(thisAis);
|
|
|
- redisUtilTemplate.set(i, dtoJSON);
|
|
|
+ redisUtilTemplate.setCacheObject(i, dtoJSON);
|
|
|
+ redisDataMap.put(i,thisAis);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -393,15 +402,17 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
List<String> strings= insertNeedList.stream().map(ShipSealOffInfo::getMmsi).collect(Collectors.toList());
|
|
|
log.info("== 3.2.1 调整缓存点为已预警:"+strings.toString());
|
|
|
strings.stream().forEach(i->{
|
|
|
- Object result = redisUtilTemplate.get(i);
|
|
|
+ Object result = redisUtilTemplate.getCacheObject(i);
|
|
|
if (!ObjectUtils.isEmpty(result)) {
|
|
|
BoatInfoEntity redisData = JSON.parseObject((String) result, BoatInfoEntity.class);
|
|
|
redisData.setIsWarning(true);
|
|
|
String dtoJSON = JSON.toJSONString(redisData);
|
|
|
|
|
|
- redisUtilTemplate.set(i, dtoJSON);
|
|
|
+ log.info("=== 3.2.1.1 开始处理:"+i+"设置状态为"+redisData.getIsWarning());
|
|
|
+ redisUtilTemplate.setCacheObject(i, dtoJSON);
|
|
|
}
|
|
|
});
|
|
|
+ sendSMSData(insertNeedList);
|
|
|
}
|
|
|
if (updateNeedList!=null && updateNeedList.size()>0) {
|
|
|
log.info("== 3.3 其中需要更新船舶:"+updateNeedList.size()+"个:"+updateNeedList.toString());
|
|
@@ -421,14 +432,48 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
|
|
|
Map<String,GHAisInfo> mapAll=notInAll.stream().collect(Collectors.toMap(GHAisInfo::getDeviCeid, Function.identity()));
|
|
|
log.info("== 离开区域范围内的船舶个数:"+notInAll.size()+",离开的详细信息:"+mapAll.keySet());
|
|
|
+
|
|
|
+ List<String> sealIds=new ArrayList<>();
|
|
|
+
|
|
|
mapAll.keySet().forEach(i->{
|
|
|
- Object result = redisUtilTemplate.get(i);
|
|
|
+ Object result = redisUtilTemplate.getCacheObject(i);
|
|
|
if (!ObjectUtils.isEmpty(result)) {
|
|
|
- redisUtilTemplate.del(i);
|
|
|
+ BoatInfoEntity redisData = JSON.parseObject((String) result, BoatInfoEntity.class);
|
|
|
+ sealIds.add(redisData.getId());
|
|
|
+ redisUtilTemplate.deleteObject(i);
|
|
|
}
|
|
|
});
|
|
|
+ if(sealIds!=null && sealIds.size()>0) {
|
|
|
|
|
|
- }
|
|
|
+ LambdaUpdateWrapper<ShipSealOffInfo> sealOffInfoLambdaUpdateWrapper = new LambdaUpdateWrapper();
|
|
|
+ sealOffInfoLambdaUpdateWrapper.set(ShipSealOffInfo::getWarningStatus, "已离开电子围栏");
|
|
|
+ sealOffInfoLambdaUpdateWrapper.in(ShipSealOffInfo::getSealId, sealIds);
|
|
|
+ shipSealOffInfoService.update(sealOffInfoLambdaUpdateWrapper);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<ShipSealOffInfo> lastPoint = new LambdaQueryWrapper<>();
|
|
|
+ lastPoint.in(ShipSealOffInfo::getSealId, sealIds);
|
|
|
+ List<ShipSealOffInfo> has = shipSealOffInfoService.list(lastPoint);
|
|
|
+ if (has != null && has.size() > 0) {
|
|
|
+ Map<String, String> hasMMSI = has.stream().filter(i -> !StringUtils.isEmpty(i.getMmsi())).collect(Collectors.toMap(ShipSealOffInfo::getMmsi, ShipSealOffInfo::getSealId));
|
|
|
+ List<ShipSealOffPoints> lastPoints = new ArrayList<>();
|
|
|
+ hasMMSI.keySet().forEach(i -> {
|
|
|
+ GHAisInfo aisInfo = mapAll.get(i);
|
|
|
+ ShipSealOffPoints sealOffPoints1 = new ShipSealOffPoints();
|
|
|
+ sealOffPoints1.setId(snowflakeConfig.snowflakeStringId());
|
|
|
+ sealOffPoints1.setMmsi(i);
|
|
|
+ sealOffPoints1.setShipName(aisInfo.getBoatName());
|
|
|
+ sealOffPoints1.setSourceType("市港航AIS");
|
|
|
+ sealOffPoints1.setSealId(hasMMSI.get(i));
|
|
|
+ sealOffPoints1.setAisTime(aisInfo.getGpsTime());
|
|
|
+ sealOffPoints1.setPointJson(JSON.toJSONString(aisInfo));
|
|
|
+ sealOffPoints1.setPointGeom(aisInfo.getMapx().toString() + " " + aisInfo.getMapy().toString());
|
|
|
+ lastPoints.add(sealOffPoints1);
|
|
|
+ });
|
|
|
+ offPointsMapper.saveAll(lastPoints, 3857);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
@@ -437,11 +482,11 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
*/
|
|
|
void getDBAllDataForNeed()
|
|
|
{
|
|
|
- Set<String> keys=redisUtilTemplate.findKeys("*");
|
|
|
- if (keys!=null && keys.size()>0) {
|
|
|
+ Collection<String> cacheKeys =redisUtilTemplate.keys("*");
|
|
|
+ if (cacheKeys!=null && cacheKeys.size()>0) {
|
|
|
LambdaQueryWrapper<ShipSealOffInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
lambdaQueryWrapper.ne(ShipSealOffInfo::getWarningVerifyStatus, "待核实");
|
|
|
- lambdaQueryWrapper.in(ShipSealOffInfo::getMmsi, keys);
|
|
|
+ lambdaQueryWrapper.in(ShipSealOffInfo::getMmsi, cacheKeys);
|
|
|
lambdaQueryWrapper.eq(ShipSealOffInfo::getDelFlag, "0");
|
|
|
List<ShipSealOffInfo> shipSealOffInfos= shipSealOffInfoService.list(lambdaQueryWrapper);
|
|
|
if (shipSealOffInfos!=null && shipSealOffInfos.size()>0)
|
|
@@ -449,7 +494,7 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
List<String> mmsis=shipSealOffInfos.stream().map(ShipSealOffInfo::getMmsi).collect(Collectors.toList());
|
|
|
log.info("=== 1.1 查询到 存在缓存中的数据已经确认过的数据,开始清除相关缓存,清除船舶为:"+mmsis.toString());
|
|
|
mmsis.forEach(i->{
|
|
|
- redisUtilTemplate.del(i);
|
|
|
+ redisUtilTemplate.deleteObject(i);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -457,4 +502,16 @@ public class ShipSealOffServiceImpl implements ShipSealOffService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ * 短信发送
|
|
|
+ */
|
|
|
+ void sendSMSData( List<ShipSealOffInfo> inAll){
|
|
|
+ inAll.stream().forEach(i->{
|
|
|
+ String message="【"+DateUtils.dateToString(i.getWarningTime(),DateUtils.DATE_FORMAT_19)+"】,发现【"+i.getShipName()+"】违规输入封航区域,请尽快核实。";
|
|
|
+ massmsService.commonSend("13393931806",message);
|
|
|
+ massmsService.commonSend("18202163836",message);
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
}
|