|
|
@ -3,14 +3,22 @@ package com.zc.business.service.impl; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.fasterxml.jackson.core.type.TypeReference; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.ruoyi.common.core.domain.AjaxResult; |
|
|
|
import com.ruoyi.common.utils.DateUtils; |
|
|
|
import com.zc.business.constant.DeviceFunctionIdConstants; |
|
|
|
import com.zc.business.constant.DeviceTypeConstants; |
|
|
|
import com.zc.business.controller.DcDeviceController; |
|
|
|
import com.zc.business.domain.*; |
|
|
|
import com.zc.business.enums.EventTypeEnum; |
|
|
|
import com.zc.business.mapper.DcEmergencyPlansMapper; |
|
|
|
import com.zc.business.mapper.EventPlanAssocMapper; |
|
|
|
import com.zc.business.service.DcEmergencyPlansService; |
|
|
|
import com.zc.business.service.DcExecuteActionService; |
|
|
|
import com.zc.business.service.IDcDeviceService; |
|
|
|
import com.zc.common.core.httpclient.exception.HttpException; |
|
|
|
import org.apache.commons.lang3.StringEscapeUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -19,6 +27,8 @@ import javax.annotation.Resource; |
|
|
|
import javax.script.ScriptEngine; |
|
|
|
import javax.script.ScriptEngineManager; |
|
|
|
import javax.script.ScriptException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
@ -29,6 +39,12 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { |
|
|
|
private DcEmergencyPlansMapper dcEmergencyPlansMapper; |
|
|
|
@Resource |
|
|
|
private DcExecuteActionService dcExecuteActionService; |
|
|
|
@Resource |
|
|
|
private IDcDeviceService dcDeviceService; |
|
|
|
@Resource |
|
|
|
private DcDeviceController dcDeviceController; |
|
|
|
@Resource |
|
|
|
private EventPlanAssocMapper eventPlanAssocMapper; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@ -56,7 +72,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { |
|
|
|
/** |
|
|
|
* 根据事件类型查询事件预案 |
|
|
|
* |
|
|
|
* @param event 事件预案 |
|
|
|
* @param event 事件 |
|
|
|
* @return 结果 |
|
|
|
*/ |
|
|
|
@Override |
|
|
@ -208,6 +224,214 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 事件确定 |
|
|
|
* |
|
|
|
* @param dcEventAnDcEmergencyPlans 事件数据 和 事件预案数据 |
|
|
|
* @return 结果 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public int executionEventConfirmation(DcEventAnDcEmergencyPlans dcEventAnDcEmergencyPlans) { |
|
|
|
|
|
|
|
// 存储所有设备id
|
|
|
|
StringBuilder deviceIds = new StringBuilder(); |
|
|
|
// 存储所有设备的执行结果
|
|
|
|
JSONArray resultArray = new JSONArray(); |
|
|
|
|
|
|
|
// 获取事件数据
|
|
|
|
DcEvent dcEvent = dcEventAnDcEmergencyPlans.getDcEvent(); |
|
|
|
// 获取事件预案数据
|
|
|
|
DcEmergencyPlans dcEmergencyPlans = dcEventAnDcEmergencyPlans.getDcEmergencyPlans(); |
|
|
|
// 事件桩号
|
|
|
|
String[] markArray = dcEvent.getStakeMark().split("\\+"); |
|
|
|
if (markArray[1].length() < 3) { |
|
|
|
// 不足三位 补零
|
|
|
|
markArray[1] = String.format("%0" + 3 + "d", markArray[1]); |
|
|
|
} |
|
|
|
// 方向
|
|
|
|
String direction = dcEvent.getDirection(); |
|
|
|
|
|
|
|
//获取事件预案中的 执行操作配置
|
|
|
|
dcEmergencyPlans.getDcExecuteAction().stream() |
|
|
|
.forEach(dcExecuteAction -> { |
|
|
|
Integer searchRule = dcExecuteAction.getSearchRule(); |
|
|
|
List<String> start = new ArrayList<>(); |
|
|
|
List<String> end = new ArrayList<>(); |
|
|
|
// 设备列表
|
|
|
|
List<DcDevice> dcDevices = new ArrayList<>(); |
|
|
|
Map<String, Object> parameter = new HashMap<>(); |
|
|
|
parameter.put("deviceType", dcExecuteAction.getDeviceType()); |
|
|
|
// 根据不同的检索规则条件 获取设备
|
|
|
|
if (searchRule.equals(1)) { |
|
|
|
// 指定设备资源
|
|
|
|
// 根据设备id,获取设备集合
|
|
|
|
LambdaQueryWrapper<DcDevice> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
JSONObject otherConfig = JSON.parseObject(dcExecuteAction.getOtherConfig()); |
|
|
|
JSONArray deviceList = JSONArray.parseArray(otherConfig.get("deviceList").toString()); |
|
|
|
queryWrapper.in(DcDevice::getId, deviceList); |
|
|
|
dcDevices = dcDeviceService.list(queryWrapper); |
|
|
|
} else if (searchRule.equals(2)) { |
|
|
|
|
|
|
|
// 事件上游最近
|
|
|
|
if (direction.equals("1")) { |
|
|
|
// 上行 取最大的几个
|
|
|
|
start.add("55"); |
|
|
|
start.add("378.7"); |
|
|
|
end.add(markArray[0]); |
|
|
|
end.add(markArray[1]); |
|
|
|
parameter.put("startStakeMark", start); |
|
|
|
parameter.put("endStakeMark", end); |
|
|
|
dcDevices = dcDeviceService.devicePileNumberQueryDevice(parameter); |
|
|
|
dcDevices = dcDevices.subList(dcDevices.size() - dcExecuteAction.getNumber(), dcDevices.size()); |
|
|
|
} else { |
|
|
|
// 下行 取最小的几个
|
|
|
|
start.add(markArray[0]); |
|
|
|
start.add(markArray[1]); |
|
|
|
end.add("208"); |
|
|
|
end.add("153.4"); |
|
|
|
parameter.put("startStakeMark", start); |
|
|
|
parameter.put("endStakeMark", end); |
|
|
|
dcDevices = dcDeviceService.devicePileNumberQueryDevice(parameter); |
|
|
|
dcDevices = dcDevices.subList(0, dcExecuteAction.getNumber()); |
|
|
|
} |
|
|
|
|
|
|
|
// // 定义Comparator来比较DcDevice对象的stakeMark字段
|
|
|
|
// Comparator<DcDevice> comparator = Comparator.comparing(DcDevice::getStakeMark);
|
|
|
|
// // 对dcDevices进行升序排序
|
|
|
|
// Collections.sort(dcDevices, comparator);
|
|
|
|
// // 对dcDevices进行降序排序
|
|
|
|
// Collections.sort(dcDevices, comparator.reversed());
|
|
|
|
} else if (searchRule.equals(3)) { |
|
|
|
// 事件下游最近
|
|
|
|
if (direction.equals("1")) { |
|
|
|
// 上行 取最大的几个
|
|
|
|
start.add(markArray[0]); |
|
|
|
start.add(markArray[1]); |
|
|
|
end.add("208"); |
|
|
|
end.add("153.4"); |
|
|
|
parameter.put("startStakeMark", start); |
|
|
|
parameter.put("endStakeMark", end); |
|
|
|
dcDevices = dcDeviceService.devicePileNumberQueryDevice(parameter); |
|
|
|
dcDevices = dcDevices.subList(0, dcExecuteAction.getNumber()); |
|
|
|
|
|
|
|
} else { |
|
|
|
// 下行 取最小的几个
|
|
|
|
start.add("55"); |
|
|
|
start.add("378.7"); |
|
|
|
end.add(markArray[0]); |
|
|
|
end.add(markArray[1]); |
|
|
|
parameter.put("startStakeMark", start); |
|
|
|
parameter.put("endStakeMark", end); |
|
|
|
dcDevices = dcDeviceService.devicePileNumberQueryDevice(parameter); |
|
|
|
dcDevices = dcDevices.subList(dcDevices.size() - dcExecuteAction.getNumber(), dcDevices.size()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 最近公里数
|
|
|
|
Integer kilometers = Integer.parseInt(markArray[0].replaceAll("K", "")); |
|
|
|
// 根据事件桩号、公里数 计算出 桩号范围
|
|
|
|
start.add(String.valueOf(kilometers - dcExecuteAction.getNumber())); |
|
|
|
start.add(markArray[1]); |
|
|
|
end.add(String.valueOf(kilometers + dcExecuteAction.getNumber())); |
|
|
|
end.add(markArray[1]); |
|
|
|
// 构造查询条件
|
|
|
|
parameter.put("startStakeMark", start); |
|
|
|
parameter.put("endStakeMark", end); |
|
|
|
parameter.put("deviceType", dcExecuteAction.getDeviceType()); |
|
|
|
// 根据桩号范围,查询附近设备
|
|
|
|
dcDevices = dcDeviceService.devicePileNumberQueryDevice(parameter); |
|
|
|
} |
|
|
|
|
|
|
|
String deviceId = dcDevices.stream() |
|
|
|
.map(DcDevice::getId) |
|
|
|
.map(String::valueOf) |
|
|
|
.collect(Collectors.joining(",")); |
|
|
|
// 存储设备id 到 deviceIds 中
|
|
|
|
deviceIds.append(","); |
|
|
|
deviceIds.append(deviceId); |
|
|
|
|
|
|
|
try { |
|
|
|
// 根据不通设备类型,执行不通的功能操作
|
|
|
|
invokedFunction( |
|
|
|
dcDevices, |
|
|
|
JSON.parseObject(dcExecuteAction.getOtherConfig()), |
|
|
|
resultArray); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
// 创建一个 预案事件关联对象
|
|
|
|
EventPlanAssoc eventPlanAssoc = new EventPlanAssoc(); |
|
|
|
// 事件编号
|
|
|
|
eventPlanAssoc.setEventId(dcEvent.getId()); |
|
|
|
|
|
|
|
// 区分是执行操作 还是 恢复操作
|
|
|
|
if (dcEventAnDcEmergencyPlans.getOperationType().equals(1)) { |
|
|
|
// 事件预案编号
|
|
|
|
eventPlanAssoc.setEmergencyPlansId(dcEmergencyPlans.getId()); |
|
|
|
eventPlanAssoc.setExecutingControlDevice(deviceIds.toString().replaceFirst(",", "")); |
|
|
|
eventPlanAssoc.setExecutingControlResult(resultArray.toJSONString()); |
|
|
|
eventPlanAssoc.setCreateTime(DateUtils.getNowDate()); |
|
|
|
return eventPlanAssocMapper.insertEventPlanAssoc(eventPlanAssoc); |
|
|
|
} else { |
|
|
|
EventPlanAssoc selectEventPlanAssoc = eventPlanAssocMapper.selectByEventId(eventPlanAssoc); |
|
|
|
selectEventPlanAssoc.setUpdateTime(DateUtils.getNowDate()); |
|
|
|
selectEventPlanAssoc.setRecoveredControlDevice(deviceIds.toString().replaceFirst(",", "")); |
|
|
|
selectEventPlanAssoc.setRecoveredControlResult(resultArray.toJSONString()); |
|
|
|
return eventPlanAssocMapper.updateEventPlanAssoc(selectEventPlanAssoc); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据不通设备类型,执行不通的功能操作 |
|
|
|
*/ |
|
|
|
public void invokedFunction(List<DcDevice> dcDevices, JSONObject otherConfig, JSONArray resultArray) throws HttpException, IOException { |
|
|
|
String iotDeviceId = ""; |
|
|
|
String functionId = ""; |
|
|
|
HashMap<String, Object> props = new HashMap<>(); |
|
|
|
|
|
|
|
for (DcDevice device : dcDevices) { |
|
|
|
iotDeviceId = device.getIotDeviceId(); |
|
|
|
|
|
|
|
if (device.getDeviceType().equals(DeviceTypeConstants.DRIVING_GUIDANCE)) { |
|
|
|
// 行车诱导
|
|
|
|
functionId = DeviceFunctionIdConstants.DRIVING_GUIDANCE; |
|
|
|
// 控制模式 1-手动 2-自动 3-万年历
|
|
|
|
String controlModel = otherConfig.get("controlModel").toString(); |
|
|
|
props.put("onWorkStatus", otherConfig.get("state").toString()); |
|
|
|
props.put("inWorkStatus", otherConfig.get("state").toString()); |
|
|
|
if (controlModel.equals("1")) { |
|
|
|
props.put("mode", "00"); |
|
|
|
} else if (controlModel.equals("2")) { |
|
|
|
Date date = new Date(); |
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
String format = dateFormat.format(date); |
|
|
|
String[] times = otherConfig.get("time").toString().split("-"); |
|
|
|
props.put("mode", "01"); |
|
|
|
props.put("startDisplayTime", format + " " + times[0]); |
|
|
|
props.put("endDisplayTime", format + " " + times[1]); |
|
|
|
} else { |
|
|
|
props.put("mode", "02"); |
|
|
|
} |
|
|
|
|
|
|
|
} else if (device.getDeviceType().equals(DeviceTypeConstants.VARIABLE_INFORMATION_FLAG)) { |
|
|
|
// 可变信息标志
|
|
|
|
functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG; |
|
|
|
} else { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
AjaxResult ajaxResult = dcDeviceController.invokedFunction(iotDeviceId, functionId, props); |
|
|
|
// 将调用结果存入到 resultArray(操作结果) 中
|
|
|
|
JSONObject result = new JSONObject(); |
|
|
|
result.put("device", device.getId()); |
|
|
|
result.put("result", ajaxResult); |
|
|
|
resultArray.add(result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 新增事件预案 |
|
|
|
* |
|
|
|