|
@@ -1,31 +1,40 @@
|
|
|
package com.yaoxiang.diagnosis.controller;
|
|
|
|
|
|
import com.yaoxiang.diagnosis.entity.UserInfo;
|
|
|
+import com.yaoxiang.diagnosis.file.FileService;
|
|
|
import com.yaoxiang.diagnosis.model.AuthUser;
|
|
|
+import com.yaoxiang.diagnosis.model.Result;
|
|
|
+import com.yaoxiang.diagnosis.model.UserVo;
|
|
|
+import com.yaoxiang.diagnosis.service.UserService;
|
|
|
+import com.yaoxiang.diagnosis.util.CommonUtil;
|
|
|
import com.yaoxiang.diagnosis.util.SecurityUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Api(tags = "用户信息")
|
|
|
@RestController
|
|
|
-@RequestMapping("/self")
|
|
|
+@RequestMapping("self")
|
|
|
public class UserInfoController {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+ @Autowired
|
|
|
+ private FileService fileService;
|
|
|
|
|
|
|
|
|
* 获取当前用户有权限使用的功能模块
|
|
|
*
|
|
|
- * @return
|
|
|
+ * @return authority
|
|
|
*/
|
|
|
@ApiOperation("获取用户权限")
|
|
|
- @GetMapping("/authority")
|
|
|
+ @GetMapping("authority")
|
|
|
public List<String> getAuthorities() {
|
|
|
AuthUser user = SecurityUtil.getCurrentUser();
|
|
|
UserInfo userInfo = user.getUser();
|
|
@@ -35,13 +44,41 @@ public class UserInfoController {
|
|
|
|
|
|
* 获取当前用户的信息
|
|
|
*
|
|
|
- * @return
|
|
|
+ * @return info
|
|
|
*/
|
|
|
@ApiOperation("获取用户信息")
|
|
|
- @GetMapping("/info")
|
|
|
+ @GetMapping("info")
|
|
|
public UserInfo getInfo() {
|
|
|
AuthUser user = SecurityUtil.getCurrentUser();
|
|
|
user.getUser().setPassword(null);
|
|
|
return user.getUser();
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation("更新积分")
|
|
|
+ @PostMapping("updateScore")
|
|
|
+ public Result updateScore(Long uid, Integer oldScore, Integer newScore) {
|
|
|
+ boolean result = userService.updateScore(uid, oldScore, newScore);
|
|
|
+ return Result.ok(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("更新头像")
|
|
|
+ @PostMapping("updateImage")
|
|
|
+ public Result updateImage(Long uid, @RequestBody MultipartFile file) throws IOException {
|
|
|
+ if (file == null) {
|
|
|
+ return Result.fail("请上传头像");
|
|
|
+ }
|
|
|
+ int suffixIndex = file.getOriginalFilename().lastIndexOf(".");
|
|
|
+ String suffix = file.getOriginalFilename().substring(suffixIndex);
|
|
|
+ String saveName = CommonUtil.randomUUID() + suffix;
|
|
|
+ String url = fileService.upload(file.getBytes(), saveName);
|
|
|
+ boolean result = userService.updateImage(uid, url);
|
|
|
+ return Result.ok(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("更新用户信息")
|
|
|
+ @PostMapping("updateInfo")
|
|
|
+ public Result updateInfo(UserVo userVo) {
|
|
|
+ boolean result = userService.updateInfo(userVo);
|
|
|
+ return Result.ok(result);
|
|
|
+ }
|
|
|
}
|