1.remove unsed code in SongController 2.implement collect/follow/fans/blackList list

main
Gary 10 months ago
parent e0de8f8677
commit 0ca110f4df

@ -1,7 +1,7 @@
package enums;
public enum CollectTypeEnum {
SONG(0, "歌曲"), JOURNAL(1, "期刊"), FOLLOW(2, "关注"), BLACK_LIST(3, "黑名单"), THUMB_UP(4, "点赞");
SONG(0, "歌曲"), JOURNAL(1, "期刊"), FOLLOWS(2, "关注"), BLACK_LIST(3, "黑名单"), FANS(4, "粉丝"), THUMB_UP(5, "点赞");
private Integer type;
private String description;

@ -0,0 +1,40 @@
package enums;
public enum UserRelationEnum {
NOT_FOLLOW(1, "未关注"),
FOLLOW(2, "已关注"),
BOTH_FOLLOW(3, "互相关注"),
SELF_BLACK_LIST(4, "他人在自己黑名单"),
OTHER_BLACK_LIST(5, "自己在他人黑名单");
private Integer status;
private String desc;
UserRelationEnum(Integer status, String desc) {
this.status = status;
this.desc = desc;
}
public static UserRelationEnum getByStatus(Integer status) {
for (UserRelationEnum item : UserRelationEnum.values()) {
if (item.getStatus().equals(status)) {
return item;
}
}
return null;
}
public Integer getStatus() {
return status;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}

@ -1,8 +1,6 @@
package com.luoo.music.controller;
import com.luoo.music.dto.response.JournalRespDTO;
import com.luoo.music.dto.response.SongRespDTO;
import com.luoo.music.pojo.Article;
import com.luoo.music.pojo.Song;
import com.luoo.music.service.ArticleService;
import com.luoo.music.service.SongService;
@ -22,13 +20,11 @@ import io.swagger.annotations.ApiOperation;
import util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@ -139,91 +135,4 @@ public class SongController {
songRespDTO.setHaveCollect(songCollectSet.contains(songRespDTO.getId()));
return songRespDTO;
}
/* *//**
* ID
*
* @param id ID
* @return
*//*
* @GetMapping("/{id}") public Result<Song> findById(@PathVariable String id) {
* return Result.success(songService.findById(id)); }
*/
/**
* +
*
* @param searchMap
* @param page
* @param size
* @return
*/
/*
* @PostMapping("/search/{page}/{size}") public Result<PageResult<Song>>
* findSearch(@RequestBody Map searchMap, @PathVariable int page,
*
* @PathVariable int size) { Page<Song> pageList =
* songService.findSearch(searchMap, page, size); return Result.success(new
* PageResult<Song>(pageList.getTotalElements(), pageList.getContent())); }
*
* @PostMapping("/init") public Result<Void> init(@RequestBody Map map) {
* List<Map> data = (List) map.get("data"); System.out.println(data.size());
* Song song = new Song(); Set<Article> set = new HashSet<Article>();
*
* int temp = 0; int num = 0; for (Map dataMap : data) { Article article = new
* Article(); article.setVolid(dataMap.get("id") + "");
* article.setTitle(dataMap.get("title") + ""); String avatar = "0000" +
* dataMap.get("id"); String substring = avatar.substring(avatar.length() - 5);
* System.out.println(substring); article.setImage(substring + "/00.jpg"); if
* (temp == (int) dataMap.get("id")) { num = num + 1; } else { num = 0; } temp =
* (int) dataMap.get("id"); String numstr = "0000" + (num + 1);
* System.out.println(numstr.substring(numstr.length() - 2));
*
* song.setAlbum(dataMap.get("album") + "");
* song.setArtist(dataMap.get("artist") + ""); song.setName(dataMap.get("name")
* + ""); song.setVolid(dataMap.get("id") + ""); song.setUrl(substring + "/" +
* numstr.substring(numstr.length() - 2) + ".mp3"); song.setSongno(num + 1);
*
* songService.add(song); set.add(article); } System.out.println(set.size());
*
* for (Article pojo : set) { // articleService.add(pojo); } return
* Result.success(); }
*
*//**
*
*
* @param searchMap
* @return
*/
/*
* @PostMapping("/search") public Result<List<Song>> findSearch(@RequestBody Map
* searchMap) { return Result.success(songService.findSearch(searchMap)); }
*
*//**
*
*
* @param song
*/
/*
* @PostMapping public Result<Void> add(@RequestBody Song song) {
* songService.add(song); return Result.success(); }
*
*//**
*
*
* @param song
*/
/*
* @PutMapping("/{id}") public Result<Void> update(@RequestBody Song
* song, @PathVariable String id) { song.setId(id); songService.update(song);
* return Result.success(); }
*
*//**
*
*
* @param id
*//*
* @DeleteMapping("/{id}") public Result<Void> delete(@PathVariable String id) {
* songService.deleteById(id); return Result.success(); }
*/
}

@ -1,25 +1,20 @@
package com.luoo.user.controller;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.Date;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import com.luoo.user.pojo.UserCollect;
import com.luoo.user.pojo.UserCollectInfo;
import com.luoo.user.service.UserCollectInfoService;
import com.luoo.user.service.UserCollectService;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@ -28,8 +23,6 @@ import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import constants.Constants;
@ -40,14 +33,17 @@ import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.pojo.UserInfo;
import com.luoo.user.service.S3Service;
import com.luoo.user.service.UserInfoService;
import com.luoo.user.util.IpUtil;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.PageResult;
import api.Result;
import api.StatusCode;
import dto.UserLoginDto;
import enums.CollectTypeEnum;
import enums.DateTimePatternEnum;
import enums.UserRelationEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@ -79,42 +75,8 @@ public class MyController extends BaseController {
@GlobalInterceptor(checkAppUserLogin = true)
public Result<UserRespDTO> getUserInfo(@RequestHeader(value = "Authorization", required = false) String authorization) {
UserLoginDto userLoginDto = getUserLoginDto(authorization);
if (null == userLoginDto) {
return Result.unauthorized(null);
}
UserRespDTO userRespDTO = new UserRespDTO();
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
BeanUtils.copyProperties(user, userRespDTO);
// EnumMap<CollectTypeEnum,Long>
// map=userCollectService.getUserCollectTypeMap(user.getId());
// int fansCount=userCollectService.getFansCount(user.getId());
// int followCount=userCollectService.getCount(user.getId(),CollectTypeEnum.FOLLOW.getType());
// int thumbUpCount=userCollectService.getCount(user.getId(),CollectTypeEnum.THUMB_UP.getType());
// int songCount=userCollectService.getCount(user.getId(),CollectTypeEnum.SONG.getType());
// int journalCount=userCollectService.getCount(user.getId(),CollectTypeEnum.JOURNAL.getType());
//
// userRespDTO.setFollowCount(followCount);
// userRespDTO.setFansCount(fansCount);
// userRespDTO.setThumbUpCount(thumbUpCount);
// userRespDTO.setCommentReplyCount(0);
// userRespDTO.setSongCount(songCount);
// userRespDTO.setJournalCount(journalCount);
if (null != userRespDTO.getAvatar()) {
userRespDTO.setAvatar(Constants.RESOURCE_PREFIX + userRespDTO.getAvatar());
}
Optional<UserCollect> optional = userCollectService.findByUserId(userLoginDto.getUserId());
if (optional.isPresent()) {
UserCollect userCollect = optional.get();
userRespDTO.setSongCount(userCollect.getSongs().size());
userRespDTO.setJournalCount(userCollect.getJournals().size());
}
if (null != user.getBirthday()) {
userRespDTO.setBirthDay(
DateUtil.format(user.getBirthday(), DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern()));
}
UserRespDTO userRespDTO = getUserRespDTO(user,true,Collections.emptySet());
return Result.success(userRespDTO);
}
@ -180,11 +142,129 @@ public class MyController extends BaseController {
if (null == user) {
return Result.failed(StatusCode.USER_INVALID_USER_ID);
}
UserRespDTO userRespDTO = getUserRespDTO(user,false,Collections.emptySet());
userRespDTO.setIpLocation(IpUtil.getIpLocation(user.getLastLoginIp()));
UserLoginDto userLoginDto = getUserLoginDto(authorization);
Optional<UserCollect> loginOptional = userCollectService.findByUserId(userLoginDto.getUserId());
if (loginOptional.isPresent()) {
UserCollect loginCollect = loginOptional.get();
Set<String> loginBlackList=new HashSet<>(loginCollect.getBlackList());
if(loginBlackList.contains(userId)) {
userRespDTO.setRelation(UserRelationEnum.SELF_BLACK_LIST.getStatus());
return Result.success(userRespDTO);
}
}
Optional<UserCollect> otherOptional = userCollectService.findByUserId(userId);
if (otherOptional.isPresent()) {
UserCollect otherCollect = otherOptional.get();
Set<String> otherBlackList=new HashSet<>(otherCollect.getBlackList());
if(otherBlackList.contains(userLoginDto.getUserId())) {
userRespDTO.setRelation(UserRelationEnum.OTHER_BLACK_LIST.getStatus());
return Result.success(userRespDTO);
}
Set<String> follows=new HashSet<>(otherCollect.getFollows());
Set<String> fans=new HashSet<>(otherCollect.getFans());
userRespDTO.setFollowCount(follows.size());
userRespDTO.setFansCount(fans.size());
boolean isFollow=fans.contains(userLoginDto.getUserId());
boolean isFan=follows.contains(userLoginDto.getUserId());
if(isFollow&&isFan) {
userRespDTO.setRelation(UserRelationEnum.BOTH_FOLLOW.getStatus());
return Result.success(userRespDTO);
}else if(isFollow&&!isFan) {
userRespDTO.setRelation(UserRelationEnum.FOLLOW.getStatus());
return Result.success(userRespDTO);
}
}
userRespDTO.setRelation(UserRelationEnum.NOT_FOLLOW.getStatus());
return Result.success(userRespDTO);
}
@ApiOperation(value = "5.查询黑名单")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true),
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) })
@GetMapping("/blackList/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<UserRespDTO>> getBlackList(@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true) Integer pageNum,
@PathVariable @VerifyParam(required = true) Integer pageSize) {
UserLoginDto userLoginDto = getUserLoginDto(authorization);
return getCollectedUserInfo(userLoginDto.getUserId(), pageNum, pageSize, CollectTypeEnum.BLACK_LIST);
}
@ApiOperation(value = "6.查询关注人信息")
@ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", required = true),
@ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true),
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) })
@GetMapping("/follows/{userId}/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<UserRespDTO>> getFollows(@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true) String userId,
@PathVariable @VerifyParam(required = true) Integer pageNum,
@PathVariable @VerifyParam(required = true) Integer pageSize) {
return getCollectedUserInfo(userId, pageNum, pageSize, CollectTypeEnum.FOLLOWS);
}
@ApiOperation(value = "7.查询粉丝信息")
@ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", required = true),
@ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true),
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) })
@GetMapping("/fans/{userId}/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<UserRespDTO>> getFans(@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true) String userId,
@PathVariable @VerifyParam(required = true) Integer pageNum,
@PathVariable @VerifyParam(required = true) Integer pageSize) {
return getCollectedUserInfo(userId, pageNum, pageSize, CollectTypeEnum.FANS);
}
private Result<PageResult<UserRespDTO>> getCollectedUserInfo(String userId, Integer pageNum, Integer pageSize,
CollectTypeEnum collectTypeEnum) {
Pair<List<String>,Set<String>> pair = userCollectService.getCollectListWithBothFollowSet(userId, pageNum, pageSize, collectTypeEnum);
List<String> objectIds = pair.getKey();
if(objectIds.isEmpty()) {
return Result.success(new PageResult<UserRespDTO>(0L, Collections.emptyList()));
}
List<UserInfo> userInfos = userInfoService.orderByField(objectIds);
List<UserRespDTO> results = userInfos.stream().map(s -> getUserRespDTO(s,false,pair.getRight()))
.collect(Collectors.toList());
return Result.success(new PageResult<UserRespDTO>(Long.valueOf(results.size()), results));
}
private UserRespDTO getUserRespDTO(UserInfo user,boolean withCount, Set<String> bothFollowSet) {
UserRespDTO userRespDTO = new UserRespDTO();
BeanUtils.copyProperties(user, userRespDTO);
if (null != userRespDTO.getAvatar()) {
userRespDTO.setAvatar(Constants.RESOURCE_PREFIX + userRespDTO.getAvatar());
}
return Result.success(userRespDTO);
if (null != user.getBirthday()) {
userRespDTO.setBirthDay(
DateUtil.format(user.getBirthday(), DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern()));
}
if(!bothFollowSet.isEmpty()&&bothFollowSet.contains(userRespDTO.getId())) {
userRespDTO.setRelation(UserRelationEnum.BOTH_FOLLOW.getStatus());
}
if(!withCount) {
return userRespDTO;
}
Optional<UserCollect> optional = userCollectService.findByUserId(userRespDTO.getId());
if (optional.isPresent()) {
UserCollect userCollect = optional.get();
userRespDTO.setSongCount(userCollect.getSongs().size());
userRespDTO.setJournalCount(userCollect.getJournals().size());
userRespDTO.setFansCount(userCollect.getFans().size());
userRespDTO.setFollowCount(userCollect.getFollows().size());
}
return userRespDTO;
}
}

