From 0a48616045ddce1562584543a0e89e5144051fde Mon Sep 17 00:00:00 2001
From: Codex Assistant <codex@example.com>
Date: 星期日, 05 十月 2025 14:52:44 +0800
Subject: [PATCH] 报名审核

---
 backend/src/main/java/com/rongyichuang/judge/service/JudgeService.java |  133 ++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 121 insertions(+), 12 deletions(-)

diff --git a/backend/src/main/java/com/rongyichuang/judge/service/JudgeService.java b/backend/src/main/java/com/rongyichuang/judge/service/JudgeService.java
index 6f8fd7c..c4d82ec 100644
--- a/backend/src/main/java/com/rongyichuang/judge/service/JudgeService.java
+++ b/backend/src/main/java/com/rongyichuang/judge/service/JudgeService.java
@@ -2,6 +2,7 @@
 
 import com.rongyichuang.judge.dto.request.JudgeInput;
 import com.rongyichuang.judge.dto.response.JudgeResponse;
+import com.rongyichuang.judge.dto.response.JudgeStatsResponse;
 import com.rongyichuang.judge.entity.Judge;
 import com.rongyichuang.tag.entity.Tag;
 import com.rongyichuang.judge.repository.JudgeRepository;
@@ -12,11 +13,15 @@
 import com.rongyichuang.common.service.MediaService;
 import com.rongyichuang.common.exception.BusinessException;
 import com.rongyichuang.common.enums.MediaTargetType;
+import com.rongyichuang.common.util.UserContextUtil;
 import com.rongyichuang.tag.repository.TagRepository;
+import com.rongyichuang.user.service.UserService;
+import com.rongyichuang.user.entity.User;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.data.domain.Sort;
-import org.springframework.data.domain.Sort;
+import org.springframework.jdbc.core.JdbcTemplate;
+import java.util.Optional;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.util.StringUtils;
 import org.slf4j.Logger;
@@ -36,16 +41,24 @@
     private final TagRepository tagRepository;
     private final MediaRepository mediaRepository;
     private final MediaService mediaService;
+    private final UserService userService;
+    private final JdbcTemplate jdbcTemplate;
+    private final UserContextUtil userContextUtil;
     
-    @Value("${app.media-url:${app.media.url:}}")
+    @Value("${app.media-url}")
     private String mediaBaseUrl;
 
     public JudgeService(JudgeRepository judgeRepository, TagRepository tagRepository, 
-                       MediaRepository mediaRepository, MediaService mediaService) {
+                       MediaRepository mediaRepository, MediaService mediaService,
+                       UserService userService, JdbcTemplate jdbcTemplate,
+                       UserContextUtil userContextUtil) {
         this.judgeRepository = judgeRepository;
         this.tagRepository = tagRepository;
         this.mediaRepository = mediaRepository;
         this.mediaService = mediaService;
+        this.userService = userService;
+        this.jdbcTemplate = jdbcTemplate;
+        this.userContextUtil = userContextUtil;
     }
 
     public List<JudgeResponse> findAll() {
@@ -66,9 +79,85 @@
                 .orElse(null);
     }
 
