Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
traffic-signal-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
signal
traffic-signal-platform
Commits
10fbf0c0
Commit
10fbf0c0
authored
Nov 22, 2024
by
duanruiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[add] 绿波时序图接口查询
parent
9ea7c2df
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
168 additions
and
115 deletions
+168
-115
Constants.java
...service/src/main/java/net/wanji/opt/common/Constants.java
+2
-0
DoubleToTwoDecimalPlacesSerializer.java
.../wanji/opt/config/DoubleToTwoDecimalPlacesSerializer.java
+26
-0
GreenBeltKafkaDTO.java
...ce/src/main/java/net/wanji/opt/dto/GreenBeltKafkaDTO.java
+10
-0
KafkaListeners.java
...ice/src/main/java/net/wanji/opt/kafka/KafkaListeners.java
+0
-60
SynthesisConsumerHandler.java
...in/java/net/wanji/opt/kafka/SynthesisConsumerHandler.java
+1
-1
GreenBeltInfoServiceImpl.java
.../net/wanji/opt/service/impl/GreenBeltInfoServiceImpl.java
+100
-50
StrategyGreenBeltController.java
...opt/synthesis/controller/StrategyGreenBeltController.java
+19
-4
GreenBeltInfoVO.java
...rvice/src/main/java/net/wanji/opt/vo/GreenBeltInfoVO.java
+10
-0
No files found.
signal-optimize-service/src/main/java/net/wanji/opt/common/Constants.java
View file @
10fbf0c0
...
...
@@ -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
signal-optimize-service/src/main/java/net/wanji/opt/config/DoubleToTwoDecimalPlacesSerializer.java
0 → 100644
View file @
10fbf0c0
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
signal-optimize-service/src/main/java/net/wanji/opt/dto/GreenBeltKafkaDTO.java
View file @
10fbf0c0
...
...
@@ -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
;
}
signal-optimize-service/src/main/java/net/wanji/opt/kafka/KafkaListeners.java
deleted
100644 → 0
View file @
9ea7c2df
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
);
}
}
signal-optimize-service/src/main/java/net/wanji/opt/kafka/SynthesisConsumerHandler.java
View file @
10fbf0c0
...
...
@@ -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"
+
...
...
signal-optimize-service/src/main/java/net/wanji/opt/service/impl/GreenBeltInfoServiceImpl.java
View file @
10fbf0c0
This diff is collapsed.
Click to expand it.
signal-optimize-service/src/main/java/net/wanji/opt/synthesis/controller/StrategyGreenBeltController.java
View file @
10fbf0c0
...
...
@@ -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.StrategyControl
VO
;
import
net.wanji.opt.
vo.GreenBeltChart
VO
;
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
);
}
}
signal-optimize-service/src/main/java/net/wanji/opt/vo/GreenBeltInfoVO.java
View file @
10fbf0c0
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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment