Commit 88e44e38 authored by duanruiming's avatar duanruiming

[add] 绿波时序图功能提交

parent 3a3921e0
...@@ -52,4 +52,9 @@ public class Constants { ...@@ -52,4 +52,9 @@ public class Constants {
*/ */
public static final Integer CANCEL_STEP_CONTROL = 11; public static final Integer CANCEL_STEP_CONTROL = 11;
/**
* 绿波优化查询缓存key
*/
public static final String GREEN_ID_OPT_KEY = "green_opt_";
} }
\ No newline at end of file
...@@ -47,4 +47,32 @@ public class RedisUtils { ...@@ -47,4 +47,32 @@ public class RedisUtils {
} }
return null; return null;
} }
/**
* @description: 判断是否存在Key
* @param key redis的Key
* @return boolean true:有 false:无
*/
public boolean hasKey(String key) {
return redis7Template.hasKey(key);
}
/**
* @description: 添加字符串
* @param key redis的Key
* @param value 添加redis的value
*/
public void set(String key, String value) {
redis7Template.opsForValue().set(key, value);
}
/**
* @description: 获取对象
* @param key redis的Key
* @return Object 返回对象
*/
public Object get(String key) {
return redis7Template.opsForValue().get(key);
}
} }
package net.wanji.opt.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.opt.po.StrategyGreenOptHistEntity;
/**
* @author duanruiming
* @date 2024/11/19 18:02
* @description 神思推送绿波时序图信息
*/
public interface StrategyGreenOptHistMapper extends BaseMapper<StrategyGreenOptHistEntity> {
}
package net.wanji.opt.kafka; package net.wanji.opt.kafka;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.wanji.common.utils.tool.JacksonUtils; import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.common.utils.tool.StringUtils; import net.wanji.common.utils.tool.StringUtils;
import net.wanji.opt.dto.CrossSchedulesDTO; import net.wanji.opt.common.Constants;
import net.wanji.opt.dto.GreenBeltKafkaDTO; import net.wanji.opt.common.RedisUtils;
import net.wanji.opt.service.GreenBeltInfoService;
import net.wanji.opt.vo.GreenBeltInfoVO; import net.wanji.opt.vo.GreenBeltInfoVO;
import org.apache.kafka.clients.consumer.Consumer; import org.apache.kafka.clients.consumer.Consumer;
import org.springframework.kafka.annotation.KafkaListener; import org.springframework.kafka.annotation.KafkaListener;
...@@ -15,10 +15,7 @@ import org.springframework.kafka.listener.ListenerExecutionFailedException; ...@@ -15,10 +15,7 @@ import org.springframework.kafka.listener.ListenerExecutionFailedException;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @author duanruiming * @author duanruiming
...@@ -27,14 +24,21 @@ import java.util.Map; ...@@ -27,14 +24,21 @@ import java.util.Map;
*/ */
@Component @Component
@Slf4j @Slf4j
public class KafkaListeners implements KafkaListenerErrorHandler { public class KafkaListeners implements KafkaListenerErrorHandler {
@KafkaListener(topics = {"green_belt_info_data"}, groupId = "group2", containerFactory = "kafkaListenerContainerFactory2") @Resource
private GreenBeltInfoService greenBeltInfoService;
@Resource
private RedisUtils redisUtils;
@KafkaListener(topics = {"green_belt_info_data"}, groupId = "group2", containerFactory = "kafkaListenerContainerFactory2")
public void receiveGreenBeltInfoData(String message) throws Exception { public void receiveGreenBeltInfoData(String message) throws Exception {
if (StringUtils.isNotBlank(message)) { if (StringUtils.isNotBlank(message)) {
message = greenBeltInfoData; GreenBeltInfoVO greenBeltInfoVO = greenBeltInfoService.convertData(message);
ObjectMapper mapper = JacksonUtils.getInstance(); greenBeltInfoService.save(greenBeltInfoVO);
GreenBeltKafkaDTO greenBeltKafkaDTO = mapper.readValue(greenBeltInfoData, GreenBeltKafkaDTO.class); String key = Constants.GREEN_ID_OPT_KEY.concat(greenBeltInfoVO.getGreenId());
redisUtils.set(key, JacksonUtils.getInstance().writeValueAsString(greenBeltInfoVO));
} }
} }
...@@ -53,191 +57,4 @@ public class KafkaListeners implements KafkaListenerErrorHandler { ...@@ -53,191 +57,4 @@ public class KafkaListeners implements KafkaListenerErrorHandler {
return KafkaListenerErrorHandler.super.handleError(message, exception, consumer); return KafkaListenerErrorHandler.super.handleError(message, exception, consumer);
} }
public static void main(String[] args) throws Exception {
String message = greenBeltInfoData;
ObjectMapper mapper = JacksonUtils.getInstance();
GreenBeltKafkaDTO kafkaDTO = mapper.readValue(message, GreenBeltKafkaDTO.class);
// 正反绿波容器
List<GreenBeltInfoVO.DirGreenDetail> dirGreenDetails = new ArrayList<>();
// 构建正向绿波
setForward(kafkaDTO, dirGreenDetails);
// 反向绿波
setBackward(kafkaDTO, dirGreenDetails);
// 返回绿波实体
GreenBeltInfoVO greenBeltInfoVO = new GreenBeltInfoVO();
greenBeltInfoVO.setGreenId(kafkaDTO.getGreenbeltId());
greenBeltInfoVO.setLength(kafkaDTO.getGreenbeltLength());
greenBeltInfoVO.setCycle(kafkaDTO.getMaxCycle());
greenBeltInfoVO.setControlTime(kafkaDTO.getControlTime());
greenBeltInfoVO.setControlDuration(kafkaDTO.getControlDuration());
greenBeltInfoVO.setType(kafkaDTO.getGreenbeltType());
greenBeltInfoVO.setDynamic(kafkaDTO.getDynamic());
greenBeltInfoVO.setControlMethod(kafkaDTO.getControlMethod());
greenBeltInfoVO.setDirGreenDetails(dirGreenDetails);
System.err.println(mapper.writeValueAsString(greenBeltInfoVO));
}
private static void setBackward(GreenBeltKafkaDTO kafkaDTO, List<GreenBeltInfoVO.DirGreenDetail> dirGreenDetails) {
// 反向绿波路口列表
List<GreenBeltInfoVO.CrossGreenDetail> crossGreenDetails = new ArrayList<>();
Map<String, Double> phaseStartBackward = kafkaDTO.getPhaseStartBackward();
for (Map.Entry<String, Double> backEntry : phaseStartBackward.entrySet()) {
String crossId = backEntry.getKey();
Double phaseStartTime = backEntry.getValue();
GreenBeltInfoVO.CrossGreenDetail crossGreenDetail = new GreenBeltInfoVO.CrossGreenDetail();
crossGreenDetail.setCrossId(crossId);
crossGreenDetail.setPhaseStartTime(phaseStartTime);
Double phaseEndTime = kafkaDTO.getPhaseEndBackward().get(crossId);
crossGreenDetail.setPhaseEndTime(phaseEndTime);
Double greenStartTime = kafkaDTO.getBeltStartBackward().get(crossId);
crossGreenDetail.setGreenStartTime(greenStartTime);
Double speed = kafkaDTO.getSpeedBackward().get(crossId);
crossGreenDetail.setSpeed(speed);
Double offset = kafkaDTO.getOffset().get(crossId);
crossGreenDetail.setOffset(offset);
crossGreenDetails.add(crossGreenDetail);
}
// 反向绿波
// 反向绿波实体
GreenBeltInfoVO.DirGreenDetail dirGreenDetail = new GreenBeltInfoVO.DirGreenDetail();
dirGreenDetail.setDirType(0);
String forwardDirection = kafkaDTO.getBackwardDirection();
dirGreenDetail.setDir(forwardDirection);
double maxSpeedForward = kafkaDTO.getMaxSpeedBackward();
dirGreenDetail.setMaxSpeed(maxSpeedForward);
double minSpeedForward = kafkaDTO.getMinSpeedBackward();
dirGreenDetail.setMinSpeed(minSpeedForward);
double greenWidthForward = kafkaDTO.getGreenWidthBackward();
dirGreenDetail.setGreenWithTime(greenWidthForward);
dirGreenDetail.setCrossGreenDetailList(crossGreenDetails);
dirGreenDetails.add(dirGreenDetail);
}
private static void setForward(GreenBeltKafkaDTO kafkaDTO, List<GreenBeltInfoVO.DirGreenDetail> dirGreenDetails) {
// 正向绿波路口列表
List<GreenBeltInfoVO.CrossGreenDetail> crossGreenDetails = new ArrayList<>();
Map<String, Double> phaseStartForward = kafkaDTO.getPhaseStartForward();
for (Map.Entry<String, Double> forwardEntry : phaseStartForward.entrySet()) {
String crossId = forwardEntry.getKey();
Double phaseStartTime = forwardEntry.getValue();
GreenBeltInfoVO.CrossGreenDetail crossGreenDetail = new GreenBeltInfoVO.CrossGreenDetail();
crossGreenDetail.setCrossId(crossId);
crossGreenDetail.setPhaseStartTime(phaseStartTime);
Double phaseEndTime = kafkaDTO.getPhaseEndForward().get(crossId);
crossGreenDetail.setPhaseEndTime(phaseEndTime);
Double greenStartTime = kafkaDTO.getBeltStartForward().get(crossId);
crossGreenDetail.setGreenStartTime(greenStartTime);
Double speed = kafkaDTO.getSpeedForward().get(crossId);
crossGreenDetail.setSpeed(speed);
Double offset = kafkaDTO.getOffset().get(crossId);
crossGreenDetail.setOffset(offset);
crossGreenDetails.add(crossGreenDetail);
}
// 正向绿波
// 正向绿波实体
GreenBeltInfoVO.DirGreenDetail dirGreenDetail = new GreenBeltInfoVO.DirGreenDetail();
dirGreenDetail.setDirType(1);
String forwardDirection = kafkaDTO.getForwardDirection();
dirGreenDetail.setDir(forwardDirection);
double maxSpeedForward = kafkaDTO.getMaxSpeedForward();
dirGreenDetail.setMaxSpeed(maxSpeedForward);
double minSpeedForward = kafkaDTO.getMinSpeedForward();
dirGreenDetail.setMinSpeed(minSpeedForward);
double greenWidthForward = kafkaDTO.getGreenWidthForward();
dirGreenDetail.setGreenWithTime(greenWidthForward);
dirGreenDetail.setCrossGreenDetailList(crossGreenDetails);
dirGreenDetails.add(dirGreenDetail);
}
public static String greenBeltInfoData = "{\n" +
"\t\"backward_direction\": \"e2w\",\n" +
"\t\"belt_start_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": 0.0,\n" +
"\t\t\"13MQJ0B5SI0\": 87.0,\n" +
"\t\t\"13MS20B5SI0\": 7.0,\n" +
"\t\t\"13MUK0B5SH0\": 79.0,\n" +
"\t\t\"13N0F0B5SH0\": 3.0,\n" +
"\t\t\"13N200B5SH0\": 86.0\n" +
"\t},\n" +
"\t\"belt_start_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 0.0,\n" +
"\t\t\"13MQJ0B5SI0\": 87.0,\n" +
"\t\t\"13MS20B5SI0\": 7.0,\n" +
"\t\t\"13MUK0B5SH0\": 79.0,\n" +
"\t\t\"13N0F0B5SH0\": 3.0,\n" +
"\t\t\"13N200B5SH0\": 86.0\n" +
"\t},\n" +
"\t\"control_duration\": 90,\n" +
"\t\"control_method\": 1,\n" +
"\t\"control_time\": \"2024-11-18T18:39:55\",\n" +
"\t\"dynamic\": 1,\n" +
"\t\"forward_direction\": \"w2e\",\n" +
"\t\"green_width_backward\": 35.9999999999999,\n" +
"\t\"green_width_forward\": 80.0,\n" +
"\t\"greenbelt_direction\": 0,\n" +
"\t\"greenbelt_id\": \"road1\",\n" +
"\t\"greenbelt_length\": 2757.0,\n" +
"\t\"greenbelt_type\": 2,\n" +
"\t\"max_cycle\": 220,\n" +
"\t\"max_speed_backward\": 45.0,\n" +
"\t\"max_speed_forward\": 35.0,\n" +
"\t\"min_speed_backward\": 35.0,\n" +
"\t\"min_speed_forward\": 25.0,\n" +
"\t\"offset\": {\n" +
"\t\t\"13MOD0B5SI0\": 198.0,\n" +
"\t\t\"13MQJ0B5SI0\": 46.0,\n" +
"\t\t\"13MS20B5SI0\": 89.0,\n" +
"\t\t\"13MUK0B5SH0\": 216.0,\n" +
"\t\t\"13N0F0B5SH0\": 201.0,\n" +
"\t\t\"13N200B5SH0\": 89.0\n" +
"\t},\n" +
"\t\"phase_end_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": 132.0,\n" +
"\t\t\"13MQJ0B5SI0\": 165.0,\n" +
"\t\t\"13MS20B5SI0\": 148.0,\n" +
"\t\t\"13MUK0B5SH0\": 115.0,\n" +
"\t\t\"13N0F0B5SH0\": 165.0,\n" +
"\t\t\"13N200B5SH0\": 155.0\n" +
"\t},\n" +
"\t\"phase_end_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 132.0,\n" +
"\t\t\"13MQJ0B5SI0\": 165.0,\n" +
"\t\t\"13MS20B5SI0\": 148.0,\n" +
"\t\t\"13MUK0B5SH0\": 115.0,\n" +
"\t\t\"13N0F0B5SH0\": 165.0,\n" +
"\t\t\"13N200B5SH0\": 155.0\n" +
"\t},\n" +
"\t\"phase_start_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": 39.0,\n" +
"\t\t\"13MQJ0B5SI0\": 42.0,\n" +
"\t\t\"13MS20B5SI0\": 43.0,\n" +
"\t\t\"13MUK0B5SH0\": 0.0,\n" +
"\t\t\"13N0F0B5SH0\": 42.0,\n" +
"\t\t\"13N200B5SH0\": 40.0\n" +
"\t},\n" +
"\t\"phase_start_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 39.0,\n" +
"\t\t\"13MQJ0B5SI0\": 42.0,\n" +
"\t\t\"13MS20B5SI0\": 43.0,\n" +
"\t\t\"13MUK0B5SH0\": 0.0,\n" +
"\t\t\"13N0F0B5SH0\": 42.0,\n" +
"\t\t\"13N200B5SH0\": 40.0\n" +
"\t},\n" +
"\t\"speed_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": -1.0,\n" +
"\t\t\"13MQJ0B5SI0\": 36.608,\n" +
"\t\t\"13MS20B5SI0\": 41.257999999999996,\n" +
"\t\t\"13MUK0B5SH0\": 40.976,\n" +
"\t\t\"13N0F0B5SH0\": 38.536,\n" +
"\t\t\"13N200B5SH0\": 42.28\n" +
"\t},\n" +
"\t\"speed_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 30.315999999999995,\n" +
"\t\t\"13MQJ0B5SI0\": 23.904,\n" +
"\t\t\"13MS20B5SI0\": 41.739999999999995,\n" +
"\t\t\"13MUK0B5SH0\": 27.832000000000004,\n" +
"\t\t\"13N0F0B5SH0\": 25.536,\n" +
"\t\t\"13N200B5SH0\": -1.0\n" +
"\t}\n" +
"}";
} }
package net.wanji.opt.po;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
/**
* @author duanruiming
* @date 2024/11/19 17:48
*/
@Data
@TableName("t_strategy_green_opt_hist")
public class StrategyGreenOptHistEntity {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@TableField("green_id")
private String greenId;
@TableField("length")
private Double length;
@TableField("cycle")
private Integer cycle;
@TableField("control_time")
private String controlTime;
@TableField("control_duration")
private Integer controlDuration;
@TableField("control_method")
private Integer controlMethod;
@TableField("type")
private Integer type;
@TableField("dynamic")
private Integer dynamic;
@TableField("dir_type")
private Integer dirType;
@TableField("dir")
private String dir;
@TableField("max_speed")
private Double maxSpeed;
@TableField("min_speed")
private Double minSpeed;
@TableField("green_width_time")
private Double greenWidthTime;
@TableField("cross_green_detail")
private String crossGreenDetail;
@TableField("create_time")
private Date createTime;
@TableField("modify_time")
private Date modifyTime;
}
package net.wanji.opt.service;
import net.wanji.opt.vo.GreenBeltInfoVO;
/**
* @author duanruiming
* @date 2024/11/19 18:07
*/
public interface GreenBeltInfoService {
/**
* 数据转换
* @param message
* @return
* @throws Exception
*/
GreenBeltInfoVO convertData(String message) throws Exception;
/**
* 存储
* @param infoVO
* @throws Exception
*/
void save(GreenBeltInfoVO infoVO) throws Exception;
}
package net.wanji.opt.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.opt.common.Constants;
import net.wanji.opt.common.RedisUtils;
import net.wanji.opt.dao.mapper.StrategyGreenOptHistMapper;
import net.wanji.opt.dto.GreenBeltKafkaDTO;
import net.wanji.opt.po.StrategyGreenOptHistEntity;
import net.wanji.opt.service.GreenBeltInfoService;
import net.wanji.opt.vo.GreenBeltInfoVO;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* @author duanruiming
* @date 2024/11/19 19:04
*/
@Service
public class GreenBeltInfoServiceImpl implements GreenBeltInfoService {
@Resource
private StrategyGreenOptHistMapper strategyGreenOptHistMapper;
public static void main(String[] args) throws Exception {
String message = greenBeltInfoData;
ObjectMapper mapper = JacksonUtils.getInstance();
GreenBeltKafkaDTO kafkaDTO = mapper.readValue(message, GreenBeltKafkaDTO.class);
// 正反绿波容器
List<GreenBeltInfoVO.DirGreenDetail> dirGreenDetails = new ArrayList<>();
// 构建正向绿波
setForward(kafkaDTO, dirGreenDetails);
// 反向绿波
setBackward(kafkaDTO, dirGreenDetails);
// 返回绿波实体
GreenBeltInfoVO greenBeltInfoVO = new GreenBeltInfoVO();
greenBeltInfoVO.setGreenId(kafkaDTO.getGreenbeltId());
greenBeltInfoVO.setLength(kafkaDTO.getGreenbeltLength());
greenBeltInfoVO.setCycle(kafkaDTO.getMaxCycle());
greenBeltInfoVO.setControlTime(kafkaDTO.getControlTime());
greenBeltInfoVO.setControlDuration(kafkaDTO.getControlDuration());
greenBeltInfoVO.setType(kafkaDTO.getGreenbeltType());
greenBeltInfoVO.setDynamic(kafkaDTO.getDynamic());
greenBeltInfoVO.setControlMethod(kafkaDTO.getControlMethod());
greenBeltInfoVO.setDirGreenDetails(dirGreenDetails);
}
@Override
public GreenBeltInfoVO convertData(String message) throws Exception {
ObjectMapper mapper = JacksonUtils.getInstance();
GreenBeltKafkaDTO kafkaDTO = mapper.readValue(greenBeltInfoData, GreenBeltKafkaDTO.class);
// 正反绿波容器
List<GreenBeltInfoVO.DirGreenDetail> dirGreenDetails = new ArrayList<>();
// 构建正向绿波
setForward(kafkaDTO, dirGreenDetails);
// 反向绿波
setBackward(kafkaDTO, dirGreenDetails);
// 返回绿波实体
GreenBeltInfoVO greenBeltInfoVO = new GreenBeltInfoVO();
greenBeltInfoVO.setGreenId(kafkaDTO.getGreenbeltId());
greenBeltInfoVO.setLength(kafkaDTO.getGreenbeltLength());
greenBeltInfoVO.setCycle(kafkaDTO.getMaxCycle());
greenBeltInfoVO.setControlTime(kafkaDTO.getControlTime());
greenBeltInfoVO.setControlDuration(kafkaDTO.getControlDuration());
greenBeltInfoVO.setType(kafkaDTO.getGreenbeltType());
greenBeltInfoVO.setDynamic(kafkaDTO.getDynamic());
greenBeltInfoVO.setControlMethod(kafkaDTO.getControlMethod());
greenBeltInfoVO.setDirGreenDetails(dirGreenDetails);
return greenBeltInfoVO;
}
@Override
public void save(GreenBeltInfoVO infoVO) throws Exception {
if (Objects.nonNull(infoVO)) {
List<GreenBeltInfoVO.DirGreenDetail> dirGreenDetails = infoVO.getDirGreenDetails();
if (!CollectionUtils.isEmpty(dirGreenDetails)) {
for (GreenBeltInfoVO.DirGreenDetail dirGreenDetail : dirGreenDetails) {
StrategyGreenOptHistEntity entity = new StrategyGreenOptHistEntity();
entity.setGreenId(infoVO.getGreenId());
entity.setLength(infoVO.getLength());
entity.setCycle(infoVO.getCycle());
entity.setControlTime(infoVO.getControlTime());
entity.setControlDuration(infoVO.getControlDuration());
entity.setControlMethod(infoVO.getControlMethod());
entity.setType(infoVO.getType());
entity.setDynamic(infoVO.getDynamic());
entity.setDirType(dirGreenDetail.getDirType());
entity.setDir(dirGreenDetail.getDir());
entity.setMaxSpeed(dirGreenDetail.getMaxSpeed());
entity.setMinSpeed(dirGreenDetail.getMinSpeed());
entity.setGreenWidthTime(dirGreenDetail.getGreenWidthTime());
entity.setCrossGreenDetail(JacksonUtils.getInstance().writeValueAsString(dirGreenDetail.getCrossGreenDetailList()));
strategyGreenOptHistMapper.insert(entity);
String key = Constants.GREEN_ID_OPT_KEY.concat(infoVO.getGreenId());
}
}
}
}
private static void setBackward(GreenBeltKafkaDTO kafkaDTO, List<GreenBeltInfoVO.DirGreenDetail> dirGreenDetails) {
// 反向绿波路口列表
List<GreenBeltInfoVO.CrossGreenDetail> crossGreenDetails = new ArrayList<>();
Map<String, Double> phaseStartBackward = kafkaDTO.getPhaseStartBackward();
for (Map.Entry<String, Double> backEntry : phaseStartBackward.entrySet()) {
String crossId = backEntry.getKey();
Double phaseStartTime = backEntry.getValue();
GreenBeltInfoVO.CrossGreenDetail crossGreenDetail = new GreenBeltInfoVO.CrossGreenDetail();
crossGreenDetail.setCrossId(crossId);
crossGreenDetail.setPhaseStartTime(phaseStartTime);
Double phaseEndTime = kafkaDTO.getPhaseEndBackward().get(crossId);
crossGreenDetail.setPhaseEndTime(phaseEndTime);
Double greenStartTime = kafkaDTO.getBeltStartBackward().get(crossId);
crossGreenDetail.setGreenStartTime(greenStartTime);
Double speed = kafkaDTO.getSpeedBackward().get(crossId);
crossGreenDetail.setSpeed(speed);
Double offset = kafkaDTO.getOffset().get(crossId);
crossGreenDetail.setOffset(offset);
crossGreenDetails.add(crossGreenDetail);
}
// 反向绿波
// 反向绿波实体
GreenBeltInfoVO.DirGreenDetail dirGreenDetail = new GreenBeltInfoVO.DirGreenDetail();
dirGreenDetail.setDirType(0);
String forwardDirection = kafkaDTO.getBackwardDirection();
dirGreenDetail.setDir(forwardDirection);
double maxSpeedForward = kafkaDTO.getMaxSpeedBackward();
dirGreenDetail.setMaxSpeed(maxSpeedForward);
double minSpeedForward = kafkaDTO.getMinSpeedBackward();
dirGreenDetail.setMinSpeed(minSpeedForward);
double greenWidthForward = kafkaDTO.getGreenWidthBackward();
dirGreenDetail.setGreenWidthTime(greenWidthForward);
dirGreenDetail.setCrossGreenDetailList(crossGreenDetails);
dirGreenDetails.add(dirGreenDetail);
}
private static void setForward(GreenBeltKafkaDTO kafkaDTO, List<GreenBeltInfoVO.DirGreenDetail> dirGreenDetails) {
// 正向绿波路口列表
List<GreenBeltInfoVO.CrossGreenDetail> crossGreenDetails = new ArrayList<>();
Map<String, Double> phaseStartForward = kafkaDTO.getPhaseStartForward();
for (Map.Entry<String, Double> forwardEntry : phaseStartForward.entrySet()) {
String crossId = forwardEntry.getKey();
Double phaseStartTime = forwardEntry.getValue();
GreenBeltInfoVO.CrossGreenDetail crossGreenDetail = new GreenBeltInfoVO.CrossGreenDetail();
crossGreenDetail.setCrossId(crossId);
crossGreenDetail.setPhaseStartTime(phaseStartTime);
Double phaseEndTime = kafkaDTO.getPhaseEndForward().get(crossId);
crossGreenDetail.setPhaseEndTime(phaseEndTime);
Double greenStartTime = kafkaDTO.getBeltStartForward().get(crossId);
crossGreenDetail.setGreenStartTime(greenStartTime);
Double speed = kafkaDTO.getSpeedForward().get(crossId);
crossGreenDetail.setSpeed(speed);
Double offset = kafkaDTO.getOffset().get(crossId);
crossGreenDetail.setOffset(offset);
crossGreenDetails.add(crossGreenDetail);
}
// 正向绿波
// 正向绿波实体
GreenBeltInfoVO.DirGreenDetail dirGreenDetail = new GreenBeltInfoVO.DirGreenDetail();
dirGreenDetail.setDirType(1);
String forwardDirection = kafkaDTO.getForwardDirection();
dirGreenDetail.setDir(forwardDirection);
double maxSpeedForward = kafkaDTO.getMaxSpeedForward();
dirGreenDetail.setMaxSpeed(maxSpeedForward);
double minSpeedForward = kafkaDTO.getMinSpeedForward();
dirGreenDetail.setMinSpeed(minSpeedForward);
double greenWidthForward = kafkaDTO.getGreenWidthForward();
dirGreenDetail.setGreenWidthTime(greenWidthForward);
dirGreenDetail.setCrossGreenDetailList(crossGreenDetails);
dirGreenDetails.add(dirGreenDetail);
}
public static String greenBeltInfoData = "{\n" +
"\t\"backward_direction\": \"e2w\",\n" +
"\t\"belt_start_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": 0.0,\n" +
"\t\t\"13MQJ0B5SI0\": 87.0,\n" +
"\t\t\"13MS20B5SI0\": 7.0,\n" +
"\t\t\"13MUK0B5SH0\": 79.0,\n" +
"\t\t\"13N0F0B5SH0\": 3.0,\n" +
"\t\t\"13N200B5SH0\": 86.0\n" +
"\t},\n" +
"\t\"belt_start_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 0.0,\n" +
"\t\t\"13MQJ0B5SI0\": 87.0,\n" +
"\t\t\"13MS20B5SI0\": 7.0,\n" +
"\t\t\"13MUK0B5SH0\": 79.0,\n" +
"\t\t\"13N0F0B5SH0\": 3.0,\n" +
"\t\t\"13N200B5SH0\": 86.0\n" +
"\t},\n" +
"\t\"control_duration\": 90,\n" +
"\t\"control_method\": 1,\n" +
"\t\"control_time\": \"2024-11-18T18:39:55\",\n" +
"\t\"dynamic\": 1,\n" +
"\t\"forward_direction\": \"w2e\",\n" +
"\t\"green_width_backward\": 35.9999999999999,\n" +
"\t\"green_width_forward\": 80.0,\n" +
"\t\"greenbelt_direction\": 0,\n" +
"\t\"greenbelt_id\": \"road1\",\n" +
"\t\"greenbelt_length\": 2757.0,\n" +
"\t\"greenbelt_type\": 2,\n" +
"\t\"max_cycle\": 220,\n" +
"\t\"max_speed_backward\": 45.0,\n" +
"\t\"max_speed_forward\": 35.0,\n" +
"\t\"min_speed_backward\": 35.0,\n" +
"\t\"min_speed_forward\": 25.0,\n" +
"\t\"offset\": {\n" +
"\t\t\"13MOD0B5SI0\": 198.0,\n" +
"\t\t\"13MQJ0B5SI0\": 46.0,\n" +
"\t\t\"13MS20B5SI0\": 89.0,\n" +
"\t\t\"13MUK0B5SH0\": 216.0,\n" +
"\t\t\"13N0F0B5SH0\": 201.0,\n" +
"\t\t\"13N200B5SH0\": 89.0\n" +
"\t},\n" +
"\t\"phase_end_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": 132.0,\n" +
"\t\t\"13MQJ0B5SI0\": 165.0,\n" +
"\t\t\"13MS20B5SI0\": 148.0,\n" +
"\t\t\"13MUK0B5SH0\": 115.0,\n" +
"\t\t\"13N0F0B5SH0\": 165.0,\n" +
"\t\t\"13N200B5SH0\": 155.0\n" +
"\t},\n" +
"\t\"phase_end_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 132.0,\n" +
"\t\t\"13MQJ0B5SI0\": 165.0,\n" +
"\t\t\"13MS20B5SI0\": 148.0,\n" +
"\t\t\"13MUK0B5SH0\": 115.0,\n" +
"\t\t\"13N0F0B5SH0\": 165.0,\n" +
"\t\t\"13N200B5SH0\": 155.0\n" +
"\t},\n" +
"\t\"phase_start_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": 39.0,\n" +
"\t\t\"13MQJ0B5SI0\": 42.0,\n" +
"\t\t\"13MS20B5SI0\": 43.0,\n" +
"\t\t\"13MUK0B5SH0\": 0.0,\n" +
"\t\t\"13N0F0B5SH0\": 42.0,\n" +
"\t\t\"13N200B5SH0\": 40.0\n" +
"\t},\n" +
"\t\"phase_start_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 39.0,\n" +
"\t\t\"13MQJ0B5SI0\": 42.0,\n" +
"\t\t\"13MS20B5SI0\": 43.0,\n" +
"\t\t\"13MUK0B5SH0\": 0.0,\n" +
"\t\t\"13N0F0B5SH0\": 42.0,\n" +
"\t\t\"13N200B5SH0\": 40.0\n" +
"\t},\n" +
"\t\"speed_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": -1.0,\n" +
"\t\t\"13MQJ0B5SI0\": 36.608,\n" +
"\t\t\"13MS20B5SI0\": 41.257999999999996,\n" +
"\t\t\"13MUK0B5SH0\": 40.976,\n" +
"\t\t\"13N0F0B5SH0\": 38.536,\n" +
"\t\t\"13N200B5SH0\": 42.28\n" +
"\t},\n" +
"\t\"speed_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 30.315999999999995,\n" +
"\t\t\"13MQJ0B5SI0\": 23.904,\n" +
"\t\t\"13MS20B5SI0\": 41.739999999999995,\n" +
"\t\t\"13MUK0B5SH0\": 27.832000000000004,\n" +
"\t\t\"13N0F0B5SH0\": 25.536,\n" +
"\t\t\"13N200B5SH0\": -1.0\n" +
"\t}\n" +
"}";
}
package net.wanji.opt.synthesis.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.opt.common.Constants;
import net.wanji.opt.common.RedisUtils;
import net.wanji.opt.service.GreenBeltInfoService;
import net.wanji.opt.synthesis.pojo.StrategyControlVO;
import net.wanji.opt.vo.GreenBeltInfoVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.ws.rs.core.MediaType;
/**
* @author duanruiming
* @date 2024/11/19 20:10
* @description 神思推送绿波时序图
*/
@Api(value = "StrategyGreenBeltController", description = "策略绿波带")
@RequestMapping("/strategyBelt")
@RestController
public class StrategyGreenBeltController {
@Resource
private RedisUtils redisUtils;
@Resource
private GreenBeltInfoService greenBeltInfoService;
@ApiOperation(value = "绿波时序图查询", notes = "绿波时序图查询", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/strategyInfoOperation",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = GreenBeltInfoVO.class),
})
public JsonViewObject strategyInfoOperation(@RequestBody String greenId) throws Exception {
// todo 测试
GreenBeltInfoVO greenBeltInfoVO1 = greenBeltInfoService.convertData(null);
greenBeltInfoService.save(greenBeltInfoVO1);
String key = Constants.GREEN_ID_OPT_KEY.concat(greenId);
redisUtils.set(key, JacksonUtils.getInstance().writeValueAsString(greenBeltInfoVO1));
Object obj = redisUtils.get(key);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
GreenBeltInfoVO greenBeltInfoVO = JacksonUtils.getInstance().readValue(String.valueOf(obj), GreenBeltInfoVO.class);
return jsonViewObject.success(greenBeltInfoVO);
}
}
...@@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModel; ...@@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
...@@ -47,7 +46,7 @@ public class GreenBeltInfoVO { ...@@ -47,7 +46,7 @@ public class GreenBeltInfoVO {
@ApiModelProperty("最小速度") @ApiModelProperty("最小速度")
private Double minSpeed; private Double minSpeed;
@ApiModelProperty("绿波带宽") @ApiModelProperty("绿波带宽")
private Double greenWithTime; private Double greenWidthTime;
@ApiModelProperty("绿波路口详情") @ApiModelProperty("绿波路口详情")
private List<CrossGreenDetail> crossGreenDetailList; private List<CrossGreenDetail> crossGreenDetailList;
} }
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.wanji.opt.dao.mapper.StrategyGreenOptHistMapper">
</mapper>
\ No newline at end of file
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