Codex Assistant
昨天 afeeed281e60466b576fbe74d339634cc5d07b82
backend/src/main/java/com/rongyichuang/judge/service/JudgeService.java
@@ -159,18 +159,28 @@
        }
        if (input.getId() != null) {
            // 更新现有评委
            judge = judgeRepository.findById(input.getId())
                    .orElseThrow(() -> new BusinessException("评委不存在"));
            // 检查用户ID是否被其他评委使用
            Optional<Judge> existingJudgeByUserId = judgeRepository.findByUserId(user.getId());
            if (existingJudgeByUserId.isPresent() && !existingJudgeByUserId.get().getId().equals(input.getId())) {
                throw new BusinessException("该手机号已被其他评委使用");
            }
        } else {
            // 新增评委
            judge = new Judge();
            // 新增评委时检查手机号是否已存在
            if (judgeRepository.existsByPhone(input.getPhone())) {
                throw new BusinessException("PHONE_EXISTS", "手机号码已存在,请使用其他手机号码");
            // 检查该用户是否已是评委
            Optional<Judge> existingJudge = judgeRepository.findByUserId(user.getId());
            if (existingJudge.isPresent()) {
                throw new BusinessException("该手机号已被其他评委使用");
            }
        }
        judge.setName(input.getName());
        judge.setPhone(input.getPhone());
        judge.setPhone(null); // 废弃judge.phone字段,设置为null
        judge.setGender(input.getGender());
        judge.setDescription(input.getDescription());
        judge.setTitle(input.getTitle());
@@ -204,7 +214,19 @@
        JudgeResponse response = new JudgeResponse();
        response.setId(judge.getId());
        response.setName(judge.getName());
        response.setPhone(judge.getPhone());
        // 通过关联的user获取phone
        if (judge.getUserId() != null) {
            Optional<User> userOpt = userService.findById(judge.getUserId());
            if (userOpt.isPresent()) {
                response.setPhone(userOpt.get().getPhone());
            } else {
                response.setPhone(null);
            }
        } else {
            response.setPhone(null);
        }
        response.setGender(judge.getGender());
        response.setDescription(judge.getDescription());
        response.setTitle(judge.getTitle());