| | |
| | | import com.rongyichuang.common.exception.BusinessException; |
| | | import com.rongyichuang.common.enums.MediaTargetType; |
| | | 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; |
| | |
| | | private final TagRepository tagRepository; |
| | | private final MediaRepository mediaRepository; |
| | | private final MediaService mediaService; |
| | | private final UserService userService; |
| | | |
| | | @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) { |
| | | this.judgeRepository = judgeRepository; |
| | | this.tagRepository = tagRepository; |
| | | this.mediaRepository = mediaRepository; |
| | | this.mediaService = mediaService; |
| | | this.userService = userService; |
| | | } |
| | | |
| | | public List<JudgeResponse> findAll() { |
| | |
| | | @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("评委不存在")); |
| | |
| | | judge.setTitle(input.getTitle()); |
| | | judge.setCompany(input.getCompany()); |
| | | judge.setIntroduction(input.getIntroduction()); |
| | | judge.setUserId(user.getId()); // 设置关联的用户ID |
| | | // 头像信息通过t_media表的target_type和target_id关联 |
| | | |
| | | // 设置专业标签 |