Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YeeAmosFireAutoSysRoot
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
station
YeeAmosFireAutoSysRoot
Commits
9926ec57
Commit
9926ec57
authored
May 28, 2022
by
maoying
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev_upgrade_plan6' of…
Merge branch 'dev_upgrade_plan6' of
http://39.98.45.134:8090/station/YeeAmosFireAutoSysRoot
into dev_upgrade_plan6
parents
c23e993b
ba7d1663
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
480 additions
and
468 deletions
+480
-468
ContingencyAction.java
...m/yeejoin/amos/fas/business/action/ContingencyAction.java
+26
-2
EquipmentFireEquipmentController.java
...business/controller/EquipmentFireEquipmentController.java
+1
-1
TimeLineController.java
...join/amos/fas/business/controller/TimeLineController.java
+59
-149
ContingencyInstanceImpl.java
...os/fas/business/service/impl/ContingencyInstanceImpl.java
+392
-316
IContingencyInstance.java
...amos/fas/business/service/intfc/IContingencyInstance.java
+2
-0
No files found.
YeeAmosFireAutoSysService/src/main/java/com/yeejoin/amos/fas/business/action/ContingencyAction.java
View file @
9926ec57
...
...
@@ -103,6 +103,9 @@ public class ContingencyAction implements CustomerAction {
@Autowired
IRocketMQService
rocketMQService
;
@Autowired
private
IContingencyInstance
contingencyInstance
;
@Value
(
"${rocket-plan-topic}"
)
private
String
rocketTopic
;
...
...
@@ -510,7 +513,6 @@ public class ContingencyAction implements CustomerAction {
result
.
add
(
tempmap1
);
this
.
sendcmd
(
"optionarea"
,
paramObj
,
result
);
}
...
...
@@ -703,7 +705,6 @@ public class ContingencyAction implements CustomerAction {
result
.
add
(
tempmap1
);
this
.
sendcmd
(
"message"
,
paramObj
,
result
);
redisTemplate
.
opsForValue
().
set
(
"contingencyRo"
,
contingencyRo
);
}
...
...
@@ -851,6 +852,7 @@ public class ContingencyAction implements CustomerAction {
@RuleMethod
(
methodLabel
=
"自动执行动作"
,
project
=
"换流站消防专项预案"
)
public
void
autoExecuteAction
(
@MethodParam
(
paramLabel
=
"当前步骤"
)
String
currentSetup
,
@MethodParam
(
paramLabel
=
"按钮状态"
)
String
buttonStatus
,
@MethodParam
(
paramLabel
=
"按钮编码"
)
String
buttonCode
,
@MethodParam
(
paramLabel
=
"规则主题"
)
String
topic
,
...
...
@@ -858,6 +860,8 @@ public class ContingencyAction implements CustomerAction {
ContingencyRo
contingencyRo
=
(
ContingencyRo
)
paramObj
;
contingencyRo
.
setButtonState
(
buttonStatus
);
contingencyRo
.
setButtonCode
(
buttonCode
);
contingencyRo
.
setStepState
(
topic
);
contingencyRo
.
setStep
(
currentSetup
);
try
{
//电力设备
Equipment
equipment
=
equipmentService
.
queryOne
(
Long
.
parseLong
(
contingencyRo
.
getEquipmentId
()));
...
...
@@ -867,6 +871,26 @@ public class ContingencyAction implements CustomerAction {
}
}
@RuleMethod
(
methodLabel
=
"自动执行动作V2"
,
project
=
"换流站消防专项预案"
)
public
void
autoExecuteActionV2
(
@MethodParam
(
paramLabel
=
"步骤编码"
)
String
stepCode
,
@MethodParam
(
paramLabel
=
"按钮编码"
)
String
buttonCode
,
@MethodParam
(
paramLabel
=
"按钮状态"
)
String
confirm
,
@MethodParam
(
paramLabel
=
"步骤状态"
)
String
stepState
,
@MethodParam
(
paramLabel
=
"动作名称"
)
String
actionName
,
@MethodParam
(
paramLabel
=
"图标"
)
String
icon
,
@MethodParam
(
paramLabel
=
"提示信息"
)
String
tips
,
@MethodParam
(
paramLabel
=
"按钮json字符串"
)
String
buttonJson
,
@MethodParam
(
paramLabel
=
"预案对象"
)
Object
paramObj
)
{
ContingencyRo
contingencyRo
=
(
ContingencyRo
)
paramObj
;
String
contingencyPlanId
=
getContingencyPlanId
(
contingencyRo
.
getBatchNo
(),
actionName
,
icon
,
tips
,
buttonJson
);
try
{
contingencyInstance
.
fire
(
contingencyRo
.
getBatchNo
(),
stepCode
,
contingencyPlanId
,
buttonCode
,
confirm
,
stepState
,
null
,
null
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
void
sendcmd
(
String
msgType
,
DeviceRo
deviceRo
,
SafteyPlanResult
result
)
{
Constructor
<?>
constructor
;
try
{
...
...
YeeAmosFireAutoSysService/src/main/java/com/yeejoin/amos/fas/business/controller/
e
quipmentFireEquipmentController.java
→
YeeAmosFireAutoSysService/src/main/java/com/yeejoin/amos/fas/business/controller/
E
quipmentFireEquipmentController.java
View file @
9926ec57
...
...
@@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping
(
value
=
"/api/equipFireEquip"
)
public
class
e
quipmentFireEquipmentController
{
public
class
E
quipmentFireEquipmentController
{
@Autowired
private
IEquipmentFireEquipmentService
equipmentFireEquipmentService
;
...
...
YeeAmosFireAutoSysService/src/main/java/com/yeejoin/amos/fas/business/controller/TimeLineController.java
View file @
9926ec57
package
com
.
yeejoin
.
amos
.
fas
.
business
.
controller
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.typroject.tyboot.core.foundation.context.RequestContext
;
import
com.yeejoin.amos.fas.business.action.CustomerAction
;
import
com.yeejoin.amos.fas.business.bo.FirePlanAlarmBo
;
import
com.yeejoin.amos.fas.business.dao.mapper.View3dMapper
;
import
com.yeejoin.amos.fas.business.service.impl.RiskSourceServiceImpl
;
import
com.yeejoin.amos.fas.business.service.intfc.IContingencyInstance
;
import
com.yeejoin.amos.fas.business.service.intfc.IContingencyOriginalDataService
;
import
com.yeejoin.amos.fas.business.service.intfc.IEquipmentService
;
import
com.yeejoin.amos.fas.business.service.intfc.IRocketMQService
;
import
com.yeejoin.amos.fas.business.service.intfc.IRuleRunningSnapshotService
;
import
com.yeejoin.amos.fas.config.Permission
;
import
com.yeejoin.amos.fas.core.common.request.CommonPageable
;
...
...
@@ -41,22 +15,33 @@ import com.yeejoin.amos.fas.core.util.CommonResponse;
import
com.yeejoin.amos.fas.core.util.CommonResponseUtil
;
import
com.yeejoin.amos.fas.core.util.DateUtil
;
import
com.yeejoin.amos.fas.dao.entity.Equipment
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
@RestController
@RequestMapping
(
value
=
"/api/timeline"
)
@Api
(
tags
=
"时间轴"
)
public
class
TimeLineController
extends
BaseController
{
@Api
(
tags
=
"时间轴"
)
public
class
TimeLineController
extends
BaseController
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
TimeLineController
.
class
);
@Autowired
IContingencyInstance
iContingencyInstance
;
@Qualifier
(
"contingencyAction"
)
@Autowired
private
CustomerAction
customerAction
;
private
CustomerAction
customerAction
;
@Autowired
IContingencyOriginalDataService
iContingencyOriginalDataService
;
...
...
@@ -66,78 +51,46 @@ public class TimeLineController extends BaseController{
@Autowired
IEquipmentService
equipmentService
;
static
LinkedList
<
Map
<
String
,
String
>>
fireQueue
=
new
LinkedList
<>();
@Autowired
private
RedisTemplate
redisTemplate
;
@Autowired
private
IRuleRunningSnapshotService
ruleRunningSnapshotService
;
@Autowired
IRocketMQService
rocketMQService
;
@Value
(
"${rocket-equip-alarm-topic}"
)
private
String
rocketTopicFireEquipAlarm
;
@Autowired
private
View3dMapper
view3dMapper
;
private
RedisTemplate
redisTemplate
;
@Autowired
private
IRuleRunningSnapshotService
ruleRunningSnapshotService
;
@Permission
//@Authorization(ingore = true)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"根据批次号查询时间轴"
,
notes
=
"根据批次号查询时间轴"
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"根据批次号查询时间轴"
,
notes
=
"根据批次号查询时间轴"
)
@RequestMapping
(
value
=
"/{instanceNo}"
,
produces
=
"application/json;charset=UTF-8"
,
method
=
RequestMethod
.
GET
)
public
CommonResponse
queryPoint
(
@PathVariable
String
instanceNo
,
@RequestParam
(
"recordType"
)
String
recordType
)
throws
Exception
{
public
CommonResponse
queryPoint
(
@PathVariable
String
instanceNo
,
@RequestParam
(
"recordType"
)
String
recordType
)
throws
Exception
{
return
CommonResponseUtil
.
success
(
iContingencyInstance
.
queryForTimeLine
(
instanceNo
,
recordType
));
return
CommonResponseUtil
.
success
(
iContingencyInstance
.
queryForTimeLine
(
instanceNo
,
recordType
));
}
@Permission
//@Authorization(ingore = true)
@ApiOperation
(
httpMethod
=
"PUT"
,
value
=
"点击按钮"
,
notes
=
"点击按钮"
)
@ApiOperation
(
httpMethod
=
"PUT"
,
value
=
"点击按钮"
,
notes
=
"点击按钮"
)
@RequestMapping
(
value
=
"/fire"
,
produces
=
"application/json;charset=UTF-8"
,
method
=
RequestMethod
.
PUT
)
public
CommonResponse
fire
(
@RequestParam
(
"batchNo"
)
String
batchNo
,
@RequestParam
(
"stepCode"
)
String
stepCode
,
@RequestParam
(
"buttonCode"
)
String
buttonCode
,
@RequestParam
(
"confirm"
)
String
confirm
,
@RequestParam
(
"contingencyPlanId"
)
String
contingencyPlanId
,
@RequestParam
(
"stepState"
)
String
stepState
)
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"batchNo"
,
batchNo
);
map
.
put
(
"stepCode"
,
stepCode
);
map
.
put
(
"buttonCode"
,
buttonCode
);
map
.
put
(
"confirm"
,
confirm
);
map
.
put
(
"contingencyPlanId"
,
contingencyPlanId
);
map
.
put
(
"stepState"
,
stepState
);
map
.
put
(
"token"
,
getToken
());
map
.
put
(
"product"
,
getProduct
());
fireQueue
.
addLast
(
map
);
//应急指挥给总部推送消息
sendPlanAlarm
(
batchNo
,
buttonCode
);
public
CommonResponse
fire
(
@RequestParam
(
"batchNo"
)
String
batchNo
,
@RequestParam
(
"stepCode"
)
String
stepCode
,
@RequestParam
(
"buttonCode"
)
String
buttonCode
,
@RequestParam
(
"confirm"
)
String
confirm
,
@RequestParam
(
"contingencyPlanId"
)
String
contingencyPlanId
,
@RequestParam
(
"stepState"
)
String
stepState
)
throws
Exception
{
iContingencyInstance
.
fire
(
batchNo
,
stepCode
,
contingencyPlanId
,
buttonCode
,
confirm
,
stepState
,
getToken
(),
getProduct
());
return
CommonResponseUtil
.
success
(
"SUCCESS"
);
}
private
void
sendPlanAlarm
(
String
batchNo
,
String
buttonCode
){
//确警后推送报警数据
if
(
"FIRE_CONFIRM"
.
equals
(
buttonCode
)){
FirePlanAlarmBo
firePlanAlarm
=
view3dMapper
.
getPlanAlarmInfo
(
batchNo
);
List
<
FirePlanAlarmBo
>
list
=
new
ArrayList
<
FirePlanAlarmBo
>();
list
.
add
(
firePlanAlarm
);
rocketMQService
.
sendMsg
(
rocketTopicFireEquipAlarm
,
"plan_alarm"
,
list
);
}
}
@Permission
@ApiOperation
(
httpMethod
=
"PUT"
,
value
=
"点击按钮"
,
notes
=
"点击按钮"
)
@ApiOperation
(
httpMethod
=
"PUT"
,
value
=
"点击按钮"
,
notes
=
"点击按钮"
)
@RequestMapping
(
value
=
"/fire/exit"
,
produces
=
"application/json;charset=UTF-8"
,
method
=
RequestMethod
.
PUT
)
public
CommonResponse
fireExit
(
@RequestParam
(
"batchNo"
)
String
batchNo
,
@RequestParam
(
"stepCode"
)
String
stepCode
,
@RequestParam
(
"buttonCode"
)
String
buttonCode
,
@RequestParam
(
"confirm"
)
String
confirm
,
@RequestParam
(
"stepState"
)
String
stepState
)
throws
Exception
{
public
CommonResponse
fireExit
(
@RequestParam
(
"batchNo"
)
String
batchNo
,
@RequestParam
(
"stepCode"
)
String
stepCode
,
@RequestParam
(
"buttonCode"
)
String
buttonCode
,
@RequestParam
(
"confirm"
)
String
confirm
,
@RequestParam
(
"stepState"
)
String
stepState
)
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
Map
<
String
,
String
>
map
=
new
HashMap
<>();
redisTemplate
.
delete
(
RiskSourceServiceImpl
.
cacheKeyForCanBeRunning
());
Optional
<
Equipment
>
equipment
=
iContingencyInstance
.
fire
(
batchNo
,
stepCode
,
""
,
buttonCode
,
confirm
,
stepState
);
Optional
<
Equipment
>
equipment
=
iContingencyInstance
.
fire
(
batchNo
,
stepCode
,
""
,
buttonCode
,
confirm
,
stepState
);
// 结束预案,更新设备重点设备参数
equipment
.
ifPresent
(
equip
->
{
equip
.
setStartTime
(
DateUtil
.
getDateNow
());
...
...
@@ -151,62 +104,26 @@ public class TimeLineController extends BaseController{
}
@Permission
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"预案回放"
,
notes
=
"预案回放"
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"预案回放"
,
notes
=
"预案回放"
)
@RequestMapping
(
value
=
"/fire/replay"
,
produces
=
"application/json;charset=UTF-8"
,
method
=
RequestMethod
.
GET
)
public
CommonResponse
replay
(
@RequestParam
(
"batchNo"
)
String
batchNo
,
@RequestParam
(
"randomNumber"
)
String
randomNumber
)
throws
Exception
{
ruleRunningSnapshotService
.
replayPlan
(
batchNo
,
randomNumber
);
public
CommonResponse
replay
(
@RequestParam
(
"batchNo"
)
String
batchNo
,
@RequestParam
(
"randomNumber"
)
String
randomNumber
)
throws
Exception
{
ruleRunningSnapshotService
.
replayPlan
(
batchNo
,
randomNumber
);
return
CommonResponseUtil
.
success
(
"SUCCESS"
);
}
@Permission
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"预案回放退出"
,
notes
=
"预案回放退出"
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"预案回放退出"
,
notes
=
"预案回放退出"
)
@RequestMapping
(
value
=
"/fire/replay/exit"
,
produces
=
"application/json;charset=UTF-8"
,
method
=
RequestMethod
.
GET
)
public
CommonResponse
replayExit
(
@RequestParam
(
"batchNo"
)
String
batchNo
,
@RequestParam
(
"randomNumber"
)
String
randomNumber
)
throws
Exception
{
ruleRunningSnapshotService
.
exitReplayPlan
(
batchNo
,
randomNumber
);
public
CommonResponse
replayExit
(
@RequestParam
(
"batchNo"
)
String
batchNo
,
@RequestParam
(
"randomNumber"
)
String
randomNumber
)
throws
Exception
{
ruleRunningSnapshotService
.
exitReplayPlan
(
batchNo
,
randomNumber
);
return
CommonResponseUtil
.
success
(
"SUCCESS"
);
}
@Scheduled
(
cron
=
"*/2 * * * * ?"
)
public
void
runFireQueue
()
throws
Exception
{
if
(
fireQueue
.
size
()
==
0
)
return
;
Map
<
String
,
String
>
map
=
fireQueue
.
getFirst
();
String
batchNo
=
map
.
get
(
"batchNo"
);
String
stepCode
=
map
.
get
(
"stepCode"
);
String
buttonCode
=
map
.
get
(
"buttonCode"
);
String
confirm
=
map
.
get
(
"confirm"
);
String
contingencyPlanId
=
map
.
get
(
"contingencyPlanId"
);
String
stepState
=
map
.
get
(
"stepState"
);
String
token
=
map
.
get
(
"token"
);
String
product
=
map
.
get
(
"product"
);
try
{
log
.
info
(
"fireQueue-size:"
+
fireQueue
.
size
());
log
.
info
(
"stepCode:"
+
map
.
get
(
"stepCode"
));
log
.
info
(
"buttonCode:"
+
map
.
get
(
"buttonCode"
));
log
.
info
(
"confirm:"
+
map
.
get
(
"confirm"
));
log
.
info
(
"stepState:"
+
map
.
get
(
"stepState"
));
RequestContext
.
setToken
(
token
);
RequestContext
.
setProduct
(
product
);
iContingencyInstance
.
setButtonExecuted
(
batchNo
,
contingencyPlanId
,
buttonCode
,
confirm
);
iContingencyInstance
.
fire
(
batchNo
,
stepCode
,
contingencyPlanId
,
buttonCode
,
confirm
,
stepState
);
}
catch
(
Exception
e
)
{
throw
e
;
}
finally
{
fireQueue
.
removeFirst
();
}
}
@Permission
// @Authorization(ingore = true)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"查询预案记录"
,
notes
=
"查询预案记录"
)
// @Authorization(ingore = true)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"查询预案记录"
,
notes
=
"查询预案记录"
)
@RequestMapping
(
value
=
"/contingency/page"
,
produces
=
"application/json;charset=UTF-8"
,
method
=
RequestMethod
.
POST
)
public
CommonResponse
contingencyRecord
(
@ApiParam
(
value
=
"查询条件"
,
required
=
false
)
@RequestBody
(
required
=
false
)
List
<
CommonRequest
>
queryRequests
,
...
...
@@ -214,29 +131,24 @@ public class TimeLineController extends BaseController{
)
{
//CommonPageable commonPageable = new CommonPageable(pageNumber,pageSize);
String
contingencyName
=
null
;
String
equipmentId
=
null
;
String
createTime
=
null
;
if
(!
CollectionUtils
.
isEmpty
(
queryRequests
))
{
for
(
CommonRequest
request:
queryRequests
)
{
if
(
"contingencyName"
.
equals
(
request
.
getName
()))
{
String
contingencyName
=
null
;
String
equipmentId
=
null
;
String
createTime
=
null
;
if
(!
CollectionUtils
.
isEmpty
(
queryRequests
))
{
for
(
CommonRequest
request
:
queryRequests
)
{
if
(
"contingencyName"
.
equals
(
request
.
getName
()))
{
contingencyName
=
String
.
valueOf
(
request
.
getValue
());
}
if
(
"equipmentId"
.
equals
(
request
.
getName
()))
{
if
(
"equipmentId"
.
equals
(
request
.
getName
()))
{
equipmentId
=
String
.
valueOf
(
request
.
getValue
());
}
if
(
"createTime"
.
equals
(
request
.
getName
()))
{
if
(
"createTime"
.
equals
(
request
.
getName
()))
{
createTime
=
String
.
valueOf
(
request
.
getValue
());
}
}
}
return
CommonResponseUtil
.
success
(
iContingencyOriginalDataService
.
queryForPage
(
contingencyName
,
equipmentId
,
createTime
,
commonPageable
));
return
CommonResponseUtil
.
success
(
iContingencyOriginalDataService
.
queryForPage
(
contingencyName
,
equipmentId
,
createTime
,
commonPageable
));
}
...
...
@@ -265,12 +177,10 @@ public class TimeLineController extends BaseController{
"}"
;
@Permission
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"根据批次号查询时间轴"
,
notes
=
"根据批次号查询时间轴"
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"根据批次号查询时间轴"
,
notes
=
"根据批次号查询时间轴"
)
@RequestMapping
(
value
=
"/replay"
,
produces
=
"application/json;charset=UTF-8"
,
method
=
RequestMethod
.
GET
)
public
CommonResponse
queryPoint
(
@RequestParam
(
"batchNo"
)
String
batchNo
)
throws
Exception
{
iRuleRunningSnapshotService
.
replay
(
batchNo
);
public
CommonResponse
queryPoint
(
@RequestParam
(
"batchNo"
)
String
batchNo
)
throws
Exception
{
iRuleRunningSnapshotService
.
replay
(
batchNo
);
return
CommonResponseUtil
.
success
();
}
}
YeeAmosFireAutoSysService/src/main/java/com/yeejoin/amos/fas/business/service/impl/ContingencyInstanceImpl.java
View file @
9926ec57
package
com
.
yeejoin
.
amos
.
fas
.
business
.
service
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yeejoin.amos.component.rule.RuleTrigger
;
import
com.yeejoin.amos.fas.business.action.ContingencyAction
;
import
com.yeejoin.amos.fas.business.action.model.ContingencyEvent
;
import
com.yeejoin.amos.fas.business.action.model.ContingencyRo
;
import
com.yeejoin.amos.fas.business.action.util.ContingencyLogPublisher
;
import
com.yeejoin.amos.fas.business.dao.mapper.FireEquipPointMapper
;
import
com.yeejoin.amos.fas.business.dao.mapper.ImpAndFireEquipMapper
;
import
com.yeejoin.amos.fas.business.dao.mapper.PlanDetailMapper
;
import
com.yeejoin.amos.fas.business.dao.repository.IContingencyOriginalDataDao
;
import
com.yeejoin.amos.fas.business.dao.repository.IContingencyPlanInstanceRepository
;
import
com.yeejoin.amos.fas.business.service.intfc.IContingencyInstance
;
import
com.yeejoin.amos.fas.business.service.intfc.IEquipmentService
;
import
com.yeejoin.amos.fas.business.service.model.Operate
;
import
com.yeejoin.amos.fas.business.service.model.OperateGroup
;
import
com.yeejoin.amos.fas.dao.entity.ContingencyOriginalData
;
import
com.yeejoin.amos.fas.dao.entity.ContingencyPlanInstance
;
import
com.yeejoin.amos.fas.dao.entity.Equipment
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.*
;
@Service
public
class
ContingencyInstanceImpl
/*extends GenericManagerImpl<ContingencyPlanInstance, String>*/
implements
IContingencyInstance
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ContingencyInstanceImpl
.
class
);
@Autowired
private
IContingencyPlanInstanceRepository
repository
;
@Autowired
IContingencyOriginalDataDao
iContingencyOriginalDataDao
;
@Autowired
private
RestTemplate
restTemplate
;
@Autowired
private
ImpAndFireEquipMapper
impAndFireEquipMapper
;
@Autowired
private
RedisTemplate
redisTemplate
;
@Autowired
private
FireEquipPointMapper
fireEquipPointMapper
;
@Autowired
private
IContingencyInstance
iContingencyInstance
;
@Autowired
private
IEquipmentService
equipmentService
;
@Value
(
"${station.name}"
)
private
String
stationName
;
private
static
Map
<
String
,
String
>
stepMap
=
new
HashMap
<>();
@Autowired
private
RuleTrigger
ruleTrigger
;
@Value
(
"${spring.application.name}"
)
private
String
serviceName
;
/* public ContingencyInstanceImpl(IContingencyPlanInstanceRepository repository) {
super(repository);
this.repository = repository;
}*/
@Autowired
ContingencyAction
contingencyAction
;
@Autowired
private
ContingencyLogPublisher
contingencyLogPublisher
;
@Autowired
private
PlanDetailMapper
planDetailMapper
;
/**
* 创建预案执行记录
*
* @param category 一级分类
* @param subCategory 二级分类
* @param content 信息内容
* @param recordType 信息分类
* @param icon 信息显示图标
*/
public
ContingencyPlanInstance
createInstanceRecord
(
String
instanceNo
,
String
category
,
String
subCategory
,
String
content
,
String
recordType
,
String
icon
)
{
ContingencyPlanInstance
planInstance
=
new
ContingencyPlanInstance
();
planInstance
.
setContent
(
content
);
planInstance
.
setIcon
(
icon
);
planInstance
.
setRecordType
(
recordType
);
planInstance
.
setCategory
(
category
);
planInstance
.
setBatchNo
(
instanceNo
);
planInstance
.
setCreateDate
(
new
Date
());
//计算序号
int
count
=
repository
.
countByBatchNo
(
instanceNo
);
planInstance
.
setSort
(++
count
);
return
this
.
repository
.
save
(
planInstance
);
}
/**
* 查询时间轴
*
* @param instanceNo
* @return
* @throws Exception
*/
public
List
<
ContingencyPlanInstance
>
queryForTimeLine
(
String
instanceNo
,
String
recordType
)
throws
Exception
{
List
<
ContingencyPlanInstance
>
categorys
=
repository
.
queryForCategory
(
instanceNo
,
recordType
);
return
categorys
;
}
public
Optional
<
Equipment
>
fire
(
String
batchNo
,
String
stepCode
,
String
contingencyPlanId
,
String
buttonCode
,
String
buttonState
,
String
stepStateOnbutton
)
throws
Exception
{
//火灾误报
ContingencyOriginalData
contingencyOriginalData
=
iContingencyOriginalDataDao
.
findByBatchNo
(
batchNo
);
String
stepKey
=
batchNo
+
"_"
+
stepCode
;
if
(
stepMap
.
get
(
stepKey
)
==
null
)
stepMap
.
put
(
stepKey
,
""
);
Equipment
equipment
;
if
(
contingencyOriginalData
!=
null
)
{
log
.
info
(
"数据库中的stepcode:"
+
contingencyOriginalData
.
getStep
());
contingencyOriginalData
.
setConfirm
(
buttonState
);
contingencyOriginalData
.
setRunstep
(
false
);
if
(
contingencyOriginalData
.
getStepState
()
==
null
)
contingencyOriginalData
.
setStepState
(
""
);
if
(
"CONFIRM"
.
equals
(
buttonState
)
&&
!
contingencyOriginalData
.
getStepState
().
contains
(
stepStateOnbutton
)
&&
stepCode
.
equals
(
contingencyOriginalData
.
getStep
()))
contingencyOriginalData
.
setStepState
(
contingencyOriginalData
.
getStepState
()
+
stepStateOnbutton
);
//请求中的步骤小于以保存的步骤
if
(
Integer
.
parseInt
(
stepCode
)
<
Integer
.
parseInt
(
contingencyOriginalData
.
getStep
()))
{
contingencyOriginalData
.
setRunstep
(
true
);
}
if
(
Integer
.
parseInt
(
stepCode
)
>
Integer
.
parseInt
(
contingencyOriginalData
.
getStep
()))
{
contingencyOriginalData
.
setStepState
(
stepStateOnbutton
);
}
iContingencyOriginalDataDao
.
updateByButton
(
contingencyOriginalData
.
getConfirm
(),
contingencyOriginalData
.
getRunstep
(),
contingencyOriginalData
.
getStepState
(),
contingencyOriginalData
.
getBatchNo
());
//使用原始数据触发规则
if
(
"CONFIRM"
.
equals
(
buttonState
)
&&
!
stepMap
.
get
(
stepKey
).
contains
(
stepStateOnbutton
))
stepMap
.
put
(
stepKey
,
stepMap
.
get
(
stepKey
)
+
stepStateOnbutton
);
ContingencyRo
contingencyRo
=
new
ContingencyRo
();
contingencyRo
.
setButtonCode
(
buttonCode
);
contingencyRo
.
setButtonState
(
buttonState
);
BeanUtils
.
copyProperties
(
contingencyOriginalData
,
contingencyRo
);
// SetpEnum step = SetpEnum.getStepByCode(stepCode);
contingencyRo
.
setStep
(
stepCode
);
contingencyRo
.
setStepState
(
stepMap
.
get
(
stepKey
));
// contingencyRo.setStep(stepCode);
log
.
info
(
"stepstate:"
+
contingencyRo
.
getStepState
());
log
.
info
(
"stepCode:"
+
stepCode
);
equipment
=
impAndFireEquipMapper
.
queryImpEqumtByFireEquipmt
(
Long
.
parseLong
(
contingencyRo
.
getFireEquipmentId
()));
if
(
equipment
!=
null
)
{
// 获取重点设备胚胎指标
// 获取遥信指标
List
<
Map
>
points
=
fireEquipPointMapper
.
getPointsByEquipmentIdAndType
(
equipment
.
getId
(),
"SWITCH"
);
HashMap
<
String
,
Integer
>
telesignallingMap
=
new
HashMap
<>();
for
(
Map
map
:
points
)
{
telesignallingMap
.
put
(
map
.
get
(
"code"
)
+
""
,
(
ObjectUtils
.
isEmpty
(
map
.
get
(
"value"
))
||
"false"
.
equals
(
map
.
get
(
"value"
).
toString
()))
?
0
:
1
);
}
contingencyRo
.
setTelesignallingMap
(
telesignallingMap
);
//获取遥测指标
points
=
fireEquipPointMapper
.
getPointsByEquipmentIdAndType
(
equipment
.
getId
(),
"ANALOGUE"
);
HashMap
<
String
,
Double
>
telemetryMap
=
new
HashMap
<>();
for
(
Map
map
:
points
)
{
telemetryMap
.
put
(
map
.
get
(
"code"
)
+
""
,
Double
.
valueOf
(
ObjectUtils
.
isEmpty
(
map
.
get
(
"value"
))
?
"0"
:
map
.
get
(
"value"
).
toString
()));
}
contingencyRo
.
setTelemetryMap
(
telemetryMap
);
contingencyRo
.
setEquipmentCode
(
equipment
.
getCode
());
List
<
String
>
plan
=
this
.
getNumberPlan
(
Long
.
parseLong
(
contingencyRo
.
getEquipmentId
()));
ruleTrigger
.
publish
(
contingencyRo
,
"换流站消防专项预案/"
+
plan
.
get
(
0
),
ArrayUtils
.
toArray
(
equipment
.
getName
()));
publisherPlanLog
(
stepCode
,
buttonCode
,
batchNo
);
}
}
else
{
throw
new
Exception
(
"数据异常,请联系管理员."
);
}
return
Optional
.
ofNullable
(
equipment
);
}
private
void
publisherPlanLog
(
String
stepCode
,
String
buttonCode
,
String
batchNo
)
{
ContingencyEvent
event
=
new
ContingencyEvent
(
this
);
JSONObject
json
=
new
JSONObject
();
JSONObject
msgContext
=
new
JSONObject
();
JSONObject
content
=
new
JSONObject
();
content
.
put
(
"stepCode"
,
stepCode
);
content
.
put
(
"buttonCode"
,
buttonCode
);
msgContext
.
put
(
"type"
,
"clickEvent"
);
msgContext
.
put
(
"content"
,
content
);
json
.
put
(
"msgType"
,
"message"
);
json
.
put
(
"msgContext"
,
msgContext
);
event
.
setMsgBody
(
json
.
toJSONString
());
String
topic
=
String
.
format
(
"/%s/%s/%s"
,
serviceName
,
stationName
,
"plan"
);
event
.
setTopic
(
topic
);
event
.
setMsgType
(
"clickEvent"
);
event
.
setContingency
(
batchNo
);
contingencyLogPublisher
.
publish
(
event
);
}
public
void
setButtonExecuted
(
String
batchNo
,
String
contingencyPlanId
,
String
code
,
String
buttonState
)
throws
Exception
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
Optional
<
ContingencyPlanInstance
>
contingencyPlanInstance1
=
repository
.
findById
(
contingencyPlanId
);
ContingencyPlanInstance
contingencyPlanInstance
=
contingencyPlanInstance1
.
get
();
if
(
contingencyPlanInstance1
.
isPresent
())
{
if
(
contingencyPlanInstance
!=
null
&&
"OPERATE"
.
equals
(
contingencyPlanInstance
.
getRecordType
()))
{
String
operateJson
=
contingencyPlanInstance
.
getContent
();
OperateGroup
operateGroup
=
objectMapper
.
readValue
(
operateJson
,
OperateGroup
.
class
);
List
<
Operate
>
operates
=
operateGroup
.
getOperate
();
if
(!
CollectionUtils
.
isEmpty
(
operates
))
{
for
(
Operate
operate
:
operates
)
{
if
(
code
.
equals
(
operate
.
getCode
())
&&
(
"executed"
.
equals
(
operate
.
getState
())
||
"disable"
.
equals
(
operate
.
getState
())))
{
if
(
"FIRE_CANCEL"
.
equals
(
code
)
||
"END_EMERGENCY"
.
equals
(
code
))
{
redisTemplate
.
delete
(
RiskSourceServiceImpl
.
cacheKeyForCanBeRunning
());
}
throw
new
Exception
(
"请勿重复操作."
);
}
if
(
"CONFIRM"
.
equals
(
buttonState
))
{
if
(
code
.
equals
(
operate
.
getCode
()))
{
operate
.
setState
(
"executed"
);
if
(
"FIRE_CANCEL"
.
equals
(
code
)
||
"END_EMERGENCY"
.
equals
(
code
))
redisTemplate
.
delete
(
RiskSourceServiceImpl
.
cacheKeyForCanBeRunning
());
}
else
{
operate
.
setState
(
"disable"
);
}
}
}
}
if
(
buttonState
.
equals
(
"CONFIRM"
))
contingencyPlanInstance
.
setRunstate
(
true
);
operateJson
=
objectMapper
.
writeValueAsString
(
operateGroup
);
contingencyPlanInstance
.
setContent
(
operateJson
);
repository
.
save
(
contingencyPlanInstance
);
}
}
}
public
void
setButtonWait
(
String
batchNo
,
String
contingencyPlanId
,
String
buttonState
)
throws
Exception
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
Optional
<
ContingencyPlanInstance
>
contingencyPlanInstance1
=
repository
.
findById
(
contingencyPlanId
);
ContingencyPlanInstance
contingencyPlanInstance
=
null
;
if
(
contingencyPlanInstance1
.
isPresent
())
{
contingencyPlanInstance
=
contingencyPlanInstance1
.
get
();
}
if
(
contingencyPlanInstance
!=
null
&&
"OPERATE"
.
equals
(
contingencyPlanInstance
.
getRecordType
()))
{
String
operateJson
=
contingencyPlanInstance
.
getContent
();
OperateGroup
operateGroup
=
objectMapper
.
readValue
(
operateJson
,
OperateGroup
.
class
);
List
<
Operate
>
operates
=
operateGroup
.
getOperate
();
if
(!
CollectionUtils
.
isEmpty
(
operates
))
{
for
(
Operate
operate
:
operates
)
{
if
(
"CONFIRM"
.
equals
(
buttonState
))
{
operate
.
setState
(
"executed"
);
}
}
}
if
(
buttonState
.
equals
(
"CONFIRM"
))
contingencyPlanInstance
.
setRunstate
(
true
);
operateJson
=
objectMapper
.
writeValueAsString
(
operateGroup
);
contingencyPlanInstance
.
setContent
(
operateJson
);
repository
.
save
(
contingencyPlanInstance
);
}
}
@Override
public
void
updateStep
(
String
step
,
String
batchNo
)
{
iContingencyOriginalDataDao
.
updateByButtonStep
(
step
,
batchNo
);
}
public
List
<
String
>
getNumberPlan
(
Long
id
)
{
List
<
String
>
ruleId
=
planDetailMapper
.
getRuleIdByEquipment
(
id
);
return
ruleId
;
}
}
package
com
.
yeejoin
.
amos
.
fas
.
business
.
service
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yeejoin.amos.component.rule.RuleTrigger
;
import
com.yeejoin.amos.fas.business.action.ContingencyAction
;
import
com.yeejoin.amos.fas.business.action.model.ContingencyEvent
;
import
com.yeejoin.amos.fas.business.action.model.ContingencyRo
;
import
com.yeejoin.amos.fas.business.action.util.ContingencyLogPublisher
;
import
com.yeejoin.amos.fas.business.bo.FirePlanAlarmBo
;
import
com.yeejoin.amos.fas.business.dao.mapper.FireEquipPointMapper
;
import
com.yeejoin.amos.fas.business.dao.mapper.ImpAndFireEquipMapper
;
import
com.yeejoin.amos.fas.business.dao.mapper.PlanDetailMapper
;
import
com.yeejoin.amos.fas.business.dao.mapper.View3dMapper
;
import
com.yeejoin.amos.fas.business.dao.repository.IContingencyOriginalDataDao
;
import
com.yeejoin.amos.fas.business.dao.repository.IContingencyPlanInstanceRepository
;
import
com.yeejoin.amos.fas.business.feign.RemoteSecurityService
;
import
com.yeejoin.amos.fas.business.service.intfc.IContingencyInstance
;
import
com.yeejoin.amos.fas.business.service.intfc.IRocketMQService
;
import
com.yeejoin.amos.fas.business.service.model.Operate
;
import
com.yeejoin.amos.fas.business.service.model.OperateGroup
;
import
com.yeejoin.amos.fas.business.vo.Toke
;
import
com.yeejoin.amos.fas.dao.entity.ContingencyOriginalData
;
import
com.yeejoin.amos.fas.dao.entity.ContingencyPlanInstance
;
import
com.yeejoin.amos.fas.dao.entity.Equipment
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.typroject.tyboot.core.foundation.context.RequestContext
;
import
java.util.*
;
@Service
public
class
ContingencyInstanceImpl
/*extends GenericManagerImpl<ContingencyPlanInstance, String>*/
implements
IContingencyInstance
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ContingencyInstanceImpl
.
class
);
static
LinkedList
<
Map
<
String
,
String
>>
fireQueue
=
new
LinkedList
<>();
@Autowired
private
IContingencyPlanInstanceRepository
repository
;
@Autowired
IContingencyOriginalDataDao
iContingencyOriginalDataDao
;
@Autowired
private
ImpAndFireEquipMapper
impAndFireEquipMapper
;
@Autowired
private
RedisTemplate
redisTemplate
;
@Autowired
private
FireEquipPointMapper
fireEquipPointMapper
;
@Autowired
IRocketMQService
rocketMQService
;
@Autowired
private
RemoteSecurityService
remoteSecurityService
;
@Value
(
"${rocket-equip-alarm-topic}"
)
private
String
rocketTopicFireEquipAlarm
;
@Autowired
private
View3dMapper
view3dMapper
;
@Value
(
"${station.name}"
)
private
String
stationName
;
private
static
Map
<
String
,
String
>
stepMap
=
new
HashMap
<>();
@Autowired
private
RuleTrigger
ruleTrigger
;
@Value
(
"${spring.application.name}"
)
private
String
serviceName
;
/* public ContingencyInstanceImpl(IContingencyPlanInstanceRepository repository) {
super(repository);
this.repository = repository;
}*/
@Autowired
ContingencyAction
contingencyAction
;
@Autowired
private
ContingencyLogPublisher
contingencyLogPublisher
;
@Autowired
private
PlanDetailMapper
planDetailMapper
;
/**
* 创建预案执行记录
*
* @param category 一级分类
* @param subCategory 二级分类
* @param content 信息内容
* @param recordType 信息分类
* @param icon 信息显示图标
*/
public
ContingencyPlanInstance
createInstanceRecord
(
String
instanceNo
,
String
category
,
String
subCategory
,
String
content
,
String
recordType
,
String
icon
)
{
ContingencyPlanInstance
planInstance
=
new
ContingencyPlanInstance
();
planInstance
.
setContent
(
content
);
planInstance
.
setIcon
(
icon
);
planInstance
.
setRecordType
(
recordType
);
planInstance
.
setCategory
(
category
);
planInstance
.
setBatchNo
(
instanceNo
);
planInstance
.
setCreateDate
(
new
Date
());
//计算序号
int
count
=
repository
.
countByBatchNo
(
instanceNo
);
planInstance
.
setSort
(++
count
);
return
this
.
repository
.
save
(
planInstance
);
}
/**
* 查询时间轴
*
* @param instanceNo
* @return
* @throws Exception
*/
public
List
<
ContingencyPlanInstance
>
queryForTimeLine
(
String
instanceNo
,
String
recordType
)
throws
Exception
{
List
<
ContingencyPlanInstance
>
categorys
=
repository
.
queryForCategory
(
instanceNo
,
recordType
);
return
categorys
;
}
public
Optional
<
Equipment
>
fire
(
String
batchNo
,
String
stepCode
,
String
contingencyPlanId
,
String
buttonCode
,
String
buttonState
,
String
stepStateOnbutton
)
throws
Exception
{
//火灾误报
ContingencyOriginalData
contingencyOriginalData
=
iContingencyOriginalDataDao
.
findByBatchNo
(
batchNo
);
String
stepKey
=
batchNo
+
"_"
+
stepCode
;
if
(
stepMap
.
get
(
stepKey
)
==
null
)
stepMap
.
put
(
stepKey
,
""
);
Equipment
equipment
;
if
(
contingencyOriginalData
!=
null
)
{
log
.
info
(
"数据库中的stepcode:"
+
contingencyOriginalData
.
getStep
());
contingencyOriginalData
.
setConfirm
(
buttonState
);
contingencyOriginalData
.
setRunstep
(
false
);
if
(
contingencyOriginalData
.
getStepState
()
==
null
)
contingencyOriginalData
.
setStepState
(
""
);
if
(
"CONFIRM"
.
equals
(
buttonState
)
&&
!
contingencyOriginalData
.
getStepState
().
contains
(
stepStateOnbutton
)
&&
stepCode
.
equals
(
contingencyOriginalData
.
getStep
()))
contingencyOriginalData
.
setStepState
(
contingencyOriginalData
.
getStepState
()
+
stepStateOnbutton
);
//请求中的步骤小于以保存的步骤
if
(
Integer
.
parseInt
(
stepCode
)
<
Integer
.
parseInt
(
contingencyOriginalData
.
getStep
()))
{
contingencyOriginalData
.
setRunstep
(
true
);
}
if
(
Integer
.
parseInt
(
stepCode
)
>
Integer
.
parseInt
(
contingencyOriginalData
.
getStep
()))
{
contingencyOriginalData
.
setStepState
(
stepStateOnbutton
);
}
iContingencyOriginalDataDao
.
updateByButton
(
contingencyOriginalData
.
getConfirm
(),
contingencyOriginalData
.
getRunstep
(),
contingencyOriginalData
.
getStepState
(),
contingencyOriginalData
.
getBatchNo
());
//使用原始数据触发规则
if
(
"CONFIRM"
.
equals
(
buttonState
)
&&
!
stepMap
.
get
(
stepKey
).
contains
(
stepStateOnbutton
))
stepMap
.
put
(
stepKey
,
stepMap
.
get
(
stepKey
)
+
stepStateOnbutton
);
ContingencyRo
contingencyRo
=
new
ContingencyRo
();
contingencyRo
.
setButtonCode
(
buttonCode
);
contingencyRo
.
setButtonState
(
buttonState
);
BeanUtils
.
copyProperties
(
contingencyOriginalData
,
contingencyRo
);
// SetpEnum step = SetpEnum.getStepByCode(stepCode);
contingencyRo
.
setStep
(
stepCode
);
contingencyRo
.
setStepState
(
stepMap
.
get
(
stepKey
));
// contingencyRo.setStep(stepCode);
log
.
info
(
"stepstate:"
+
contingencyRo
.
getStepState
());
log
.
info
(
"stepCode:"
+
stepCode
);
equipment
=
impAndFireEquipMapper
.
queryImpEqumtByFireEquipmt
(
Long
.
parseLong
(
contingencyRo
.
getFireEquipmentId
()));
if
(
equipment
!=
null
)
{
// 获取重点设备胚胎指标
// 获取遥信指标
List
<
Map
>
points
=
fireEquipPointMapper
.
getPointsByEquipmentIdAndType
(
equipment
.
getId
(),
"SWITCH"
);
HashMap
<
String
,
Integer
>
telesignallingMap
=
new
HashMap
<>();
for
(
Map
map
:
points
)
{
telesignallingMap
.
put
(
map
.
get
(
"code"
)
+
""
,
(
ObjectUtils
.
isEmpty
(
map
.
get
(
"value"
))
||
"false"
.
equals
(
map
.
get
(
"value"
).
toString
()))
?
0
:
1
);
}
contingencyRo
.
setTelesignallingMap
(
telesignallingMap
);
//获取遥测指标
points
=
fireEquipPointMapper
.
getPointsByEquipmentIdAndType
(
equipment
.
getId
(),
"ANALOGUE"
);
HashMap
<
String
,
Double
>
telemetryMap
=
new
HashMap
<>();
for
(
Map
map
:
points
)
{
telemetryMap
.
put
(
map
.
get
(
"code"
)
+
""
,
Double
.
valueOf
(
ObjectUtils
.
isEmpty
(
map
.
get
(
"value"
))
?
"0"
:
map
.
get
(
"value"
).
toString
()));
}
contingencyRo
.
setTelemetryMap
(
telemetryMap
);
contingencyRo
.
setEquipmentCode
(
equipment
.
getCode
());
List
<
String
>
plan
=
this
.
getNumberPlan
(
Long
.
parseLong
(
contingencyRo
.
getEquipmentId
()));
ruleTrigger
.
publish
(
contingencyRo
,
"换流站消防专项预案/"
+
plan
.
get
(
0
),
ArrayUtils
.
toArray
(
equipment
.
getName
()));
publisherPlanLog
(
stepCode
,
buttonCode
,
batchNo
);
}
}
else
{
throw
new
Exception
(
"数据异常,请联系管理员."
);
}
return
Optional
.
ofNullable
(
equipment
);
}
private
void
publisherPlanLog
(
String
stepCode
,
String
buttonCode
,
String
batchNo
)
{
ContingencyEvent
event
=
new
ContingencyEvent
(
this
);
JSONObject
json
=
new
JSONObject
();
JSONObject
msgContext
=
new
JSONObject
();
JSONObject
content
=
new
JSONObject
();
content
.
put
(
"stepCode"
,
stepCode
);
content
.
put
(
"buttonCode"
,
buttonCode
);
msgContext
.
put
(
"type"
,
"clickEvent"
);
msgContext
.
put
(
"content"
,
content
);
json
.
put
(
"msgType"
,
"message"
);
json
.
put
(
"msgContext"
,
msgContext
);
event
.
setMsgBody
(
json
.
toJSONString
());
String
topic
=
String
.
format
(
"/%s/%s/%s"
,
serviceName
,
stationName
,
"plan"
);
event
.
setTopic
(
topic
);
event
.
setMsgType
(
"clickEvent"
);
event
.
setContingency
(
batchNo
);
contingencyLogPublisher
.
publish
(
event
);
}
public
void
setButtonExecuted
(
String
batchNo
,
String
contingencyPlanId
,
String
code
,
String
buttonState
)
throws
Exception
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
Optional
<
ContingencyPlanInstance
>
contingencyPlanInstance1
=
repository
.
findById
(
contingencyPlanId
);
ContingencyPlanInstance
contingencyPlanInstance
=
contingencyPlanInstance1
.
get
();
if
(
contingencyPlanInstance1
.
isPresent
())
{
if
(
contingencyPlanInstance
!=
null
&&
"OPERATE"
.
equals
(
contingencyPlanInstance
.
getRecordType
()))
{
String
operateJson
=
contingencyPlanInstance
.
getContent
();
OperateGroup
operateGroup
=
objectMapper
.
readValue
(
operateJson
,
OperateGroup
.
class
);
List
<
Operate
>
operates
=
operateGroup
.
getOperate
();
if
(!
CollectionUtils
.
isEmpty
(
operates
))
{
for
(
Operate
operate
:
operates
)
{
if
(
code
.
equals
(
operate
.
getCode
())
&&
(
"executed"
.
equals
(
operate
.
getState
())
||
"disable"
.
equals
(
operate
.
getState
())))
{
if
(
"FIRE_CANCEL"
.
equals
(
code
)
||
"END_EMERGENCY"
.
equals
(
code
))
{
redisTemplate
.
delete
(
RiskSourceServiceImpl
.
cacheKeyForCanBeRunning
());
}
throw
new
Exception
(
"请勿重复操作."
);
}
if
(
"CONFIRM"
.
equals
(
buttonState
))
{
if
(
code
.
equals
(
operate
.
getCode
()))
{
operate
.
setState
(
"executed"
);
if
(
"FIRE_CANCEL"
.
equals
(
code
)
||
"END_EMERGENCY"
.
equals
(
code
))
redisTemplate
.
delete
(
RiskSourceServiceImpl
.
cacheKeyForCanBeRunning
());
}
else
{
operate
.
setState
(
"disable"
);
}
}
}
}
if
(
buttonState
.
equals
(
"CONFIRM"
))
contingencyPlanInstance
.
setRunstate
(
true
);
operateJson
=
objectMapper
.
writeValueAsString
(
operateGroup
);
contingencyPlanInstance
.
setContent
(
operateJson
);
repository
.
save
(
contingencyPlanInstance
);
}
}
}
public
void
setButtonWait
(
String
batchNo
,
String
contingencyPlanId
,
String
buttonState
)
throws
Exception
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
Optional
<
ContingencyPlanInstance
>
contingencyPlanInstance1
=
repository
.
findById
(
contingencyPlanId
);
ContingencyPlanInstance
contingencyPlanInstance
=
null
;
if
(
contingencyPlanInstance1
.
isPresent
())
{
contingencyPlanInstance
=
contingencyPlanInstance1
.
get
();
}
if
(
contingencyPlanInstance
!=
null
&&
"OPERATE"
.
equals
(
contingencyPlanInstance
.
getRecordType
()))
{
String
operateJson
=
contingencyPlanInstance
.
getContent
();
OperateGroup
operateGroup
=
objectMapper
.
readValue
(
operateJson
,
OperateGroup
.
class
);
List
<
Operate
>
operates
=
operateGroup
.
getOperate
();
if
(!
CollectionUtils
.
isEmpty
(
operates
))
{
for
(
Operate
operate
:
operates
)
{
if
(
"CONFIRM"
.
equals
(
buttonState
))
{
operate
.
setState
(
"executed"
);
}
}
}
if
(
buttonState
.
equals
(
"CONFIRM"
))
contingencyPlanInstance
.
setRunstate
(
true
);
operateJson
=
objectMapper
.
writeValueAsString
(
operateGroup
);
contingencyPlanInstance
.
setContent
(
operateJson
);
repository
.
save
(
contingencyPlanInstance
);
}
}
@Override
public
void
updateStep
(
String
step
,
String
batchNo
)
{
iContingencyOriginalDataDao
.
updateByButtonStep
(
step
,
batchNo
);
}
@Override
public
Optional
<
Equipment
>
fire
(
String
batchNo
,
String
stepCode
,
String
contingencyPlanId
,
String
buttonCode
,
String
buttonState
,
String
stepStateOnbutton
,
String
token
,
String
product
)
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"batchNo"
,
batchNo
);
map
.
put
(
"stepCode"
,
stepCode
);
map
.
put
(
"buttonCode"
,
buttonCode
);
map
.
put
(
"confirm"
,
buttonState
);
map
.
put
(
"contingencyPlanId"
,
contingencyPlanId
);
map
.
put
(
"stepState"
,
stepStateOnbutton
);
if
(
StringUtils
.
isNotBlank
(
token
)
||
StringUtils
.
isNotBlank
(
product
))
{
Toke
serverToken
=
remoteSecurityService
.
getServerToken
();
map
.
put
(
"token"
,
serverToken
.
getToke
());
map
.
put
(
"product"
,
serverToken
.
getProduct
());
}
else
{
map
.
put
(
"token"
,
token
);
map
.
put
(
"product"
,
product
);
}
fireQueue
.
addLast
(
map
);
//应急指挥给总部推送消息
sendPlanAlarm
(
batchNo
,
buttonCode
);
return
Optional
.
empty
();
}
private
void
sendPlanAlarm
(
String
batchNo
,
String
buttonCode
)
{
//确警后推送报警数据
if
(
"FIRE_CONFIRM"
.
equals
(
buttonCode
))
{
FirePlanAlarmBo
firePlanAlarm
=
view3dMapper
.
getPlanAlarmInfo
(
batchNo
);
List
<
FirePlanAlarmBo
>
list
=
new
ArrayList
<
FirePlanAlarmBo
>();
list
.
add
(
firePlanAlarm
);
rocketMQService
.
sendMsg
(
rocketTopicFireEquipAlarm
,
"plan_alarm"
,
list
);
}
}
@Scheduled
(
cron
=
"*/2 * * * * ?"
)
public
void
runFireQueue
()
throws
Exception
{
if
(
fireQueue
.
size
()
==
0
)
return
;
Map
<
String
,
String
>
map
=
fireQueue
.
getFirst
();
String
batchNo
=
map
.
get
(
"batchNo"
);
String
stepCode
=
map
.
get
(
"stepCode"
);
String
buttonCode
=
map
.
get
(
"buttonCode"
);
String
confirm
=
map
.
get
(
"confirm"
);
String
contingencyPlanId
=
map
.
get
(
"contingencyPlanId"
);
String
stepState
=
map
.
get
(
"stepState"
);
String
token
=
map
.
get
(
"token"
);
String
product
=
map
.
get
(
"product"
);
try
{
log
.
info
(
"fireQueue-size:"
+
fireQueue
.
size
());
log
.
info
(
"stepCode:"
+
map
.
get
(
"stepCode"
));
log
.
info
(
"buttonCode:"
+
map
.
get
(
"buttonCode"
));
log
.
info
(
"confirm:"
+
map
.
get
(
"confirm"
));
log
.
info
(
"stepState:"
+
map
.
get
(
"stepState"
));
RequestContext
.
setToken
(
token
);
RequestContext
.
setProduct
(
product
);
setButtonExecuted
(
batchNo
,
contingencyPlanId
,
buttonCode
,
confirm
);
fire
(
batchNo
,
stepCode
,
contingencyPlanId
,
buttonCode
,
confirm
,
stepState
);
}
catch
(
Exception
e
)
{
throw
e
;
}
finally
{
fireQueue
.
removeFirst
();
}
}
public
List
<
String
>
getNumberPlan
(
Long
id
)
{
List
<
String
>
ruleId
=
planDetailMapper
.
getRuleIdByEquipment
(
id
);
return
ruleId
;
}
}
YeeAmosFireAutoSysService/src/main/java/com/yeejoin/amos/fas/business/service/intfc/IContingencyInstance.java
View file @
9926ec57
...
...
@@ -22,4 +22,6 @@ public interface IContingencyInstance {
Optional
<
Equipment
>
fire
(
String
batchNo
,
String
stepCode
,
String
contingencyPlanId
,
String
buttonCode
,
String
buttonState
,
String
stepStateOnbutton
)
throws
Exception
;
void
updateStep
(
String
step
,
String
batchNo
);
Optional
<
Equipment
>
fire
(
String
batchNo
,
String
stepCode
,
String
contingencyPlanId
,
String
buttonCode
,
String
buttonState
,
String
stepStateOnbutton
,
String
token
,
String
product
)
throws
Exception
;
}
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