@@ -1,6 +1,7 @@
|
||||
package com.yunhai.userhome.controller.api;
|
||||
|
||||
import com.yunhai.platform.apistd.BizException;
|
||||
import com.yunhai.platform.openapi.client.OpenApiUserClient;
|
||||
import com.yunhai.platform.openapi.client.YschBaseOpenApi;
|
||||
import com.yunhai.platform.utils.enums.ClientEnum;
|
||||
import com.yunhai.platform.utils.exception.ErrorCode;
|
||||
@@ -55,6 +56,9 @@ public class UserSettingsController {
|
||||
@Autowired
|
||||
private UsedAppService usedAppService;
|
||||
|
||||
@Autowired
|
||||
private OpenApiUserClient openApiUserClient;
|
||||
|
||||
// ==================== 壁纸 ====================
|
||||
|
||||
/**
|
||||
@@ -525,6 +529,33 @@ public class UserSettingsController {
|
||||
userSettingsService.saveDesktopAppList(desktopApps);
|
||||
}
|
||||
|
||||
// ==================== 头像 ====================
|
||||
|
||||
/**
|
||||
* 上传头像:校验后经 OpenAPI 转发至 UserBase 统一存储(压缩并写入 sys_user.profile_picture)。<br>
|
||||
* 前端调用:UserInfoModal 更换头像 → POST /api/avatarUpload。<br>
|
||||
* 注意不复用 checkFile(其 5MB 上限被壁纸/图标共用),头像单独限制 20MB(与前端一致,拍照原图普遍偏大)。
|
||||
*/
|
||||
@PostMapping(value = "avatarUpload", produces = "application/json")
|
||||
public Map<String, String> avatarUpload(BoaUser authUserWithDept, @RequestParam("file") MultipartFile file) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new BizException(ErrorCode.CUSTOM, "请选择上传文件");
|
||||
}
|
||||
if (file.getSize() > 20L * 1024 * 1024) {
|
||||
throw new BizException(ErrorCode.CUSTOM, "图片大小不能超过20MB");
|
||||
}
|
||||
String url;
|
||||
try {
|
||||
url = openApiUserClient.updateUserProfilePicture(
|
||||
authUserWithDept.getId(), file.getBytes(), file.getOriginalFilename());
|
||||
} catch (Exception e) {
|
||||
throw new BizException(ErrorCode.CUSTOM, e.getMessage());
|
||||
}
|
||||
Map<String, String> result = new HashMap<>();
|
||||
result.put("url", url);
|
||||
return result;
|
||||
}
|
||||
|
||||
// ==================== 私有方法 ====================
|
||||
|
||||
private String upload(@RequestParam("file") MultipartFile file, String pathName) {
|
||||
|
||||
Reference in New Issue
Block a user