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" +
......
......@@ -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