|
|
@@ -2,20 +2,23 @@ package com.izouma.nineth.service.netease;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.izouma.nineth.config.RedisKeys;
|
|
|
import com.izouma.nineth.domain.netease.Team;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
-import com.izouma.nineth.repo.Netease.TeamRepo;
|
|
|
-import com.izouma.nineth.service.netease.NeteaseUserService;
|
|
|
+import com.izouma.nineth.repo.netease.NeteaseMessageRepo;
|
|
|
+import com.izouma.nineth.repo.netease.TeamRepo;
|
|
|
+import com.izouma.nineth.utils.DateTimeUtils;
|
|
|
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.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.lang.reflect.Member;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
@@ -25,8 +28,10 @@ import java.util.Map;
|
|
|
@AllArgsConstructor
|
|
|
public class TeamService {
|
|
|
|
|
|
- private TeamRepo teamRepo;
|
|
|
- private NeteaseUserService neteaseUserService;
|
|
|
+ private TeamRepo teamRepo;
|
|
|
+ private NeteaseUserService neteaseUserService;
|
|
|
+ private RedisTemplate<String, Object> redisTemplate;
|
|
|
+ private NeteaseMessageRepo neteaseMessageRepo;
|
|
|
|
|
|
public Page<Team> all(PageQuery pageQuery) {
|
|
|
Long userId = SecurityUtils.getAuthenticatedUser().getId();
|
|
|
@@ -47,6 +52,7 @@ public class TeamService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ team.setUnread(getUnreadCount(userId.toString(), team.getTid().toString()));
|
|
|
team.setInTeam(inTeam);
|
|
|
newContent.add(team);
|
|
|
});
|
|
|
@@ -96,4 +102,21 @@ public class TeamService {
|
|
|
team.setMembers(members);
|
|
|
return teamRepo.save(team);
|
|
|
}
|
|
|
+
|
|
|
+ public void checkout(String accid, String tid) {
|
|
|
+ Long ts = DateTimeUtils.toTimestamp(LocalDateTime.now());
|
|
|
+ redisTemplate.opsForValue().set(RedisKeys.USER_CHECKOUT_TIME + accid + ":" + tid, ts);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Long getUnreadCount(String accid, String tid) {
|
|
|
+ Long ts = (Long) redisTemplate.opsForValue().get(RedisKeys.USER_CHECKOUT_TIME + accid + ":" + tid);
|
|
|
+ Long unreadCount = 0L;
|
|
|
+ if (ts != null) {
|
|
|
+ LocalDateTime localDateTime = DateTimeUtils.toLocalDateTime(ts);
|
|
|
+ unreadCount = neteaseMessageRepo.countAllByToIdAndOpeAndCreatedAtAfter(tid, 1, localDateTime);
|
|
|
+ } else {
|
|
|
+ unreadCount = neteaseMessageRepo.countAllByToIdAndOpe(tid, 1);
|
|
|
+ }
|
|
|
+ return unreadCount;
|
|
|
+ }
|
|
|
}
|