个人中心优化,增加上传头像接口
This commit is contained in:
@@ -4,14 +4,17 @@ import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.ShopUser;
|
||||
import com.ruoyi.common.core.domain.entity.ShopUserResq;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.framework.web.service.SysLoginService;
|
||||
import com.ruoyi.system.config.AliConfig;
|
||||
import com.ruoyi.system.service.AliConfigService;
|
||||
import com.ruoyi.system.service.IShopUserService;
|
||||
import com.ruoyi.system.service.ShopUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@RequestMapping("/client")
|
||||
@RestController
|
||||
@@ -23,7 +26,8 @@ public class ClientShopUserController {
|
||||
private AliConfigService aliConfigService;
|
||||
@Autowired
|
||||
private ShopUserService shopUserService;
|
||||
|
||||
@Autowired
|
||||
private IShopUserService iShopUserService;
|
||||
|
||||
/**
|
||||
* 获取验证码
|
||||
@@ -65,10 +69,77 @@ public class ClientShopUserController {
|
||||
*/
|
||||
@PostMapping("/updateUser")
|
||||
public AjaxResult modifyUserInfo(@RequestBody ShopUser shopUser){
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
if (userId == null) {
|
||||
return AjaxResult.error("用户未登录");
|
||||
}
|
||||
shopUser.setUserId(userId);
|
||||
return AjaxResult.success(shopUserService.modifyUser(shopUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取个人信息
|
||||
* @return 个人信息
|
||||
*/
|
||||
@GetMapping("/getUserInfo")
|
||||
public AjaxResult getUserInfo() {
|
||||
// 获取当前登录用户名
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
if (userId == null) {
|
||||
return AjaxResult.error("用户未登录");
|
||||
}
|
||||
|
||||
// 根据用户ID查询完整的用户信息
|
||||
ShopUser shopUser = iShopUserService.selectShopUserByUserId(userId);
|
||||
if (shopUser == null) {
|
||||
return AjaxResult.error("未找到用户信息");
|
||||
}
|
||||
|
||||
// 出于安全考虑,清除敏感信息
|
||||
shopUser.setPassword(null);
|
||||
|
||||
return AjaxResult.success(shopUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID获取个人信息
|
||||
* @param userId 用户ID
|
||||
* @return 个人信息
|
||||
*/
|
||||
@GetMapping("/getUserInfoById/{userId}")
|
||||
public AjaxResult getUserInfoById(@PathVariable("userId") Long userId) {
|
||||
if (userId == null) {
|
||||
return AjaxResult.error("用户ID不能为空");
|
||||
}
|
||||
|
||||
// 根据用户ID查询完整的用户信息
|
||||
ShopUser shopUser = iShopUserService.selectShopUserByUserId(userId);
|
||||
if (shopUser == null) {
|
||||
return AjaxResult.error("未找到用户信息");
|
||||
}
|
||||
|
||||
// 出于安全考虑,清除敏感信息
|
||||
shopUser.setPassword(null);
|
||||
|
||||
return AjaxResult.success(shopUser);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/user/file")
|
||||
public AjaxResult addConfigFile(
|
||||
@RequestParam("file") MultipartFile file
|
||||
) throws IOException {
|
||||
// 检查是否已经登录
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
if (userId == null) {
|
||||
return AjaxResult.error("用户未登录");
|
||||
}
|
||||
// 1. 处理文件上传
|
||||
if (file != null && !file.isEmpty()) {
|
||||
// 保存文件逻辑
|
||||
return AjaxResult.success("请求成功", AliConfig.ossUp("user/", file.getOriginalFilename(), file.getInputStream()));
|
||||
}
|
||||
return AjaxResult.error("文件不能为空");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user