1.add user feedback interface

main
Gary 12 months ago
parent 90c55009fb
commit ec0ccb7ed6

@ -9,6 +9,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import com.luoo.user.pojo.Feedback;
import com.luoo.user.pojo.UserCollect;
import com.luoo.user.service.UserCollectService;
@ -23,6 +24,7 @@ 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.RestController;
import org.springframework.web.multipart.MultipartFile;
import constants.Constants;
@ -31,6 +33,7 @@ import controller.BaseController;
import com.luoo.user.dto.UserInfoUpdateDto;
import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.pojo.UserInfo;
import com.luoo.user.service.FeedbackService;
import com.luoo.user.service.S3Service;
import com.luoo.user.service.UserInfoService;
import com.luoo.user.util.IpUtil;
@ -43,11 +46,14 @@ import api.StatusCode;
import dto.UserLoginDto;
import enums.CollectTypeEnum;
import enums.DateTimePatternEnum;
import enums.RequestFrequencyTypeEnum;
import enums.UserRelationEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.SneakyThrows;
import util.DateUtil;
import util.IdWorker;
import util.ScaleFilter;
@ -67,23 +73,27 @@ public class MyController extends BaseController {
@Autowired
// private UserCollectInfoService userCollectInfoService;
private UserCollectService userCollectService;
@Autowired
private FeedbackService feedbackService;
public static String UPLOAD_DIRECTORY = "user/avatar/";
public static String USER_AVATAR_DIRECTORY = "user/avatar/";
public static String USER_FEEDBACK_IMAGE_DIRECTORY = "user/feedback/";
@ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息")
@GetMapping("/userInfo")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<UserRespDTO> getUserInfo(@RequestHeader(value = "Authorization", required = false) String authorization) {
public Result<UserRespDTO> getUserInfo(
@RequestHeader(value = "Authorization", required = true) String authorization) {
UserLoginDto userLoginDto = getUserLoginDto(authorization);
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
UserRespDTO userRespDTO = getUserRespDTO(user,true,Collections.emptySet());
UserRespDTO userRespDTO = getUserRespDTO(user, true, Collections.emptySet());
return Result.success(userRespDTO);
}
@ApiOperation(value = "2.更新个人信息", notes = "游客无法编辑个人信息")
@PutMapping("/userInfo")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> updateUserInfo(@RequestHeader(value = "Authorization", required = false) String authorization,
public Result<Void> updateUserInfo(@RequestHeader(value = "Authorization", required = true) String authorization,
@VerifyParam(required = true) @RequestBody UserInfoUpdateDto userInfoUpdateDto) {
UserLoginDto userLoginDto = getUserLoginDto(authorization);
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
@ -116,15 +126,15 @@ public class MyController extends BaseController {
@ApiOperation(value = "3.上传个人头像", notes = "图片压缩为70X70 JPEG存入S3桶为indie目录为 user/avatar/")
@PostMapping("/avatar")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<String> uploadAvatar(@RequestHeader(value = "Authorization", required = false) String authorization,
public Result<String> uploadAvatar(@RequestHeader(value = "Authorization", required = true) String authorization,
@VerifyParam(required = true) MultipartFile file) throws IOException {
UserLoginDto userLoginDto = getUserLoginDto(authorization);
byte[] thumbnail = ScaleFilter.createThumbnail(file.getInputStream(), Constants.LENGTH_70, Constants.LENGTH_70);
String avatarName = userLoginDto.getUserId() + "_" + idWorker.nextId()
+ StringTools.getFileSuffix(file.getOriginalFilename());
String filePath = UPLOAD_DIRECTORY + avatarName;
s3Service.uploadAvatar("indie", filePath, thumbnail);
String filePath = USER_AVATAR_DIRECTORY + avatarName;
s3Service.uploadImage("indie", filePath, thumbnail);
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
user.setAvatar(filePath);
@ -136,23 +146,24 @@ public class MyController extends BaseController {
@ApiOperation(value = "4.查看他人信息", notes = "游客无法查看他人信息")
@GetMapping("/otherUserInfo/{userId}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<UserRespDTO> getOtherUserInfo(@RequestHeader(value = "Authorization", required = false) String authorization,
public Result<UserRespDTO> getOtherUserInfo(
@RequestHeader(value = "Authorization", required = true) String authorization,
@VerifyParam(required = true) @PathVariable String userId) {
UserInfo user = userInfoService.findById(userId);
if (null == user) {
return Result.failed(StatusCode.USER_INVALID_USER_ID);
}
UserRespDTO userRespDTO = getUserRespDTO(user,false,Collections.emptySet());
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)) {
Set<String> loginBlackList = new HashSet<>(loginCollect.getBlackList());
if (loginBlackList.contains(userId)) {
userRespDTO.setRelation(UserRelationEnum.SELF_BLACK_LIST.getStatus());
return Result.success(userRespDTO);
}
@ -160,22 +171,22 @@ public class MyController extends BaseController {
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())) {
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());
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) {
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) {
} else if (isFollow && !isFan) {
userRespDTO.setRelation(UserRelationEnum.FOLLOW.getStatus());
return Result.success(userRespDTO);
}
@ -183,64 +194,102 @@ public class MyController extends BaseController {
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) })
@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,
public Result<PageResult<UserRespDTO>> getBlackList(
@RequestHeader(value = "Authorization", required = true) 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) })
@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,
public Result<PageResult<UserRespDTO>> getFollows(
@RequestHeader(value = "Authorization", required = true) 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) })
@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,
public Result<PageResult<UserRespDTO>> getFans(
@RequestHeader(value = "Authorization", required = true) 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);
}
@ApiOperation(value = "8.意见反馈", notes = "每天最多反馈10条")
@PostMapping("/feedback")
@GlobalInterceptor(checkAppUserLogin = true, frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 10)
public Result<Void> sendFeedback(@RequestHeader(value = "Authorization", required = true) String authorization,
@ApiParam(value = "反馈类型3个值0bug, 1建议2其它", required = true) @VerifyParam(required = true) @RequestParam("type") Integer type,
@ApiParam(value = "反馈内容最多300字", required = true) @VerifyParam(required = true, max = 300) @RequestParam("content") String content,
@ApiParam(value = "图片单张图片最大5M一次上传最多10张图片", required = false) @RequestParam("files") List<MultipartFile> files,
@ApiParam(value = "联系方式可选最多50字", required = false) @RequestParam("contact") @VerifyParam(max = 50) String contact) {
UserLoginDto userLoginDto = getUserLoginDto(authorization);
Feedback feedback = new Feedback();
feedback.setFeedbackId(String.valueOf(idWorker.nextId()));
feedback.setType(type);
feedback.setUserId(userLoginDto.getUserId());
feedback.setNickName(userLoginDto.getNickName());
feedback.setContent(content);
feedback.setImages(uploadImages(feedback, files));
feedbackService.save(feedback);
return Result.success();
}
private String uploadImages(Feedback feedback, List<MultipartFile> files) {
if (null == files || files.isEmpty()) {
return null;
}
return files.parallelStream().map(f -> uploadImages(feedback, f)).collect(Collectors.joining(","));
}
@SneakyThrows
private String uploadImages(Feedback feedback, MultipartFile file) {
String imageName = feedback.getUserId() + "_" + feedback.getFeedbackId() + "_" + idWorker.nextId()
+ StringTools.getFileSuffix(file.getOriginalFilename());
String filePath = USER_FEEDBACK_IMAGE_DIRECTORY + imageName;
s3Service.uploadImage("indie", filePath, file.getBytes());
return imageName;
}
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);
Pair<List<String>, Set<String>> pair = userCollectService.getCollectListWithBothFollowSet(userId, pageNum,
pageSize, collectTypeEnum);
List<String> objectIds = pair.getKey();
if(objectIds.isEmpty()) {
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()))
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) {
private UserRespDTO getUserRespDTO(UserInfo user, boolean withCount, Set<String> bothFollowSet) {
UserRespDTO userRespDTO = new UserRespDTO();
BeanUtils.copyProperties(user, userRespDTO);
if (null != userRespDTO.getAvatar()) {
@ -250,10 +299,10 @@ public class MyController extends BaseController {
userRespDTO.setBirthDay(
DateUtil.format(user.getBirthday(), DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern()));
}
if(!bothFollowSet.isEmpty()&&bothFollowSet.contains(userRespDTO.getId())) {
if (!bothFollowSet.isEmpty() && bothFollowSet.contains(userRespDTO.getId())) {
userRespDTO.setRelation(UserRelationEnum.BOTH_FOLLOW.getStatus());
}
if(!withCount) {
if (!withCount) {
return userRespDTO;
}
Optional<UserCollect> optional = userCollectService.findByUserId(userRespDTO.getId());
@ -264,7 +313,7 @@ public class MyController extends BaseController {
userRespDTO.setFansCount(userCollect.getFans().size());
userRespDTO.setFollowCount(userCollect.getFollows().size());
}
return userRespDTO;
}
}

@ -0,0 +1,7 @@
package com.luoo.user.dao;
import com.luoo.user.pojo.Feedback;
import org.springframework.data.jpa.repository.JpaRepository;
public interface FeedbackDao extends JpaRepository<Feedback, String> {
}

@ -0,0 +1,27 @@
package com.luoo.user.dto;
import java.util.List;
import org.springframework.web.multipart.MultipartFile;
import annotation.VerifyParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class UserFeedbackDto {
@ApiModelProperty(value = "反馈类型3个值0bug, 1建议2其它", example = "0")
@VerifyParam(required = true)
private int type;
@ApiModelProperty(value = "反馈内容最多300字")
@VerifyParam(required = true, max = 300)
private String content;
@ApiModelProperty(value = "图片单张图片最大5M一次上传最多10张图片")
private List<MultipartFile> files;
@ApiModelProperty(value = "联系方式可选最多50字")
@VerifyParam(max = 50)
private String contact;
}

@ -0,0 +1,92 @@
package com.luoo.user.pojo;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Id;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
@Getter
@Setter
@Entity
@Table(name="tb_user_feedback")
@EntityListeners(AuditingEntityListener.class)
public class Feedback implements Serializable {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@Id
private String feedbackId;
/**
* ID
*/
private String userId;
/**
*
*/
private String nickName;
/**
*
*/
private String content;
/**
* 30bug, 12
*/
private int type;
/**
*
*/
private String images;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@CreatedDate
private Date createTime;
/**
* ID
*/
private String pFeedbackId;
/**
* 0: 1:
*/
private int status;
/**
* 0:访 1:
*/
private int sendType;
/**
* 访
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@LastModifiedDate
private Date clientLastSendTime;
}

@ -0,0 +1,17 @@
package com.luoo.user.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.luoo.user.dao.FeedbackDao;
import com.luoo.user.pojo.Feedback;
@Service
public class FeedbackService {
@Autowired
private FeedbackDao feedbackDao;
public void save(Feedback appFeedback) {
feedbackDao.save(appFeedback);
}
}

@ -1,7 +1,5 @@
package com.luoo.user.service;
import com.google.common.collect.Lists;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import software.amazon.awssdk.core.sync.RequestBody;
@ -14,11 +12,9 @@ import software.amazon.awssdk.services.s3.presigner.S3Presigner;
import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.function.Consumer;
@Service
@ -97,7 +93,7 @@ public class S3Service {
return 1;
}
public void uploadAvatar(String bucket, String key, byte[] buffer) {
public void uploadImage(String bucket, String key, byte[] buffer) {
PutObjectRequest putObjectRequest = PutObjectRequest.builder()
.bucket(bucket)
.key(key)

Loading…
Cancel
Save