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
af2428c0
Commit
af2428c0
authored
Jan 05, 2025
by
zhouleilei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
控制指令新增日志
parent
87055487
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
50 deletions
+78
-50
ControlCommandStrategyServiceImpl.java
...rvice/control/impl/ControlCommandStrategyServiceImpl.java
+28
-8
CommandFaildTask.java
...ce/src/main/java/net/wanji/utc/task/CommandFaildTask.java
+50
-42
No files found.
signal-utc-service/src/main/java/net/wanji/utc/service/control/impl/ControlCommandStrategyServiceImpl.java
View file @
af2428c0
...
...
@@ -300,6 +300,7 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
String
ip
=
IpAddressUtil
.
getIpAddress
(
request
);
signalCommandLogPO
.
setIp
(
ip
);
log
.
info
(
"服务器请求返回 信息jsonViewObject:{}"
,
jsonViewObject
);
int
commandResult
=
0
;
if
(
code
==
200
){
commandResult
=
1
;
...
...
@@ -322,7 +323,12 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
signalCommandLogPO
.
setLampTime
(
lampTime
);
}
}
signalCommandLogPOMapper
.
insert
(
signalCommandLogPO
);
int
insert
=
signalCommandLogPOMapper
.
insert
(
signalCommandLogPO
);
if
(
insert
>
0
)
{
log
.
info
(
"定时任务 插入t_signal_command_log成功,crossId = {},commandType = {},time = {},insert = {}"
,
jsonObject
.
getString
(
"crossId"
),
commandType
,
LocalDateTimeUtil
.
formatNow
(
LocalDateTimeUtil
.
TIMEFORMATTER
),
insert
);
}
else
{
log
.
info
(
"定时任务 插入t_signal_command_log失败,crossId = {},commandType = {},time = {},insert = {}"
,
jsonObject
.
getString
(
"crossId"
),
commandType
,
LocalDateTimeUtil
.
formatNow
(
LocalDateTimeUtil
.
TIMEFORMATTER
),
insert
);
}
//排除查询环图接口
if
(
commandType
!=
10
){
LambdaQueryWrapper
<
SignalCommandPO
>
lambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
...
...
@@ -332,7 +338,12 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
//插入
SignalCommandPO
signalCommandPO
=
new
SignalCommandPO
();
BeanUtil
.
copyProperties
(
signalCommandLogPO
,
signalCommandPO
);
signalCommandPOMapper
.
insert
(
signalCommandPO
);
int
insert1
=
signalCommandPOMapper
.
insert
(
signalCommandPO
);
if
(
insert1
>
0
)
{
log
.
info
(
"定时任务 插入t_signal_command成功,crossId = {},commandType = {},time = {},insert = {}"
,
jsonObject
.
getString
(
"crossId"
),
commandType
,
LocalDateTimeUtil
.
formatNow
(
LocalDateTimeUtil
.
TIMEFORMATTER
),
insert1
);
}
else
{
log
.
info
(
"定时任务 插入t_signal_command失败,crossId = {},commandType = {},time = {},insert = {}"
,
jsonObject
.
getString
(
"crossId"
),
commandType
,
LocalDateTimeUtil
.
formatNow
(
LocalDateTimeUtil
.
TIMEFORMATTER
),
insert1
);
}
}
else
{
//更新
SignalCommandPO
signalCommandPO
=
signalCommandPOS
.
get
(
0
);
...
...
@@ -343,7 +354,12 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
signalCommandPO
.
setIp
(
ip
);
signalCommandPO
.
setQueryTime
(
queryTime
);
signalCommandPO
.
setUpdateCount
(
0
);
signalCommandPOMapper
.
update
(
signalCommandPO
,
lambdaQueryWrapper
);
int
update
=
signalCommandPOMapper
.
update
(
signalCommandPO
,
lambdaQueryWrapper
);
if
(
update
>
0
)
{
log
.
info
(
"定时任务 更新t_signal_command成功,crossId = {},commandType = {},time = {},update = {}"
,
jsonObject
.
getString
(
"crossId"
),
commandType
,
LocalDateTimeUtil
.
formatNow
(
LocalDateTimeUtil
.
TIMEFORMATTER
),
update
);
}
else
{
log
.
info
(
"定时任务 更新t_signal_command失败,crossId = {},commandType = {},time = {},update = {}"
,
jsonObject
.
getString
(
"crossId"
),
commandType
,
LocalDateTimeUtil
.
formatNow
(
LocalDateTimeUtil
.
TIMEFORMATTER
),
update
);
}
}
}
}
...
...
@@ -367,12 +383,16 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
if
(
StringUtils
.
isBlank
(
crossId
))
{
return
jsonViewObject
.
fail
(
"路口编号不能为空"
);
}
try
{
String
manufacturerIdCode
=
crossInfoCache
.
getManufacturerCodeByCrossId
(
crossId
);
if
(
StringUtils
.
equals
(
BasicEnum
.
ManufacturerEnum
.
HK
.
getCode
(),
manufacturerIdCode
))
{
jsonViewObject
=
hkControlCommandService
.
recoverSchedule
(
crossId
);
}
else
{
jsonViewObject
=
wanJiControlCommandService
.
recoverSchedule
(
crossId
);
}
}
catch
(
Exception
e
)
{
jsonViewObject
=
JsonViewObject
.
newInstance
().
fail
(
e
.
getMessage
());
}
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"crossId"
,
crossId
);
//插入命令操作日志
...
...
signal-utc-service/src/main/java/net/wanji/utc/task/CommandFaildTask.java
View file @
af2428c0
...
...
@@ -19,8 +19,6 @@ import net.wanji.utc.common.typeenum.BasicEnum;
import
net.wanji.utc.service.control.ControlCommandService
;
import
net.wanji.utc.service.control.ControlCommandStrategyService
;
import
net.wanji.utc.util.StringUtils
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
...
...
@@ -36,7 +34,6 @@ import java.util.concurrent.ConcurrentHashMap;
*/
@Component
@Slf4j
@EnableAsync
@SuppressWarnings
(
"all"
)
public
class
CommandFaildTask
{
@Resource
...
...
@@ -54,26 +51,25 @@ public class CommandFaildTask {
private
SignalCommandLogPOMapper
signalCommandLogPOMapper
;
@Scheduled
(
cron
=
"0/5 * * * * ?"
)
@Async
public
void
commandFaildTask
()
throws
Exception
{
LambdaQueryWrapper
<
SignalCommandPO
>
lambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
lambdaQueryWrapper
.
eq
(
SignalCommandPO:
:
getCommandResult
,
2
);
List
<
SignalCommandPO
>
crossInfoPOList
=
signalCommandPOMapper
.
selectList
(
lambdaQueryWrapper
);
log
.
info
(
"定时任务恢复控制指令,需要执行恢复路口集合crossInfoPOList = {}"
,
crossInfoPOList
);
if
(
ObjectUtil
.
isNotEmpty
(
crossInfoPOList
))
{
for
(
SignalCommandPO
signalCommandPO
:
crossInfoPOList
)
{
String
crossId
=
signalCommandPO
.
getCrossId
();
Integer
commandType
=
signalCommandPO
.
getCommandType
();
Integer
updateCount
=
signalCommandPO
.
getUpdateCount
();
if
(
ObjectUtil
.
isNull
(
updateCount
)){
if
(
ObjectUtil
.
isNull
(
updateCount
))
{
updateCount
=
0
;
}
try
{
log
.
info
(
"定时任务自动恢复开始执行(不保证恢复成功),crossId={},commandType={},updateCount={}"
,
crossId
,
commandType
,
updateCount
);
//处理数据
handlerCommand
(
crossId
,
commandType
,
updateCount
);
log
.
info
(
"定时任务自动恢复执行成功(不保证恢复成功),crossId={},commandType={},updateCount={}"
,
crossId
,
commandType
,
updateCount
);
handlerCommand
(
crossId
,
commandType
,
updateCount
);
}
catch
(
Exception
e
)
{
log
.
error
(
"定时任务自动恢复报错,crossId={},commandType={},updateCount={}"
,
crossId
,
commandType
,
updateCount
);
throw
new
RuntimeException
(
e
);
log
.
error
(
"定时任务自动恢复报错,crossId={},commandType={},updateCount={}"
,
crossId
,
commandType
,
updateCount
);
}
}
}
...
...
@@ -85,24 +81,24 @@ public class CommandFaildTask {
* @Param crossId 路口编号
* @Param commandType 控制模式
**/
private
void
handlerCommand
(
String
crossId
,
Integer
commandType
,
int
updateCount
)
{
private
void
handlerCommand
(
String
crossId
,
Integer
commandType
,
int
updateCount
)
{
switch
(
commandType
)
{
//1-步进控制/恢复(公用);2-恢复时间表(公用);3-相位锁定/解锁(公用);4-临时方案下发(公用);5-下发命令失败,程序下发恢复指令;10-查询环图失败记录',
case
1
:
//恢复步进
recoverStepControlStrategy
(
crossId
,
updateCount
,
commandType
);
recoverStepControlStrategy
(
crossId
,
updateCount
,
commandType
);
break
;
case
2
:
//恢复时间表
recoverScheduleStrategy
(
crossId
,
updateCount
,
commandType
);
recoverScheduleStrategy
(
crossId
,
updateCount
,
commandType
);
break
;
case
3
:
//相位解锁
recoverLockControlStrategy
(
crossId
,
updateCount
,
commandType
);
recoverLockControlStrategy
(
crossId
,
updateCount
,
commandType
);
break
;
case
4
:
//恢复 临时方案下发
recoverScheduleStrategy
(
crossId
,
updateCount
,
commandType
);
recoverScheduleStrategy
(
crossId
,
updateCount
,
commandType
);
break
;
default
:
log
.
error
(
"commandType有误,crossId={},commandType={}"
,
crossId
,
commandType
);
...
...
@@ -116,9 +112,13 @@ public class CommandFaildTask {
* @Description 恢复步进
* @Param crossId
**/
private
void
recoverStepControlStrategy
(
String
crossId
,
int
updateCount
,
int
commandType
)
{
private
void
recoverStepControlStrategy
(
String
crossId
,
int
updateCount
,
int
commandType
)
{
String
now
=
LocalDateTimeUtil
.
formatNow
(
LocalDateTimeUtil
.
TIMEFORMATTER
);
JsonViewObject
jsonViewObject
;
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"crossId"
,
crossId
);
jsonObject
.
put
(
"command"
,
0
);
jsonObject
.
put
(
"stepNum"
,
0
);
try
{
String
manufacturerIdCode
=
crossInfoCache
.
getManufacturerCodeByCrossId
(
crossId
);
if
(
StringUtils
.
equals
(
BasicEnum
.
ManufacturerEnum
.
HK
.
getCode
(),
manufacturerIdCode
))
{
...
...
@@ -127,14 +127,11 @@ public class CommandFaildTask {
jsonViewObject
=
wanJiControlCommandService
.
stepControl
(
crossId
,
0
,
0
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"定时任务 恢复步进出错,crossId={}"
,
crossId
);
jsonViewObject
=
JsonViewObject
.
newInstance
().
fail
(
e
.
getMessage
());
}
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"crossId"
,
crossId
);
jsonObject
.
put
(
"command"
,
0
);
jsonObject
.
put
(
"stepNum"
,
0
);
//插入命令操作日志
insertCommandLog
(
now
,
jsonViewObject
,
jsonObject
,
commandType
,
updateCount
);
insertCommandLog
(
now
,
jsonViewObject
,
jsonObject
,
commandType
,
updateCount
);
}
/**
...
...
@@ -143,24 +140,24 @@ public class CommandFaildTask {
* @Param crossId
**/
private
void
recoverScheduleStrategy
(
String
crossId
,
int
updateCount
,
int
commandType
)
{
try
{
private
void
recoverScheduleStrategy
(
String
crossId
,
int
updateCount
,
int
commandType
)
{
String
now
=
LocalDateTimeUtil
.
formatNow
(
LocalDateTimeUtil
.
TIMEFORMATTER
);
JsonViewObject
jsonViewObject
=
JsonViewObject
.
newInstance
();
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"crossId"
,
crossId
);
try
{
String
manufacturerIdCode
=
crossInfoCache
.
getManufacturerCodeByCrossId
(
crossId
);
if
(
StringUtils
.
equals
(
BasicEnum
.
ManufacturerEnum
.
HK
.
getCode
(),
manufacturerIdCode
))
{
jsonViewObject
=
hkControlCommandService
.
recoverSchedule
(
crossId
);
}
else
{
jsonViewObject
=
wanJiControlCommandService
.
recoverSchedule
(
crossId
);
}
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"crossId"
,
crossId
);
//插入命令操作日志
insertCommandLog
(
now
,
jsonViewObject
,
jsonObject
,
commandType
,
updateCount
);
}
catch
(
Exception
e
)
{
log
.
error
(
"定时任务 恢复时间表出错,crossId={}"
,
crossId
);
throw
new
RuntimeException
(
e
);
log
.
error
(
"定时任务 恢复时间表出错,crossId={}"
,
crossId
);
jsonViewObject
=
JsonViewObject
.
newInstance
().
fail
(
e
.
getMessage
()
);
}
//插入命令操作日志
insertCommandLog
(
now
,
jsonViewObject
,
jsonObject
,
commandType
,
updateCount
);
}
/**
...
...
@@ -169,13 +166,15 @@ public class CommandFaildTask {
* @Param crossId
**/
private
void
recoverLockControlStrategy
(
String
crossId
,
int
updateCount
,
int
commandType
)
{
private
void
recoverLockControlStrategy
(
String
crossId
,
int
updateCount
,
int
commandType
)
{
String
now
=
LocalDateTimeUtil
.
formatNow
(
LocalDateTimeUtil
.
TIMEFORMATTER
);
JsonViewObject
jsonViewObject
;
ControlCommandVO
commandVO
=
new
ControlCommandVO
();
commandVO
.
setCrossCode
(
crossId
);
commandVO
.
setCommand
(
0
);
commandVO
.
setDuration
(
0
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
commandVO
));
jsonObject
.
put
(
"crossId"
,
commandVO
.
getCrossCode
());
try
{
String
manufacturerIdCode
=
crossInfoCache
.
getManufacturerCodeByCrossId
(
commandVO
.
getCrossCode
());
if
(
StringUtils
.
equals
(
BasicEnum
.
ManufacturerEnum
.
HK
.
getCode
(),
manufacturerIdCode
))
{
...
...
@@ -185,11 +184,10 @@ public class CommandFaildTask {
}
}
catch
(
Exception
e
)
{
jsonViewObject
=
JsonViewObject
.
newInstance
().
fail
(
e
.
getMessage
());
log
.
error
(
"定时任务 恢复临时方案下发出错,crossId={}"
,
crossId
);
}
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
commandVO
));
jsonObject
.
put
(
"crossId"
,
commandVO
.
getCrossCode
());
//插入命令操作日志
insertCommandLog
(
now
,
jsonViewObject
,
jsonObject
,
commandType
,
updateCount
);
insertCommandLog
(
now
,
jsonViewObject
,
jsonObject
,
commandType
,
updateCount
);
}
/**
...
...
@@ -199,8 +197,8 @@ public class CommandFaildTask {
* @Param jsonViewObject 操作结果
* @Param jsonObject 参数
**/
public
void
insertCommandLog
(
String
queryTime
,
JsonViewObject
jsonViewObject
,
JSONObject
jsonObject
,
int
commandType
,
int
updateCount
)
{
updateCount
=
updateCount
+
1
;
public
void
insertCommandLog
(
String
queryTime
,
JsonViewObject
jsonViewObject
,
JSONObject
jsonObject
,
int
commandType
,
int
updateCount
)
{
updateCount
=
updateCount
+
1
;
SignalCommandLogPO
signalCommandLogPO
=
new
SignalCommandLogPO
();
signalCommandLogPO
.
setCrossId
(
jsonObject
.
getString
(
"crossId"
));
signalCommandLogPO
.
setDataInfo
(
jsonObject
.
toJSONString
());
...
...
@@ -210,20 +208,20 @@ public class CommandFaildTask {
Integer
code
=
jsonViewObject
.
getCode
();
String
ip
=
"localhost"
;
signalCommandLogPO
.
setIp
(
ip
);
log
.
info
(
"定时任务返回 信息jsonViewObject:{}"
,
jsonViewObject
);
if
(
code
==
200
)
{
signalCommandLogPO
.
setCommandResult
(
1
);
signalCommandLogPO
.
setUpdateCount
(
0
);
}
else
{
if
(
updateCount
>=
24
){
if
(
updateCount
>=
24
)
{
//如果两分钟更新失败,则将状态设置为3
signalCommandLogPO
.
setCommandResult
(
3
);
}
else
{
signalCommandLogPO
.
setUpdateCount
(
0
);
}
else
{
signalCommandLogPO
.
setCommandResult
(
2
);
}
}
signalCommandLogPO
.
setResultMessage
(
jsonViewObject
.
getMessage
());
ConcurrentHashMap
<
String
,
List
<
LightsStatusVO2
>>
produceListMap
=
SignalStatusTask
.
produceListMap
;
if
(!
produceListMap
.
isEmpty
())
{
List
<
LightsStatusVO2
>
list
=
produceListMap
.
get
(
jsonObject
.
get
(
"crossId"
));
...
...
@@ -238,14 +236,24 @@ public class CommandFaildTask {
}
}
//插入日志表
signalCommandLogPOMapper
.
insert
(
signalCommandLogPO
);
int
insert
=
signalCommandLogPOMapper
.
insert
(
signalCommandLogPO
);
if
(
insert
>
0
)
{
log
.
info
(
"定时任务 插入t_signal_command_log成功,crossId = {},commandType = {},time = {},insert = {}"
,
jsonObject
.
getString
(
"crossId"
),
commandType
,
LocalDateTimeUtil
.
formatNow
(
LocalDateTimeUtil
.
TIMEFORMATTER
),
insert
);
}
else
{
log
.
info
(
"定时任务 插入t_signal_command_log失败,crossId = {},commandType = {},time = {},insert = {}"
,
jsonObject
.
getString
(
"crossId"
),
commandType
,
LocalDateTimeUtil
.
formatNow
(
LocalDateTimeUtil
.
TIMEFORMATTER
),
insert
);
}
SignalCommandPO
signalCommandPO
=
new
SignalCommandPO
();
BeanUtil
.
copyProperties
(
signalCommandLogPO
,
signalCommandPO
);
signalCommandPO
.
setCommandType
(
commandType
);
//更新状态表
LambdaQueryWrapper
<
SignalCommandPO
>
lambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
lambdaQueryWrapper
.
eq
(
SignalCommandPO:
:
getCrossId
,
jsonObject
.
getString
(
"crossId"
));
signalCommandPOMapper
.
update
(
signalCommandPO
,
lambdaQueryWrapper
);
lambdaQueryWrapper
.
eq
(
SignalCommandPO:
:
getCrossId
,
jsonObject
.
getString
(
"crossId"
));
int
update
=
signalCommandPOMapper
.
update
(
signalCommandPO
,
lambdaQueryWrapper
);
if
(
update
>
0
)
{
log
.
info
(
"定时任务 更新t_signal_command成功,crossId = {},commandType = {},time = {},update = {}"
,
jsonObject
.
getString
(
"crossId"
),
commandType
,
LocalDateTimeUtil
.
formatNow
(
LocalDateTimeUtil
.
TIMEFORMATTER
),
update
);
}
else
{
log
.
info
(
"定时任务 更新t_signal_command失败,crossId = {},commandType = {},time = {},update = {}"
,
jsonObject
.
getString
(
"crossId"
),
commandType
,
LocalDateTimeUtil
.
formatNow
(
LocalDateTimeUtil
.
TIMEFORMATTER
),
update
);
}
}
}
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