reactor:【INFRA】文件上传 api,增加 directory 参数,去除 path 参数,并支持按照日期分目录、文件名不再使用 sha256 而是时间戳
This commit is contained in:
@@ -23,14 +23,11 @@ import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY;
|
||||
|
||||
@Tag(name = "管理后台 - 用户个人中心")
|
||||
@RestController
|
||||
@@ -79,16 +76,4 @@ public class UserProfileController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Deprecated // TODO @芋艿:逐步替换到 updateUserProfile 接口
|
||||
@RequestMapping(value = "/update-avatar",
|
||||
method = {RequestMethod.POST, RequestMethod.PUT}) // 解决 uni-app 不支持 Put 上传文件的问题
|
||||
@Operation(summary = "上传用户个人头像")
|
||||
public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception {
|
||||
if (file.isEmpty()) {
|
||||
throw exception(FILE_IS_EMPTY);
|
||||
}
|
||||
String avatar = userService.updateUserAvatar(getLoginUserId(), file.getInputStream());
|
||||
return success(avatar);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqV
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -73,14 +72,6 @@ public interface AdminUserService {
|
||||
*/
|
||||
void updateUserPassword(Long id, @Valid UserProfileUpdatePasswordReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 更新用户头像
|
||||
*
|
||||
* @param id 用户 id
|
||||
* @param avatarFile 头像文件
|
||||
*/
|
||||
String updateUserAvatar(Long id, InputStream avatarFile) throws Exception;
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*
|
||||
|
||||
@@ -82,8 +82,6 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
@Resource
|
||||
private UserPostMapper userPostMapper;
|
||||
|
||||
@Resource
|
||||
private FileApi fileApi;
|
||||
@Resource
|
||||
private ConfigApi configApi;
|
||||
|
||||
@@ -205,19 +203,6 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
userMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String updateUserAvatar(Long id, InputStream avatarFile) {
|
||||
validateUserExists(id);
|
||||
// 存储文件
|
||||
String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile));
|
||||
// 更新路径
|
||||
AdminUserDO sysUserDO = new AdminUserDO();
|
||||
sysUserDO.setId(id);
|
||||
sysUserDO.setAvatar(avatar);
|
||||
userMapper.updateById(sysUserDO);
|
||||
return avatar;
|
||||
}
|
||||
|
||||
@Override
|
||||
@LogRecord(type = SYSTEM_USER_TYPE, subType = SYSTEM_USER_UPDATE_PASSWORD_SUB_TYPE, bizNo = "{{#id}}",
|
||||
success = SYSTEM_USER_UPDATE_PASSWORD_SUCCESS)
|
||||
|
||||
Reference in New Issue
Block a user