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.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.luoo.user.pojo.Feedback;
import com.luoo.user.pojo.UserCollect; import com.luoo.user.pojo.UserCollect;
import com.luoo.user.service.UserCollectService; 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.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.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;
@ -31,6 +33,7 @@ import controller.BaseController;
import com.luoo.user.dto.UserInfoUpdateDto; import com.luoo.user.dto.UserInfoUpdateDto;
import com.luoo.user.dto.response.UserRespDTO; import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.pojo.UserInfo; import com.luoo.user.pojo.UserInfo;
import com.luoo.user.service.FeedbackService;
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 com.luoo.user.util.IpUtil;
@ -43,11 +46,14 @@ import api.StatusCode;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.CollectTypeEnum; import enums.CollectTypeEnum;
import enums.DateTimePatternEnum; import enums.DateTimePatternEnum;
import enums.RequestFrequencyTypeEnum;
import enums.UserRelationEnum; 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;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.SneakyThrows;
import util.DateUtil; import util.DateUtil;
import util.IdWorker; import util.IdWorker;
import util.ScaleFilter; import util.ScaleFilter;
@ -67,13 +73,17 @@ public class MyController extends BaseController {
@Autowired @Autowired
// private UserCollectInfoService userCollectInfoService; // private UserCollectInfoService userCollectInfoService;
private UserCollectService userCollectService; 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 = "游客无法获取个人信息") @ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息")
@GetMapping("/userInfo") @GetMapping("/userInfo")
@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 = true) String authorization) {
UserLoginDto userLoginDto = getUserLoginDto(authorization); UserLoginDto userLoginDto = getUserLoginDto(authorization);
UserInfo user = userInfoService.findById(userLoginDto.getUserId()); UserInfo user = userInfoService.findById(userLoginDto.getUserId());
UserRespDTO userRespDTO = getUserRespDTO(user, true, Collections.emptySet()); UserRespDTO userRespDTO = getUserRespDTO(user, true, Collections.emptySet());
@ -83,7 +93,7 @@ public class MyController extends BaseController {
@ApiOperation(value = "2.更新个人信息", notes = "游客无法编辑个人信息") @ApiOperation(value = "2.更新个人信息", notes = "游客无法编辑个人信息")
@PutMapping("/userInfo") @PutMapping("/userInfo")
@GlobalInterceptor(checkAppUserLogin = true) @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) { @VerifyParam(required = true) @RequestBody UserInfoUpdateDto userInfoUpdateDto) {
UserLoginDto userLoginDto = getUserLoginDto(authorization); UserLoginDto userLoginDto = getUserLoginDto(authorization);
UserInfo user = userInfoService.findById(userLoginDto.getUserId()); 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/") @ApiOperation(value = "3.上传个人头像", notes = "图片压缩为70X70 JPEG存入S3桶为indie目录为 user/avatar/")
@PostMapping("/avatar") @PostMapping("/avatar")
@GlobalInterceptor(checkAppUserLogin = true) @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 { @VerifyParam(required = true) MultipartFile file) throws IOException {
UserLoginDto userLoginDto = getUserLoginDto(authorization); UserLoginDto userLoginDto = getUserLoginDto(authorization);
byte[] thumbnail = ScaleFilter.createThumbnail(file.getInputStream(), Constants.LENGTH_70, Constants.LENGTH_70); byte[] thumbnail = ScaleFilter.createThumbnail(file.getInputStream(), Constants.LENGTH_70, Constants.LENGTH_70);
String avatarName = userLoginDto.getUserId() + "_" + idWorker.nextId() String avatarName = userLoginDto.getUserId() + "_" + idWorker.nextId()
+ StringTools.getFileSuffix(file.getOriginalFilename()); + StringTools.getFileSuffix(file.getOriginalFilename());
String filePath = UPLOAD_DIRECTORY + avatarName; String filePath = USER_AVATAR_DIRECTORY + avatarName;
s3Service.uploadAvatar("indie", filePath, thumbnail); s3Service.uploadImage("indie", filePath, thumbnail);
UserInfo user = userInfoService.findById(userLoginDto.getUserId()); UserInfo user = userInfoService.findById(userLoginDto.getUserId());
user.setAvatar(filePath); user.setAvatar(filePath);
@ -136,7 +146,8 @@ public class MyController extends BaseController {
@ApiOperation(value = "4.查看他人信息", notes = "游客无法查看他人信息") @ApiOperation(value = "4.查看他人信息", notes = "游客无法查看他人信息")
@GetMapping("/otherUserInfo/{userId}") @GetMapping("/otherUserInfo/{userId}")
@GlobalInterceptor(checkAppUserLogin = true) @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) { @VerifyParam(required = true) @PathVariable String userId) {
UserInfo user = userInfoService.findById(userId); UserInfo user = userInfoService.findById(userId);
if (null == user) { if (null == user) {
@ -185,26 +196,26 @@ public class MyController extends BaseController {
} }
@ApiOperation(value = "5.查询黑名单") @ApiOperation(value = "5.查询黑名单")
@ApiImplicitParams({ @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true),
@ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true),
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) }) @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) })
@GetMapping("/blackList/{pageNum}/{pageSize}") @GetMapping("/blackList/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true) @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 pageNum,
@PathVariable @VerifyParam(required = true) Integer pageSize) { @PathVariable @VerifyParam(required = true) Integer pageSize) {
UserLoginDto userLoginDto = getUserLoginDto(authorization); UserLoginDto userLoginDto = getUserLoginDto(authorization);
return getCollectedUserInfo(userLoginDto.getUserId(), pageNum, pageSize, CollectTypeEnum.BLACK_LIST); return getCollectedUserInfo(userLoginDto.getUserId(), pageNum, pageSize, CollectTypeEnum.BLACK_LIST);
} }
@ApiOperation(value = "6.查询关注人信息") @ApiOperation(value = "6.查询关注人信息")
@ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", required = true), @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", required = true),
@ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true), @ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true),
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) }) @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) })
@GetMapping("/follows/{userId}/{pageNum}/{pageSize}") @GetMapping("/follows/{userId}/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true) @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) String userId,
@PathVariable @VerifyParam(required = true) Integer pageNum, @PathVariable @VerifyParam(required = true) Integer pageNum,
@PathVariable @VerifyParam(required = true) Integer pageSize) { @PathVariable @VerifyParam(required = true) Integer pageSize) {
@ -218,16 +229,54 @@ public class MyController extends BaseController {
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) }) @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) })
@GetMapping("/fans/{userId}/{pageNum}/{pageSize}") @GetMapping("/fans/{userId}/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true) @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) String userId,
@PathVariable @VerifyParam(required = true) Integer pageNum, @PathVariable @VerifyParam(required = true) Integer pageNum,
@PathVariable @VerifyParam(required = true) Integer pageSize) { @PathVariable @VerifyParam(required = true) Integer pageSize) {
return getCollectedUserInfo(userId, pageNum, pageSize, CollectTypeEnum.FANS); 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, private Result<PageResult<UserRespDTO>> getCollectedUserInfo(String userId, Integer pageNum, Integer pageSize,
CollectTypeEnum collectTypeEnum) { 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(); List<String> objectIds = pair.getKey();
if (objectIds.isEmpty()) { if (objectIds.isEmpty()) {
return Result.success(new PageResult<UserRespDTO>(0L, Collections.emptyList())); return Result.success(new PageResult<UserRespDTO>(0L, Collections.emptyList()));

@ -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; 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.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import software.amazon.awssdk.core.sync.RequestBody; import software.amazon.awssdk.core.sync.RequestBody;
@ -14,11 +12,9 @@ import software.amazon.awssdk.services.s3.presigner.S3Presigner;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
@Service @Service
@ -97,7 +93,7 @@ public class S3Service {
return 1; return 1;
} }
public void uploadAvatar(String bucket, String key, byte[] buffer) { public void uploadImage(String bucket, String key, byte[] buffer) {
PutObjectRequest putObjectRequest = PutObjectRequest.builder() PutObjectRequest putObjectRequest = PutObjectRequest.builder()
.bucket(bucket) .bucket(bucket)
.key(key) .key(key)

Loading…
Cancel
Save