添加查询数量模板.

This commit is contained in:
lijiahang
2023-08-24 15:45:35 +08:00
parent 8695fa9af3
commit de4569890f
7 changed files with 58 additions and 5 deletions

View File

@@ -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 {

View File

@@ -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);

View File

@@ -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) {
// 条件

View File

@@ -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}
*

View File

@@ -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
}
}

View File

@@ -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}
*

View File

@@ -51,6 +51,12 @@
<groupId>com.orion.ops</groupId>
<artifactId>orion-ops-spring-boot-starter-storage</artifactId>
</dependency>
<!-- test -->
<dependency>
<groupId>com.orion.ops</groupId>
<artifactId>orion-ops-spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
</project>