更新日志

This commit is contained in:
USER-20220102CG\noblelift
2023-02-06 15:05:27 +08:00
parent fcda87f637
commit 6315e94b8a
18 changed files with 612 additions and 71 deletions

View File

@@ -0,0 +1,24 @@
package org.nl.modules.logging;
/**
* @author: lyd
* @description:
* @Date: 2022/10/11
*/
public enum InterfaceLogType {
DEFAULT("默认"),
LMS_TO_ACS("LMS请求ACS"),
ACS_TO_LMS("ACS请求LMS"),
ACS_TO_LK("ACS请求LMS"),
LK_TO_ACS("ACS请求LMS");
private String desc;
InterfaceLogType(String desc) {
this.desc=desc;
}
public String getDesc() {
return desc;
}
}

View File

@@ -15,6 +15,8 @@
*/
package org.nl.modules.logging.annotation;
import org.nl.modules.logging.InterfaceLogType;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -28,4 +30,33 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface Log {
String value() default "";
/**
* 是否打印到日志文件
*
* @return
*/
boolean isPrintToLogFile() default false;
/**
* 是否插入操作日志表
*
* @return
*/
boolean isAddLogTable() default true;
/**
* 是否接口日志
*
* @return
*/
boolean isInterfaceLog() default false;
/**
* 接口日志类型
*
* @return
*/
InterfaceLogType interfaceLogType() default InterfaceLogType.DEFAULT;
}

View File

@@ -15,8 +15,11 @@
*/
package org.nl.modules.logging.aspect;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
@@ -25,12 +28,14 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.nl.common.utils.IdUtil;
import org.nl.modules.common.utils.RequestHolder;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.common.utils.StringUtils;
import org.nl.modules.common.utils.ThrowableUtil;
import org.nl.modules.logging.domain.Log;
import org.nl.modules.logging.service.LogService;
import org.nl.modules.wql.core.bean.WQLObject;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
@@ -38,10 +43,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* @author Zheng Jie
@@ -75,21 +77,62 @@ public class LogAspect {
*/
@Around("logPointcut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
String trackId = UUID.randomUUID().toString();
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
// 方法路径
String methodName = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()";
String params=getParameter(method, joinPoint.getArgs());
log.info("请求方法:{}",methodName);
log.info("请求方法参数:{}",params);
String params = getParameter(method, joinPoint.getArgs());
org.nl.modules.logging.annotation.Log logInfo = method.getAnnotation(org.nl.modules.logging.annotation.Log.class);
//是否输出到日志文件
if (logInfo.isPrintToLogFile()) {
log.info("track_id:{},请求方法:{},请求方法参数:{}",trackId,methodName,params);
}
HttpServletRequest request = RequestHolder.getHttpServletRequest();
String requestIp = StringUtils.getIp(request);
Object result;
currentTime.set(System.currentTimeMillis());
result = joinPoint.proceed();
Log log = new Log("INFO",System.currentTimeMillis() - currentTime.get());
currentTime.remove();
HttpServletRequest request = RequestHolder.getHttpServletRequest();
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request),joinPoint, log);
try {
result = joinPoint.proceed();
//是否把日志存到日志表
if (logInfo.isAddLogTable()) {
Log log = new Log("INFO", System.currentTimeMillis() - currentTime.get());
currentTime.remove();
logService.save(getUsername(), StringUtils.getBrowser(request), requestIp, joinPoint, log);
}
if (logInfo.isInterfaceLog()) {
try {
WQLObject interfaceLog = WQLObject.getWQLObject("sys_interface_log");
JSONObject json = new JSONObject();
json.put("log_id", IdUtil.getStringId());
json.put("description", logInfo.value());
json.put("log_type", logInfo.interfaceLogType().getDesc());
json.put("log_level", "1");
json.put("method", methodName);
json.put("params", getParameter(method, joinPoint.getArgs()));
json.put("request_ip", StringUtils.getIp(request));
// json.put("time", System.currentTimeMillis() - currentTime.get());
json.put("username", getUsername());
json.put("address", StringUtils.getCityInfo(requestIp));
json.put("browser", StringUtils.getBrowser(request));
json.put("exception_detail", IdUtil.getStringId());
json.put("create_time", DateUtil.now());
json.put("return_result", result.toString());
interfaceLog.insert(json);
} catch (Exception e) {
}
}
}catch (Exception ex){
log.error("track_id:{},error:{}",trackId,ex.getMessage());
Log log = new Log("ERROR", System.currentTimeMillis() - currentTime.get());
currentTime.remove();
log.setExceptionDetail(ThrowableUtil.getStackTrace(ex).getBytes());
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log);
throw ex;
}
return result;
}

