From c06d6e53f60f1ff0719d3ef80adab4a36adf8981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E5=A4=A9?= <2982176321@qq.com> Date: Tue, 19 Oct 2021 22:16:42 +0800 Subject: [PATCH] =?UTF-8?q?[update]=20=E6=96=B0=E5=A2=9E=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=98=B5=E7=A7=B0=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=EF=BC=8C=E6=9F=A5=E8=AF=A2=E6=98=B5=E7=A7=B0=E4=B8=8E=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/file/InfFileController.java | 8 +-- .../infra/convert/file/InfFileConvert.java | 2 +- .../infra/dal/mysql/file/InfFileMapper.java | 25 -------- .../infra/enums/InfErrorCodeConstants.java | 3 - .../service/user/impl/SysUserServiceImpl.java | 4 +- .../service/file/InfFileServiceTest.java | 16 ++--- .../service/user/SysUserServiceImplTest.java | 4 +- .../dal/mysql/file/InfFileCoreMapper.java | 14 +++++ .../infra}/file/vo/InfFilePageReqVO.java | 2 +- .../modules/infra}/file/vo/InfFileRespVO.java | 2 +- .../file/config/FileConfiguration.java | 2 +- .../framework/file/config/FileProperties.java | 2 +- .../infra/framework/file/package-info.java | 2 +- .../service/file/InfFileCoreService.java | 15 ++--- .../file/impl/InfFileCoreServiceImpl.java | 25 ++++---- .../user/vo/SysUserCoreProfileRespVo.java | 20 ++++++ .../system/enums/SysErrorCodeConstants.java | 3 + .../user/SysUserProfileController.http | 8 +++ .../user/SysUserProfileController.java | 42 ++++++++++++- .../member/enums/MbrErrorCodeConstants.java | 5 ++ .../member/service/user/MbrUserService.java | 25 ++++++++ .../service/user/impl/MbrUserServiceImpl.java | 61 +++++++++++++++++++ 22 files changed, 218 insertions(+), 72 deletions(-) delete mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/file/InfFileMapper.java rename {yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller => yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra}/file/vo/InfFilePageReqVO.java (94%) rename {yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller => yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra}/file/vo/InfFileRespVO.java (88%) rename {yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver => yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice}/modules/infra/framework/file/config/FileConfiguration.java (81%) rename {yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver => yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice}/modules/infra/framework/file/config/FileProperties.java (88%) rename {yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver => yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice}/modules/infra/framework/file/package-info.java (92%) rename yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileService.java => yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/InfFileCoreService.java (69%) rename yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/impl/InfFileServiceImpl.java => yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/impl/InfFileCoreServiceImpl.java (66%) create mode 100644 yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/controller/user/vo/SysUserCoreProfileRespVo.java diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/InfFileController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/InfFileController.java index 6b2c743ca..2fcbbd00f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/InfFileController.java +++ b/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; import cn.hutool.core.io.IoUtil; 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.PageResult; -import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFileRespVO; +import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO; +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.service.file.InfFileService; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -35,7 +35,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; public class InfFileController { @Resource - private InfFileService fileService; + private InfFileCoreService fileService; @PostMapping("/upload") @ApiOperation("上传文件") diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/file/InfFileConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/file/InfFileConvert.java index d39452ffe..78b665292 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/file/InfFileConvert.java +++ b/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; import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; 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.factory.Mappers; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/file/InfFileMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/file/InfFileMapper.java deleted file mode 100644 index 022f90acb..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/file/InfFileMapper.java +++ /dev/null @@ -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 { - - default Integer selectCountById(String id) { - return selectCount("id", id); - } - - default PageResult selectPage(InfFilePageReqVO reqVO) { - return selectPage(reqVO, new QueryWrapperX() - .likeIfPresent("id", reqVO.getId()) - .likeIfPresent("type", reqVO.getType()) - .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) - .orderByDesc("create_time")); - } - -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/enums/InfErrorCodeConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/enums/InfErrorCodeConstants.java index b53ff8c1d..98155e723 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/enums/InfErrorCodeConstants.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/enums/InfErrorCodeConstants.java @@ -27,7 +27,4 @@ public interface InfErrorCodeConstants { ErrorCode API_ERROR_LOG_NOT_FOUND = new ErrorCode(1001002000, "API 错误日志不存在"); ErrorCode API_ERROR_LOG_PROCESSED = new ErrorCode(1001002001, "API 错误日志已处理"); - // ========== 文件 1001003000 ========== - ErrorCode FILE_NOT_EXISTS = new ErrorCode(1001003000, "文件不存在"); - } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java index af7705b63..8901ca022 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java +++ b/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; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.IdUtil; 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.SysUserProfileUpdateReqVO; 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.permission.SysPermissionService; 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.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.exception.ServiceException; @@ -59,7 +59,7 @@ public class SysUserServiceImpl implements SysUserService { @Resource private PasswordEncoder passwordEncoder; @Resource - private InfFileService fileService; + private InfFileCoreService fileService; @Override public Long createUser(SysUserCreateReqVO reqVO) { diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileServiceTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileServiceTest.java index 4849d49cd..7c9cafce3 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileServiceTest.java +++ b/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; import cn.hutool.core.io.resource.ResourceUtil; 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.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.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.impl.InfFileServiceImpl; +import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties; +import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; @@ -15,8 +15,8 @@ import org.springframework.context.annotation.Import; 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.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.framework.test.core.util.AssertUtils.assertServiceException; 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 org.junit.jupiter.api.Assertions.*; -@Import({InfFileServiceImpl.class, FileProperties.class}) +@Import({InfFileCoreServiceImpl.class, FileProperties.class}) public class InfFileServiceTest extends BaseDbUnitTest { @Resource - private InfFileServiceImpl fileService; + private InfFileCoreServiceImpl fileService; @MockBean private FileProperties fileProperties; @Resource - private InfFileMapper fileMapper; + private InfFileCoreMapper fileMapper; @Test public void testCreateFile_success() { diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserServiceImplTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserServiceImplTest.java index e20e72793..70751eeac 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserServiceImplTest.java +++ b/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; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.RandomUtil; 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.SysUserProfileUpdateReqVO; 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.permission.SysPermissionService; 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.enums.common.SysSexEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; @@ -69,7 +69,7 @@ public class SysUserServiceImplTest extends BaseDbUnitTest { @MockBean private PasswordEncoder passwordEncoder; @MockBean - private InfFileService fileService; + private InfFileCoreService fileService; @Test public void testCreatUser_success() { diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/file/InfFileCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/file/InfFileCoreMapper.java index 180dc2d79..43703c5da 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/file/InfFileCoreMapper.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/file/InfFileCoreMapper.java @@ -1,10 +1,24 @@ 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.coreservice.modules.infra.dal.dataobject.file.InfFileDO; +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import org.apache.ibatis.annotations.Mapper; @Mapper public interface InfFileCoreMapper extends BaseMapperX { + default Integer selectCountById(String id) { + return selectCount("id", id); + } + + default PageResult selectPage(InfFilePageReqVO reqVO) { + return selectPage(reqVO, new QueryWrapperX() + .likeIfPresent("id", reqVO.getId()) + .likeIfPresent("type", reqVO.getType()) + .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc("create_time")); + } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/vo/InfFilePageReqVO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/file/vo/InfFilePageReqVO.java similarity index 94% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/vo/InfFilePageReqVO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/file/vo/InfFilePageReqVO.java index 152466a19..a6124f7ea 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/vo/InfFilePageReqVO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/file/vo/InfFilePageReqVO.java @@ -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 io.swagger.annotations.ApiModel; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/vo/InfFileRespVO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/file/vo/InfFileRespVO.java similarity index 88% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/vo/InfFileRespVO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/file/vo/InfFileRespVO.java index 2388d7f3d..57dd5b197 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/vo/InfFileRespVO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/file/vo/InfFileRespVO.java @@ -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.ApiModelProperty; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/framework/file/config/FileConfiguration.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/framework/file/config/FileConfiguration.java similarity index 81% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/framework/file/config/FileConfiguration.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/framework/file/config/FileConfiguration.java index e71377e3f..a10c7a7af 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/framework/file/config/FileConfiguration.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/framework/file/config/FileConfiguration.java @@ -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.context.annotation.Configuration; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/framework/file/config/FileProperties.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/framework/file/config/FileProperties.java similarity index 88% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/framework/file/config/FileProperties.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/framework/file/config/FileProperties.java index db1a6b71f..0d8ed7cda 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/framework/file/config/FileProperties.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/framework/file/config/FileProperties.java @@ -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 org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/framework/file/package-info.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/framework/file/package-info.java similarity index 92% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/framework/file/package-info.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/framework/file/package-info.java index a69b53eb5..2c2798ee6 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/framework/file/package-info.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/framework/file/package-info.java @@ -13,4 +13,4 @@ * 综合考虑,暂时使用方案 3 的方式,比较适合这样一个 all in one 的项目。 * 随着文件的量级大了之后,还是推荐采用云服务。 */ -package cn.iocoder.yudao.adminserver.modules.infra.framework.file; +package cn.iocoder.yudao.coreservice.modules.infra.framework.file; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileService.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/InfFileCoreService.java similarity index 69% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileService.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/InfFileCoreService.java index e19e3ecab..f6f251abe 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileService.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/InfFileCoreService.java @@ -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.file.vo.InfFilePageReqVO; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; /** - * 文件 Service 接口 - * - * @author 芋道源码 + * @Class:ruoyi-vue-pro.cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService + * @Descript: 文件 core Service 接口 + * @Author:宋天 + * @Date:2021/10/19 */ -public interface InfFileService { +public interface InfFileCoreService { + /** * 保存文件,并返回文件的访问路径 @@ -42,5 +44,4 @@ public interface InfFileService { * @return 文件分页 */ PageResult getFilePage(InfFilePageReqVO pageReqVO); - } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/impl/InfFileServiceImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/impl/InfFileCoreServiceImpl.java similarity index 66% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/impl/InfFileServiceImpl.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/impl/InfFileCoreServiceImpl.java index 0436b804f..850701ffa 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/impl/InfFileServiceImpl.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/impl/InfFileCoreServiceImpl.java @@ -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.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.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 javax.annotation.Resource; 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.adminserver.modules.infra.enums.InfErrorCodeConstants.FILE_NOT_EXISTS; -import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS; /** - * 文件 Service 实现类 - * - * @author 芋道源码 + * @Class:ruoyi-vue-pro.cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl + * @Descript: core service 文件实现类 + * @Author:宋天 + * @Date:2021/10/19 */ @Service -public class InfFileServiceImpl implements InfFileService { +public class InfFileCoreServiceImpl implements InfFileCoreService { @Resource - private InfFileMapper fileMapper; + private InfFileCoreMapper fileMapper; @Resource private FileProperties fileProperties; diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/controller/user/vo/SysUserCoreProfileRespVo.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/controller/user/vo/SysUserCoreProfileRespVo.java new file mode 100644 index 000000000..50c9a6856 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/controller/user/vo/SysUserCoreProfileRespVo.java @@ -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; +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/SysErrorCodeConstants.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/SysErrorCodeConstants.java index 3c1fc87ef..60249398c 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/SysErrorCodeConstants.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/SysErrorCodeConstants.java @@ -14,4 +14,7 @@ public interface SysErrorCodeConstants { ErrorCode SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS = new ErrorCode(1006000001, "模板参数({})缺失"); ErrorCode SMS_SEND_TEMPLATE_NOT_EXISTS = new ErrorCode(1006000000, "短信模板不存在"); + // 文件相关 + ErrorCode FILE_PATH_EXISTS = new ErrorCode(1006001000, "文件路径已存在"); + ErrorCode FILE_NOT_EXISTS = new ErrorCode(1006001002, "文件不存在"); } diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.http b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.http index 72cf861b8..eb3d8fea6 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.http +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.http @@ -1,3 +1,11 @@ ### 请求 /system/user/profile/get 接口 => 没有权限 GET {{userServerUrl}}/system/user/profile/get 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 \ No newline at end of file diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.java index 4b66b4e18..a1e0f5a25 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.java @@ -1,14 +1,24 @@ 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.security.core.annotations.PreAuthenticated; +import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +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 = "用户个人中心") @RestController @@ -17,6 +27,9 @@ import org.springframework.web.bind.annotation.RestController; @Slf4j public class SysUserProfileController { + @Resource + private MbrUserService userService; + @GetMapping("/get") @ApiOperation("获得登录用户信息") @PreAuthenticated @@ -24,4 +37,27 @@ public class SysUserProfileController { return null; } + @PutMapping("/revise-nickname") + @ApiOperation("修改用户昵称") + public CommonResult reviseNickname(@RequestParam("nickName") String nickName) { + userService.reviseNickname(getLoginUserId(), nickName); + return success(true); + } + + @PutMapping("/revise-avatar") + @ApiOperation("修改用户头像") + public CommonResult 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 getUserInfo(@RequestParam("id") Long id) { + return success(userService.getUserInfo(id)); + } } + diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/enums/MbrErrorCodeConstants.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/enums/MbrErrorCodeConstants.java index 265d1d485..5d8507d7f 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/enums/MbrErrorCodeConstants.java +++ b/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; */ public interface MbrErrorCodeConstants { + // 用户相关 + ErrorCode USER_NOT_EXISTS = new ErrorCode(1004000000, "用户不存在"); + + // 文件相关 + ErrorCode FILE_IS_EMPTY = new ErrorCode(1004000000, "用户不存在"); } diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/MbrUserService.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/MbrUserService.java index 2d5466865..bb81d3718 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/MbrUserService.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/MbrUserService.java @@ -1,8 +1,11 @@ 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.system.controller.user.vo.SysUserCoreProfileRespVo; import cn.iocoder.yudao.framework.common.validation.Mobile; +import java.io.InputStream; + /** * 前台用户 Service 接口 * @@ -44,4 +47,26 @@ public interface MbrUserService { */ 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); + } diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/impl/MbrUserServiceImpl.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/impl/MbrUserServiceImpl.java index 71fb9dd88..f10c03ed1 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/impl/MbrUserServiceImpl.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/impl/MbrUserServiceImpl.java @@ -1,18 +1,27 @@ package cn.iocoder.yudao.userserver.modules.member.service.user.impl; +import cn.hutool.core.io.IoUtil; 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.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.userserver.modules.member.dal.mysql.user.MbrUserMapper; import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; +import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.validation.Valid; +import java.io.InputStream; 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 实现类 * @@ -26,6 +35,9 @@ public class MbrUserServiceImpl implements MbrUserService { @Resource private MbrUserMapper userMapper; + @Resource + private InfFileCoreService fileCoreService; + @Resource private PasswordEncoder passwordEncoder; @@ -68,4 +80,53 @@ public class MbrUserServiceImpl implements MbrUserService { 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); + } + } }