diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java index 21d7119b6..fd079d0b8 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java @@ -1,6 +1,8 @@ package com.jsowell.pile.service.impl; import cn.hutool.core.util.PageUtil; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import com.google.common.collect.Lists; import com.jsowell.common.constant.CacheConstants; import com.jsowell.common.constant.Constants; @@ -450,20 +452,22 @@ public class PileStationInfoServiceImpl implements PileStationInfoService { */ @Override public PageResponse uniAppQueryStationInfoList(QueryStationDTO dto) { - long pageNum = dto.getPageNum() == 0 ? 1L : dto.getPageNum(); - long pageSize = dto.getPageSize() == 0 ? 10L : dto.getPageSize(); + int pageNum = dto.getPageNum() == 0 ? 1 : dto.getPageNum(); + int pageSize = dto.getPageSize() == 0 ? 10 : dto.getPageSize(); // 小程序站点列表页只展示对外开放的站点 dto.setPublicFlag(Constants.ONE); // 根据前台参数分页 + PageHelper.startPage(pageNum, pageSize); List list = pileStationInfoMapper.queryStationInfos(dto); + PageInfo pageInfo = new PageInfo<>(list); List stationVOList = Lists.newArrayList(); - StationInfoVO stationVO = null; + StationInfoVO stationVO; String stationLng = dto.getStationLng(); String stationLat = dto.getStationLat(); double distance = 0d; - for (PileStationVO pileStationVO : list) { + for (PileStationVO pileStationVO : pageInfo.getList()) { stationVO = new StationInfoVO(); if (StringUtils.isNotEmpty(stationLng) && StringUtils.isNotEmpty(stationLat)) { try{ @@ -491,11 +495,10 @@ public class PileStationInfoServiceImpl implements PileStationInfoService { stationVO.setStationImgList(Lists.newArrayList(pileStationVO.getPictures().split(","))); } + // 查询快慢充数量 Map map = pileConnectorInfoService.getPileTypeNum(Long.parseLong(pileStationVO.getId())); - Integer fastFree = map.get("fastFree"); Integer slowFree = map.get("slowFree"); - stationVO.setFastTotal(map.get("fastTotal")); stationVO.setFastFree(fastFree); stationVO.setSlowTotal(map.get("slowTotal")); @@ -526,21 +529,16 @@ public class PileStationInfoServiceImpl implements PileStationInfoService { return a.compareTo(b); }); } - List collect = stationVOList.stream() - .skip((pageNum - 1) * pageSize) - .limit(pageSize) - .collect(Collectors.toList()); - int total = stationVOList.size(); - int pages = PageUtil.totalPage(total, dto.getPageSize()); // 返回结果集 - return PageResponse.builder() - .pageNum(Integer.parseInt(String.valueOf(pageNum))) - .pageSize(Integer.parseInt(String.valueOf(pageSize))) - .list(collect) - .pages(pages) - .total(total) + PageResponse pageResponse = PageResponse.builder() + .pageNum(pageInfo.getPageNum()) + .pageSize(pageInfo.getPageSize()) + .list(stationVOList) + .pages(pageInfo.getPages()) + .total(pageInfo.getTotal()) .build(); + return pageResponse; } /**