From 7ad9c3c93f0cc103347ae2e2429e0122fb512e24 Mon Sep 17 00:00:00 2001
From: lrj <owen.stl@gmail.com>
Date: 星期三, 01 十月 2025 21:26:12 +0800
Subject: [PATCH] feat: 修复员工管理功能并优化UI

---
 backend/src/main/java/com/rongyichuang/activity/service/ActivityService.java |  116 ++++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 88 insertions(+), 28 deletions(-)

diff --git a/backend/src/main/java/com/rongyichuang/activity/service/ActivityService.java b/backend/src/main/java/com/rongyichuang/activity/service/ActivityService.java
index a0ad78b..75bebca 100644
--- a/backend/src/main/java/com/rongyichuang/activity/service/ActivityService.java
+++ b/backend/src/main/java/com/rongyichuang/activity/service/ActivityService.java
@@ -16,6 +16,8 @@
 import com.rongyichuang.common.dto.PageResponse;
 import com.rongyichuang.rating.entity.RatingScheme;
 import com.rongyichuang.rating.repository.RatingSchemeRepository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Example;
 import org.springframework.data.domain.ExampleMatcher;
@@ -37,6 +39,8 @@
 @Service
 @Transactional
 public class ActivityService {
+    
+    private static final Logger log = LoggerFactory.getLogger(ActivityService.class);
     
     @Autowired
     private ActivityRepository activityRepository;
@@ -70,9 +74,18 @@
         List<ActivityResponse> content = page.getContent().stream()
             .map(activity -> {
                 ActivityResponse response = new ActivityResponse(activity);
-                // 璁剧疆鍙傝禌浜烘暟锛堝鏍搁�氳繃鐨勬姤鍚嶆暟閲忥級
-                Long playerCountLong = activityPlayerRepository.countByActivityId(activity.getId());
-                int playerCount = playerCountLong != null ? playerCountLong.intValue() : 0;
+                // 璁剧疆鍙傝禌浜烘暟锛堝彧缁熻绗竴闃舵鐨勫鏍搁�氳繃瀛﹀憳浜烘暟锛�
+                int playerCount = 0;
+                Activity firstStage = activityRepository.findFirstStageByActivityId(activity.getId());
+                if (firstStage != null) {
+                    // 濡傛灉鏈夌涓�闃舵锛岀粺璁$涓�闃舵鐨勫鏍搁�氳繃浜烘暟
+                    Long playerCountLong = activityPlayerRepository.countByStageIdAndState(firstStage.getId(), 1);
+                    playerCount = playerCountLong != null ? playerCountLong.intValue() : 0;
+                } else {
+                    // 濡傛灉娌℃湁闃舵锛岀粺璁℃椿鍔ㄦ湰韬殑瀹℃牳閫氳繃浜烘暟
+                    Long playerCountLong = activityPlayerRepository.countByActivityIdAndState(activity.getId(), 1);
+                    playerCount = playerCountLong != null ? playerCountLong.intValue() : 0;
+                }
                 response.setPlayerCount(playerCount);
                 return response;
             })
@@ -176,6 +189,9 @@
         // 淇濆瓨姣旇禌
         activity = activityRepository.save(activity);
         
+        // 璁板綍鏃ュ織浠ヤ究璋冭瘯
+        log.info("淇濆瓨姣旇禌鎴愬姛锛屾瘮璧汭D: {}, 姣旇禌鍚嶇О: {}", activity.getId(), activity.getName());
+        
         // 濡傛灉鏄瘮璧涗笖鏈夐樁娈典俊鎭紝淇濆瓨闃舵
         if (input.isMainActivity() && input.getStages() != null && !input.getStages().isEmpty()) {
             saveActivityStages(activity.getId(), input.getStages());
@@ -255,7 +271,11 @@
                 stage.setRatingSchemeId(activity.getRatingSchemeId());
             }
             
-            activityRepository.save(stage);
+            // 淇濆瓨闃舵骞惰幏鍙栬嚜澧濱D
+            stage = activityRepository.save(stage);
+            
+            // 璁板綍鏃ュ織浠ヤ究璋冭瘯
+            log.info("淇濆瓨闃舵鎴愬姛锛岄樁娈礗D: {}, 闃舵鍚嶇О: {}", stage.getId(), stage.getName());
         }
     }
     
