TRX há 1 ano atrás
pai
commit
35ee5b9e11

+ 52 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/payment/RequestInfoSaveParam.java

@@ -0,0 +1,52 @@
+package com.zhongshu.card.client.model.payment;
+
+import com.zhongshu.card.client.utils.type.payment.RequestType;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+
+/**
+ * @author TRX
+ * @date 2024/8/22
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class RequestInfoSaveParam {
+
+    @Schema(description = "关联的请求id")
+    private String requestId;
+
+    @Schema(description = "请求用户userId")
+    private String userId;
+
+    @Schema(description = "请求用户名称")
+    private String userName;
+
+    @Schema(description = "api信息")
+    private Object apiParam;
+
+    @Schema(description = "请求参数")
+    private Object param;
+
+    @Schema(description = "返回参数")
+    private Object response;
+
+    @Schema(description = "是否成功")
+    private Boolean isSuccess = Boolean.TRUE;
+
+    @Schema(description = "请求分类")
+    private RequestType requestType = RequestType.Common;
+
+    @Schema(description = "错误信息")
+    private String msg = "";
+
+    @Schema(description = "请求耗时:毫秒")
+    private Long millis;
+
+    @Schema(description = "过期时间")
+    private Long TTL;
+}

+ 1 - 1
FullCardClient/src/main/java/com/zhongshu/card/client/service/MqttFeignService.java → FullCardClient/src/main/java/com/zhongshu/card/client/service/feign/MqttFeignService.java

@@ -1,4 +1,4 @@
-package com.zhongshu.card.client.service;
+package com.zhongshu.card.client.service.feign;
 
 import com.zhongshu.card.client.model.mqtt.SendMessageModel;
 import com.github.microservice.net.ResultContent;

+ 1 - 1
FullCardClient/src/main/java/com/zhongshu/card/client/service/OrganizationFeignService.java → FullCardClient/src/main/java/com/zhongshu/card/client/service/feign/OrganizationFeignService.java

@@ -1,4 +1,4 @@
-package com.zhongshu.card.client.service;
+package com.zhongshu.card.client.service.feign;
 
 import com.zhongshu.card.client.model.org.*;
 import com.github.microservice.net.ResultContent;

+ 1 - 1
FullCardClient/src/main/java/com/zhongshu/card/client/service/ProjectPaySettingFeignService.java → FullCardClient/src/main/java/com/zhongshu/card/client/service/feign/ProjectPaySettingFeignService.java

@@ -1,4 +1,4 @@
-package com.zhongshu.card.client.service;
+package com.zhongshu.card.client.service.feign;
 
 import com.zhongshu.card.client.model.feign.ProjectWxPayParam;
 import com.zhongshu.card.client.model.payment.paySetting.*;

+ 1 - 1
FullCardClient/src/main/java/com/zhongshu/card/client/service/ProjectPaySettingService.java → FullCardClient/src/main/java/com/zhongshu/card/client/service/feign/ProjectPaySettingService.java

@@ -1,4 +1,4 @@
-package com.zhongshu.card.client.service;
+package com.zhongshu.card.client.service.feign;
 
 import com.zhongshu.card.client.model.feign.ProjectWxPayParam;
 import com.zhongshu.card.client.model.payment.paySetting.*;

+ 20 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/service/feign/RequestInfoFeignService.java

@@ -0,0 +1,20 @@
+package com.zhongshu.card.client.service.feign;
+
+import com.github.microservice.net.ResultContent;
+import com.zhongshu.card.client.model.mqtt.SendMessageModel;
+import com.zhongshu.card.client.model.payment.RequestInfoSaveParam;
+import io.swagger.v3.oas.annotations.Operation;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+
+@FeignClient(name = "fullcardserver/requestInfo/manager")
+public interface RequestInfoFeignService {
+
+    @Operation(summary = "保存请求数据", description = "保存请求数据")
+    @RequestMapping(value = "saveRequestInfo", method = {RequestMethod.POST})
+    ResultContent saveRequestInfo(@RequestBody RequestInfoSaveParam param);
+
+}

+ 1 - 1
FullCardClient/src/main/java/com/zhongshu/card/client/service/UserFeignService.java → FullCardClient/src/main/java/com/zhongshu/card/client/service/feign/UserFeignService.java

@@ -1,4 +1,4 @@
-package com.zhongshu.card.client.service;
+package com.zhongshu.card.client.service.feign;
 
 import com.zhongshu.card.client.model.org.UserCountModel;
 import com.github.microservice.net.ResultContent;

+ 40 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/feign/RequestInfoFeignController.java

@@ -0,0 +1,40 @@
+package com.zhongshu.card.server.core.controller.feign;
+
+import com.github.microservice.net.ResultContent;
+import com.zhongshu.card.client.model.mqtt.SendMessageModel;
+import com.zhongshu.card.client.model.org.OrganizationUserModel;
+import com.zhongshu.card.client.model.payment.RequestInfoSaveParam;
+import com.zhongshu.card.server.core.service.payment.RequestInfoService;
+import io.swagger.v3.oas.annotations.Hidden;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author TRX
+ * @date 2024/8/22
+ */
+@RestController
+@RequestMapping("requestInfo/manager")
+@Tag(name = "请求日志数据")
+@Hidden
+public class RequestInfoFeignController {
+
+    @Autowired
+    RequestInfoService requestInfoService;
+
+    @Operation(summary = "保存请求数据", description = "保存请求数据")
+    @RequestMapping(value = "saveRequestInfo", method = {RequestMethod.POST})
+    public ResultContent<OrganizationUserModel> saveRequestInfo(@RequestBody RequestInfoSaveParam param) {
+        return requestInfoService.saveRequestInfo(param);
+    }
+
+
+}
+
+
+

