mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 11:49:19 +08:00
完成订单批量导入功能
This commit is contained in:
+14
@@ -4,11 +4,13 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.ChangePasswordDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.UpdateUserInfoDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.UserVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.UserService;
|
||||
import top.xyquan.ecomdmbbackend.utils.FileUploadUtils;
|
||||
|
||||
/**
|
||||
* 用户管理控制器
|
||||
@@ -44,4 +46,16 @@ public class UserController {
|
||||
userService.changePassword(changePasswordDTO);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "上传用户头像", description = "上传用户头像图片")
|
||||
@PostMapping("/upload-avatar")
|
||||
public ApiResponse<UserVO> uploadAvatar(@RequestParam("file") MultipartFile file) {
|
||||
// 检查是否为图片文件
|
||||
if (!FileUploadUtils.isImageFile(file.getOriginalFilename())) {
|
||||
return ApiResponse.fail("只能上传图片文件");
|
||||
}
|
||||
|
||||
UserVO userVO = userService.uploadAvatar(file);
|
||||
return ApiResponse.success(userVO);
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -1,6 +1,7 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.ChangePasswordDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.LoginDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.RegisterDTO;
|
||||
@@ -59,4 +60,12 @@ public interface UserService extends IService<UserPO> {
|
||||
* @param changePasswordDTO 密码信息
|
||||
*/
|
||||
void changePassword(ChangePasswordDTO changePasswordDTO);
|
||||
|
||||
/**
|
||||
* 上传用户头像
|
||||
*
|
||||
* @param file 头像文件
|
||||
* @return 更新后的用户信息
|
||||
*/
|
||||
UserVO uploadAvatar(MultipartFile file);
|
||||
}
|
||||
|
||||
+29
@@ -21,6 +21,7 @@ import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
|
||||
import top.xyquan.ecomdmbbackend.utils.JwtUtils;
|
||||
import top.xyquan.ecomdmbbackend.utils.SecurityUtils;
|
||||
import top.xyquan.ecomdmbbackend.utils.TokenPayload;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -220,6 +221,34 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
||||
this.updateById(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO uploadAvatar(MultipartFile file) {
|
||||
// 从Security上下文获取用户ID
|
||||
Long userId = SecurityUtils.getCurrentUserId();
|
||||
if (userId == null) {
|
||||
throw new BusinessException("用户未登录");
|
||||
}
|
||||
|
||||
// 查询用户信息
|
||||
UserPO user = this.getById(userId);
|
||||
if (user == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
|
||||
// 上传头像到媒体模块(支持哈希校验和共享)
|
||||
MediaImageVO mediaImageVO = mediaImageService.uploadImageWithType(file, "avatar");
|
||||
String avatarUrl = mediaImageVO.getUrl();
|
||||
|
||||
// 更新用户头像信息
|
||||
user.setAvatar(avatarUrl);
|
||||
this.updateById(user);
|
||||
|
||||
// 转换为VO并返回
|
||||
UserVO userVO = new UserVO();
|
||||
BeanUtils.copyProperties(user, userVO);
|
||||
return userVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成登录响应
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user