Commit 494b5d5a authored by 吴俊凯's avatar 吴俊凯

预案启动代码提交

parent 1efd642c
package com.yeejoin.amos.fas.common.enums;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*0、运行中,1、完毕,3、中断
* @author suhg
*/
public enum PlanRecordStatusEnum {
OPERATION("运行中",0),
COMPLETE("完毕",1),
INTERRUPT("中断",2);
/**
* 名称,描述
*/
private String name;
/**
* 编码
*/
private Integer code;
/**
* 颜色
*/
private String color;
private PlanRecordStatusEnum(String name, Integer code){
this.name = name;
this.code = code;
}
public static PlanRecordStatusEnum getEnum(Integer code) {
PlanRecordStatusEnum checkStatusEnum = null;
for(PlanRecordStatusEnum type: PlanRecordStatusEnum.values()) {
if (type.getCode().equals(code)) {
checkStatusEnum = type;
break;
}
}
return checkStatusEnum;
}
public static List<Map<String,Object>> getEnumList() {
List<Map<String,Object>> nameList = new ArrayList<>();
for (PlanRecordStatusEnum c: PlanRecordStatusEnum.values()) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", c.getName());
map.put("code", c.getCode());
nameList.add(map);
}
return nameList;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
}
package com.yeejoin.amos.fas.business.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.fas.business.service.intfc.ContingencyPlanService;
import com.yeejoin.amos.fas.business.vo.ContingencyPlanParamVo;
import com.yeejoin.amos.fas.core.util.CommonResponseUtil2;
import com.yeejoin.amos.fas.core.util.ResponseModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/contingencyPlan")
......@@ -21,8 +20,25 @@ public class ContingencyPlanController extends BaseController {
private ContingencyPlanService contingencyPlanService;
@ApiOperation(value = "启动")
@RequestMapping(value = "/start", method = RequestMethod.POST)
public ResponseModel create(@RequestBody ContingencyPlanParamVo vo) {
public ResponseModel start(@RequestBody ContingencyPlanParamVo vo) {
contingencyPlanService.planStart(vo);
return CommonResponseUtil2.success();
}
@ApiOperation(value = "装备确景")
@RequestMapping(value = "/scene", method = RequestMethod.POST)
public ResponseModel scene(@ApiParam(value = "装备Id", required = true) String equipmentId) {
ContingencyPlanParamVo vo = contingencyPlanService.equipmentScene(Long.parseLong(equipmentId));
return CommonResponseUtil2.success(vo);
}
@ApiOperation(value = "预案启动记录分页列表")
@RequestMapping(value = "/recordList", method = RequestMethod.POST)
public ResponseModel recordList(
@ApiParam(value = "预案名称") @RequestParam(required = false) String planName,
@RequestParam int pageNumber,
@RequestParam int pageSize) {
Page page = contingencyPlanService.recordListByPage(planName,pageNumber,pageSize);
return CommonResponseUtil2.success(page);
}
}
package com.yeejoin.amos.fas.business.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.yeejoin.amos.fas.core.enums.ReserveEnum;
import com.yeejoin.amos.fas.core.util.CommonResponseUtil2;
import com.yeejoin.amos.fas.core.util.ResponseModel;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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 com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.fas.business.action.model.FireEquimentDataRo;
import com.yeejoin.amos.fas.business.action.model.ProtalDataRo;
......@@ -38,9 +13,11 @@ import com.yeejoin.amos.fas.business.vo.ReginParams;
import com.yeejoin.amos.fas.config.Permission;
import com.yeejoin.amos.fas.core.common.request.CommonPageable;
import com.yeejoin.amos.fas.core.common.response.RiskSourceTreeResponse;
import com.yeejoin.amos.fas.core.enums.ReserveEnum;
import com.yeejoin.amos.fas.core.util.CommonResponse;
import com.yeejoin.amos.fas.core.util.CommonResponseUtil;
import com.yeejoin.amos.fas.dao.entity.RiskSource;
import com.yeejoin.amos.fas.core.util.CommonResponseUtil2;
import com.yeejoin.amos.fas.core.util.ResponseModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
......@@ -648,7 +625,7 @@ public class RiskSourceController extends BaseController {
@RequestMapping(value = "/startEquipReserve", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
public ResponseModel startEquipReserve(@RequestParam Long id, @RequestParam String typeCode) {
ReserveEnum reserveEnum = riskSourceService.startEquipReserve(id, typeCode);
ReserveEnum reserveEnum = riskSourceService.startEquipReserve(id, typeCode,null);
Integer status = reserveEnum.getStatus();
String text = reserveEnum.getText();
if (status == 1) {
......
......@@ -2,6 +2,10 @@ package com.yeejoin.amos.fas.business.dao.mapper;
import org.springframework.stereotype.Repository;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <h1><h1>
*
......@@ -10,4 +14,6 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface PlanOperationRecordMapper {
Integer PlanOperationRecordListByCount(Map<String,Object> params);
List<HashMap<String,Object>> PlanOperationRecordListByPage(Map<String,Object> params);
}
package com.yeejoin.amos.fas.business.dao.repository;
import com.yeejoin.amos.fas.dao.entity.PlanEquipment;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
/**
......@@ -11,4 +12,6 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface IPlanEquipmentDao extends BaseDao<PlanEquipment, Long> {
@Query(value="SELECT * from c_plan_equipment where fire_equipment_id = ?1 AND is_delete = 0 ", nativeQuery = true)
PlanEquipment findByFireEquipmentId(Long fireEquipmentId);
}
package com.yeejoin.amos.fas.business.dao.repository;
import com.yeejoin.amos.fas.dao.entity.PlanOperationRecord;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
/**
......@@ -11,4 +12,6 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface IPlanOperationRecordDao extends BaseDao<PlanOperationRecord, Long> {
@Query(value="SELECT * from c_plan_operation_record where batch_no = ?1 AND is_delete = 0 ", nativeQuery = true)
PlanOperationRecord findByBatchNo(String batchNo);
}
package com.yeejoin.amos.fas.business.service.impl;
import com.yeejoin.amos.fas.business.dao.repository.IPlanDetailDao;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.fas.business.dao.mapper.PlanOperationRecordMapper;
import com.yeejoin.amos.fas.business.dao.repository.*;
import com.yeejoin.amos.fas.business.service.intfc.ContingencyPlanService;
import com.yeejoin.amos.fas.business.service.intfc.IEquipmentService;
import com.yeejoin.amos.fas.business.service.intfc.IRiskSourceService;
import com.yeejoin.amos.fas.business.vo.ContingencyPlanParamVo;
import com.yeejoin.amos.fas.common.enums.ContingencyPlanStatusEnum;
import com.yeejoin.amos.fas.common.enums.PlanRecordStatusEnum;
import com.yeejoin.amos.fas.core.enums.NumberEnum;
import com.yeejoin.amos.fas.core.enums.ReserveEnum;
import com.yeejoin.amos.fas.dao.entity.Equipment;
import com.yeejoin.amos.fas.dao.entity.PlanDetail;
import com.yeejoin.amos.fas.dao.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Optional;
import java.util.*;
/**
*@program: YeeAmosFireAutoSysRoot
......@@ -30,8 +32,18 @@ public class ContingencyPlanServiceImpl implements ContingencyPlanService {
private IEquipmentService equipmentService;
@Autowired
private IRiskSourceService riskSourceService;
@Autowired
private IPlanOperationRecordDao planOperationRecordDao;
@Qualifier("IEquipmentFireEquipmentDao")
@Autowired
private IEquipmentFireEquipmentDao equipmentFireEquipmentDao;
@Qualifier("iEquipmentDao")
@Autowired
private IEquipmentDao equipmentDao;
@Autowired
private IPlanEquipmentDao planEquipmentDao;
@Autowired
private PlanOperationRecordMapper planOperationRecordMapper;
@Override
public String planStart(ContingencyPlanParamVo vo){
ReserveEnum reserveEnum= null;
......@@ -53,12 +65,20 @@ public class ContingencyPlanServiceImpl implements ContingencyPlanService {
}else {
return "预控启动状态不正确";
}
//预案启动
Optional<PlanDetail> PlanDetailOp = planDetailDao.findById(Long.valueOf(vo.getPlanId()));
//插入运行记录表
PlanOperationRecord planOperationRecord = new PlanOperationRecord();
planOperationRecord.setStatus(PlanRecordStatusEnum.OPERATION.getCode());
planOperationRecord.setPlanId(PlanDetailOp.get().getId());
planOperationRecord.setIsDelete(true);
planOperationRecord.setStartTime(new Date());
planOperationRecord.setPlanPattern(Integer.parseInt(vo.getStatus()));
PlanOperationRecord result = planOperationRecordDao.save(planOperationRecord);
//预案启动
if(PlanDetailOp.get()!=null){
Equipment equipment = equipmentService.queryOne(PlanDetailOp.get().getId());
//预案启动
reserveEnum = riskSourceService.startEquipReserve(equipment.getId(),equipment.getCode());
reserveEnum = riskSourceService.startEquipReserve(equipment.getId(),equipment.getCode(),result.getId());
if(ReserveEnum.RUN.getStatus() == reserveEnum.getStatus()){
PlanDetail planDetail = PlanDetailOp.get();
planDetail.setStatus(Integer.parseInt(ContingencyPlanStatusEnum.SIMULATION_START.getCode()));
......@@ -67,4 +87,40 @@ public class ContingencyPlanServiceImpl implements ContingencyPlanService {
}
return reserveEnum.getText();
}
@Override
public ContingencyPlanParamVo equipmentScene(Long equipmentId) {
ContingencyPlanParamVo vo = null;
List<EquipmentFireEquipment> equipmentFireEquipmentList = equipmentFireEquipmentDao.findAllByEquipmentId(equipmentId);
if(equipmentFireEquipmentList.size()>0){
Optional<Equipment> equipmentOptional = equipmentDao.findById(equipmentFireEquipmentList.get(0).getEquipmentId());
if(equipmentOptional.get()!=null){
PlanEquipment planEquipment = planEquipmentDao.findByFireEquipmentId(equipmentOptional.get().getId());
if(planEquipment!=null){
vo =new ContingencyPlanParamVo();
vo.setPlanId(planEquipment.getPlanId().toString());
vo.setStatus(ContingencyPlanStatusEnum.ONGOING.getCode());
return vo;
}
}
}
return vo;
}
@Override
public Page recordListByPage(String planName, int pageNumber, int pageSize) {
Map<String,Object> params = new HashMap<>();
params.put("planName",planName);
params.put("pageNumber",pageNumber);
params.put("pageSize",pageSize);
List<HashMap<String,Object>> result = planOperationRecordMapper.PlanOperationRecordListByPage(params);
Integer count = planOperationRecordMapper.PlanOperationRecordListByCount(params);
Page page = new Page();
page.setRecords(result);
page.setTotal(count);
page.setSize(pageSize);
page.setPages(pageNumber);
return page;
}
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ import com.yeejoin.amos.fas.business.action.mq.WebMqttSubscribe;
import com.yeejoin.amos.fas.business.dao.mapper.*;
import com.yeejoin.amos.fas.business.dao.repository.IContingencyOriginalDataDao;
import com.yeejoin.amos.fas.business.dao.repository.IEvaluationModelDao;
import com.yeejoin.amos.fas.business.dao.repository.IPlanOperationRecordDao;
import com.yeejoin.amos.fas.business.dao.repository.IPreplanPictureDao;
import com.yeejoin.amos.fas.business.feign.RemoteSecurityService;
import com.yeejoin.amos.fas.business.param.AlarmParam;
......@@ -41,7 +42,6 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -118,7 +118,8 @@ public class HandlerMqttMessageImpl implements IEquipmentHandlerService {
@Value("${spring.application.name}")
private String serviceName;
@Autowired
private IPlanOperationRecordDao planOperationRecordDao;
@Override
public void handlerMqttMessage(String topic, String data) {
......@@ -137,7 +138,7 @@ public class HandlerMqttMessageImpl implements IEquipmentHandlerService {
if (EquipmentRiskTypeEnum.HZGJ.getCode().equals(equipmentSpecificIndex.getType())) {
log.info("(报警)Message type is: " + equipmentSpecificIndex.getType());
// 报警触发调用规则服务
executeDynamicPlan(deviceData, equipment, equipmentSpecific, toke);
executeDynamicPlan(deviceData, equipment, equipmentSpecific, toke,topicEntity.getRecordId());
} else if (EquipmentRiskTypeEnum.GZ.getCode().equals(equipmentSpecificIndex.getType())) {
// 设备故障处理逻辑
log.info("(故障)Message type is: " + equipmentSpecificIndex.getType());
......@@ -268,18 +269,18 @@ public class HandlerMqttMessageImpl implements IEquipmentHandlerService {
* @Date 2020/11/11 20:46
*/
@Async
void executeDynamicPlan(AlarmParam deviceData, Equipment equipment, EquipmentSpecificForRiskVo equipmentSpecific, Toke toke) {
void executeDynamicPlan(AlarmParam deviceData, Equipment equipment, EquipmentSpecificForRiskVo equipmentSpecific, Toke toke,String recordId) {
String batchNo = UUID.randomUUID().toString();
RequestContext.setToken(toke.getToke());
RequestContext.setProduct(toke.getProduct());
try {
alarmContingency(batchNo, equipmentSpecific, equipment);
alarmContingency(batchNo, equipmentSpecific, equipment,recordId);
} catch (Exception e) {
e.printStackTrace();
}
}
public void alarmContingency(String batchNo, EquipmentSpecificForRiskVo equipmentSpecific, Equipment equipment) throws Exception {
public void alarmContingency(String batchNo, EquipmentSpecificForRiskVo equipmentSpecific, Equipment equipment,String recordId) throws Exception {
Object oldContingencyRo = redisTemplate.opsForValue().get("contingencyRo");
ContingencyRo contingencyRo = new ContingencyRo();
contingencyRo.setBatchNo(batchNo);
......@@ -349,5 +350,14 @@ public class HandlerMqttMessageImpl implements IEquipmentHandlerService {
ContingencyOriginalData contingencyOriginalData = new ContingencyOriginalData();
BeanUtils.copyProperties(contingencyRo, contingencyOriginalData);
iContingencyOriginalDataDao.save(contingencyOriginalData);
//更新预案执行记录表的批次号
Optional<PlanOperationRecord> opt = planOperationRecordDao.findById(Long.valueOf(recordId));
PlanOperationRecord planOperationRecord =null;
if(opt.get()!=null){
planOperationRecord = opt.get();
planOperationRecord.setBatchNo(contingencyOriginalData.getBatchNo());
planOperationRecordDao.save(opt.get());
}
}
}
......@@ -950,7 +950,7 @@ public class RiskSourceServiceImpl implements IRiskSourceService {
@Override
@Transactional
public ReserveEnum startEquipReserve(Long id, String typeCode) {
public ReserveEnum startEquipReserve(Long id, String typeCode,Long recordId) {
int count = equipmentService.countByStatus(NumberEnum.ONE.getValue());
......@@ -965,6 +965,9 @@ public class RiskSourceServiceImpl implements IRiskSourceService {
TopicEntityVo topicEntity = new TopicEntityVo();
topicEntity.setMessage(JSON.toJSONString(equipmentSpecificIndexVo));
if(recordId!=null){
topicEntity.setRecordId(Long.valueOf(recordId).toString());
}
String data = JSON.toJSONString(topicEntity);
System.out.println(data);
......
package com.yeejoin.amos.fas.business.service.intfc;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.fas.business.vo.ContingencyPlanParamVo;
/**
......@@ -10,4 +11,8 @@ import com.yeejoin.amos.fas.business.vo.ContingencyPlanParamVo;
public interface ContingencyPlanService {
String planStart(ContingencyPlanParamVo vo);
ContingencyPlanParamVo equipmentScene(Long equipmentId);
Page recordListByPage (String planName, int pageNumber, int pageSize);
}
......@@ -29,7 +29,7 @@ public interface IRiskSourceService {
* 新增及维护风险点
*/
RiskSource editRiskSource(HashMap<String, Object> map) throws Exception;
/**
* 风险模型新增及维护时远程同步
*
......@@ -48,7 +48,7 @@ public interface IRiskSourceService {
*/
// String saveToEquipManage(String appKey, String product, String token, String success, long id,
// String code, String name, Long parentId);
/**
* 将本地 风险模型推送到远程同步
*
......@@ -65,8 +65,8 @@ public interface IRiskSourceService {
// String synToEquipManage(String appKey, String product, String token, String success, List<RiskSourceTreeResponse> riskSourcesTree);
/**
*
* 是否同步到对站系统
*
* 是否同步到对站系统
*
* @return boolean
* @throws <br>
......@@ -185,10 +185,10 @@ public interface IRiskSourceService {
void notifyFmeaFromDelete(Long handId, String from);
void notifyRiskSourceDelete(Long handId);
/**
*
* 不做任何不能删校验,直接删除,慎用
*
* 不做任何不能删校验,直接删除,慎用
*
* @param id void
* @throws <br>
......@@ -212,6 +212,6 @@ public interface IRiskSourceService {
* @return Boolean
*/
Boolean removeBind(Long instanceId);
ReserveEnum startEquipReserve(Long id, String typeCode);
ReserveEnum startEquipReserve(Long id, String typeCode,Long recordId);
}
......@@ -22,4 +22,6 @@ public class TopicEntityVo {
private String message;
private String type;
private String recordId;
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.amos.fas.business.dao.mapper.PlanOperationRecordMapper">
<select id="PlanOperationRecordListByPage" parameterType="hashmap" resultType="java.util.HashMap">
SELECT
record.batch_No AS batchNo,
detail.plan_name AS planName,
original.fire_Equipment_Name AS fireEquipmentName,
record.start_time AS startTime,
TIMESTAMPDIFF(second,record.start_time,record.end_time) as executionTime,
record.plan_pattern as planPattern,
'' AS executionType
FROM
`c_plan_operation_record` record
LEFT JOIN c_plan_detail detail ON detail.id = record.plan_id
LEFT JOIN contingency_original_data original ON original.batch_no = record.batch_no
<where>
<if test="planName !=null and planName != ''"> ( detail.plan_name like concat(concat("%",#{planName}),"%"))</if>
</where>
limit #{pageNumber} * #{pageSize},
</select>
<select id="PlanOperationRecordListByCount" parameterType="hashmap" resultType="java.lang.Integer">
SELECT
record.batch_No AS batchNo,
detail.plan_name AS planName,
original.fire_Equipment_Name AS fireEquipmentName,
record.start_time AS startTime,
TIMESTAMPDIFF(second,record.start_time,record.end_time) as executionTime,
record.plan_pattern as planPattern,
'' AS executionType
FROM
`c_plan_operation_record` record
LEFT JOIN c_plan_detail detail ON detail.id = record.plan_id
LEFT JOIN contingency_original_data original ON original.batch_no = record.batch_no
<where>
<if test="planName !=null and planName != ''"> ( detail.plan_name like concat(concat("%",#{planName}),"%"))</if>
</where>
limit #{pageNumber} * #{pageSize},
</select>
</mapper>
\ No newline at end of file
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