From de4569890f285dcc56074ac8bbf326ed1170039a Mon Sep 17 00:00:00 2001 From: lijiahang Date: Thu, 24 Aug 2023 15:45:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9F=A5=E8=AF=A2=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E6=A8=A1=E6=9D=BF.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/core/base/BaseUnitTest.java | 4 ++- .../generator/VelocityTemplateEngine.java | 1 + .../orion-server-module-service-impl.java.vm | 8 ++++++ .../orion-server-module-service.java.vm | 8 ++++++ .../orion-server-provider-api-impl.java.vm | 28 ++++++++++++++++--- .../orion-server-provider-api.java.vm | 8 ++++++ .../orion-ops-module-infra-service/pom.xml | 6 ++++ 7 files changed, 58 insertions(+), 5 deletions(-) diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-test/src/main/java/com/orion/ops/framework/test/core/base/BaseUnitTest.java b/orion-ops-framework/orion-ops-spring-boot-starter-test/src/main/java/com/orion/ops/framework/test/core/base/BaseUnitTest.java index 1d666c37..38782947 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-test/src/main/java/com/orion/ops/framework/test/core/base/BaseUnitTest.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-test/src/main/java/com/orion/ops/framework/test/core/base/BaseUnitTest.java @@ -16,6 +16,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; +import org.springframework.test.annotation.Commit; import org.springframework.test.context.ActiveProfiles; import org.springframework.transaction.annotation.Transactional; @@ -26,9 +27,10 @@ import org.springframework.transaction.annotation.Transactional; * @version 1.0.0 * @since 2023/8/23 15:12 */ +@Commit +@Transactional(rollbackFor = Exception.class) @ActiveProfiles("unit-test") @TestMethodOrder(MethodOrderer.OrderAnnotation.class) -@Transactional(rollbackFor = Exception.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseUnitTest.Application.class) public class BaseUnitTest { diff --git a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/VelocityTemplateEngine.java b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/VelocityTemplateEngine.java index 3486cafb..e65ddf12 100644 --- a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/VelocityTemplateEngine.java +++ b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/VelocityTemplateEngine.java @@ -219,6 +219,7 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine { map.put("getById", "通过 id 查询" + comment); map.put("listByIdList", "通过 id 批量查询" + comment); map.put("listAll", "查询全部" + comment); + map.put("queryCount", "查询" + comment + "数量"); map.put("queryPage", "分页查询" + comment); map.put("deleteById", "通过 id 删除" + comment); map.put("batchDeleteByIdList", "通过 id 批量删除" + comment); diff --git a/orion-ops-launch/src/main/resources/templates/orion-server-module-service-impl.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-module-service-impl.java.vm index 23ec212d..5dcde2b0 100644 --- a/orion-ops-launch/src/main/resources/templates/orion-server-module-service-impl.java.vm +++ b/orion-ops-launch/src/main/resources/templates/orion-server-module-service-impl.java.vm @@ -91,6 +91,14 @@ public class ${table.serviceImplName} implements ${table.serviceName} { .list(${type}Convert.MAPPER::to); } + @Override + public Long get${type}Count(${type}QueryRequest request) { + // 条件 + LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(request); + // 查询 + return ${typeLower}DAO.selectCount(wrapper); + } + @Override public DataGrid<${type}VO> get${type}Page(${type}QueryRequest request) { // 条件 diff --git a/orion-ops-launch/src/main/resources/templates/orion-server-module-service.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-module-service.java.vm index 05f47834..d6713cfe 100644 --- a/orion-ops-launch/src/main/resources/templates/orion-server-module-service.java.vm +++ b/orion-ops-launch/src/main/resources/templates/orion-server-module-service.java.vm @@ -56,6 +56,14 @@ public interface ${table.serviceName} { */ List<${type}VO> get${type}List(${type}QueryRequest request); + /** + * ${apiComment.queryCount} + * + * @param request request + * @return count + */ + Long get${type}Count(Favorite${type}Request request); + /** * ${apiComment.queryPage} * diff --git a/orion-ops-launch/src/main/resources/templates/orion-server-provider-api-impl.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-provider-api-impl.java.vm index d14dfd93..57f3fa7a 100644 --- a/orion-ops-launch/src/main/resources/templates/orion-server-provider-api-impl.java.vm +++ b/orion-ops-launch/src/main/resources/templates/orion-server-provider-api-impl.java.vm @@ -89,16 +89,23 @@ public class ${type}ApiImpl implements ${type}Api { log.info("${type}Api.get${type}List dto: {}", JSON.toJSONString(dto)); Valid.valid(dto); // 条件 - LambdaQueryWrapper<${type}DO> wrapper = ${typeLower}DAO.wrapper() - #foreach($field in ${table.fields}) - .eq(${type}DO::get${field.capitalName}, dto.get${field.capitalName}())#if(!$foreach.hasNext);#end - #end + LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(dto); // 查询 return ${typeLower}DAO.of() .wrapper(wrapper) .dataGrid(${type}ProviderConvert.MAPPER::to); } + @Override + public Long get${type}Count(FavoriteQueryDTO dto) { + log.info("${type}Api.get${type}Count dto: {}", JSON.toJSONString(dto)); + Valid.valid(dto); + // 条件 + LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(dto); + // 查询 + return ${typeLower}DAO.selectCount(wrapper); + } + @Override public Integer delete${type}ById(Long id) { log.info("${type}Api.delete${type}ById id: {}", id); @@ -115,4 +122,17 @@ public class ${type}ApiImpl implements ${type}Api { return ${typeLower}DAO.deleteBatchIds(idList); } + /** + * 构建查询 wrapper + * + * @param dto dto + * @return wrapper + */ + private LambdaQueryWrapper<${type}DO> buildQueryWrapper(${type}QueryDTO dto) { + return ${typeLower}DAO.wrapper() + #foreach($field in ${table.fields}) + .eq(${type}DO::get${field.capitalName}, dto.get${field.capitalName}())#if(!$foreach.hasNext);#end + #end + } + } diff --git a/orion-ops-launch/src/main/resources/templates/orion-server-provider-api.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-provider-api.java.vm index 4204d3eb..5a163a76 100644 --- a/orion-ops-launch/src/main/resources/templates/orion-server-provider-api.java.vm +++ b/orion-ops-launch/src/main/resources/templates/orion-server-provider-api.java.vm @@ -56,6 +56,14 @@ public interface ${type}Api { */ List<${type}DTO> get${type}List(${type}QueryDTO dto); + /** + * ${apiComment.queryCount} + * + * @param dto dto + * @return count + */ + Long get${type}Count(${type}QueryDTO dto); + /** * ${apiComment.deleteById} * diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/pom.xml b/orion-ops-module-infra/orion-ops-module-infra-service/pom.xml index c1e4c613..873727ec 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/pom.xml +++ b/orion-ops-module-infra/orion-ops-module-infra-service/pom.xml @@ -51,6 +51,12 @@ com.orion.ops orion-ops-spring-boot-starter-storage + + + + com.orion.ops + orion-ops-spring-boot-starter-test + \ No newline at end of file