TRX hace 1 año
padre
commit
eb9141fe42

+ 1 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/base/SuperMain.java

@@ -17,6 +17,7 @@ public class SuperMain extends SuperEntity {
     @Schema(description = "所属机构ID")
     private String oid;
 
+    @Indexed
     @Schema(description = "所属项目oid")
     private String projectOid;
 

+ 2 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/paySetting/PayOrderSetting.java

@@ -8,6 +8,7 @@ import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import org.springframework.data.mongodb.core.index.Indexed;
 import org.springframework.data.mongodb.core.mapping.Document;
 
 import java.util.Date;
@@ -27,6 +28,7 @@ public class PayOrderSetting extends SuperMain {
     private PaymentType paymentType;
 
     @Schema(description = "所属用户userId")
+    @Indexed
     private String userId;
 
     @Schema(description = "是否启用")

+ 2 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/paySetting/ProjectMainPaySetting.java

@@ -12,6 +12,7 @@ import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import org.springframework.data.mongodb.core.index.Indexed;
 import org.springframework.data.mongodb.core.mapping.DBRef;
 import org.springframework.data.mongodb.core.mapping.Document;
 
@@ -44,6 +45,7 @@ public class ProjectMainPaySetting extends SuperMain {
     @DBRef(lazy = true)
     private ProjectOrgPaySettingInfo childPaySettingInfo;
 
+    @Indexed
     @Schema(description = "项目的支付渠道设置:微信支付、银联支付")
     private PaymentType channelType;
 

+ 1 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/OrganizationUserServiceImpl.java

@@ -157,7 +157,7 @@ public class OrganizationUserServiceImpl extends SuperService {
         if (ObjectUtils.isEmpty(projectInfo)) {
             return ResultContent.buildFail("项目不存在");
         }
-        if (projectInfo.getAuthType() == AuthType.Project) {
+        if (projectInfo.getAuthType() != AuthType.Project) {
             return ResultContent.buildFail("projectOid机构类型不属于项目,请检查参数");
         }
         // 判断是否存在

+ 20 - 12
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/ChinaumsSenselessPayService.java

@@ -36,6 +36,7 @@ import com.zhongshu.card.server.core.domain.payment.ExpenseFlow;
 import com.zhongshu.card.server.core.model.pay.UnionFrictionlessPayFinishModel;
 import com.zhongshu.card.server.core.service.base.SuperService;
 import com.zhongshu.card.server.core.service.paySetting.OrgPayAccountService;
+import com.zhongshu.card.server.core.service.paySetting.ProjectMainPaySettingService;
 import com.zhongshu.card.server.core.service.payment.PayCallService;
 import com.zhongshu.card.server.core.util.BeanUtils;
 import com.zhongshu.card.server.core.util.CommonUtil;
@@ -78,6 +79,9 @@ public class ChinaumsSenselessPayService extends SuperService {
     @Autowired
     ExecQueueService execQueueService;
 
+    @Autowired
+    private ProjectMainPaySettingService projectMainPaySettingService;
+
 
     /**
      * 银联申请签约
@@ -177,14 +181,18 @@ public class ChinaumsSenselessPayService extends SuperService {
         return ResultContent.buildFail("银联请求失败");
     }
 
-    public boolean isSigned(String projectOid, String userId){
-        String accountName = orgPayAccountService.queryOgPayAccount(projectOid, PaymentType.UnionFrictionlessPay);
-        com.github.microservice.pay.client.ret.ResultContent<AccountModel> accountModelResultContent = payProductAccountService.get(accountName);
-        if (!accountModelResultContent.getState().equals(ResultState.Success)) {
-            throw new RuntimeException(accountModelResultContent.getMsg());
+    public boolean isSigned(String projectOid, String userId) {
+//        String accountName = orgPayAccountService.queryOgPayAccount(projectOid, PaymentType.UnionFrictionlessPay);
+//        com.github.microservice.pay.client.ret.ResultContent<AccountModel> accountModelResultContent = payProductAccountService.get(accountName);
+//        if (!accountModelResultContent.getState().equals(ResultState.Success)) {
+//            throw new RuntimeException(accountModelResultContent.getMsg());
+//        }
+//        ChinaumsSenselessConf conf = (ChinaumsSenselessConf) accountModelResultContent.getContent().getConf();
+//        String mid = conf.getMchId();
+        String mid = projectMainPaySettingService.getProjectPaymentMchId(projectOid, PaymentType.UnionFrictionlessPay);
+        if (StringUtils.isEmpty(mid)) {
+            return false;
         }
-        ChinaumsSenselessConf conf = (ChinaumsSenselessConf) accountModelResultContent.getContent().getConf();
-        String mid = conf.getMchId();
         ChinaumsSenselessUserSignInfo topByUserIdAndMidAndExpire = chinaumsSenselessUserSignInfoDao.findTopByUserIdAndMidAndExpire(userId, mid, false);
         return topByUserIdAndMidAndExpire.getContractState().equals(ContractState.SIGNED);
     }
@@ -428,7 +436,7 @@ public class ChinaumsSenselessPayService extends SuperService {
         Map bodyMap = JsonUtil.toObject(JsonUtil.toJson(refundResultContent.getContent()), Map.class);
 
         if (bodyMap.get("respCode").equals("TARGET_PROCESSING")) {
-            execQueueService.add(Map.of("refundOrderNo", refundOrderNo), 5, data->{
+            execQueueService.add(Map.of("refundOrderNo", refundOrderNo), 5, data -> {
                 final ExpenseFlowDao expenseFlowDao = ApplicationContextHolder.getContext().getBean(ExpenseFlowDao.class);
                 final ChinaumsSenselessPayService chinaumsSenselessPayService = ApplicationContextHolder.getContext().getBean(ChinaumsSenselessPayService.class);
                 final PayCallService payCallService = ApplicationContextHolder.getContext().getBean(PayCallService.class);
@@ -438,22 +446,22 @@ public class ChinaumsSenselessPayService extends SuperService {
                     log.info("找不到退款单");
                     return false;
                 }
-                if (refundOrder.getRefundState().equals(RefundState.Refunded) || refundOrder.getRefundState().equals(RefundState.Fail)){
+                if (refundOrder.getRefundState().equals(RefundState.Refunded) || refundOrder.getRefundState().equals(RefundState.Fail)) {
                     log.info("当前退款单状态为已退款或退款失败");
                     return true;
                 }
                 ResultContent<UnionFrictionlessPayFinishModel> refundQuery = chinaumsSenselessPayService.refundQuery(refundOrder.getProjectOid(), refundOrder.getUserId(), refundOrder.getShopOid(), refundOrderNo, true);
-                if (!refundQuery.getState().equals(com.github.microservice.net.ResultState.Success)){
+                if (!refundQuery.getState().equals(com.github.microservice.net.ResultState.Success)) {
                     log.info("查询退款结果失败:{}", refundQuery.getMsg());
                     return false;
                 }
                 log.info("refundStatus:{}", refundQuery.getContent().getRefundStatus());
-                if (refundQuery.getContent().getRefundStatus().equals("PROCESSING") || refundQuery.getContent().getRefundStatus().equals("UNKNOWN")){
+                if (refundQuery.getContent().getRefundStatus().equals("PROCESSING") || refundQuery.getContent().getRefundStatus().equals("UNKNOWN")) {
                     return false;
                 }
                 ResultContent resultContent = payCallService.unionFrictionlessPayRefundFinish(refundQuery.getContent());
                 return resultContent.getState().equals(com.github.microservice.net.ResultState.Success);
-            }, System.currentTimeMillis() + 30*24*60*60*1000L);
+            }, System.currentTimeMillis() + 30 * 24 * 60 * 60 * 1000L);
             return ResultContent.buildContent(refundResultContent.getContent());
         }
         return ResultContent.buildFail(bodyMap.get("respDesc").toString());

+ 15 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/paySetting/PayOrderSettingService.java

@@ -19,6 +19,7 @@ import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StopWatch;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -128,13 +129,19 @@ public class PayOrderSettingService extends SuperService {
      * @return
      */
     public ResultContent<List<PaymentType>> getUserPayment(String userId, String projectOid) {
+        StopWatch stopWatch = new StopWatch();
+        stopWatch.start("查询项目支付");
         // 得到项目支持的付款方式
         List<PaymentType> supportTypes = getProjectPayment(projectOid);
         if (ObjectUtils.isEmpty(supportTypes)) {
             return ResultContent.buildFail("项目暂无开启支付渠道");
         }
+        stopWatch.stop();
+
+
         // 不同的支付渠道 结合当前用户判断
         if (ObjectUtils.isNotEmpty(supportTypes)) {
+            stopWatch.start("查询用户排序");
             // 用户的排序
             List<PayOrderSetting> payOrderSettings = payOrderSettingDao.findByUserIdAndProjectOidOrderBySortAsc(userId, projectOid);
             if (ObjectUtils.isNotEmpty(payOrderSettings)) {
@@ -150,15 +157,20 @@ public class PayOrderSettingService extends SuperService {
                     }
                 });
             }
+            stopWatch.stop();
         }
 
+        stopWatch.start("3");
         // 转换后的
         List<PaymentType> userPaymentTypes = new ArrayList<>();
         if (ObjectUtils.isNotEmpty(supportTypes)) {
             for (PaymentType paymentType : supportTypes) {
                 paymentType = payCallService.turnPaymentType(paymentType);
                 if (paymentType == PaymentType.UnionFrictionlessPay) {
+                    stopWatch.stop();
+                    stopWatch.start("是否签约");
                     boolean b = chinaumsSenselessPayService.isSigned(projectOid, userId);
+                    stopWatch.stop();
                     if (!b) {
                         log.info("用户未开启银联无感支付: {}", userId);
                         continue;
@@ -170,6 +182,9 @@ public class PayOrderSettingService extends SuperService {
                 }
             }
         }
+        stopWatch.start("122");
+        stopWatch.stop();
+        log.info("cx111; {}", stopWatch.prettyPrint());
         return ResultContent.buildSuccess(userPaymentTypes);
     }
 

+ 22 - 2
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/paySetting/ProjectMainPaySettingService.java

@@ -2,7 +2,10 @@ package com.zhongshu.card.server.core.service.paySetting;
 
 import com.github.microservice.net.ResultContent;
 import com.github.microservice.types.payment.PaymentType;
-import com.zhongshu.card.client.model.paySetting.paySetting.*;
+import com.zhongshu.card.client.model.paySetting.paySetting.PayShareListModel;
+import com.zhongshu.card.client.model.paySetting.paySetting.PayShareListParam;
+import com.zhongshu.card.client.model.paySetting.paySetting.ProjectMainPaySettingModel;
+import com.zhongshu.card.client.model.paySetting.paySetting.ProjectMainPaySettingParam;
 import com.zhongshu.card.client.type.paySetting.RegularType;
 import com.zhongshu.card.client.type.paySetting.SettlementRulesType;
 import com.zhongshu.card.client.utils.DateUtils;
@@ -17,7 +20,6 @@ import com.zhongshu.card.server.core.domain.paySetting.ProjectOrgPaySettingInfo;
 import com.zhongshu.card.server.core.service.base.SuperService;
 import com.zhongshu.card.server.core.service.schedule.ScheduleTaskConfigService;
 import com.zhongshu.card.server.core.util.BeanUtils;
-import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -147,6 +149,24 @@ public class ProjectMainPaySettingService extends SuperService {
         return ResultContent.buildSuccess();
     }
 
+    /**
+     * 查询主商户的 商户号
+     *
+     * @param projectOid
+     * @param paymentType
+     * @return
+     */
+    public String getProjectPaymentMchId(String projectOid, PaymentType paymentType) {
+        ProjectMainPaySetting mainPaySetting = projectMainPaySettingDao.findTopByProjectOidAndChannelType(projectOid, paymentType);
+        if (ObjectUtils.isNotEmpty(mainPaySetting)) {
+            ProjectOrgPaySettingInfo paySettingInfo = mainPaySetting.getPaySettingInfo();
+            if (paySettingInfo != null) {
+                return paySettingInfo.getMchId();
+            }
+        }
+        return "";
+    }
+
     /**
      * 得到项目配置
      *

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

@@ -250,7 +250,7 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
     private void commonVerifyExpenseFlow(ExpenseFlow entity) {
         String deviceId = entity.getDeviceId();
         StopWatch stopWatch = new StopWatch();
-        stopWatch.start("设备");
+        stopWatch.start("验证");
 
         // 验证设备
         DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
@@ -270,16 +270,10 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
             entity.setVerifyError(String.format("设备未绑定机构"));
             return;
         }
-        stopWatch.stop();
-
-        stopWatch.start("区域");
         // 设备所属的商户/机构
         entity.setShopOid(deviceInfo.getBeLongOid());
         // 设备区域
         entity.setArea(areaService.toSimpleModel(deviceInfo.getArea()));
-        stopWatch.stop();
-
-        stopWatch.start("项目信息");
         // 填充项目信息
         String projectOid = deviceInfo.getProjectOid();
         Organization projectInfo = organizationDao.findTopByOid(projectOid);
@@ -292,9 +286,6 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
             entity.setVerifyError("未绑定项目信息");
             return;
         }
-        stopWatch.stop();
-
-        stopWatch.start("卡片信息");
         if (entity.getOrderFromType() == OrderFromType.Swipe) {
             CardInfo cardInfo = cardInfoDao.findByCode(entity.getCardNo());
             // 验证卡片
@@ -323,7 +314,6 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
             }
             entity.setMode(iotParam.getMode());
         }
-        stopWatch.stop();
 
         // 验证用户信息
         if (StringUtils.isEmpty(entity.getUserId())) {
@@ -331,7 +321,6 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
             return;
         }
 
-        stopWatch.start("用户信息");
         UserAccount userAccount = userCountDao.findTopByUserId(entity.getUserId());
         if (ObjectUtils.isEmpty(userAccount)) {
             entity.setVerifyError("用户未注册");
@@ -344,9 +333,6 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
             entity.setVerifyError("用户已锁定");
             return;
         }
-        stopWatch.stop();
-
-        stopWatch.start("用户设备权限");
         // 判断设备和用户是否绑定
         DevicePermiss devicePermiss = devicePermissDao.findTopByUserIdAndDeviceIdAndProjectOid(entity.getUserId(), entity.getDeviceId(), entity.getProjectOid());
         if (ObjectUtils.isEmpty(devicePermiss)) {
@@ -357,9 +343,6 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
             entity.setVerifyError("用户设备权限未启用");
             return;
         }
-        stopWatch.stop();
-
-        stopWatch.start("end");
         // 消费设备信息
         if (deviceInfo.getDeviceType() != null) {
             entity.setPayType(deviceInfo.getDeviceType().getRemark());

+ 5 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/payment/PayCallService.java

@@ -37,6 +37,7 @@ import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StopWatch;
 
 import java.math.BigDecimal;
 import java.util.*;
@@ -96,6 +97,8 @@ public class PayCallService extends SuperService {
             return ResultContent.buildFail(String.format("订单不能支付:%s", orderType.getRemark()));
         }
 
+        StopWatch stopWatch = new StopWatch();
+        stopWatch.start("1");
         // 得到用户所有的支付渠道,依次尝试扣款
         ResultContent<List<PaymentType>> resultContent = payOrderSettingService.getUserPayment(entity.getUserId(), entity.getProjectOid());
         if (resultContent.isFailed()) {
@@ -104,6 +107,8 @@ public class PayCallService extends SuperService {
             expenseFlowDao.save(entity);
             return ResultContent.buildFail(msg);
         }
+        stopWatch.stop();
+        log.info("支付过程: {}", stopWatch.prettyPrint());
 
         List<PaymentType> paymentTypes = resultContent.getContent();
         if (ObjectUtils.isEmpty(paymentTypes)) {

+ 0 - 3
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/schedule/TaskContextService.java

@@ -1,15 +1,12 @@
 package com.zhongshu.card.server.core.service.schedule;
 
 import com.zhongshu.card.client.type.ScheduleType;
-import com.zhongshu.card.server.core.dao.payment.ExpenseFlowDao;
 import com.zhongshu.card.server.core.domain.schedule.ScheduleTaskConfig;
 import com.zhongshu.card.server.core.service.payment.PayCallService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.HashMap;
-
 /**
  * @author TRX
  * @date 2024/11/6