From d6333fc353441ce22486f5f67f04191bb3ec4d12 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 9 Mar 2022 00:27:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20ProjectReactor=20=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=EF=BC=8C=E5=AE=9E=E7=8E=B0=E4=B8=80=E9=94=AE=E6=94=B9?= =?UTF-8?q?=E5=8C=85=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tenant/core/util/TenantUtils.java | 1 - .../infra/service/file/FileServiceTest.java | 8 +- .../controller/admin/user/UserController.java | 2 +- .../errorcode/ErrorCodeServiceTest.java | 14 ++-- .../service/sms/SmsTemplateServiceTest.java | 8 +- .../service/tenant/TenantServiceImplTest.java | 4 +- .../service/user/UserServiceImplTest.java | 12 +-- .../java/cn/iocoder/yudao/ProjectReactor.java | 81 +++++++++++++++++++ 8 files changed, 105 insertions(+), 25 deletions(-) create mode 100644 yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/util/TenantUtils.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/util/TenantUtils.java index 22758fadd..3ea29b227 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/util/TenantUtils.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/util/TenantUtils.java @@ -32,5 +32,4 @@ public class TenantUtils { } } - } diff --git a/yudao-module-infra/yudao-module-infra-impl/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java b/yudao-module-infra/yudao-module-infra-impl/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java index 8356957e4..259502ca7 100644 --- a/yudao-module-infra/yudao-module-infra-impl/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java +++ b/yudao-module-infra/yudao-module-infra-impl/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java @@ -38,7 +38,7 @@ public class FileServiceTest extends BaseDbUnitTest { public void testGetFilePage() { // mock 数据 FileDO dbFile = randomPojo(FileDO.class, o -> { // 等会查询到 - o.setId("yudao"); + o.setId("yunai"); o.setType("jpg"); o.setCreateTime(buildTime(2021, 1, 15)); }); @@ -47,17 +47,17 @@ public class FileServiceTest extends BaseDbUnitTest { fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> o.setId("tudou"))); // 测试 type 不匹配 fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> { - o.setId("yudao02"); + o.setId("yunai02"); o.setType("png"); })); // 测试 createTime 不匹配 fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> { - o.setId("yudao03"); + o.setId("yunai03"); o.setCreateTime(buildTime(2020, 1, 15)); })); // 准备参数 FilePageReqVO reqVO = new FilePageReqVO(); - reqVO.setId("yudao"); + reqVO.setId("yunai"); reqVO.setType("jp"); reqVO.setBeginCreateTime(buildTime(2021, 1, 10)); reqVO.setEndCreateTime(buildTime(2021, 1, 20)); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java index fbba57730..993b66dea 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java @@ -163,7 +163,7 @@ public class UserController { public void importTemplate(HttpServletResponse response) throws IOException { // 手动创建导出 demo List list = Arrays.asList( - UserImportExcelVO.builder().username("yudao").deptId(1L).email("yudao@iocoder.cn").mobile("15601691300") + UserImportExcelVO.builder().username("yunai").deptId(1L).email("yunai@iocoder.cn").mobile("15601691300") .nickname("芋道").status(CommonStatusEnum.ENABLE.getStatus()).sex(SexEnum.MALE.getSex()).build(), UserImportExcelVO.builder().username("yuanma").deptId(2L).email("yuanma@iocoder.cn").mobile("15601701300") .nickname("源码").status(CommonStatusEnum.DISABLE.getStatus()).sex(SexEnum.FEMALE.getSex()).build() diff --git a/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java b/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java index e16cbf1f2..0026b478b 100644 --- a/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java +++ b/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java @@ -92,9 +92,9 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { // 准备参数 ErrorCodePageReqVO reqVO = new ErrorCodePageReqVO(); reqVO.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); - reqVO.setApplicationName("yudao"); + reqVO.setApplicationName("tu"); reqVO.setCode(1); - reqVO.setMessage("yu"); + reqVO.setMessage("ma"); reqVO.setBeginCreateTime(buildTime(2020, 11, 1)); reqVO.setEndCreateTime(buildTime(2020, 11, 30)); @@ -112,16 +112,16 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { private ErrorCodeDO initGetErrorCodePage() { ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> { // 等会查询到 o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); - o.setApplicationName("yudaoyuanma"); + o.setApplicationName("tudou"); o.setCode(1); - o.setMessage("yudao"); + o.setMessage("yuanma"); o.setCreateTime(buildTime(2020, 11, 11)); }); errorCodeMapper.insert(dbErrorCode); // 测试 type 不匹配 errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()))); // 测试 applicationName 不匹配 - errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setApplicationName("yunai"))); + errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setApplicationName("yuan"))); // 测试 code 不匹配 errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setCode(2))); // 测试 message 不匹配 @@ -138,9 +138,9 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { // 准备参数 ErrorCodeExportReqVO reqVO = new ErrorCodeExportReqVO(); reqVO.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); - reqVO.setApplicationName("yudao"); + reqVO.setApplicationName("tu"); reqVO.setCode(1); - reqVO.setMessage("yu"); + reqVO.setMessage("ma"); reqVO.setBeginCreateTime(buildTime(2020, 11, 1)); reqVO.setEndCreateTime(buildTime(2020, 11, 30)); diff --git a/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceTest.java b/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceTest.java index 034310fa2..a3acac897 100644 --- a/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceTest.java +++ b/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceTest.java @@ -201,7 +201,7 @@ public class SmsTemplateServiceTest extends BaseDbUnitTest { SmsTemplateDO dbSmsTemplate = randomPojo(SmsTemplateDO.class, o -> { // 等会查询到 o.setType(SmsTemplateTypeEnum.PROMOTION.getType()); o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - o.setCode("yudaoyuanma"); + o.setCode("tudou"); o.setContent("芋道源码"); o.setApiTemplateId("yunai"); o.setChannelId(1L); @@ -226,7 +226,7 @@ public class SmsTemplateServiceTest extends BaseDbUnitTest { SmsTemplatePageReqVO reqVO = new SmsTemplatePageReqVO(); reqVO.setType(SmsTemplateTypeEnum.PROMOTION.getType()); reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - reqVO.setCode("yudao"); + reqVO.setCode("tu"); reqVO.setContent("芋道"); reqVO.setApiTemplateId("yu"); reqVO.setChannelId(1L); @@ -247,7 +247,7 @@ public class SmsTemplateServiceTest extends BaseDbUnitTest { SmsTemplateDO dbSmsTemplate = randomPojo(SmsTemplateDO.class, o -> { // 等会查询到 o.setType(SmsTemplateTypeEnum.PROMOTION.getType()); o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - o.setCode("yudaoyuanma"); + o.setCode("tudou"); o.setContent("芋道源码"); o.setApiTemplateId("yunai"); o.setChannelId(1L); @@ -272,7 +272,7 @@ public class SmsTemplateServiceTest extends BaseDbUnitTest { SmsTemplateExportReqVO reqVO = new SmsTemplateExportReqVO(); reqVO.setType(SmsTemplateTypeEnum.PROMOTION.getType()); reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - reqVO.setCode("yudao"); + reqVO.setCode("tu"); reqVO.setContent("芋道"); reqVO.setApiTemplateId("yu"); reqVO.setChannelId(1L); diff --git a/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImplTest.java b/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImplTest.java index cd0a72329..075298e1e 100644 --- a/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImplTest.java @@ -176,7 +176,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { }), eq(RoleTypeEnum.SYSTEM.getType()))).thenReturn(200L); // mock 用户 300L when(userService.createUser(argThat(user -> { - assertEquals("yudao", user.getUsername()); + assertEquals("yunai", user.getUsername()); assertEquals("yuanma", user.getPassword()); assertEquals("芋道", user.getNickname()); assertEquals("15601691300", user.getMobile()); @@ -190,7 +190,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { o.setPackageId(100L); o.setStatus(randomCommonStatus()); o.setDomain("https://www.iocoder.cn"); - o.setUsername("yudao"); + o.setUsername("yunai"); o.setPassword("yuanma"); }); diff --git a/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/user/UserServiceImplTest.java b/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/user/UserServiceImplTest.java index 0ecfbfead..49d18dc06 100644 --- a/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/user/UserServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/user/UserServiceImplTest.java @@ -175,12 +175,12 @@ public class UserServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateUserPassword_success() { // mock 数据 - AdminUserDO dbUser = randomAdminUserDO(o -> o.setPassword("encode:yudao")); + AdminUserDO dbUser = randomAdminUserDO(o -> o.setPassword("encode:tudou")); userMapper.insert(dbUser); // 准备参数 Long userId = dbUser.getId(); UserProfileUpdatePasswordReqVO reqVO = randomPojo(UserProfileUpdatePasswordReqVO.class, o -> { - o.setOldPassword("yudao"); + o.setOldPassword("tudou"); o.setNewPassword("yuanma"); }); // mock 方法 @@ -272,7 +272,7 @@ public class UserServiceImplTest extends BaseDbUnitTest { AdminUserDO dbUser = initGetUserPageData(); // 准备参数 UserPageReqVO reqVO = new UserPageReqVO(); - reqVO.setUsername("yudao"); + reqVO.setUsername("tu"); reqVO.setMobile("1560"); reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); reqVO.setBeginTime(buildTime(2020, 12, 1)); @@ -296,7 +296,7 @@ public class UserServiceImplTest extends BaseDbUnitTest { AdminUserDO dbUser = initGetUserPageData(); // 准备参数 UserExportReqVO reqVO = new UserExportReqVO(); - reqVO.setUsername("yudao"); + reqVO.setUsername("tu"); reqVO.setMobile("1560"); reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); reqVO.setBeginTime(buildTime(2020, 12, 1)); @@ -319,7 +319,7 @@ public class UserServiceImplTest extends BaseDbUnitTest { private AdminUserDO initGetUserPageData() { // mock 数据 AdminUserDO dbUser = randomAdminUserDO(o -> { // 等会查询到 - o.setUsername("yudaoyuanma"); + o.setUsername("tudou"); o.setMobile("15601691300"); o.setStatus(CommonStatusEnum.ENABLE.getStatus()); o.setCreateTime(buildTime(2020, 12, 12)); @@ -327,7 +327,7 @@ public class UserServiceImplTest extends BaseDbUnitTest { }); userMapper.insert(dbUser); // 测试 username 不匹配 - userMapper.insert(ObjectUtils.cloneIgnoreId(dbUser, o -> o.setUsername("yuanma"))); + userMapper.insert(ObjectUtils.cloneIgnoreId(dbUser, o -> o.setUsername("dou"))); // 测试 mobile 不匹配 userMapper.insert(ObjectUtils.cloneIgnoreId(dbUser, o -> o.setMobile("18818260888"))); // 测试 status 不匹配 diff --git a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java new file mode 100644 index 000000000..33857df9c --- /dev/null +++ b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java @@ -0,0 +1,81 @@ +package cn.iocoder.yudao; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.StrUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.Collection; + +/** + * 项目修改器,一键替换 Maven 的 groupId、artifactId,项目的 package 等 + * + * 通过修改 groupIdNew、artifactIdNew、projectBaseDirNew 三个变量 + * + * @author 芋道源码 + */ +@Slf4j +public class ProjectReactor { + + private static final String GROUP_ID = "cn.iocoder.boot"; + private static final String ARTIFACT_ID = "yudao"; + private static final String PACKAGE_NAME = "cn.iocoder.yudao"; + + public static void main(String[] args) { + String projectBaseDir = getProjectBaseDir(); + // ========== 配置,需要你手动修改 ========== + String groupIdNew = "cn.star.gg"; + String artifactIdNew = "star"; + String packageNameNew = "cn.start.pp"; + String projectBaseDirNew = projectBaseDir + "-new"; + // ========== ========== + + // 获得需要复制的文件 + log.info("[main][开始获得需要重写的文件]"); + Collection files = listFiles(projectBaseDir); + log.info("[main][需要重写的文件数量:{},预计需要 5-10 秒]", files.size()); + // 写入文件 + files.forEach(file -> { + String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew); + writeFile(file, content, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew); + }); + log.info("[main][重写完成]"); + } + + private static String getProjectBaseDir() { + // noinspection ConstantConditions + return StrUtil.subBefore(ProjectReactor.class.getClassLoader().getResource("").getFile(), + "/yudao-server", false); + } + + private static Collection listFiles(String projectBaseDir) { + Collection files = FileUtils.listFiles(new File(projectBaseDir), null, true); + files.removeIf(file -> file.getPath().contains("/target/")); + files.removeIf(file -> file.getPath().contains("/node_modules/")); + files.removeIf(file -> file.getPath().contains("/.idea/")); // 移除 IDEA 自身的文件 + files.removeIf(file -> file.getPath().contains("/.git/")); // 移除 Git 自身的文件 + files.removeIf(file -> file.getPath().contains("/dist/")); // 移除 Node 编译出来的 + return files; + } + + private static String replaceFileContent(File file, String groupIdNew, + String artifactIdNew, String packageNameNew) { + return FileUtil.readString(file, StandardCharsets.UTF_8) + .replaceAll(GROUP_ID, groupIdNew) + .replaceAll(PACKAGE_NAME, packageNameNew) + .replaceAll(ARTIFACT_ID, artifactIdNew) // 必须放在最后替换,因为 ARTIFACT_ID 太短! + .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew)); + } + + private static void writeFile(File file, String fileContent, String projectBaseDir, + String projectBaseDirNew, String packageNameNew, String artifactIdNew) { + String newPath = file.getPath().replace(projectBaseDir, projectBaseDirNew) // 新目录 + .replace(PACKAGE_NAME.replaceAll("\\.", "/"), packageNameNew.replaceAll("\\.", "/")) + .replace(ARTIFACT_ID, artifactIdNew) // + .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew)); + FileUtil.writeUtf8String(fileContent, newPath); + } + +}