|
|
@@ -0,0 +1,81 @@
|
|
|
+package com.zswl.dataservice.service.openApi;
|
|
|
+
|
|
|
+import com.zswl.dataservice.dao.UserDao;
|
|
|
+import com.zswl.dataservice.dao.mqtt.OperationLogsDao;
|
|
|
+import com.zswl.dataservice.dao.openApi.OpenApiRequestLogDao;
|
|
|
+import com.zswl.dataservice.domain.base.SuperEntity;
|
|
|
+import com.zswl.dataservice.domain.mqtt.OperationLogs;
|
|
|
+import com.zswl.dataservice.domain.openApi.OpenApiRequestLog;
|
|
|
+import com.zswl.dataservice.domain.user.User;
|
|
|
+import com.zswl.dataservice.model.openApi.requestLog.OpenApiRequestLogModel;
|
|
|
+import com.zswl.dataservice.model.openApi.requestLog.OpenApiRequestLogSearch;
|
|
|
+import com.zswl.dataservice.model.operLogs.OperationLogsModel;
|
|
|
+import com.zswl.dataservice.model.operLogs.OperationLogsSearchParam;
|
|
|
+import com.zswl.dataservice.service.base.SuperService;
|
|
|
+import com.zswl.dataservice.utils.DateUtils;
|
|
|
+import com.zswl.dataservice.utils.bean.BeanUtils;
|
|
|
+import com.zswl.dataservice.utils.mqtt.type.LogsLevel;
|
|
|
+import com.zswl.dataservice.utils.net.IPUtil;
|
|
|
+import com.zswl.dataservice.utils.page.PageEntityUtil;
|
|
|
+import com.zswl.dataservice.utils.result.ResultContent;
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author TRX
|
|
|
+ * @date 2024/5/24
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class OpenApiRequestLogsService extends SuperService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private HttpServletRequest request;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OpenApiRequestLogDao openApiRequestLogDao;
|
|
|
+
|
|
|
+ public ResultContent addLogs(String appId, String msg) {
|
|
|
+ OpenApiRequestLog logs = new OpenApiRequestLog();
|
|
|
+ logs.setMsg(msg);
|
|
|
+ logs.setAppId(appId);
|
|
|
+ logs.setRequestTime(System.currentTimeMillis());
|
|
|
+ logs.setRequestTimeStr(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();
|
|
|
+ }
|
|
|
+ openApiRequestLogDao.save(logs);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 日志列表
|
|
|
+ *
|
|
|
+ * @param pageable
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent<Page<OpenApiRequestLogModel>> pageLogs(Pageable pageable, OpenApiRequestLogSearch param) {
|
|
|
+ Page<OpenApiRequestLog> page = openApiRequestLogDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+
|
|
|
+ public OpenApiRequestLogModel toModel(OpenApiRequestLog entity) {
|
|
|
+ OpenApiRequestLogModel model = null;
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ model = new OpenApiRequestLogModel();
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|