+ 1 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/payment/ProjectPaySettingController.java

@@ -5,7 +5,7 @@ import com.github.microservice.auth.security.type.AuthType;
 import com.zhongshu.card.client.model.feign.ProjectWxPayParam;
 import com.zhongshu.card.client.model.payment.paySetting.*;
 import com.github.microservice.net.ResultContent;
-import com.zhongshu.card.client.service.ProjectPaySettingService;
+import com.zhongshu.card.client.service.feign.ProjectPaySettingService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.beans.factory.annotation.Autowired;

+ 1 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/payment/ProjectPaySettingServiceImpl.java

@@ -4,7 +4,7 @@ import com.github.microservice.auth.security.type.AuthType;
 import com.zhongshu.card.client.model.feign.ProjectWxPayParam;
 import com.zhongshu.card.client.model.payment.paySetting.*;
 import com.github.microservice.net.ResultContent;
-import com.zhongshu.card.client.service.ProjectPaySettingService;
+import com.zhongshu.card.client.service.feign.ProjectPaySettingService;
 import com.zhongshu.card.server.core.dao.org.OrganizationDao;
 import com.zhongshu.card.server.core.dao.payment.ProjectPaySettingDao;
 import com.zhongshu.card.server.core.dao.payment.WxPayConfigDao;

+ 42 - 2
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/payment/RequestInfoService.java

@@ -1,13 +1,21 @@
 package com.zhongshu.card.server.core.service.payment;
 
 import com.github.microservice.models.hxz.base.HxzBaseResult;
+import com.github.microservice.net.ResultContent;
+import com.zhongshu.card.client.model.payment.RequestInfoSaveParam;
 import com.zhongshu.card.client.utils.type.payment.RequestType;
+import com.zhongshu.card.server.core.dao.org.UserCountDao;
 import com.zhongshu.card.server.core.dao.payment.RequestInfoDao;
+import com.zhongshu.card.server.core.domain.org.UserAccount;
 import com.zhongshu.card.server.core.domain.payment.RequestInfo;
 import com.zhongshu.card.server.core.httpRequest.apiConf.APIResponseModel;
 import com.zhongshu.card.client.utils.DateUtils;
+import com.zhongshu.card.server.core.util.BeanUtils;
+import com.zhongshu.card.server.core.util.CommonUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.util.Date;
@@ -23,6 +31,37 @@ public class RequestInfoService {
     @Autowired
     RequestInfoDao requestInfoDao;
 
+    @Autowired
+    UserCountDao userCountDao;
+
+    private static Long ttlTime = 30 * 24 * 60 * 60 * 1000L;
+
+    /**
+     * 保存请求数据
+     *
+     * @param param
+     * @return
+     */
+    @Async
+    public ResultContent saveRequestInfo(RequestInfoSaveParam param) {
+        RequestInfo requestInfo = new RequestInfo();
+        BeanUtils.copyProperties(param, requestInfo);
+        requestInfo.setTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
+        Long ttl = param.getTTL();
+        if (CommonUtil.longIsEmpty(ttl)) {
+            ttl = ttlTime;
+        }
+        requestInfo.setTTL(new Date(System.currentTimeMillis() + ttlTime));
+        if (StringUtils.isNotEmpty(param.getUserId())) {
+            UserAccount userAccount = userCountDao.findTopByUserId(param.getUserId());
+            if (userAccount != null) {
+                requestInfo.setUserName(userAccount.getName());
+            }
+        }
+        requestInfoDao.save(requestInfo);
+        return ResultContent.buildSuccess();
+    }
+
     /**
      * 添加 HXZ 请求日志
      *
@@ -38,13 +77,14 @@ public class RequestInfoService {
         requestInfo.setMsg(response.getMsg());
         requestInfo.setTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
         requestInfo.setRequestType(RequestType.HXZ);
-        requestInfo.setTTL(new Date(System.currentTimeMillis() + 30 * 24 * 60 * 60 * 1000L));
+        requestInfo.setTTL(new Date(System.currentTimeMillis() + ttlTime));
         requestInfoDao.save(requestInfo);
         return true;
     }
 
     /**
      * 添加IOT平台访问日志
+     *
      * @param param
      * @param response
      * @return
@@ -58,7 +98,7 @@ public class RequestInfoService {
         requestInfo.setMsg(response.getMsg());
         requestInfo.setTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
         requestInfo.setRequestType(RequestType.IotCenter);
-        requestInfo.setTTL(new Date(System.currentTimeMillis() + 30 * 24 * 60 * 60 * 1000L));
+        requestInfo.setTTL(new Date(System.currentTimeMillis() + ttlTime));
         requestInfo.setMillis(response.getMillis());
         requestInfoDao.save(requestInfo);
         return true;