[uodate]新增修改昵称/修改头像/读取用户信息(头像+昵称)接口
This commit is contained in:
parent
1a17e5ecb8
commit
a98fdc67a6
|
@ -1,3 +1,11 @@
|
|||
### 请求 /system/user/page 接口 => 没有权限
|
||||
GET {{baseUrl}}/system/user/page?pageNo=1&pageSize=10
|
||||
Authorization: Bearer test104 # 使用测试账号
|
||||
|
||||
###
|
||||
PUT {{baseUrl}}/system/user/update-nick-name
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
{
|
||||
"nickname": "芋艿"
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package cn.iocoder.yudao.adminserver.modules.system.controller.user;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
@ -32,6 +33,7 @@ import java.util.*;
|
|||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
@Api(tags = "用户")
|
||||
@RestController
|
||||
|
@ -171,4 +173,18 @@ public class SysUserController {
|
|||
return success(userService.importUsers(list, updateSupport));
|
||||
}
|
||||
|
||||
@PutMapping("/update-nick-name")
|
||||
@ApiOperation("修改用户昵称")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:update')")
|
||||
public CommonResult<Boolean> updateNickName(@Valid @RequestBody SysUserProfileUpdateReqVO reqVO) {
|
||||
userService.updateNickName(getLoginUserId(), reqVO.getNickname());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get-user-info")
|
||||
@ApiOperation("获取用户信息:头像+昵称")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:query')")
|
||||
public CommonResult<SysUserDO> getUserInfo(){
|
||||
return success(userService.getUserInfo(getLoginUserId()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,4 +99,14 @@ public class SysUserProfileController {
|
|||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/avatar")
|
||||
@ApiOperation("修改用户头像")
|
||||
public CommonResult<Boolean> updateAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException{
|
||||
if (file.isEmpty()) {
|
||||
throw ServiceExceptionUtil.exception(FILE_IS_EMPTY);
|
||||
}
|
||||
userService.updateAvatar(getLoginUserId(),file.getInputStream());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
package cn.iocoder.yudao.adminserver.modules.system.service.user;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserImportExcelVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserImportRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserUpdateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
|
||||
|
@ -166,4 +161,24 @@ public interface SysUserService {
|
|||
*/
|
||||
SysUserImportRespVO importUsers(List<SysUserImportExcelVO> importUsers, boolean isUpdateSupport);
|
||||
|
||||
/**
|
||||
* 修改用户昵称
|
||||
* @param loginUserId 用户id
|
||||
* @param newNickname 用户新昵称
|
||||
*/
|
||||
void updateNickName(Long loginUserId, String newNickname);
|
||||
|
||||
/**
|
||||
* 修改用户头像
|
||||
* @param loginUserId 用户id
|
||||
* @param inputStream 文件
|
||||
*/
|
||||
void updateAvatar(Long loginUserId, InputStream inputStream);
|
||||
|
||||
/**
|
||||
* 获取当前登录用户头像与昵称
|
||||
* @return 用户实体类,仅包含头像于昵称两项
|
||||
* @param loginUserId 用户id
|
||||
*/
|
||||
SysUserDO getUserInfo(Long loginUserId);
|
||||
}
|
||||
|
|
|
@ -370,4 +370,46 @@ public class SysUserServiceImpl implements SysUserService {
|
|||
return respVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNickName(Long loginUserId, String newNickname) {
|
||||
this.checkUserExists(loginUserId);
|
||||
|
||||
SysUserDO sysUserDO = new SysUserDO();
|
||||
sysUserDO.setId(loginUserId);
|
||||
sysUserDO.setNickname(newNickname);
|
||||
userMapper.updateById(sysUserDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAvatar(Long loginUserId, InputStream avatarFile) {
|
||||
SysUserDO sysUserDO = userMapper.selectById(loginUserId);
|
||||
if (sysUserDO == null){
|
||||
throw exception(USER_NOT_EXISTS);
|
||||
}
|
||||
// 判断是否第一次上传头像
|
||||
if (sysUserDO.getAvatar().isEmpty()) {
|
||||
this.updateUserAvatar(loginUserId,avatarFile);
|
||||
return;
|
||||
}
|
||||
|
||||
// 删除旧文件
|
||||
String url = sysUserDO.getAvatar();
|
||||
String AvatarName = url.substring(url.lastIndexOf("/")+1);
|
||||
fileService.deleteFile(AvatarName);
|
||||
|
||||
// 存储文件
|
||||
String avatar = fileService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile));
|
||||
sysUserDO.setAvatar(avatar);
|
||||
userMapper.updateById(sysUserDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserDO getUserInfo(Long loginUserId) {
|
||||
SysUserDO sysUserDO = userMapper.selectById(loginUserId);
|
||||
|
||||
SysUserDO user = new SysUserDO();
|
||||
user.setNickname(sysUserDO.getNickname());
|
||||
user.setAvatar(sysUserDO.getAvatar());
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,22 +44,23 @@ spring:
|
|||
datasource:
|
||||
master:
|
||||
name: ruoyi-vue-pro
|
||||
url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: root
|
||||
password: 123456
|
||||
slave: # 模拟从库,可根据自己需要修改
|
||||
name: ruoyi-vue-pro
|
||||
url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
|
||||
url: jdbc:mysql://127.0.0.1:3308/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: root
|
||||
password: 123456
|
||||
# slave: # 模拟从库,可根据自己需要修改
|
||||
# name: ruoyi-vue-pro
|
||||
# url: jdbc:mysql://127.0.0.1:3308/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
|
||||
# driver-class-name: com.mysql.jdbc.Driver
|
||||
# username: root
|
||||
# password: 123456
|
||||
|
||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||
redis:
|
||||
host: 127.0.0.1 # 地址
|
||||
port: 6379 # 端口
|
||||
database: 0 # 数据库索引
|
||||
password: 123456
|
||||
|
||||
--- #################### 定时任务相关配置 ####################
|
||||
|
||||
|
|
|
@ -576,6 +576,28 @@ public class SysUserServiceImplTest extends BaseDbUnitTest {
|
|||
verify(passwordEncoder, times(1)).matches(eq(oldPassword), eq(user.getPassword()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_update_nick_name() {
|
||||
// 准备数据
|
||||
SysUserDO user = randomSysUserDO();
|
||||
userMapper.insert(user);
|
||||
System.out.println("=====>"+user);
|
||||
// 调用测试
|
||||
userService.updateNickName(user.getId(), randomString());
|
||||
|
||||
System.out.println(userMapper.selectById(user.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_get_user_info() {
|
||||
// 准备数据
|
||||
SysUserDO user = randomSysUserDO();
|
||||
userMapper.insert(user);
|
||||
// 调用测试
|
||||
System.out.println(userService.getUserInfo(user.getId()));
|
||||
}
|
||||
|
||||
|
||||
// ========== 随机对象 ==========
|
||||
|
||||
@SafeVarargs
|
||||
|
|
|
@ -123,7 +123,7 @@ export default {
|
|||
uploadImg() {
|
||||
this.$refs.cropper.getCropBlob(data => {
|
||||
let formData = new FormData();
|
||||
formData.append("avatarfile", data);
|
||||
formData.append("avatarFile", data);
|
||||
uploadAvatar(formData).then(response => {
|
||||
this.open = false;
|
||||
this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;
|
||||
|
|
Loading…
Reference in New Issue