Commit 4c0f4ca7 authored by hanbing's avatar hanbing

[update] 快速特勤,更新自动解锁车辆和路口列表

parent e92b7ab3
......@@ -15,7 +15,6 @@ import net.wanji.feign.service.UtcFeignClients;
import net.wanji.web.common.constant.Constant;
import net.wanji.web.mapper.SpecialServiceCrossMapper;
import net.wanji.web.mapper.SpecialServiceMapper;
import net.wanji.web.po.SpecialServiceCrossPO;
import net.wanji.web.po.SpecialServicePO;
import net.wanji.web.websocket.WebSocketServer;
import org.apache.kafka.clients.consumer.Consumer;
......@@ -29,7 +28,6 @@ import org.springframework.kafka.support.Acknowledgment;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -45,37 +43,22 @@ import java.util.concurrent.ConcurrentHashMap;
public class ConsumerHandler implements KafkaListenerErrorHandler {
private final SpecialServiceMapper specialServiceMapper;
private final SpecialServiceCrossMapper specialServiceCrossMapper;
private final BaseCrossInfoMapper baseCrossInfoMapper;
private final UtcFeignClients utcFeignClients;
private List<String> carPlates = new ArrayList<>();
private List<BaseCrossInfoPO> crossList = new ArrayList<>();
public static String carPlate;
public static List<BaseCrossInfoPO> crossList = new ArrayList<>();
public ConsumerHandler(SpecialServiceMapper specialServiceMapper, SpecialServiceCrossMapper specialServiceCrossMapper, BaseCrossInfoMapper baseCrossInfoMapper, @Qualifier("net.wanji.feign.service.UtcFeignClients") UtcFeignClients utcFeignClients) {
this.specialServiceMapper = specialServiceMapper;
this.specialServiceCrossMapper = specialServiceCrossMapper;
this.baseCrossInfoMapper = baseCrossInfoMapper;
this.utcFeignClients = utcFeignClients;
}
@PostConstruct
private void initCarplates() {
List<SpecialServicePO> specialServicePOList = specialServiceMapper.selectExec();
for (SpecialServicePO specialServicePO : specialServicePOList) {
String plateNum = specialServicePO.getPlateNum();
if (StrUtil.isNotEmpty(plateNum)) {
carPlates.add(plateNum);
}
}
public static void updateCarplate(String newCarPlate) {
carPlate = newCarPlate;
}
@PostConstruct
private void initCrossList() {
List<SpecialServiceCrossPO> unLockCrosses = specialServiceCrossMapper.selectByAutoUnlock();
for (SpecialServiceCrossPO unLockCross : unLockCrosses) {
String crossId = unLockCross.getCrossId();
BaseCrossInfoPO baseCrossInfoPO = baseCrossInfoMapper.selectById(crossId);
crossList.add(baseCrossInfoPO);
}
public static void updateCrossList(List<BaseCrossInfoPO> newCrossList) {
crossList = newCrossList;
}
/**
......@@ -110,43 +93,42 @@ public class ConsumerHandler implements KafkaListenerErrorHandler {
for (JNMatchResultMiniData.E1FrameParticipant car : carList) {
String picLicense = car.getPicLicense();
// 是否是特勤车辆
for (String carPlate : carPlates) {
if (StrUtil.equals(picLicense, carPlate)) {
// 判断是否经过自动解锁路口
for (BaseCrossInfoPO cross : crossList) {
// 车辆位置
double carLong = car.getLongitude();
double carLat = car.getLatitude();
String carLonLatStr = carLong + "," + carLat;
Geometry carGeo = GeometryUtil.str2Geometry(carLonLatStr);
// 路口缓冲区
String crossLocation = cross.getLocation();
double[] crossLonLat = CrossUtil.getLonLat(crossLocation);
String crossLonLatStr = crossLonLat[0] + "," + crossLonLat[1];
Geometry crossGeo = GeometryUtil.str2Geometry(crossLonLatStr);
Geometry crossBuff = GeomsConvertUtil.getGeometryBuf(crossGeo, "80.0");
if (carGeo.intersects(crossBuff)) {
// 解锁
LockControlVO vo = new LockControlVO();
String crossId = cross.getId();
vo.setCrossCode(crossId);
vo.setCommand(0);
vo.setDuration(999);
vo.setPhaseList(new ArrayList<>());
utcFeignClients.lockControl(vo);
// 修改路口为非自动解锁路口,状态为已解锁
SpecialServicePO specialServicePO = specialServiceMapper.selectIdByPlateNum(picLicense);
Integer specialServiceId = specialServicePO.getId();
specialServiceCrossMapper.updateStatusFail(crossId, specialServiceId);
// 给前端推送WebSocket
Set<WebSocketServer> events =
WebSocketServer.getWebSocketSet(Constant.WEBSOCKET_AUTO_UNLOCK);
if (CollectionUtil.isNotEmpty(events)) {
for (WebSocketServer socketServer : events) {
socketServer.sendMessage(crossId);
}
if (StrUtil.equals(picLicense, carPlate)) {
// 判断是否经过自动解锁路口
for (BaseCrossInfoPO cross : crossList) {
// 车辆位置
double carLong = car.getLongitude();
double carLat = car.getLatitude();
String carLonLatStr = carLong + "," + carLat;
Geometry carGeo = GeometryUtil.str2Geometry(carLonLatStr);
// 路口缓冲区
String crossLocation = cross.getLocation();
double[] crossLonLat = CrossUtil.getLonLat(crossLocation);
String crossLonLatStr = crossLonLat[0] + "," + crossLonLat[1];
Geometry crossGeo = GeometryUtil.str2Geometry(crossLonLatStr);
Geometry crossBuff = GeomsConvertUtil.getGeometryBuf(crossGeo, "80.0");
if (carGeo.intersects(crossBuff)) {
// 解锁
LockControlVO vo = new LockControlVO();
String crossId = cross.getId();
vo.setCrossCode(crossId);
vo.setCommand(0);
vo.setDuration(999);
vo.setPhaseList(new ArrayList<>());
utcFeignClients.lockControl(vo);
// 修改路口为非自动解锁路口,状态为已解锁
SpecialServicePO specialServicePO = specialServiceMapper.selectIdByPlateNum(picLicense);
Integer specialServiceId = specialServicePO.getId();
specialServiceCrossMapper.updateStatusFail(crossId, specialServiceId);
// 给前端推送WebSocket
Set<WebSocketServer> events =
WebSocketServer.getWebSocketSet(Constant.WEBSOCKET_AUTO_UNLOCK);
if (CollectionUtil.isNotEmpty(events)) {
for (WebSocketServer socketServer : events) {
socketServer.sendMessage(crossId);
}
}
crossList.remove(cross);
}
}
}
......
......@@ -18,6 +18,7 @@ import net.wanji.databus.vo.LockControlVO;
import net.wanji.feign.service.UtcFeignClients;
import net.wanji.web.bo.*;
import net.wanji.web.common.enums.CrossDirEnum;
import net.wanji.web.kafka.ConsumerHandler;
import net.wanji.web.mapper.*;
import net.wanji.web.po.SpecialServiceCrossPO;
import net.wanji.web.po.SpecialServicePO;
......@@ -70,11 +71,12 @@ public class SpecialServiceServiceImpl implements SpecialServiceService {
@Transactional
public void addOrUpdateSpecialService(AddSpecialServiceBO addSpecialServiceBO) {
Integer specialServiceId = addSpecialServiceBO.getId();
String plateNum = addSpecialServiceBO.getPlateNum();
if (ObjectUtil.isEmpty(specialServiceId)) { // 不传ID为新增
// 插入特勤表
SpecialServicePO specialServicePO = new SpecialServicePO();
specialServicePO.setName(addSpecialServiceBO.getName());
specialServicePO.setPlateNum(addSpecialServiceBO.getPlateNum());
specialServicePO.setPlateNum(plateNum);
specialServicePO.setStartLocation(addSpecialServiceBO.getStartLocation());
specialServicePO.setEndLocation(addSpecialServiceBO.getEndLocation());
......@@ -169,13 +171,12 @@ public class SpecialServiceServiceImpl implements SpecialServiceService {
SpecialServicePO specialServicePO = new SpecialServicePO();
specialServicePO.setId(specialServiceId);
specialServicePO.setName(addSpecialServiceBO.getName());
specialServicePO.setPlateNum(addSpecialServiceBO.getPlateNum());
specialServicePO.setPlateNum(plateNum);
specialServicePO.setStartLocation(addSpecialServiceBO.getStartLocation());
specialServicePO.setEndLocation(addSpecialServiceBO.getEndLocation());
specialServiceMapper.updateOne(specialServicePO);
// 修改特勤路口关系表
specialServiceCrossMapper.deleteCrossBySpecialServiceId(specialServiceId);
List<RouteElementVO> route = addSpecialServiceBO.getRoute();
......@@ -700,8 +701,12 @@ public class SpecialServiceServiceImpl implements SpecialServiceService {
}
@Override
@Transactional
public void autoUnlock(GroupListVO groupListVO) {
Integer specialServiceId = groupListVO.getSpecialServiceId();
SpecialServicePO specialServicePO = specialServiceMapper.selectById(specialServiceId);
String plateNum = specialServicePO.getPlateNum();
ConsumerHandler.updateCarplate(plateNum);
List<GroupListVO.GroupListElement> groupList = groupListVO.getGroupList();
for (GroupListVO.GroupListElement groupListElement : groupList) {
......@@ -713,6 +718,15 @@ public class SpecialServiceServiceImpl implements SpecialServiceService {
specialServiceCrossMapper.updateAutoUnlock(crossId, autoUnlock, specialServiceId, status);
}
}
List<BaseCrossInfoPO> crossList = new ArrayList<>();
List<SpecialServiceCrossPO> unLockCrosses = specialServiceCrossMapper.selectByAutoUnlock();
for (SpecialServiceCrossPO unLockCross : unLockCrosses) {
String crossId = unLockCross.getCrossId();
BaseCrossInfoPO baseCrossInfoPO = baseCrossInfoMapper.selectById(crossId);
crossList.add(baseCrossInfoPO);
}
ConsumerHandler.updateCrossList(crossList);
}
private List<GroupListVO.GroupListElement> buildGroupList(SpecialServicePO specialServicePO) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment