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