TRX 1 рік тому
батько
коміт
12163c81f4

+ 1 - 1
FullCardClient/src/main/java/com/zhongshu/card/client/model/operLogs/OperationLogsAddParam.java

@@ -43,7 +43,7 @@ public class OperationLogsAddParam {
     private String content;
 
     @Schema(description = "日志级别,重要程度")
-    private LogsLevel level;
+    private LogsLevel level = LogsLevel.Low;
 
     @Schema(description = "管理数据ID")
     private String dataId;

+ 2 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/FullCardServerApplication.java

@@ -6,11 +6,13 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.context.annotation.ComponentScan;
+import org.springframework.scheduling.annotation.EnableAsync;
 
 
 @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
 @EnableApplicationClient
 @ComponentScan("com.zhongshu.card.server.core")
+@EnableAsync
 public class FullCardServerApplication extends ApplicationBootSuper {
 
 	public static void main(String[] args) {

+ 2 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/user/OperationLogsController.java

@@ -48,7 +48,8 @@ public class OperationLogsController {
     @Operation(summary = "添加日志", description = "添加日志")
     @RequestMapping(value = "manager/addLog", method = {RequestMethod.POST})
     public ResultContent<OrganizationUserModel> addLog(@RequestBody OperationLogsAddParam param) {
-        return operationLogsService.addLog(param);
+        operationLogsService.addLog(param);
+        return ResultContent.buildSuccess();
     }
 
 }

+ 10 - 5
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/payment/ExpenseFlow.java

@@ -74,10 +74,6 @@ public class ExpenseFlow extends SuperMain {
     @Schema(description = "卡片信息")
     private CardInfo cardInfo;
 
-    @Schema(description = "关联钱包信息")
-    @DBRef(lazy = true)
-    private Wallet wallet;
-
     @Schema(description = "消费类型,如:餐饮消费")
     private String payType;
 
@@ -99,7 +95,7 @@ public class ExpenseFlow extends SuperMain {
     @Schema(description = "当前的第几小时")
     private Integer hourOfDay;
 
-    @Schema(description = "消费创建时间")
+    @Schema(description = "消费创建时间 yyyy-MM-dd HH:mm:ss SSS")
     private String paymentTime;
 
     public void setTimes() {
@@ -176,6 +172,15 @@ public class ExpenseFlow extends SuperMain {
     @Schema(description = "调用支付的 支付结果")
     private Object payResult;
 
+    @Schema(description = "支付开始时间")
+    private Long payStartTime;
+
+    @Schema(description = "支付结束时间")
+    private Long payEndTime;
+
+    @Schema(description = "支付耗用的时间")
+    private Long payMillis = 0L;
+
     //-----------------------退款 start--------------------------
     @Schema(description = "是否退款")
     private Boolean isRefund;

+ 10 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/base/SuperService.java

@@ -3,10 +3,13 @@ package com.zhongshu.card.server.core.service.base;
 import com.github.microservice.auth.security.helper.AuthHelper;
 import com.zhongshu.card.client.model.base.SuperParam;
 import com.zhongshu.card.client.model.base.SuperSearch;
+import com.zhongshu.card.client.model.operLogs.OperationLogsAddParam;
 import com.zhongshu.card.server.core.dao.org.UserCountDao;
 import com.zhongshu.card.server.core.domain.base.SuperMain;
 import com.zhongshu.card.server.core.domain.org.UserAccount;
 import com.zhongshu.card.client.utils.DateUtils;
+import com.zhongshu.card.server.core.util.CommonUtil;
+import jakarta.servlet.http.HttpServletRequest;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -26,6 +29,9 @@ public abstract class SuperService {
     @Autowired
     UserCountDao userCountDao;
 
+    @Autowired
+    private HttpServletRequest request;
+
     /**
      * 得到当前的用户ID
      *
@@ -204,4 +210,8 @@ public abstract class SuperService {
             param.setEndTime(endTime);
         }
     }
+
+    public OperationLogsAddParam initLog(String userId) {
+        return CommonUtil.initLog(request, userId);
+    }
 }

+ 34 - 24
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/payment/ExpenseFlowServiceImpl.java

@@ -8,6 +8,7 @@ import com.github.microservice.models.hxz.*;
 import com.github.microservice.models.type.OrderFromType;
 import com.github.microservice.models.type.PaymentDeviceType;
 import com.github.microservice.models.type.PaymentType;
+import com.zhongshu.card.client.model.operLogs.OperationLogsAddParam;
 import com.zhongshu.card.client.model.payment.*;
 import com.zhongshu.card.client.model.payment.statistic.BusinessMainStatisticModel;
 import com.zhongshu.card.client.model.payment.statistic.StatisticItem;
@@ -37,9 +38,12 @@ import com.zhongshu.card.server.core.httpRequest.ApiRequestService;
 import com.zhongshu.card.server.core.httpRequest.apiConf.APIResponseModel;
 import com.zhongshu.card.server.core.service.base.SuperService;
 import com.zhongshu.card.server.core.service.org.OrganizationServiceImpl;
+import com.zhongshu.card.server.core.service.user.OperationLogsService;
 import com.zhongshu.card.server.core.util.*;
 import com.zhongshu.payment.client.model.WalletModel;
 import com.zhongshu.payment.client.model.param.AmountUpdateParam;
+import com.zhongshu.payment.client.payModel.commn.CreateOrderParam;
+import com.zhongshu.payment.client.service.OrderPayFeignService;
 import com.zhongshu.payment.client.service.WalletFeignService;
 import com.zhongshu.payment.client.types.WalletType;
 import lombok.extern.slf4j.Slf4j;
@@ -97,6 +101,12 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
     @Autowired
     WalletFeignService walletFeignService;
 
+    @Autowired
+    OrderPayFeignService orderPayFeignService;
+
+    @Autowired
+    OperationLogsService operationLogsService;
+
     /**
      * 创建流水
      *
@@ -162,21 +172,31 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
             return ResultContent.buildSuccess(entity);
         }
 
-        // 钱包支付
-        AmountUpdateParam param = new AmountUpdateParam();
-        param.setOid(entity.getProjectOid());
+        CreateOrderParam param = new CreateOrderParam();
+        param.setProjectOid(entity.getProjectOid());
         param.setUserId(entity.getUserId());
         param.setShopId(entity.getShopOid());
         param.setSchoolId(entity.getSchoolOid());
         param.setTotal(entity.getPayAmount());
         param.setOutTradeNo(entity.getPaymentNo());
-        ResultContent content = walletFeignService.consume(param);
+        param.setPaymentType(entity.getPaymentType());
+        param.setDescription("刷卡消费");
+
+        OperationLogsAddParam logsAddParam = initLog(entity.getUserId());
+        logsAddParam.setTitle("刷卡消费");
+        logsAddParam.setDataId(entity.getPaymentNo());
+        entity.setPayStartTime(System.currentTimeMillis());
+        ResultContent content = orderPayFeignService.createAndPay(param);
         if (content.isSuccess()) {
             // 关联参数
-            entity.setPaymentStatus("支付成功");
+            String msg = "支付成功";
+            entity.setPaymentStatus(msg);
             entity.setIsPaySuccess(Boolean.TRUE);
-            entity.setPayRemark("支付成功");
+            entity.setPayRemark(msg);
             entity.setOrderType(OrderType.HAVE_PAID);
+            logsAddParam.setMessageType(MessageType.Info);
+            logsAddParam.setLevel(LogsLevel.Low);
+            logsAddParam.setContent(msg);
         } else {
             String msg = content.getMsg();
             if (StringUtils.isNotEmpty(msg) && msg.contains("Connection reset")) {
@@ -184,10 +204,17 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
             }
             entity.setPaymentStatus(msg);
             entity.setIsPaySuccess(Boolean.FALSE);
-            entity.setPayRemark(content.getMsg());
+            entity.setPayRemark(msg);
             entity.setOrderType(OrderType.PAID_ERROR);
+            logsAddParam.setMessageType(MessageType.Warn);
+            logsAddParam.setLevel(LogsLevel.Low);
+            logsAddParam.setContent(msg);
         }
+        operationLogsService.addLog(logsAddParam);
+        entity.setPayEndTime(System.currentTimeMillis());
+        entity.setPayMillis(entity.getPayEndTime() - entity.getPayStartTime());
         expenseFlowDao.save(entity);
+
         return ResultContent.buildSuccess();
     }
 
@@ -344,23 +371,6 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
             return;
         }
 
-//        // 个人钱包
-//        if (paymentType == PaymentType.UserWallet) {
-//            // 得到消费的金额
-//            BigDecimal amount = entity.getPayAmount();
-//            // 钱包信息
-//            Wallet wallet = walletService.getUserWalletByUserId(entity.getUserId());
-//            if (wallet.getDataState() != DataState.Enable) {
-//                entity.setVerifyError(String.format("支付失败钱包%s", wallet.getDataState().getRemark()));
-//                return;
-//            }
-//            // 检查
-//            if (wallet.getAmount().compareTo(amount) < 0) {
-//                entity.setVerifyError("余额不足");
-//                return;
-//            }
-//        }
-
         // 消费设备信息
         if (deviceInfo.getDeviceType() != null) {
             entity.setPayType(deviceInfo.getDeviceType().getRemark());

+ 9 - 2
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/user/OperationLogsService.java

@@ -24,6 +24,7 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.util.Date;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author TRX
@@ -42,7 +43,14 @@ public class OperationLogsService extends SuperService {
     private static Long ttlTime = 60 * 24 * 60 * 60 * 1000L;
 
     @Async
-    public ResultContent addLog(OperationLogsAddParam param) {
+    public void addLog(OperationLogsAddParam param) {
+        try {
+            log.error("开始等待");
+            TimeUnit.SECONDS.sleep(5);
+            log.error("结束...............");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
         OperationLogs logs = new OperationLogs();
         BeanUtils.copyProperties(param, logs);
         logs.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
@@ -55,7 +63,6 @@ public class OperationLogsService extends SuperService {
             }
         }
         operationLogsDao.save(logs);
-        return ResultContent.buildSuccess();
     }
 
     public ResultContent addLogs(String content, LogsLevel level) {

+ 18 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/util/CommonUtil.java

@@ -1,16 +1,20 @@
 package com.zhongshu.card.server.core.util;
 
+import com.github.microservice.core.util.net.IPUtil;
+import com.github.microservice.models.type.LogServiceType;
 import com.google.common.collect.Lists;
 import com.google.zxing.BarcodeFormat;
 import com.google.zxing.client.j2se.MatrixToImageWriter;
 import com.google.zxing.common.BitMatrix;
 import com.google.zxing.qrcode.QRCodeWriter;
+import com.zhongshu.card.client.model.operLogs.OperationLogsAddParam;
 import com.zhongshu.card.client.utils.DateUtils;
 import com.zhongshu.card.client.utils.ITree;
 import com.zhongshu.card.client.type.Sex;
 import com.zhongshu.card.client.type.school.CardType;
 import com.zhongshu.card.server.core.domain.base.SuperMain;
 import com.zhongshu.card.server.core.util.exception.BusinessException;
+import jakarta.servlet.http.HttpServletRequest;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import net.sourceforge.pinyin4j.PinyinHelper;
@@ -531,4 +535,18 @@ public class CommonUtil {
         return 0;
     }
 
+    public static OperationLogsAddParam initLog(HttpServletRequest request, String userId) {
+        OperationLogsAddParam param = new OperationLogsAddParam();
+        try {
+            param.setUid(userId);
+            param.setUa(request.getHeader("User-Agent"));
+            param.setIp(IPUtil.getRemoteIp(request));
+            param.setUrl(request.getRequestURI());
+            param.setLogServiceType(LogServiceType.FullCard);
+        } catch (Exception e) {
+            log.error("initLog error {}", e.getMessage());
+        }
+        return param;
+    }
+
 }