From ae3349d2ff53767b5bc9cb30e1bf7e15f9e814ee Mon Sep 17 00:00:00 2001
From: lrj <owen.stl@gmail.com>
Date: 星期五, 03 十月 2025 20:45:44 +0800
Subject: [PATCH] 清理测试代码和调试文件

---
 backend/src/main/java/com/rongyichuang/user/service/UserService.java |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/backend/src/main/java/com/rongyichuang/user/service/UserService.java b/backend/src/main/java/com/rongyichuang/user/service/UserService.java
index 8ee3be7..3f78aa6 100644
--- a/backend/src/main/java/com/rongyichuang/user/service/UserService.java
+++ b/backend/src/main/java/com/rongyichuang/user/service/UserService.java
@@ -5,6 +5,7 @@
 import com.rongyichuang.employee.repository.EmployeeRepository;
 import com.rongyichuang.judge.repository.JudgeRepository;
 import com.rongyichuang.player.repository.PlayerRepository;
+import com.rongyichuang.common.util.UserContextUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
@@ -20,6 +21,9 @@
 @Service
 @Transactional
 public class UserService {
+
+    @Autowired
+    private UserContextUtil userContextUtil;
 
     private static final Logger logger = LoggerFactory.getLogger(UserService.class);
 
@@ -57,6 +61,39 @@
             if (password != null && !password.trim().isEmpty()) {
                 user.setPassword(passwordEncoder.encode(password));
             }
+
+            // 瑕嗙洊 wxOpenid / wxUnionid锛氬鏋滃綋鍓嶇櫥褰曠敤鎴锋湁openid/unionid锛屽苟涓庡簱涓笉鍚岋紝鍒欎互褰撳墠鐧诲綍瑕嗙洊
+            try {
+                Long currentUserId = userContextUtil != null ? userContextUtil.getCurrentUserId() : null;
+                if (currentUserId != null) {
+                    Optional<User> currentUserOpt = userRepository.findById(currentUserId);
+                    if (currentUserOpt.isPresent()) {
+                        User currentUser = currentUserOpt.get();
+                        String currentWxOpenid = currentUser.getWxOpenid();
+                        String currentWxUnionid = currentUser.getWxUnionid();
+
+                        boolean needUpdateWx = false;
+                        if (currentWxOpenid != null && !currentWxOpenid.trim().isEmpty()) {
+                            if (user.getWxOpenid() == null || !currentWxOpenid.equals(user.getWxOpenid())) {
+                                user.setWxOpenid(currentWxOpenid);
+                                needUpdateWx = true;
+                            }
+                        }
+                        if (currentWxUnionid != null && !currentWxUnionid.trim().isEmpty()) {
+                            if (user.getWxUnionid() == null || !currentWxUnionid.equals(user.getWxUnionid())) {
+                                user.setWxUnionid(currentWxUnionid);
+                                needUpdateWx = true;
+                            }
+                        }
+                        if (needUpdateWx) {
+                            logger.info("瑕嗙洊鐢ㄦ埛(wx)鏍囪瘑锛歱hone鍖归厤鐨勭敤鎴稩D={}, 浣跨敤褰撳墠鐧诲綍鐢ㄦ埛ID={} 鐨� openid/unionid 瑕嗙洊", user.getId(), currentUserId);
+                        }
+                    }
+                }
+            } catch (Exception ex) {
+                logger.warn("瑕嗙洊wxOpenid/unionid鏃跺彂鐢熷紓甯革紙蹇界暐锛屼笉闃绘柇鎶ュ悕娴佺▼锛夛細{}", ex.getMessage());
+            }
+
             return userRepository.save(user);
         } else {
             // 鐢ㄦ埛涓嶅瓨鍦紝鍒涘缓鏂扮敤鎴�

--
Gitblit v1.8.0