添加设备log

This commit is contained in:
huangzj
2023-08-08 09:51:55 +08:00
parent 8bb82cf859
commit 0054466fd9
4 changed files with 86 additions and 2 deletions

View File

@@ -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 "";
}

View File

@@ -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);
}
}