添加查询数量模板.
This commit is contained in:
@@ -16,6 +16,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.test.annotation.Commit;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -26,9 +27,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @since 2023/8/23 15:12
|
* @since 2023/8/23 15:12
|
||||||
*/
|
*/
|
||||||
|
@Commit
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@ActiveProfiles("unit-test")
|
@ActiveProfiles("unit-test")
|
||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseUnitTest.Application.class)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseUnitTest.Application.class)
|
||||||
public class BaseUnitTest {
|
public class BaseUnitTest {
|
||||||
|
|
||||||
|
|||||||
@@ -219,6 +219,7 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
|||||||
map.put("getById", "通过 id 查询" + comment);
|
map.put("getById", "通过 id 查询" + comment);
|
||||||
map.put("listByIdList", "通过 id 批量查询" + comment);
|
map.put("listByIdList", "通过 id 批量查询" + comment);
|
||||||
map.put("listAll", "查询全部" + comment);
|
map.put("listAll", "查询全部" + comment);
|
||||||
|
map.put("queryCount", "查询" + comment + "数量");
|
||||||
map.put("queryPage", "分页查询" + comment);
|
map.put("queryPage", "分页查询" + comment);
|
||||||
map.put("deleteById", "通过 id 删除" + comment);
|
map.put("deleteById", "通过 id 删除" + comment);
|
||||||
map.put("batchDeleteByIdList", "通过 id 批量删除" + comment);
|
map.put("batchDeleteByIdList", "通过 id 批量删除" + comment);
|
||||||
|
|||||||
@@ -91,6 +91,14 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
|||||||
.list(${type}Convert.MAPPER::to);
|
.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
|
@Override
|
||||||
public DataGrid<${type}VO> get${type}Page(${type}QueryRequest request) {
|
public DataGrid<${type}VO> get${type}Page(${type}QueryRequest request) {
|
||||||
// 条件
|
// 条件
|
||||||
|
|||||||
@@ -56,6 +56,14 @@ public interface ${table.serviceName} {
|
|||||||
*/
|
*/
|
||||||
List<${type}VO> get${type}List(${type}QueryRequest request);
|
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}
|
* ${apiComment.queryPage}
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -89,16 +89,23 @@ public class ${type}ApiImpl implements ${type}Api {
|
|||||||
log.info("${type}Api.get${type}List dto: {}", JSON.toJSONString(dto));
|
log.info("${type}Api.get${type}List dto: {}", JSON.toJSONString(dto));
|
||||||
Valid.valid(dto);
|
Valid.valid(dto);
|
||||||
// 条件
|
// 条件
|
||||||
LambdaQueryWrapper<${type}DO> wrapper = ${typeLower}DAO.wrapper()
|
LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(dto);
|
||||||
#foreach($field in ${table.fields})
|
|
||||||
.eq(${type}DO::get${field.capitalName}, dto.get${field.capitalName}())#if(!$foreach.hasNext);#end
|
|
||||||
#end
|
|
||||||
// 查询
|
// 查询
|
||||||
return ${typeLower}DAO.of()
|
return ${typeLower}DAO.of()
|
||||||
.wrapper(wrapper)
|
.wrapper(wrapper)
|
||||||
.dataGrid(${type}ProviderConvert.MAPPER::to);
|
.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
|
@Override
|
||||||
public Integer delete${type}ById(Long id) {
|
public Integer delete${type}ById(Long id) {
|
||||||
log.info("${type}Api.delete${type}ById id: {}", 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);
|
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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,14 @@ public interface ${type}Api {
|
|||||||
*/
|
*/
|
||||||
List<${type}DTO> get${type}List(${type}QueryDTO dto);
|
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}
|
* ${apiComment.deleteById}
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -51,6 +51,12 @@
|
|||||||
<groupId>com.orion.ops</groupId>
|
<groupId>com.orion.ops</groupId>
|
||||||
<artifactId>orion-ops-spring-boot-starter-storage</artifactId>
|
<artifactId>orion-ops-spring-boot-starter-storage</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.orion.ops</groupId>
|
||||||
|
<artifactId>orion-ops-spring-boot-starter-test</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
Reference in New Issue
Block a user