🔨 数据清理时添加条数限制.

This commit is contained in:
lijiahang
2024-08-29 18:26:26 +08:00
parent d7b747eac4
commit 104a9a0aa3
61 changed files with 490 additions and 283 deletions

View File

@@ -1,17 +0,0 @@
package com.orion.visor.framework.common.annotation;
import java.lang.annotation.*;
/**
* 保留
*
* @author Jiahang Li
* @version 1.0.0
* @since 2024/6/6 15:26
*/
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Keep {
}

View File

@@ -0,0 +1,26 @@
package com.orion.visor.framework.common.entity;
/**
* 数据清理请求 定义
*
* @author Jiahang Li
* @version 1.0.0
* @since 2024/8/29 11:26
*/
public interface DataClearRequest {
/**
* 获取清理数量限制
*
* @return 清理限制
*/
Integer getLimit();
/**
* 设置清理数量限制
*
* @param limit limit
*/
void setLimit(Integer limit);
}

View File

@@ -1,12 +1,12 @@
package com.orion.visor.framework.common.entity;
import com.orion.lang.define.wrapper.IPageRequest;
import com.orion.visor.framework.common.validator.group.Page;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
/**
* 公共页码请求
@@ -17,16 +17,18 @@ import javax.validation.constraints.Min;
*/
@Data
@Schema(description = "公共页码请求")
public class PageRequest implements IPageRequest {
public class PageRequest {
@NotNull(groups = Page.class)
@Min(value = 1, groups = Page.class)
@Max(value = 10000, groups = Page.class)
@Schema(description = "页码")
private int page;
private Integer page;
@NotNull(groups = Page.class)
@Min(value = 1, groups = Page.class)
@Max(value = 200, groups = Page.class)
@Schema(description = "大小")
private int limit;
private Integer limit;
}

View File

@@ -20,7 +20,7 @@ public class SqlUtils {
* @param limit limit
* @return limit
*/
public static String limit(Integer limit) {
public static String limit(Number limit) {
return Const.LIMIT + Const.SPACE + limit;
}
@@ -31,7 +31,7 @@ public class SqlUtils {
* @param limit limit
* @return limit
*/
public static String limit(int offset, Integer limit) {
public static String limit(Number offset, Number limit) {
return Const.LIMIT + Const.SPACE + offset + Const.COMMA + limit;
}

View File

@@ -37,7 +37,7 @@ public class DataQuery<T> {
private final BaseMapper<T> dao;
private IPageRequest page;
private PageRequest page;
private Wrapper<T> wrapper;
@@ -74,8 +74,9 @@ public class DataQuery<T> {
return new DataQuery<>(dao, wrapper);
}
public DataQuery<T> page(IPageRequest page) {
this.page = Valid.notNull(page, "page is null");
public DataQuery<T> page(com.orion.visor.framework.common.entity.PageRequest page) {
com.orion.visor.framework.common.entity.PageRequest pr = Valid.notNull(page, "page is null");
this.page = new PageRequest(pr.getPage(), pr.getLimit());
return this;
}
@@ -200,6 +201,18 @@ public class DataQuery<T> {
return dao.selectCount(wrapper);
}
public Long countMax(Number max) {
Long count = dao.selectCount(wrapper);
if (max == null) {
return count;
}
long maxValue = max.longValue();
if (maxValue <= 0L) {
return count;
}
return Math.min(count, maxValue);
}
public boolean absent() {
return dao.selectCount(wrapper) == 0;
}

View File

@@ -60,6 +60,18 @@ Authorization: {{token}}
}
${httpComment} ${apiComment.queryCount}
POST {{baseUrl}}/${package.ModuleName}/${typeHyphen}/count
Content-Type: application/json
Authorization: {{token}}
{
#foreach($field in ${table.fields})
"${field.propertyName}": ""#if($foreach.hasNext),#end
#end
}
${httpComment} ${apiComment.deleteById}
DELETE {{baseUrl}}/${package.ModuleName}/${typeHyphen}/delete?id=1
Authorization: {{token}}

View File

@@ -113,6 +113,13 @@ public class ${table.controllerName} {
return ${typeLower}Service.get${type}Page(request);
}
@PostMapping("/count")
@Operation(summary = "${apiComment.queryCount}")
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
public Long get${type}Count(@Validated @RequestBody ${type}QueryRequest request) {
return ${typeLower}Service.get${type}Count(request);
}
#if($meta.enableDemoApi)
@DemoDisableApi
#end

View File

@@ -152,10 +152,9 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
#end
@Override
public Long get${type}Count(${type}QueryRequest request) {
// 条件
LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(request);
// 查询
return ${typeLower}DAO.selectCount(wrapper);
return ${typeLower}DAO.of()
.wrapper(this.buildQueryWrapper(request))
.countMax(request.getLimit());
}
@Override

View File

@@ -115,6 +115,13 @@ export function get${vue.featureEntity}Page(request: ${vue.featureEntity}QueryRe
return axios.post<DataGrid<${vue.featureEntity}QueryResponse>>('/${package.ModuleName}/${typeHyphen}/query', request);
}
/**
* $apiComment.queryCount
*/
export function get${vue.featureEntity}Count(request: ${vue.featureEntity}QueryRequest) {
return axios.post<number>('/${package.ModuleName}/${typeHyphen}/count', request);
}
/**
* $apiComment.deleteById
*/