From d11ca1c51c36d18b17515f09f1def81aeff61405 Mon Sep 17 00:00:00 2001 From: zwjsec Date: Thu, 11 Jul 2024 11:07:14 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90feature=E3=80=91=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E9=A2=86=E5=9F=9F=E5=BA=94=E7=94=A8=E8=81=9A=E5=90=88=E5=B1=95?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/PackageConstant.java | 5 ++++ .../fieldpkg/FieldPkgGatewayImpl.java | 24 +++++++++++++++ .../fieldpkg/converter/FieldPkgConverter.java | 29 ++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/easysoftware/common/constant/PackageConstant.java b/src/main/java/com/easysoftware/common/constant/PackageConstant.java index 292432c..12d13c7 100644 --- a/src/main/java/com/easysoftware/common/constant/PackageConstant.java +++ b/src/main/java/com/easysoftware/common/constant/PackageConstant.java @@ -29,6 +29,11 @@ public final class PackageConstant { */ public static final int MIN_PAGE_NUM = 1; + /** + * zero constant. + */ + public static final int ZERO = 0; + /** * Maximum page size allowed. */ diff --git a/src/main/java/com/easysoftware/infrastructure/fieldpkg/FieldPkgGatewayImpl.java b/src/main/java/com/easysoftware/infrastructure/fieldpkg/FieldPkgGatewayImpl.java index 33d1c33..dd97178 100644 --- a/src/main/java/com/easysoftware/infrastructure/fieldpkg/FieldPkgGatewayImpl.java +++ b/src/main/java/com/easysoftware/infrastructure/fieldpkg/FieldPkgGatewayImpl.java @@ -17,6 +17,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.easysoftware.application.fieldpkg.dto.FieldPkgSearchCondition; import com.easysoftware.application.fieldpkg.vo.FieldPkgVo; +import com.easysoftware.common.constant.PackageConstant; import com.easysoftware.common.exception.ParamErrorException; import com.easysoftware.common.utils.ClassField; import com.easysoftware.common.utils.QueryWrapperUtil; @@ -62,6 +63,28 @@ public class FieldPkgGatewayImpl implements FieldPkgGateway { IPage resPage = mapper.selectPage(page, wrapper); List list = resPage.getRecords(); List voList = FieldPkgConverter.toVo(list); + + if (condition.getOs() == null && condition.getArch() == null) { + voList = FieldPkgConverter.aggregateVoByName(voList); + } + + // 聚合后个数少于约定数目 查询下一页填充后聚合返回 + if (voList.size() < condition.getPageSize()) { + Page nextPage = new Page<>(condition.getPageNum() + 1, condition.getPageSize()); + IPage nextResPage = mapper.selectPage(nextPage, wrapper); + List nextPlist = nextResPage.getRecords(); + List nextVoList = FieldPkgConverter.toVo(nextPlist); + List candidateVo = FieldPkgConverter.aggregateVoByName(nextVoList); + int missNum = condition.getPageSize() - voList.size(); + for (FieldPkgVo vo : candidateVo) { + if (missNum <= PackageConstant.ZERO) { + break; + } + voList.add(vo); + missNum--; + } + } + long total = resPage.getTotal(); return Map.ofEntries( @@ -129,6 +152,7 @@ public class FieldPkgGatewayImpl implements FieldPkgGateway { /** * query pkg num of arch by os. + * * @param os os. * @return pkg nums of arch. */ diff --git a/src/main/java/com/easysoftware/infrastructure/fieldpkg/converter/FieldPkgConverter.java b/src/main/java/com/easysoftware/infrastructure/fieldpkg/converter/FieldPkgConverter.java index df31d91..bb1f1e8 100644 --- a/src/main/java/com/easysoftware/infrastructure/fieldpkg/converter/FieldPkgConverter.java +++ b/src/main/java/com/easysoftware/infrastructure/fieldpkg/converter/FieldPkgConverter.java @@ -21,7 +21,7 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; - +import java.util.Comparator; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; @@ -56,6 +56,33 @@ public final class FieldPkgConverter { return res; } + /** + * aggregate a list of FieldPkgVo objects to a list of aggregateFieldPkgVo view + * objects. + * + * @param doList The list of FieldPkgVo objects to aggregate. + * @return A list of FieldPkgVo view objects. + */ + public static List aggregateVoByName(final List doList) { + List res = new ArrayList<>(); + + Map> groupedByName = doList.stream() + .collect(Collectors.groupingBy(FieldPkgVo::getName)); + + for (Map.Entry> entry : groupedByName.entrySet()) { + List voList = entry.getValue(); + List sortedVoList = voList.stream() + .sorted(Comparator.comparing(FieldPkgVo::getOs).reversed()) + .toList(); + // 取最新OS + if (!sortedVoList.isEmpty()) { + res.add(sortedVoList.get(0)); + } + } + + return res; + } + /** * Converts a FieldApplicationDO object to a FieldPkgDO view object. * -- Gitee