|
|
@@ -1,9 +1,11 @@
|
|
|
package com.zhongshu.iot.server.core.service.user;
|
|
|
|
|
|
+import com.github.microservice.dataConfig.IotTtlConfig;
|
|
|
+import com.github.microservice.net.ResultContent;
|
|
|
import com.zhongshu.card.client.model.org.UserCountModel;
|
|
|
import com.zhongshu.iot.client.model.operLogs.OperationLogsModel;
|
|
|
import com.zhongshu.iot.client.model.operLogs.OperationLogsSearchParam;
|
|
|
-import com.zhongshu.iot.client.type.OperationLogType;
|
|
|
+import com.zhongshu.iot.client.type.OperationLogBusType;
|
|
|
import com.zhongshu.iot.client.type.type.LogsLevel;
|
|
|
import com.zhongshu.iot.server.core.dao.UserDao;
|
|
|
import com.zhongshu.iot.server.core.dao.mqtt.OperationLogsDao;
|
|
|
@@ -14,7 +16,6 @@ import com.zhongshu.iot.server.core.util.DateUtils;
|
|
|
import com.zhongshu.iot.server.core.util.bean.BeanUtils;
|
|
|
import com.zhongshu.iot.server.core.util.net.IPUtil;
|
|
|
import com.zhongshu.iot.server.core.util.page.PageEntityUtil;
|
|
|
-import com.github.microservice.net.ResultContent;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
@@ -23,6 +24,8 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
/**
|
|
|
* @author TRX
|
|
|
* @date 2024/5/24
|
|
|
@@ -38,77 +41,53 @@ public class OperationLogsService extends SuperService {
|
|
|
private UserDao userDao;
|
|
|
|
|
|
@Autowired
|
|
|
- HttpServletRequest request;
|
|
|
+ private HttpServletRequest request;
|
|
|
|
|
|
public ResultContent addLogs(String content, LogsLevel level) {
|
|
|
- OperationLogs logs = new OperationLogs();
|
|
|
- logs.setContent(content);
|
|
|
- if (level == null) {
|
|
|
- level = LogsLevel.Low;
|
|
|
- }
|
|
|
- logs.setLevel(level);
|
|
|
- UserCountModel user = getCrrentUser();
|
|
|
- if (ObjectUtils.isNotEmpty(user)) {
|
|
|
- logs.setUid(user.getId());
|
|
|
- logs.setUserName(user.getName());
|
|
|
- logs.setLoginName(user.getLoginName());
|
|
|
- }
|
|
|
- logs.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
|
|
|
- try {
|
|
|
- logs.setUa(request.getHeader("User-Agent"));
|
|
|
- logs.setIp(IPUtil.getRemoteIp(request));
|
|
|
- logs.setUrl(request.getRequestURI());
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- operationLogsDao.save(logs);
|
|
|
- return ResultContent.buildSuccess();
|
|
|
+ return addLogs(content, level, null, null);
|
|
|
}
|
|
|
|
|
|
- public ResultContent addLogs(String content, LogsLevel level, SuperEntity entity) {
|
|
|
- OperationLogs logs = new OperationLogs();
|
|
|
- logs.setContent(content);
|
|
|
- if (level == null) {
|
|
|
- level = LogsLevel.Low;
|
|
|
- }
|
|
|
- logs.setLevel(level);
|
|
|
- UserCountModel user = getCrrentUser();
|
|
|
- if (ObjectUtils.isNotEmpty(user)) {
|
|
|
- logs.setUid(user.getId());
|
|
|
- logs.setUserName(user.getName());
|
|
|
- logs.setLoginName(user.getLoginName());
|
|
|
- }
|
|
|
- logs.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
|
|
|
- if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
- logs.setDataId(entity.getId());
|
|
|
- logs.setBackObj(entity);
|
|
|
- }
|
|
|
- try {
|
|
|
- logs.setUa(request.getHeader("User-Agent"));
|
|
|
- logs.setIp(IPUtil.getRemoteIp(request));
|
|
|
- logs.setUrl(request.getRequestURI());
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("addLogs: {}", e.getMessage());
|
|
|
- }
|
|
|
- operationLogsDao.save(logs);
|
|
|
- return ResultContent.buildSuccess();
|
|
|
+ public ResultContent addLogs(String content, OperationLogBusType operationLogBusType) {
|
|
|
+ return addLogs(content, null, operationLogBusType, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent addLogs(String content, OperationLogBusType operationLogBusType, SuperEntity entity) {
|
|
|
+ return addLogs(content, null, operationLogBusType, entity);
|
|
|
}
|
|
|
|
|
|
- public ResultContent addLogs(String content, LogsLevel level, OperationLogType operationLogType, SuperEntity entity) {
|
|
|
+ /**
|
|
|
+ * 操作日志
|
|
|
+ * @param content 内容:如:删除了用户
|
|
|
+ * @param level 日志级别 如:高、中、低
|
|
|
+ * @param operationLogBusType 关联的业务类型
|
|
|
+ * @param entity 对应实体
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent addLogs(String content, LogsLevel level, OperationLogBusType operationLogBusType, SuperEntity entity) {
|
|
|
OperationLogs logs = new OperationLogs();
|
|
|
+ logs.setTTL(new Date(System.currentTimeMillis() + IotTtlConfig.IOT_OPERATION_LOGS_TTL));
|
|
|
+
|
|
|
logs.setContent(content);
|
|
|
- logs.setOperationLogType(operationLogType);
|
|
|
if (level == null) {
|
|
|
level = LogsLevel.Low;
|
|
|
}
|
|
|
logs.setLevel(level);
|
|
|
+ if (operationLogBusType == null) {
|
|
|
+ operationLogBusType = OperationLogBusType.Common;
|
|
|
+ }
|
|
|
+ logs.setOperationLogBusType(operationLogBusType);
|
|
|
+
|
|
|
+ // 操作的用户信息
|
|
|
UserCountModel user = getCrrentUser();
|
|
|
if (ObjectUtils.isNotEmpty(user)) {
|
|
|
logs.setUid(user.getId());
|
|
|
logs.setUserName(user.getName());
|
|
|
logs.setLoginName(user.getLoginName());
|
|
|
+ logs.setPhone(user.getPhone());
|
|
|
}
|
|
|
logs.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
|
|
|
+
|
|
|
+ // 数据对象
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
logs.setDataId(entity.getId());
|
|
|
logs.setBackObj(entity);
|
|
|
@@ -118,7 +97,7 @@ public class OperationLogsService extends SuperService {
|
|
|
logs.setIp(IPUtil.getRemoteIp(request));
|
|
|
logs.setUrl(request.getRequestURI());
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("addLogs: {}", e.getMessage());
|
|
|
}
|
|
|
operationLogsDao.save(logs);
|
|
|
return ResultContent.buildSuccess();
|