From 2e9cce2284a6c0fce5fd5bc2bbb7bd2e16e8db09 Mon Sep 17 00:00:00 2001 From: zhangzhiqiang Date: Fri, 10 Feb 2023 14:38:10 +0800 Subject: [PATCH 1/6] =?UTF-8?q?add:=E7=94=9F=E4=BA=A7es=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lms/nladmin-system/pom.xml | 5 + .../main/java/org/nl/config/DruidFilter.java | 98 +++++++++++++++++++ .../nl/modules/logging/aspect/LogAspect.java | 9 +- .../META-INF/druid-filter.properties | 1 + .../main/resources/config/application-dev.yml | 25 ++--- .../resources/config/application-prod.yml | 21 ++-- 6 files changed, 132 insertions(+), 27 deletions(-) create mode 100644 lms/nladmin-system/src/main/java/org/nl/config/DruidFilter.java create mode 100644 lms/nladmin-system/src/main/resources/META-INF/druid-filter.properties diff --git a/lms/nladmin-system/pom.xml b/lms/nladmin-system/pom.xml index d823fcc49..506e552b6 100644 --- a/lms/nladmin-system/pom.xml +++ b/lms/nladmin-system/pom.xml @@ -452,6 +452,11 @@ easyexcel 2.2.6 + + mysql + mysql-connector-java + 8.0.20 + diff --git a/lms/nladmin-system/src/main/java/org/nl/config/DruidFilter.java b/lms/nladmin-system/src/main/java/org/nl/config/DruidFilter.java new file mode 100644 index 000000000..f885eafdf --- /dev/null +++ b/lms/nladmin-system/src/main/java/org/nl/config/DruidFilter.java @@ -0,0 +1,98 @@ +package org.nl.config; + +import com.alibaba.druid.filter.FilterChain; +import com.alibaba.druid.filter.FilterEventAdapter; +import com.alibaba.druid.proxy.jdbc.JdbcParameter; +import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy; +import com.alibaba.druid.proxy.jdbc.ResultSetProxy; +import com.alibaba.druid.proxy.jdbc.StatementProxy; +import com.alibaba.druid.sql.SQLUtils; +import com.alibaba.druid.util.JdbcUtils; +import com.alibaba.fastjson.JSON; +import com.mysql.cj.jdbc.result.ResultSetImpl; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.MDC; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +/* + * @author ZZQ + * @Date 2023/2/10 11:27 上午 + */ +@Slf4j +public class DruidFilter extends FilterEventAdapter { + + @Override + public int preparedStatement_executeUpdate(FilterChain chain, PreparedStatementProxy statement) throws SQLException { + + return super.preparedStatement_executeUpdate(chain, statement); + } + + @Override + public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql) throws SQLException { + + return super.statement_executeUpdate(chain, statement, sql); + } + + @Override + protected void statementExecuteAfter(StatementProxy statement, String sql, boolean result) { + String traceId = MDC.get("traceId"); + int size = statement.getParametersSize(); + String executeSql = sql; + int count = 0; + try { + count=statement.getUpdateCount(); + }catch (Exception ex){ } + if (StringUtils.isNotEmpty(traceId) && count>0) { + if (size > 0) { + Collection values = statement.getParameters().values(); + List params = new ArrayList<>(); + for (JdbcParameter value : values) { + params.add(value.getValue()); + } + executeSql = SQLUtils.format(executeSql, JdbcUtils.MYSQL, params); + } + log.info("[----SQL----][update][ SQL: {} ]", executeSql); + } + super.statementExecuteAfter(statement, sql, result); + } + @Override + public ResultSetProxy statement_getResultSet(FilterChain chain, StatementProxy statement) throws SQLException { + ResultSetProxy rs = super.statement_getResultSet(chain, statement); + String executeSql = statement.getLastExecuteSql(); + String traceId = MDC.get("traceId"); + if (StringUtils.isNotEmpty(traceId)){ + int result = 0; + if (rs != null) { + ResultSetImpl rss = rs.getResultSetRaw().unwrap(ResultSetImpl.class); + result = rss.getRows().size(); + } + try { + int size = statement.getParametersSize(); + if (size>0){ + Collection values = statement.getParameters().values(); + List params = new ArrayList<>(); + for (JdbcParameter value : values) { + params.add(value.getValue()); + } + executeSql = SQLUtils.format(executeSql, JdbcUtils.MYSQL, params); + } + }catch (Exception ex){ + log.warn("[-SQL解析异常-][{}]",ex.getMessage()); + } + log.info("[----SQL----][select][执行结果:{}][ SQL: {} ]",result, executeSql); + } + return rs; + } + + + + + +} diff --git a/lms/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java b/lms/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java index bdd69c14e..63a20d641 100644 --- a/lms/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java +++ b/lms/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java @@ -116,21 +116,20 @@ public class LogAspect { } } }catch (Exception ex){ - StringBuffer errorInfo = new StringBuffer(); - errorInfo.append(ex.getMessage()).append("\n"); + StringBuffer errorStack = new StringBuffer(); + String errorMsg = ex.getMessage(); int x = 0; StackTraceElement[] stackTrace = ex.getStackTrace(); if (stackTrace!=null && stackTrace.length>0){ - errorInfo.append("---堆栈信息:"); for (StackTraceElement stack : stackTrace) { x++; - errorInfo.append(stack.toString()).append("\n"); + errorStack.append(stack.toString()).append(" | "); if (x>10){ break; } } } - log.error("[--requestError--][请求接口:{}][请求参数:{}]【异常信息 :{}】", url,params, errorInfo.toString()); + log.error("[-requestError-][请求接口:{}]【异常信息:{}】[请求参数:{}][异常堆栈:{}]", url,errorMsg,params, errorStack.toString()); Log log = new Log("ERROR", System.currentTimeMillis() - comming); log.setExceptionDetail(ThrowableUtil.getStackTrace(ex).getBytes()); logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log); diff --git a/lms/nladmin-system/src/main/resources/META-INF/druid-filter.properties b/lms/nladmin-system/src/main/resources/META-INF/druid-filter.properties new file mode 100644 index 000000000..9b025c101 --- /dev/null +++ b/lms/nladmin-system/src/main/resources/META-INF/druid-filter.properties @@ -0,0 +1 @@ +druid.filters.DruidFilter=org.nl.config.DruidFilter diff --git a/lms/nladmin-system/src/main/resources/config/application-dev.yml b/lms/nladmin-system/src/main/resources/config/application-dev.yml index 94688b690..d267e00d8 100644 --- a/lms/nladmin-system/src/main/resources/config/application-dev.yml +++ b/lms/nladmin-system/src/main/resources/config/application-dev.yml @@ -23,10 +23,10 @@ spring: db-type: com.alibaba.druid.pool.DruidDataSource driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy # url: jdbc:log4jdbc:mysql://${DB_HOST:10.1.3.91}:${DB_PORT:3306}/${DB_NAME:lms_test2}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true - url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:hl_tb_lms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true + url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:lms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true # username: ${DB_USER:root} username: ${DB_USER:root} - password: ${DB_PWD:Root.123456} + password: ${DB_PWD:942464Yy} # 初始连接数 initial-size: 5 # 最小连接数 @@ -58,16 +58,17 @@ spring: enabled: true url-pattern: /druid/* reset-enable: false - filter: - stat: - enabled: true - # 记录慢SQL - log-slow-sql: true - slow-sql-millis: 1000 - merge-sql: true - wall: - config: - multi-statement-allow: true + filters: + DruidFilter,stat +# stat: +# enabled: true +# # 记录慢SQL +# log-slow-sql: true +# slow-sql-millis: 1000 +# merge-sql: true +# wall: +# config: +# multi-statement-allow: true redis: #数据库索引 database: ${REDIS_DB:15} diff --git a/lms/nladmin-system/src/main/resources/config/application-prod.yml b/lms/nladmin-system/src/main/resources/config/application-prod.yml index 385fb963e..6bb7eed6e 100644 --- a/lms/nladmin-system/src/main/resources/config/application-prod.yml +++ b/lms/nladmin-system/src/main/resources/config/application-prod.yml @@ -59,16 +59,17 @@ spring: enabled: true url-pattern: /druid/* reset-enable: false - filter: - stat: - enabled: true - # 记录慢SQL - log-slow-sql: true - slow-sql-millis: 1000 - merge-sql: true - wall: - config: - multi-statement-allow: true + filters: + DruidFilter,stat +# stat: +# enabled: true +# # 记录慢SQL +# log-slow-sql: true +# slow-sql-millis: 1000 +# merge-sql: true +# wall: +# config: +# multi-statement-allow: true redis: #数据库索引 database: ${REDIS_DB:14} From 12ea57f8f3af57e3d3295b451ebd50cb91a3ae66 Mon Sep 17 00:00:00 2001 From: zhangzhiqiang Date: Fri, 10 Feb 2023 17:05:39 +0800 Subject: [PATCH 2/6] a --- .../modules/logging/rest/EsLogController.java | 6 +-- .../modules/logging/service/EsLogService.java | 2 +- .../modules/logging/service/dto/LogQuery.java | 4 ++ .../service/impl/EsLogServiceImpl.java | 38 ++++++++++++++++--- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/lms/nladmin-system/src/main/java/org/nl/modules/logging/rest/EsLogController.java b/lms/nladmin-system/src/main/java/org/nl/modules/logging/rest/EsLogController.java index c2e3fe096..bc9f8b9b5 100644 --- a/lms/nladmin-system/src/main/java/org/nl/modules/logging/rest/EsLogController.java +++ b/lms/nladmin-system/src/main/java/org/nl/modules/logging/rest/EsLogController.java @@ -23,10 +23,10 @@ public class EsLogController { private final EsLogService esLogService; - @GetMapping("/labels") + @GetMapping("/labels/{type}") @ApiOperation("获取标签") - public ResponseEntity labelsValues() { - return new ResponseEntity<>(esLogService.getLabelsValues(), HttpStatus.OK); + public ResponseEntity labelsValues(@PathVariable String type) { + return new ResponseEntity<>(esLogService.getLabelsValues(type), HttpStatus.OK); } @PostMapping("/query") diff --git a/lms/nladmin-system/src/main/java/org/nl/modules/logging/service/EsLogService.java b/lms/nladmin-system/src/main/java/org/nl/modules/logging/service/EsLogService.java index 04a6dcd59..1a7d2c79a 100644 --- a/lms/nladmin-system/src/main/java/org/nl/modules/logging/service/EsLogService.java +++ b/lms/nladmin-system/src/main/java/org/nl/modules/logging/service/EsLogService.java @@ -16,7 +16,7 @@ public interface EsLogService { * 获取labels和values树 * @return */ - JSONArray getLabelsValues(); + JSONArray getLabelsValues(String type); /** * 日志查询 diff --git a/lms/nladmin-system/src/main/java/org/nl/modules/logging/service/dto/LogQuery.java b/lms/nladmin-system/src/main/java/org/nl/modules/logging/service/dto/LogQuery.java index bc006286d..e5e1d8a66 100644 --- a/lms/nladmin-system/src/main/java/org/nl/modules/logging/service/dto/LogQuery.java +++ b/lms/nladmin-system/src/main/java/org/nl/modules/logging/service/dto/LogQuery.java @@ -27,6 +27,10 @@ public class LogQuery { * 日志级别 */ private String logLevel; + /** + * 系统标签 + */ + private String system; /** * 是否只查询Http相关请求 */ diff --git a/lms/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/EsLogServiceImpl.java b/lms/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/EsLogServiceImpl.java index 9d6ccdd38..773810291 100644 --- a/lms/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/EsLogServiceImpl.java +++ b/lms/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/EsLogServiceImpl.java @@ -8,9 +8,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.formula.functions.T; +import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.script.Script; +import org.elasticsearch.search.aggregations.AggregationBuilders; +import org.elasticsearch.search.aggregations.Aggregations; +import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.nl.common.domain.query.PageQuery; import org.nl.common.enums.LevelEnum; import org.nl.modules.logging.repository.EsLogRepository; @@ -21,12 +25,19 @@ import org.nl.wms.ext.acs.service.impl.AcsToWmsServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; +import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl; +import org.springframework.data.elasticsearch.core.query.FetchSourceFilter; +import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.function.Consumer; +import java.util.function.Function; /** * @author ldjun @@ -40,6 +51,8 @@ public class EsLogServiceImpl implements EsLogService { private final EsLogRepository esLogRepository; + private final ElasticsearchRestTemplate elasticsearchRestTemplate; + @Override public Page query(LogQuery logQuery){ Page page = new Page<>(); @@ -60,6 +73,9 @@ public class EsLogServiceImpl implements EsLogService { if (StringUtils.isNotEmpty(logQuery.getLogLevel())){ query.must().add(QueryBuilders.matchQuery("logLevel", LevelEnum.checkLevel(logQuery.getLogLevel()))); } + if (StringUtils.isNotEmpty(logQuery.getSystem())){ + query.must().add(QueryBuilders.matchQuery("system", logQuery.getSystem())); + } if (logQuery.getIsRequest()){ query.must().add(QueryBuilders.existsQuery("requestMethod")); } @@ -86,13 +102,23 @@ public class EsLogServiceImpl implements EsLogService { @Override - public JSONArray getLabelsValues() { + public JSONArray getLabelsValues(String type) { JSONArray result = new JSONArray(); - for (LevelEnum value : LevelEnum.values()) { - JSONObject level = new JSONObject(); - level.put("label", value.name()); - level.put("value", value.name()); - result.add(level); + FetchSourceFilter fetchSourceFilter = new FetchSourceFilter(new String[]{type}, null); + NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder(); + queryBuilder.withCollapseField(type+".keyword"); + queryBuilder.withSourceFilter(fetchSourceFilter); + queryBuilder.addAggregation(AggregationBuilders.terms(type).field(type+".keyword").size(100)); + Aggregations agg = elasticsearchRestTemplate.query(queryBuilder.build(), SearchResponse::getAggregations); + Terms terms = agg.get(type); + List buckets = terms.getBuckets(); + if (!CollectionUtils.isEmpty(buckets)){ + buckets.stream().map(Terms.Bucket::getKeyAsString).forEach(v-> { + JSONObject item = new JSONObject(); + item.put("label", v); + item.put("value", v); + result.add(item); + }); } return result; } From 5b97d381dca08b407db8ea5340ad2ea7ee9bb744 Mon Sep 17 00:00:00 2001 From: zhangzhiqiang Date: Fri, 10 Feb 2023 17:06:27 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lms/nladmin-ui/src/views/loki/api/loki.js | 4 +- lms/nladmin-ui/src/views/loki/view/index.vue | 46 +++++++++++++++----- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/lms/nladmin-ui/src/views/loki/api/loki.js b/lms/nladmin-ui/src/views/loki/api/loki.js index a1da580e3..b5a309420 100644 --- a/lms/nladmin-ui/src/views/loki/api/loki.js +++ b/lms/nladmin-ui/src/views/loki/api/loki.js @@ -8,9 +8,9 @@ export function getLogData(param) { }) } -export function labelsValues() { +export function labelsValues(type) { return request({ - url: '/api/esLog/labels', + url: '/api/esLog/labels/' + type, method: 'get' }) } diff --git a/lms/nladmin-ui/src/views/loki/view/index.vue b/lms/nladmin-ui/src/views/loki/view/index.vue index 2a7111615..65b239c40 100644 --- a/lms/nladmin-ui/src/views/loki/view/index.vue +++ b/lms/nladmin-ui/src/views/loki/view/index.vue @@ -3,12 +3,27 @@
- + + + + + + @@ -135,16 +150,15 @@
- {{ log.system }} + {{ log.system }} {{ log.thread }} {{ log.logLevel }} {{ log.requestIp }} - {{ log.requestTime }} + {{ log.requestTime }} {{ log.traceId }} {{ log.requestMethod }} -----{{ log.message }}
-
@@ -158,6 +172,7 @@ import logOperation from '@/views/loki/api/loki' let queryParam = { logLevel: null, + system: null, startTime: null, endTime: null, traceId: null, @@ -172,7 +187,9 @@ export default { data() { return { labelsOptions: [], // 所有标签和对应所有值数据 + systemOptions: [], // 所有标签和对应所有值数据 logLevelValue: '', + system: '', timeRange: [], message: '', traceId: '', @@ -243,7 +260,8 @@ export default { } }, created() { - this.initLabelsValues() + this.initLabelsValues('logLevel') + this.initLabelsValues('system') }, methods: { fontType(level) { @@ -258,9 +276,14 @@ export default { } return { 'color': '#a74dc6' } }, - initLabelsValues() { - logOperation.labelsValues().then(res => { - this.labelsOptions = res + initLabelsValues(type) { + logOperation.labelsValues(type).then(res => { + if (type === 'logLevel') { + this.labelsOptions = res + } + if (type === 'system') { + this.systemOptions = res + } }) }, queryData() { @@ -281,6 +304,7 @@ export default { queryParam.traceId = this.traceId queryParam.size = this.size queryParam.page = this.page + queryParam.system = this.system logOperation.getLogData(queryParam).then(res => { this.showEmpty = false From 60df5d317e8a92afccdbe14dd97b1d10ec2d89fa Mon Sep 17 00:00:00 2001 From: "USER-20220102CG\\noblelift" <546428999@qq.com> Date: Fri, 10 Feb 2023 17:25:45 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HongXiangConveyorDeviceDriver.java | 10 ++- .../hongxiang_device/ItemProtocol.java | 4 + .../wms/service/impl/WmsToAcsServiceImpl.java | 4 +- .../org/nl/acs/opc/DeviceExecuteAutoRun.java | 2 +- .../nl/acs/opc/DeviceManageServiceImpl.java | 8 +- .../nl/acs/opc/DeviceOpcProtocolRunable.java | 21 ++++- .../main/java/org/nl/acs/opc/ObjectUtl.java | 78 +++++++++++++++++++ .../acs/opc/opcServerManageServiceImpl.java | 2 +- .../src/views/acs/history/udwData/index.vue | 58 ++++++-------- 9 files changed, 143 insertions(+), 44 deletions(-) create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/opc/ObjectUtl.java diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java index 39f29a9e8..279774b80 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java @@ -74,6 +74,7 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple public int error = 0; public int door = 0; public int temperature = 0; + public int to_temperature = 0; public int countdown_house = 0; public int countdown_min = 0; public int countdown_sec = 0; @@ -120,6 +121,9 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple String device_code; + String message = null; + + @Override public Device getDevice() { return this.device; @@ -130,7 +134,6 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple @Override public void execute() { - String message = null; device_code = this.getDeviceCode(); heartbeat = this.itemProtocol.getItem_heartbeat(); @@ -154,7 +157,7 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple currentA = this.itemProtocol.getItem_currentA(); currentB = this.itemProtocol.getItem_currentB(); currentC = this.itemProtocol.getItem_currentC(); - + to_temperature = this.itemProtocol.getItem_to_temperature(); if (mode != last_mode) { //this.setRequireSucess(false); } @@ -187,6 +190,7 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple } if (finish == 1 && !requireSucess) { + message = "烘箱完成反馈LMS..."; logServer.deviceExecuteLog(this.getDevice_code(), "", "", "开始烘箱完成反馈lms~"); //烘箱完成反馈LMS apply_finish(); @@ -358,8 +362,10 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); if (applyLabelingAndBindingResponse.getstatus() == 200) { requireSucess = true; + message = "烘箱完成反馈LMS成功..."; logServer.deviceExecuteLog(this.getDevice_code(), "", "", "烘箱完成反馈lms响应消息:" + String.valueOf(applyLabelingAndBindingResponse)); } else { + message = "烘箱完成反馈LMS失败,"+String.valueOf(applyLabelingAndBindingResponse); logServer.deviceExecuteLog(this.getDevice_code(), "", "", "烘箱完成反馈lms响应消息:" + String.valueOf(applyLabelingAndBindingResponse)); } return true; diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java index 03e42ab96..95e821503 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java @@ -118,6 +118,10 @@ public class ItemProtocol { return this.getOpcFloatValue(item_currentC); } ; + public int getItem_to_temperature(){ + return this.getOpcIntegerValue(item_to_temperature); + } ; + Boolean isonline; public int getOpcIntegerValue(String protocol) { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java index 15564de89..4f99defa4 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java @@ -232,7 +232,9 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { jo.put("countdown_min", hongXiangConveyorDeviceDriver.getCountdown_min()); jo.put("countdown_sec", hongXiangConveyorDeviceDriver.getCountdown_sec()); //温度需要除以10 - jo.put("temperature", hongXiangConveyorDeviceDriver.getTemperature()/10); + jo.put("temperature", hongXiangConveyorDeviceDriver.getTo_temperature()/10); + jo.put("now_temperature", hongXiangConveyorDeviceDriver.getTemperature()/10); + jo.put("door", hongXiangConveyorDeviceDriver.getDoor()); jo.put("finish", hongXiangConveyorDeviceDriver.getFinish()); jo.put("task", hongXiangConveyorDeviceDriver.getTask()); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceExecuteAutoRun.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceExecuteAutoRun.java index 7b775bec7..9aaf6e918 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceExecuteAutoRun.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceExecuteAutoRun.java @@ -83,7 +83,7 @@ public class DeviceExecuteAutoRun extends AbstractAutoRunnable { } } - Thread.sleep(10000L); +// Thread.sleep(10000L); log.info("设备执行线程开始..."); while (true) { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceManageServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceManageServiceImpl.java index 3c673e1f7..c0f64d9f0 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceManageServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceManageServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import org.nl.modules.wql.core.bean.ResultBean; import org.nl.modules.wql.core.bean.WQLObject; import org.springframework.stereotype.Service; @@ -34,7 +35,12 @@ public class DeviceManageServiceImpl implements DeviceManageService { String opc_plc_id = json.getString("opc_plc_id"); if (StrUtil.isNotEmpty(opc_plc_id) && StrUtil.isNotEmpty(opc_server_id)) { //OPC表【acs_opc】 - String opc_code = opcTab.query("is_delete= '0' AND is_active= '1' AND opc_id = '" + opc_server_id + "'").uniqueResult(0).getString("opc_code"); + JSONObject rb = opcTab.query("is_delete= '0' AND is_active= '1' AND opc_id = '" + opc_server_id + "'").uniqueResult(0); + if(ObjectUtil.isEmpty(rb)){ + System.out.println(device.getDevice_code()); + continue; + } + String opc_code= rb.getString("opc_code"); device.setOpc_server_code(opc_code); if(ObjectUtil.isEmpty(plcTab.query("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").uniqueResult(0))) { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java index 174e204b1..2b62bd20c 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java @@ -61,7 +61,11 @@ public class DeviceOpcProtocolRunable implements Runnable { while (true) { try { 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(); +// Group group = server.addGroup(this.OpcServer.getOpc_host()); + Group group = server.addGroup(this.OpcServer.getOpc_code()); + if(ObjectUtil.isEmpty(group)){ + log.info("group is null "); + } List itemsString = new ArrayList(); Iterator it = this.protocols.iterator(); @@ -110,11 +114,18 @@ public class DeviceOpcProtocolRunable implements Runnable { label97: while (true) { long begin = System.currentTimeMillis(); - Map itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0])); + Map itemStatus = null; + try { + itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0])); + } catch (Exception e){ +// System.out.println("数据同步异常:"+itemsMap); + e.printStackTrace(); + } long end = System.currentTimeMillis(); log.trace("{} 开始记时{}", tag, DateUtil.now()); long duration = end - begin; log.trace("{} 读取耗时:{}", tag, duration); + System.out.println("线程:"+tag + " 读取耗时:"+ duration); if (duration > 1000L) { if (!time_out) { log.warn("{} 读取超时 : {}", tag, duration); @@ -125,6 +136,8 @@ public class DeviceOpcProtocolRunable implements Runnable { time_out = false; } + if(ObjectUtil.isEmpty(itemStatus)) continue label97; + Set items = itemStatus.keySet(); Iterator var18 = items.iterator(); @@ -151,7 +164,7 @@ public class DeviceOpcProtocolRunable implements Runnable { ItemState itemState = (ItemState) itemStatus.get(item); value = OpcUtl.getValue(item, itemState); his = accessor_value.getValue(item.getId()); - if (!ObjectUtil.equal(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) { + if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) { log.warn("opc 值不健康 item: {}, 状态: {}", item.getId(), itemState.getQuality()); } } while (ObjectUtil.equal(value, his));//如果两次的值相等,不走下面的代码 @@ -178,7 +191,7 @@ public class DeviceOpcProtocolRunable implements Runnable { } } } catch (Exception var30) { - String error_message = "设备信息同步异常"; + String error_message = "设备信息同步异常,"+var30; if (!StrUtil.equals(this.message, error_message)) { log.warn("", var30); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/ObjectUtl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/ObjectUtl.java new file mode 100644 index 000000000..ce5a34127 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/ObjectUtl.java @@ -0,0 +1,78 @@ +package org.nl.acs.opc; + + +import org.nl.modules.wql.exception.WDKException; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Objects; + +public class ObjectUtl { + private ObjectUtl() { + } + + public static boolean isEquals(Object a, Object b) { + if (a == null && b == null) { + return true; + } else if (a != null && b != null) { + if (a.getClass().isArray()) { + if (a instanceof boolean[]) { + return Arrays.equals((boolean[]) ((boolean[]) a), (boolean[]) ((boolean[]) b)); + } else if (a instanceof byte[]) { + return Arrays.equals((byte[]) ((byte[]) a), (byte[]) ((byte[]) b)); + } else if (a instanceof int[]) { + return Arrays.equals((int[]) ((int[]) a), (int[]) ((int[]) b)); + } else if (a instanceof long[]) { + return Arrays.equals((long[]) ((long[]) a), (long[]) ((long[]) b)); + } else if (a instanceof double[]) { + return Arrays.equals((double[]) ((double[]) a), (double[]) ((double[]) b)); + } else if (a instanceof short[]) { + return Arrays.equals((short[]) ((short[]) a), (short[]) ((short[]) b)); + } else if (a instanceof char[]) { + return Arrays.equals((char[]) ((char[]) a), (char[]) ((char[]) b)); + } else if (a instanceof float[]) { + return Arrays.equals((float[]) ((float[]) a), (float[]) ((float[]) b)); + } else if (a instanceof Object[]) { + return Arrays.equals((Object[]) ((Object[]) a), (Object[]) ((Object[]) b)); + } else { + throw new WDKException("未实现"); + } + } else { + return Objects.equals(a, b); + } + } else { + return false; + } + } + + public static boolean isTrue(Boolean boolean_) { + return boolean_ != null && isEquals(boolean_, true); + } + + public static boolean isTrue(Boolean targetBoolean, boolean defaultBoolean) { + return targetBoolean == null ? defaultBoolean : targetBoolean; + } + + public static boolean isFalse(Boolean boolean_) { + return boolean_ != null && isEquals(boolean_, false); + } + + + + + + public static boolean isObject(Class clazz) { + if (clazz == null) { + return false; + } else if (clazz.getClass().isArray()) { + return false; + } else { + return Object.class.isAssignableFrom(clazz); + } + } +} \ No newline at end of file diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/opcServerManageServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/opcServerManageServiceImpl.java index 6222371a7..05d4d38c5 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/opcServerManageServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/opcServerManageServiceImpl.java @@ -29,7 +29,7 @@ public class opcServerManageServiceImpl implements OpcServerManageService { public List queryAll() { //return this.opcServerRepository.queryAll(OpcServerManageDto.class); //OPC表【acs_opc】 - JSONArray arr = WQLObject.getWQLObject("acs_opc").query().getResultJSONArray(0); + JSONArray arr = WQLObject.getWQLObject("acs_opc").query("is_active='1' and is_delete='0'").getResultJSONArray(0); return arr.toJavaList(OpcServerManageDto.class); } diff --git a/acs/nladmin-ui/src/views/acs/history/udwData/index.vue b/acs/nladmin-ui/src/views/acs/history/udwData/index.vue index 5be540e3d..17f53a1fd 100644 --- a/acs/nladmin-ui/src/views/acs/history/udwData/index.vue +++ b/acs/nladmin-ui/src/views/acs/history/udwData/index.vue @@ -45,9 +45,6 @@ - - -
@@ -102,7 +104,7 @@ import crudOperation from '@crud/CRUD.operation' import { getDicts } from '@/api/system/dict' const defaultForm = { - unified_key: 'opc_value', + unified_key: '', key: null, value: null, last_modify_date: null @@ -142,7 +144,14 @@ export default { ], permission: { }, + dialogFormVisible: false, rules: { + }, + form: { + unified_key: 'opc_value', + key: null, + value: null, + last_modify_date: null } } }, @@ -155,26 +164,7 @@ export default { // 钩子:在获取表格数据之前执行,false 则代表不获取数据 [CRUD.HOOK.beforeRefresh]() { return true - }, - // https://www.cnblogs.com/jdWu-d/p/11898666.html - beforeHandleCommand(index, row, command) { - return { - 'index': index, - 'row': row, - 'command': command - } - }, - handleCommand(command) { - switch (command.command) { - case 'a':// 完成 - this.finish(command.index, command.row) - break - case 'b':// 取消 - this.cancel(command.index, command.row) - break - } } - } } From 27d30e4271b2f66cbff524c2cb7f9e5c108fe5d3 Mon Sep 17 00:00:00 2001 From: ludj Date: Fri, 10 Feb 2023 17:29:48 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/nl/acs/opc/DeviceOpcProtocolRunable.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java index 2b62bd20c..a609a2d78 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java @@ -19,10 +19,12 @@ public class DeviceOpcProtocolRunable implements Runnable { OpcServerManageDto OpcServer; int error_num; String message; + private Server server; public DeviceOpcProtocolRunable() { this.error_num = 0; this.message = null; + this.server = null; } public List getProtocols() { @@ -60,7 +62,7 @@ public class DeviceOpcProtocolRunable implements Runnable { public void run() { while (true) { try { - Server server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain()); + this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain()); // Group group = server.addGroup(this.OpcServer.getOpc_host()); Group group = server.addGroup(this.OpcServer.getOpc_code()); if(ObjectUtil.isEmpty(group)){ @@ -191,6 +193,15 @@ public class DeviceOpcProtocolRunable implements Runnable { } } } catch (Exception var30) { + if (this.server != null) { + try { + this.server.disconnect(); + } catch (Exception var25) { + } + } + + this.server = null; + String error_message = "设备信息同步异常,"+var30; if (!StrUtil.equals(this.message, error_message)) { log.warn("", var30); From 46e3e51a4c9f34afc84f54be6572175d37533e30 Mon Sep 17 00:00:00 2001 From: liuxy Date: Fri, 10 Feb 2023 22:02:37 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/nl/wms/pda/st/wql/PDA_CHECK.wql | 2 +- .../org/nl/wms/st/outbill/wql/ST_OUTIVT02.wql | 55 ++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/pda/st/wql/PDA_CHECK.wql b/lms/nladmin-system/src/main/java/org/nl/wms/pda/st/wql/PDA_CHECK.wql index c344e7ff6..e8b5b609d 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/pda/st/wql/PDA_CHECK.wql +++ b/lms/nladmin-system/src/main/java/org/nl/wms/pda/st/wql/PDA_CHECK.wql @@ -98,7 +98,7 @@ IF 输入.flag = "2" QUERY - SELECT + SELECT DISTINCT dtl.check_code, ( CASE diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/st/outbill/wql/ST_OUTIVT02.wql b/lms/nladmin-system/src/main/java/org/nl/wms/st/outbill/wql/ST_OUTIVT02.wql index 2374d99e8..5c5e7b25e 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/st/outbill/wql/ST_OUTIVT02.wql +++ b/lms/nladmin-system/src/main/java/org/nl/wms/st/outbill/wql/ST_OUTIVT02.wql @@ -17,6 +17,8 @@ 输入.pcsn TYPEAS s_string 输入.struct_id TYPEAS s_string 输入.iostorinv_id TYPEAS s_string + 输入.width TYPEAS s_string + 输入.thickness TYPEAS s_string [临时表] --这边列出来的临时表就会在运行期动态创建 @@ -121,4 +123,55 @@ ENDSELECT ENDQUERY - ENDIF \ No newline at end of file + ENDIF + + IF 输入.flag = "5" + QUERY + SELECT + sub.width, + sub.thickness + FROM + ST_IVT_IOStorInvDis dis + LEFT JOIN pdm_bi_subpackagerelation sub ON sub.package_box_sn = dis.box_no + WHERE + 1 = 1 + + OPTION 输入.iostorinv_id <> "" + dis.iostorinv_id = 输入.iostorinv_id + ENDOPTION + + group by sub.width,sub.thickness + + ENDSELECT + ENDQUERY + ENDIF + + IF 输入.flag = "6" + QUERY + SELECT + sub.package_box_sn AS box_no, + MAX( sub.product_description ) AS material_name, + SUM( sub.net_weight ) AS qty + FROM + ST_IVT_IOStorInvDis dis + LEFT JOIN pdm_bi_subpackagerelation sub ON sub.container_name = dis.pcsn + WHERE + 1 = 1 + + OPTION 输入.iostorinv_id <> "" + dis.iostorinv_id = 输入.iostorinv_id + ENDOPTION + + OPTION 输入.width <> "" + sub.width = 输入.width + ENDOPTION + + OPTION 输入.thickness <> "" + sub.width = 输入.thickness + ENDOPTION + + group by sub.package_box_sn + + ENDSELECT + ENDQUERY + ENDIF