@@ -264,14 +284,20 @@
      */
     private void saveActivityJudges(Long activityId, List<ActivityJudgeInput> judgeInputs) {
         if (judgeInputs == null || judgeInputs.isEmpty()) {
+            log.info("娌℃湁璇勫闇�瑕佷繚瀛橈紝姣旇禌ID: {}", activityId);
             return;
         }
+        
+        log.info("寮�濮嬩繚瀛樿瘎濮旓紝姣旇禌ID: {}, 璇勫鏁伴噺: {}", activityId, judgeInputs.size());
         
         // 鑾峰彇姣旇禌鐨勬墍鏈夐樁娈碉紙濡傛灉鏈夌殑璇濓級
         List<Activity> stages = activityRepository.findByPidAndStateOrderByCreateTimeAsc(activityId, 1);
         
         // 淇濆瓨璇勫鍏宠仈
         for (ActivityJudgeInput judgeInput : judgeInputs) {
+            log.info("澶勭悊璇勫: ID={}, 濮撳悕={}, 闃舵IDs={}", 
+                judgeInput.getJudgeId(), judgeInput.getJudgeName(), judgeInput.getStageIds());
+            
             // 鍏堝垹闄よ璇勫鐨勭幇鏈夊叧鑱�
             activityJudgeRepository.deleteByActivityIdAndJudgeId(activityId, judgeInput.getJudgeId());
             
@@ -280,12 +306,14 @@
                 if (stages.isEmpty()) {
                     // 姣旇禌娌℃湁闃舵锛岀洿鎺ュ叧鑱斿埌姣旇禌锛坰tage_id涓簄ull琛ㄧず鎵�鏈夐樁娈碉級
                     ActivityJudge activityJudge = new ActivityJudge(activityId, judgeInput.getJudgeId(), null);
-                    activityJudgeRepository.save(activityJudge);
+                    activityJudge = activityJudgeRepository.save(activityJudge);
+                    log.info("淇濆瓨璇勫鍏宠仈鎴愬姛: 姣旇禌ID={}, 璇勫ID={}, 闃舵ID=null", activityId, judgeInput.getJudgeId());
                 } else {
                     // 涓烘瘡涓樁娈靛垱寤哄叧鑱�
                     for (Activity stage : stages) {
                         ActivityJudge activityJudge = new ActivityJudge(activityId, judgeInput.getJudgeId(), stage.getId());
-                        activityJudgeRepository.save(activityJudge);
+                        activityJudge = activityJudgeRepository.save(activityJudge);
+                        log.info("淇濆瓨璇勫鍏宠仈鎴愬姛: 姣旇禌ID={}, 璇勫ID={}, 闃舵ID={}", activityId, judgeInput.getJudgeId(), stage.getId());
                     }
                 }
             } else {
@@ -294,7 +322,8 @@
                     // 濡傛灉stageId绛変簬褰撳墠姣旇禌ID锛岃〃绀鸿瘎濮旇礋璐f暣涓瘮璧涳紝stage_id璁句负null
                     Long actualStageId = stageId.equals(activityId) ? null : stageId;
                     ActivityJudge activityJudge = new ActivityJudge(activityId, judgeInput.getJudgeId(), actualStageId);
-                    activityJudgeRepository.save(activityJudge);
+                    activityJudge = activityJudgeRepository.save(activityJudge);
+                    log.info("淇濆瓨璇勫鍏宠仈鎴愬姛: 姣旇禌ID={}, 璇勫ID={}, 闃舵ID={}", activityId, judgeInput.getJudgeId(), actualStageId);
                 }
             }
         }
@@ -332,39 +361,23 @@
         // 鑾峰彇鎵�鏈夌姸鎬佷负1鐨勬椿鍔�
         List<Activity> allActivities = activityRepository.findByStateOrderByPidAscNameAsc(1);
         
-        // 杩囨护锛氬彧淇濈暀姣旇禌闃舵锛坧id>0锛�
+        // 杩囨护锛氬彧淇濈暀涓绘瘮璧涳紙pid=0锛�
         List<Activity> filteredActivities = allActivities.stream()
-            .filter(activity -> activity.getPid() > 0)
+            .filter(activity -> activity.getPid() == 0)
             .collect(Collectors.toList());
         
