From 7958f1dddb8a7f4e70d232b07a7703955ecedae0 Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: 星期六, 26 八月 2023 12:45:33 +0800
Subject: [PATCH] 优化diamante

---
 service-acct/src/main/java/com/java110/acct/cmd/payment/QrCodePaymentCmd.java |   72 ++++++++++++++++++++++++++++--------
 1 files changed, 56 insertions(+), 16 deletions(-)

diff --git a/service-acct/src/main/java/com/java110/acct/cmd/payment/QrCodePaymentCmd.java b/service-acct/src/main/java/com/java110/acct/cmd/payment/QrCodePaymentCmd.java
index 2be3171..fbd66ba 100644
--- a/service-acct/src/main/java/com/java110/acct/cmd/payment/QrCodePaymentCmd.java
+++ b/service-acct/src/main/java/com/java110/acct/cmd/payment/QrCodePaymentCmd.java
@@ -2,30 +2,38 @@
 
 import com.alibaba.fastjson.JSONObject;
 import com.java110.acct.smo.IQrCodePaymentSMO;
-import com.java110.acct.smo.impl.QrCodeWechatPaymentAdapt;
 import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.context.ICmdDataFlowContext;
-import com.java110.core.event.cmd.AbstractServiceCmdListener;
+import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.CmdEvent;
 import com.java110.core.factory.CallApiServiceFactory;
 import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.core.log.LoggerFactory;
+import com.java110.dto.community.CommunityDto;
+import com.java110.dto.fee.FeeDetailDto;
+import com.java110.intf.community.ICommunityV1InnerServiceSMO;
+import com.java110.utils.cache.MappingCache;
 import com.java110.utils.constant.CommonConstant;
+import com.java110.utils.constant.WechatConstant;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.factory.ApplicationContextFactory;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.StringUtil;
 import com.java110.vo.ResultVo;
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
 
 /**
  * 鎵爜浠�
  */
 @Java110Cmd(serviceCode = "payment.qrCodePayment")
-public class QrCodePaymentCmd extends AbstractServiceCmdListener {
+public class QrCodePaymentCmd extends Cmd {
     private static Logger logger = LoggerFactory.getLogger(QrCodePaymentCmd.class);
+
+    @Autowired
+    private ICommunityV1InnerServiceSMO communityV1InnerServiceSMOImpl;
 
 
     private IQrCodePaymentSMO qrCodePaymentSMOImpl;
@@ -33,6 +41,8 @@
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
         Assert.hasKeyAndValue(reqJson, "authCode", "鏈寘鍚巿鏉冪爜");
+        Assert.hasKeyAndValue(reqJson, "receivedAmount", "鏈寘鍚敮浠橀噾棰�");
+        Assert.hasKeyAndValue(reqJson, "subServiceCode", "鏈寘鍚敮浠樻帴鍙�");
     }
 
     @Override
@@ -44,29 +54,59 @@
             throw new IllegalArgumentException("鎺堟潈鐮侀敊璇�");
         }
 
-        int pre = Integer.parseInt(authCode.substring(0, 2));
-        if (pre > 24 && pre < 31) { // 鏀粯瀹�
-            qrCodePaymentSMOImpl = ApplicationContextFactory.getBean("qrCodeAliPaymentAdapt", IQrCodePaymentSMO.class);
-        }else{
-            qrCodePaymentSMOImpl = ApplicationContextFactory.getBean("qrCodeWechatPaymentAdapt", IQrCodePaymentSMO.class);
+        String payQrAdapt = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAY_QR_ADAPT);
+
+        if (StringUtil.isEmpty(payQrAdapt)) {
+            int pre = Integer.parseInt(authCode.substring(0, 2));
+            if (pre > 24 && pre < 31) { // 鏀粯瀹�
+                qrCodePaymentSMOImpl = ApplicationContextFactory.getBean("qrCodeAliPaymentAdapt", IQrCodePaymentSMO.class);
+                reqJson.put("primeRate", FeeDetailDto.PRIME_REATE_WECHAT_QRCODE);
+            } else {
+                qrCodePaymentSMOImpl = ApplicationContextFactory.getBean("qrCodeWechatPaymentAdapt", IQrCodePaymentSMO.class);
+                reqJson.put("primeRate", FeeDetailDto.PRIME_REATE_ALI_QRCODE);
+            }
+        } else {
+            qrCodePaymentSMOImpl = ApplicationContextFactory.getBean(payQrAdapt, IQrCodePaymentSMO.class);
+        }
+
+        CommunityDto communityDto = new CommunityDto();
+        communityDto.setCommunityId(reqJson.getString("communityId"));
+        List<CommunityDto> communityDtos = communityV1InnerServiceSMOImpl.queryCommunitys(communityDto);
+
+        Assert.listOnlyOne(communityDtos, "灏忓尯涓嶅瓨鍦�");
+
+        String feeName = communityDtos.get(0).getName();
+        if (!StringUtil.isEmpty(reqJson.getString("payerObjName"))) {
+            feeName += ("-" + reqJson.getString("payerObjName"));
+        }
+
+        if (!StringUtil.isEmpty(reqJson.getString("feeName"))) {
+            feeName += ("-" + reqJson.getString("feeName"));
+        }
+
+        if (feeName.length() > 120) {
+            feeName = feeName.substring(0, 120);
         }
 
         ResultVo resultVo = null;
         try {
-            resultVo = qrCodePaymentSMOImpl.pay(reqJson.getString("communityId"), orderId, receivedAmount, authCode, "");
+            resultVo = qrCodePaymentSMOImpl.pay(reqJson.getString("communityId"), orderId, receivedAmount, authCode, feeName);
         } catch (Exception e) {
+            logger.error("寮傚父浜�", e);
             cmdDataFlowContext.setResponseEntity(ResultVo.error(e.getLocalizedMessage()));
             return;
         }
-        logger.debug("閫傞厤鍣ㄨ繑鍥炵粨鏋�:"+resultVo.toString());
+        logger.debug("閫傞厤鍣ㄨ繑鍥炵粨鏋�:" + resultVo.toString());
         if (ResultVo.CODE_OK != resultVo.getCode()) {
-            cmdDataFlowContext.setResponseEntity(ResultVo.error(resultVo.getMsg(),reqJson));
+            reqJson.put("orderId", orderId);
+            cmdDataFlowContext.setResponseEntity(ResultVo.error(resultVo.getMsg(), reqJson));
             return;
         }
         String appId = cmdDataFlowContext.getReqHeaders().get(CommonConstant.APP_ID);
         String userId = cmdDataFlowContext.getReqHeaders().get(CommonConstant.USER_ID);
-        String paramOut = CallApiServiceFactory.postForApi(appId, reqJson.toJSONString(), "fee.payFee", String.class, userId);
-        cmdDataFlowContext.setResponseEntity(new ResponseEntity(paramOut, HttpStatus.OK));
+        //JSONObject paramOut = CallApiServiceFactory.postForApi(appId, reqJson, "fee.payFee", JSONObject.class, userId);
+        JSONObject paramOut = CallApiServiceFactory.postForApi(appId, reqJson, reqJson.getString("subServiceCode"), JSONObject.class, userId);
+        cmdDataFlowContext.setResponseEntity(ResultVo.createResponseEntity(paramOut));
     }
 
 }

--
Gitblit v1.8.0