|
|
|
@ -5,6 +5,8 @@ import java.io.FileInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -19,10 +21,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import constants.Constants;
|
|
|
|
|
import controller.BaseController;
|
|
|
|
|
|
|
|
|
|
import com.luoo.user.dto.response.UserRespDTO;
|
|
|
|
|
import com.luoo.user.pojo.User;
|
|
|
|
|
import com.luoo.user.service.UserService;
|
|
|
|
|
import com.luoo.user.pojo.UserInfo;
|
|
|
|
|
import com.luoo.user.service.UserInfoService;
|
|
|
|
|
|
|
|
|
|
import annotation.GlobalInterceptor;
|
|
|
|
|
import annotation.VerifyParam;
|
|
|
|
@ -35,7 +38,6 @@ import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import util.DateUtil;
|
|
|
|
|
import util.JwtUtil;
|
|
|
|
|
import util.ScaleFilter;
|
|
|
|
|
import util.StringTools;
|
|
|
|
|
|
|
|
|
@ -43,11 +45,9 @@ import util.StringTools;
|
|
|
|
|
@CrossOrigin
|
|
|
|
|
@RequestMapping("/my")
|
|
|
|
|
@Api(tags = "MyController")
|
|
|
|
|
public class MyController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
public class MyController extends BaseController{
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserService userService;
|
|
|
|
|
private UserInfoService userInfoService;
|
|
|
|
|
|
|
|
|
|
public static String UPLOAD_DIRECTORY = System.getProperty("user.dir") + File.separator+"luoo_uploads"+File.separator;
|
|
|
|
|
|
|
|
|
@ -55,22 +55,17 @@ public class MyController {
|
|
|
|
|
@GetMapping("/getUserInfo")
|
|
|
|
|
@GlobalInterceptor
|
|
|
|
|
public Result getUserInfo(@RequestHeader(value = "token", required = false) String token) {
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(token);
|
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
|
}
|
|
|
|
|
UserRespDTO userRespDTO = new UserRespDTO();
|
|
|
|
|
if (Constants.TOKEN_ROLE_APP_USER.equals(userLoginDto.getRoles())) {
|
|
|
|
|
User user = userService.findById(userLoginDto.getUserId());
|
|
|
|
|
BeanUtils.copyProperties(user, userRespDTO);
|
|
|
|
|
} else {
|
|
|
|
|
userRespDTO.setNickname(userLoginDto.getNickName());
|
|
|
|
|
userRespDTO.setId(userLoginDto.getUserId());
|
|
|
|
|
}
|
|
|
|
|
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
|
|
|
|
|
BeanUtils.copyProperties(user, userRespDTO);
|
|
|
|
|
return Result.success(userRespDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "2.编辑个人信息", notes = "游客无法编辑个人信息")
|
|
|
|
|
@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),
|
|
|
|
@ -80,30 +75,32 @@ public class MyController {
|
|
|
|
|
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) {
|
|
|
|
|
@RequestParam("birthDay") String birthDay,
|
|
|
|
|
@RequestParam("sex") Integer sex) {
|
|
|
|
|
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
User user = userService.findById(userLoginDto.getUserId());
|
|
|
|
|
if (!StringTools.isEmpty(nickName) && !nickName.equals(user.getNickname())) {
|
|
|
|
|
long count = userService.countByNickName(nickName);
|
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(token);
|
|
|
|
|
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
|
|
|
|
|
if (!StringTools.isEmpty(nickName) && !nickName.equals(user.getNickName())) {
|
|
|
|
|
long count = userInfoService.countByNickName(nickName);
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
return Result.failed(StatusCode.USER_NICK_NAME_HAS_BEEN_EXIST);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!StringTools.isEmpty(nickName)) {
|
|
|
|
|
user.setNickname(nickName);
|
|
|
|
|
user.setNickName(nickName);
|
|
|
|
|
}
|
|
|
|
|
if (!StringTools.isEmpty(signature)) {
|
|
|
|
|
user.setPersonality(signature);
|
|
|
|
|
user.setSignature(signature);
|
|
|
|
|
}
|
|
|
|
|
if (!StringTools.isEmpty(birthDay)) {
|
|
|
|
|
user.setBirthday(DateUtil.parse(birthDay, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern()));
|
|
|
|
|
}
|
|
|
|
|
if (!StringTools.isEmpty(sex)) {
|
|
|
|
|
if (null!=sex) {
|
|
|
|
|
user.setSex(sex);
|
|
|
|
|
}
|
|
|
|
|
userService.update(user);
|
|
|
|
|
user.setModifyTime(new Date());
|
|
|
|
|
userInfoService.update(user);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -112,7 +109,7 @@ public class MyController {
|
|
|
|
|
@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);
|
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(token);
|
|
|
|
|
String folderName = UPLOAD_DIRECTORY + Constants.FOLDER_AVATAR;
|
|
|
|
|
File folder = new File(folderName);
|
|
|
|
|
if (!folder.exists()) {
|
|
|
|
@ -122,10 +119,10 @@ public class MyController {
|
|
|
|
|
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());
|
|
|
|
|
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
|
|
|
|
|
user.setAvatar(Constants.FOLDER_AVATAR + avatarName);
|
|
|
|
|
|
|
|
|
|
userService.update(user);
|
|
|
|
|
userInfoService.update(user);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
//待优化
|
|
|
|
@ -134,7 +131,7 @@ public class MyController {
|
|
|
|
|
@GlobalInterceptor(checkLogin = true)
|
|
|
|
|
public @ResponseBody byte[] getImage(@RequestHeader(value = "token", required = false) String token)
|
|
|
|
|
throws IOException {
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(token);
|
|
|
|
|
String folderName = UPLOAD_DIRECTORY + "avatar";
|
|
|
|
|
File folder = new File(folderName);
|
|
|
|
|
File avatarFileName = new File(folder.getPath() + File.separator + userLoginDto.getUserId() + ".JPG");
|
|
|
|
|