添加设备log
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package com.njcn.common.pojo.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2023/8/7 19:09【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DeviceLogDTO {
|
||||
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 操作
|
||||
*/
|
||||
private String operate;
|
||||
|
||||
/**
|
||||
* 结果(0:失败 1:成功)
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 失败原因
|
||||
*/
|
||||
private String failReason;
|
||||
|
||||
/**
|
||||
* 登录名称
|
||||
*/
|
||||
private String loginName;
|
||||
|
||||
private String userIndex;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.njcn.web.advice;
|
||||
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2023/8/7 18:47【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
@Documented
|
||||
|
||||
public @interface DeviceLog {
|
||||
|
||||
|
||||
String operateType() default "";
|
||||
}
|
||||
@@ -2,12 +2,15 @@ package com.njcn.web.service.impl;
|
||||
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.LogInfo;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.common.pojo.dto.LogInfoDTO;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.common.utils.ReflectCommonUtil;
|
||||
import com.njcn.web.advice.DeviceLog;
|
||||
import com.njcn.web.service.ILogService;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -77,6 +80,13 @@ public class LogServiceImpl implements ILogService {
|
||||
String operateType = ReflectCommonUtil.getOperateTypeByMethod(returnType.getMethod());
|
||||
LogInfoDTO logInfoDTO = new LogInfoDTO(loginName, userName, ip, methodDescribe, operateType, result.equalsIgnoreCase("失败") ? 0 : 1, "", levelStringToNumber(level), type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), userIndex);
|
||||
publisher.send("/userLog", PubUtils.obj2json(logInfoDTO), 2, false);
|
||||
//如果存在设备日志注解,则记录设备日志
|
||||
if(Objects.nonNull((returnType.getMethod()))&& (returnType.getMethod()).isAnnotationPresent(DeviceLog.class)){
|
||||
String deviceOperate = returnType.getMethod().getAnnotation(DeviceLog.class).operateType();
|
||||
DeviceLogDTO deviceLogDTO = new DeviceLogDTO(userName,deviceOperate,result.equalsIgnoreCase("失败") ? 0 : 1,"",loginName,userIndex);
|
||||
publisher.send("/deviceLog", PubUtils.obj2json(deviceLogDTO), 2, false);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.njcn.system.controller;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.dto.LogInfoDTO;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
@@ -24,6 +25,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
/**
|
||||
@@ -59,10 +61,16 @@ public class UserLogController extends BaseController {
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
|
||||
@PostMapping("/query")
|
||||
@ApiOperation("查询审计日志")
|
||||
@ApiOperation("查询审计日志(治理模块)")
|
||||
public HttpResult<List<UserLog>> queryUserLog() {
|
||||
String methodDescribe = getMethodDescribe("queryUserLog");
|
||||
List<UserLog> list = userLogService.lambdaQuery().eq(UserLog::getLoginName, RequestUtil.getUsername()).orderByDesc(UserLog::getCreateTime).last("limit 100").list();
|
||||
List<UserLog> list = userLogService.lambdaQuery().eq(UserLog::getLoginName, RequestUtil.getUsername()).
|
||||
in(UserLog::getServiceName, Stream.of(ServerInfo.CS_DEVICE_BOOT,
|
||||
ServerInfo.CS_HARMONIC_BOOT,
|
||||
ServerInfo.CS_REPORT_BOOT,
|
||||
ServerInfo.CS_EVENT_BOOT,
|
||||
ServerInfo.CS_WARN_BOOT,
|
||||
ServerInfo.CS_SYSTEM_BOOT)).orderByDesc(UserLog::getCreateTime).last("limit 100").list();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user