Commit c06d6e53f60f1ff0719d3ef80adab4a36adf8981
1 parent
d194e147
[update] 新增修改昵称,修改头像,查询昵称与头像接口
Showing
22 changed files
with
218 additions
and
72 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/InfFileController.java
| ... | ... | @@ -2,12 +2,12 @@ package cn.iocoder.yudao.adminserver.modules.infra.controller.file; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.io.IoUtil; |
| 4 | 4 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; |
| 5 | +import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; | |
| 5 | 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; | |
| 8 | -import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFileRespVO; | |
| 8 | +import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO; | |
| 9 | +import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFileRespVO; | |
| 9 | 10 | import cn.iocoder.yudao.adminserver.modules.infra.convert.file.InfFileConvert; |
| 10 | -import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; | |
| 11 | 11 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| 12 | 12 | import io.swagger.annotations.Api; |
| 13 | 13 | import io.swagger.annotations.ApiImplicitParam; |
| ... | ... | @@ -35,7 +35,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 35 | 35 | public class InfFileController { |
| 36 | 36 | |
| 37 | 37 | @Resource |
| 38 | - private InfFileService fileService; | |
| 38 | + private InfFileCoreService fileService; | |
| 39 | 39 | |
| 40 | 40 | @PostMapping("/upload") |
| 41 | 41 | @ApiOperation("上传文件") | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/file/InfFileConvert.java
| ... | ... | @@ -2,7 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.infra.convert.file; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFileRespVO; | |
| 5 | +import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFileRespVO; | |
| 6 | 6 | import org.mapstruct.Mapper; |
| 7 | 7 | import org.mapstruct.factory.Mappers; |
| 8 | 8 | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/file/InfFileMapper.java deleted
| 1 | -package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | |
| 4 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 6 | -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | |
| 7 | -import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; | |
| 8 | -import org.apache.ibatis.annotations.Mapper; | |
| 9 | - | |
| 10 | -@Mapper | |
| 11 | -public interface InfFileMapper extends BaseMapperX<InfFileDO> { | |
| 12 | - | |
| 13 | - default Integer selectCountById(String id) { | |
| 14 | - return selectCount("id", id); | |
| 15 | - } | |
| 16 | - | |
| 17 | - default PageResult<InfFileDO> selectPage(InfFilePageReqVO reqVO) { | |
| 18 | - return selectPage(reqVO, new QueryWrapperX<InfFileDO>() | |
| 19 | - .likeIfPresent("id", reqVO.getId()) | |
| 20 | - .likeIfPresent("type", reqVO.getType()) | |
| 21 | - .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) | |
| 22 | - .orderByDesc("create_time")); | |
| 23 | - } | |
| 24 | - | |
| 25 | -} |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/enums/InfErrorCodeConstants.java
| ... | ... | @@ -27,7 +27,4 @@ public interface InfErrorCodeConstants { |
| 27 | 27 | ErrorCode API_ERROR_LOG_NOT_FOUND = new ErrorCode(1001002000, "API 错误日志不存在"); |
| 28 | 28 | ErrorCode API_ERROR_LOG_PROCESSED = new ErrorCode(1001002001, "API 错误日志已处理"); |
| 29 | 29 | |
| 30 | - // ========== 文件 1001003000 ========== | |
| 31 | - ErrorCode FILE_NOT_EXISTS = new ErrorCode(1001003000, "文件不存在"); | |
| 32 | - | |
| 33 | 30 | } | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java
| ... | ... | @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.io.IoUtil; |
| 5 | 5 | import cn.hutool.core.util.IdUtil; |
| 6 | 6 | import cn.hutool.core.util.StrUtil; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; | |
| 8 | 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; |
| 9 | 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO; |
| 10 | 9 | 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; |
| 16 | 15 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; |
| 17 | 16 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; |
| 18 | 17 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 18 | +import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; | |
| 19 | 19 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; |
| 20 | 20 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 21 | 21 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| ... | ... | @@ -59,7 +59,7 @@ public class SysUserServiceImpl implements SysUserService { |
| 59 | 59 | @Resource |
| 60 | 60 | private PasswordEncoder passwordEncoder; |
| 61 | 61 | @Resource |
| 62 | - private InfFileService fileService; | |
| 62 | + private InfFileCoreService fileService; | |
| 63 | 63 | |
| 64 | 64 | @Override |
| 65 | 65 | public Long createUser(SysUserCreateReqVO reqVO) { | ... | ... |
yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileServiceTest.java
| ... | ... | @@ -3,11 +3,11 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.file; |
| 3 | 3 | import cn.hutool.core.io.resource.ResourceUtil; |
| 4 | 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 5 | 5 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; |
| 6 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper; | |
| 7 | +import cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl; | |
| 6 | 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.infra.framework.file.config.FileProperties; | |
| 8 | -import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; | |
| 9 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file.InfFileMapper; | |
| 10 | -import cn.iocoder.yudao.adminserver.modules.infra.service.file.impl.InfFileServiceImpl; | |
| 9 | +import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties; | |
| 10 | +import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO; | |
| 11 | 11 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 12 | 12 | import org.junit.jupiter.api.Test; |
| 13 | 13 | import org.springframework.boot.test.mock.mockito.MockBean; |
| ... | ... | @@ -15,8 +15,8 @@ import org.springframework.context.annotation.Import; |
| 15 | 15 | |
| 16 | 16 | import javax.annotation.Resource; |
| 17 | 17 | |
| 18 | +import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.FILE_NOT_EXISTS; | |
| 18 | 19 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 19 | -import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.FILE_NOT_EXISTS; | |
| 20 | 20 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS; |
| 21 | 21 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 22 | 22 | 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 |
| 24 | 24 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; |
| 25 | 25 | import static org.junit.jupiter.api.Assertions.*; |
| 26 | 26 | |
| 27 | -@Import({InfFileServiceImpl.class, FileProperties.class}) | |
| 27 | +@Import({InfFileCoreServiceImpl.class, FileProperties.class}) | |
| 28 | 28 | public class InfFileServiceTest extends BaseDbUnitTest { |
| 29 | 29 | |
| 30 | 30 | @Resource |
| 31 | - private InfFileServiceImpl fileService; | |
| 31 | + private InfFileCoreServiceImpl fileService; | |
| 32 | 32 | |
| 33 | 33 | @MockBean |
| 34 | 34 | private FileProperties fileProperties; |
| 35 | 35 | |
| 36 | 36 | @Resource |
| 37 | - private InfFileMapper fileMapper; | |
| 37 | + private InfFileCoreMapper fileMapper; | |
| 38 | 38 | |
| 39 | 39 | @Test |
| 40 | 40 | public void testCreateFile_success() { | ... | ... |
yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserServiceImplTest.java
| ... | ... | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.adminserver.modules.system.service.user; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.RandomUtil; |
| 5 | 5 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; | |
| 7 | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; |
| 8 | 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO; |
| 9 | 8 | 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; |
| 14 | 13 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; |
| 15 | 14 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; |
| 16 | 15 | import cn.iocoder.yudao.adminserver.modules.system.service.user.impl.SysUserServiceImpl; |
| 16 | +import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; | |
| 17 | 17 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; |
| 18 | 18 | import cn.iocoder.yudao.coreservice.modules.system.enums.common.SysSexEnum; |
| 19 | 19 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| ... | ... | @@ -69,7 +69,7 @@ public class SysUserServiceImplTest extends BaseDbUnitTest { |
| 69 | 69 | @MockBean |
| 70 | 70 | private PasswordEncoder passwordEncoder; |
| 71 | 71 | @MockBean |
| 72 | - private InfFileService fileService; | |
| 72 | + private InfFileCoreService fileService; | |
| 73 | 73 | |
| 74 | 74 | @Test |
| 75 | 75 | public void testCreatUser_success() { | ... | ... |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/file/InfFileCoreMapper.java
| 1 | 1 | package cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 3 | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | 6 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | |
| 5 | 8 | import org.apache.ibatis.annotations.Mapper; |
| 6 | 9 | |
| 7 | 10 | @Mapper |
| 8 | 11 | public interface InfFileCoreMapper extends BaseMapperX<InfFileDO> { |
| 12 | + default Integer selectCountById(String id) { | |
| 13 | + return selectCount("id", id); | |
| 14 | + } | |
| 15 | + | |
| 16 | + default PageResult<InfFileDO> selectPage(InfFilePageReqVO reqVO) { | |
| 17 | + return selectPage(reqVO, new QueryWrapperX<InfFileDO>() | |
| 18 | + .likeIfPresent("id", reqVO.getId()) | |
| 19 | + .likeIfPresent("type", reqVO.getType()) | |
| 20 | + .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) | |
| 21 | + .orderByDesc("create_time")); | |
| 22 | + } | |
| 9 | 23 | |
| 10 | 24 | } | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/vo/InfFilePageReqVO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/file/vo/InfFilePageReqVO.java
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/vo/InfFileRespVO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/file/vo/InfFileRespVO.java
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/framework/file/config/FileConfiguration.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/framework/file/config/FileConfiguration.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.infra.framework.file.config; | |
| 1 | +package cn.iocoder.yudao.coreservice.modules.infra.framework.file.config; | |
| 2 | 2 | |
| 3 | 3 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 4 | 4 | import org.springframework.context.annotation.Configuration; | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/framework/file/config/FileProperties.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/framework/file/config/FileProperties.java
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/framework/file/package-info.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/framework/file/package-info.java
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileService.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/InfFileCoreService.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.infra.service.file; | |
| 1 | +package cn.iocoder.yudao.coreservice.modules.infra.service.file; | |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; |
| 4 | +import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; | |
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | - * 文件 Service 接口 | |
| 9 | - * | |
| 10 | - * @author 芋道源码 | |
| 8 | + * @Class:ruoyi-vue-pro.cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService | |
| 9 | + * @Descript: 文件 core Service 接口 | |
| 10 | + * @Author:宋天 | |
| 11 | + * @Date:2021/10/19 | |
| 11 | 12 | */ |
| 12 | -public interface InfFileService { | |
| 13 | +public interface InfFileCoreService { | |
| 14 | + | |
| 13 | 15 | |
| 14 | 16 | /** |
| 15 | 17 | * 保存文件,并返回文件的访问路径 |
| ... | ... | @@ -42,5 +44,4 @@ public interface InfFileService { |
| 42 | 44 | * @return 文件分页 |
| 43 | 45 | */ |
| 44 | 46 | PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO); |
| 45 | - | |
| 46 | 47 | } | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/impl/InfFileServiceImpl.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/impl/InfFileCoreServiceImpl.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.infra.service.file.impl; | |
| 1 | +package cn.iocoder.yudao.coreservice.modules.infra.service.file.impl; | |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.io.FileTypeUtil; |
| 4 | 4 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; |
| 5 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper; | |
| 6 | +import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO; | |
| 7 | +import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties; | |
| 8 | +import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; | |
| 5 | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.infra.framework.file.config.FileProperties; | |
| 7 | -import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; | |
| 8 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file.InfFileMapper; | |
| 9 | -import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; | |
| 10 | 10 | import org.springframework.stereotype.Service; |
| 11 | 11 | |
| 12 | 12 | import javax.annotation.Resource; |
| 13 | 13 | import java.io.ByteArrayInputStream; |
| 14 | 14 | |
| 15 | +import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.FILE_NOT_EXISTS; | |
| 16 | +import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS; | |
| 15 | 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 16 | -import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.FILE_NOT_EXISTS; | |
| 17 | -import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS; | |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * 文件 Service 实现类 | |
| 21 | - * | |
| 22 | - * @author 芋道源码 | |
| 20 | + * @Class:ruoyi-vue-pro.cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl | |
| 21 | + * @Descript: core service 文件实现类 | |
| 22 | + * @Author:宋天 | |
| 23 | + * @Date:2021/10/19 | |
| 23 | 24 | */ |
| 24 | 25 | @Service |
| 25 | -public class InfFileServiceImpl implements InfFileService { | |
| 26 | +public class InfFileCoreServiceImpl implements InfFileCoreService { | |
| 26 | 27 | |
| 27 | 28 | @Resource |
| 28 | - private InfFileMapper fileMapper; | |
| 29 | + private InfFileCoreMapper fileMapper; | |
| 29 | 30 | |
| 30 | 31 | @Resource |
| 31 | 32 | private FileProperties fileProperties; | ... | ... |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/controller/user/vo/SysUserCoreProfileRespVo.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.controller.user.vo; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | +import lombok.AllArgsConstructor; | |
| 6 | +import lombok.Data; | |
| 7 | +import lombok.NoArgsConstructor; | |
| 8 | + | |
| 9 | +@Data | |
| 10 | +@NoArgsConstructor | |
| 11 | +@AllArgsConstructor | |
| 12 | +@ApiModel("用户个人中心信息 Response VO") | |
| 13 | +public class SysUserCoreProfileRespVo { | |
| 14 | + | |
| 15 | + @ApiModelProperty(value = "用户昵称", required = true, example = "芋艿") | |
| 16 | + private String nickName; | |
| 17 | + | |
| 18 | + @ApiModelProperty(value = "用户头像", required = true, example = "/infra/file/get/35a12e57-4297-4faa-bf7d-7ed2f211c952") | |
| 19 | + private String avatar; | |
| 20 | +} | ... | ... |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/SysErrorCodeConstants.java
| ... | ... | @@ -14,4 +14,7 @@ public interface SysErrorCodeConstants { |
| 14 | 14 | ErrorCode SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS = new ErrorCode(1006000001, "模板参数({})缺失"); |
| 15 | 15 | ErrorCode SMS_SEND_TEMPLATE_NOT_EXISTS = new ErrorCode(1006000000, "短信模板不存在"); |
| 16 | 16 | |
| 17 | + // 文件相关 | |
| 18 | + ErrorCode FILE_PATH_EXISTS = new ErrorCode(1006001000, "文件路径已存在"); | |
| 19 | + ErrorCode FILE_NOT_EXISTS = new ErrorCode(1006001002, "文件不存在"); | |
| 17 | 20 | } | ... | ... |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.http
| 1 | 1 | ### 请求 /system/user/profile/get 接口 => 没有权限 |
| 2 | 2 | GET {{userServerUrl}}/system/user/profile/get |
| 3 | 3 | Authorization: Bearer test245 |
| 4 | + | |
| 5 | +### 请求 /system/user/profile/revise-nickname 接口 成功 | |
| 6 | +PUT http://localhost:28080/api/system/user/profile/revise-nickname?nickName=yunai111 | |
| 7 | +Authorization: Bearer test245 | |
| 8 | + | |
| 9 | +### 请求 /system/user/profile/get-user-info 接口 成功 | |
| 10 | +GET http://localhost:28080/api/system/user/profile/get-user-info?id=245 | |
| 11 | +Authorization: Bearer test245 | |
| 4 | 12 | \ No newline at end of file | ... | ... |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.java
| 1 | 1 | package cn.iocoder.yudao.userserver.modules.member.controller.user; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.controller.user.vo.SysUserCoreProfileRespVo; | |
| 4 | +import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | |
| 3 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 6 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; |
| 7 | +import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; | |
| 5 | 8 | import io.swagger.annotations.Api; |
| 6 | 9 | import io.swagger.annotations.ApiOperation; |
| 7 | 10 | import lombok.extern.slf4j.Slf4j; |
| 8 | 11 | import org.springframework.validation.annotation.Validated; |
| 9 | -import org.springframework.web.bind.annotation.GetMapping; | |
| 10 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 11 | -import org.springframework.web.bind.annotation.RestController; | |
| 12 | +import org.springframework.web.bind.annotation.*; | |
| 13 | +import org.springframework.web.multipart.MultipartFile; | |
| 14 | + | |
| 15 | +import javax.annotation.Resource; | |
| 16 | + | |
| 17 | +import java.io.IOException; | |
| 18 | + | |
| 19 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 20 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 21 | +import static cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConstants.FILE_IS_EMPTY; | |
| 12 | 22 | |
| 13 | 23 | @Api(tags = "用户个人中心") |
| 14 | 24 | @RestController |
| ... | ... | @@ -17,6 +27,9 @@ import org.springframework.web.bind.annotation.RestController; |
| 17 | 27 | @Slf4j |
| 18 | 28 | public class SysUserProfileController { |
| 19 | 29 | |
| 30 | + @Resource | |
| 31 | + private MbrUserService userService; | |
| 32 | + | |
| 20 | 33 | @GetMapping("/get") |
| 21 | 34 | @ApiOperation("获得登录用户信息") |
| 22 | 35 | @PreAuthenticated |
| ... | ... | @@ -24,4 +37,27 @@ public class SysUserProfileController { |
| 24 | 37 | return null; |
| 25 | 38 | } |
| 26 | 39 | |
| 40 | + @PutMapping("/revise-nickname") | |
| 41 | + @ApiOperation("修改用户昵称") | |
| 42 | + public CommonResult<Boolean> reviseNickname(@RequestParam("nickName") String nickName) { | |
| 43 | + userService.reviseNickname(getLoginUserId(), nickName); | |
| 44 | + return success(true); | |
| 45 | + } | |
| 46 | + | |
| 47 | + @PutMapping("/revise-avatar") | |
| 48 | + @ApiOperation("修改用户头像") | |
| 49 | + public CommonResult<String> reviseAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException { | |
| 50 | + if (file.isEmpty()) { | |
| 51 | + throw ServiceExceptionUtil.exception(FILE_IS_EMPTY); | |
| 52 | + } | |
| 53 | + String avatar = userService.reviseAvatar(getLoginUserId(), file.getInputStream()); | |
| 54 | + return success(avatar); | |
| 55 | + } | |
| 56 | + | |
| 57 | + @GetMapping("/get-user-info") | |
| 58 | + @ApiOperation("获取用户头像与昵称") | |
| 59 | + public CommonResult<SysUserCoreProfileRespVo> getUserInfo(@RequestParam("id") Long id) { | |
| 60 | + return success(userService.getUserInfo(id)); | |
| 61 | + } | |
| 27 | 62 | } |
| 63 | + | ... | ... |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/enums/MbrErrorCodeConstants.java
| ... | ... | @@ -9,4 +9,9 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; |
| 9 | 9 | */ |
| 10 | 10 | public interface MbrErrorCodeConstants { |
| 11 | 11 | |
| 12 | + // 用户相关 | |
| 13 | + ErrorCode USER_NOT_EXISTS = new ErrorCode(1004000000, "用户不存在"); | |
| 14 | + | |
| 15 | + // 文件相关 | |
| 16 | + ErrorCode FILE_IS_EMPTY = new ErrorCode(1004000000, "用户不存在"); | |
| 12 | 17 | } | ... | ... |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/MbrUserService.java
| 1 | 1 | package cn.iocoder.yudao.userserver.modules.member.service.user; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; |
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.controller.user.vo.SysUserCoreProfileRespVo; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.validation.Mobile; |
| 5 | 6 | |
| 7 | +import java.io.InputStream; | |
| 8 | + | |
| 6 | 9 | /** |
| 7 | 10 | * 前台用户 Service 接口 |
| 8 | 11 | * |
| ... | ... | @@ -44,4 +47,26 @@ public interface MbrUserService { |
| 44 | 47 | */ |
| 45 | 48 | MbrUserDO getUser(Long id); |
| 46 | 49 | |
| 50 | + /** | |
| 51 | + * 修改用户昵称 | |
| 52 | + * @param loginUserId 登录用户id | |
| 53 | + * @param nickName 用户新昵称 | |
| 54 | + */ | |
| 55 | + void reviseNickname(Long loginUserId, String nickName); | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * 修改用户头像 | |
| 59 | + * @param loginUserId 登录用户id | |
| 60 | + * @param inputStream 头像文件 | |
| 61 | + * @return 头像url | |
| 62 | + */ | |
| 63 | + String reviseAvatar(Long loginUserId, InputStream inputStream); | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * 根据用户id,获取用户头像与昵称 | |
| 67 | + * @param loginUserId 登录用户id | |
| 68 | + * @return 用户响应实体类 | |
| 69 | + */ | |
| 70 | + SysUserCoreProfileRespVo getUserInfo(Long loginUserId); | |
| 71 | + | |
| 47 | 72 | } | ... | ... |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/impl/MbrUserServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.userserver.modules.member.service.user.impl; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.io.IoUtil; | |
| 3 | 4 | import cn.hutool.core.util.IdUtil; |
| 5 | +import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; | |
| 4 | 6 | import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; |
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.controller.user.vo.SysUserCoreProfileRespVo; | |
| 8 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | |
| 5 | 9 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 6 | 10 | import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper; |
| 7 | 11 | import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; |
| 12 | +import com.google.common.annotations.VisibleForTesting; | |
| 8 | 13 | import lombok.extern.slf4j.Slf4j; |
| 9 | 14 | import org.springframework.security.crypto.password.PasswordEncoder; |
| 10 | 15 | import org.springframework.stereotype.Service; |
| 11 | 16 | |
| 12 | 17 | import javax.annotation.Resource; |
| 13 | 18 | import javax.validation.Valid; |
| 19 | +import java.io.InputStream; | |
| 14 | 20 | import java.util.Date; |
| 15 | 21 | |
| 22 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 23 | +import static cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConstants.USER_NOT_EXISTS; | |
| 24 | + | |
| 16 | 25 | /** |
| 17 | 26 | * User Service 实现类 |
| 18 | 27 | * |
| ... | ... | @@ -27,6 +36,9 @@ public class MbrUserServiceImpl implements MbrUserService { |
| 27 | 36 | private MbrUserMapper userMapper; |
| 28 | 37 | |
| 29 | 38 | @Resource |
| 39 | + private InfFileCoreService fileCoreService; | |
| 40 | + | |
| 41 | + @Resource | |
| 30 | 42 | private PasswordEncoder passwordEncoder; |
| 31 | 43 | |
| 32 | 44 | @Override |
| ... | ... | @@ -68,4 +80,53 @@ public class MbrUserServiceImpl implements MbrUserService { |
| 68 | 80 | return userMapper.selectById(id); |
| 69 | 81 | } |
| 70 | 82 | |
| 83 | + @Override | |
| 84 | + public void reviseNickname(Long loginUserId, String nickName) { | |
| 85 | + MbrUserDO mbrUserDO = userMapper.selectById(loginUserId); | |
| 86 | + // 仅当新昵称不等于旧昵称时进行修改 | |
| 87 | + if (!nickName.equals(mbrUserDO.getNickname())){ | |
| 88 | + MbrUserDO user = new MbrUserDO(); | |
| 89 | + user.setId(mbrUserDO.getId()); | |
| 90 | + user.setNickname(nickName); | |
| 91 | + userMapper.updateById(user); | |
| 92 | + } | |
| 93 | + } | |
| 94 | + | |
| 95 | + @Override | |
| 96 | + public String reviseAvatar(Long loginUserId, InputStream avatarFile) { | |
| 97 | + this.checkUserExists(loginUserId); | |
| 98 | + // 创建文件 | |
| 99 | + String avatar = fileCoreService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile)); | |
| 100 | + // 更新头像路径 | |
| 101 | + MbrUserDO userDO = new MbrUserDO(); | |
| 102 | + userDO.setId(loginUserId); | |
| 103 | + userDO.setAvatar(avatar); | |
| 104 | + userMapper.updateById(userDO); | |
| 105 | + return avatar; | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Override | |
| 109 | + public SysUserCoreProfileRespVo getUserInfo(Long loginUserId) { | |
| 110 | + MbrUserDO mbrUserDO = userMapper.selectById(loginUserId); | |
| 111 | + if (mbrUserDO == null){ | |
| 112 | + log.error("用户不存在:{}",loginUserId); | |
| 113 | + throw exception(USER_NOT_EXISTS); | |
| 114 | + } | |
| 115 | + | |
| 116 | + SysUserCoreProfileRespVo userRes = new SysUserCoreProfileRespVo(); | |
| 117 | + userRes.setNickName(mbrUserDO.getNickname()); | |
| 118 | + userRes.setAvatar(mbrUserDO.getAvatar()); | |
| 119 | + return userRes; | |
| 120 | + } | |
| 121 | + | |
| 122 | + @VisibleForTesting | |
| 123 | + public void checkUserExists(Long id) { | |
| 124 | + if (id == null) { | |
| 125 | + return; | |
| 126 | + } | |
| 127 | + MbrUserDO user = userMapper.selectById(id); | |
| 128 | + if (user == null) { | |
| 129 | + throw exception(USER_NOT_EXISTS); | |
| 130 | + } | |
| 131 | + } | |
| 71 | 132 | } | ... | ... |