|
|
|
@ -1,24 +1,25 @@
|
|
|
|
|
package com.luoo.user.controller;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
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;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
import com.luoo.user.dto.response.UserRespDTO;
|
|
|
|
|
import com.luoo.user.pojo.User;
|
|
|
|
|
import com.luoo.user.service.UserService;
|
|
|
|
@ -35,6 +36,7 @@ import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import util.DateUtil;
|
|
|
|
|
import util.JwtUtil;
|
|
|
|
|
import util.ScaleFilter;
|
|
|
|
|
import util.StringTools;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@ -47,9 +49,7 @@ public class MyController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserService userService;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @Value("${project.folder:}") private String projectFolder="./";
|
|
|
|
|
*/
|
|
|
|
|
public static String UPLOAD_DIRECTORY = System.getProperty("user.dir") + File.separator+"luoo_uploads"+File.separator;
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "1.获取个人信息")
|
|
|
|
|
@GetMapping("/getUserInfo")
|
|
|
|
@ -70,73 +70,75 @@ public class MyController {
|
|
|
|
|
return Result.success(userRespDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "2.编辑个人信息",notes="游客无法编辑个人信息")
|
|
|
|
|
@ApiImplicitParams({
|
|
|
|
|
@ApiImplicitParam(name = "nickName", value = "昵称,最多12个字符", required = false),
|
|
|
|
|
@ApiImplicitParam(name = "signature", value = "签名,最多50个字符", required = false),
|
|
|
|
|
@ApiImplicitParam(name = "birthDay", value = "生日,格式为: yyyy.MM.dd", required = false),
|
|
|
|
|
@ApiImplicitParam(name = "sex", value = "性别,4个值,0为男,1 为女,2为保密,不填为空", required = false)
|
|
|
|
|
})
|
|
|
|
|
@ApiOperation(value = "2.编辑个人信息", notes = "游客无法编辑个人信息")
|
|
|
|
|
@ApiImplicitParams({ @ApiImplicitParam(name = "nickName", value = "昵称,最多12个字符", required = false),
|
|
|
|
|
@ApiImplicitParam(name = "signature", value = "签名,最多50个字符", required = false),
|
|
|
|
|
@ApiImplicitParam(name = "birthDay", value = "生日,格式为: yyyy.MM.dd", required = false),
|
|
|
|
|
@ApiImplicitParam(name = "sex", value = "性别,4个值,0为男,1 为女,2为保密,不填为空", required = false) })
|
|
|
|
|
@PostMapping("/updateUserInfo")
|
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
|
public Result<Void> updateUserInfo(@RequestHeader(value = "token", required = false) String token,
|
|
|
|
|
@VerifyParam(max = 12) @RequestParam("nickName") String nickName,
|
|
|
|
|
@VerifyParam(max = 50)@RequestParam("signature") String signature,
|
|
|
|
|
@RequestParam("birthDay") String birthDay,
|
|
|
|
|
@RequestParam("sex") String sex) {
|
|
|
|
|
|
|
|
|
|
@VerifyParam(max = 12) @RequestParam("nickName") String nickName,
|
|
|
|
|
@VerifyParam(max = 50) @RequestParam("signature") String signature,
|
|
|
|
|
@RequestParam("birthDay") String birthDay, @RequestParam("sex") String sex) {
|
|
|
|
|
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
User user = userService.findById(userLoginDto.getUserId());
|
|
|
|
|
if(!StringTools.isEmpty(nickName)&&!nickName.equals(user.getNickname())) {
|
|
|
|
|
if (!StringTools.isEmpty(nickName) && !nickName.equals(user.getNickname())) {
|
|
|
|
|
long count = userService.countByNickName(nickName);
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
return Result.failed(StatusCode.USER_NICK_NAME_HAS_BEEN_EXIST);
|
|
|
|
|
}
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
return Result.failed(StatusCode.USER_NICK_NAME_HAS_BEEN_EXIST);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!StringTools.isEmpty(nickName)) {
|
|
|
|
|
|
|
|
|
|
if (!StringTools.isEmpty(nickName)) {
|
|
|
|
|
user.setNickname(nickName);
|
|
|
|
|
}
|
|
|
|
|
if(!StringTools.isEmpty(signature)) {
|
|
|
|
|
if (!StringTools.isEmpty(signature)) {
|
|
|
|
|
user.setPersonality(signature);
|
|
|
|
|
}
|
|
|
|
|
if(!StringTools.isEmpty(birthDay)) {
|
|
|
|
|
if (!StringTools.isEmpty(birthDay)) {
|
|
|
|
|
user.setBirthday(DateUtil.parse(birthDay, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern()));
|
|
|
|
|
}
|
|
|
|
|
if(!StringTools.isEmpty(sex)) {
|
|
|
|
|
if (!StringTools.isEmpty(sex)) {
|
|
|
|
|
user.setSex(sex);
|
|
|
|
|
}
|
|
|
|
|
userService.update(user);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @ApiOperation(value = "2.上传个人头像")
|
|
|
|
|
*
|
|
|
|
|
* @RequestMapping("/uploadAvatar")
|
|
|
|
|
*
|
|
|
|
|
* @GlobalInterceptor(checkLogin = true) public Result
|
|
|
|
|
* uploadAvatar(@RequestHeader(value = "token", required = false) String token,
|
|
|
|
|
* MultipartFile file) throws IOException { UserLoginDto userLoginDto =
|
|
|
|
|
* jwtUtil.getUserLoginDto(token); String folderName = projectFolder +
|
|
|
|
|
* Constants.FOLDER_AVATAR; File folder = new File(folderName); if
|
|
|
|
|
* (!folder.exists()) { folder.exists(); }
|
|
|
|
|
*
|
|
|
|
|
* String avatarName = userLoginDto.getUserId() +
|
|
|
|
|
* StringTools.getFileSuffix(file.getOriginalFilename()); File avatarFileName =
|
|
|
|
|
* new File(folder.getPath() + "/" + avatarName);
|
|
|
|
|
*
|
|
|
|
|
* file.transferTo(avatarFileName);
|
|
|
|
|
*
|
|
|
|
|
* ScaleFilter.createThumbnail(avatarFileName, Constants.LENGTH_70,
|
|
|
|
|
* Constants.LENGTH_70, avatarFileName);
|
|
|
|
|
*
|
|
|
|
|
* AppUserInfo appUserInfo = new AppUserInfo();
|
|
|
|
|
* appUserInfo.setAvatar(Constants.FOLDER_AVATAR + avatarName);
|
|
|
|
|
* appUserInfoService.updateAppUserInfoByUserId(appUserInfo,
|
|
|
|
|
* userLoginDto.getUserId()); return getSuccessResponseVO(null); }
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "3.上传个人头像", notes = "图片压缩为70X70 JPEG,存入服务器用户目录/luoo_uploads/avatar/")
|
|
|
|
|
@PostMapping("/uploadAvatar")
|
|
|
|
|
@GlobalInterceptor(checkLogin = true)
|
|
|
|
|
public Result<Void> uploadAvatar(@RequestHeader(value = "token", required = false) String token,
|
|
|
|
|
@VerifyParam(required = true) MultipartFile file) throws IOException {
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
String folderName = UPLOAD_DIRECTORY + Constants.FOLDER_AVATAR;
|
|
|
|
|
File folder = new File(folderName);
|
|
|
|
|
if (!folder.exists()) {
|
|
|
|
|
java.nio.file.Files.createDirectories(Paths.get(folderName));
|
|
|
|
|
}
|
|
|
|
|
String avatarName = userLoginDto.getUserId() + StringTools.getFileSuffix(file.getOriginalFilename());
|
|
|
|
|
File avatarFileName = new File(folder.getPath() + "/" + avatarName);
|
|
|
|
|
file.transferTo(avatarFileName);
|
|
|
|
|
ScaleFilter.createThumbnail(avatarFileName, Constants.LENGTH_70, Constants.LENGTH_70, avatarFileName);
|
|
|
|
|
User user = userService.findById(userLoginDto.getUserId());
|
|
|
|
|
user.setAvatar(Constants.FOLDER_AVATAR + avatarName);
|
|
|
|
|
|
|
|
|
|
userService.update(user);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
//待优化
|
|
|
|
|
@ApiOperation(value = "4.下载个人头像")
|
|
|
|
|
@GetMapping(value = "/avatar", produces = MediaType.IMAGE_JPEG_VALUE)
|
|
|
|
|
@GlobalInterceptor(checkLogin = true)
|
|
|
|
|
public @ResponseBody byte[] getImage(@RequestHeader(value = "token", required = false) String token)
|
|
|
|
|
throws IOException {
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
String folderName = UPLOAD_DIRECTORY + "avatar";
|
|
|
|
|
File folder = new File(folderName);
|
|
|
|
|
File avatarFileName = new File(folder.getPath() + File.separator + userLoginDto.getUserId() + ".JPG");
|
|
|
|
|
InputStream in = new FileInputStream(avatarFileName);
|
|
|
|
|
return IOUtils.toByteArray(in);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|