设备监控部分代码,日志监控修复排序

This commit is contained in:
lyd
2022-08-17 15:40:49 +08:00
parent 785bc93613
commit e17604b6d7
6 changed files with 146 additions and 12 deletions

View File

@@ -0,0 +1,22 @@
package org.nl.acs.monitor;
import com.alibaba.fastjson.JSONObject;
/**
* @Author: lyd
* @Description: 设备监控服务
* @Date: 2022-08-17
*/
public interface DeviceStageMonitor {
/**
* 根据设备获取设备状态(中文名:如故障、联机等)
* @return
*/
public JSONObject getDeviceStatusName();
/**
* 根据舞台数据修改设备驱动状态
* @param data
*/
public void setDeviceStatus(JSONObject data);
}

View File

@@ -0,0 +1,27 @@
package org.nl.acs.monitor.rest;
import com.alibaba.fastjson.JSONArray;
import io.swagger.annotations.ApiOperation;
import org.nl.annotation.Log;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
* @Author: lyd
* @Description:
* @Date: 2022-08-17
*/
public class DeviceStageMonitorController {
// @PostMapping("/getDeviceByCodes")
// @Log("获取舞台设备信息")
// @ApiOperation("获取舞台设备信息")
// public ResponseEntity<Object> getDeviceByCodes(@RequestBody String json) throws Exception{
// JSONArray jsonArray = JSONArray.parseArray(json);
// return new ResponseEntity<>(stageService.getDeviceByCodes(jsonArray), HttpStatus.OK);
// }
}

View File

@@ -0,0 +1,18 @@
package org.nl.acs.monitor.service;
import com.alibaba.fastjson.JSONArray;
/**
* @Author: lyd
* @Description: 取设备舞台监控数据
* @Date: 2022-08-17
*/
public interface DeviceStageMonitorService {
/**
* 取设备舞台监控数据
*
* @param jsonArray 前端传来设备编号和节点的id
* @return
*/
public JSONArray getData(JSONArray jsonArray);
}

View File

@@ -0,0 +1,54 @@
package org.nl.acs.monitor.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.monitor.DeviceStageMonitor;
import org.nl.acs.monitor.service.DeviceStageMonitorService;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
import org.springframework.stereotype.Service;
/**
* @Author: lyd
* @Description:
* @Date: 2022-08-17
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class DeviceStageMonitorServiceImpl implements DeviceStageMonitorService {
private final DeviceAppService deviceAppService;
@Override
public JSONArray getData(JSONArray jsonArray) {
JSONArray arr = new JSONArray();
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject obj = new JSONObject();
JSONObject js = jsonArray.getJSONObject(i);
String device_code = js.getString("device_code");
if (ObjectUtil.isEmpty(device_code)) continue;
Device device = deviceAppService.findDeviceByCode(device_code);
if (ObjectUtil.isNull(device)) continue;
JSONObject json = new JSONObject();
if (device.getDeviceDriver() instanceof DeviceStageMonitor) {
DeviceStageMonitor monitorService = (DeviceStageMonitor) device.getDeviceDriver();
json = monitorService.getDeviceStatusName();
}
obj.put("data", json);
obj.put("device_code", js.get("device_code"));
obj.put("id", js.getString("id")); // 设备不存在就只保留id方便前端查看
arr.add(obj);
}
return arr;
}
}

View File

@@ -139,15 +139,15 @@
<!-- <el-table-column prop="manufacturer" label="生产厂家" />-->
<!-- <el-table-column prop="manufacturer_phone" label="厂家电话" />-->
<el-table-column prop="remark" label="备注" />
<!-- <el-table-column label="操作" width="150px" align="center">-->
<!-- <template slot-scope="scope">-->
<!-- <el-button size="mini" style="margin-left: -1px;margin-right: 2px" type="text">-->
<!-- <router-link :to="'/devices/device/config/' + scope.row.device_code ">-->
<!-- 驱动配置-->
<!-- </router-link>-->
<!-- </el-button>-->
<!-- </template>-->
<!-- </el-table-column>-->
<!-- <el-table-column label="操作" width="150px" align="center">-->
<!-- <template slot-scope="scope">-->
<!-- <el-button size="mini" style="margin-left: -1px;margin-right: 2px" type="text">-->
<!-- <router-link :to="'/devices/device/config/' + scope.row.device_code ">-->
<!-- 驱动配置-->
<!-- </router-link>-->
<!-- </el-button>-->
<!-- </template>-->
<!-- </el-table-column>-->
<el-table-column v-permission="['admin','device:edit','device:del']" label="操作" width="200px" align="center">
<template slot-scope="scope">
<udOperation

View File

@@ -324,6 +324,12 @@ export default {
for (const k in this.logs) {
this.logs[k][1] = ansi_up.ansi_to_html(this.logs[k][1])
}
if (this.direction === 'backward') { // 由于使用公共标签会导致时间顺序错乱,因此对二维数组进行排序
this.logs.sort((a, b) => b[0] - a[0])
} else {
this.logs.sort((a, b) => a[0] - b[0])
}
console.log(this.logs)
} else {
this.showEmpty = true
this.emptyText = '暂无日志信息,请选择时间段试试'
@@ -351,9 +357,6 @@ export default {
const bottomest = Math.round(scrollTop + clientHeight)
if (bottomest === scrollHeight) {
// 加载新数据
// console.log(this.logs[this.logs.length - 1][0]) // 最后一个日志的时间
// console.log(queryParam.end - queryParam.start) // 时差
// 需要:最后一个日志时间, 时差 ---- 查询的时间范围:最后时间-时 - 差最后时间
queryParam.limits = this.scrollStep
queryParam.direction = this.direction
if (this.direction === 'backward') {
@@ -382,6 +385,11 @@ export default {
}
}
console.log(tempArray)
if (this.direction === 'backward') { // 由于使用公共标签会导致时间顺序错乱,因此对二维数组进行排序
tempArray.sort((a, b) => b[0] - a[0])
} else {
tempArray.sort((a, b) => a[0] - b[0])
}
for (const k in tempArray) {
tempArray[k][1] = ansi_up.ansi_to_html(tempArray[k][1]) // 数据转换
this.logs.push(tempArray[k]) // 追加数据
@@ -444,6 +452,11 @@ export default {
for (const k in this.logs) {
this.logs[k][1] = ansi_up.ansi_to_html(this.logs[k][1])
}
if (this.direction === 'backward') { // 由于使用公共标签会导致时间顺序错乱,因此对二维数组进行排序
this.logs.sort((a, b) => b[0] - a[0])
} else {
this.logs.sort((a, b) => a[0] - b[0])
}
} else {
this.showEmpty = true
this.emptyText = '暂无日志信息,请选择时间段试试'