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
06f3f7be
Commit
06f3f7be
authored
Nov 21, 2022
by
wuxiaokai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
控制指令接口-黄闪控制,关灯控制,步进控制
parent
95eb7b4a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
152 additions
and
23 deletions
+152
-23
Constants.java
...rc/main/java/net/wanji/utc/common/constant/Constants.java
+6
-6
ControlException.java
...java/net/wanji/utc/common/exception/ControlException.java
+0
-1
ControlCommandController.java
...va/net/wanji/utc/controller/ControlCommandController.java
+81
-10
CrossPhaseMapper.java
.../src/main/java/net/wanji/utc/mapper/CrossPhaseMapper.java
+4
-0
HKControlCommandServiceImpl.java
...t/wanji/utc/service/impl/HKControlCommandServiceImpl.java
+51
-6
CrossPhaseMapper.xml
...tc-service/src/main/resources/mapper/CrossPhaseMapper.xml
+10
-0
No files found.
signal-utc-service/src/main/java/net/wanji/utc/common/constant/Constants.java
View file @
06f3f7be
...
...
@@ -64,19 +64,19 @@ public class Constants {
/**
* 恢复正常方案: 0-多时段控制模式
*/
public
static
final
Integer
NORMAL_RUNNING_
MODE
=
0
;
public
static
final
Integer
NORMAL_RUNNING_
CONTROL
=
0
;
/**
* 关灯
*/
public
static
final
Integer
OFF_LIGHT_MODE
=
1
;
public
static
final
Integer
CLOSE_LIGHT_CONTROL
=
1
;
/**
* 黄闪
*/
public
static
final
Integer
YELLOW_
RUNNING_MODE
=
2
;
public
static
final
Integer
YELLOW_
LIGHT_CONTROL
=
2
;
/**
* 手动全红
*/
public
static
final
Integer
RED_RUNNING_MODE
=
3
;
public
static
final
Integer
ALL_RED_CONTROL
=
3
;
/**
* 定周期控制
*/
...
...
@@ -84,11 +84,11 @@ public class Constants {
/**
* 步进控制
*/
public
static
final
Integer
STEP_
UPDATE_MODE
=
10
;
public
static
final
Integer
STEP_
CONTROL
=
10
;
/**
* 取消步进
*/
public
static
final
Integer
CANCEL_STEP_
MODE
=
11
;
public
static
final
Integer
CANCEL_STEP_
CONTROL
=
11
;
public
static
ApiInfoPO
getManufacturerUrlMap
(
String
key
)
{
return
manufacturerUrlMap
.
get
(
key
);
...
...
signal-utc-service/src/main/java/net/wanji/utc/common/exception/ControlException.java
View file @
06f3f7be
package
net
.
wanji
.
utc
.
common
.
exception
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
net.wanji.utc.common.BaseInfoInterface
;
...
...
signal-utc-service/src/main/java/net/wanji/utc/controller/ControlCommandController.java
View file @
06f3f7be
...
...
@@ -6,13 +6,14 @@ import net.wanji.utc.common.typeenum.BasicEnum;
import
net.wanji.utc.mapper.CrossInfoMapper
;
import
net.wanji.utc.po.CrossInfoPO
;
import
net.wanji.utc.service.ControlCommandService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
static
net
.
wanji
.
utc
.
common
.
ResultEnum
.
BODY_NOT_MATCH
;
/**
...
...
@@ -28,26 +29,96 @@ public class ControlCommandController {
@Value
(
"${signal.mock}"
)
private
boolean
mock
;
@
Autowired
@
Resource
private
CrossInfoMapper
crossInfoMapper
;
@
Autowired
@
Resource
private
ControlCommandService
hkControlCommandService
;
/**
* 全红控制
*
* @param signalId 信号机id
* @param command 指令
* @return {@link Result}<{@link T}>
*/
@PostMapping
(
"/allRedControl"
)
public
<
T
>
Result
<
T
>
allRedControl
(
@RequestParam
String
signalId
,
@RequestParam
Integer
command
)
{
if
(
mock
)
return
Result
.
success
();
CrossInfoPO
crossInfoPO
=
crossInfoMapper
.
selectByCode
(
signalId
);
if
(
crossInfoPO
==
null
)
{
throw
new
ControlException
(
BODY_NOT_MATCH
.
getResultCode
(),
"参数错误,信号机ID不正确。"
);
Integer
manufacturerId
=
check
(
signalId
);
if
(
manufacturerId
.
equals
(
BasicEnum
.
ManufacturerEnum
.
HK
.
getCode
()))
{
return
hkControlCommandService
.
allRedControl
(
signalId
,
null
,
null
,
command
);
}
else
{
// todo else
return
null
;
}
}
/**
* 黄闪控制
*
* @param signalId 信号id
* @param command 命令
* @return {@link Result}<{@link T}>
*/
@PostMapping
(
"/yellowLightControl"
)
public
<
T
>
Result
<
T
>
yellowLightControl
(
@RequestParam
String
signalId
,
@RequestParam
Integer
command
)
{
if
(
mock
)
return
Result
.
success
();
Integer
manufacturerId
=
check
(
signalId
);
if
(
manufacturerId
.
equals
(
BasicEnum
.
ManufacturerEnum
.
HK
.
getCode
()))
{
return
hkControlCommandService
.
yellowLightControl
(
signalId
,
null
,
null
,
command
);
}
else
{
// todo else
return
null
;
}
}
/**
* 关灯控制
*
* @param signalId 信号id
* @param command 命令
* @return {@link Result}<{@link T}>
*/
@PostMapping
(
"/closeLightControl"
)
public
<
T
>
Result
<
T
>
closeLightControl
(
@RequestParam
String
signalId
,
@RequestParam
Integer
command
)
{
if
(
mock
)
return
Result
.
success
();
Integer
manufacturerId
=
check
(
signalId
);
if
(
manufacturerId
.
equals
(
BasicEnum
.
ManufacturerEnum
.
HK
.
getCode
()))
{
return
hkControlCommandService
.
closeLightControl
(
signalId
,
null
,
null
,
command
);
}
else
{
// todo else
return
null
;
}
Integer
manufacturerId
=
crossInfoPO
.
getManufacturerId
();
Result
<
T
>
result
=
new
Result
<>();
}
/**
* 步进控制
*
* @param signalId 信号id
* @param command 命令
* @param stepNum 一步num
* @return {@link Result}<{@link T}>
*/
@PostMapping
(
"/stepControl"
)
public
<
T
>
Result
<
T
>
stepControl
(
@RequestParam
String
signalId
,
@RequestParam
Integer
command
,
@RequestParam
int
stepNum
)
{
if
(
mock
)
return
Result
.
success
();
Integer
manufacturerId
=
check
(
signalId
);
if
(
manufacturerId
.
equals
(
BasicEnum
.
ManufacturerEnum
.
HK
.
getCode
()))
{
re
sult
=
hkControlCommandService
.
allRedControl
(
signalId
,
null
,
null
,
command
);
re
turn
hkControlCommandService
.
stepControl
(
signalId
,
null
,
null
,
command
,
stepNum
);
}
else
{
// todo else
return
null
;
}
}
private
Integer
check
(
String
signalId
)
{
CrossInfoPO
crossInfoPO
=
crossInfoMapper
.
selectByCode
(
signalId
);
if
(
crossInfoPO
==
null
)
{
throw
new
ControlException
(
BODY_NOT_MATCH
.
getResultCode
(),
"参数错误,信号机ID不正确。"
);
}
return
result
;
return
crossInfoPO
.
getManufacturerId
()
;
}
}
signal-utc-service/src/main/java/net/wanji/utc/mapper/CrossPhaseMapper.java
View file @
06f3f7be
...
...
@@ -3,6 +3,8 @@ package net.wanji.utc.mapper;
import
net.wanji.utc.po.CrossPhasePO
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
/**
* @author Kent HAN
* @date 2022/11/18 10:44
...
...
@@ -11,4 +13,6 @@ public interface CrossPhaseMapper {
void
deleteOne
(
@Param
(
"crossId"
)
String
crossId
,
@Param
(
"phaseNo"
)
String
phaseNo
);
void
insertOne
(
CrossPhasePO
crossPhasePO
);
List
<
CrossPhasePO
>
selectByCrossIdAndPlanId
(
@Param
(
"crossId"
)
String
crossId
,
@Param
(
"planId"
)
String
planId
);
}
signal-utc-service/src/main/java/net/wanji/utc/service/impl/HKControlCommandServiceImpl.java
View file @
06f3f7be
...
...
@@ -10,16 +10,21 @@ import net.wanji.utc.common.baseentity.BaseCrossInfo;
import
net.wanji.utc.common.constant.Constants
;
import
net.wanji.utc.common.exception.ControlException
;
import
net.wanji.utc.common.typeenum.BasicEnum
;
import
net.wanji.utc.entity.TCrossPhase
;
import
net.wanji.utc.mapper.CrossPhaseMapper
;
import
net.wanji.utc.po.CrossPhasePO
;
import
net.wanji.utc.service.ControlCommandService
;
import
net.wanji.utc.service.HkGetSignalMethodService
;
import
net.wanji.utc.vo.PhaseLock
;
import
net.wanji.utc.vo.signal.SignalLightStateVo
;
import
net.wanji.utc.vo.signal.SignalRingVo
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
static
net
.
wanji
.
utc
.
common
.
constant
.
Constants
.*;
...
...
@@ -37,6 +42,9 @@ public class HKControlCommandServiceImpl implements ControlCommandService {
@Resource
private
ArtemisConfig
artemisConfig
;
@Resource
private
CrossPhaseMapper
crossPhaseMapper
;
@Override
public
<
T
>
Result
<
T
>
schemeSend
()
{
return
null
;
...
...
@@ -59,23 +67,26 @@ public class HKControlCommandServiceImpl implements ControlCommandService {
@Override
public
<
T
>
Result
<
T
>
stepControl
(
String
signalId
,
String
sourceType
,
String
signalType
,
Integer
command
,
Integer
stepNum
)
{
return
null
;
if
(
command
.
equals
(
TRUE
))
return
updateManualStep
(
signalId
,
STEP_CONTROL
,
stepNum
);
else
return
updateManual
(
signalId
,
CANCEL_STEP_CONTROL
);
}
@Override
public
<
T
>
Result
<
T
>
allRedControl
(
String
signalId
,
String
sourceType
,
String
signalType
,
Integer
command
)
{
Integer
runningMode
=
command
.
equals
(
Constants
.
TRUE
)
?
RED_RUNNING_MODE
:
NORMAL_RUNNING_MODE
;
Integer
runningMode
=
command
.
equals
(
TRUE
)
?
ALL_RED_CONTROL
:
NORMAL_RUNNING_CONTROL
;
return
updateManual
(
signalId
,
runningMode
);
}
@Override
public
<
T
>
Result
<
T
>
yellowLightControl
(
String
signalId
,
String
sourceType
,
String
signalType
,
Integer
command
)
{
return
null
;
Integer
runningMode
=
command
.
equals
(
TRUE
)
?
YELLOW_LIGHT_CONTROL
:
NORMAL_RUNNING_CONTROL
;
return
updateManual
(
signalId
,
runningMode
);
}
@Override
public
<
T
>
Result
<
T
>
closeLightControl
(
String
signalId
,
String
sourceType
,
String
signalType
,
Integer
command
)
{
return
null
;
Integer
runningMode
=
command
.
equals
(
TRUE
)
?
CLOSE_LIGHT_CONTROL
:
NORMAL_RUNNING_CONTROL
;
return
updateManual
(
signalId
,
runningMode
);
}
@Override
...
...
@@ -93,13 +104,47 @@ public class HKControlCommandServiceImpl implements ControlCommandService {
return
null
;
}
private
<
T
>
Result
<
T
>
updateManualStep
(
String
signalId
,
Integer
runningMode
,
Integer
stepNum
)
{
JSONObject
bodyObjectParam
=
new
JSONObject
();
bodyObjectParam
.
put
(
"crossCode"
,
signalId
);
bodyObjectParam
.
put
(
"controlType"
,
runningMode
);
int
controlNo
=
0
;
if
(
0
!=
stepNum
)
{
//根据当前实时灯态获取运行的相位
SignalLightStateVo
signalInfoVo
=
getSignalInfoVos
(
signalId
).
get
(
0
);
//暂时按单环处理
SignalRingVo
signalRunring
=
signalInfoVo
.
getRings
().
get
(
0
);
String
phaseId
=
signalRunring
.
getPhaseId
();
//获取方案数据列表
List
<
CrossPhasePO
>
baseCrossPhasePlanList
=
crossPhaseMapper
.
selectByCrossIdAndPlanId
(
signalInfoVo
.
getTelesemeId
(),
signalInfoVo
.
getPhasePlanId
());
Map
<
String
,
List
<
CrossPhasePO
>>
groupByPhase
=
baseCrossPhasePlanList
.
stream
().
collect
(
Collectors
.
groupingBy
(
CrossPhasePO:
:
getPhaseNo
));
//根据相位获取当前相序
int
newPhaseOrderId
=
0
;
for
(
String
key
:
groupByPhase
.
keySet
())
{
CrossPhasePO
crossPhase
=
groupByPhase
.
get
(
key
).
get
(
0
);
if
(
crossPhase
.
getPhaseNo
().
equals
(
phaseId
))
{
newPhaseOrderId
=
(
crossPhase
.
getSort
()
+
stepNum
)
%
groupByPhase
.
size
();
}
}
//根据相序获取相位
for
(
String
key
:
groupByPhase
.
keySet
())
{
CrossPhasePO
crossPhase
=
groupByPhase
.
get
(
key
).
get
(
0
);
if
(
newPhaseOrderId
==
crossPhase
.
getSort
())
{
controlNo
=
Integer
.
parseInt
(
crossPhase
.
getPhaseNo
());
}
}
}
bodyObjectParam
.
put
(
"controlNo"
,
controlNo
);
return
setSignalControl
(
bodyObjectParam
);
}
/**
* @param signalId 信号机编号
* @param signalId
信号机编号
* @param runningMode 0-多时段控制模式 1-关灯、2-黄闪、3-全红、11-取消步进控制、12-灯态锁定、13-灯态解锁
*/
private
<
T
>
Result
<
T
>
updateManual
(
String
signalId
,
Integer
runningMode
)
{
//执行恢复时间表方案命令
if
(
NORMAL_RUNNING_
MODE
.
equals
(
runningMode
)
||
CANCEL_STEP_MODE
.
equals
(
runningMode
))
{
if
(
NORMAL_RUNNING_
CONTROL
.
equals
(
runningMode
)
||
CANCEL_STEP_CONTROL
.
equals
(
runningMode
))
{
//根据实时灯态获取当前运行模式
SignalLightStateVo
signalInfoVo
=
getSignalInfoVos
(
signalId
).
get
(
0
);
//如果当前模式已经是定周期,就不在执行恢复时间表方案指令
...
...
signal-utc-service/src/main/resources/mapper/CrossPhaseMapper.xml
View file @
06f3f7be
...
...
@@ -32,5 +32,15 @@
where cross_id = #{crossId} and phase_no = #{phaseNo}
</delete>
<sql
id=
"baseColumn"
>
id,phase_no,name,sort,cross_id,plan_id,ring_no,control_mode,phase_time,green_time,
green_flash_time,ped_flash_time,yellow_time,red_time,min_green_time,max_green_time
</sql>
<select
id=
"selectByCrossIdAndPlanId"
resultMap=
"BaseResultMap"
>
select
<include
refid=
"baseColumn"
/>
from t_cross_phase where cross_id = #{crossId} and planId = #{planId}
</select>
</mapper>
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