diff --git a/src/main/java/com/dl/officialsite/common/enums/CodeEnums.java b/src/main/java/com/dl/officialsite/common/enums/CodeEnums.java index 03f93be2..3910325d 100644 --- a/src/main/java/com/dl/officialsite/common/enums/CodeEnums.java +++ b/src/main/java/com/dl/officialsite/common/enums/CodeEnums.java @@ -17,7 +17,8 @@ public enum CodeEnums { MEMBER_NOT_IN_TEAM("1004", "member not in team"), TEAM_NOT_EXIST("1005", "team not exist"), - LOGIN_IN("2001", "please login"); + LOGIN_IN("2001", "please login"), + TEAM_ADMIN_NOT_EXIST("1006", "team admin not exist"); private String code; diff --git a/src/main/java/com/dl/officialsite/team/TeamService.java b/src/main/java/com/dl/officialsite/team/TeamService.java index 3f18a75d..0df9452d 100644 --- a/src/main/java/com/dl/officialsite/team/TeamService.java +++ b/src/main/java/com/dl/officialsite/team/TeamService.java @@ -1,5 +1,7 @@ package com.dl.officialsite.team; +import static org.bouncycastle.asn1.x500.style.RFC4519Style.member; + import com.dl.officialsite.common.constants.Constants; import com.dl.officialsite.common.enums.CodeEnums; import com.dl.officialsite.common.exception.BizException; @@ -112,6 +114,7 @@ public void join(TeamMemberJoinVO teamMember) { } + @Transactional(rollbackOn = Exception.class) public void approve(TeamMemberApproveVO teamMemberApproveVO) { List memberIds = teamMemberApproveVO.getMemberIds(); List teamMembers = new ArrayList<>(); @@ -127,11 +130,24 @@ public void approve(TeamMemberApproveVO teamMemberApproveVO) { teamMemberRepository.saveAll(teamMembers); //发送邮件 Team team = teamRepository.findById(teamMemberApproveVO.getTeamId()).get(); - String subject = team.getTeamName() + "团队新成员加入申请"; - List mailAddress = new ArrayList<>(); - //todo 这里需要确认有那些管理员 - if (mailAddress.size() != 0) { - emailService.memberExitTeam(mailAddress, subject, subject); + String administratorAddress = team.getAdministrator(); + if (!ObjectUtils.isEmpty(administratorAddress) || !"".equals(administratorAddress)) { + Optional admin = memberRepository.findByAddress(administratorAddress); + if (admin.isPresent()) { + Member member = admin.get(); + String email = member.getEmail(); + String subject = team.getTeamName() + "团队新成员加入申请"; + List mailAddress = new ArrayList<>(); + mailAddress.add(email); + emailService.memberExitTeam(mailAddress, subject, subject); + } else { + throw new BizException(CodeEnums.TEAM_ADMIN_NOT_EXIST.getCode(), + CodeEnums.TEAM_ADMIN_NOT_EXIST.getMsg()); + } + + } else { + throw new BizException(CodeEnums.TEAM_ADMIN_NOT_EXIST.getCode(), + CodeEnums.TEAM_ADMIN_NOT_EXIST.getMsg()); } }