View File

@@ -0,0 +1,51 @@
package org.nl.modules.logging.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.nl.modules.logging.annotation.Log;
import org.nl.modules.logging.service.InterfaceLogService;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* @author ldjun
* @version 1.0
* @date 2023年01月29日 18:55
* @desc desc
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/interfaceLog")
@Api(tags = "系统:接口日志管理")
public class InterfaceLogController {
private final InterfaceLogService interfaceLogService;
@GetMapping
@Log("查询接口日志")
@ApiOperation("查询接口日志")
//@SaCheckPermission("point:list")
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
return new ResponseEntity<>(interfaceLogService.queryAll(whereJson, page), HttpStatus.OK);
}
@DeleteMapping(value = "/delLogs")
@Log("删除所有接口日志")
@ApiOperation("删除所有接口日志")
public ResponseEntity<Object> delLogs(){
interfaceLogService.delLogs();
return new ResponseEntity<>(HttpStatus.OK);
}
@GetMapping("/logTypeList")
@Log("查询接口日志类型下拉框")
@ApiOperation("查询接口日志类型下拉框")
public ResponseEntity<Object> logTypeList() {
return new ResponseEntity<>(interfaceLogService.logTypeList(), HttpStatus.OK);
}
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.modules.logging.service;
import com.alibaba.fastjson.JSONArray;
import org.springframework.data.domain.Pageable;
import java.util.Map;
/**
* @author Zheng Jie
* @date 2018-11-24
*/
public interface InterfaceLogService {
/**
* 查询数据分页
* @param whereJson 条件
* @param page 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(Map whereJson, Pageable page);
/**
* 删除所有日志
*/
void delLogs();
JSONArray logTypeList();
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.modules.logging.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.logging.InterfaceLogType;
import org.nl.modules.logging.service.InterfaceLogService;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* @author Zheng Jie
* @date 2018-11-24
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class InterfaceLogServiceImpl implements InterfaceLogService {
@Override
public Map<String, Object> queryAll(Map whereJson, Pageable pageable) {
HashMap map = new HashMap();
map.put("flag", "1");
map.put("blurry", whereJson.get("blurry"));
map.put("logType", whereJson.get("logType"));
map.put("begin_time", whereJson.get("begin_time"));
map.put("end_time", whereJson.get("end_time"));
JSONObject json = WQL.getWO("QSCH_INTERFACE_LOGS").addParamMap(map).pageQuery(WqlUtil.getHttpContext(pageable), "create_time desc");
return json;
}
@Override
public void delLogs() {
WQLObject logTab = WQLObject.getWQLObject("sys_interface_log");
logTab.delete("log_id is not null");
}
@Override
public JSONArray logTypeList() {
JSONArray jsonArray = new JSONArray();
InterfaceLogType[] values = InterfaceLogType.values();
for (InterfaceLogType value : values) {
jsonArray.add(value.getDesc());
}
return jsonArray;
}
}

View File

@@ -0,0 +1,68 @@
[交易说明]
交易名: 接口日志分页查询
所属模块:
功能简述:
版权所有:
表引用:
版本经历:
[数据库]
--指定数据库为空采用默认值默认为db.properties中列出的第一个库
[IO定义]
#################################################
## 表字段对应输入参数
#################################################
输入.flag TYPEAS s_string
输入.blurry TYPEAS s_string
输入.logType TYPEAS s_string
输入.begin_time TYPEAS s_string
输入.end_time TYPEAS s_string
[临时表]
--这边列出来的临时表就会在运行期动态创建
[临时变量]
--所有中间过程变量均可在此处定义
[业务过程]
##########################################
# 1、输入输出检查 #
##########################################
##########################################
# 2、主过程前处理 #
##########################################
##########################################
# 3、业务主过程 #
##########################################
IF 输入.flag = "1"
PAGEQUERY
SELECT
*
FROM
sys_interface_log
WHERE
1=1
OPTION 输入.blurry <> ""
description like "%" 输入.blurry "%"
ENDOPTION
OPTION 输入.logType <> ""
log_type = 输入.logType
ENDOPTION
OPTION 输入.begin_time <> ""
create_time >= 输入.begin_time
ENDOPTION
OPTION 输入.end_time <> ""
create_time <= 输入.end_time
ENDOPTION
ENDSELECT
ENDPAGEQUERY
ENDIF