Commit 640a10a8 authored by 田涛's avatar 田涛

数字预案绑定资源删除信息同步

parent e3d3fb78
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.service.intfc.IContingencyPlanService;
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 com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.fas.business.service.intfc.ContingencyPlanService;
import com.yeejoin.amos.fas.business.vo.PlanDetailVo;
import com.yeejoin.amos.fas.config.Permission;
import com.yeejoin.amos.fas.core.util.CommonResponseUtil2;
import com.yeejoin.amos.fas.core.util.ResponseModel;
import com.yeejoin.amos.fas.exception.YeeException;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import io.swagger.annotations.Api;
......@@ -18,10 +14,7 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Date;
......@@ -33,7 +26,7 @@ import java.util.List;
public class ContingencyPlanController extends BaseController {
@Autowired
private ContingencyPlanService contingencyPlanService;
private IContingencyPlanService contingencyPlanService;
/**
* 创建数字预案
......
......@@ -23,8 +23,5 @@ public interface PlanDocMapper {
*/
int updateIsDeleteByPlanIdList(@Param("planIdList") List<Long> idList, @Param("isDelete") Boolean isDelete);
/**
* 获取预案已使用的文档id
*/
Map<String, Long> getUsedDocId();
int logicDeleteByDocIdList(@Param("docIdList") List<Long> idList);
}
......@@ -22,4 +22,5 @@ public interface PlanEquipmentMapper {
*/
int updateIsDeleteByPlanIdList(@Param("planIdList") List<Long> idList, @Param("isDelete") Boolean isDelete);
int logicDeleteByEquipIdList(@Param("equipIdList") List<Long> idList);
}
......@@ -22,5 +22,6 @@ public interface PlanRuleMapper {
*/
int updateIsDeleteByPlanIdList(@Param("planIdList") List<Long> idList, @Param("isDelete") Boolean isDelete);
int logicDeleteByRuleIdList(@Param("ruleIdList") List<String> idList);
}
package com.yeejoin.amos.fas.business.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.component.rule.config.ClazzUtils;
import com.yeejoin.amos.fas.business.dao.mapper.*;
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.IContingencyPlanService;
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;
......@@ -15,21 +17,30 @@ import com.yeejoin.amos.fas.core.enums.ReserveEnum;
import com.yeejoin.amos.fas.dao.entity.*;
import com.yeejoin.amos.fas.exception.YeeException;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.paho.client.mqttv3.IMqttMessageListener;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.util.*;
/**
*@program: YeeAmosFireAutoSysRoot
*@description: 预案实现类
*@author: wujunkai
*@create: 2021-01-14 14:59
* @program: YeeAmosFireAutoSysRoot
* @description: 预案实现类
* @author: wujunkai
* @create: 2021-01-14 14:59
*/
@Service
public class ContingencyPlanServiceImpl implements ContingencyPlanService {
public class ContingencyPlanServiceImpl implements IContingencyPlanService {
private final Logger logger = LogManager.getLogger(ContingencyPlanServiceImpl.class);
@Autowired
private IEquipmentService equipmentService;
......@@ -39,7 +50,7 @@ public class ContingencyPlanServiceImpl implements ContingencyPlanService {
private IPlanOperationRecordDao planOperationRecordDao;
@Qualifier("IEquipmentFireEquipmentDao")
@Autowired
private IEquipmentFireEquipmentDao equipmentFireEquipmentDao;
private IEquipmentFireEquipmentDao equipmentFireEquipmentDao;
@Qualifier("iEquipmentDao")
@Autowired
private IEquipmentDao equipmentDao;
......@@ -54,12 +65,13 @@ public class ContingencyPlanServiceImpl implements ContingencyPlanService {
private final PlanEquipmentMapper planEquipmentMapper;
private final PlanRuleMapper planRuleMapper;
private final PlanDocMapper planDocMapper;
private final EmqKeeper emqKeeper;
@Autowired
public ContingencyPlanServiceImpl(IPlanDetailDao planDetailDao, IPlanDocDao planDocDao, IPlanEquipmentDao planEquipmentDao,
IPlanRuleDao planRuleDao, IPlanClassifyTreeDao classifyTreeDao, PlanDetailMapper planDetailMapper,
PlanEquipmentMapper planEquipmentMapper, PlanRuleMapper planRuleMapper, PlanDocMapper planDocMapper,
PlanOperationRecordMapper planOperationRecordMapper) {
PlanOperationRecordMapper planOperationRecordMapper, EmqKeeper emqKeeper) {
this.planDetailDao = planDetailDao;
this.planDocDao = planDocDao;
this.planEquipmentDao = planEquipmentDao;
......@@ -70,27 +82,28 @@ public class ContingencyPlanServiceImpl implements ContingencyPlanService {
this.planRuleMapper = planRuleMapper;
this.planDocMapper = planDocMapper;
this.planOperationRecordMapper = planOperationRecordMapper;
this.emqKeeper = emqKeeper;
}
@Override
public String planStart(ContingencyPlanParamVo vo){
ReserveEnum reserveEnum= null;
public String planStart(ContingencyPlanParamVo vo) {
ReserveEnum reserveEnum = null;
//模拟启动
if(ContingencyPlanStatusEnum.SIMULATION_START.getCode().equals(vo.getStatus())){
Integer[] statusArray = (Integer[]) Arrays.asList(ContingencyPlanStatusEnum.SIMULATION_START.getCode(),ContingencyPlanStatusEnum.ONGOING.getCode()).toArray();
int count =planDetailDao.findByStatus(statusArray);
if (ContingencyPlanStatusEnum.SIMULATION_START.getCode().equals(vo.getStatus())) {
Integer[] statusArray = (Integer[]) Arrays.asList(ContingencyPlanStatusEnum.SIMULATION_START.getCode(), ContingencyPlanStatusEnum.ONGOING.getCode()).toArray();
int count = planDetailDao.findByStatus(statusArray);
if (count > NumberEnum.ZERO.getValue()) {
return ReserveEnum.RUNNING.getText();
}
}else if(ContingencyPlanStatusEnum.ONGOING.getCode().equals(vo.getStatus())){
//自动启动
} else if (ContingencyPlanStatusEnum.ONGOING.getCode().equals(vo.getStatus())) {
//自动启动
Integer[] statusArray = (Integer[]) Arrays.asList(ContingencyPlanStatusEnum.ONGOING.getCode()).toArray();
int count =planDetailDao.findByStatus(statusArray);
int count = planDetailDao.findByStatus(statusArray);
if (count > NumberEnum.ZERO.getValue()) {
return ReserveEnum.RUNNING.getText();
}
}else {
} else {
return "预控启动状态不正确";
}
Optional<PlanDetail> PlanDetailOp = planDetailDao.findById(Long.valueOf(vo.getPlanId()));
......@@ -103,11 +116,11 @@ public class ContingencyPlanServiceImpl implements ContingencyPlanService {
planOperationRecord.setPlanPattern(vo.getStatus());
PlanOperationRecord result = planOperationRecordDao.save(planOperationRecord);
//预案启动
if(PlanDetailOp.get()!=null){
if (PlanDetailOp.get() != null) {
Equipment equipment = equipmentService.queryOne(PlanDetailOp.get().getId());
//预案启动
reserveEnum = riskSourceService.startEquipReserve(equipment.getId(),equipment.getCode(),result.getId());
if(ReserveEnum.RUN == reserveEnum){
reserveEnum = riskSourceService.startEquipReserve(equipment.getId(), equipment.getCode(), result.getId());
if (ReserveEnum.RUN == reserveEnum) {
PlanDetail planDetail = PlanDetailOp.get();
planDetail.setStatus(ContingencyPlanStatusEnum.SIMULATION_START.getCode());
planDetailDao.save(planDetail);
......@@ -119,13 +132,13 @@ public class ContingencyPlanServiceImpl implements ContingencyPlanService {
@Override
public ContingencyPlanParamVo equipmentScene(Long equipmentId) {
ContingencyPlanParamVo vo = null;
List<EquipmentFireEquipment> equipmentFireEquipmentList = equipmentFireEquipmentDao.findAllByEquipmentId(equipmentId);
if(equipmentFireEquipmentList.size()>0){
List<EquipmentFireEquipment> equipmentFireEquipmentList = equipmentFireEquipmentDao.findAllByEquipmentId(equipmentId);
if (equipmentFireEquipmentList.size() > 0) {
Equipment equipment = equipmentDao.findById(equipmentFireEquipmentList.get(0).getEquipmentId()).orElse(null);
if(equipment!=null){
if (equipment != null) {
PlanEquipment planEquipment = planEquipmentDao.findByFireEquipmentId(equipment.getId());
if(planEquipment!=null){
vo =new ContingencyPlanParamVo();
if (planEquipment != null) {
vo = new ContingencyPlanParamVo();
vo.setPlanId(planEquipment.getPlanId().toString());
vo.setStatus(ContingencyPlanStatusEnum.ONGOING.getCode());
return vo;
......@@ -137,12 +150,12 @@ public class ContingencyPlanServiceImpl implements ContingencyPlanService {
@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);
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);
......@@ -355,4 +368,56 @@ public class ContingencyPlanServiceImpl implements ContingencyPlanService {
}
return resMap;
}
@Override
public void subscribeTopic() {
try {
emqKeeper.getMqttClient().subscribe(DELETE_SYNC_PLAN_DOC, (s, mqttMessage) -> {
System.out.println(s);
byte[] payload = mqttMessage.getPayload();
try {
List<Long> ids = (List<Long>) ClazzUtils.deserializableObject(payload);
if (!ValidationUtil.isEmpty(ids)) {
planDocMapper.logicDeleteByDocIdList(ids);
}
} catch (Exception e) {
logger.error("预案文档删除同步出错", e);
}
});
} catch (MqttException e) {
logger.fatal("订阅文档删除同步消息失败,资源删除或取消无法同步", e);
}
try {
emqKeeper.getMqttClient().subscribe(DELETE_SYNC_PLAN_RULE, (s, mqttMessage) -> {
System.out.println(s);
byte[] payload = mqttMessage.getPayload();
try {
List<String> ids = (List<String>) ClazzUtils.deserializableObject(payload);
if (!ValidationUtil.isEmpty(ids)) {
planRuleMapper.logicDeleteByRuleIdList(ids);
}
} catch (Exception e) {
logger.error("预案规则删除同步出错", e);
}
});
} catch (MqttException e) {
logger.fatal("订阅规则删除同步消息失败,资源删除或取消无法同步", e);
}
try {
emqKeeper.getMqttClient().subscribe(DELETE_SYNC_PLAN_EQUIP, (s, mqttMessage) -> {
System.out.println(s);
byte[] payload = mqttMessage.getPayload();
try {
List<Long> ids = (List<Long>) ClazzUtils.deserializableObject(payload);
if (!ValidationUtil.isEmpty(ids)) {
planEquipmentMapper.logicDeleteByEquipIdList(ids);
}
} catch (Exception e) {
logger.error("预案保护对象删除同步出错", e);
}
});
} catch (MqttException e) {
logger.fatal("订阅保护对象删除同步消息失败,资源删除或取消无法同步", e);
}
}
}
\ No newline at end of file
......@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.fas.business.vo.PlanDetailVo;
import com.yeejoin.amos.fas.dao.entity.PlanDetail;
import com.yeejoin.amos.fas.exception.YeeException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
......@@ -18,7 +20,11 @@ import java.util.Map;
* @date 2021-01-14
* 预案操作
*/
public interface ContingencyPlanService {
public interface IContingencyPlanService {
String DELETE_SYNC_PLAN_DOC = "DELETE_SYNC_PLAN_DOC";
String DELETE_SYNC_PLAN_RULE = "DELETE_SYNC_PLAN_RULE";
String DELETE_SYNC_PLAN_EQUIP = "DELETE_SYNC_PLAN_EQUIP";
String planStart(ContingencyPlanParamVo vo);
......@@ -100,4 +106,9 @@ public interface ContingencyPlanService {
* @return
*/
Map<Long, Long> getPlanUsedEquipments();
/**
* 监听文档取消发布/规则、装备删除动态
*/
void subscribeTopic();
}
package com.yeejoin.amos.fas.config;
import com.yeejoin.amos.fas.business.service.intfc.IContingencyPlanService;
import com.yeejoin.amos.fas.business.service.intfc.IEquipmentHandlerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
......@@ -18,10 +19,13 @@ import org.springframework.stereotype.Component;
public class ApplicationRunnerImpl implements ApplicationRunner {
@Autowired
IEquipmentHandlerService equipmentHandlerService;
private IEquipmentHandlerService equipmentHandlerService;
@Autowired
private IContingencyPlanService contingencyPlanService;
@Override
public void run(ApplicationArguments args) throws Exception {
equipmentHandlerService.subscribeTopic();
contingencyPlanService.subscribeTopic();
}
}
......@@ -8,4 +8,11 @@
#{planId}
</foreach>
</update>
<update id="logicDeleteByDocIdList" parameterType="list">
UPDATE c_plan_doc SET is_delete = 1 WHERE doc_id IN
<foreach collection="docIdList" separator="," item="docId" open="(" close=")">
#{docId}
</foreach>
</update>
</mapper>
\ No newline at end of file
......@@ -8,4 +8,12 @@
#{planId}
</foreach>
</update>
<update id="logicDeleteByEquipIdList" parameterType="list">
UPDATE c_plan_equipment SET is_delete = 1 WHERE fire_equipment_id IN
<foreach collection="equipIdList" separator="," item="equipId" open="(" close=")">
#{equipId}
</foreach>
</update>
</mapper>
\ No newline at end of file
......@@ -8,4 +8,11 @@
#{planId}
</foreach>
</update>
<update id="logicDeleteByRuleIdList" parameterType="list">
UPDATE c_plan_rule SET is_delete = 1 WHERE rule_id IN
<foreach collection="ruleIdList" separator="," item="ruleId" open="(" close=")">
#{ruleId}
</foreach>
</update>
</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