实现需求56 检查项目设置-》检查类型维护中的分页功能。

This commit is contained in:
HuangShun
2026-02-04 16:03:41 +08:00
parent a434dfdfff
commit 2c2bb1adb0
2 changed files with 167 additions and 62 deletions

View File

@@ -1,6 +1,8 @@
package com.openhis.web.check.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.core.common.core.controller.BaseController;
import com.core.common.core.domain.AjaxResult;
import com.core.common.core.domain.R;
@@ -20,7 +22,8 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.time.LocalDate;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
* 检查类型管理Controller
@@ -42,14 +45,59 @@ public class CheckTypeController extends BaseController {
private final ICheckPackageAppService checkPackageAppService;
/**
* 获取检查类型列表
* 获取检查类型列表(支持分页)
*/
@GetMapping("/list")
public AjaxResult list() {
List<CheckType> list = checkTypeService.list();
return AjaxResult.success(list);
}
public AjaxResult list(
@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "10") Integer pageSize) {
if (pageSize > 10) pageSize = 10;
// 1. 分页查询父节点NULL + 0 都算父)
Page<CheckType> parentPage = checkTypeService.page(
new Page<>(pageNo, pageSize),
new QueryWrapper<CheckType>()
.and(w -> w.isNull("parent_id").or().eq("parent_id", 0))
.orderByAsc("id")
);
if (parentPage.getRecords().isEmpty()) {
return AjaxResult.success(parentPage);
}
// 2. 父ID列表注意类型
List<Long> parentIds = parentPage.getRecords()
.stream()
.map(CheckType::getId)
.collect(Collectors.toList());
// 3. 查询子节点
List<CheckType> children = checkTypeService.list(
new QueryWrapper<CheckType>().in("parent_id", parentIds)
);
// 4. 分组
Map<Long, List<CheckType>> childMap =
children.stream().collect(Collectors.groupingBy(CheckType::getParentId));
// 5. 拼接父 + 子
List<CheckType> result = new ArrayList<>();
for (CheckType parent : parentPage.getRecords()) {
result.add(parent);
List<CheckType> list = childMap.get(parent.getId());
if (list != null && !list.isEmpty()) {
result.addAll(list);
}
}
// 6. 返回total 是父节点总数)
Page<CheckType> page =
new Page<>(pageNo, pageSize, parentPage.getTotal());
page.setRecords(result);
return AjaxResult.success(page);
}
/**
* 获取检查方法列表
*/