Commit 79da36ac040910496eeefb9f7720c94238956de6
1 parent
c06d6e53
[update]更新代码规范
Showing
16 changed files
with
158 additions
and
85 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/InfFileController.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.controller.file; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.controller.file; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.io.IoUtil; | 3 | import cn.hutool.core.io.IoUtil; |
| 4 | +import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFilePageReqVO; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFileRespVO; | ||
| 4 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | 7 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; |
| 5 | -import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; | ||
| 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 8 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | -import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO; | ||
| 9 | -import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFileRespVO; | ||
| 10 | import cn.iocoder.yudao.adminserver.modules.infra.convert.file.InfFileConvert; | 10 | import cn.iocoder.yudao.adminserver.modules.infra.convert.file.InfFileConvert; |
| 11 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | 11 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| 12 | import io.swagger.annotations.Api; | 12 | import io.swagger.annotations.Api; |
| @@ -35,7 +35,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | @@ -35,7 +35,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 35 | public class InfFileController { | 35 | public class InfFileController { |
| 36 | 36 | ||
| 37 | @Resource | 37 | @Resource |
| 38 | - private InfFileCoreService fileService; | 38 | + private InfFileService fileService; |
| 39 | 39 | ||
| 40 | @PostMapping("/upload") | 40 | @PostMapping("/upload") |
| 41 | @ApiOperation("上传文件") | 41 | @ApiOperation("上传文件") |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/file/InfFileConvert.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.convert.file; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.convert.file; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFileRespVO; | ||
| 3 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | 4 | 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.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFileRespVO; | ||
| 6 | import org.mapstruct.Mapper; | 6 | import org.mapstruct.Mapper; |
| 7 | import org.mapstruct.factory.Mappers; | 7 | import org.mapstruct.factory.Mappers; |
| 8 | 8 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.adminserver.modules.infra.service.file; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFilePageReqVO; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 文件 Service 接口 | ||
| 9 | + * | ||
| 10 | + * @author 芋道源码 | ||
| 11 | + */ | ||
| 12 | +public interface InfFileService { | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 保存文件,并返回文件的访问路径 | ||
| 16 | + * | ||
| 17 | + * @param path 文件路径 | ||
| 18 | + * @param content 文件内容 | ||
| 19 | + * @return 文件路径 | ||
| 20 | + */ | ||
| 21 | + String createFile(String path, byte[] content); | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 删除文件 | ||
| 25 | + * | ||
| 26 | + * @param id 编号 | ||
| 27 | + */ | ||
| 28 | + void deleteFile(String id); | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 获得文件 | ||
| 32 | + * | ||
| 33 | + * @param path 文件路径 | ||
| 34 | + * @return 文件 | ||
| 35 | + */ | ||
| 36 | + InfFileDO getFile(String path); | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 获得文件分页 | ||
| 40 | + * | ||
| 41 | + * @param pageReqVO 分页查询 | ||
| 42 | + * @return 文件分页 | ||
| 43 | + */ | ||
| 44 | + PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO); | ||
| 45 | + | ||
| 46 | +} |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/impl/InfFileServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.adminserver.modules.infra.service.file.impl; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFilePageReqVO; | ||
| 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.InfFileCoreService; | ||
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 9 | +import org.springframework.stereotype.Service; | ||
| 10 | + | ||
| 11 | +import javax.annotation.Resource; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * 文件 Service 实现类 | ||
| 15 | + * | ||
| 16 | + * @author 芋道源码 | ||
| 17 | + */ | ||
| 18 | +@Service | ||
| 19 | +public class InfFileServiceImpl implements InfFileService { | ||
| 20 | + @Resource | ||
| 21 | + private InfFileCoreMapper fileCoreMapper; | ||
| 22 | + | ||
| 23 | + @Resource | ||
| 24 | + private InfFileCoreService fileCoreService; | ||
| 25 | + | ||
| 26 | + @Override | ||
| 27 | + public String createFile(String path, byte[] content) { | ||
| 28 | + return fileCoreService.createFile(path,content); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + @Override | ||
| 32 | + public void deleteFile(String id) { | ||
| 33 | + fileCoreService.deleteFile(id); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public InfFileDO getFile(String path) { | ||
| 38 | + return fileCoreService.getFile(path); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @Override | ||
| 42 | + public PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO) { | ||
| 43 | + return fileCoreMapper.selectPage(pageReqVO); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | +} |
yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileServiceTest.java
| @@ -2,12 +2,12 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.file; | @@ -2,12 +2,12 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.file; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.io.resource.ResourceUtil; | 3 | import cn.hutool.core.io.resource.ResourceUtil; |
| 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; | 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 5 | +import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFilePageReqVO; | ||
| 5 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | 6 | 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.dal.mysql.file.InfFileCoreMapper; |
| 7 | import cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl; | 8 | import cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl; |
| 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties; | 10 | import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties; |
| 10 | -import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO; | ||
| 11 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | 11 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 12 | import org.junit.jupiter.api.Test; | 12 | import org.junit.jupiter.api.Test; |
| 13 | import org.springframework.boot.test.mock.mockito.MockBean; | 13 | import org.springframework.boot.test.mock.mockito.MockBean; |
| @@ -28,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.*; | @@ -28,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.*; | ||
| 28 | public class InfFileServiceTest extends BaseDbUnitTest { | 28 | public class InfFileServiceTest extends BaseDbUnitTest { |
| 29 | 29 | ||
| 30 | @Resource | 30 | @Resource |
| 31 | - private InfFileCoreServiceImpl fileService; | 31 | + private InfFileService fileService; |
| 32 | 32 | ||
| 33 | @MockBean | 33 | @MockBean |
| 34 | private FileProperties fileProperties; | 34 | private FileProperties fileProperties; |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/file/vo/InfFilePageReqVO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/controller/file/vo/InfFilePageReqVO.java
| 1 | -package cn.iocoder.yudao.coreservice.modules.infra.file.vo; | 1 | +package cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | import io.swagger.annotations.ApiModel; | 4 | import io.swagger.annotations.ApiModel; |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/file/vo/InfFileRespVO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/controller/file/vo/InfFileRespVO.java
| 1 | -package cn.iocoder.yudao.coreservice.modules.infra.file.vo; | 1 | +package cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo; |
| 2 | 2 | ||
| 3 | import io.swagger.annotations.ApiModel; | 3 | import io.swagger.annotations.ApiModel; |
| 4 | import io.swagger.annotations.ApiModelProperty; | 4 | import io.swagger.annotations.ApiModelProperty; |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/file/InfFileCoreMapper.java
| 1 | package cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file; | 1 | package cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO; | 3 | +import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFilePageReqVO; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 6 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | 6 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/InfFileCoreService.java
| 1 | package cn.iocoder.yudao.coreservice.modules.infra.service.file; | 1 | package cn.iocoder.yudao.coreservice.modules.infra.service.file; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | 3 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; |
| 4 | -import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO; | ||
| 5 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 6 | 4 | ||
| 7 | /** | 5 | /** |
| 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 | 6 | + * core service 文件接口 |
| 7 | + * | ||
| 8 | + * @author 宋天 | ||
| 12 | */ | 9 | */ |
| 13 | public interface InfFileCoreService { | 10 | public interface InfFileCoreService { |
| 14 | 11 | ||
| @@ -36,12 +33,4 @@ public interface InfFileCoreService { | @@ -36,12 +33,4 @@ public interface InfFileCoreService { | ||
| 36 | * @return 文件 | 33 | * @return 文件 |
| 37 | */ | 34 | */ |
| 38 | InfFileDO getFile(String path); | 35 | InfFileDO getFile(String path); |
| 39 | - | ||
| 40 | - /** | ||
| 41 | - * 获得文件分页 | ||
| 42 | - * | ||
| 43 | - * @param pageReqVO 分页查询 | ||
| 44 | - * @return 文件分页 | ||
| 45 | - */ | ||
| 46 | - PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO); | ||
| 47 | } | 36 | } |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/impl/InfFileCoreServiceImpl.java
| @@ -3,24 +3,20 @@ package cn.iocoder.yudao.coreservice.modules.infra.service.file.impl; | @@ -3,24 +3,20 @@ package cn.iocoder.yudao.coreservice.modules.infra.service.file.impl; | ||
| 3 | import cn.hutool.core.io.FileTypeUtil; | 3 | import cn.hutool.core.io.FileTypeUtil; |
| 4 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | 4 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; |
| 5 | import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper; | 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; | 6 | import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties; |
| 8 | import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; | 7 | import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; |
| 9 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 10 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
| 11 | 9 | ||
| 12 | import javax.annotation.Resource; | 10 | import javax.annotation.Resource; |
| 13 | import java.io.ByteArrayInputStream; | 11 | import java.io.ByteArrayInputStream; |
| 14 | 12 | ||
| 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; | 13 | +import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.*; |
| 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 14 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 18 | 15 | ||
| 19 | /** | 16 | /** |
| 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 | 17 | + * core service 文件实现类 |
| 18 | + * | ||
| 19 | + * @author 宋天 | ||
| 24 | */ | 20 | */ |
| 25 | @Service | 21 | @Service |
| 26 | public class InfFileCoreServiceImpl implements InfFileCoreService { | 22 | public class InfFileCoreServiceImpl implements InfFileCoreService { |
| @@ -65,9 +61,4 @@ public class InfFileCoreServiceImpl implements InfFileCoreService { | @@ -65,9 +61,4 @@ public class InfFileCoreServiceImpl implements InfFileCoreService { | ||
| 65 | return fileMapper.selectById(path); | 61 | return fileMapper.selectById(path); |
| 66 | } | 62 | } |
| 67 | 63 | ||
| 68 | - @Override | ||
| 69 | - public PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO) { | ||
| 70 | - return fileMapper.selectPage(pageReqVO); | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | } | 64 | } |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.http
| @@ -3,7 +3,7 @@ GET {{userServerUrl}}/system/user/profile/get | @@ -3,7 +3,7 @@ GET {{userServerUrl}}/system/user/profile/get | ||
| 3 | Authorization: Bearer test245 | 3 | Authorization: Bearer test245 |
| 4 | 4 | ||
| 5 | ### 请求 /system/user/profile/revise-nickname 接口 成功 | 5 | ### 请求 /system/user/profile/revise-nickname 接口 成功 |
| 6 | -PUT http://localhost:28080/api/system/user/profile/revise-nickname?nickName=yunai111 | 6 | +PUT http://localhost:28080/api/system/user/profile/update-nickname?nickName=yunai222 |
| 7 | Authorization: Bearer test245 | 7 | Authorization: Bearer test245 |
| 8 | 8 | ||
| 9 | ### 请求 /system/user/profile/get-user-info 接口 成功 | 9 | ### 请求 /system/user/profile/get-user-info 接口 成功 |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.java
| 1 | package cn.iocoder.yudao.userserver.modules.member.controller.user; | 1 | package cn.iocoder.yudao.userserver.modules.member.controller.user; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.coreservice.modules.system.controller.user.vo.SysUserCoreProfileRespVo; | 3 | +import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.SysUserInfoRespVO; |
| 4 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | 4 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; | 6 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; |
| @@ -37,15 +37,17 @@ public class SysUserProfileController { | @@ -37,15 +37,17 @@ public class SysUserProfileController { | ||
| 37 | return null; | 37 | return null; |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | - @PutMapping("/revise-nickname") | 40 | + @PutMapping("/update-nickname") |
| 41 | @ApiOperation("修改用户昵称") | 41 | @ApiOperation("修改用户昵称") |
| 42 | - public CommonResult<Boolean> reviseNickname(@RequestParam("nickName") String nickName) { | ||
| 43 | - userService.reviseNickname(getLoginUserId(), nickName); | 42 | + @PreAuthenticated |
| 43 | + public CommonResult<Boolean> updateNickname(@RequestParam("nickName") String nickName) { | ||
| 44 | + userService.updateNickname(getLoginUserId(), nickName); | ||
| 44 | return success(true); | 45 | return success(true); |
| 45 | } | 46 | } |
| 46 | 47 | ||
| 47 | @PutMapping("/revise-avatar") | 48 | @PutMapping("/revise-avatar") |
| 48 | @ApiOperation("修改用户头像") | 49 | @ApiOperation("修改用户头像") |
| 50 | + @PreAuthenticated | ||
| 49 | public CommonResult<String> reviseAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException { | 51 | public CommonResult<String> reviseAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException { |
| 50 | if (file.isEmpty()) { | 52 | if (file.isEmpty()) { |
| 51 | throw ServiceExceptionUtil.exception(FILE_IS_EMPTY); | 53 | throw ServiceExceptionUtil.exception(FILE_IS_EMPTY); |
| @@ -56,8 +58,9 @@ public class SysUserProfileController { | @@ -56,8 +58,9 @@ public class SysUserProfileController { | ||
| 56 | 58 | ||
| 57 | @GetMapping("/get-user-info") | 59 | @GetMapping("/get-user-info") |
| 58 | @ApiOperation("获取用户头像与昵称") | 60 | @ApiOperation("获取用户头像与昵称") |
| 59 | - public CommonResult<SysUserCoreProfileRespVo> getUserInfo(@RequestParam("id") Long id) { | ||
| 60 | - return success(userService.getUserInfo(id)); | 61 | + @PreAuthenticated |
| 62 | + public CommonResult<SysUserInfoRespVO> getUserInfo() { | ||
| 63 | + return success(userService.getUserInfo(getLoginUserId())); | ||
| 61 | } | 64 | } |
| 62 | } | 65 | } |
| 63 | 66 |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/controller/user/vo/SysUserCoreProfileRespVo.java renamed to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/vo/SysUserInfoRespVO.java
| 1 | -package cn.iocoder.yudao.coreservice.modules.system.controller.user.vo; | 1 | +package cn.iocoder.yudao.userserver.modules.member.controller.user.vo; |
| 2 | 2 | ||
| 3 | import io.swagger.annotations.ApiModel; | 3 | import io.swagger.annotations.ApiModel; |
| 4 | import io.swagger.annotations.ApiModelProperty; | 4 | import io.swagger.annotations.ApiModelProperty; |
| @@ -6,11 +6,11 @@ import lombok.AllArgsConstructor; | @@ -6,11 +6,11 @@ import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Data; | 6 | import lombok.Data; |
| 7 | import lombok.NoArgsConstructor; | 7 | import lombok.NoArgsConstructor; |
| 8 | 8 | ||
| 9 | +@ApiModel("用户个人信息 Response VO") | ||
| 9 | @Data | 10 | @Data |
| 10 | @NoArgsConstructor | 11 | @NoArgsConstructor |
| 11 | @AllArgsConstructor | 12 | @AllArgsConstructor |
| 12 | -@ApiModel("用户个人中心信息 Response VO") | ||
| 13 | -public class SysUserCoreProfileRespVo { | 13 | +public class SysUserInfoRespVO { |
| 14 | 14 | ||
| 15 | @ApiModelProperty(value = "用户昵称", required = true, example = "芋艿") | 15 | @ApiModelProperty(value = "用户昵称", required = true, example = "芋艿") |
| 16 | private String nickName; | 16 | private String nickName; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/enums/MbrErrorCodeConstants.java
| @@ -9,9 +9,9 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; | @@ -9,9 +9,9 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; | ||
| 9 | */ | 9 | */ |
| 10 | public interface MbrErrorCodeConstants { | 10 | public interface MbrErrorCodeConstants { |
| 11 | 11 | ||
| 12 | - // 用户相关 | ||
| 13 | - ErrorCode USER_NOT_EXISTS = new ErrorCode(1004000000, "用户不存在"); | 12 | + // ==========用户相关============ |
| 13 | + ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在"); | ||
| 14 | 14 | ||
| 15 | - // 文件相关 | ||
| 16 | - ErrorCode FILE_IS_EMPTY = new ErrorCode(1004000000, "用户不存在"); | 15 | + // ==========文件相关 =========== |
| 16 | + ErrorCode FILE_IS_EMPTY = new ErrorCode(1004002000, "文件不存在"); | ||
| 17 | } | 17 | } |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/MbrUserService.java
| 1 | package cn.iocoder.yudao.userserver.modules.member.service.user; | 1 | package cn.iocoder.yudao.userserver.modules.member.service.user; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | 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 | +import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.SysUserInfoRespVO; |
| 5 | import cn.iocoder.yudao.framework.common.validation.Mobile; | 5 | import cn.iocoder.yudao.framework.common.validation.Mobile; |
| 6 | 6 | ||
| 7 | import java.io.InputStream; | 7 | import java.io.InputStream; |
| @@ -49,24 +49,24 @@ public interface MbrUserService { | @@ -49,24 +49,24 @@ public interface MbrUserService { | ||
| 49 | 49 | ||
| 50 | /** | 50 | /** |
| 51 | * 修改用户昵称 | 51 | * 修改用户昵称 |
| 52 | - * @param loginUserId 登录用户id | 52 | + * @param userId 用户id |
| 53 | * @param nickName 用户新昵称 | 53 | * @param nickName 用户新昵称 |
| 54 | */ | 54 | */ |
| 55 | - void reviseNickname(Long loginUserId, String nickName); | 55 | + void updateNickname(Long userId, String nickName); |
| 56 | 56 | ||
| 57 | /** | 57 | /** |
| 58 | * 修改用户头像 | 58 | * 修改用户头像 |
| 59 | - * @param loginUserId 登录用户id | 59 | + * @param userId 用户id |
| 60 | * @param inputStream 头像文件 | 60 | * @param inputStream 头像文件 |
| 61 | * @return 头像url | 61 | * @return 头像url |
| 62 | */ | 62 | */ |
| 63 | - String reviseAvatar(Long loginUserId, InputStream inputStream); | 63 | + String reviseAvatar(Long userId, InputStream inputStream); |
| 64 | 64 | ||
| 65 | /** | 65 | /** |
| 66 | * 根据用户id,获取用户头像与昵称 | 66 | * 根据用户id,获取用户头像与昵称 |
| 67 | - * @param loginUserId 登录用户id | 67 | + * @param userId 用户id |
| 68 | * @return 用户响应实体类 | 68 | * @return 用户响应实体类 |
| 69 | */ | 69 | */ |
| 70 | - SysUserCoreProfileRespVo getUserInfo(Long loginUserId); | 70 | + SysUserInfoRespVO getUserInfo(Long userId); |
| 71 | 71 | ||
| 72 | } | 72 | } |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/impl/MbrUserServiceImpl.java
| @@ -4,8 +4,7 @@ import cn.hutool.core.io.IoUtil; | @@ -4,8 +4,7 @@ import cn.hutool.core.io.IoUtil; | ||
| 4 | import cn.hutool.core.util.IdUtil; | 4 | import cn.hutool.core.util.IdUtil; |
| 5 | import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; | 5 | import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; |
| 6 | import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | 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; | 7 | +import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.SysUserInfoRespVO; |
| 9 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 8 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 10 | import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper; | 9 | import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper; |
| 11 | import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; | 10 | import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; |
| @@ -81,52 +80,51 @@ public class MbrUserServiceImpl implements MbrUserService { | @@ -81,52 +80,51 @@ public class MbrUserServiceImpl implements MbrUserService { | ||
| 81 | } | 80 | } |
| 82 | 81 | ||
| 83 | @Override | 82 | @Override |
| 84 | - public void reviseNickname(Long loginUserId, String nickName) { | ||
| 85 | - MbrUserDO mbrUserDO = userMapper.selectById(loginUserId); | 83 | + public void updateNickname(Long userId, String nickName) { |
| 84 | + MbrUserDO user = this.checkUserExists(userId); | ||
| 86 | // 仅当新昵称不等于旧昵称时进行修改 | 85 | // 仅当新昵称不等于旧昵称时进行修改 |
| 87 | - if (!nickName.equals(mbrUserDO.getNickname())){ | ||
| 88 | - MbrUserDO user = new MbrUserDO(); | ||
| 89 | - user.setId(mbrUserDO.getId()); | ||
| 90 | - user.setNickname(nickName); | ||
| 91 | - userMapper.updateById(user); | 86 | + if (nickName.equals(user.getNickname())){ |
| 87 | + return; | ||
| 92 | } | 88 | } |
| 89 | + MbrUserDO userDO = new MbrUserDO(); | ||
| 90 | + userDO.setId(user.getId()); | ||
| 91 | + userDO.setNickname(nickName); | ||
| 92 | + userMapper.updateById(userDO); | ||
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | @Override | 95 | @Override |
| 96 | - public String reviseAvatar(Long loginUserId, InputStream avatarFile) { | ||
| 97 | - this.checkUserExists(loginUserId); | 96 | + public String reviseAvatar(Long userId, InputStream avatarFile) { |
| 97 | + this.checkUserExists(userId); | ||
| 98 | // 创建文件 | 98 | // 创建文件 |
| 99 | String avatar = fileCoreService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile)); | 99 | String avatar = fileCoreService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile)); |
| 100 | // 更新头像路径 | 100 | // 更新头像路径 |
| 101 | - MbrUserDO userDO = new MbrUserDO(); | ||
| 102 | - userDO.setId(loginUserId); | ||
| 103 | - userDO.setAvatar(avatar); | 101 | + MbrUserDO userDO = MbrUserDO.builder() |
| 102 | + .id(userId) | ||
| 103 | + .avatar(avatar) | ||
| 104 | + .build(); | ||
| 104 | userMapper.updateById(userDO); | 105 | userMapper.updateById(userDO); |
| 105 | return avatar; | 106 | return avatar; |
| 106 | } | 107 | } |
| 107 | 108 | ||
| 108 | @Override | 109 | @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; | 110 | + public SysUserInfoRespVO getUserInfo(Long userId) { |
| 111 | + MbrUserDO user = this.checkUserExists(userId); | ||
| 112 | + SysUserInfoRespVO userResp = new SysUserInfoRespVO(); | ||
| 113 | + userResp.setNickName(user.getNickname()); | ||
| 114 | + userResp.setAvatar(user.getAvatar()); | ||
| 115 | + return userResp; | ||
| 120 | } | 116 | } |
| 121 | 117 | ||
| 122 | @VisibleForTesting | 118 | @VisibleForTesting |
| 123 | - public void checkUserExists(Long id) { | 119 | + public MbrUserDO checkUserExists(Long id) { |
| 124 | if (id == null) { | 120 | if (id == null) { |
| 125 | - return; | 121 | + return null; |
| 126 | } | 122 | } |
| 127 | MbrUserDO user = userMapper.selectById(id); | 123 | MbrUserDO user = userMapper.selectById(id); |
| 128 | if (user == null) { | 124 | if (user == null) { |
| 129 | throw exception(USER_NOT_EXISTS); | 125 | throw exception(USER_NOT_EXISTS); |
| 126 | + }else{ | ||
| 127 | + return user; | ||
| 130 | } | 128 | } |
| 131 | } | 129 | } |
| 132 | } | 130 | } |