From d9a9d8a2dad1d1e57b184bf8f972a03d654d883a Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期五, 22 七月 2022 15:07:01 +0800
Subject: [PATCH] 优化

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wxpay/UsrWxPayConfigService.java |   63 ++++++++++++++++++++-----------
 1 files changed, 41 insertions(+), 22 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wxpay/UsrWxPayConfigService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wxpay/UsrWxPayConfigService.java
index 0f16fa7..4635542 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wxpay/UsrWxPayConfigService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wxpay/UsrWxPayConfigService.java
@@ -41,10 +41,11 @@
         }
         WxConfigEntity config;
         //鏈缃敮浠樺弬鏁帮紝鍒欎娇鐢ㄩ粯璁ゆ敮浠樺弬鏁�
-        if (pole.getClientId() == null) {
-            config = getById(0);
-        }
         config = getOne(Wrappers.lambdaQuery(WxConfigEntity.class).eq(WxConfigEntity::getClientId, pole.getClientId()).eq(WxConfigEntity::getState, 1));
+//        if (pole.getClientId() == null) {
+              //娌℃湁褰掑睘鐨勭伅鏉嗕娇鐢ㄩ粯璁ら厤缃�
+//            config = getById(15);
+//        }
         if (config == null) {
             throw new BusinessException("鐢ㄦ埛鏈厤缃敮浠橀厤缃�,璇烽厤缃悗閲嶈瘯");
         }
@@ -63,12 +64,15 @@
         config.setAppid(configParam.getAppId());
         config.setAppappid(configParam.getAppAppId());
         if (SecurityUtils.getClientId() != null) {
-            config.setCreateUserId(SecurityUtils.getUserId());
             if (clientService.findClientId()) {
                 config.setClientId(clientService.getClientId());
             } else {
                 config.setClientId(SecurityUtils.getUserId());
             }
+            config.setCreateUserId(SecurityUtils.getUserId());
+        } else {
+            config.setClientId(SecurityUtils.getUserId());
+            config.setCreateUserId(SecurityUtils.getUserId());
         }
         return save(config);
     }
@@ -99,15 +103,19 @@
         LambdaQueryWrapper<WxConfigEntity> wrapper = new LambdaQueryWrapper<>();
         System.out.println("----------------------------" + clientService.findClientId());
         PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
-        if (SecurityUtils.getClientId() != null) {//瀹㈡埛
-            if (clientService.findClientId()) {//浜岀骇瀹㈡埛
+        if (SecurityUtils.getClientId() != null) {
+            //瀹㈡埛
+            if (clientService.findClientId()) {
+                //浜岀骇瀹㈡埛
                 PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
                 wrapper = Wrappers.lambdaQuery(WxConfigEntity.class).eq(WxConfigEntity::getCreateUserId, SecurityUtils.getUserId());
-            } else if (!clientService.findClientId()) {//涓�绾у鎴�
+            } else if (!clientService.findClientId()) {
+                //涓�绾у鎴�
                 PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
                 wrapper = Wrappers.lambdaQuery(WxConfigEntity.class).eq(WxConfigEntity::getClientId, SecurityUtils.getUserId());
             }
-        } else {//绠$悊
+        } else {
+            //绠$悊
             PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
             wrapper = Wrappers.lambdaQuery(WxConfigEntity.class);
         }
@@ -138,6 +146,7 @@
                     wxConfigEntity.setAppappid(wxConfigEntity.getAppappid().replaceAll("(?<=.{4}).*(?=.{4})", "*"));
                     wxConfigEntity.setMchId(wxConfigEntity.getMchId().replaceAll("(?<=.{4}).*(?=.{4})", "*"));
                     wxConfigEntity.setPrivateKey(wxConfigEntity.getPrivateKey().replaceAll("(?<=.{4}).*(?=.{4})", "*"));
+                    wxConfigEntity.setAppSecret(wxConfigEntity.getAppSecret().replaceAll("(?<=.{4}).*(?=.{4})", "*"));
                 }
         );
         return list;
@@ -155,28 +164,38 @@
         /**
          * 鑾峰彇褰撳墠鐢ㄦ埛鎵�鏈夌殑wx鏀粯閰嶇疆
          */
+        List<WxConfigEntity> configList;
         if (SecurityUtils.getClientId() != null) {
             //瀹㈡埛
-            List<WxConfigEntity> configList = list(Wrappers.lambdaQuery(WxConfigEntity.class).eq(WxConfigEntity::getClientId, SecurityUtils.getUserId())
+            configList = list(Wrappers.lambdaQuery(WxConfigEntity.class).eq(WxConfigEntity::getClientId, SecurityUtils.getUserId())
                     .or(
                             user -> {
                                 user.eq(WxConfigEntity::getCreateUserId, SecurityUtils.getUserId());
                             }
                     ));
-            if (configList.size() == 1 && state == 0) {
-                throw new BusinessException("褰撳墠鐢ㄦ埛鍙湁涓�涓敮浠橀厤缃�,涓嶈兘鍋滅敤");
-            }
-            //璁剧疆褰撳墠鐢ㄦ埛鎵�鏈夌殑鏀粯閰嶇疆涓哄仠鐢�
-            configList.forEach(
-                    wxConfigEntity -> {
-                        wxConfigEntity.setState(0);
-                    }
-            );
-            boolean b = updateBatchById(configList);
-            if (!b) {
-                throw new BusinessException("鏇存柊澶辫触");
-            }
+        } else {
+            //绠$悊
+            configList = list(Wrappers.lambdaQuery(WxConfigEntity.class).eq(WxConfigEntity::getClientId, byId.getCreateUserId())
+                    .or(
+                            user -> {
+                                user.eq(WxConfigEntity::getCreateUserId, SecurityUtils.getUserId());
+                            }
+                    ));
         }
+        if (configList.size() == 1 && state == 0) {
+            throw new BusinessException("褰撳墠鐢ㄦ埛鍙湁涓�涓敮浠橀厤缃�,涓嶈兘鍋滅敤");
+        }
+        //璁剧疆褰撳墠鐢ㄦ埛鎵�鏈夌殑鏀粯閰嶇疆涓哄仠鐢�
+        configList.forEach(
+                wxConfigEntity -> {
+                    wxConfigEntity.setState(0);
+                }
+        );
+        boolean b = updateBatchById(configList);
+        if (!b) {
+            throw new BusinessException("鏇存柊澶辫触");
+        }
+
         WxConfigEntity config = new WxConfigEntity();
         config.setConfigId(id);
         config.setState(state);

--
Gitblit v1.9.3