From b0264f1e2ae25e9690dc632999cb4ec8df1ad393 Mon Sep 17 00:00:00 2001 From: xiaofajia <1665375861@qq.com> Date: Sat, 14 Dec 2024 15:41:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=96=99=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E5=8A=A0=E6=95=B0=E9=87=8F=E3=80=81=E8=A1=A5=E6=AD=A3=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/InspectionFileController.java | 17 +++++++++++++ .../service/IInspectionFileService.java | 12 +++++++++ .../impl/InspectionFileServiceImpl.java | 25 ++++++++++++++++--- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/controller/InspectionFileController.java b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/controller/InspectionFileController.java index af3c0ae5..ac3409c3 100644 --- a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/controller/InspectionFileController.java +++ b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/controller/InspectionFileController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.inspection.controller; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.core.controller.BaseController; import cn.iocoder.yudao.module.inspection.entity.InspectionFile; @@ -13,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; +import java.util.List; /** * inspectionFileController @@ -105,4 +107,19 @@ public class InspectionFileController extends BaseController } return toAjax(inspectionFileService.deleteInspectionFileById(id)); } + + /** + * 根据id统计数量 + * + * @author 小李 + * @date 14:30 2024/12/14 + * @param ids ids + **/ + @GetMapping("/getCountByIds") + public CommonResult getCountByIds(@RequestParam(value = "ids" ,required = false) List ids) { + if (CollUtil.isEmpty(ids)){ + return null; + } + return success(inspectionFileService.getCountByIds(ids)); + } } diff --git a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/IInspectionFileService.java b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/IInspectionFileService.java index f97a3821..f242a637 100644 --- a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/IInspectionFileService.java +++ b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/IInspectionFileService.java @@ -5,6 +5,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; +import java.util.List; +import java.util.Map; + /** * inspectionFileService接口 * @@ -63,4 +66,13 @@ public interface IInspectionFileService extends IService * @return 分页结果 */ IPage selectInspectionFileList(Page page, InspectionFile inspectionFile); + + /** + * 根据id统计数量 + * + * @author 小李 + * @date 14:30 2024/12/14 + * @param ids ids + **/ + Map getCountByIds(List ids); } diff --git a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionFileServiceImpl.java b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionFileServiceImpl.java index 38349e98..92af6e3f 100644 --- a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionFileServiceImpl.java +++ b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionFileServiceImpl.java @@ -16,6 +16,8 @@ import org.springframework.stereotype.Service; import java.util.Arrays; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * inspectionFileService业务层处理 @@ -160,12 +162,29 @@ public class InspectionFileServiceImpl extends ServiceImpl selectInspectionFileList(Page page, InspectionFile inspectionFile) { // 创建一个空的 QueryWrapper - QueryWrapper queryWrapper = new QueryWrapper<>(); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); if (ObjectUtil.isNotEmpty(inspectionFile.getFatherId())) { - queryWrapper.eq("father_id", inspectionFile.getFatherId()); + queryWrapper.eq(InspectionFile::getFatherId, inspectionFile.getFatherId()); } - + queryWrapper.orderByAsc(InspectionFile::getType); + queryWrapper.orderByDesc(InspectionFile::getCreateTime); // 直接调用 MyBatis-Plus 的 page 方法进行分页查询 return this.page(page, queryWrapper); // 返回符合条件的分页查询结果 } + + /** + * 根据id统计数量 + * + * @author 小李 + * @date 14:30 2024/12/14 + * @param ids ids + **/ + @Override + public Map getCountByIds(List ids){ + List inspectionFiles = baseMapper.selectList(new LambdaQueryWrapper().in(InspectionFile::getFatherId, ids)); + return inspectionFiles.stream().collect(Collectors.groupingBy( + InspectionFile::getFatherId, + Collectors.counting() + )); + } }