Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:add function get team detail #40

Merged
merged 5 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/dl/officialsite/team/TeamController.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ BaseResponse getTeams(@RequestBody TeamQueryVo teamQueryVo, @RequestParam String

@GetMapping("/id")
BaseResponse getTeamById(@RequestParam Long teamId, @RequestParam String address) {
Team team = teamService.getTeamById(teamId);
return BaseResponse.successWithData(team);
TeamsMembersVo teamAndMembers = teamService.getTeamById(teamId);
return BaseResponse.successWithData(teamAndMembers);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public interface TeamMemberRepository extends JpaRepository<TeamMember, Long> {
@Query(value = "select member_id from team_member where team_id = :team_id", nativeQuery = true)
List<Long> findByTeamId(@Param("team_id")Long teamId);

@Query(value = "select member_id from team_member where team_id = :team_id and status = :status",
nativeQuery =
true)
List<Long> findByTeamIdStatus(@Param("team_id")Long teamId, @Param("status")int status);

@Query(value = "select * from team_member where team_id = :team_id and member_id = :member_id",
nativeQuery = true)
Optional<TeamMember> findByTeamAndMember(@Param("team_id")Long teamId, @Param("member_id")Long memberId);
Expand Down
47 changes: 37 additions & 10 deletions src/main/java/com/dl/officialsite/team/TeamService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -77,7 +79,7 @@ public javax.persistence.criteria.Predicate toPredicate(
TeamsMembersVo teamsMembersVo = new TeamsMembersVo();
BeanUtils.copyProperties(team, teamsMembersVo);
List<Member> members = new ArrayList<>();
List<Long> memberIds = teamMemberRepository.findByTeamId(team.getId());
List<Long> memberIds = teamMemberRepository.findByTeamIdStatus(team.getId(), teamQueryVo.getStatus());
memberIds.stream().forEach(memberId -> {
Member member = memberRepository.findById(memberId).get();
members.add(member);
Expand All @@ -90,11 +92,11 @@ public javax.persistence.criteria.Predicate toPredicate(

public void join(TeamMemberJoinVO teamMember) {
Member member = memberRepository.findById(teamMember.getMemberId()).get();
if (ObjectUtils.isEmpty(member.getTelegramId()) || ObjectUtils.isEmpty(
/* if (ObjectUtils.isEmpty(member.getTelegramId()) || ObjectUtils.isEmpty(
member.getWechatId())) {
throw new BizException(CodeEnums.TELEGRAM_WECHAT_NOT_BIND.getCode(),
CodeEnums.TELEGRAM_WECHAT_NOT_BIND.getMsg());
}
}*/
//判断是否已经退出过团队
Optional<TeamMember> optional = teamMemberRepository.findByTeamAndMember(
teamMember.getTeamId()
Expand All @@ -112,6 +114,7 @@ public void join(TeamMemberJoinVO teamMember) {

}

@Transactional(rollbackOn = Exception.class)
public void approve(TeamMemberApproveVO teamMemberApproveVO) {
List<Long> memberIds = teamMemberApproveVO.getMemberIds();
List<TeamMember> teamMembers = new ArrayList<>();
Expand All @@ -127,11 +130,24 @@ public void approve(TeamMemberApproveVO teamMemberApproveVO) {
teamMemberRepository.saveAll(teamMembers);
//发送邮件
Team team = teamRepository.findById(teamMemberApproveVO.getTeamId()).get();
String subject = team.getTeamName() + "团队新成员加入申请";
List<String> mailAddress = new ArrayList<>();
//todo 这里需要确认有那些管理员
if (mailAddress.size() != 0) {
emailService.memberExitTeam(mailAddress, subject, subject);
String administratorAddress = team.getAdministrator();
if (!ObjectUtils.isEmpty(administratorAddress) || !"".equals(administratorAddress)) {
Optional<Member> admin = memberRepository.findByAddress(administratorAddress);
if (admin.isPresent()) {
Member member = admin.get();
String email = member.getEmail();
String subject = team.getTeamName() + "团队新成员加入申请";
List<String> 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());
}
}

Expand Down Expand Up @@ -174,16 +190,27 @@ public List<TeamVO> getMemberRole(Long memberId) {
Team team = teamRepository.findById(teamMember.getTeamId()).get();
TeamVO teamVO = new TeamVO();
BeanUtils.copyProperties(team, teamVO);
teamVO.setStatus(teamMember.getStatus());
teamVOS.add(teamVO);
});
return teamVOS;
}
}

public Team getTeamById(Long teamId) {
public TeamsMembersVo getTeamById(Long teamId) {
Optional<Team> optional = teamRepository.findById(teamId);
if (optional.isPresent()) {
return optional.get();
TeamsMembersVo teamsMembersVo = new TeamsMembersVo();
Team team = optional.get();
List<Member> members = new ArrayList<>();
List<Long> memberIds = teamMemberRepository.findByTeamId(team.getId());
memberIds.stream().forEach(memberId -> {
Member member = memberRepository.findById(memberId).get();
members.add(member);
});
teamsMembersVo.setMembers(members);
BeanUtils.copyProperties(team, teamsMembersVo);
return teamsMembersVo;
} else {
throw new BizException(CodeEnums.TEAM_NOT_EXIST.getCode(),
CodeEnums.TEAM_NOT_EXIST.getMsg());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/dl/officialsite/team/vo/TeamQueryVo.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
public class TeamQueryVo {

private String teamName;

private int status;
}
4 changes: 4 additions & 0 deletions src/main/java/com/dl/officialsite/team/vo/TeamVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
@Data
public class TeamVO {

private Long id;

private String teamName;

private String teamProfile;
Expand All @@ -22,5 +24,7 @@ public class TeamVO {
// dao admin , core contributor, builder
private String authority;

private int status;

private List<Long> members;
}