diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java index 550944a..b9dddb5 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java @@ -333,6 +333,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic agv_message = conveyorPressStationDeviceDriver.getDevice_code() + message; logService.deviceExecuteLog(device_code, "", "", message); log.info("{},{}", device_code,message); + log.info("模式为{} 光电信号{} 取放信号{}",conveyorPressStationDeviceDriver.getMode(),conveyorPressStationDeviceDriver.getMove(),conveyorPressStationDeviceDriver.getIo_action()); lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message)); } } @@ -585,6 +586,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic agv_message = conveyorPressStationDeviceDriver.getDevice_code() + message; logService.deviceExecuteLog(device_code, "", "", message); log.info("{},{}", device_code,message); + log.info("模式为{} 光电信号{} 取放信号{}",conveyorPressStationDeviceDriver.getMode(),conveyorPressStationDeviceDriver.getMove(),conveyorPressStationDeviceDriver.getIo_action()); lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message)); } } @@ -857,6 +859,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic agv_message = conveyorPressStationDeviceDriver.getDevice_code() + message; logService.deviceExecuteLog(device_code, "", "", message); log.info("{},{}", device_code,message); + log.info("模式为{} 光电信号{} 取放信号{}",conveyorPressStationDeviceDriver.getMode(),conveyorPressStationDeviceDriver.getMove(),conveyorPressStationDeviceDriver.getIo_action()); lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message)); } } @@ -1114,6 +1117,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic agv_message = conveyorPressStationDeviceDriver.getDevice_code() + message; logService.deviceExecuteLog(device_code, "", "", message); log.info("{},{}", device_code,message); + log.info("模式为{} 光电信号{} 取放信号{}",conveyorPressStationDeviceDriver.getMode(),conveyorPressStationDeviceDriver.getMove(),conveyorPressStationDeviceDriver.getIo_action()); lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message)); } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java index 474dd7b..8e7bb1e 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java @@ -24,7 +24,7 @@ public interface OpcDeviceDriver extends DeviceDriver { //设备扩展表【acs_device_extra】 WQLObject extraTab = WQLObject.getWQLObject("acs_device_extra"); - JSONArray arr = extraTab.query("filed_type='02' and device_id = '" + this.getDevice().getDevice_id() + "'").getResultJSONArray(0); + JSONArray arr = extraTab.query(" (filed_type='02' or filed_type='03' )and device_id = '" + this.getDevice().getDevice_id() + "'").getResultJSONArray(0); for (int i = 0; i < arr.size(); i++) { JSONObject json = arr.getJSONObject(i); OpcItemDto dto = new OpcItemDto(); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/converor_barcode/ConveyorBarcodeDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/converor_barcode/ConveyorBarcodeDeviceDriver.java index ce5e6ac..f670f69 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/converor_barcode/ConveyorBarcodeDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/converor_barcode/ConveyorBarcodeDeviceDriver.java @@ -458,6 +458,7 @@ public class ConveyorBarcodeDeviceDriver extends AbstractOpcDeviceDriver impleme jo.put("isOnline", isonline); jo.put("hasGoods", hasGoods); jo.put("message", message); + jo.put("requireSucess",requireSucess); return jo; } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator_site/LnshPalletizingManipulatorSiteDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator_site/LnshPalletizingManipulatorSiteDeviceDriver.java index 12c6101..6e4c9c8 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator_site/LnshPalletizingManipulatorSiteDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator_site/LnshPalletizingManipulatorSiteDeviceDriver.java @@ -37,6 +37,7 @@ import org.nl.acs.opc.DeviceAppService; import org.nl.acs.order.service.ProduceshiftorderService; import org.nl.acs.route.service.RouteLineService; import org.nl.acs.task.service.TaskService; +import org.nl.modules.lucene.enums.LogTypeEnum; import org.nl.modules.lucene.service.LuceneExecuteLogService; import org.nl.modules.lucene.service.dto.LuceneLogDto; import org.nl.modules.wql.util.SpringContextHolder; @@ -898,8 +899,15 @@ public class LnshPalletizingManipulatorSiteDeviceDriver extends AbstractOpcDevic ApplyTaskResponse resp = JSON.toJavaObject(JSONObject.parseObject(acsToWmsService.applyTask(request)),ApplyTaskResponse.class); message = RequestMethodEnum.getName("apply_take_full_vehicle") + "apply_take_full_vehicle 接口请求LMS..."; - lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request))); + LuceneLogDto dto = new LuceneLogDto(); + dto.setDevice_code(this.device_code); + dto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc()); + dto.setRemark(JSON.toJSONString(request)); + lucene.deviceExecuteLog(dto); +// lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request))); +// log.info("{}",JSON.toJSONString(dto)); +// log.info("{}",JSON.toJSONString(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)))); if (resp.getCode() == 200) { this.writing(200); this.setRequireSucess(true); @@ -1200,7 +1208,6 @@ public class LnshPalletizingManipulatorSiteDeviceDriver extends AbstractOpcDevic ReadUtil.write(itemMap, server); ReadUtil.write(itemMap, server); server.disconnect(); - logServer.deviceExecuteLog(this.device_code, "", "", "to_command 写入 " + command); lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, "to_command 写入 " + command)); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/LmsUtil.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/LmsUtil.java index 84b8de7..57891f3 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/LmsUtil.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/LmsUtil.java @@ -35,19 +35,19 @@ public class LmsUtil { } String liKu_wcs_url = paramService.findByCode("wmsurl").getValue(); try { - log.info("请求LMS参数:{}", JSON.toJSONString(requestParam)); +// log.info("请求LMS参数:{}", JSON.toJSONString(requestParam)); String body = HttpRequest .post(liKu_wcs_url + api).setConnectionTimeout(3000) .body(JSON.toJSONString(requestParam)) .execute() .body(); - log.info("请求LMS参数返回参数:{}", body); +// log.info("请求LMS参数返回参数:{}", body); return body; } catch (Exception e) { JSONObject result = new JSONObject(); result.put("code", "500"); result.put("message", e.getMessage()); - log.info("请求LMS异常返回参数:{}", String.valueOf(result)); +// log.info("请求LMS异常返回参数:{}", String.valueOf(result)); return String.valueOf(result); } } 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 815c3da..7f009be 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 @@ -276,14 +276,13 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { resp.setMessage("请求成功"); log.info("createFromWms - 返回参数 {}", JSON.toJSON(resp)); -// LuceneLogDto logDto = LuceneLogDto.builder() -// .device_code("LMSTOACS") -// .requestparam(JSON.toJSON(resp).toString()) -// .responseparam(JSON.toJSON(resp).toString()) -// .status_code(String.valueOf(resp.getCode())) -// .method(tasks.getRequest_medthod_code()) -// .build(); -// lucene.interfaceExecuteLog(logDto); + LuceneLogDto logDto = LuceneLogDto.builder() + .requestparam(JSON.toJSON(resp).toString()) + .responseparam(JSON.toJSON(resp).toString()) + .status_code(String.valueOf(resp.getCode())) + .method(tasks.getRequest_medthod_code()) + .build(); + lucene.interfaceExecuteLog(logDto); return (JSONObject) JSON.toJSON(resp); } finally { MDC.remove(log_file_type); @@ -550,6 +549,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { lnshSplitManipulatorDeviceDriver.writing(100); is_flag = true; } + //下发成功后,写入工单信息表记录 // ProduceshiftorderDto dto = new ProduceshiftorderDto(); @@ -578,9 +578,14 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { resp.setRequestNo(request_no); resp.setResponseDate(AgvUtil.getDate()); resp.setMessage("请求成功"); - log.info("createOrder - 返回参数 {}", JSON.toJSON(resp)); + LuceneLogDto logDto = LuceneLogDto.builder() + .requestparam(JSON.toJSON(resp).toString()) + .responseparam(JSON.toJSON(resp).toString()) + .status_code(String.valueOf(resp.getCode())) + .method(orders.getRequest_medthod_code()) + .build(); + lucene.interfaceExecuteLog(logDto); return (JSONObject) JSON.toJSON(resp); - } finally { MDC.remove(log_file_type); } 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 5a10c40..d299cba 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 @@ -3,10 +3,12 @@ package org.nl.acs.opc; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import lombok.extern.slf4j.Slf4j; import org.nl.acs.udw.UnifiedDataAccessor; import org.nl.acs.udw.UnifiedDataAccessorFactory; import org.nl.acs.udw.UnifiedDataAppService; +import org.nl.modules.lucene.enums.LogTypeEnum; import org.nl.modules.lucene.service.LuceneExecuteLogService; import org.nl.modules.lucene.service.dto.LuceneLogDto; import org.nl.modules.wql.util.SpringContextHolder; @@ -118,7 +120,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC try { Item item = group.addItem(string); itemsMap.put(string, item); - log.trace("添加成功 {}", string); +// log.trace("添加成功 {}", string); } catch (Exception var26) { err_message.append(string + ":" + var26.getMessage()); if (!is_error) { @@ -130,7 +132,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC String tag; if (is_error) { tag = err_message.toString(); - log.warn("{}:{}", OpcConfig.resource_code, tag); +// log.warn("{}:{}", OpcConfig.resource_code, tag); } if (!OpcStartTag.is_run) { @@ -152,18 +154,18 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC while (DeviceOpcSynchronizeAutoRun.isRun) { long begin = System.currentTimeMillis(); if (log.isTraceEnabled()) { - log.trace("{} 开始记时{}", tag, DateUtil.now()); +// log.trace("{} 开始记时{}", tag, DateUtil.now()); } Map itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0])); long end = System.currentTimeMillis(); long duration = end - begin; if (log.isTraceEnabled()) { - log.trace("{} 读取耗时:{}", tag, duration); +// log.trace("{} 读取耗时:{}", tag, duration); } if (duration > 1000L) { if (!time_out) { - log.warn("{} 读取超时 : {}", tag, duration); +// log.warn("{} 读取超时 : {}", tag, duration); } time_out = true; @@ -186,7 +188,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC String itemId = item.getId(); Object his = accessor_value.getValue(itemId); if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) { - log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality()); +// log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality()); } if (!UnifiedDataAppService.isEquals(value, his)) { @@ -218,29 +220,28 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC if (log.isWarnEnabled()) { log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null, 5000 + random); } - - ThreadUtl.sleep((long) (5000 + random)); + ThreadUtl.sleep((long) ((new Random()).nextInt(3) + 1) * 1000); + break start; } else if (this.all_null < 6) { if (log.isWarnEnabled()) { log.warn(tag + "重新创建server"); log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null, 30000 + random); } -// ThreadUtl.sleep((long) (30000 + random)); ThreadUtl.sleep((long) ((new Random()).nextInt(3) + 1) * 1000); break start; } else if (this.all_null < 12) { if (log.isWarnEnabled()) { - log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, '\uea60' + random); +// log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, '\uea60' + random); } + ThreadUtl.sleep((long) ((new Random()).nextInt(3) + 1) * 1000); + break start; - ThreadUtl.sleep((long) ('\uea60' + random)); } else { if (log.isWarnEnabled()) { - log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, 120000 + random); +// log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, 120000 + random); } - - ThreadUtl.sleep((long) (120000 + random)); - +// ThreadUtl.sleep((long) ((new Random()).nextInt(3) + 1) * 1000); +// break start; } ++this.all_null; } else { @@ -351,7 +352,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC this.server = null; } - log.warn("opc server {} {}", this.getOpcGroupID(), connected ? "connected" : "disconnected"); +// log.warn("opc server {} {}", this.getOpcGroupID(), connected ? "connected" : "disconnected"); } private String getOpcGroupID() { @@ -381,7 +382,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC // } else if (log.isInfoEnabled()) { // log.info("Item {} new value: {}, Timestamp: {}, Quality: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime(), itemState.getQuality()}); // } - log.trace("Item {} new value: {}, Timestamp: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime()}); +// log.trace("Item {} new value: {}, Timestamp: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime()}); OpcItemDto itemDto = this.getItem(itemId); // if (Boolean.TRUE.equals(itemDto.getNeed_log())) { @@ -397,6 +398,8 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC private void logItemChanged(String itemId, UnifiedDataAccessor accessor_value, Object value, OpcItemDto itemDto) { Object his = accessor_value.getValue(itemId); + itemDto.setHis_item_value(his); + itemDto.setItem_value(value); List relate_items = itemDto.getRelate_items(); if (relate_items != null && !relate_items.isEmpty()) { StringBuilder sb = new StringBuilder(); @@ -407,24 +410,22 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC Object obj = accessor_value.getValue(relate); sb.append("key:" + relate + "value:" + obj + ";"); } - log.info("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value, sb}); - // 存在上次点位值为null情况 则不记录日志 if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time")) { - if((ObjectUtil.equal(his,"null") || ObjectUtil.isEmpty(his)) || (ObjectUtil.equal(value,"null") || ObjectUtil.isEmpty(value)) ){ - //lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value))); - } else { - lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value))); - } + // 存在上次点位值为null情况 则不记录日志 + LuceneLogDto luceneLogDto = new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), + String.valueOf(itemDto.getHis_item_value()), String.valueOf(itemDto.getItem_value())); + luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc()); + log.info("{}", JSON.toJSONString(luceneLogDto)); } } else { - log.info("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value}); +// log.info("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value}); // 存在上次点位值为null情况 则不记录日志 if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time")) { - if((ObjectUtil.equal(his,"null") || ObjectUtil.isEmpty(his)) || (ObjectUtil.equal(value,"null") || ObjectUtil.isEmpty(value)) ){ - //lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value))); - } else { - lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value))); - } + LuceneLogDto luceneLogDto = new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), + String.valueOf(itemDto.getHis_item_value()), String.valueOf(itemDto.getItem_value())); + luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc()); + log.info("{}", JSON.toJSONString(luceneLogDto)); + } } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcItemDto.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcItemDto.java index 4563762..bd71a09 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcItemDto.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcItemDto.java @@ -14,6 +14,7 @@ public class OpcItemDto { private String opc_plc_code; private String item_code; private Object item_value; + private Object his_item_value; private Boolean need_log = Boolean.valueOf(false); private List relate_items = new ArrayList(); diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LogMessageConstant.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LogMessageConstant.java new file mode 100644 index 0000000..ca7f941 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LogMessageConstant.java @@ -0,0 +1,44 @@ +package org.nl.modules.lucene.common; + +/** + * @Author: lyd + * @Description: 定义lucene相关常量 + * @Date: 2023/8/25 + */ +public class LogMessageConstant { + /** 级别 */ + public final static String FIELD_LEVEL = "level"; + /** 时间 */ + public final static String FIELD_TIMESTAMP = "timestamp"; + /** 类的限定名 */ + public final static String FIELD_CLASS_NAME = "logger"; + /** 线程名 */ + public final static String FIELD_THREAD = "thread"; + /** 日志内容 */ + public final static String FIELD_MESSAGE = "message"; + public final static String FIELD_TRACEID = "tlogTraceId"; + // 定义颜色值 + /** 文本颜色:黑色 */ + public final static String COLOR_BLACK = "\u001B[30m"; + /** 文本颜色:红色 */ + public final static String COLOR_RED = "\u001B[31m"; + /** 文本颜色:绿色 */ + public final static String COLOR_GREEN = "\u001B[32m"; + /** 文本颜色:黄色 */ + public final static String COLOR_YELLOW = "\u001B[33m"; + /** 文本颜色:蓝色 */ + public final static String COLOR_BLUE = "\u001B[34m"; + /** 文本颜色:品红色 */ + public final static String COLOR_MAGENTA = "\u001B[35m"; + /** 文本颜色:青色 */ + public final static String COLOR_CYAN = "\u001B[36m"; + /** 文本颜色:白色 */ + public final static String COLOR_WHITE = "\u001B[37m"; + /** 文本颜色重置 */ + public final static String COLOR_RESET = "\u001B[0m"; + /** 背景颜色:黄色 */ + public final static String BACKGROUND_YELLOW = "\u001B[43m"; + + /** 索引路径 */ + public final static String INDEX_DIR = "D:\\lucene\\index"; +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneAppender.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneAppender.java new file mode 100644 index 0000000..56dd6ca --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneAppender.java @@ -0,0 +1,123 @@ +package org.nl.modules.lucene.common; +/** + * @author ldjun + * @version 1.0 + * @date 2023年08月24日 13:00 + * @desc desc + */ + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.AppenderBase; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSONObject; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.document.*; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.FSDirectory; +import org.nl.acs.opc.OpcItemDto; +import org.nl.modules.lucene.enums.LogTypeEnum; +import org.nl.modules.lucene.service.LuceneExecuteLogService; +import org.nl.modules.lucene.service.dto.LuceneLogDto; +import org.nl.modules.wql.util.SpringContextHolder; +import org.wltea.analyzer.lucene.IKAnalyzer; + +import java.io.IOException; +import java.nio.file.Paths; +import java.util.Map; + +public class LuceneAppender extends AppenderBase { + + private Directory index; + private IndexWriter indexWriter; + + + @Override + public void start() { + super.start(); + try { + index = FSDirectory.open(Paths.get(LogMessageConstant.INDEX_DIR)); + } catch (IOException e) { + e.printStackTrace(); + } + + // 初始化 Lucene 索引 + Analyzer analyzer = new IKAnalyzer(); + IndexWriterConfig config = new IndexWriterConfig(analyzer); + try { + indexWriter = new IndexWriter(index, config); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + @Override + protected void append(ILoggingEvent event) { + String message = event.getFormattedMessage(); + try { + LuceneLogDto luceneLogDto = JSONObject.parseObject(message, LuceneLogDto.class); + +// LuceneLogDto luceneLogDto = new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), +// String.valueOf(itemDto.getHis_item_value()), String.valueOf(itemDto.getItem_value())); +// luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc()); + //IndexWriter indexWriter = LuceneIndexWriter.getIndexWriter(); + //创建一个Document对象 + Document document = new Document(); + try { + //记录索引开始时间 + long startTime = System.currentTimeMillis(); + //向document对象中添加域。 + if (ObjectUtil.isNotEmpty(luceneLogDto.getDevice_code())) { + document.add(new StringField("device_code", luceneLogDto.getDevice_code(), Field.Store.YES)); +// document.add(new TextField("device_code", luceneLogDto.getDevice_code(), Field.Store.YES)); + } + if (ObjectUtil.isNotEmpty(luceneLogDto.getContent())) { + document.add(new StringField("fieldContent", luceneLogDto.getContent(), Field.Store.YES)); + } + if (ObjectUtil.isNotEmpty(luceneLogDto.getMethod())) { + document.add(new StringField("method", luceneLogDto.getMethod(), Field.Store.YES)); + } + if (ObjectUtil.isNotEmpty(luceneLogDto.getStatus_code())) { + document.add(new StringField("status_code", luceneLogDto.getStatus_code(), Field.Store.YES)); + } + if (ObjectUtil.isNotEmpty(luceneLogDto.getRequestparam())) { + document.add(new StringField("requestparam", luceneLogDto.getRequestparam(), Field.Store.YES)); + } + if (ObjectUtil.isNotEmpty(luceneLogDto.getResponseparam())) { + document.add(new StringField("responseparam", luceneLogDto.getResponseparam(), Field.Store.YES)); + } + document.add(new StringField("logType", luceneLogDto.getLogType(), Field.Store.YES)); + document.add(new StringField("logTime", DateUtil.format(new DateTime(), "yyyy-MM-dd HH:mm:ss.SSS"), Field.Store.YES)); + document.add(new NumericDocValuesField("logTime",System.currentTimeMillis()));//排序 + //记录索引结束时间 + long endTime = System.currentTimeMillis(); + // log.info("建立索引共耗时{}毫秒", endTime - startTime); + + try { + indexWriter.addDocument(document); + indexWriter.commit(); + } catch (IOException e) { + e.printStackTrace(); + } + } catch (Exception e) { + return; + } + } catch (Exception e){ + return; + } + } + + @Override + public void stop() { + super.stop(); + try { + indexWriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneIndexWriter.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneIndexWriter.java index df7c4eb..c37e2f5 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneIndexWriter.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneIndexWriter.java @@ -16,45 +16,45 @@ import java.text.SimpleDateFormat; import java.util.Date; public class LuceneIndexWriter { - private static IndexWriter indexWriter; - - static { - try { - Directory directory = FSDirectory.open(new File(UrlConfig.luceneUrl).toPath()); - IndexWriterConfig config = new IndexWriterConfig(new IKAnalyzer()); - indexWriter = new IndexWriter(directory, config); - } catch (Exception e) { - e.printStackTrace(); - } - /**当当前线程结束时,自动关闭IndexWriter,使用Runtime对象*/ - Runtime.getRuntime().addShutdownHook(new Thread(){ - @Override - public void run() { - try { - closeIndexWriter(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - /**在线程结束时,自动关闭IndexWriter*/ - public static IndexWriter getIndexWriter() { - return indexWriter; - } - /**关闭IndexWriter - * @throws IOException - * @throws CorruptIndexException */ - public static void closeIndexWriter() throws Exception { - if(indexWriter != null) { - indexWriter.close(); - } - } - - public static void main(String[] args) throws IOException { - indexWriter.deleteAll(); - } - +// private static IndexWriter indexWriter; +// +// static { +// try { +// Directory directory = FSDirectory.open(new File(UrlConfig.luceneUrl).toPath()); +// IndexWriterConfig config = new IndexWriterConfig(new IKAnalyzer()); +// indexWriter = new IndexWriter(directory, config); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// /**当当前线程结束时,自动关闭IndexWriter,使用Runtime对象*/ +// Runtime.getRuntime().addShutdownHook(new Thread(){ +// @Override +// public void run() { +// try { +// closeIndexWriter(); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// }); +// } +// /**在线程结束时,自动关闭IndexWriter*/ +// public static IndexWriter getIndexWriter() { +// return indexWriter; +// } +// /**关闭IndexWriter +// * @throws IOException +// * @throws CorruptIndexException */ +// public static void closeIndexWriter() throws Exception { +// if(indexWriter != null) { +// indexWriter.close(); +// } +// } +// +// public static void main(String[] args) throws IOException { +// indexWriter.deleteAll(); +// } +// public static String getDate(String timeString) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");//时间格式 Date date = sdf.parse(timeString); @@ -62,5 +62,4 @@ public class LuceneIndexWriter { return timeString; } - } diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/Searcher.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/Searcher.java index 19ce19f..9cd0af2 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/Searcher.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/Searcher.java @@ -36,6 +36,7 @@ public class Searcher { //构建IndexSearcher IndexSearcher searcher = new IndexSearcher(reader); //标准分词器,会自动去掉空格啊,is a the等单词 + Analyzer analyzer = new IKAnalyzer(true); // Analyzer analyzer = new StandardAnalyzer(); // Analyzer analyzer = new IKAnalyzer(false); //查询解析器 @@ -49,7 +50,7 @@ public class Searcher { int start = pageNum * pageSize;// 当前页的起始条数 int end = start + pageSize;// 当前页的结束条数(不能包含) // 创建排序对象,需要排序字段SortField,参数:字段的名称、字段的类型、是否反转如果是false,升序。true降序 - Sort sort = new Sort(new SortField("logTime", SortField.Type.DOC,true)); + Sort sort = new Sort(new SortField("logTime", SortField.Type.LONG,true)); TopDocs docs = null; BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder(); diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneExecuteLogServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneExecuteLogServiceImpl.java index c97f22b..70619e6 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneExecuteLogServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneExecuteLogServiceImpl.java @@ -3,6 +3,7 @@ package org.nl.modules.lucene.service.impl; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSON; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -35,57 +36,57 @@ public class LuceneExecuteLogServiceImpl implements LuceneExecuteLogService { String now = DateUtil.now(); } - @SneakyThrows @Override public void deviceExecuteLog(LuceneLogDto luceneLogDto) { luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc()); - addIndex(luceneLogDto); + log.info("{}", JSON.toJSONString(luceneLogDto)); } @Override public void interfaceExecuteLog(LuceneLogDto luceneLogDto) { luceneLogDto.setLogType(LogTypeEnum.INTERFACE_LOG.getDesc()); - addIndex(luceneLogDto); +// addIndex(luceneLogDto); + log.info("{}", JSON.toJSONString(luceneLogDto)); } private void addIndex(LuceneLogDto luceneLogDto) { - IndexWriter indexWriter = LuceneIndexWriter.getIndexWriter(); - //创建一个Document对象 - Document document = new Document(); - try { - //记录索引开始时间 - long startTime = System.currentTimeMillis(); - //向document对象中添加域。 - if (ObjectUtil.isNotEmpty(luceneLogDto.getDevice_code())) { - document.add(new StringField("device_code", luceneLogDto.getDevice_code(), Field.Store.YES)); -// document.add(new TextField("device_code", luceneLogDto.getDevice_code(), Field.Store.YES)); - } - if (ObjectUtil.isNotEmpty(luceneLogDto.getContent())) { - document.add(new StringField("fieldContent", luceneLogDto.getContent(), Field.Store.YES)); - } - if (ObjectUtil.isNotEmpty(luceneLogDto.getMethod())) { - document.add(new StringField("method", luceneLogDto.getMethod(), Field.Store.YES)); - } - if (ObjectUtil.isNotEmpty(luceneLogDto.getStatus_code())) { - document.add(new StringField("status_code", luceneLogDto.getStatus_code(), Field.Store.YES)); - } - if (ObjectUtil.isNotEmpty(luceneLogDto.getRequestparam())) { - document.add(new StringField("requestparam", luceneLogDto.getRequestparam(), Field.Store.YES)); - } - if (ObjectUtil.isNotEmpty(luceneLogDto.getResponseparam())) { - document.add(new StringField("responseparam", luceneLogDto.getResponseparam(), Field.Store.YES)); - } - document.add(new StringField("logType", luceneLogDto.getLogType(), Field.Store.YES)); - document.add(new StringField("logTime", DateUtil.format(new DateTime(), "yyyy-MM-dd HH:mm:ss.SSS"), Field.Store.YES)); - indexWriter.addDocument(document); - //记录索引结束时间 - long endTime = System.currentTimeMillis(); - log.info("建立索引共耗时{}毫秒", endTime - startTime); - indexWriter.commit(); - MDC.put("DEVICECODE", luceneLogDto.getDevice_code()); - } catch (Exception e) { - log.error(e.getMessage(), e); - } +// IndexWriter indexWriter = LuceneIndexWriter.getIndexWriter(); +// //创建一个Document对象 +// Document document = new Document(); +// try { +// //记录索引开始时间 +// long startTime = System.currentTimeMillis(); +// //向document对象中添加域。 +// if (ObjectUtil.isNotEmpty(luceneLogDto.getDevice_code())) { +// document.add(new StringField("device_code", luceneLogDto.getDevice_code(), Field.Store.YES)); +//// document.add(new TextField("device_code", luceneLogDto.getDevice_code(), Field.Store.YES)); +// } +// if (ObjectUtil.isNotEmpty(luceneLogDto.getContent())) { +// document.add(new StringField("fieldContent", luceneLogDto.getContent(), Field.Store.YES)); +// } +// if (ObjectUtil.isNotEmpty(luceneLogDto.getMethod())) { +// document.add(new StringField("method", luceneLogDto.getMethod(), Field.Store.YES)); +// } +// if (ObjectUtil.isNotEmpty(luceneLogDto.getStatus_code())) { +// document.add(new StringField("status_code", luceneLogDto.getStatus_code(), Field.Store.YES)); +// } +// if (ObjectUtil.isNotEmpty(luceneLogDto.getRequestparam())) { +// document.add(new StringField("requestparam", luceneLogDto.getRequestparam(), Field.Store.YES)); +// } +// if (ObjectUtil.isNotEmpty(luceneLogDto.getResponseparam())) { +// document.add(new StringField("responseparam", luceneLogDto.getResponseparam(), Field.Store.YES)); +// } +// document.add(new StringField("logType", luceneLogDto.getLogType(), Field.Store.YES)); +// document.add(new StringField("logTime", DateUtil.format(new DateTime(), "yyyy-MM-dd HH:mm:ss.SSS"), Field.Store.YES)); +// indexWriter.addDocument(document); +// //记录索引结束时间 +// long endTime = System.currentTimeMillis(); +// log.info("建立索引共耗时{}毫秒", endTime - startTime); +// indexWriter.commit(); +// MDC.put("DEVICECODE", luceneLogDto.getDevice_code()); +// } catch (Exception e) { +// log.error(e.getMessage(), e); +// } } @Override diff --git a/acs/nladmin-system/src/main/resources/config/application-dev.yml b/acs/nladmin-system/src/main/resources/config/application-dev.yml index 0585c63..7bd7aa6 100644 --- a/acs/nladmin-system/src/main/resources/config/application-dev.yml +++ b/acs/nladmin-system/src/main/resources/config/application-dev.yml @@ -6,8 +6,8 @@ spring: druid: db-type: com.alibaba.druid.pool.DruidDataSource driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy - url: jdbc:log4jdbc:mysql://${DB_HOST:10.93.41.198}:${DB_PORT:3306}/${DB_NAME:rl_mg_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true -# url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:rl_mg_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true +# url: jdbc:log4jdbc:mysql://${DB_HOST:10.93.41.198}:${DB_PORT:3306}/${DB_NAME:rl_mg_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true + url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:rl_mg_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true username: ${DB_USER:root} password: ${DB_PWD:123456} # 初始连接数 @@ -127,7 +127,7 @@ file: avatarMaxSize: 5 logging: file: - path: C:\log\wms + path: C:\log\ACS config: classpath:logback-spring.xml lucene: index: diff --git a/acs/nladmin-system/src/main/resources/config/application-prod.yml b/acs/nladmin-system/src/main/resources/config/application-prod.yml index fdcbec5..11e8128 100644 --- a/acs/nladmin-system/src/main/resources/config/application-prod.yml +++ b/acs/nladmin-system/src/main/resources/config/application-prod.yml @@ -6,7 +6,8 @@ spring: druid: db-type: com.alibaba.druid.pool.DruidDataSource driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy - url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.4.210}:${DB_PORT:3306}/${DB_NAME:acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true + # url: jdbc:log4jdbc:mysql://${DB_HOST:10.93.41.198}:${DB_PORT:3306}/${DB_NAME:rl_mg_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true + url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:rl_mg_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true username: ${DB_USER:root} password: ${DB_PWD:123456} # 初始连接数 @@ -52,7 +53,7 @@ spring: multi-statement-allow: true redis: #数据库索引 - database: ${REDIS_DB:2} + database: ${REDIS_DB:15} host: ${REDIS_HOST:127.0.0.1} port: ${REDIS_PORT:6379} password: ${REDIS_PWD:} @@ -126,7 +127,7 @@ file: avatarMaxSize: 5 logging: file: - path: D:\log\acs + path: C:\log\ACS config: classpath:logback-spring.xml lucene: index: @@ -153,5 +154,5 @@ sa-token: token-prefix: Bearer loki: - url: http://192.168.4.210:3100/loki/api/v1 + url: http://localhost:3100/loki/api/v1 systemName: acs diff --git a/acs/nladmin-system/src/main/resources/config/application.yml b/acs/nladmin-system/src/main/resources/config/application.yml index 7e3fbea..43cf9ea 100644 --- a/acs/nladmin-system/src/main/resources/config/application.yml +++ b/acs/nladmin-system/src/main/resources/config/application.yml @@ -2,7 +2,7 @@ spring: freemarker: check-template-location: false profiles: - active: dev + active: prod jackson: time-zone: GMT+8 data: @@ -44,7 +44,7 @@ rsa: private_key: MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEA0vfvyTdGJkdbHkB8mp0f3FE0GYP3AYPaJF7jUd1M0XxFSE2ceK3k2kw20YvQ09NJKk+OMjWQl9WitG9pB6tSCQIDAQABAkA2SimBrWC2/wvauBuYqjCFwLvYiRYqZKThUS3MZlebXJiLB+Ue/gUifAAKIg1avttUZsHBHrop4qfJCwAI0+YRAiEA+W3NK/RaXtnRqmoUUkb59zsZUBLpvZgQPfj1MhyHDz0CIQDYhsAhPJ3mgS64NbUZmGWuuNKp5coY2GIj/zYDMJp6vQIgUueLFXv/eZ1ekgz2Oi67MNCk5jeTF2BurZqNLR3MSmUCIFT3Q6uHMtsB9Eha4u7hS31tj1UWE+D+ADzp59MGnoftAiBeHT7gDMuqeJHPL4b+kC+gzV4FGTfhR9q3tTbklZkD2A== logging: file: - path: C:\log\wms + path: C:\log\ACS config: classpath:logback-spring.xml # sa-token白名单配置 security: diff --git a/acs/nladmin-system/src/main/resources/log/Lucene.xml b/acs/nladmin-system/src/main/resources/log/Lucene.xml index b53961d..f00bdbd 100644 --- a/acs/nladmin-system/src/main/resources/log/Lucene.xml +++ b/acs/nladmin-system/src/main/resources/log/Lucene.xml @@ -23,12 +23,19 @@ + + + + + 512 + - + + diff --git a/acs/nladmin-system/src/main/resources/logback-spring.xml b/acs/nladmin-system/src/main/resources/logback-spring.xml index 85bbca8..a5017fc 100644 --- a/acs/nladmin-system/src/main/resources/logback-spring.xml +++ b/acs/nladmin-system/src/main/resources/logback-spring.xml @@ -57,10 +57,17 @@ https://juejin.cn/post/6844903775631572999 0 - 500 + 200 + + + + + 512 + + 1000 @@ -85,10 +92,12 @@ https://juejin.cn/post/6844903775631572999 + + @@ -137,10 +146,12 @@ https://juejin.cn/post/6844903775631572999 + + diff --git a/lms/nladmin-system/nlsso-server/src/main/resources/logback-spring.xml b/lms/nladmin-system/nlsso-server/src/main/resources/logback-spring.xml index 9c01099..7661eba 100644 --- a/lms/nladmin-system/nlsso-server/src/main/resources/logback-spring.xml +++ b/lms/nladmin-system/nlsso-server/src/main/resources/logback-spring.xml @@ -23,7 +23,7 @@ https://juejin.cn/post/6844903775631572999 ${log.pattern} - ${log.charset} + diff --git a/lms/nladmin-ui/src/views/system/notice/NoticeIconReader.vue b/lms/nladmin-ui/src/views/system/notice/NoticeIconReader.vue index e8eba7d..b2d8250 100644 --- a/lms/nladmin-ui/src/views/system/notice/NoticeIconReader.vue +++ b/lms/nladmin-ui/src/views/system/notice/NoticeIconReader.vue @@ -4,7 +4,7 @@ :visible.sync="visible" :modal-append-to-body="false" :append-to-body="true" - width="40%"> + width="60%">