@ -23,12 +23,12 @@ public class UserCollectController {
private UserCollectService userCollectService;
//@ApiOperation(value = "1.喜欢歌曲/收藏期刊/关注/黑名单/点赞")
@ApiOperation(value = "1.喜欢歌曲/收藏期刊")
@ApiOperation(value = "1.喜欢歌曲/收藏期刊/关注/黑名单")
@ApiImplicitParams({
//@ApiImplicitParam(name = "objectId", value = "喜欢歌曲/收藏期刊/关注某用户/某用户列入黑名单/点赞评论的id", required = true),
//@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊2:关注3:黑名单4:点赞", required = true) })
@ApiImplicitParam(name = "objectId", value = "喜欢歌曲/收藏期刊的id", required = true),
@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊", required = true) })
@ApiImplicitParam(name = "objectId", value = "喜欢歌曲/收藏期刊/关注某用户/某用户列入黑名单的id", required = true),
@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊2:关注3:黑名单", required = true) })
@PostMapping
@GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> addCollect(@RequestHeader(value = "Authorization", required = false) String authorization,
@ -40,12 +40,12 @@ public class UserCollectController {
}
//@ApiOperation(value = "2.取消 喜欢歌曲/收藏期刊/关注/黑名单/点赞")
@ApiOperation(value = "2.取消 喜欢歌曲/收藏期刊")
@ApiOperation(value = "2.取消 喜欢歌曲/收藏期刊/关注/黑名单/粉丝")
@ApiImplicitParams({
//@ApiImplicitParam(name = "objectId", value = "喜欢歌曲/收藏期刊/关注某用户/某用户列入黑名单/点赞评论的id", required = true),
//@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊2:关注3:黑名单4:点赞", required = true) })
@ApiImplicitParam(name = "objectId", value = "喜欢歌曲/收藏期刊的id", required = true),
@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊", required = true) })
@ApiImplicitParam(name = "objectId", value = "喜欢歌曲/收藏期刊/关注某用户/某用户列入黑名单/粉丝的id", required = true),
@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊2:关注3:黑名单4:粉丝", required = true) })
@DeleteMapping
@GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> cancelCollect(@RequestHeader(value = "Authorization", required = false) String authorization,

@ -1,6 +1,7 @@
package com.luoo.user.dao;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
@ -31,4 +32,7 @@ public interface UserInfoDao extends JpaRepository<UserInfo, String>, JpaSpecifi
@Query(value = "select new client.vo.SimpleUser(id, nickName) from UserInfo where id in ?1 order by field(id,?1)")
public List<SimpleUser> getSimpleUserOrderByField(List<String> idList);
@Query(value = "select * from tb_user_info where id = ?1", nativeQuery = true)
public UserInfo getById(String id);
}

@ -1,13 +1,8 @@
package com.luoo.user.dto.response;
import com.luoo.user.dto.UserCollectJournalDto;
import com.luoo.user.dto.UserCollectSongDto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
import java.util.Set;
@Data
public class UserRespDTO {
@ApiModelProperty(value = "ID")
@ -30,12 +25,14 @@ public class UserRespDTO {
private int thumbUpCount;
@ApiModelProperty(value = "喜欢歌曲数")
private int songCount;
@ApiModelProperty(value = "收藏期刊数")
private int journalCount;
@ApiModelProperty(value = "获得评论数")
private int commentReplyCount;
@ApiModelProperty(value = "生日,格式为: yyyy.MM.dd")
private String birthDay;
@ApiModelProperty(value = "与他人关系1未关注2 已关注3互相关注 4他人在自己黑名单5自己在他人黑名单", example = "1")
private int relation;
@ApiModelProperty(value = "IP 归属地,精确到省份", example = "北京")
private String ipLocation;
}

@ -34,4 +34,11 @@ public class UserCollect implements Serializable {
private LinkedList<String> journals;
private LinkedList<String> songs;
private LinkedList<String> fans;
private LinkedList<String> follows;
private LinkedList<String> blackList;
}

@ -1,11 +1,16 @@
package com.luoo.user.service;
import java.util.Collections;
import java.util.Date;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -32,28 +37,58 @@ public class UserCollectService {
if (null == collectTypeEnum) {
throw new BizException(StatusCode.VALIDATE_FAILED);
}
UserCollect userCollect=null;
Optional<UserCollect> dbCollect = userCollectDao.findById(userId);
if (dbCollect.isPresent()) {
userCollect=dbCollect.get();
}else {
userCollect = new UserCollect();
userCollect.setUserId(userId);
userCollect.setJournals(new LinkedList<>());
userCollect.setSongs(new LinkedList<>());
}
UserCollect userCollect=dbCollect.isPresent()?dbCollect.get():createUserCollect(userId);
switch (collectTypeEnum) {
case SONG:
addOrRemove(isAdd,userCollect.getSongs(),objectId);
break;
case JOURNAL:
addOrRemove(isAdd,userCollect.getJournals(),objectId);
break;
case FOLLOWS:
Optional<UserCollect> followsDbCollect = userCollectDao.findById(objectId);
UserCollect followsUserCollect=followsDbCollect.isPresent()?followsDbCollect.get():createUserCollect(objectId);
addOrRemove(isAdd,userCollect.getFollows(),objectId,followsUserCollect.getFans(),userId);
userCollectDao.save(followsUserCollect);
break;
case FANS:
Optional<UserCollect> fansDbCollect = userCollectDao.findById(objectId);
UserCollect fansUserCollect=fansDbCollect.isPresent()?fansDbCollect.get():createUserCollect(objectId);
addOrRemove(isAdd,userCollect.getFans(),objectId,fansUserCollect.getFollows(),userId);
userCollectDao.save(fansUserCollect);
break;
case BLACK_LIST:
addOrRemove(isAdd,userCollect.getBlackList(),objectId);
break;
default:
break;
}
userCollectDao.save(userCollect);
}
private void addOrRemove(boolean isAdd, LinkedList<String> follows, String objectId, LinkedList<String> fans,
String userId) {
if(isAdd) {
follows.addFirst(objectId);
fans.addFirst(userId);
}else{
follows.removeFirstOccurrence(objectId);
fans.removeFirstOccurrence(userId);
}
}
private UserCollect createUserCollect(String userId) {
UserCollect userCollect = new UserCollect();
userCollect.setUserId(userId);
userCollect.setJournals(new LinkedList<>());
userCollect.setSongs(new LinkedList<>());
userCollect.setFollows(new LinkedList<>());
userCollect.setFans(new LinkedList<>());
userCollect.setBlackList(new LinkedList<>());
return userCollect;
}
private void addOrRemove(boolean isAdd, LinkedList<String> list, String objectId) {
if(isAdd) {
list.addFirst(objectId);
@ -70,4 +105,61 @@ public class UserCollectService {
public Optional<UserCollect> findByUserId(String userId) {
return userCollectDao.findById(userId);
}
public List<String> getCollectList(String userId, Integer pageNum, Integer pageSize,
CollectTypeEnum collectTypeEnum) {
if (null == userId) {
return Collections.emptyList();
}
Optional<UserCollect> optional = userCollectDao.findById(userId);
if (!optional.isPresent()) {
return Collections.emptyList();
}
UserCollect userCollect = optional.get();
switch (collectTypeEnum) {
case FOLLOWS:
return getPageResult(pageNum, pageSize, userCollect.getFollows());
case FANS:
return getPageResult(pageNum, pageSize, userCollect.getFans());
case BLACK_LIST:
return getPageResult(pageNum, pageSize, userCollect.getBlackList());
default:
return Collections.emptyList();
}
}
private List<String> getPageResult(Integer pageNum, Integer pageSize, LinkedList<String> objectIds) {
int end=pageNum * pageSize;
if (null != pageNum && null != pageSize && pageNum > 0 && pageSize > 0&&end<=objectIds.size()) {
return objectIds.subList((pageNum - 1) * pageSize, end);
}
return objectIds;
}
public Pair<List<String>, Set<String>> getCollectListWithBothFollowSet(String userId, Integer pageNum, Integer pageSize,
CollectTypeEnum collectTypeEnum) {
if (null == userId) {
return Pair.of(Collections.emptyList(), Collections.emptySet());
}
Optional<UserCollect> optional = userCollectDao.findById(userId);
if (!optional.isPresent()) {
return Pair.of(Collections.emptyList(), Collections.emptySet());
}
UserCollect userCollect = optional.get();
switch (collectTypeEnum) {
case FOLLOWS:
List<String> follows=getPageResult(pageNum, pageSize, userCollect.getFollows());
Set<String> fans=new HashSet<>(userCollect.getFans());
Set<String> bothFollowSet=follows.stream().filter(fans::contains).collect(Collectors.toSet());
return Pair.of(follows, bothFollowSet);
case FANS:
List<String> fanList=getPageResult(pageNum, pageSize, userCollect.getFans());
Set<String> followList=new HashSet<>(userCollect.getFollows());
Set<String> bothFanSet=fanList.stream().filter(followList::contains).collect(Collectors.toSet());
return Pair.of(fanList, bothFanSet);
case BLACK_LIST:
return Pair.of(getPageResult(pageNum, pageSize, userCollect.getBlackList()), Collections.emptySet());
default:
return Pair.of(Collections.emptyList(), Collections.emptySet());
}
}
}

@ -114,7 +114,7 @@ public class UserInfoService {
* @return
*/
public UserInfo findById(String id) {
return userInfoDao.findById(id).get();
return userInfoDao.getById(id);
}

@ -0,0 +1,7 @@
package com.luoo.user.util;
public class IpUtil {
public static String getIpLocation(String ip) {
return "中国";
}
}
Loading…
Cancel
Save