Merge remote-tracking branch 'origin/master'

This commit is contained in:
zhangzhiqiang
2023-02-10 10:52:01 +08:00
2 changed files with 92 additions and 84 deletions

View File

@@ -6,7 +6,6 @@ import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.nl.acs.udw.UnifiedDataAccessor; import org.nl.acs.udw.UnifiedDataAccessor;
import org.nl.acs.udw.UnifiedDataAccessorFactory; import org.nl.acs.udw.UnifiedDataAccessorFactory;
import org.nl.modules.wql.util.SpringContextHolder;
import org.openscada.opc.lib.da.Group; import org.openscada.opc.lib.da.Group;
import org.openscada.opc.lib.da.Item; import org.openscada.opc.lib.da.Item;
import org.openscada.opc.lib.da.ItemState; import org.openscada.opc.lib.da.ItemState;
@@ -16,16 +15,11 @@ import java.util.*;
@Slf4j @Slf4j
public class DeviceOpcProtocolRunable implements Runnable { public class DeviceOpcProtocolRunable implements Runnable {
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class);
List<OpcItemDto> protocols; List<OpcItemDto> protocols;
OpcServerManageDto OpcServer; OpcServerManageDto OpcServer;
int error_num; int error_num;
String message; String message;
Group group;
public DeviceOpcProtocolRunable() { public DeviceOpcProtocolRunable() {
this.error_num = 0; this.error_num = 0;
this.message = null; this.message = null;
@@ -66,8 +60,8 @@ public class DeviceOpcProtocolRunable implements Runnable {
public void run() { public void run() {
while (true) { while (true) {
try { try {
group= opcServerService.getServer(this.OpcServer.getOpc_code()); Server server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
Group group = server.addGroup();
List<String> itemsString = new ArrayList(); List<String> itemsString = new ArrayList();
Iterator it = this.protocols.iterator(); Iterator it = this.protocols.iterator();
@@ -97,7 +91,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
} }
if (is_error) { if (is_error) {
log.info("设备OPC数据同步配置异常," + err_message); log.info("设备OPC数据同步配置异常");
} }
if (!OpcStartTag.is_run) { if (!OpcStartTag.is_run) {
@@ -109,30 +103,14 @@ public class DeviceOpcProtocolRunable implements Runnable {
if (this.OpcServer != null) { if (this.OpcServer != null) {
tag = tag + this.OpcServer.getOpc_code(); tag = tag + this.OpcServer.getOpc_code();
} }
UnifiedDataAccessor accessor_value = UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
boolean time_out = false; boolean time_out = false;
label97: label97:
while (true) { while (true) {
// System.out.println("label97");
long begin = System.currentTimeMillis(); long begin = System.currentTimeMillis();
Map<Item, ItemState> itemStatus =null; Map<Item, ItemState> itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
try{
itemStatus=group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
}catch (Exception e){
try{
itemStatus=group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
}catch (Exception e2){
itemStatus=group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
}
}
//TODO 读完释放server可行否?
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
log.trace("{} 开始记时{}", tag, DateUtil.now()); log.trace("{} 开始记时{}", tag, DateUtil.now());
long duration = end - begin; long duration = end - begin;
@@ -147,13 +125,11 @@ public class DeviceOpcProtocolRunable implements Runnable {
time_out = false; time_out = false;
} }
// A1_HK_04.A1_HK_04.A1_HK_04_3.door 列表
Set<Item> items = itemStatus.keySet(); Set<Item> items = itemStatus.keySet();
Iterator var18 = items.iterator(); Iterator var18 = items.iterator();
while (true) { while (true) {
Item item; Item item;
// A1_HK_04.A1_HK_04.A1_HK_04_3.door
//当前值 //当前值
Object value; Object value;
//旧的值 //旧的值
@@ -168,16 +144,14 @@ public class DeviceOpcProtocolRunable implements Runnable {
this.error_num = 0; this.error_num = 0;
this.message = null; this.message = null;
} }
// 所有信号读完并且没有变化的值
continue label97; continue label97;
} }
item = (Item) var18.next(); item = (Item) var18.next();
ItemState itemState = itemStatus.get(item); ItemState itemState = (ItemState) itemStatus.get(item);
value = OpcUtl.getValue(item, itemState); value = OpcUtl.getValue(item, itemState);
his = accessor_value.getValue(item.getId()); his = accessor_value.getValue(item.getId());
if (!ObjectUtil.equal(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) if (!ObjectUtil.equal(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
&& his != null) {
log.warn("opc 值不健康 item: {}, 状态: {}", item.getId(), itemState.getQuality()); log.warn("opc 值不健康 item: {}, 状态: {}", item.getId(), itemState.getQuality());
} }
} while (ObjectUtil.equal(value, his));//如果两次的值相等,不走下面的代码 } while (ObjectUtil.equal(value, his));//如果两次的值相等,不走下面的代码
@@ -196,24 +170,14 @@ public class DeviceOpcProtocolRunable implements Runnable {
} }
log.info("信号{}变更从{}->{};信号快照:{}", new Object[]{item.getId(), his, value, sb}); log.info("信号{}变更从{}->{};信号快照:{}", new Object[]{item.getId(), his, value, sb});
} }
//设置值 //设置值
accessor_value.setValue(item.getId(), value); accessor_value.setValue(item.getId(), value);
} }
} }
} catch (Exception var30) { } catch (Exception var30) {
if (group != null) {
try {
group.getServer().dispose();
group.clear();
group.remove();
} catch (Exception var6) {
}
this.group = null;
}
String error_message = "设备信息同步异常"; String error_message = "设备信息同步异常";
if (!StrUtil.equals(this.message, error_message)) { if (!StrUtil.equals(this.message, error_message)) {
log.warn("", var30); log.warn("", var30);
@@ -223,6 +187,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000)); Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000));
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
Thread.currentThread().interrupt();
} }
++this.error_num; ++this.error_num;
if (this.error_num > 3 && !StrUtil.equals(this.message, error_message)) { if (this.error_num > 3 && !StrUtil.equals(this.message, error_message)) {
@@ -232,4 +197,12 @@ public class DeviceOpcProtocolRunable implements Runnable {
} }
} }
} }
public static String formatDuring(long mss) {
long days = mss / 86400000L;
long hours = mss % 86400000L / 3600000L;
long minutes = mss % 3600000L / 60000L;
long seconds = mss % 60000L / 1000L;
return days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds ";
}
} }

