更换用户背景图。

This commit is contained in:
haotianmingyue 2024-10-25 10:13:23 +08:00
parent 04302faaa4
commit 454bca30f4
2 changed files with 30 additions and 1 deletions

View File

@ -435,4 +435,32 @@ public class AppSystemController {
}
@PostMapping("/changeBackground")
public AjaxResult changeBackground(@RequestParam("user_name") String userName,
@RequestParam("background") MultipartFile background)
{
String localPath = RuoYiConfig.getProfile();
//头像图片
// MultipartFile avatarImage = uploadAvatarDto.getAvatarImage();
if (background.isEmpty()) {
return error("文件为空");
}
// 验证文件类型可选这里只允许jpg,jpeg和png格式
String fileType = background.getContentType().split("/")[1].toLowerCase();
if (!"jpg".equals(fileType) && !"jpeg".equals(fileType) && !"png".equals(fileType)) {
return error("只支持jpg、jpeg和png格式的图片");
}
String filePath = localPath + "/background";
try {
// 保存文件到服务器
background.transferTo(new File(filePath, userName+"_background.jpg"));
AjaxResult ajax = success();
ajax.put("上背景图片地址", filePath+"/"+userName+"_background.jpg");
return ajax;// 可以返回文件的相对路径或URL给前端
} catch (IOException e) {
e.printStackTrace();
return error("文件上传失败");
}
}
}

View File

@ -135,7 +135,7 @@ public class SysRegisterService
SysUser sysUser = new SysUser();
sysUser.setUserName(username);
sysUser.setPhonenumber(username);
sysUser.setAvatar("D:\\ruoyi\\uploadPath\\avatar\\default.png");
sysUser.setAvatar("https://gips0.baidu.com/it/u=3124792457,2870658645&fm=3039&app=3039&f=JPEG");
sysUser.setUserType("01");
UserInfo userInfo = new UserInfo();
@ -194,6 +194,7 @@ public class SysRegisterService
//---------------------------- 新建用户个人信息--------------------------------------------
userInfo.setUserId(newSysUser.getUserId());
userInfo.setPhonenumber(username);
userInfo.setBackGround("https://iknow-pic.cdn.bcebos.com/37d12f2eb9389b507e7594cf9735e5dde6116ea0");
// 获取当前时间的毫秒值
long currentTimeMillis = System.currentTimeMillis();
// 利用毫秒值构造Date对象