From bd999ecc09fcacf4016edcba85caf9b9696d2140 Mon Sep 17 00:00:00 2001
From: lrj <owen.stl@gmail.com>
Date: 星期六, 04 十月 2025 18:40:31 +0800
Subject: [PATCH] feat: 同步本地改动(认证/评审/用户/选手模块更新;新增/调整 GraphQL schema;小程序个人信息与评审相关页面、配置与资源等)

---
 backend/src/main/java/com/rongyichuang/auth/service/AuthService.java |  108 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 86 insertions(+), 22 deletions(-)

diff --git a/backend/src/main/java/com/rongyichuang/auth/service/AuthService.java b/backend/src/main/java/com/rongyichuang/auth/service/AuthService.java
index bd2fa0f..e9deed6 100644
--- a/backend/src/main/java/com/rongyichuang/auth/service/AuthService.java
+++ b/backend/src/main/java/com/rongyichuang/auth/service/AuthService.java
@@ -19,13 +19,18 @@
 import com.rongyichuang.player.repository.PlayerRepository;
 import com.rongyichuang.user.entity.User;
 import com.rongyichuang.user.repository.UserRepository;
+import com.rongyichuang.common.entity.Media;
+import com.rongyichuang.common.repository.MediaRepository;
+import com.rongyichuang.common.enums.MediaTargetType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.authentication.BadCredentialsException;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
 import java.util.Optional;
 import javax.crypto.Cipher;
 import javax.crypto.spec.IvParameterSpec;
@@ -64,6 +69,12 @@
 
     @Autowired
     private WechatApiService wechatApiService;
