|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
package com.cweb.controller; |
|
|
|
|
|
|
|
|
|
import com.cweb.config.TuanYouConfig; |
|
|
|
|
import com.github.pagehelper.Page; |
|
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
|
import com.hai.common.security.SessionObject; |
|
|
|
@ -48,8 +49,8 @@ public class HighGasController { |
|
|
|
|
@RequestParam(name = "oilNoName", required = true) String oilNoName, |
|
|
|
|
@RequestParam(name = "longitude", required = true) String longitude, |
|
|
|
|
@RequestParam(name = "latitude", required = true) String latitude, |
|
|
|
|
@RequestParam(name = "pageNum", required = true) String pageNum, |
|
|
|
|
@RequestParam(name = "pageSize", required = true) String pageSize |
|
|
|
|
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
|
|
|
|
@RequestParam(name = "pageSize", required = true) Integer pageSize |
|
|
|
|
) { |
|
|
|
|
try { |
|
|
|
|
if (StringUtils.isBlank(storeName)) { |
|
|
|
@ -61,7 +62,9 @@ public class HighGasController { |
|
|
|
|
store.put("distance", Math.round(distance/100d)/10d); |
|
|
|
|
} |
|
|
|
|
List<Map<String, Object>> distance = storeList.stream().sorted(Comparator.comparingDouble(entry -> Double.valueOf(entry.get("distance").toString()))).collect(Collectors.toList()); |
|
|
|
|
return ResponseMsgUtil.success(distance); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResponseMsgUtil.success(initPageInfoObj(pageNum,distance.size(),pageSize,new PageInfo<>(distance))); |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("HighGasController -> getGasDetailByStoreKey() error!",e); |
|
|
|
@ -69,6 +72,83 @@ public class HighGasController { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static <T> PageInfo<T> initPageInfoObj(int currentPage, int total, int pageSize, PageInfo<T> pageInfo) { |
|
|
|
|
List<T> list = pageInfo.getList(); |
|
|
|
|
int fromIndex = 0; |
|
|
|
|
int toIndex = 0; |
|
|
|
|
if (total / pageSize == 0 && total % pageSize > 0) { |
|
|
|
|
fromIndex = 0; |
|
|
|
|
toIndex = total; |
|
|
|
|
} else { |
|
|
|
|
if (total / pageSize >= 1 && total % pageSize >= 0) { |
|
|
|
|
fromIndex = pageSize * (currentPage - 1); |
|
|
|
|
if (pageSize * currentPage >= total) { |
|
|
|
|
toIndex = total; |
|
|
|
|
} else { |
|
|
|
|
toIndex = pageSize * currentPage; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
list = list.subList(fromIndex, toIndex); |
|
|
|
|
} catch (IndexOutOfBoundsException e) { |
|
|
|
|
fromIndex = 0; |
|
|
|
|
toIndex= pageSize; |
|
|
|
|
list = list.subList(fromIndex, toIndex); |
|
|
|
|
}catch(IllegalArgumentException e) { |
|
|
|
|
fromIndex = total-pageSize; |
|
|
|
|
toIndex =total; |
|
|
|
|
list = list.subList(fromIndex, toIndex); |
|
|
|
|
} |
|
|
|
|
pageInfo.setList(list); |
|
|
|
|
pageInfo.setNextPage(currentPage < ((total + pageSize - 1) / pageSize) ? currentPage + 1 : currentPage); |
|
|
|
|
pageInfo.setTotal(total); |
|
|
|
|
pageInfo.setPageNum(currentPage); |
|
|
|
|
pageInfo.setPages((total + pageSize - 1) / pageSize); |
|
|
|
|
pageInfo.setNavigateLastPage((total + pageSize - 1) / pageSize); |
|
|
|
|
pageInfo.setPrePage(currentPage > 1 ? currentPage - 1 : currentPage); |
|
|
|
|
pageInfo.setIsFirstPage(currentPage == 1 ? true : false); |
|
|
|
|
pageInfo.setIsLastPage(currentPage == (total + pageSize - 1) / pageSize ? true : false); |
|
|
|
|
pageInfo.setHasPreviousPage(currentPage == 1 ? false : true); |
|
|
|
|
pageInfo.setHasNextPage(currentPage == (total + pageSize - 1) / pageSize ? false : true); |
|
|
|
|
return calcNavigatepageNums(pageInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static <T> PageInfo<T> calcNavigatepageNums(PageInfo<T> pageInfo) { |
|
|
|
|
// 当总页数小于或等于导航页码数时
|
|
|
|
|
if (pageInfo.getPages() <= pageInfo.getNavigatePages()) { |
|
|
|
|
pageInfo.setNavigatepageNums(new int[pageInfo.getPages()]); |
|
|
|
|
for (int i = 0; i < pageInfo.getPages(); i++) { |
|
|
|
|
pageInfo.getNavigatepageNums()[i] = i + 1; |
|
|
|
|
} |
|
|
|
|
} else { // 当总页数大于导航页码数时
|
|
|
|
|
pageInfo.setNavigatepageNums(new int[pageInfo.getNavigatePages()]); |
|
|
|
|
int startNum = pageInfo.getPageNum() - pageInfo.getNavigatePages() / 2; |
|
|
|
|
int endNum = pageInfo.getPageNum() + pageInfo.getNavigatePages() / 2; |
|
|
|
|
|
|
|
|
|
if (startNum < 1) { |
|
|
|
|
startNum = 1; |
|
|
|
|
// (最前navigatePages页
|
|
|
|
|
for (int i = 0; i < pageInfo.getNavigatePages(); i++) { |
|
|
|
|
pageInfo.getNavigatepageNums()[i] = startNum++; |
|
|
|
|
} |
|
|
|
|
} else if (endNum > pageInfo.getPages()) { |
|
|
|
|
endNum = pageInfo.getPages(); |
|
|
|
|
// 最后navigatePages页
|
|
|
|
|
for (int i = pageInfo.getNavigatePages() - 1; i >= 0; i--) { |
|
|
|
|
pageInfo.getNavigatepageNums()[i] = endNum--; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// 所有中间页
|
|
|
|
|
for (int i = 0; i < pageInfo.getNavigatePages(); i++) { |
|
|
|
|
pageInfo.getNavigatepageNums()[i] = startNum++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return pageInfo; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping(value="/getGasDetailByStoreKey",method = RequestMethod.GET) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "根据门店key 查询") |
|
|
|
|