View File

@@ -3,12 +3,19 @@
<div class="head-container"> <div class="head-container">
<!--工具栏--> <!--工具栏-->
<el-form :inline="true" class="demo-form-inline" label-suffix=":" label-width="90px"> <el-form :inline="true" class="demo-form-inline" label-suffix=":" label-width="90px">
<el-form-item label="日志标签"> <el-form-item label="日志级别">
<el-cascader <el-select
v-model="labelAndValue" v-model="logLevelValue"
:options="labelsOptions" style="width: 100px; height: 35px;top: -5px;"
placeholder="选择标签" placeholder="选择级别"
>
<el-option
v-for="item in labelsOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/> />
</el-select>
</el-form-item> </el-form-item>
<el-form-item label="关键字"> <el-form-item label="关键字">
<el-input <el-input
@@ -18,6 +25,34 @@
clearable clearable
/> />
</el-form-item> </el-form-item>
<el-form-item label="链路追踪">
<el-input
v-model="traceId"
size="mini"
placeholder="请输入链路id"
clearable
/>
</el-form-item>
<el-form-item label="SQL日志" prop="filterSql">
<el-switch
v-model="filterSql"
active-color="#409EFF"
inactive-color="#F56C6C"
active-value="1"
inactive-valu="0"
/>
</el-form-item>
<el-form-item label="HTTP日志" prop="isRequest">
<el-switch
v-model="isRequest"
active-color="#409EFF"
inactive-color="#F56C6C"
active-value="1"
inactive-valu="0"
/>
</el-form-item>
<el-form-item v-show="!showOptions" label="时间范围"> <el-form-item v-show="!showOptions" label="时间范围">
<el-date-picker <el-date-picker
v-model="timeRange" v-model="timeRange"
@@ -47,24 +82,6 @@
<span class="el-icon-sort" @click="changeShow" /> <span class="el-icon-sort" @click="changeShow" />
</el-tooltip> </el-tooltip>
</el-form-item> </el-form-item>
<el-form-item label="SQL日志" prop="filterSql">
<el-switch
v-model="filterSql"
active-color="#409EFF"
inactive-color="#F56C6C"
active-value="1"
inactive-valu="0"
/>
</el-form-item>
<el-form-item label="HTTP日志" prop="isRequest">
<el-switch
v-model="isRequest"
active-color="#409EFF"
inactive-color="#F56C6C"
active-value="1"
inactive-valu="0"
/>
</el-form-item>
<el-form-item label="显示条数"> <el-form-item label="显示条数">
<el-input-number <el-input-number
v-model="size" v-model="size"
@@ -117,8 +134,14 @@
<div style="width: 100%"> <div style="width: 100%">
<div v-for="(log, index) in logs" :key="index"> <div v-for="(log, index) in logs" :key="index">
<div> <div>
<span >{{log.system}}</span>
<span style="margin: 5px;">{{log.system}}---{{log.message}}</span> <span style="color: #13ce66">{{log.thread}}</span>
<span style="color: #00afff">{{log.logLevel}}</span>
<span>{{log.requestIp}}</span>
<span style="color: #b4bccc">{{log.requestTime}}</span>
<span style="color: chocolate">{{log.traceId}}</span>
<span style="color: #7a6df0">{{log.requestMethod}}</span>
<span style="margin: 5px;">-----{{log.message}}</span>
</div> </div>
</div> </div>
@@ -136,6 +159,7 @@ let queryParam = {
logLevel: null, logLevel: null,
startTime: null, startTime: null,
endTime: null, endTime: null,
traceId: null,
message: null, message: null,
filterSql: true, filterSql: true,
isRequest: true, isRequest: true,
@@ -146,10 +170,11 @@ export default {
name: 'ES', name: 'ES',
data() { data() {
return { return {
labelAndValue: [], // 搜索的值
labelsOptions: [], // 所有标签和对应所有值数据 labelsOptions: [], // 所有标签和对应所有值数据
logLevelValue: '',
timeRange: [], timeRange: [],
message: '', message: '',
traceId: '',
size: 20, size: 20,
logData: [], logData: [],
filterSql: '1', filterSql: '1',
@@ -222,20 +247,27 @@ export default {
methods: { methods: {
initLabelsValues() { initLabelsValues() {
logOperation.labelsValues().then(res => { logOperation.labelsValues().then(res => {
this.labelsOptions = res this.labelsOptions = res
}) })
}, },
queryData() { queryData() {
// 清空查询数据 // 清空查询数据
this.clearParam() this.clearParam()
queryParam.logLabel = this.labelAndValue[0] queryParam.logLevel = this.logLevelValue
const time = new Date() const time = new Date()
if (this.timeZoneValue !== '') { if (this.timeZoneValue !== '') {
queryParam.endTime = ((time.getTime() - this.timeZoneValue) * 1000000).toString() queryParam.startTime = new Date(((time.getTime() - this.timeZoneValue)))
}
debugger
if (this.timeRange !== '' && this.timeRange.length > 0) {
queryParam.startTime = this.timeRange[0]
queryParam.endTime = this.timeRange[1]
} }
queryParam.message = this.message.replace(/^\s*|\s*$/g, '') queryParam.message = this.message.replace(/^\s*|\s*$/g, '')
queryParam.filterSql = this.filterSql === '1' queryParam.filterSql = this.filterSql === '1'
queryParam.isRequest = this.filterSql === '1' queryParam.isRequest = this.filterSql === '1'
queryParam.traceId = this.traceId
queryParam.size = this.size queryParam.size = this.size
queryParam.page = this.page queryParam.page = this.page
@@ -247,14 +279,17 @@ export default {
this.logs.push(res.records[j]) this.logs.push(res.records[j])
} }
}) })
},
changetype() {
}, },
clearParam() { clearParam() {
queryParam = { queryParam = {
logLabel: null, logLevel: null,
logLabelValue: null,
startTime: null, startTime: null,
endTime: null, endTime: null,
message: null, message: null,
traceId: null,
isRequest: true, isRequest: true,
filterSql: true, filterSql: true,
size: 20 size: 20