|
|
@@ -8,11 +8,15 @@ import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.Netease.TeamRepo;
|
|
|
import com.izouma.nineth.service.netease.NeteaseUserService;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
+import com.izouma.nineth.utils.SecurityUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.lang.reflect.Member;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -25,7 +29,28 @@ public class TeamService {
|
|
|
private NeteaseUserService neteaseUserService;
|
|
|
|
|
|
public Page<Team> all(PageQuery pageQuery) {
|
|
|
- return teamRepo.findAll(JpaUtils.toSpecification(pageQuery, Team.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
+ Long userId = SecurityUtils.getAuthenticatedUser().getId();
|
|
|
+ Page<Team> teams = teamRepo
|
|
|
+ .findAll(JpaUtils.toSpecification(pageQuery, Team.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
+ List<Team> content = teams.getContent();
|
|
|
+ List<Team> newContent = new ArrayList<>();
|
|
|
+ content.forEach(team -> {
|
|
|
+ List<String> members = new ArrayList<>(team.getMembers());
|
|
|
+ boolean inTeam = false;
|
|
|
+ if (StringUtils.equals(team.getOwnerid(), userId.toString())) {
|
|
|
+ inTeam = true;
|
|
|
+ } else {
|
|
|
+ for (String member : members) {
|
|
|
+ String accid = userId.toString();
|
|
|
+ if (StringUtils.equals(accid, member)) {
|
|
|
+ inTeam = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ team.setInTeam(inTeam);
|
|
|
+ newContent.add(team);
|
|
|
+ });
|
|
|
+ return new PageImpl<>(newContent, teams.getPageable(), teams.getTotalElements());
|
|
|
}
|
|
|
|
|
|
public Team create(Team team) {
|
|
|
@@ -48,12 +73,14 @@ public class TeamService {
|
|
|
return teamRepo.save(team);
|
|
|
}
|
|
|
|
|
|
- public Team invite(List<String> invitedIds, String tid) {
|
|
|
+ public Team invite(String id, String tid) {
|
|
|
+ List<String> ids = new ArrayList<>();
|
|
|
+ ids.add(id);
|
|
|
Team team = teamRepo.findById(Long.valueOf(tid)).orElseThrow(new BusinessException("未找到群聊"));
|
|
|
Map<String, String> params = new HashMap<>();
|
|
|
params.put("tid", tid);
|
|
|
params.put("owner", team.getOwnerid());
|
|
|
- params.put("members", JSONObject.toJSONString(invitedIds));
|
|
|
+ params.put("members", JSONObject.toJSONString(ids));
|
|
|
params.put("magree", "0");
|
|
|
params.put("custom", team.getCustom().toString());
|
|
|
params.put("msg", "欢迎加入大厅测试群~~");
|
|
|
@@ -64,8 +91,9 @@ public class TeamService {
|
|
|
if (code != 200) {
|
|
|
throw new BusinessException("注册出错,请核查后重新注册");
|
|
|
}
|
|
|
- List<String> members = team.getMembers();
|
|
|
- members.addAll(invitedIds);
|
|
|
+ List<String> members = new ArrayList<>(team.getMembers());
|
|
|
+ members.add(id);
|
|
|
+ team.setMembers(members);
|
|
|
return teamRepo.save(team);
|
|
|
}
|
|
|
}
|