Commit ca37a2ae authored by 高东东's avatar 高东东

*)添加预案回放退出工程

parent b90e5484
......@@ -575,14 +575,14 @@ public class ContingencyAction implements CustomerAction {
log.error("=======================================================================================");
stopSnapshop(contingencyRo);
instedParams(paramJSON, contingencyRo);
String parameter = instedParams(paramJSON, contingencyRo);
SafteyPlanResult result = new SafteyPlanResult();
Map<String, Object> tempmap1 = new HashMap<>();
tempmap1.put("key", actionName);
tempmap1.put("content",actionType);
tempmap1.put("parameter",paramJSON);
tempmap1.put("parameter",parameter);
result.add(tempmap1);
this.sendcmd("maparea", paramObj, result);
}
......
......@@ -96,7 +96,6 @@ public class TimeLineController extends BaseController{
}
@Permission
//@Authorization(ingore = true)
@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,
......@@ -104,6 +103,15 @@ public class TimeLineController extends BaseController{
ruleRunningSnapshotService.replayPlan(batchNo, randomNumber);
return CommonResponseUtil.success("SUCCESS");
}
@Permission
@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);
return CommonResponseUtil.success("SUCCESS");
}
@Scheduled(cron = "*/2 * * * * ?")
public void runFireQueue() throws Exception
......
package com.yeejoin.amos.fas.business.service.impl;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
......@@ -16,6 +18,7 @@ import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.typroject.tyboot.core.foundation.context.SpringContextHelper;
......@@ -23,10 +26,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.yeejoin.amos.fas.business.action.CustomerAction;
import com.yeejoin.amos.fas.business.action.model.ContingencyRo;
import com.yeejoin.amos.fas.business.action.mq.WebMqttComponent;
import com.yeejoin.amos.fas.business.action.result.ActionResult;
import com.yeejoin.amos.fas.business.action.result.SafteyPlanResult;
import com.yeejoin.amos.fas.business.action.result.message.AbstractActionResultMessage;
import com.yeejoin.amos.fas.business.dao.mapper.RuleRuningSnapshotMapper;
import com.yeejoin.amos.fas.business.dao.repository.IRuleRuningSnapshotDao;
import com.yeejoin.amos.fas.business.service.intfc.IRuleRunningSnapshotService;
import com.yeejoin.amos.fas.business.service.model.RuleRuningSnapshot;
import com.yeejoin.amos.fas.business.service.model.ToipResponse;
/**
*
......@@ -63,6 +70,8 @@ public class RuleRunigSnapshotServiceImpl
@Autowired
private WebMqttComponent webMqttComponent;
private static String PACKAGEURL = "com.yeejoin.amos.fas.business.action.result.message.";
static {
objectMapper = new ObjectMapper();
}
......@@ -151,13 +160,30 @@ public class RuleRunigSnapshotServiceImpl
{
logger.info("开始回放:batchNo="+batchNo);
logger.info("获取到动作记录个数:"+oldEntityList.size());
redisTemplate.opsForValue().set("replay:" + batchNo +":" + randomNumber, true);
int count = 0;
for(RuleRuningSnapshot snapshot : oldEntityList)
{
if(batchNo == null)
return ;
Object play = redisTemplate.opsForValue().get("replay:" + batchNo +":" + randomNumber);
if (ObjectUtils.isEmpty(play)) {
SafteyPlanResult result = new SafteyPlanResult();
Map<String, Object> tempmap1 = new HashMap<>();
tempmap1.put("type", "event");
tempmap1.put("content", "stopPlan");
result.add(tempmap1);
Constructor<?> constructor = Class.forName(
PACKAGEURL + result.getClass().getSimpleName() + "Message")
.getConstructor(ActionResult.class);
AbstractActionResultMessage<?> action = (AbstractActionResultMessage<?>) constructor.newInstance(result);
ToipResponse toipResponse = action.buildResponse("message", batchNo, result.toJson());
webMqttComponent.publish(String.format("%s/%s/%s", snapshot.getPackageId(), "replay", randomNumber), toipResponse.toJsonStr());
return;
}
//延迟
logger.info("开始执行第"+(++count)+"个动作.");
logger.info("方法名:"+snapshot.getMethodClass()+"."+snapshot.getMethodName());
......@@ -181,9 +207,16 @@ public class RuleRunigSnapshotServiceImpl
{
logger.info("回放失败.");
logger.error(e.getMessage(),e);
} finally {
redisTemplate.delete("replay:" + batchNo +":" + randomNumber);
}
}
@Override
public void exitReplayPlan(String batchNo, String randomNumber) {
redisTemplate.delete("replay:" + batchNo +":" + randomNumber);
}
@Async
public void replay(String batchNo) throws Exception
{
......@@ -281,4 +314,6 @@ public class RuleRunigSnapshotServiceImpl
public static void setReplayBatchNoToNull() {
RuleRunigSnapshotServiceImpl.replayBatchNo = null;
}
}
\ No newline at end of file
......@@ -17,4 +17,6 @@ public interface IRuleRunningSnapshotService
public void reacordPlan(String topic, String msgType, String msgBody, Object contingency);
public void replayPlan(String batchNo, String randomNumber) throws Exception;
void exitReplayPlan(String batchNo, String randomNumber);
}
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