From dd2f5ba2c301bcc0ea4404c0ee2b147808e72b0c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 24 Oct 2023 18:48:02 +0800 Subject: [PATCH] 统一 boot 和 cloud 代码 --- pom.xml | 12 ++++++------ yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeAutoConfiguration.java | 39 +++++++++++++++++++++++++++++++++++++++ yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeConfiguration.java | 39 --------------------------------------- yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports | 2 +- yudao-framework/yudao-spring-boot-starter-biz-tenant/src/test/java/cn/iocoder/yudao/framework/tenant/core/job/TestJob.java | 28 ---------------------------- yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java | 2 -- yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImplTest.java | 98 -------------------------------------------------------------------------------------------------- yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/MemberAddressServiceImplTest.java | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java | 1 - yudao-server/pom.xml | 90 +++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------- 10 files changed, 189 insertions(+), 220 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeAutoConfiguration.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeConfiguration.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-tenant/src/test/java/cn/iocoder/yudao/framework/tenant/core/job/TestJob.java delete mode 100644 yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImplTest.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/MemberAddressServiceImplTest.java diff --git a/pom.xml b/pom.xml index d308fa9..49ccb7b 100644 --- a/pom.xml +++ b/pom.xml @@ -15,12 +15,12 @@ yudao-module-system yudao-module-infra - - - - - - + yudao-module-member + yudao-module-bpm + yudao-module-report + yudao-module-mp + yudao-module-pay + yudao-module-mall diff --git a/yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeAutoConfiguration.java new file mode 100644 index 0000000..ed2c92f --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeAutoConfiguration.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.framework.errorcode.config; + +import cn.iocoder.yudao.framework.errorcode.core.generator.ErrorCodeAutoGenerator; +import cn.iocoder.yudao.framework.errorcode.core.generator.ErrorCodeAutoGeneratorImpl; +import cn.iocoder.yudao.framework.errorcode.core.loader.ErrorCodeLoader; +import cn.iocoder.yudao.framework.errorcode.core.loader.ErrorCodeLoaderImpl; +import cn.iocoder.yudao.module.system.api.errorcode.ErrorCodeApi; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.scheduling.annotation.EnableScheduling; + +/** + * 错误码配置类 + * + * @author 芋道源码 + */ +@AutoConfiguration +@ConditionalOnProperty(prefix = "yudao.error-code", value = "enable", matchIfMissing = true) // 允许使用 yudao.error-code.enable=false 禁用访问日志 +@EnableConfigurationProperties(ErrorCodeProperties.class) +@EnableScheduling // 开启调度任务的功能,因为 ErrorCodeRemoteLoader 通过定时刷新错误码 +public class YudaoErrorCodeAutoConfiguration { + + @Bean + public ErrorCodeAutoGenerator errorCodeAutoGenerator(@Value("${spring.application.name}") String applicationName, + ErrorCodeProperties errorCodeProperties, + ErrorCodeApi errorCodeApi) { + return new ErrorCodeAutoGeneratorImpl(applicationName, errorCodeProperties.getConstantsClassList(), errorCodeApi); + } + + @Bean + public ErrorCodeLoader errorCodeLoader(@Value("${spring.application.name}") String applicationName, + ErrorCodeApi errorCodeApi) { + return new ErrorCodeLoaderImpl(applicationName, errorCodeApi); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeConfiguration.java deleted file mode 100644 index 74c21f1..0000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeConfiguration.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.framework.errorcode.config; - -import cn.iocoder.yudao.framework.errorcode.core.generator.ErrorCodeAutoGenerator; -import cn.iocoder.yudao.framework.errorcode.core.generator.ErrorCodeAutoGeneratorImpl; -import cn.iocoder.yudao.framework.errorcode.core.loader.ErrorCodeLoader; -import cn.iocoder.yudao.framework.errorcode.core.loader.ErrorCodeLoaderImpl; -import cn.iocoder.yudao.module.system.api.errorcode.ErrorCodeApi; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.scheduling.annotation.EnableScheduling; - -/** - * 错误码配置类 - * - * @author 芋道源码 - */ -@AutoConfiguration -@ConditionalOnProperty(prefix = "yudao.error-code", value = "enable", matchIfMissing = true) // 允许使用 yudao.error-code.enable=false 禁用访问日志 -@EnableConfigurationProperties(ErrorCodeProperties.class) -@EnableScheduling // 开启调度任务的功能,因为 ErrorCodeRemoteLoader 通过定时刷新错误码 -public class YudaoErrorCodeConfiguration { - - @Bean - public ErrorCodeAutoGenerator errorCodeAutoGenerator(@Value("${spring.application.name}") String applicationName, - ErrorCodeProperties errorCodeProperties, - ErrorCodeApi errorCodeApi) { - return new ErrorCodeAutoGeneratorImpl(applicationName, errorCodeProperties.getConstantsClassList(), errorCodeApi); - } - - @Bean - public ErrorCodeLoader errorCodeLoader(@Value("${spring.application.name}") String applicationName, - ErrorCodeApi errorCodeApi) { - return new ErrorCodeLoaderImpl(applicationName, errorCodeApi); - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 69aa256..ecd3f71 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1 +1 @@ -cn.iocoder.yudao.framework.errorcode.config.YudaoErrorCodeConfiguration \ No newline at end of file +cn.iocoder.yudao.framework.errorcode.config.YudaoErrorCodeAutoConfiguration diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/test/java/cn/iocoder/yudao/framework/tenant/core/job/TestJob.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/test/java/cn/iocoder/yudao/framework/tenant/core/job/TestJob.java deleted file mode 100644 index 2a6d200..0000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/test/java/cn/iocoder/yudao/framework/tenant/core/job/TestJob.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.framework.tenant.core.job; - -import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; -import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -@Component -public class TestJob implements JobHandler { - - private final List tenantIds = new CopyOnWriteArrayList<>(); - - @Override - @TenantJob // 标记多租户 - public String execute(String param) throws Exception { - tenantIds.add(TenantContextHolder.getTenantId()); - return "success"; - } - - public List getTenantIds() { - CollUtil.sort(tenantIds, Long::compareTo); - return tenantIds; - } - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java index 01b5714..2f22f4f 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java @@ -29,8 +29,6 @@ public class SecurityConfiguration { .antMatchers("/swagger-resources/**").anonymous() .antMatchers("/webjars/**").anonymous() .antMatchers("/*/api-docs").anonymous(); - // 积木报表 - registry.antMatchers("/jmreport/**").permitAll(); // Spring Boot Actuator 的安全配置 registry.antMatchers("/actuator").anonymous() .antMatchers("/actuator/**").anonymous(); diff --git a/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImplTest.java b/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImplTest.java deleted file mode 100644 index e4337f2..0000000 --- a/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImplTest.java +++ /dev/null @@ -1,98 +0,0 @@ -package cn.iocoder.yudao.module.member.service.address; - -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; -import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; -import cn.iocoder.yudao.module.member.dal.dataobject.address.MemberAddressDO; -import cn.iocoder.yudao.module.member.dal.mysql.address.MemberAddressMapper; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.Import; - -import javax.annotation.Resource; - -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; -import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.ADDRESS_NOT_EXISTS; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -/** - * {@link AddressServiceImpl} 的单元测试类 - * - * @author 芋道源码 - */ -@Import(AddressServiceImpl.class) -public class AddressServiceImplTest extends BaseDbUnitTest { - - @Resource - private AddressServiceImpl addressService; - - @Resource - private MemberAddressMapper addressMapper; - - @Test - public void testCreateAddress_success() { - // 准备参数 - AppAddressCreateReqVO reqVO = randomPojo(AppAddressCreateReqVO.class); - - // 调用 - Long addressId = addressService.createAddress(randomLongId(), reqVO); - // 断言 - assertNotNull(addressId); - // 校验记录的属性是否正确 - MemberAddressDO address = addressMapper.selectById(addressId); - assertPojoEquals(reqVO, address); - } - - @Test - public void testUpdateAddress_success() { - // mock 数据 - MemberAddressDO dbAddress = randomPojo(MemberAddressDO.class); - addressMapper.insert(dbAddress);// @Sql: 先插入出一条存在的数据 - // 准备参数 - AppAddressUpdateReqVO reqVO = randomPojo(AppAddressUpdateReqVO.class, o -> { - o.setId(dbAddress.getId()); // 设置更新的 ID - }); - - // 调用 - addressService.updateAddress(dbAddress.getUserId(), reqVO); - // 校验是否更新正确 - MemberAddressDO address = addressMapper.selectById(reqVO.getId()); // 获取最新的 - assertPojoEquals(reqVO, address); - } - - @Test - public void testUpdateAddress_notExists() { - // 准备参数 - AppAddressUpdateReqVO reqVO = randomPojo(AppAddressUpdateReqVO.class); - - // 调用, 并断言异常 - assertServiceException(() -> addressService.updateAddress(randomLongId(), reqVO), ADDRESS_NOT_EXISTS); - } - - @Test - public void testDeleteAddress_success() { - // mock 数据 - MemberAddressDO dbAddress = randomPojo(MemberAddressDO.class); - addressMapper.insert(dbAddress);// @Sql: 先插入出一条存在的数据 - // 准备参数 - Long id = dbAddress.getId(); - - // 调用 - addressService.deleteAddress(dbAddress.getUserId(), id); - // 校验数据不存在了 - assertNull(addressMapper.selectById(id)); - } - - @Test - public void testDeleteAddress_notExists() { - // 准备参数 - Long id = randomLongId(); - - // 调用, 并断言异常 - assertServiceException(() -> addressService.deleteAddress(randomLongId(), id), ADDRESS_NOT_EXISTS); - } - -} diff --git a/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/MemberAddressServiceImplTest.java b/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/MemberAddressServiceImplTest.java new file mode 100644 index 0000000..f584993 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/MemberAddressServiceImplTest.java @@ -0,0 +1,98 @@ +package cn.iocoder.yudao.module.member.service.address; + +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; +import cn.iocoder.yudao.module.member.dal.dataobject.address.MemberAddressDO; +import cn.iocoder.yudao.module.member.dal.mysql.address.MemberAddressMapper; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; + +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.ADDRESS_NOT_EXISTS; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * {@link AddressServiceImpl} 的单元测试类 + * + * @author 芋道源码 + */ +@Import(AddressServiceImpl.class) +public class MemberAddressServiceImplTest extends BaseDbUnitTest { + + @Resource + private AddressServiceImpl addressService; + + @Resource + private MemberAddressMapper addressMapper; + + @Test + public void testCreateAddress_success() { + // 准备参数 + AppAddressCreateReqVO reqVO = randomPojo(AppAddressCreateReqVO.class); + + // 调用 + Long addressId = addressService.createAddress(randomLongId(), reqVO); + // 断言 + assertNotNull(addressId); + // 校验记录的属性是否正确 + MemberAddressDO address = addressMapper.selectById(addressId); + assertPojoEquals(reqVO, address); + } + + @Test + public void testUpdateAddress_success() { + // mock 数据 + MemberAddressDO dbAddress = randomPojo(MemberAddressDO.class); + addressMapper.insert(dbAddress);// @Sql: 先插入出一条存在的数据 + // 准备参数 + AppAddressUpdateReqVO reqVO = randomPojo(AppAddressUpdateReqVO.class, o -> { + o.setId(dbAddress.getId()); // 设置更新的 ID + }); + + // 调用 + addressService.updateAddress(dbAddress.getUserId(), reqVO); + // 校验是否更新正确 + MemberAddressDO address = addressMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, address); + } + + @Test + public void testUpdateAddress_notExists() { + // 准备参数 + AppAddressUpdateReqVO reqVO = randomPojo(AppAddressUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> addressService.updateAddress(randomLongId(), reqVO), ADDRESS_NOT_EXISTS); + } + + @Test + public void testDeleteAddress_success() { + // mock 数据 + MemberAddressDO dbAddress = randomPojo(MemberAddressDO.class); + addressMapper.insert(dbAddress);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbAddress.getId(); + + // 调用 + addressService.deleteAddress(dbAddress.getUserId(), id); + // 校验数据不存在了 + assertNull(addressMapper.selectById(id)); + } + + @Test + public void testDeleteAddress_notExists() { + // 准备参数 + Long id = randomLongId(); + + // 调用, 并断言异常 + assertServiceException(() -> addressService.deleteAddress(randomLongId(), id), ADDRESS_NOT_EXISTS); + } + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java index 1c48951..dbfad66 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java @@ -31,5 +31,4 @@ public interface DictDataConvert { List convertList03(List list); - List convertList04(List list); } diff --git a/yudao-server/pom.xml b/yudao-server/pom.xml index 87a9617..d0be49d 100644 --- a/yudao-server/pom.xml +++ b/yudao-server/pom.xml @@ -37,59 +37,59 @@ - - - - - + + cn.iocoder.boot + yudao-module-member-biz + ${revision} + - - - - - + + cn.iocoder.boot + yudao-module-report-biz + ${revision} + - - - - - + + cn.iocoder.boot + yudao-module-bpm-biz + ${revision} + - - - - - + + cn.iocoder.boot + yudao-module-pay-biz + ${revision} + - - - - - + + cn.iocoder.boot + yudao-module-mp-biz + ${revision} + - - - - - - - - - - - - - - - - - - - - + + cn.iocoder.boot + yudao-module-promotion-biz + ${revision} + + + cn.iocoder.boot + yudao-module-product-biz + ${revision} + + + cn.iocoder.boot + yudao-module-trade-biz + ${revision} + + + cn.iocoder.boot + yudao-module-statistics-biz + ${revision} + -- libgit2 0.21.4