|
|
@ -1,25 +1,20 @@
|
|
|
|
package com.luoo.user.controller;
|
|
|
|
package com.luoo.user.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.EnumMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import com.luoo.user.pojo.UserCollect;
|
|
|
|
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 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.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
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.CrossOrigin;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
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.RequestBody;
|
|
|
|
import org.springframework.web.bind.annotation.RequestHeader;
|
|
|
|
import org.springframework.web.bind.annotation.RequestHeader;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
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.bind.annotation.RestController;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import constants.Constants;
|
|
|
|
import constants.Constants;
|
|
|
@ -40,14 +33,17 @@ import com.luoo.user.dto.response.UserRespDTO;
|
|
|
|
import com.luoo.user.pojo.UserInfo;
|
|
|
|
import com.luoo.user.pojo.UserInfo;
|
|
|
|
import com.luoo.user.service.S3Service;
|
|
|
|
import com.luoo.user.service.S3Service;
|
|
|
|
import com.luoo.user.service.UserInfoService;
|
|
|
|
import com.luoo.user.service.UserInfoService;
|
|
|
|
|
|
|
|
import com.luoo.user.util.IpUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import annotation.GlobalInterceptor;
|
|
|
|
import annotation.GlobalInterceptor;
|
|
|
|
import annotation.VerifyParam;
|
|
|
|
import annotation.VerifyParam;
|
|
|
|
|
|
|
|
import api.PageResult;
|
|
|
|
import api.Result;
|
|
|
|
import api.Result;
|
|
|
|
import api.StatusCode;
|
|
|
|
import api.StatusCode;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import enums.CollectTypeEnum;
|
|
|
|
import enums.CollectTypeEnum;
|
|
|
|
import enums.DateTimePatternEnum;
|
|
|
|
import enums.DateTimePatternEnum;
|
|
|
|
|
|
|
|
import enums.UserRelationEnum;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
@ -79,42 +75,8 @@ public class MyController extends BaseController {
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
public Result<UserRespDTO> getUserInfo(@RequestHeader(value = "Authorization", required = false) String authorization) {
|
|
|
|
public Result<UserRespDTO> getUserInfo(@RequestHeader(value = "Authorization", required = false) String authorization) {
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UserRespDTO userRespDTO = new UserRespDTO();
|
|
|
|
|
|
|
|
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
|
|
|
|
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
|
|
|
|
|
|
|
|
UserRespDTO userRespDTO = getUserRespDTO(user,true,Collections.emptySet());
|
|
|
|
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()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result.success(userRespDTO);
|
|
|
|
return Result.success(userRespDTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -180,11 +142,129 @@ public class MyController extends BaseController {
|
|
|
|
if (null == user) {
|
|
|
|
if (null == user) {
|
|
|
|
return Result.failed(StatusCode.USER_INVALID_USER_ID);
|
|
|
|
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();
|
|
|
|
UserRespDTO userRespDTO = new UserRespDTO();
|
|
|
|
BeanUtils.copyProperties(user, userRespDTO);
|
|
|
|
BeanUtils.copyProperties(user, userRespDTO);
|
|
|
|
if (null != userRespDTO.getAvatar()) {
|
|
|
|
if (null != userRespDTO.getAvatar()) {
|
|
|
|
userRespDTO.setAvatar(Constants.RESOURCE_PREFIX + 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|