-        // 杞崲涓篈ctivityResponse锛屽寘鍚埗姣旇禌淇℃伅
+        // 杞崲涓篈ctivityResponse
         List<ActivityResponse> result = filteredActivities.stream()
             .map(activity -> {
                 ActivityResponse response = new ActivityResponse(activity);
-                // 璁剧疆鍙傝禌浜烘暟锛堝鏍搁�氳繃鐨勬姤鍚嶆暟閲忥級
+                // 璁剧疆鍙傝禌浜烘暟锛堟墍鏈夐樁娈电殑鎶ュ悕鏁伴噺鎬诲拰锛�
                 Long playerCountLong = activityPlayerRepository.countByActivityId(activity.getId());
                 int playerCount = playerCountLong != null ? playerCountLong.intValue() : 0;
                 response.setPlayerCount(playerCount);
                 
-                // 璁剧疆鐖舵瘮璧涗俊鎭�
-                Optional<Activity> parentOpt = activityRepository.findById(activity.getPid());
-                if (parentOpt.isPresent()) {
-                    Activity parent = parentOpt.get();
-                    response.setParent(new ActivityResponse(parent));
-                }
-                
                 return response;
             })
-            .sorted((a, b) -> {
-                // 鍏堟寜鐖舵瘮璧涘悕绉版帓搴忥紝鍐嶆寜闃舵鍚嶇О鎺掑簭
-                if (a.getParent() != null && b.getParent() != null) {
-                    int parentCompare = a.getParent().getName().compareTo(b.getParent().getName());
-                    if (parentCompare != 0) {
-                        return parentCompare;
-                    }
-                }
-                return a.getName().compareTo(b.getName());
-            })
+            .sorted((a, b) -> a.getName().compareTo(b.getName()))
             .collect(Collectors.toList());
         
         return result;
@@ -388,6 +401,53 @@
     }
     
     /**
+     * 鑾峰彇鎵�鏈夋瘮璧涢樁娈碉紙鐢ㄤ簬璇勫椤甸潰涓嬫媺閫夋嫨锛�
+     * 杩斿洖鎵�鏈夌姸鎬佷负1涓攑id>0鐨勬瘮璧涢樁娈�
+     */
+    public List<ActivityResponse> findAllStagesForSelection() {
+        // 鑾峰彇鎵�鏈夌姸鎬佷负1鐨勬椿鍔�
+        List<Activity> allActivities = activityRepository.findByStateOrderByPidAscNameAsc(1);
+        
+        // 鍒嗙涓绘瘮璧涘拰闃舵
+        Map<Long, Activity> parentActivitiesMap = allActivities.stream()
+            .filter(activity -> activity.getPid() == 0)
+            .collect(Collectors.toMap(Activity::getId, activity -> activity));
+        
+        // 杩囨护锛氬彧淇濈暀姣旇禌闃舵锛坧id>0锛�
+        List<Activity> filteredStages = allActivities.stream()
+            .filter(activity -> activity.getPid() > 0)
+            .collect(Collectors.toList());
+        
+        // 杞崲涓篈ctivityResponse
+        List<ActivityResponse> result = filteredStages.stream()
+            .map(activity -> {
+                ActivityResponse response = new ActivityResponse(activity);
+                // 璁剧疆鍙傝禌浜烘暟锛堝鏍搁�氳繃鐨勬姤鍚嶆暟閲忥級
+                Long playerCountLong = activityPlayerRepository.countByActivityId(activity.getId());
+                int playerCount = playerCountLong != null ? playerCountLong.intValue() : 0;
+                response.setPlayerCount(playerCount);
+                
+                // 鎵嬪姩璁剧疆parent淇℃伅
+                Activity parentActivity = parentActivitiesMap.get(activity.getPid());
+                if (parentActivity != null) {
+                    ActivityResponse parentResponse = new ActivityResponse(parentActivity);
+                    response.setParent(parentResponse);
+                }
+                
+                return response;
+            })
+            .sorted((a, b) -> {
+                // 鍏堟寜鐖舵瘮璧汭D鎺掑簭锛屽啀鎸夐樁娈靛悕绉版帓搴�
+                int pidCompare = Long.compare(a.getPid(), b.getPid());
+                if (pidCompare != 0) return pidCompare;
+                return a.getName().compareTo(b.getName());
+            })
+            .collect(Collectors.toList());
+        
+        return result;
+    }
+    
+    /**
      * 缁熻姣旇禌鏁伴噺
      */
     public long countActiveActivities() {

--
Gitblit v1.8.0