|
@@ -7,6 +7,7 @@ import com.izouma.nineth.domain.netease.NeteaseMessage;
|
|
|
import com.izouma.nineth.domain.netease.NeteaseUser;
|
|
import com.izouma.nineth.domain.netease.NeteaseUser;
|
|
|
import com.izouma.nineth.domain.netease.Team;
|
|
import com.izouma.nineth.domain.netease.Team;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
|
|
+import com.izouma.nineth.dto.netease.TeamMember;
|
|
|
import com.izouma.nineth.enums.netease.TeamType;
|
|
import com.izouma.nineth.enums.netease.TeamType;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.AssetRepo;
|
|
import com.izouma.nineth.repo.AssetRepo;
|
|
@@ -58,6 +59,7 @@ public class TeamService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ team.setBan(team.getBanned().stream().anyMatch(member -> StringUtils.equals(member, userId.toString())));
|
|
|
team.setLastMsg(getTeamLastMessage(team.getTid()));
|
|
team.setLastMsg(getTeamLastMessage(team.getTid()));
|
|
|
team.setUnread(getUnreadCount(userId.toString(), team.getTid().toString()));
|
|
team.setUnread(getUnreadCount(userId.toString(), team.getTid().toString()));
|
|
|
team.setInTeam(inTeam);
|
|
team.setInTeam(inTeam);
|
|
@@ -143,10 +145,54 @@ public class TeamService {
|
|
|
teamRepo.save(team);
|
|
teamRepo.save(team);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void muteMember(Long tid, String accid) {
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
|
+ Team team = teamRepo.findById(tid).orElseThrow(new BusinessException("暂无"));
|
|
|
|
|
+ params.put("tid", tid);
|
|
|
|
|
+ params.put("owner", team.getOwnerid());
|
|
|
|
|
+ params.put("accid", accid);
|
|
|
|
|
+ params.put("mute", 1);
|
|
|
|
|
+ String result = neteaseUserService
|
|
|
|
|
+ .httpPost("team/muteTlist.action", "application/x-www-form-urlencoded;charset=utf-8", params);
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result);
|
|
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
|
|
+ if (code != 200) {
|
|
|
|
|
+ throw new BusinessException("禁言操作出错");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<String> banned = new ArrayList<>(team.getBanned());
|
|
|
|
|
+ banned.add(accid);
|
|
|
|
|
+ team.setBanned(banned);
|
|
|
|
|
+ teamRepo.save(team);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void cancelMuteMember(Long tid, String accid) {
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
|
+ Team team = teamRepo.findById(tid).orElseThrow(new BusinessException("暂无"));
|
|
|
|
|
+ params.put("tid", tid);
|
|
|
|
|
+ params.put("owner", team.getOwnerid());
|
|
|
|
|
+ params.put("accid", accid);
|
|
|
|
|
+ params.put("mute", 0);
|
|
|
|
|
+ String result = neteaseUserService
|
|
|
|
|
+ .httpPost("team/muteTlist.action", "application/x-www-form-urlencoded;charset=utf-8", params);
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result);
|
|
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
|
|
+ if (code != 200) {
|
|
|
|
|
+ throw new BusinessException("禁言操作出错");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<String> banned = new ArrayList<>(team.getBanned());
|
|
|
|
|
+ banned.removeIf(id -> StringUtils.equals(id, accid));
|
|
|
|
|
+ team.setBanned(banned);
|
|
|
|
|
+ teamRepo.save(team);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public Team invite(String id, String tid) {
|
|
public Team invite(String id, String tid) {
|
|
|
List<String> ids = new ArrayList<>();
|
|
List<String> ids = new ArrayList<>();
|
|
|
ids.add(id);
|
|
ids.add(id);
|
|
|
Team team = teamRepo.findById(Long.valueOf(tid)).orElseThrow(new BusinessException("未找到群聊"));
|
|
Team team = teamRepo.findById(Long.valueOf(tid)).orElseThrow(new BusinessException("未找到群聊"));
|
|
|
|
|
+ List<String> kicked = team.getKicked();
|
|
|
|
|
+ if (kicked.stream().anyMatch(member -> StringUtils.equals(member, id))) {
|
|
|
|
|
+ throw new BusinessException("用户被踢出,无法加入");
|
|
|
|
|
+ }
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("tid", tid);
|
|
params.put("tid", tid);
|
|
|
params.put("owner", team.getOwnerid());
|
|
params.put("owner", team.getOwnerid());
|
|
@@ -185,6 +231,27 @@ public class TeamService {
|
|
|
teamRepo.save(team);
|
|
teamRepo.save(team);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void kick(String id, String tid) {
|
|
|
|
|
+ Team team = teamRepo.findById(Long.valueOf(tid)).orElseThrow(new BusinessException("未找到群聊"));
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
|
+ params.put("tid", tid);
|
|
|
|
|
+ params.put("accid", id);
|
|
|
|
|
+ String result = neteaseUserService
|
|
|
|
|
+ .httpPost("team/leave.action", "application/x-www-form-urlencoded;charset=utf-8", params);
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result);
|
|
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
|
|
+ if (code != 200) {
|
|
|
|
|
+ throw new BusinessException("退群出错");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<String> members = new ArrayList<>(team.getMembers());
|
|
|
|
|
+ members.removeIf(member -> StringUtils.equals(member, id));
|
|
|
|
|
+ team.setMembers(members);
|
|
|
|
|
+ List<String> kicked = new ArrayList<>(team.getKicked());
|
|
|
|
|
+ kicked.add(id);
|
|
|
|
|
+ team.setKicked(kicked);
|
|
|
|
|
+ teamRepo.save(team);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void checkout(String accid, String tid) {
|
|
public void checkout(String accid, String tid) {
|
|
|
Long ts = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
Long ts = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
redisTemplate.opsForValue().set(RedisKeys.USER_CHECKOUT_TIME + accid + ":" + tid, ts);
|
|
redisTemplate.opsForValue().set(RedisKeys.USER_CHECKOUT_TIME + accid + ":" + tid, ts);
|
|
@@ -236,4 +303,22 @@ public class TeamService {
|
|
|
}
|
|
}
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public List<TeamMember> getTeamMembers(Long tid) {
|
|
|
|
|
+ Team team = teamRepo.findById(tid).orElseThrow(new BusinessException("未找到群组"));
|
|
|
|
|
+ List<String> strings = team.getMembers();
|
|
|
|
|
+ List<NeteaseUser> neteaseUsers = neteaseUserRepo.findAllByAccIdIn(strings);
|
|
|
|
|
+ List<TeamMember> result = new ArrayList<>();
|
|
|
|
|
+ List<String> banned = new ArrayList<>(team.getBanned());
|
|
|
|
|
+ neteaseUsers.forEach(member -> {
|
|
|
|
|
+ TeamMember teamMember = new TeamMember();
|
|
|
|
|
+ teamMember.setAccid(member.getAccId());
|
|
|
|
|
+ teamMember.setAvatar(member.getIcon());
|
|
|
|
|
+ teamMember.setNickName(member.getName());
|
|
|
|
|
+ teamMember.setBanned(banned.stream()
|
|
|
|
|
+ .anyMatch(bannedOne -> StringUtils.equals(bannedOne, member.getAccId())));
|
|
|
|
|
+ result.add(teamMember);
|
|
|
|
|
+ });
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|