diff --git a/src/main/java/neatlogic/module/inspect/api/configfile/ListInspectConfigFilePathApi.java b/src/main/java/neatlogic/module/inspect/api/configfile/ListInspectConfigFilePathApi.java index 9cb79da4c2e5d3baeada66c0b6f45fc049c79ac1..22a636f0ef40e09dcb16f0d0d5e80650821bcc8d 100644 --- a/src/main/java/neatlogic/module/inspect/api/configfile/ListInspectConfigFilePathApi.java +++ b/src/main/java/neatlogic/module/inspect/api/configfile/ListInspectConfigFilePathApi.java @@ -26,6 +26,7 @@ import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.util.TableResultUtil; import neatlogic.module.inspect.dao.mapper.InspectConfigFileMapper; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -74,17 +75,24 @@ public class ListInspectConfigFilePathApi extends PrivateApiComponentBase { int rowNum = inspectConfigFileMapper.getInspectConfigFilePathCount(searchVo); if (rowNum > 0) { searchVo.setRowNum(rowNum); - List inspectResourceConfigFilePathList = inspectConfigFileMapper.getInspectConfigFilePathList(searchVo); - List idList = inspectResourceConfigFilePathList.stream().map(InspectConfigFilePathVo::getId).collect(Collectors.toList()); - List inspectResourceConfigFileVersionCountList = inspectConfigFileMapper.getInspectConfigFileVersionCountByPathIdList(idList); - Map versionCountMap = inspectResourceConfigFileVersionCountList.stream().collect(Collectors.toMap(InspectConfigFilePathVo::getId, InspectConfigFilePathVo::getVersionCount)); - for (InspectConfigFilePathVo pathVo : inspectResourceConfigFilePathList) { - Integer versionCount = versionCountMap.get(pathVo.getId()); - if (versionCount != null) { - pathVo.setVersionCount(versionCount); + List idList = inspectConfigFileMapper.getInspectConfigFilePathIdList(searchVo); + if (CollectionUtils.isNotEmpty(idList)) { + List tbodyList = new ArrayList<>(); + List inspectResourceConfigFilePathList = inspectConfigFileMapper.getInspectConfigFilePathList(idList); + Map map = inspectResourceConfigFilePathList.stream().collect(Collectors.toMap(InspectConfigFilePathVo::getId, e -> e)); + List inspectResourceConfigFileVersionCountList = inspectConfigFileMapper.getInspectConfigFileVersionCountByPathIdList(idList); + Map versionCountMap = inspectResourceConfigFileVersionCountList.stream().collect(Collectors.toMap(InspectConfigFilePathVo::getId, InspectConfigFilePathVo::getVersionCount)); + for (Long id : idList) { + InspectConfigFilePathVo pathVo = map.get(id); + Integer versionCount = versionCountMap.get(pathVo.getId()); + if (versionCount != null) { + pathVo.setVersionCount(versionCount); + } + tbodyList.add(pathVo); } + return TableResultUtil.getResult(tbodyList, searchVo); } - return TableResultUtil.getResult(inspectResourceConfigFilePathList, searchVo); + } return TableResultUtil.getResult(new ArrayList<>(), searchVo); } diff --git a/src/main/java/neatlogic/module/inspect/dao/mapper/InspectConfigFileMapper.java b/src/main/java/neatlogic/module/inspect/dao/mapper/InspectConfigFileMapper.java index a4de700422aa033a3b4fc0b8c71d2121b09967e7..4905ae04ba1db6e65fc29b4406b1ec514e8b4a0e 100644 --- a/src/main/java/neatlogic/module/inspect/dao/mapper/InspectConfigFileMapper.java +++ b/src/main/java/neatlogic/module/inspect/dao/mapper/InspectConfigFileMapper.java @@ -58,7 +58,9 @@ public interface InspectConfigFileMapper { int getInspectConfigFilePathCount(InspectConfigFilePathSearchVo searchVo); - List getInspectConfigFilePathList(InspectConfigFilePathSearchVo searchVo); + List getInspectConfigFilePathIdList(InspectConfigFilePathSearchVo searchVo); + + List getInspectConfigFilePathList(List idList); List getInspectConfigFilePathListByJobId(Long jobId); diff --git a/src/main/java/neatlogic/module/inspect/dao/mapper/InspectConfigFileMapper.xml b/src/main/java/neatlogic/module/inspect/dao/mapper/InspectConfigFileMapper.xml index 799a1df04d57a37c4ecbdc48abe43754593474c8..1fe6d20fc43ff0fe9cb1edaa08152c5d4c3fb9bf 100644 --- a/src/main/java/neatlogic/module/inspect/dao/mapper/InspectConfigFileMapper.xml +++ b/src/main/java/neatlogic/module/inspect/dao/mapper/InspectConfigFileMapper.xml @@ -431,9 +431,9 @@ - SELECT - a.`id`, - a.`resource_id` AS resourceId, - a.`path`, - a.`inspect_time` AS inspectTime, - b.`name` AS resourceName, - b.`ip` AS resourceIP, - b.`port` AS resourcePort, - b.`type_label` AS resourceTypeLabel + a.`id` FROM `inspect_config_file_path` a JOIN @{DATA_SCHEMA}.`scence_ipobject_detail` b ON b.`id` = a.`resource_id` - AND (a.`path` LIKE CONCAT('%', #{keyword}, '%') - OR b.`name` LIKE CONCAT('%', #{keyword}, '%') - OR b.`ip` LIKE CONCAT('%', #{keyword}, '%') + AND (a.`path` LIKE CONCAT('%', #{keyword}, '%') + OR b.`name` LIKE CONCAT('%', #{keyword}, '%') + OR b.`ip` LIKE CONCAT('%', #{keyword}, '%') ) @@ -480,10 +473,30 @@ - ORDER BY a.`inspect_time` desc + GROUP BY a.`id` + ORDER BY MAX(a.`inspect_time`) desc LIMIT #{startNum}, #{pageSize} + +