Commit 4fb23d57 authored by KeYong's avatar KeYong

优化预案流程

parent 95f60d8e
...@@ -771,6 +771,7 @@ public class ContingencyAction implements CustomerAction { ...@@ -771,6 +771,7 @@ public class ContingencyAction implements CustomerAction {
RequestContext.setProduct(toke.getProduct()); RequestContext.setProduct(toke.getProduct());
try { try {
iContingencyInstance.setButtonExecuted(contingencyRo.getBatchNo(), contingencyPlanInstance.getId(), buttonCode, "CONFIRM", null); iContingencyInstance.setButtonExecuted(contingencyRo.getBatchNo(), contingencyPlanInstance.getId(), buttonCode, "CONFIRM", null);
iContingencyInstance.fire(contingencyRo.getBatchNo(), stepCode, contingencyPlanInstance.getId(), buttonCode, "CONFIRM", stepState); iContingencyInstance.fire(contingencyRo.getBatchNo(), stepCode, contingencyPlanInstance.getId(), buttonCode, "CONFIRM", stepState);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
package com.yeejoin.amos.fas.business.controller; package com.yeejoin.amos.fas.business.controller;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
......
package com.yeejoin.amos.fas.business.controller; package com.yeejoin.amos.fas.business.controller;
import com.yeejoin.amos.fas.business.service.intfc.EquipmentSpecificIndexService; import com.yeejoin.amos.fas.business.service.intfc.EquipmentSpecificIndexService;
import com.yeejoin.amos.fas.config.Permission;
import com.yeejoin.amos.fas.core.util.CommonResponse; import com.yeejoin.amos.fas.core.util.CommonResponse;
import com.yeejoin.amos.fas.core.util.CommonResponseUtil; import com.yeejoin.amos.fas.core.util.CommonResponseUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import lombok.val;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
......
...@@ -2,7 +2,6 @@ package com.yeejoin.amos.fas.business.controller; ...@@ -2,7 +2,6 @@ package com.yeejoin.amos.fas.business.controller;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.yeejoin.amos.fas.business.dao.mapper.FireEquipPointMapper; import com.yeejoin.amos.fas.business.dao.mapper.FireEquipPointMapper;
import com.yeejoin.amos.fas.business.entity.mybatis.FireEquipmentPointEntity;
import com.yeejoin.amos.fas.business.service.intfc.IFireEquipPontService; import com.yeejoin.amos.fas.business.service.intfc.IFireEquipPontService;
import com.yeejoin.amos.fas.business.vo.ReginParams; import com.yeejoin.amos.fas.business.vo.ReginParams;
import com.yeejoin.amos.fas.config.Permission; import com.yeejoin.amos.fas.config.Permission;
...@@ -19,15 +18,12 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -19,15 +18,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
......
...@@ -6,7 +6,6 @@ import com.yeejoin.amos.fas.business.service.intfc.IFireCarService; ...@@ -6,7 +6,6 @@ import com.yeejoin.amos.fas.business.service.intfc.IFireCarService;
import com.yeejoin.amos.fas.business.service.intfc.IFireEquipService; import com.yeejoin.amos.fas.business.service.intfc.IFireEquipService;
//import com.yeejoin.amos.fas.business.service.intfc.IWaterResourceService; //import com.yeejoin.amos.fas.business.service.intfc.IWaterResourceService;
import com.yeejoin.amos.fas.business.util.CommonPageParamUtil; import com.yeejoin.amos.fas.business.util.CommonPageParamUtil;
import com.yeejoin.amos.fas.business.vo.ReginParams;
import com.yeejoin.amos.fas.config.Permission; import com.yeejoin.amos.fas.config.Permission;
import com.yeejoin.amos.fas.core.common.request.CommonPageable; import com.yeejoin.amos.fas.core.common.request.CommonPageable;
import com.yeejoin.amos.fas.core.common.request.CommonRequest; import com.yeejoin.amos.fas.core.common.request.CommonRequest;
...@@ -24,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -24,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
......
...@@ -4,14 +4,12 @@ import com.alibaba.fastjson.JSON; ...@@ -4,14 +4,12 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.component.feign.config.TokenOperation; import com.yeejoin.amos.component.feign.config.TokenOperation;
import com.yeejoin.amos.component.feign.model.FeignClientResult; import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.fas.business.feign.OutTokenLoginFeign;
import com.yeejoin.amos.fas.business.feign.PrivilegeFeign; import com.yeejoin.amos.fas.business.feign.PrivilegeFeign;
import com.yeejoin.amos.fas.business.feign.RemoteSecurityService; import com.yeejoin.amos.fas.business.feign.RemoteSecurityService;
import com.yeejoin.amos.fas.business.vo.CompanyBo; import com.yeejoin.amos.fas.business.vo.CompanyBo;
import com.yeejoin.amos.fas.business.vo.DepartmentBo; import com.yeejoin.amos.fas.business.vo.DepartmentBo;
import com.yeejoin.amos.fas.business.vo.ReginParams; import com.yeejoin.amos.fas.business.vo.ReginParams;
import com.yeejoin.amos.fas.business.vo.RoleBo; import com.yeejoin.amos.fas.business.vo.RoleBo;
import com.yeejoin.amos.fas.business.vo.Toke;
import com.yeejoin.amos.feign.privilege.Privilege; import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel; import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.privilege.model.ApplicationModel; import com.yeejoin.amos.feign.privilege.model.ApplicationModel;
...@@ -35,7 +33,6 @@ import org.springframework.web.context.request.ServletRequestAttributes; ...@@ -35,7 +33,6 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import org.typroject.tyboot.core.foundation.context.RequestContext; import org.typroject.tyboot.core.foundation.context.RequestContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
......
...@@ -20,21 +20,14 @@ import com.yeejoin.amos.feign.privilege.model.AgencyUserModel; ...@@ -20,21 +20,14 @@ import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import javafx.application.Application;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.context.RequestContextEntityType;
import java.applet.AppletContext;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
......
package com.yeejoin.amos.fas.business.event;
import com.yeejoin.amos.fas.business.vo.PlanExecuteVo;
import org.springframework.context.ApplicationEvent;
import org.typroject.tyboot.core.foundation.context.RequestContextModel;
/**
* @author keyong
* @title: ContingecyEvent
* <pre>
* @description: TODO
* </pre>
* @date 2023/4/4 16:31
*/
public class ContingecyExecEvent extends ApplicationEvent {
/**
* Create a new ApplicationEvent.
*
* @param source the object on which the event initially occurred (never {@code null})
*/
private String eventType;
private RequestContextModel context;
// 根据业务需要添加属性
private PlanExecuteVo planExecute;
public ContingecyExecEvent(Object source) {
super(source);
}
public String getEventType() {
return eventType;
}
public void setEventType(String eventType) {
this.eventType = eventType;
}
public PlanExecuteVo getPlanExecute() {
return planExecute;
}
public void setPlanExecute(PlanExecuteVo planExecute) {
this.planExecute = planExecute;
}
public RequestContextModel getContext() {
return context;
}
public void setContext(RequestContextModel context) {
this.context = context;
}
}
package com.yeejoin.amos.fas.business.event;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import java.util.List;
/**
* @author keyong
* @title: AsynEventListener
* <pre>
* @description: TODO
* </pre>
* @date 2023/4/4 16:34
*/
@Configuration
public class ContingercyAsyncEventListener implements ApplicationListener<ContingecyExecEvent> {
@Autowired
List<EventHandler> handlers;
@Override
@Async
public void onApplicationEvent(ContingecyExecEvent event) {
if (handlers == null) return;
RequestContext.setLoginId(event.getContext().getLoginId());
RequestContext.setToken(event.getContext().getToken());
RequestContext.setProduct(event.getContext().getProduct());
RequestContext.setAppKey(event.getContext().getAppKey());
RequestContext.setAgencyCode(event.getContext().getAgencyCode());
RequestContext.setExeUserId(event.getContext().getExcutedUserId());
for(EventHandler handler : handlers) {
if (handler.getEventType().equals(event.getEventType())) {
try {
handler.handler(event);
} catch (Exception e) {
e.printStackTrace();
}
}
}
RequestContext.clean();
}
}
package com.yeejoin.amos.fas.business.event;
/**
* @author keyong
* @title: EventHandler
* <pre>
* @description: TODO
* </pre>
* @date 2023/4/4 16:31
*/
public interface EventHandler {
public void handler(ContingecyExecEvent event) throws Exception;
public String getEventType();
}
package com.yeejoin.amos.fas.business.event;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author keyong
* @title: EventType
* <pre>
* @description: TODO
* </pre>
* @date 2023/4/4 16:33
*/
@Getter
@AllArgsConstructor
public enum EventType {
FIRE_NEXT_RULE("触发下一个预案", "FIRE_NEXT_RULE"),
UPDATE_CONTINGENCY_DATE("更新业务预案数据", "FIRE_NEXT_RULE");
private String name;
private String code;
}
package com.yeejoin.amos.fas.business.event;
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.*;
import com.yeejoin.amos.fas.business.dao.repository.IContingencyOriginalDataDao;
import com.yeejoin.amos.fas.business.service.intfc.*;
import com.yeejoin.amos.fas.business.vo.ContingencyInstanceInfoVO;
import com.yeejoin.amos.fas.dao.entity.ContingencyOriginalData;
import com.yeejoin.amos.fas.dao.entity.Equipment;
import org.apache.commons.lang3.ArrayUtils;
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.Component;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author keyong
* @title: FireContingencyHandler
* <pre>
* @description: TODO
* </pre>
* @date 2023/4/4 16:33
*/
@Component
public class FireContingencyHandler implements EventHandler{
private static final Logger log = LoggerFactory.getLogger(FireContingencyHandler.class);
@Autowired
IContingencyOriginalDataDao iContingencyOriginalDataDao;
@Autowired
private ImpAndFireEquipMapper impAndFireEquipMapper;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private ContingencyLogPublisher contingencyLogPublisher;
@Autowired
private PlanDetailMapper planDetailMapper;
@Autowired
IRocketMQService rocketMQService;
@Autowired
private ContingencyInstanceInfoService contingencyInstanceInfoService;
@Autowired
private RuleTrigger ruleTrigger;
@Autowired
ContingencyAction contingencyAction;
private static Map<String, String> stepMap = new HashMap<>();
@Value("${spring.application.name}")
private String serviceName;
@Value("${station.name}")
private String stationName;
@Override
public void handler(ContingecyExecEvent event) throws Exception {
/**
* TODO 只处理调用触发下次原,不错业务数据更新
*/
fire(event.getPlanExecute().getBatchNo(),
event.getPlanExecute().getStepCode(),
event.getPlanExecute().getContingencyPlanId(),
event.getPlanExecute().getButtonCode(),
event.getPlanExecute().getConfirm(),
event.getPlanExecute().getStepState());
}
@Override
public String getEventType() {
return EventType.FIRE_NEXT_RULE.name();
}
public void 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);
}
//使用原始数据触发规则
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);
ContingencyInstanceInfoVO infoVO = contingencyInstanceInfoService.selectDisposalDetails(batchNo);
if (!ObjectUtils.isEmpty(infoVO.getPosition())) {
contingencyOriginalData.setPosition(infoVO.getPosition());
}
BeanUtils.copyProperties(contingencyOriginalData, contingencyRo);
contingencyRo.setStep(stepCode);
contingencyRo.setStepState(stepMap.get(stepKey));
String isMock = redisTemplate.boundValueOps("isMock").get(0, -1);
if (isMock != null) {
contingencyRo.setIsMock("true".equals(isMock));
} else {
contingencyRo.setIsMock(false);
}
log.info("stepstate:" + contingencyRo.getStepState());
log.info("stepCode:" + stepCode);
equipment = impAndFireEquipMapper.queryImpEqumtByFireEquipmt(Long.parseLong(contingencyRo.getFireEquipmentId()));
if (equipment != null) {
contingencyRo.setEquipmentCode(equipment.getCode());
Map<String, Object> params = contingencyRo.getParams();
params.put("appKey", RequestContext.getAppKey());
params.put("product", RequestContext.getProduct());
params.put("token", RequestContext.getToken());
contingencyRo.setParams(params);
List<String> plan = this.getNumberPlan(Long.parseLong(contingencyRo.getEquipmentId()));
ruleTrigger.publish(contingencyRo, "换流站消防专项预案/" + plan.get(0), ArrayUtils.toArray(equipment.getName()));
}
iContingencyOriginalDataDao.updateByButton(
contingencyOriginalData.getConfirm(),
contingencyOriginalData.getRunstep(),
contingencyOriginalData.getStepState(),
batchNo
);
if (equipment != null) {
publisherPlanLog(stepCode, buttonCode, batchNo);
}
} else {
throw new Exception("数据异常,请联系管理员.");
}
return;
}
public List<String> getNumberPlan(Long id) {
List<String> ruleId = planDetailMapper.getRuleIdByEquipment(id);
return ruleId;
}
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);
}
}
package com.yeejoin.amos.fas.business.event;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* @author keyong
* @title: ListenerConfig
* <pre>
* @description: TODO
* </pre>
* @date 2023/4/4 18:26
*/
@Configuration
@EnableAsync
public class ListenerConfig {
// @Autowired
// ContingercyAsyncEventListener listener;
//
// public ContingercyAsyncEventListener applicationStartListener(){
// ContingercyAsyncEventListener listener = new ContingercyAsyncEventListener();
// return listener;
// }
// @Override
// public Executor getAsyncExecutor() {
// ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
// // 核心线程数
// taskExecutor.setCorePoolSize(2);
// // 最大线程数
// taskExecutor.setMaxPoolSize(10);
// // 队列大小
// taskExecutor.setQueueCapacity(15);
// // 线程名的前缀
// taskExecutor.setThreadNamePrefix("async-thread-");
// taskExecutor.initialize();
// return taskExecutor;
// }
// @Bean("applicationEventMulticaster")
// public SimpleApplicationEventMulticaster aimpleApplicationEventMulticaster(BeanFactory beanFactory, ThreadPoolExecutor threadPoolExecutor) {
// SimpleApplicationEventMulticaster s = new SimpleApplicationEventMulticaster(beanFactory);
// s.setTaskExecutor(new ThreadPoolExecutor());
// return s;
// }
}
package com.yeejoin.amos.fas.business.event;
import lombok.Data;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.context.RequestContextModel;
/**
* @author keyong
* @title: RequestContextHolder
* <pre>
* @description: TODO
* </pre>
* @date 2023/4/4 16:46
*/
@Data
public class RequestContextHolder {
private RequestContextModel context;
}
...@@ -13,15 +13,15 @@ import com.yeejoin.amos.fas.business.bo.FirePlanAlarmBo; ...@@ -13,15 +13,15 @@ import com.yeejoin.amos.fas.business.bo.FirePlanAlarmBo;
import com.yeejoin.amos.fas.business.dao.mapper.*; 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.IContingencyOriginalDataDao;
import com.yeejoin.amos.fas.business.dao.repository.IContingencyPlanInstanceRepository; import com.yeejoin.amos.fas.business.dao.repository.IContingencyPlanInstanceRepository;
import com.yeejoin.amos.fas.business.event.ContingecyExecEvent;
import com.yeejoin.amos.fas.business.event.EventHandler;
import com.yeejoin.amos.fas.business.event.EventType;
import com.yeejoin.amos.fas.business.feign.RemoteSecurityService; import com.yeejoin.amos.fas.business.feign.RemoteSecurityService;
import com.yeejoin.amos.fas.business.service.intfc.*; import com.yeejoin.amos.fas.business.service.intfc.*;
import com.yeejoin.amos.fas.business.service.model.Operate; import com.yeejoin.amos.fas.business.service.model.Operate;
import com.yeejoin.amos.fas.business.service.model.OperateGroup; import com.yeejoin.amos.fas.business.service.model.OperateGroup;
import com.yeejoin.amos.fas.business.util.DateUtils; import com.yeejoin.amos.fas.business.util.DateUtils;
import com.yeejoin.amos.fas.business.vo.ButtonJsonVO; import com.yeejoin.amos.fas.business.vo.*;
import com.yeejoin.amos.fas.business.vo.ContingencyInstanceInfoVO;
import com.yeejoin.amos.fas.business.vo.PlanStepJsonVO;
import com.yeejoin.amos.fas.business.vo.Toke;
import com.yeejoin.amos.fas.common.enums.PlanReplyMessageEnum; import com.yeejoin.amos.fas.common.enums.PlanReplyMessageEnum;
import com.yeejoin.amos.fas.dao.entity.ContingencyOriginalData; import com.yeejoin.amos.fas.dao.entity.ContingencyOriginalData;
import com.yeejoin.amos.fas.dao.entity.ContingencyPlanInstance; import com.yeejoin.amos.fas.dao.entity.ContingencyPlanInstance;
...@@ -38,8 +38,8 @@ import org.slf4j.LoggerFactory; ...@@ -38,8 +38,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -132,6 +132,9 @@ public class ContingencyInstanceImpl implements IContingencyInstance { ...@@ -132,6 +132,9 @@ public class ContingencyInstanceImpl implements IContingencyInstance {
@Autowired @Autowired
private PlanDetailMapper planDetailMapper; private PlanDetailMapper planDetailMapper;
@Autowired
private ApplicationEventPublisher applicationContext;
/** /**
* 创建预案执行记录 * 创建预案执行记录
* *
...@@ -217,9 +220,9 @@ public class ContingencyInstanceImpl implements IContingencyInstance { ...@@ -217,9 +220,9 @@ public class ContingencyInstanceImpl implements IContingencyInstance {
contingencyOriginalData.setStepState(contingencyOriginalData.getStepState() + stepStateOnbutton); contingencyOriginalData.setStepState(contingencyOriginalData.getStepState() + stepStateOnbutton);
//请求中的步骤小于以保存的步骤 //请求中的步骤小于以保存的步骤
if (Integer.parseInt(stepCode) < Integer.parseInt(contingencyOriginalData.getStep())) { // if (Integer.parseInt(stepCode) < Integer.parseInt(contingencyOriginalData.getStep())) {
contingencyOriginalData.setRunstep(true); // contingencyOriginalData.setRunstep(true);
} // }
if (Integer.parseInt(stepCode) > Integer.parseInt(contingencyOriginalData.getStep())) { if (Integer.parseInt(stepCode) > Integer.parseInt(contingencyOriginalData.getStep())) {
contingencyOriginalData.setStepState(stepStateOnbutton); contingencyOriginalData.setStepState(stepStateOnbutton);
...@@ -270,7 +273,7 @@ public class ContingencyInstanceImpl implements IContingencyInstance { ...@@ -270,7 +273,7 @@ public class ContingencyInstanceImpl implements IContingencyInstance {
contingencyRo.setParams(params); contingencyRo.setParams(params);
List<String> plan = this.getNumberPlan(Long.parseLong(contingencyRo.getEquipmentId())); List<String> plan = this.getNumberPlan(Long.parseLong(contingencyRo.getEquipmentId()));
// contingencyRo.setRunstep(false);
ruleTrigger.publish(contingencyRo, "换流站消防专项预案/" + plan.get(0), ArrayUtils.toArray(equipment.getName())); ruleTrigger.publish(contingencyRo, "换流站消防专项预案/" + plan.get(0), ArrayUtils.toArray(equipment.getName()));
publisherPlanLog(stepCode, buttonCode, batchNo); publisherPlanLog(stepCode, buttonCode, batchNo);
...@@ -429,31 +432,64 @@ public class ContingencyInstanceImpl implements IContingencyInstance { ...@@ -429,31 +432,64 @@ public class ContingencyInstanceImpl implements IContingencyInstance {
@Override @Override
public Optional<Equipment> fire(String batchNo, String stepCode, String buttonJson, String contingencyPlanId, String buttonCode, String buttonState, String stepStateOnbutton, String isExecute, String isAuto, String token, String product, String appKey,String startUserName) throws Exception { public Optional<Equipment> fire(String batchNo, String stepCode, String buttonJson, String contingencyPlanId, String buttonCode, String buttonState, String stepStateOnbutton, String isExecute, String isAuto, String token, String product, String appKey,String startUserName) throws Exception {
Map<String, String> map = new HashMap<>(); // Map<String, String> map = new HashMap<>();
map.put("batchNo", batchNo); // map.put("batchNo", batchNo);
map.put("stepCode", stepCode); // map.put("stepCode", stepCode);
map.put("buttonCode", buttonCode); // map.put("buttonCode", buttonCode);
map.put("confirm", buttonState); // map.put("confirm", buttonState);
map.put("contingencyPlanId", contingencyPlanId); // map.put("contingencyPlanId", contingencyPlanId);
map.put("stepState", stepStateOnbutton); // map.put("stepState", stepStateOnbutton);
// 是否执行 // // 是否执行
map.put("isExecute", isExecute); // map.put("isExecute", isExecute);
// 是否自动执行 // // 是否自动执行
map.put("isAuto", isAuto); // map.put("isAuto", isAuto);
if(startUserName != null) { // if(startUserName != null) {
map.put("startUserName", startUserName); // map.put("startUserName", startUserName);
} // }
map.put("buttonJson", buttonJson); // map.put("buttonJson", buttonJson);
map.put("appKey", RequestContext.getAppKey()); // map.put("appKey", RequestContext.getAppKey());
map.put("token", RequestContext.getToken()); // map.put("token", RequestContext.getToken());
map.put("product", RequestContext.getProduct()); // map.put("product", RequestContext.getProduct());
fireQueue.addLast(map);
PlanExecuteVo vo = new PlanExecuteVo();
vo.setConfirm(buttonState);
vo.setStepState(stepStateOnbutton);
vo.setBatchNo(batchNo);
vo.setStepCode(stepCode);
vo.setButtonCode(buttonCode);
vo.setContingencyPlanId(contingencyPlanId);
vo.setButtonJson(buttonJson);
vo.setIsAuto(isAuto);
vo.setIsExecute(isExecute);
ContingecyExecEvent fireEvent = new ContingecyExecEvent(this);
fireEvent.setEventType(EventType.FIRE_NEXT_RULE.name());
fireEvent.setPlanExecute(vo);
fireEvent.setContext(RequestContext.cloneRequestContext());
applicationContext.publishEvent(fireEvent);
ContingecyExecEvent updateEvent = new ContingecyExecEvent(this);
updateEvent.setEventType(EventType.UPDATE_CONTINGENCY_DATE.name());
updateEvent.setPlanExecute(vo);
updateEvent.setContext(RequestContext.cloneRequestContext());
// TODO 构建event对象,
try {
applicationContext.publishEvent(updateEvent);
} catch (Exception e) {
e.printStackTrace();
}
// 下面代码之后去掉。
// fireQueue.addLast(map);
//应急指挥给总部推送消息 //应急指挥给总部推送消息
// sendPlanAlarm(batchNo, buttonCode); // sendPlanAlarm(batchNo, buttonCode);
return Optional.empty(); return Optional.empty();
} }
@Autowired
List<EventHandler> handlers;
@Override @Override
public ContingencyPlanInstance updateExtendColumn(ContingencyPlanInstance contingencyPlanInstance) { public ContingencyPlanInstance updateExtendColumn(ContingencyPlanInstance contingencyPlanInstance) {
String recordType = contingencyPlanInstance.getRecordType(); String recordType = contingencyPlanInstance.getRecordType();
...@@ -534,7 +570,7 @@ public class ContingencyInstanceImpl implements IContingencyInstance { ...@@ -534,7 +570,7 @@ public class ContingencyInstanceImpl implements IContingencyInstance {
} }
@Scheduled(cron = "*/2 * * * * ?") // @Scheduled(cron = "*/2 * * * * ?")
public void runFireQueue() throws Exception { public void runFireQueue() throws Exception {
if (fireQueue.size() == 0) if (fireQueue.size() == 0)
...@@ -558,10 +594,11 @@ public class ContingencyInstanceImpl implements IContingencyInstance { ...@@ -558,10 +594,11 @@ public class ContingencyInstanceImpl implements IContingencyInstance {
RequestContext.setAppKey(appKey); RequestContext.setAppKey(appKey);
RequestContext.setProduct(product); RequestContext.setProduct(product);
RequestContext.setToken(token); RequestContext.setToken(token);
fire(batchNo, stepCode, contingencyPlanId, buttonCode, confirm, stepState);
// 更新redis中预案步骤数据 // 更新redis中预案步骤数据
planVisual3dService.updatePlanStepToRedis(batchNo, stepCode, buttonJson, contingencyPlanId, buttonCode, isExecute, isAuto); planVisual3dService.updatePlanStepToRedis(batchNo, stepCode, buttonJson, contingencyPlanId, buttonCode, isExecute, isAuto);
setButtonExecuted(batchNo, contingencyPlanId, buttonCode, confirm, user); setButtonExecuted(batchNo, contingencyPlanId, buttonCode, confirm, user);
fire(batchNo, stepCode, contingencyPlanId, buttonCode, confirm, stepState);
} catch (Exception e) { } catch (Exception e) {
throw e; throw e;
} finally { } finally {
......
...@@ -222,7 +222,9 @@ public class ContingencyPlanServiceImpl implements IContingencyPlanService { ...@@ -222,7 +222,9 @@ public class ContingencyPlanServiceImpl implements IContingencyPlanService {
boolean isMock = vo.getStatus() == 4; boolean isMock = vo.getStatus() == 4;
deviceData.setIsMock(isMock); deviceData.setIsMock(isMock);
redisTemplate.opsForValue().set("isMock", isMock ? "true" : "false"); redisTemplate.opsForValue().set("isMock", isMock ? "true" : "false");
String batchNo = equipmentHandlerService.executeDynamicPlan(deviceData, equipment, equipmentSpecific, toke, operationRecord.getId());
String batchNo = UUID.randomUUID().toString();
//更新模型状态 //更新模型状态
PlanDetail planDetail = PlanDetailOp.get(); PlanDetail planDetail = PlanDetailOp.get();
planDetail.setStatus(vo.getStatus()); planDetail.setStatus(vo.getStatus());
...@@ -243,7 +245,7 @@ public class ContingencyPlanServiceImpl implements IContingencyPlanService { ...@@ -243,7 +245,7 @@ public class ContingencyPlanServiceImpl implements IContingencyPlanService {
planOperationRecordDataSync(record); planOperationRecordDataSync(record);
result.setMessage(ReserveEnum.RUN.getText()); result.setMessage(ReserveEnum.RUN.getText());
result.setBatchNo(batchNo); result.setBatchNo(batchNo);
equipmentHandlerService.executeDynamicPlan(batchNo, deviceData, equipment, equipmentSpecific, toke, operationRecord.getId());
// String topic = String.format("/%s/%s/%s", serviceName, stationName, "plan"); // String topic = String.format("/%s/%s/%s", serviceName, stationName, "plan");
// Map<String, Object> map = new HashMap<>(); // Map<String, Object> map = new HashMap<>();
// JSONObject msgContext = new JSONObject(); // JSONObject msgContext = new JSONObject();
......
...@@ -48,6 +48,8 @@ import java.util.*; ...@@ -48,6 +48,8 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static java.lang.Thread.*;
/** /**
* @author keyong * @author keyong
* @title: HandlerMqttMessageImpl * @title: HandlerMqttMessageImpl
...@@ -521,13 +523,14 @@ public class HandlerMqttMessageImpl implements IEquipmentHandlerService { ...@@ -521,13 +523,14 @@ public class HandlerMqttMessageImpl implements IEquipmentHandlerService {
* @Author keyong * @Author keyong
* @Date 2020/11/11 20:46 * @Date 2020/11/11 20:46
*/ */
// @Async @Async
@Override @Override
public String executeDynamicPlan(AlarmParam deviceData, Equipment equipment, EquipmentSpecificForRiskVo equipmentSpecific, Toke toke, Long recordId) { public String executeDynamicPlan(String batchNo, AlarmParam deviceData, Equipment equipment, EquipmentSpecificForRiskVo equipmentSpecific, Toke toke, Long recordId) {
String batchNo = UUID.randomUUID().toString();
RequestContext.setToken(toke.getToke()); RequestContext.setToken(toke.getToke());
RequestContext.setProduct(toke.getProduct()); RequestContext.setProduct(toke.getProduct());
try { try {
sleep(1000);
alarmContingency(batchNo, equipmentSpecific, equipment, recordId, deviceData.getIsMock()); alarmContingency(batchNo, equipmentSpecific, equipment, recordId, deviceData.getIsMock());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -20,5 +20,5 @@ public interface IEquipmentHandlerService { ...@@ -20,5 +20,5 @@ public interface IEquipmentHandlerService {
void subscribeTopic(); void subscribeTopic();
String executeDynamicPlan(AlarmParam deviceData, Equipment equipment, EquipmentSpecificForRiskVo equipmentSpecific, Toke toke, Long recordId); String executeDynamicPlan(String batchNO, AlarmParam deviceData, Equipment equipment, EquipmentSpecificForRiskVo equipmentSpecific, Toke toke, Long recordId);
} }
...@@ -12,4 +12,6 @@ public class PlanExecuteVo { ...@@ -12,4 +12,6 @@ public class PlanExecuteVo {
private String confirm; private String confirm;
private String contingencyPlanId; private String contingencyPlanId;
private String stepState; private String stepState;
private String isAuto;
private String isExecute;
} }
...@@ -143,14 +143,14 @@ ...@@ -143,14 +143,14 @@
<when test = "outAndOr != null and outAndOr != '' and outAndOr == 'and'"> <when test = "outAndOr != null and outAndOr != '' and outAndOr == 'and'">
<if test="list != null and list.size() > 0"> <if test="list != null and list.size() > 0">
<foreach collection="list" item="item" index="index" open="(" close=")" separator="and"> <foreach collection="list" item="item" index="index" open="(" close=")" separator="and">
esi.equipment_index_key = #{item.equipSpeIndexKey} esi.equipment_index_key = #{item.equipSpeIndexKey} and esi.`value` = #{item.standardValue}
</foreach> </foreach>
</if> </if>
</when> </when>
<otherwise> <otherwise>
<if test="list != null and list.size() > 0"> <if test="list != null and list.size() > 0">
<foreach collection="list" item="item" index="index" open="(" close=")" separator="or"> <foreach collection="list" item="item" index="index" open="(" close=")" separator="or">
esi.equipment_index_key = #{item.equipSpeIndexKey} esi.equipment_index_key = #{item.equipSpeIndexKey} and esi.`value` = #{item.standardValue}
</foreach> </foreach>
</if> </if>
</otherwise> </otherwise>
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
"isParallel": "1", "isParallel": "1",
"roleCode": "Digital_Responsing_Plan_A", "roleCode": "Digital_Responsing_Plan_A",
"index": 0, "index": 0,
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "15", "stepCode": "15",
...@@ -17,7 +18,8 @@ ...@@ -17,7 +18,8 @@
"isParallel": "1", "isParallel": "1",
"roleCode": "Digital_Responsing_Plan_A", "roleCode": "Digital_Responsing_Plan_A",
"index": 1, "index": 1,
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "2", "stepCode": "2",
...@@ -27,7 +29,8 @@ ...@@ -27,7 +29,8 @@
"isParallel": "0", "isParallel": "0",
"roleCode": "Digital_Responsing_Plan_A", "roleCode": "Digital_Responsing_Plan_A",
"index": 2, "index": 2,
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "16", "stepCode": "16",
...@@ -49,7 +52,8 @@ ...@@ -49,7 +52,8 @@
} }
], ],
"outAndOr": "and", "outAndOr": "and",
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "3", "stepCode": "3",
...@@ -71,7 +75,8 @@ ...@@ -71,7 +75,8 @@
} }
], ],
"outAndOr": "and", "outAndOr": "and",
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "4", "stepCode": "4",
...@@ -93,7 +98,8 @@ ...@@ -93,7 +98,8 @@
} }
], ],
"outAndOr": "and", "outAndOr": "and",
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "7", "stepCode": "7",
...@@ -115,7 +121,8 @@ ...@@ -115,7 +121,8 @@
} }
], ],
"outAndOr": "and", "outAndOr": "and",
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "17", "stepCode": "17",
...@@ -137,7 +144,8 @@ ...@@ -137,7 +144,8 @@
} }
], ],
"outAndOr": "and", "outAndOr": "and",
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "18", "stepCode": "18",
...@@ -147,7 +155,8 @@ ...@@ -147,7 +155,8 @@
"isParallel": "0", "isParallel": "0",
"roleCode": "Digital_Responsing_Plan_B", "roleCode": "Digital_Responsing_Plan_B",
"index": 8, "index": 8,
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "19", "stepCode": "19",
...@@ -169,7 +178,8 @@ ...@@ -169,7 +178,8 @@
} }
], ],
"outAndOr": "and", "outAndOr": "and",
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "20", "stepCode": "20",
...@@ -191,7 +201,8 @@ ...@@ -191,7 +201,8 @@
} }
], ],
"outAndOr": "and", "outAndOr": "and",
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "6", "stepCode": "6",
...@@ -213,7 +224,8 @@ ...@@ -213,7 +224,8 @@
} }
], ],
"outAndOr": "and", "outAndOr": "and",
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "5", "stepCode": "5",
...@@ -223,7 +235,8 @@ ...@@ -223,7 +235,8 @@
"isParallel": "0", "isParallel": "0",
"roleCode": "Digital_Responsing_Plan_B", "roleCode": "Digital_Responsing_Plan_B",
"index": 12, "index": 12,
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "21", "stepCode": "21",
...@@ -245,7 +258,8 @@ ...@@ -245,7 +258,8 @@
} }
], ],
"outAndOr": "and", "outAndOr": "and",
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "22", "stepCode": "22",
...@@ -255,7 +269,8 @@ ...@@ -255,7 +269,8 @@
"isParallel": "1", "isParallel": "1",
"roleCode": "Digital_Responsing_Plan_B", "roleCode": "Digital_Responsing_Plan_B",
"index": 14, "index": 14,
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "8", "stepCode": "8",
...@@ -265,7 +280,8 @@ ...@@ -265,7 +280,8 @@
"isParallel": "0", "isParallel": "0",
"roleCode": "Digital_Responsing_Plan_B", "roleCode": "Digital_Responsing_Plan_B",
"index": 15, "index": 15,
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "13", "stepCode": "13",
...@@ -275,7 +291,8 @@ ...@@ -275,7 +291,8 @@
"isParallel": "0", "isParallel": "0",
"roleCode": "Digital_Responsing_Plan_B", "roleCode": "Digital_Responsing_Plan_B",
"index": 16, "index": 16,
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "23", "stepCode": "23",
...@@ -285,7 +302,8 @@ ...@@ -285,7 +302,8 @@
"isParallel": "0", "isParallel": "0",
"roleCode": "Digital_Responsing_Plan_B", "roleCode": "Digital_Responsing_Plan_B",
"index": 17, "index": 17,
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "24", "stepCode": "24",
...@@ -295,7 +313,8 @@ ...@@ -295,7 +313,8 @@
"isParallel": "0", "isParallel": "0",
"roleCode": "Digital_Responsing_Plan_B", "roleCode": "Digital_Responsing_Plan_B",
"index": 18, "index": 18,
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
}, },
{ {
"stepCode": "14", "stepCode": "14",
...@@ -305,6 +324,7 @@ ...@@ -305,6 +324,7 @@
"isParallel": "1", "isParallel": "1",
"roleCode": "Digital_Responsing_Plan_B", "roleCode": "Digital_Responsing_Plan_B",
"index": 19, "index": 19,
"isAuto": 0 "isAuto": 0,
"checkYesOrNo": ""
} }
] ]
\ 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