[update] 新增修改昵称,修改头像,查询昵称与头像接口

This commit is contained in:
宋天 2021-10-19 22:16:42 +08:00
parent d194e14780
commit c06d6e53f6
22 changed files with 218 additions and 72 deletions

View File

@ -2,12 +2,12 @@ package cn.iocoder.yudao.adminserver.modules.infra.controller.file;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO;
import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFileRespVO; import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFileRespVO;
import cn.iocoder.yudao.adminserver.modules.infra.convert.file.InfFileConvert; import cn.iocoder.yudao.adminserver.modules.infra.convert.file.InfFileConvert;
import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService;
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
@ -35,7 +35,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
public class InfFileController { public class InfFileController {
@Resource @Resource
private InfFileService fileService; private InfFileCoreService fileService;
@PostMapping("/upload") @PostMapping("/upload")
@ApiOperation("上传文件") @ApiOperation("上传文件")

View File

@ -2,7 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.infra.convert.file;
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFileRespVO; import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFileRespVO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;

View File

@ -1,25 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file;
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface InfFileMapper extends BaseMapperX<InfFileDO> {
default Integer selectCountById(String id) {
return selectCount("id", id);
}
default PageResult<InfFileDO> selectPage(InfFilePageReqVO reqVO) {
return selectPage(reqVO, new QueryWrapperX<InfFileDO>()
.likeIfPresent("id", reqVO.getId())
.likeIfPresent("type", reqVO.getType())
.betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc("create_time"));
}
}

View File

@ -27,7 +27,4 @@ public interface InfErrorCodeConstants {
ErrorCode API_ERROR_LOG_NOT_FOUND = new ErrorCode(1001002000, "API 错误日志不存在"); ErrorCode API_ERROR_LOG_NOT_FOUND = new ErrorCode(1001002000, "API 错误日志不存在");
ErrorCode API_ERROR_LOG_PROCESSED = new ErrorCode(1001002001, "API 错误日志已处理"); ErrorCode API_ERROR_LOG_PROCESSED = new ErrorCode(1001002001, "API 错误日志已处理");
// ========== 文件 1001003000 ==========
ErrorCode FILE_NOT_EXISTS = new ErrorCode(1001003000, "文件不存在");
} }

View File

@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService;
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; 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.profile.SysUserProfileUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*;
@ -16,6 +15,7 @@ import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService;
import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService;
import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService;
import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService;
import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService;
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.exception.ServiceException;
@ -59,7 +59,7 @@ public class SysUserServiceImpl implements SysUserService {
@Resource @Resource
private PasswordEncoder passwordEncoder; private PasswordEncoder passwordEncoder;
@Resource @Resource
private InfFileService fileService; private InfFileCoreService fileService;
@Override @Override
public Long createUser(SysUserCreateReqVO reqVO) { public Long createUser(SysUserCreateReqVO reqVO) {

View File

@ -3,11 +3,11 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.file;
import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.io.resource.ResourceUtil;
import cn.iocoder.yudao.adminserver.BaseDbUnitTest; import cn.iocoder.yudao.adminserver.BaseDbUnitTest;
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper;
import cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.adminserver.modules.infra.framework.file.config.FileProperties; import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties;
import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO;
import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file.InfFileMapper;
import cn.iocoder.yudao.adminserver.modules.infra.service.file.impl.InfFileServiceImpl;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
@ -15,8 +15,8 @@ import org.springframework.context.annotation.Import;
import javax.annotation.Resource; import javax.annotation.Resource;
import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.FILE_NOT_EXISTS;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.FILE_NOT_EXISTS;
import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
@ -24,17 +24,17 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
@Import({InfFileServiceImpl.class, FileProperties.class}) @Import({InfFileCoreServiceImpl.class, FileProperties.class})
public class InfFileServiceTest extends BaseDbUnitTest { public class InfFileServiceTest extends BaseDbUnitTest {
@Resource @Resource
private InfFileServiceImpl fileService; private InfFileCoreServiceImpl fileService;
@MockBean @MockBean
private FileProperties fileProperties; private FileProperties fileProperties;
@Resource @Resource
private InfFileMapper fileMapper; private InfFileCoreMapper fileMapper;
@Test @Test
public void testCreateFile_success() { public void testCreateFile_success() {

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.adminserver.modules.system.service.user;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.iocoder.yudao.adminserver.BaseDbUnitTest; import cn.iocoder.yudao.adminserver.BaseDbUnitTest;
import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService;
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; 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.profile.SysUserProfileUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*;
@ -14,6 +13,7 @@ import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService;
import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService;
import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService;
import cn.iocoder.yudao.adminserver.modules.system.service.user.impl.SysUserServiceImpl; import cn.iocoder.yudao.adminserver.modules.system.service.user.impl.SysUserServiceImpl;
import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService;
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO;
import cn.iocoder.yudao.coreservice.modules.system.enums.common.SysSexEnum; import cn.iocoder.yudao.coreservice.modules.system.enums.common.SysSexEnum;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
@ -69,7 +69,7 @@ public class SysUserServiceImplTest extends BaseDbUnitTest {
@MockBean @MockBean
private PasswordEncoder passwordEncoder; private PasswordEncoder passwordEncoder;
@MockBean @MockBean
private InfFileService fileService; private InfFileCoreService fileService;
@Test @Test
public void testCreatUser_success() { public void testCreatUser_success() {

View File

@ -1,10 +1,24 @@
package cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file; package cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file;
import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface InfFileCoreMapper extends BaseMapperX<InfFileDO> { public interface InfFileCoreMapper extends BaseMapperX<InfFileDO> {
default Integer selectCountById(String id) {
return selectCount("id", id);
}
default PageResult<InfFileDO> selectPage(InfFilePageReqVO reqVO) {
return selectPage(reqVO, new QueryWrapperX<InfFileDO>()
.likeIfPresent("id", reqVO.getId())
.likeIfPresent("type", reqVO.getType())
.betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc("create_time"));
}
} }

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo; package cn.iocoder.yudao.coreservice.modules.infra.file.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo; package cn.iocoder.yudao.coreservice.modules.infra.file.vo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.infra.framework.file.config; package cn.iocoder.yudao.coreservice.modules.infra.framework.file.config;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.infra.framework.file.config; package cn.iocoder.yudao.coreservice.modules.infra.framework.file.config;
import lombok.Data; import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;

View File

@ -13,4 +13,4 @@
* 综合考虑暂时使用方案 3 的方式比较适合这样一个 all in one 的项目 * 综合考虑暂时使用方案 3 的方式比较适合这样一个 all in one 的项目
* 随着文件的量级大了之后还是推荐采用云服务 * 随着文件的量级大了之后还是推荐采用云服务
*/ */
package cn.iocoder.yudao.adminserver.modules.infra.framework.file; package cn.iocoder.yudao.coreservice.modules.infra.framework.file;

View File

@ -1,15 +1,17 @@
package cn.iocoder.yudao.adminserver.modules.infra.service.file; package cn.iocoder.yudao.coreservice.modules.infra.service.file;
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO;
/** /**
* 文件 Service 接口 * @Class:ruoyi-vue-pro.cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService
* * @Descript: 文件 core Service 接口
* @author 芋道源码 * @Author:宋天
* @Date:2021/10/19
*/ */
public interface InfFileService { public interface InfFileCoreService {
/** /**
* 保存文件并返回文件的访问路径 * 保存文件并返回文件的访问路径
@ -42,5 +44,4 @@ public interface InfFileService {
* @return 文件分页 * @return 文件分页
*/ */
PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO); PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO);
} }

View File

@ -1,31 +1,32 @@
package cn.iocoder.yudao.adminserver.modules.infra.service.file.impl; package cn.iocoder.yudao.coreservice.modules.infra.service.file.impl;
import cn.hutool.core.io.FileTypeUtil; import cn.hutool.core.io.FileTypeUtil;
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper;
import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO;
import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties;
import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.adminserver.modules.infra.framework.file.config.FileProperties;
import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO;
import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file.InfFileMapper;
import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.FILE_NOT_EXISTS;
import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.FILE_NOT_EXISTS;
import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS;
/** /**
* 文件 Service 实现类 * @Class:ruoyi-vue-pro.cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl
* * @Descript: core service 文件实现类
* @author 芋道源码 * @Author:宋天
* @Date:2021/10/19
*/ */
@Service @Service
public class InfFileServiceImpl implements InfFileService { public class InfFileCoreServiceImpl implements InfFileCoreService {
@Resource @Resource
private InfFileMapper fileMapper; private InfFileCoreMapper fileMapper;
@Resource @Resource
private FileProperties fileProperties; private FileProperties fileProperties;

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.coreservice.modules.system.controller.user.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("用户个人中心信息 Response VO")
public class SysUserCoreProfileRespVo {
@ApiModelProperty(value = "用户昵称", required = true, example = "芋艿")
private String nickName;
@ApiModelProperty(value = "用户头像", required = true, example = "/infra/file/get/35a12e57-4297-4faa-bf7d-7ed2f211c952")
private String avatar;
}

View File

@ -14,4 +14,7 @@ public interface SysErrorCodeConstants {
ErrorCode SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS = new ErrorCode(1006000001, "模板参数({})缺失"); ErrorCode SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS = new ErrorCode(1006000001, "模板参数({})缺失");
ErrorCode SMS_SEND_TEMPLATE_NOT_EXISTS = new ErrorCode(1006000000, "短信模板不存在"); ErrorCode SMS_SEND_TEMPLATE_NOT_EXISTS = new ErrorCode(1006000000, "短信模板不存在");
// 文件相关
ErrorCode FILE_PATH_EXISTS = new ErrorCode(1006001000, "文件路径已存在");
ErrorCode FILE_NOT_EXISTS = new ErrorCode(1006001002, "文件不存在");
} }

View File

@ -1,3 +1,11 @@
### 请求 /system/user/profile/get 接口 => 没有权限 ### 请求 /system/user/profile/get 接口 => 没有权限
GET {{userServerUrl}}/system/user/profile/get GET {{userServerUrl}}/system/user/profile/get
Authorization: Bearer test245 Authorization: Bearer test245
### 请求 /system/user/profile/revise-nickname 接口 成功
PUT http://localhost:28080/api/system/user/profile/revise-nickname?nickName=yunai111
Authorization: Bearer test245
### 请求 /system/user/profile/get-user-info 接口 成功
GET http://localhost:28080/api/system/user/profile/get-user-info?id=245
Authorization: Bearer test245

View File

@ -1,14 +1,24 @@
package cn.iocoder.yudao.userserver.modules.member.controller.user; package cn.iocoder.yudao.userserver.modules.member.controller.user;
import cn.iocoder.yudao.coreservice.modules.system.controller.user.vo.SysUserCoreProfileRespVo;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.io.IOException;
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.userserver.modules.member.enums.MbrErrorCodeConstants.FILE_IS_EMPTY;
@Api(tags = "用户个人中心") @Api(tags = "用户个人中心")
@RestController @RestController
@ -17,6 +27,9 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j @Slf4j
public class SysUserProfileController { public class SysUserProfileController {
@Resource
private MbrUserService userService;
@GetMapping("/get") @GetMapping("/get")
@ApiOperation("获得登录用户信息") @ApiOperation("获得登录用户信息")
@PreAuthenticated @PreAuthenticated
@ -24,4 +37,27 @@ public class SysUserProfileController {
return null; return null;
} }
@PutMapping("/revise-nickname")
@ApiOperation("修改用户昵称")
public CommonResult<Boolean> reviseNickname(@RequestParam("nickName") String nickName) {
userService.reviseNickname(getLoginUserId(), nickName);
return success(true);
}
@PutMapping("/revise-avatar")
@ApiOperation("修改用户头像")
public CommonResult<String> reviseAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException {
if (file.isEmpty()) {
throw ServiceExceptionUtil.exception(FILE_IS_EMPTY);
}
String avatar = userService.reviseAvatar(getLoginUserId(), file.getInputStream());
return success(avatar);
}
@GetMapping("/get-user-info")
@ApiOperation("获取用户头像与昵称")
public CommonResult<SysUserCoreProfileRespVo> getUserInfo(@RequestParam("id") Long id) {
return success(userService.getUserInfo(id));
}
} }

View File

@ -9,4 +9,9 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
*/ */
public interface MbrErrorCodeConstants { public interface MbrErrorCodeConstants {
// 用户相关
ErrorCode USER_NOT_EXISTS = new ErrorCode(1004000000, "用户不存在");
// 文件相关
ErrorCode FILE_IS_EMPTY = new ErrorCode(1004000000, "用户不存在");
} }

View File

@ -1,8 +1,11 @@
package cn.iocoder.yudao.userserver.modules.member.service.user; package cn.iocoder.yudao.userserver.modules.member.service.user;
import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO;
import cn.iocoder.yudao.coreservice.modules.system.controller.user.vo.SysUserCoreProfileRespVo;
import cn.iocoder.yudao.framework.common.validation.Mobile; import cn.iocoder.yudao.framework.common.validation.Mobile;
import java.io.InputStream;
/** /**
* 前台用户 Service 接口 * 前台用户 Service 接口
* *
@ -44,4 +47,26 @@ public interface MbrUserService {
*/ */
MbrUserDO getUser(Long id); MbrUserDO getUser(Long id);
/**
* 修改用户昵称
* @param loginUserId 登录用户id
* @param nickName 用户新昵称
*/
void reviseNickname(Long loginUserId, String nickName);
/**
* 修改用户头像
* @param loginUserId 登录用户id
* @param inputStream 头像文件
* @return 头像url
*/
String reviseAvatar(Long loginUserId, InputStream inputStream);
/**
* 根据用户id获取用户头像与昵称
* @param loginUserId 登录用户id
* @return 用户响应实体类
*/
SysUserCoreProfileRespVo getUserInfo(Long loginUserId);
} }

View File

@ -1,18 +1,27 @@
package cn.iocoder.yudao.userserver.modules.member.service.user.impl; package cn.iocoder.yudao.userserver.modules.member.service.user.impl;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService;
import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO;
import cn.iocoder.yudao.coreservice.modules.system.controller.user.vo.SysUserCoreProfileRespVo;
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper; import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper;
import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService;
import com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.InputStream;
import java.util.Date; import java.util.Date;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConstants.USER_NOT_EXISTS;
/** /**
* User Service 实现类 * User Service 实现类
* *
@ -26,6 +35,9 @@ public class MbrUserServiceImpl implements MbrUserService {
@Resource @Resource
private MbrUserMapper userMapper; private MbrUserMapper userMapper;
@Resource
private InfFileCoreService fileCoreService;
@Resource @Resource
private PasswordEncoder passwordEncoder; private PasswordEncoder passwordEncoder;
@ -68,4 +80,53 @@ public class MbrUserServiceImpl implements MbrUserService {
return userMapper.selectById(id); return userMapper.selectById(id);
} }
@Override
public void reviseNickname(Long loginUserId, String nickName) {
MbrUserDO mbrUserDO = userMapper.selectById(loginUserId);
// 仅当新昵称不等于旧昵称时进行修改
if (!nickName.equals(mbrUserDO.getNickname())){
MbrUserDO user = new MbrUserDO();
user.setId(mbrUserDO.getId());
user.setNickname(nickName);
userMapper.updateById(user);
}
}
@Override
public String reviseAvatar(Long loginUserId, InputStream avatarFile) {
this.checkUserExists(loginUserId);
// 创建文件
String avatar = fileCoreService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile));
// 更新头像路径
MbrUserDO userDO = new MbrUserDO();
userDO.setId(loginUserId);
userDO.setAvatar(avatar);
userMapper.updateById(userDO);
return avatar;
}
@Override
public SysUserCoreProfileRespVo getUserInfo(Long loginUserId) {
MbrUserDO mbrUserDO = userMapper.selectById(loginUserId);
if (mbrUserDO == null){
log.error("用户不存在:{}",loginUserId);
throw exception(USER_NOT_EXISTS);
}
SysUserCoreProfileRespVo userRes = new SysUserCoreProfileRespVo();
userRes.setNickName(mbrUserDO.getNickname());
userRes.setAvatar(mbrUserDO.getAvatar());
return userRes;
}
@VisibleForTesting
public void checkUserExists(Long id) {
if (id == null) {
return;
}
MbrUserDO user = userMapper.selectById(id);
if (user == null) {
throw exception(USER_NOT_EXISTS);
}
}
} }