Commit 10fbf0c0 authored by duanruiming's avatar duanruiming

[add] 绿波时序图接口查询

parent 9ea7c2df
......@@ -56,5 +56,7 @@ public class Constants {
* 绿波优化查询缓存key
*/
public static final String GREEN_ID_OPT_KEY = "green_opt_";
public static final String GREEN_ID_OPT_CHART_KEY = "green_opt_chart_";
}
\ No newline at end of file
package net.wanji.opt.config;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.text.DecimalFormat;
/**
* @author duanruiming
* @date 2024/11/20 19:00
*/
public class DoubleToTwoDecimalPlacesSerializer extends JsonSerializer<Double> {
private static final DecimalFormat df = new DecimalFormat("#.00");
@Override
public void serialize(Double value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
if (value != null) {
String formattedValue = df.format(value);
gen.writeString(formattedValue);
} else {
gen.writeNull();
}
}
}
\ No newline at end of file
......@@ -70,4 +70,14 @@ public class GreenBeltKafkaDTO {
private int dynamic; // 是否动态绿波(1=是,0=否)
@JsonProperty("control_method")
private int controlMethod; // -1=stop by error, 0=no control, 1=control
@JsonProperty("travel_time_forward")
private Map<String, Double> travelTimeForward;
@JsonProperty("travel_time_backward")
private Map<String, Double> travelTimeBackward;
@JsonProperty("distance_forward")
private Map<String, Double> distanceForward;
@JsonProperty("distance_backward")
private Map<String, Double> distanceBackward;
}
package net.wanji.opt.kafka;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.common.utils.tool.StringUtils;
import net.wanji.opt.common.Constants;
import net.wanji.opt.common.RedisUtils;
import net.wanji.opt.service.GreenBeltInfoService;
import net.wanji.opt.vo.GreenBeltInfoVO;
import org.apache.kafka.clients.consumer.Consumer;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.listener.KafkaListenerErrorHandler;
import org.springframework.kafka.listener.ListenerExecutionFailedException;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @author duanruiming
* @date 2024/11/18 23:40
* @description 消费神思推送kafka数据,不同kafka
*/
@Component
@Slf4j
public class KafkaListeners implements KafkaListenerErrorHandler {
@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 {
if (StringUtils.isNotBlank(message)) {
GreenBeltInfoVO greenBeltInfoVO = greenBeltInfoService.convertData(message);
greenBeltInfoService.save(greenBeltInfoVO);
String key = Constants.GREEN_ID_OPT_KEY.concat(greenBeltInfoVO.getGreenId());
redisUtils.set(key, JacksonUtils.getInstance().writeValueAsString(greenBeltInfoVO));
}
}
@Override
@NonNull
public Object handleError(Message<?> message, ListenerExecutionFailedException e) {
return new Object();
}
@Override
@NonNull
public Object handleError(Message<?> message, ListenerExecutionFailedException exception, Consumer<?, ?> consumer) {
String errorMessage = String.format("监听主题:%s,消费者详情:%s,异常信息:%s,消息详情:%s",
consumer.listTopics(), consumer.groupMetadata(), exception, message);
log.error(errorMessage);
return KafkaListenerErrorHandler.super.handleError(message, exception, consumer);
}
}
......@@ -35,7 +35,7 @@ public class SynthesisConsumerHandler implements KafkaListenerErrorHandler {
private SynthesisOptimizeLogInfoMapper synthesisOptimizeLogInfoMapper;
private String str = "{\n" +
" \"cross_id\":\"cross0001\", \n" +
"\"cross_id\":\"cross0001\", \n" +
"\t\"control_id\":\"123456\", \n" +
"\t\"provider\":\"hisense\", \n" +
"\t\"plan_no\":4, \n" +
......
......@@ -3,7 +3,6 @@ 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;
......@@ -49,6 +48,7 @@ public class GreenBeltInfoServiceImpl implements GreenBeltInfoService {
greenBeltInfoVO.setDynamic(kafkaDTO.getDynamic());
greenBeltInfoVO.setControlMethod(kafkaDTO.getControlMethod());
greenBeltInfoVO.setDirGreenDetails(dirGreenDetails);
System.err.println(mapper.writeValueAsString(greenBeltInfoVO));
}
@Override
......@@ -123,6 +123,11 @@ public class GreenBeltInfoServiceImpl implements GreenBeltInfoService {
crossGreenDetail.setSpeed(speed);
Double offset = kafkaDTO.getOffset().get(crossId);
crossGreenDetail.setOffset(offset);
Double distance = kafkaDTO.getDistanceBackward().get(crossId);
crossGreenDetail.setDistance(distance);
Double travelTime = kafkaDTO.getTravelTimeBackward().get(crossId);
crossGreenDetail.setTravelTime(travelTime);
crossGreenDetails.add(crossGreenDetail);
}
// 反向绿波
......@@ -159,6 +164,11 @@ public class GreenBeltInfoServiceImpl implements GreenBeltInfoService {
crossGreenDetail.setSpeed(speed);
Double offset = kafkaDTO.getOffset().get(crossId);
crossGreenDetail.setOffset(offset);
Double distance = kafkaDTO.getDistanceForward().get(crossId);
crossGreenDetail.setDistance(distance);
Double travelTime = kafkaDTO.getTravelTimeForward().get(crossId);
crossGreenDetail.setTravelTime(travelTime);
crossGreenDetails.add(crossGreenDetail);
}
// 正向绿波
......@@ -181,64 +191,88 @@ public class GreenBeltInfoServiceImpl implements GreenBeltInfoService {
"\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\t\"13MQJ0B5SI0\": 91.0,\n" +
"\t\t\"13MS20B5SI0\": 25.0,\n" +
"\t\t\"13MUK0B5SH0\": 0.0,\n" +
"\t\t\"13N0F0B5SH0\": 45.0,\n" +
"\t\t\"13N200B5SH0\": 0.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\t\"13MQJ0B5SI0\": 91.0,\n" +
"\t\t\"13MS20B5SI0\": 25.0,\n" +
"\t\t\"13MUK0B5SH0\": 0.0,\n" +
"\t\t\"13N0F0B5SH0\": 45.0,\n" +
"\t\t\"13N200B5SH0\": 0.0\n" +
"\t},\n" +
"\t\"control_duration\": 90,\n" +
"\t\"control_duration\": 10,\n" +
"\t\"control_method\": 1,\n" +
"\t\"control_time\": \"2024-11-18T18:39:55\",\n" +
"\t\"control_time\": \"2024-11-20T18:15:31\",\n" +
"\t\"cycle\": {\n" +
"\t\t\"13MOD0B5SI0\": 220.0,\n" +
"\t\t\"13MQJ0B5SI0\": 220.0,\n" +
"\t\t\"13MS20B5SI0\": 220.0,\n" +
"\t\t\"13MUK0B5SH0\": 220.0,\n" +
"\t\t\"13N0F0B5SH0\": 220.0,\n" +
"\t\t\"13N200B5SH0\": 220.0\n" +
"\t},\n" +
"\t\"distance_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": -1.0,\n" +
"\t\t\"13MQJ0B5SI0\": 637.5,\n" +
"\t\t\"13MS20B5SI0\": 412.49999999999994,\n" +
"\t\t\"13MUK0B5SH0\": 725.0,\n" +
"\t\t\"13N0F0B5SH0\": 525.0,\n" +
"\t\t\"13N200B5SH0\": 450.0\n" +
"\t},\n" +
"\t\"distance_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 637.5,\n" +
"\t\t\"13MQJ0B5SI0\": 412.49999999999994,\n" +
"\t\t\"13MS20B5SI0\": 725.0,\n" +
"\t\t\"13MUK0B5SH0\": 525.0,\n" +
"\t\t\"13N0F0B5SH0\": 450.0,\n" +
"\t\t\"13N200B5SH0\": -1.0\n" +
"\t},\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\"green_width_backward\": 42.0,\n" +
"\t\"green_width_forward\": 41.0,\n" +
"\t\"greenbelt_direction\": 2,\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\"max_speed_backward\": 50.0,\n" +
"\t\"max_speed_forward\": 50.0,\n" +
"\t\"min_speed_backward\": 40.0,\n" +
"\t\"min_speed_forward\": 40.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\t\"13MOD0B5SI0\": 0.0,\n" +
"\t\t\"13MQJ0B5SI0\": 87.0,\n" +
"\t\t\"13MS20B5SI0\": 117.0,\n" +
"\t\t\"13MUK0B5SH0\": 119.0,\n" +
"\t\t\"13N0F0B5SH0\": 0.0,\n" +
"\t\t\"13N200B5SH0\": 0.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\t\"13MOD0B5SI0\": 142.0,\n" +
"\t\t\"13MQJ0B5SI0\": 175.0,\n" +
"\t\t\"13MS20B5SI0\": 158.0,\n" +
"\t\t\"13MUK0B5SH0\": 125.0,\n" +
"\t\t\"13N0F0B5SH0\": 175.0,\n" +
"\t\t\"13N200B5SH0\": 145.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\t\"13MOD0B5SI0\": 142.0,\n" +
"\t\t\"13MQJ0B5SI0\": 175.0,\n" +
"\t\t\"13MS20B5SI0\": 158.0,\n" +
"\t\t\"13MUK0B5SH0\": 125.0,\n" +
"\t\t\"13N0F0B5SH0\": 175.0,\n" +
"\t\t\"13N200B5SH0\": 145.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\"13MS20B5SI0\": 45.0,\n" +
"\t\t\"13MUK0B5SH0\": 0.0,\n" +
"\t\t\"13N0F0B5SH0\": 42.0,\n" +
"\t\t\"13N200B5SH0\": 40.0\n" +
......@@ -246,25 +280,41 @@ public class GreenBeltInfoServiceImpl implements GreenBeltInfoService {
"\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\"13MS20B5SI0\": 45.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\t\"13MQJ0B5SI0\": 45.0,\n" +
"\t\t\"13MS20B5SI0\": 44.99999999999999,\n" +
"\t\t\"13MUK0B5SH0\": 45.0,\n" +
"\t\t\"13N0F0B5SH0\": 45.0,\n" +
"\t\t\"13N200B5SH0\": 45.0\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\"13MOD0B5SI0\": 45.0,\n" +
"\t\t\"13MQJ0B5SI0\": 44.99999999999999,\n" +
"\t\t\"13MS20B5SI0\": 45.0,\n" +
"\t\t\"13MUK0B5SH0\": 45.0,\n" +
"\t\t\"13N0F0B5SH0\": 45.0,\n" +
"\t\t\"13N200B5SH0\": -1.0\n" +
"\t},\n" +
"\t\"travel_time_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": -1.0,\n" +
"\t\t\"13MQJ0B5SI0\": 51.0,\n" +
"\t\t\"13MS20B5SI0\": 33.0,\n" +
"\t\t\"13MUK0B5SH0\": 58.0,\n" +
"\t\t\"13N0F0B5SH0\": 42.0,\n" +
"\t\t\"13N200B5SH0\": 36.0\n" +
"\t},\n" +
"\t\"travel_time_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 51.0,\n" +
"\t\t\"13MQJ0B5SI0\": 33.0,\n" +
"\t\t\"13MS20B5SI0\": 58.0,\n" +
"\t\t\"13MUK0B5SH0\": 42.0,\n" +
"\t\t\"13N0F0B5SH0\": 36.0,\n" +
"\t\t\"13N200B5SH0\": -1.0\n" +
"\t}\n" +
"}";
......
......@@ -9,7 +9,7 @@ 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.GreenBeltChartVO;
import net.wanji.opt.vo.GreenBeltInfoVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -34,14 +34,14 @@ public class StrategyGreenBeltController {
@Resource
private GreenBeltInfoService greenBeltInfoService;
@ApiOperation(value = "绿波时序图查询", notes = "绿波时序图查询", response = JsonViewObject.class,
@ApiOperation(value = "绿波时序图数据查询", notes = "绿波时序图数据查询", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/strategyInfoOperation",
@PostMapping(value = "/greenBletData",
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 {
public JsonViewObject greenBletData(@RequestBody String greenId) throws Exception {
// todo 测试
GreenBeltInfoVO greenBeltInfoVO1 = greenBeltInfoService.convertData(null);
......@@ -54,4 +54,19 @@ public class StrategyGreenBeltController {
GreenBeltInfoVO greenBeltInfoVO = JacksonUtils.getInstance().readValue(String.valueOf(obj), GreenBeltInfoVO.class);
return jsonViewObject.success(greenBeltInfoVO);
}
@ApiOperation(value = "绿波时序图图形查询", notes = "绿波时序图图形查询", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/greenBeltChart",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = GreenBeltInfoVO.class),
})
public JsonViewObject greenBeltChart(@RequestBody String greenId) throws Exception {
String key = Constants.GREEN_ID_OPT_CHART_KEY.concat(greenId);
Object obj = redisUtils.get(key);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
GreenBeltChartVO greenBeltChartVO = JacksonUtils.getInstance().readValue(String.valueOf(obj), GreenBeltChartVO.class);
return jsonViewObject.success(greenBeltChartVO);
}
}
package net.wanji.opt.vo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import net.wanji.opt.config.DoubleToTwoDecimalPlacesSerializer;
import java.util.List;
......@@ -42,8 +44,10 @@ public class GreenBeltInfoVO {
@ApiModelProperty("绿波方向")
private String dir;
@ApiModelProperty("最大速度")
@JsonSerialize(using = DoubleToTwoDecimalPlacesSerializer.class)
private Double maxSpeed;
@ApiModelProperty("最小速度")
@JsonSerialize(using = DoubleToTwoDecimalPlacesSerializer.class)
private Double minSpeed;
@ApiModelProperty("绿波带宽")
private Double greenWidthTime;
......@@ -62,9 +66,15 @@ public class GreenBeltInfoVO {
@ApiModelProperty("绿波带开始时间")
private Double greenStartTime;
@ApiModelProperty("绿波速度")
@JsonSerialize(using = DoubleToTwoDecimalPlacesSerializer.class)
private Double speed;
@ApiModelProperty("相位差")
private Double offset;
@ApiModelProperty("行程时间")
private Double travelTime;
@ApiModelProperty("到下一个路口距离")
@JsonSerialize(using = DoubleToTwoDecimalPlacesSerializer.class)
private Double distance;
}
}
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