From dc643ba44fd2a426263015491268a0f0d6b4671d Mon Sep 17 00:00:00 2001 From: lrj <owen.stl@gmail.com> Date: 星期三, 01 十月 2025 08:39:29 +0800 Subject: [PATCH] 删除包含test、check、fix的文件名的文件 --- backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerService.java | 275 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 260 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerService.java b/backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerService.java index 85464e6..6cb95a5 100644 --- a/backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerService.java +++ b/backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerService.java @@ -8,6 +8,8 @@ import com.rongyichuang.player.entity.Player; import com.rongyichuang.player.repository.ActivityPlayerRepository; import com.rongyichuang.player.repository.PlayerRepository; +import com.rongyichuang.activity.repository.ActivityRepository; +import com.rongyichuang.activity.entity.Activity; import com.rongyichuang.common.entity.Media; import com.rongyichuang.common.repository.MediaRepository; import com.rongyichuang.common.enums.MediaTargetType; @@ -16,6 +18,7 @@ import com.rongyichuang.user.service.UserService; import com.rongyichuang.media.service.MediaV2Service; import com.rongyichuang.media.dto.MediaSaveInput; +import com.rongyichuang.message.service.MessageService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -42,6 +45,9 @@ private PlayerRepository playerRepository; @Autowired + private ActivityRepository activityRepository; + + @Autowired private MediaRepository mediaRepository; @Autowired @@ -52,6 +58,9 @@ @Autowired private MediaV2Service mediaV2Service; + + @Autowired + private MessageService messageService; @@ -99,11 +108,24 @@ } log.info("鏈彂鐜伴噸澶嶆姤鍚�"); - // 4. 鍒涘缓鎶ュ悕璁板綍 + // 4. 鏌ユ壘绗竴闃舵锛屽鏋滄病鏈夊垯浣跨敤娲诲姩鏈韩 + log.info("鏌ユ壘娲诲姩鐨勭涓�闃舵锛屾椿鍔↖D: {}", input.getActivityId()); + Activity firstStage = activityRepository.findFirstStageByActivityId(input.getActivityId()); + Long stageId; + if (firstStage != null) { + stageId = firstStage.getId(); + log.info("鎵惧埌绗竴闃舵锛岄樁娈礗D: {}, 闃舵鍚嶇О: {}", firstStage.getId(), firstStage.getName()); + } else { + // 濡傛灉娌℃湁鎵惧埌绗竴闃舵锛屼娇鐢ㄦ椿鍔ㄦ湰韬綔涓洪樁娈� + stageId = input.getActivityId(); + log.info("鏈壘鍒扮涓�闃舵锛屼娇鐢ㄦ椿鍔ㄦ湰韬綔涓洪樁娈碉紝娲诲姩ID: {}", input.getActivityId()); + } + + // 5. 鍒涘缓鎶ュ悕璁板綍 log.info("寮�濮嬪垱寤烘姤鍚嶈褰�"); ActivityPlayer activityPlayer = new ActivityPlayer(); activityPlayer.setActivityId(input.getActivityId()); - activityPlayer.setStageId(input.getActivityId()); // 鏍规嵁鏂囨。锛氬鏋滄瘮璧涙湭瀹氫箟闃舵锛宻tage_id璁句负activity_id + activityPlayer.setStageId(stageId); // 缁戝畾鍒扮涓�闃舵鎴栨椿鍔ㄦ湰韬� activityPlayer.setPlayerId(player.getId()); activityPlayer.setRegionId(input.getRegionId()); activityPlayer.setProjectName(input.getProjectName()); // 璁剧疆椤圭洰鍚嶇О @@ -114,18 +136,19 @@ ActivityPlayer savedActivityPlayer = activityPlayerRepository.save(activityPlayer); log.info("鎶ュ悕璁板綍鍒涘缓鎴愬姛锛孖D: {}", savedActivityPlayer.getId()); - // 5. 淇濆瓨鍏朵粬濯掍綋鏂囦欢锛堝吋瀹规棫鐗堟湰锛� + // 6. 淇濆瓨鍏朵粬濯掍綋鏂囦欢锛堝吋瀹规棫鐗堟湰锛� if (input.getMediaFiles() != null && !input.getMediaFiles().isEmpty()) { saveMediaFiles(savedActivityPlayer.getId(), input.getMediaFiles()); } - // 6. 淇濆瓨澶村儚濯掍綋璁板綍 + // 7. 淇濆瓨澶村儚濯掍綋璁板綍 if (input.getPlayerInfo().getAvatarMediaId() != null && !input.getPlayerInfo().getAvatarMediaId().trim().isEmpty()) { savePlayerAvatarMedia(player.getId(), input.getPlayerInfo().getAvatarMediaId()); } - // 7. 淇濆瓨闄勪欢濯掍綋璁板綍 + // 8. 淇濆瓨闄勪欢濯掍綋璁板綍 if (input.getAttachmentMediaIds() != null && !input.getAttachmentMediaIds().isEmpty()) { + log.info("寮�濮嬩繚瀛橀檮浠跺獟浣撹褰曪紝鎶ュ悕ID: {}, 闄勪欢鏁伴噺: {}", savedActivityPlayer.getId(), input.getAttachmentMediaIds().size()); saveAttachmentMediaRecords(savedActivityPlayer.getId(), input.getAttachmentMediaIds()); } @@ -329,26 +352,248 @@ } /** - * 淇濆瓨瀛﹀憳澶村儚 - * 鍙傝�僯udge妯″潡鐨勫疄鐜帮紝灏嗗凡涓婁紶鐨勫ご鍍忓獟浣撴枃浠跺叧鑱斿埌瀛﹀憳 + * 瀹℃牳閫氳繃 + */ + public Boolean approveActivityPlayer(Long activityPlayerId, String feedback) { + try { + Optional<ActivityPlayer> activityPlayerOpt = activityPlayerRepository.findById(activityPlayerId); + if (!activityPlayerOpt.isPresent()) { + throw new RuntimeException("鎶ュ悕璁板綍涓嶅瓨鍦�"); + } + + ActivityPlayer activityPlayer = activityPlayerOpt.get(); + activityPlayer.setState(1); // 1=瀹℃牳閫氳繃 + activityPlayer.setFeedback(feedback); + activityPlayerRepository.save(activityPlayer); + + // 鍒涘缓瀹℃牳閫氳繃娑堟伅 + messageService.createApprovalMessage( + activityPlayerId, + activityPlayer.getPlayerId(), + activityPlayer.getProjectName() + ); + + log.info("瀹℃牳閫氳繃鎴愬姛锛宎ctivityPlayerId: {}", activityPlayerId); + return true; + } catch (Exception e) { + log.error("瀹℃牳閫氳繃澶辫触锛宎ctivityPlayerId: {}", activityPlayerId, e); + throw new RuntimeException("瀹℃牳閫氳繃澶辫触", e); + } + } + + /** + * 瀹℃牳椹冲洖 + */ + public Boolean rejectActivityPlayer(Long activityPlayerId, String feedback) { + try { + Optional<ActivityPlayer> activityPlayerOpt = activityPlayerRepository.findById(activityPlayerId); + if (!activityPlayerOpt.isPresent()) { + throw new RuntimeException("鎶ュ悕璁板綍涓嶅瓨鍦�"); + } + + ActivityPlayer activityPlayer = activityPlayerOpt.get(); + activityPlayer.setState(2); // 2=瀹℃牳椹冲洖 + activityPlayer.setFeedback(feedback); + activityPlayerRepository.save(activityPlayer); + + // 鍒涘缓瀹℃牳椹冲洖娑堟伅 + messageService.createRejectionMessage( + activityPlayerId, + activityPlayer.getPlayerId(), + activityPlayer.getProjectName() + ); + + log.info("瀹℃牳椹冲洖鎴愬姛锛宎ctivityPlayerId: {}", activityPlayerId); + return true; + } catch (Exception e) { + log.error("瀹℃牳椹冲洖澶辫触锛宎ctivityPlayerId: {}", activityPlayerId, e); + throw new RuntimeException("瀹℃牳椹冲洖澶辫触", e); + } + } + + /** + * 鏇存柊鎶ュ悕淇℃伅 + */ + public ActivityRegistrationResponse updateActivityRegistration(Long activityPlayerId, ActivityRegistrationInput input) { + try { + log.info("寮�濮嬫洿鏂版姤鍚嶄俊鎭紝鎶ュ悕ID: {}", activityPlayerId); + + // 1. 鏌ユ壘鐜版湁鎶ュ悕璁板綍 + Optional<ActivityPlayer> activityPlayerOpt = activityPlayerRepository.findById(activityPlayerId); + if (!activityPlayerOpt.isPresent()) { + throw new RuntimeException("鎶ュ悕璁板綍涓嶅瓨鍦�"); + } + + ActivityPlayer activityPlayer = activityPlayerOpt.get(); + + // 2. 鏇存柊閫夋墜淇℃伅 + Player player = playerRepository.findById(activityPlayer.getPlayerId()).orElse(null); + if (player != null) { + player.setName(input.getPlayerInfo().getName()); + if (input.getPlayerInfo().getGender() != null) { + player.setGender(input.getPlayerInfo().getGender()); + } + if (input.getPlayerInfo().getEducation() != null) { + player.setEducation(input.getPlayerInfo().getEducation()); + } + if (input.getPlayerInfo().getIntroduction() != null) { + player.setIntroduction(input.getPlayerInfo().getIntroduction()); + } + if (input.getPlayerInfo().getDescription() != null) { + player.setDescription(input.getPlayerInfo().getDescription()); + } + playerRepository.save(player); + + // 鏇存柊鐢ㄦ埛淇℃伅 + updateUserInfo(player, input); + } + + // 3. 鏇存柊鎶ュ悕璁板綍鍩烘湰淇℃伅 + if (input.getProjectName() != null) { + activityPlayer.setProjectName(input.getProjectName()); + } + if (input.getDescription() != null) { + activityPlayer.setDescription(input.getDescription()); + } + if (input.getRegionId() != null) { + activityPlayer.setRegionId(input.getRegionId()); + } + + activityPlayerRepository.save(activityPlayer); + + // 4. 澶勭悊澶村儚鏇存柊 + if (input.getPlayerInfo().getAvatarMediaId() != null && !input.getPlayerInfo().getAvatarMediaId().isEmpty()) { + // 淇濆瓨鏂板ご鍍� + savePlayerAvatarMedia(player.getId(), input.getPlayerInfo().getAvatarMediaId()); + } + + // 5. 澶勭悊姣旇禌鍥剧墖鍜岃棰戞洿鏂� + if (input.getMediaFiles() != null) { + // 鍒犻櫎鏃х殑姣旇禌鍥剧墖鍜岃棰戣褰� + deleteOldSubmissionMedia(activityPlayerId); + // 淇濆瓨鏂扮殑姣旇禌鍥剧墖鍜岃棰� + saveMediaFiles(activityPlayerId, input.getMediaFiles()); + } + + // 6. 澶勭悊闄勪欢鏇存柊 + if (input.getAttachmentMediaIds() != null) { + // 鍒犻櫎鏃ч檮浠惰褰� + deleteOldAttachmentMedia(activityPlayerId); + // 淇濆瓨鏂伴檮浠� + saveAttachmentMediaRecords(activityPlayerId, input.getAttachmentMediaIds()); + } + + log.info("鏇存柊鎶ュ悕淇℃伅鎴愬姛锛屾姤鍚岻D: {}", activityPlayerId); + + ActivityRegistrationResponse response = new ActivityRegistrationResponse(); + response.setSuccess(true); + response.setMessage("鏇存柊鎶ュ悕淇℃伅鎴愬姛"); + response.setRegistrationId(activityPlayerId); + response.setPlayerId(player.getId()); + response.setUserId(player.getUserId()); + response.setActivityPlayerId(activityPlayerId); + + return response; + + } catch (Exception e) { + log.error("鏇存柊鎶ュ悕淇℃伅澶辫触锛屾姤鍚岻D: {}", activityPlayerId, e); + throw new RuntimeException("鏇存柊鎶ュ悕淇℃伅澶辫触: " + e.getMessage(), e); + } + } + + + + /** + * 鍒犻櫎鏃х殑姣旇禌鍥剧墖鍜岃棰戣褰� + */ + private void deleteOldSubmissionMedia(Long activityPlayerId) { + try { + List<Media> oldSubmissionMedia = mediaRepository.findByTargetTypeAndTargetIdAndState( + MediaTargetType.ACTIVITY_PLAYER_SUBMISSION.getValue(), activityPlayerId, 1); + for (Media media : oldSubmissionMedia) { + media.setState(0); // 璁剧疆涓哄垹闄ょ姸鎬� + mediaRepository.save(media); + } + log.info("鍒犻櫎鏃ф瘮璧涘浘鐗�/瑙嗛璁板綍鎴愬姛锛屾姤鍚岻D: {}, 鍒犻櫎鏁伴噺: {}", activityPlayerId, oldSubmissionMedia.size()); + } catch (Exception e) { + log.error("鍒犻櫎鏃ф瘮璧涘浘鐗�/瑙嗛璁板綍澶辫触锛屾姤鍚岻D: {}", activityPlayerId, e); + } + } + + /** + * 鍒犻櫎鏃х殑闄勪欢濯掍綋璁板綍 + */ + private void deleteOldAttachmentMedia(Long activityPlayerId) { + try { + List<Media> oldAttachments = mediaRepository.findByTargetTypeAndTargetIdAndState( + 5, activityPlayerId, 1); // target_type=5 鏄檮浠� + for (Media oldAttachment : oldAttachments) { + oldAttachment.setState(0); // 璁剧疆涓哄垹闄ょ姸鎬� + mediaRepository.save(oldAttachment); + } + log.info("鍒犻櫎鏃ч檮浠惰褰曟垚鍔燂紝鎶ュ悕ID: {}, 鍒犻櫎鏁伴噺: {}", activityPlayerId, oldAttachments.size()); + } catch (Exception e) { + log.error("鍒犻櫎鏃ч檮浠惰褰曞け璐ワ紝鎶ュ悕ID: {}", activityPlayerId, e); + } + } + + /** + * 鏇存柊瀹℃牳鎰忚 + */ + public Boolean updateFeedback(Long activityPlayerId, String feedback) { + try { + Optional<ActivityPlayer> activityPlayerOpt = activityPlayerRepository.findById(activityPlayerId); + if (!activityPlayerOpt.isPresent()) { + throw new RuntimeException("鎶ュ悕璁板綍涓嶅瓨鍦�"); + } + + ActivityPlayer activityPlayer = activityPlayerOpt.get(); + activityPlayer.setFeedback(feedback); + activityPlayerRepository.save(activityPlayer); + + log.info("鏇存柊瀹℃牳鎰忚鎴愬姛锛宎ctivityPlayerId: {}", activityPlayerId); + return true; + } catch (Exception e) { + log.error("鏇存柊瀹℃牳鎰忚澶辫触锛宎ctivityPlayerId: {}", activityPlayerId, e); + throw new RuntimeException("鏇存柊瀹℃牳鎰忚澶辫触", e); + } + } + + /** + * 淇濆瓨鐢ㄦ埛澶村儚 + * 灏嗗凡涓婁紶鐨勫ご鍍忓獟浣撴枃浠跺叧鑱斿埌鐢ㄦ埛 */ private void savePlayerAvatar(Long playerId, Long avatarMediaId) { try { - // 鏌ユ壘鐜版湁鐨勫ご鍍忚褰曞苟鍒犻櫎锛堢‘淇濅竴涓鍛樺彧鏈変竴涓ご鍍忥級 - mediaRepository.deleteByTargetTypeAndTargetId(MediaTargetType.STUDENT_AVATAR.getValue(), playerId); + // 鑾峰彇player瀵瑰簲鐨勭敤鎴稩D + Optional<Player> playerOpt = playerRepository.findById(playerId); + if (!playerOpt.isPresent()) { + log.warn("鏈壘鍒板鍛樿褰曪紝瀛﹀憳ID: {}", playerId); + return; + } + + Player player = playerOpt.get(); + Long userId = player.getUserId(); + if (userId == null) { + log.warn("瀛﹀憳鏈叧鑱旂敤鎴凤紝瀛﹀憳ID: {}", playerId); + return; + } + + // 鏌ユ壘鐜版湁鐨勫ご鍍忚褰曞苟鍒犻櫎锛堢‘淇濅竴涓敤鎴峰彧鏈変竴涓ご鍍忥級 + mediaRepository.deleteByTargetTypeAndTargetId(MediaTargetType.USER_AVATAR.getValue(), userId); // 鏇存柊濯掍綋鏂囦欢鐨則arget淇℃伅 Media avatarMedia = mediaRepository.findById(avatarMediaId).orElse(null); if (avatarMedia != null) { - avatarMedia.setTargetType(MediaTargetType.STUDENT_AVATAR.getValue()); - avatarMedia.setTargetId(playerId); + avatarMedia.setTargetType(MediaTargetType.USER_AVATAR.getValue()); + avatarMedia.setTargetId(userId); mediaRepository.save(avatarMedia); - log.info("瀛﹀憳澶村儚淇濆瓨鎴愬姛锛屽鍛業D: {}, 濯掍綋ID: {}", playerId, avatarMediaId); + log.info("鐢ㄦ埛澶村儚淇濆瓨鎴愬姛锛岀敤鎴稩D: {}, 濯掍綋ID: {}", userId, avatarMediaId); } else { log.warn("鏈壘鍒板ご鍍忓獟浣撴枃浠讹紝濯掍綋ID: {}", avatarMediaId); } } catch (Exception e) { - log.error("淇濆瓨瀛﹀憳澶村儚鏃跺彂鐢熼敊璇紝瀛﹀憳ID: {}, 濯掍綋ID: {}", playerId, avatarMediaId, e); + log.error("淇濆瓨鐢ㄦ埛澶村儚鏃跺彂鐢熼敊璇紝瀛﹀憳ID: {}, 濯掍綋ID: {}", playerId, avatarMediaId, e); } } @@ -385,7 +630,7 @@ MediaSaveInput input = new MediaSaveInput(); input.setTargetType("player"); input.setTargetId(playerId); - input.setUrl(avatarMediaId); // COS璺緞 + input.setPath(avatarMediaId); // COS璺緞 input.setFileName("avatar.jpg"); // 榛樿澶村儚鏂囦欢鍚� input.setFileExt("jpg"); // 鏂囦欢鎵╁睍鍚� input.setFileSize(0L); // 鏂囦欢澶у皬鏆傛椂璁句负0 @@ -411,7 +656,7 @@ MediaSaveInput input = new MediaSaveInput(); input.setTargetType("activity_player"); input.setTargetId(activityPlayerId); - input.setUrl(mediaId); // COS璺緞 + input.setPath(mediaId); // COS璺緞 input.setFileName("attachment"); // 榛樿闄勪欢鏂囦欢鍚� input.setFileExt("jpg"); // 鏂囦欢鎵╁睍鍚� input.setFileSize(0L); // 鏂囦欢澶у皬鏆傛椂璁句负0 -- Gitblit v1.8.0