Browse Source

设备管控增加记录到dc_oper_log中

develop
Mr.Wang 5 months ago
parent
commit
4d2bd2fbe4
  1. 2
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java
  2. 193
      zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java

2
zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java

@ -477,7 +477,7 @@ public class DcDeviceController extends BaseController {
}
private AjaxResult getAjaxResult(String deviceId, String functionId, HashMap<String, Object> props) {
public AjaxResult getAjaxResult(String deviceId, String functionId, HashMap<String, Object> props) {
if (!StringUtils.hasText(deviceId) || !StringUtils.hasText(functionId)) {
return AjaxResult.error("设备未接入");
}

193
zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java

@ -7,10 +7,16 @@ 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.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.ip.IpUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.service.ISysDeptService;
import com.zc.business.constant.DeviceFunctionIdConstants;
import com.zc.business.constant.DeviceTypeConstants;
import com.zc.business.controller.BroadcastController;
@ -19,10 +25,7 @@ import com.zc.business.domain.*;
import com.zc.business.enums.*;
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.business.service.IDcFacilityService;
import com.zc.business.service.*;
import com.zc.common.core.httpclient.exception.HttpException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -65,6 +68,12 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
@Autowired
private DcEventProcessServiceImpl dcEventProcessService;
@Resource
private IDcOperLogService iDcOperLogService;
@Resource
private ISysDeptService iSysDeptService;
/**
* 查询事件预案
@ -806,15 +815,37 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
List<DcDevice> dcDevices,
JSONObject otherConfig,
JSONArray resultArray) {
CountDownLatch latch = new CountDownLatch(dcDevices.size());
for (DcDevice device : dcDevices) {
threadPoolTaskExecutor.execute(() -> {
String iotDeviceId = "";
String functionId = "";
StringBuilder remark = new StringBuilder();
iotDeviceId = device.getIotDeviceId();
HashMap<String, Object> props = new HashMap<>();
// 构造设备控制记录数据格式
List<HashMap<String, List<Map<String,Object>>>> propsList = new ArrayList<>();
// 调用状态 0正常 1异常
Integer status = 0;
HashMap<String, List<Map<String,Object>>> proDevice = new HashMap<>();
// devices
List<Map<String,Object>> dev = new ArrayList<>();
Map<String,Object> deviceMap = new HashMap<>();
deviceMap.put("id",device.getId());
deviceMap.put("iotDeviceId",device.getIotDeviceId());
deviceMap.put("deviceType",device.getDeviceType());
dev.add(deviceMap);
proDevice.put("devices",dev);
// functions
List<Map<String,Object>> functionList = new ArrayList<>();
remark.append("在");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar calendar = Calendar.getInstance();
remark.append(dateFormat.format(calendar.getTime()));
remark.append("调用");
remark.append(device.getDeviceName());
try {
if (device.getDeviceType().equals(DeviceTypeConstants.DRIVING_GUIDANCE.toString())) {
// 行车诱导
@ -839,8 +870,19 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
}
result.put("device", device.getId());
result.put("deviceName",device.getDeviceName());
AjaxResult ajaxResult = dcDeviceController.invokedFunction(iotDeviceId, functionId, props);
processingDeviceParameters(functionId,functionList,props);
AjaxResult ajaxResult = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props);
// 将调用结果存入到 resultArray(操作结果) 中
if (ajaxResult.get("code").equals(200)) {
status = 0;
remark.append("成功");
}else {
status = 1;
remark.append("失败");
}
result.put("result", ajaxResult);
resultArray.add(result);
@ -851,13 +893,23 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
// 还原上次 恢复操作
props.put("fileId", "10");
functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_1B;
AjaxResult ajaxResult1B = dcDeviceController.invokedFunction(iotDeviceId, functionId, props);
processingDeviceParameters(functionId,functionList,props);
AjaxResult ajaxResult1B = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props);
JSONObject result = new JSONObject();
result.put("device", device.getId());
result.put("deviceName",device.getDeviceName());
result.put("content","还原上次");
result.put("result", ajaxResult1B);
resultArray.add(result);
if (ajaxResult1B.get("code").equals(200)) {
status = 0;
remark.append("成功");
}else {
status = 1;
remark.append("失败");
}
} else {
// 情报板发布全流程
JSONArray contentList = JSON.parseArray(otherConfig.get("contentList").toString());
@ -873,10 +925,17 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
errorResult.put("device",device.getId());
errorResult.put("content","未匹配到对应的模板内容");
resultArray.add(errorResult);
status = 1;
remark.append("失败");
}else {
JSONObject jsonObject = new JSONObject();
jsonObject.put("dcInfoBoardTemplate",foundContent);
boardReleaseProcess(props, iotDeviceId, jsonObject, device, resultArray);
status = boardReleaseProcess(props, iotDeviceId, jsonObject, device, resultArray, functionList);
if (status.equals(0)) {
remark.append("成功");
}else {
remark.append("失败");
}
}
}
@ -920,10 +979,21 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
result.put("device", device.getId());
result.put("deviceName",device.getDeviceName());
result.put("content",params.get("text"));
processingDeviceParameters("A1",functionList,props);
JSONObject returnResult = broadcastController.nearCamListDistance(params);
result.put("result", returnResult);
resultArray.add(result);
if (returnResult.get("retCode").equals("0")) {
status = 0;
remark.append("成功");
}else {
status = 1;
remark.append("失败");
}
}
else if (device.getDeviceType().equals(DeviceTypeConstants.LASER_FATIGUE_AWAKENING.toString())) {
@ -933,7 +1003,10 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
JSONObject resultTime = new JSONObject();
resultTime.put("device", device.getId());
resultTime.put("deviceName",device.getDeviceName());
AjaxResult ajaxResultState = dcDeviceController.invokedFunction(iotDeviceId, "SETMD", map);
processingDeviceParameters("SETMD",functionList,map);
AjaxResult ajaxResultState = dcDeviceController.getAjaxResult(iotDeviceId, "SETMD", map);
resultTime.put("resultState", ajaxResultState);
// 操作时长
@ -943,45 +1016,68 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
propsTime.put("SET", operationDuration);
functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_SETTM;
resultTime.put("content","状态:"+name+";操作时长"+otherConfig.get("operationDuration")+"分钟");
AjaxResult ajaxResult = dcDeviceController.invokedFunction(iotDeviceId, functionId, propsTime);
processingDeviceParameters(functionId,functionList,propsTime);
AjaxResult ajaxResult = dcDeviceController.getAjaxResult(iotDeviceId, functionId, propsTime);
resultTime.put("result", ajaxResult);
resultArray.add(resultTime);
if (ajaxResultState.get("code").equals(200) && ajaxResult.get("code").equals(200)) {
status = 0;
remark.append("成功");
}else {
status = 1;
remark.append("失败");
}
}
proDevice.put("functions",functionList);
propsList.add(proDevice);
insertEquipmentControlRecordTable(device,propsList,resultArray,status,remark.toString());
} catch (HttpException | IOException e) {
log.error(e.toString());
throw new RuntimeException(e);
} finally {
latch.countDown(); // 确保在异常情况下也能减少CountDownLatch计数
}
});
}
try {
latch.await(); // 等待所有线程执行完毕
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
/**
* 调用设备参数存储格式
*/
public void processingDeviceParameters(String functionId,
List<Map<String,Object>> functionList,
Object props) {
// 调用设备参数存储格式
Map<String,Object> functionMap = new HashMap<>();
functionMap.put("functionId",functionId);
functionMap.put("params",props);
functionList.add(functionMap);
}
/**
* 情报板发布全流程
*/
public void boardReleaseProcess(HashMap<String, Object> props,
public Integer boardReleaseProcess(HashMap<String, Object> props,
String iotDeviceId,
JSONObject otherConfig,
DcDevice device,
JSONArray resultArray
JSONArray resultArray,
List<Map<String,Object>> functionList
) throws HttpException, IOException {
String functionId = "";
Integer status = 0;
// 执行操作
// 可变信息标志 分三步
// 1:执行11功能码
functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_11;
props.put("fileName", "play011.lst");
props.put("size", "65535");
AjaxResult ajaxResult11 = dcDeviceController.invokedFunction(iotDeviceId, functionId, props);
processingDeviceParameters(functionId,functionList,props);
AjaxResult ajaxResult11 = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props);
if (ajaxResult11.get("code").equals(200)) {
// 2:执行13功能码
HashMap<String, Object> props11 = new HashMap<>();
@ -1012,7 +1108,10 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
parameters.put("formatStyle", dcInfoBoardTemplate.getFormatStyle());
list.add(parameters);
props11.put("parameters", list);
AjaxResult ajaxResult13 = dcDeviceController.invokedFunction(iotDeviceId, functionId, props11);
processingDeviceParameters(functionId,functionList,props11);
AjaxResult ajaxResult13 = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props11);
JSONObject result = new JSONObject();
result.put("device", device.getId());
result.put("deviceName",device.getDeviceName());
@ -1021,15 +1120,61 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
// 3: 执行1B功能码
functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_1B;
props1B.put("fileId", "11");
AjaxResult ajaxResult1B = dcDeviceController.invokedFunction(iotDeviceId, functionId, props1B);
processingDeviceParameters(functionId,functionList,props1B);
AjaxResult ajaxResult1B = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props1B);
if (ajaxResult1B.get("code").equals(200)) {
status = 0;
}else {
status = 1;
}
result.put("content",dcInfoBoardTemplate.getContent());
result.put("result", ajaxResult1B);
} else {
result.put("content","发布失败");
result.put("result", ajaxResult13);
status = 1;
}
resultArray.add(result);
}else {
status = 1;
}
return status;
}
/**
* 设备控制记录表插入
*/
public void insertEquipmentControlRecordTable(DcDevice dcDevice,
List<HashMap<String, List<Map<String,Object>>>> propsList,
JSONArray resultList,
Integer status,
String remark) {
DcOperLog dcOperLog = new DcOperLog();
List<String> deviceIds = new ArrayList<>();
deviceIds.add(dcDevice.getId().toString());
dcOperLog.setDcDeviceId(deviceIds.toString());
dcOperLog.setDcDeviceType(dcDevice.getDeviceType());
List<String> deviceNames = new ArrayList<>();
deviceNames.add(dcDevice.getDeviceName());
dcOperLog.setDcDeviceName(deviceNames.toString());
LoginUser loginUser = SecurityUtils.getLoginUser();
dcOperLog.setOperName(loginUser.getUsername());
SysDept sysDept = iSysDeptService.selectDeptById(SecurityUtils.getLoginUser().getDeptId());
dcOperLog.setDeptName(sysDept.getDeptName());
dcOperLog.setOperLocation(SecurityUtils.getLoginUser().getLoginLocation());
dcOperLog.setOperType("3");
dcOperLog.setOperIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
dcOperLog.setOperLocation(SecurityUtils.getLoginUser().getLoginLocation());
dcOperLog.setOperParam(JSON.toJSONString(propsList));
dcOperLog.setJsonResult(String.valueOf(resultList));
dcOperLog.setStatus(status);
dcOperLog.setOperTime(new Date());
dcOperLog.setRemark(remark);
iDcOperLogService.addDcOperLog(dcOperLog);
}

Loading…
Cancel
Save