+    /**
+     * 鏍规嵁鐢ㄦ埛ID鑾峰彇璇勫淇℃伅
+     */
+    public Judge findByUserId(Long userId) {
+        Optional<Judge> judge = judgeRepository.findByUserId(userId);
+        return judge.orElse(null);
+    }
+
+    /**
+     * 鑾峰彇褰撳墠璇勫鐨勭粺璁℃暟鎹�
+     */
+    public JudgeStatsResponse getJudgeStats() {
+        log.info("鑾峰彇璇勫缁熻鏁版嵁");
+        
+        Long currentJudgeId = userContextUtil.getCurrentJudgeId();
+        if (currentJudgeId == null) {
+            throw new RuntimeException("褰撳墠鐢ㄦ埛涓嶆槸璇勫锛屾棤娉曟煡璇㈣瘎瀹$粺璁�");
+        }
+        
+        // 鏌ヨ鎴戞湭璇勫鐨勬暟閲�
+        String unReviewedSql = "SELECT COUNT(*) FROM t_activity_player ap " +
+                              "WHERE EXISTS (" +
+                              "  SELECT 1 FROM t_activity_judge aj " +
+                              "  WHERE ap.activity_id = aj.activity_id " +
+                              "  AND ap.stage_id = aj.stage_id " +
+                              "  AND aj.judge_id = ? " +
+                              ") " +
+                              "AND NOT EXISTS (" +
+                              "  SELECT 1 FROM t_activity_player_rating apr " +
+                              "  WHERE ap.id = apr.activity_player_id " +
+                              "  AND apr.judge_id = ? " +
+                              "  AND apr.state = 1 " +
+                              ") " +
+                              "AND ap.state = 1";
+        Integer unReviewedCount = jdbcTemplate.queryForObject(unReviewedSql, Integer.class, currentJudgeId, currentJudgeId);
+
+        // 鏌ヨ鎴戝凡璇勫鐨勬暟閲�
+        String reviewedSql = "SELECT COUNT(*) FROM t_activity_player ap " +
+                            "WHERE EXISTS (" +
+                            "  SELECT 1 FROM t_activity_judge aj " +
+                            "  WHERE ap.activity_id = aj.activity_id " +
+                            "  AND ap.stage_id = aj.stage_id " +
+                            "  AND aj.judge_id = ? " +
+                            ") " +
+                            "AND EXISTS (" +
+                            "  SELECT 1 FROM t_activity_player_rating apr " +
+                            "  WHERE ap.id = apr.activity_player_id " +
+                            "  AND apr.judge_id = ? " +
+                            "  AND apr.state = 1 " +
+                            ") " +
+                            "AND ap.state = 1";
+        Integer reviewedCount = jdbcTemplate.queryForObject(reviewedSql, Integer.class, currentJudgeId, currentJudgeId);
+
+        // 璁$畻鎬绘暟
+        Integer totalCount = (unReviewedCount != null ? unReviewedCount : 0) + (reviewedCount != null ? reviewedCount : 0);
+
+        log.info("璇勫缁熻鏁版嵁 - 寰呰瘎瀹�: {}, 宸茶瘎瀹�: {}, 鎬绘暟: {}", unReviewedCount, reviewedCount, totalCount);
+
+        return new JudgeStatsResponse(
+            unReviewedCount != null ? unReviewedCount : 0,
+            reviewedCount != null ? reviewedCount : 0,
+            totalCount
+        );
+    }
+
     @Transactional
     public JudgeResponse save(JudgeInput input) {
         Judge judge;
+        User user;
+        
+        // 澶勭悊User琛ㄩ�昏緫
+        if (input.getPassword() != null && !input.getPassword().trim().isEmpty() && !"鈥⑩�⑩�⑩�⑩�⑩�⑩�⑩��".equals(input.getPassword())) {
+            // 鏈夊瘑鐮佷笖涓嶆槸鍗犱綅绗︽椂锛屽垱寤烘垨鏇存柊鐢ㄦ埛锛堝寘鍚瘑鐮侊級
+            user = userService.findOrCreateUserByPhone(input.getPhone(), input.getName(), input.getPassword());
+        } else {
+            // 鏃犲瘑鐮佹垨鏄崰浣嶇鏃讹紝鍙洿鏂扮敤鎴峰熀鏈俊鎭紙涓嶆洿鏂板瘑鐮侊級
+            user = userService.findOrCreateUserByPhone(input.getPhone(), input.getName(), null);
+        }
+
         if (input.getId() != null) {
             judge = judgeRepository.findById(input.getId())
                     .orElseThrow(() -> new BusinessException("璇勫涓嶅瓨鍦�"));
@@ -87,6 +176,7 @@
         judge.setTitle(input.getTitle());
         judge.setCompany(input.getCompany());
         judge.setIntroduction(input.getIntroduction());
+        judge.setUserId(user.getId()); // 璁剧疆鍏宠仈鐨勭敤鎴稩D
         // 澶村儚淇℃伅閫氳繃t_media琛ㄧ殑target_type鍜宼arget_id鍏宠仈
 
         // 璁剧疆涓撲笟鏍囩
@@ -184,15 +274,31 @@
      * 淇濆瓨濯掍綋淇℃伅
      */
     public MediaResponse saveMediaInfo(MediaInput input) {
-        Media media = mediaService.saveMedia(
-            input.getName(),
-            input.getPath(),
-            input.getFileSize(),
-            input.getFileExt(),
-            input.getMediaType(),
-            input.getTargetType(),
-            input.getTargetId()
-        );
+        Media media;
+        
+        // 濡傛灉鏈夌缉鐣ュ浘璺緞锛屼娇鐢ㄦ敮鎸佺缉鐣ュ浘鐨勬柟娉�
+        if (input.getThumbPath() != null && !input.getThumbPath().trim().isEmpty()) {
+            media = mediaService.saveMedia(
+                input.getName(),
+                input.getPath(),
+                input.getFileSize(),
+                input.getFileExt(),
+                input.getMediaType(),
+                input.getTargetType(),
+                input.getTargetId(),
+                input.getThumbPath()
+            );
+        } else {
+            media = mediaService.saveMedia(
+                input.getName(),
+                input.getPath(),
+                input.getFileSize(),
+                input.getFileExt(),
+                input.getMediaType(),
+                input.getTargetType(),
+                input.getTargetId()
+            );
+        }
         
         MediaResponse response = new MediaResponse();
         response.setId(media.getId());
@@ -203,6 +309,9 @@
         response.setMediaType(media.getMediaType());
         response.setTargetType(media.getTargetType());
         response.setTargetId(media.getTargetId());
+        response.setThumbPath(media.getThumbPath());
+        response.setDuration(media.getDuration());
+        response.setDescription(media.getDescription());
         
         return response;
     }

--
Gitblit v1.8.0