+
+    @Autowired
+    private MediaRepository mediaRepository;
+
+    @Value("${app.base-url}")
+    private String baseUrl;
 
     /**
      * 鐢ㄦ埛鐧诲綍
@@ -282,35 +293,46 @@
             logger.warn("鈿狅笍 unionid涓虹┖鎴栫敤鎴峰凡鎵惧埌锛岃烦杩噓nionid鏌ユ壘");
         }
 
-        // 4. 濡傛灉閮芥病鎵惧埌锛屽垱寤烘柊鐢ㄦ埛
+        // 4. 濡傛灉閮芥病鎵惧埌鐢ㄦ埛锛屼笉鍒涘缓鏂扮敤鎴凤紝鍙褰曠櫥褰曚俊鎭�
         if (user == null) {
-            logger.info("鏈壘鍒扮幇鏈夌敤鎴凤紝寮�濮嬪垱寤烘柊鐢ㄦ埛");
-            logger.info("鏂扮敤鎴蜂俊鎭�:");
+            logger.info("鏈壘鍒扮幇鏈夌敤鎴凤紝鏅�氳闂敤鎴蜂笉鍒涘缓user璁板綍锛屽彧璁板綍鐧诲綍淇℃伅");
+            logger.info("璁块棶鐢ㄦ埛淇℃伅:");
             logger.info("- openid: {}", wxLoginRequest.getWxOpenid());
             logger.info("- unionid: {}", wxLoginRequest.getWxUnionid());
             logger.info("- phone: {}", wxLoginRequest.getPhone());
             
+            // 璁板綍鐧诲綍淇℃伅鍒皌_login_record锛屼絾涓嶅垱寤虹敤鎴�
+            logger.info("姝ラ3: 璁板綍璁块棶鐢ㄦ埛鐨勭櫥褰曚俊鎭�");
+            WxLoginRecord loginRecord = null;
             try {
-                user = new User();
-                user.setWxOpenid(wxLoginRequest.getWxOpenid());
-                user.setWxUnionid(wxLoginRequest.getWxUnionid());
-                user.setName("寰俊鐢ㄦ埛"); // 榛樿鍚嶇О锛屽悗缁彲浠ユ洿鏂�
-                user.setPhone(wxLoginRequest.getPhone()); // 濡傛灉鏈夋巿鏉冩墜鏈哄彿
-                
-                user = userRepository.save(user);
-                isNewUser = true;
-                
-                logger.info("鉁� 鎴愬姛鍒涘缓鏂扮殑寰俊鐢ㄦ埛");
-                logger.info("- 鏂扮敤鎴稩D: {}", user.getId());
-                logger.info("- 鏂扮敤鎴峰鍚�: {}", user.getName());
-                logger.info("- 鏂扮敤鎴锋墜鏈哄彿: {}", user.getPhone());
-                
+                loginRecord = wxLoginRecordService.createLoginRecord(
+                        wxLoginRequest.getWxOpenid(),
+                        wxLoginRequest.getWxUnionid(),
+                        null, // 娌℃湁鐢ㄦ埛ID
+                        wxLoginRequest.getLoginIp(),
+                        wxLoginRequest.getDeviceInfo(),
+                        wxLoginRequest.getSessionKey(),
+                        wxLoginRequest.getPhoneAuthorized()
+                );
+                logger.info("鉁� 鎴愬姛鍒涘缓璁块棶鐢ㄦ埛鐧诲綍璁板綍锛岃褰旾D: {}", loginRecord.getId());
             } catch (Exception e) {
-                logger.error("鉂� 鍒涘缓鏂扮敤鎴峰け璐�");
-                logger.error("寮傚父淇℃伅: {}", e.getMessage());
+                logger.error("鉂� 鍒涘缓鐧诲綍璁板綍澶辫触: {}", e.getMessage());
                 logger.error("寮傚父鍫嗘爤:", e);
-                throw new RuntimeException("鍒涘缓鏂扮敤鎴峰け璐�: " + e.getMessage(), e);
+                throw new RuntimeException("鍒涘缓鐧诲綍璁板綍澶辫触: " + e.getMessage(), e);
             }
+            
+            // 杩斿洖璁块棶鐢ㄦ埛鐨勫搷搴旓紙鏃犵敤鎴蜂俊鎭紝鏃爐oken锛�
+            WxLoginResponse response = new WxLoginResponse();
+            response.setSuccess(true);
+            response.setMessage("璁块棶鎴愬姛");
+            response.setSessionKey(wxLoginRequest.getSessionKey());
+            response.setIsNewUser(false);
+            response.setHasEmployee(false);
+            response.setHasJudge(false);
+            response.setHasPlayer(false);
+            
+            logger.info("=== 寰俊璁块棶娴佺▼瀹屾垚锛堟棤鐢ㄦ埛鍒涘缓锛� ===");
+            return response;
         }
 
         // 5. 璁板綍鐧诲綍淇℃伅鍒版柊琛�
@@ -437,8 +459,29 @@
             throw new RuntimeException("鏋勫缓鍩虹鐢ㄦ埛淇℃伅澶辫触: " + e.getMessage(), e);
         }
 
-        // 9. 璁剧疆鎵�鏈夊叧鑱旂殑瑙掕壊淇℃伅
-        logger.info("姝ラ8: 璁剧疆瑙掕壊璇︾粏淇℃伅");
+        // 9. 鑾峰彇骞惰缃敤鎴峰ご鍍�
+        logger.info("姝ラ8: 鑾峰彇鐢ㄦ埛澶村儚");
+        try {
+            List<Media> avatarMediaList = mediaRepository.findByTargetTypeAndTargetIdAndState(
+                MediaTargetType.USER_AVATAR.getValue(), 
+                user.getId(), 
+                1
+            );
+            if (!avatarMediaList.isEmpty()) {
+                Media avatarMedia = avatarMediaList.get(0);
+                String fullAvatarUrl = buildFullMediaUrl(avatarMedia.getPath());
+                userInfo.setAvatarUrl(fullAvatarUrl);
+                logger.info("鉁� 鎵惧埌鐢ㄦ埛澶村儚: {} -> {}", avatarMedia.getPath(), fullAvatarUrl);
+            } else {
+                logger.info("鐢ㄦ埛{}娌℃湁鎵惧埌澶村儚", user.getId());
+            }
+        } catch (Exception e) {
+            logger.error("鉂� 鑾峰彇鐢ㄦ埛澶村儚澶辫触: {}", e.getMessage());
+            logger.error("寮傚父鍫嗘爤:", e);
+        }
+
+        // 10. 璁剧疆鎵�鏈夊叧鑱旂殑瑙掕壊淇℃伅
+        logger.info("姝ラ9: 璁剧疆瑙掕壊璇︾粏淇℃伅");
         
         if (employeeOpt.isPresent()) {
             try {
@@ -520,6 +563,27 @@
     }
 
     /**
+     * 鏋勫缓瀹屾暣鐨勫獟浣揢RL
+     * @param path 濯掍綋璺緞
+     * @return 瀹屾暣鐨刄RL
+     */
+    private String buildFullMediaUrl(String path) {
+        if (path == null || path.trim().isEmpty()) {
+            return null;
+        }
+        
+        // 濡傛灉璺緞宸茬粡鏄畬鏁碪RL锛岀洿鎺ヨ繑鍥�
+        if (path.startsWith("http://") || path.startsWith("https://")) {
+            return path;
+        }
+        
+        // 鏋勫缓瀹屾暣URL
+        String cleanBaseUrl = baseUrl.endsWith("/") ? baseUrl.substring(0, baseUrl.length() - 1) : baseUrl;
+        String cleanPath = path.startsWith("/") ? path : "/" + path;
+        return cleanBaseUrl + cleanPath;
+    }
+
+    /**
      * 瑙e瘑寰俊鎵嬫満鍙�
      */
     public PhoneDecryptResponse decryptPhoneNumber(String encryptedData, String iv, String sessionKey) {

--
Gitblit v1.8.0