Java Stream遍历与一般的foreach循环处理压测分析
-
foreach 循环的压测 (1000并发)
-
Java stram 遍历 (1000并发)
- 代码实例(怎样优化代码?)
@Override
public List<StoreInfoDTO> getStoreInfoListSql(String storeId,Double longitude,Double latitude) {
List<StoreInformation> storeInfoList = null;
try {
QueryWrapper<StoreInformation> query = new QueryWrapper<>();
query.eq(StoreInformation.STORE_STATE, StoreStatus.OPEN);//正常营业中
if(StringUtils.isNotBlank(storeId)){
query.eq(StoreInformation.STORE_CODE, storeId);
}
storeInfoList = storeInformationMapper.selectList(query);
} catch (Exception e) {
log.error("查询门店信息异常:storeId:{},经度longitude:{},纬度latitude:{}",storeId,longitude,latitude);
e.printStackTrace();
}
List<StoreInfoDTO> storeList = Lists.newArrayList();
if(null != storeInfoList && storeInfoList.size() > 0){
// storeInfoList = storeInfoList.stream().filter(item -> Objects.equals(item.getStoreState(), StoreDailyStatus.OPEN)).collect(Collectors.toList());
// storeList = storeInfoList.stream().map(item -> {
// StoreInfoDTO storeLocationInfo = new StoreInfoDTO();
// BeanUtils.copyProperties(item, storeLocationInfo);
// //计算距离
// if(null != longitude && null != latitude){
// double lon2 = item.getLongitude().doubleValue();
// double lat2 = item.getLatitude().doubleValue();
// Double distance = aMapWebApiCallService.getDistance(longitude,latitude,lon2,lat2);//计算两个坐标的距离
// storeLocationInfo.setDistance(distance.intValue());
// }
// return storeLocationInfo;
// }).collect(Collectors.toList());
for (StoreInformation storeInfo : storeInfoList) {
if(Objects.equals(storeInfo.getStoreState(), StoreDailyStatus.CLOSE)){//过滤调已打烊的
continue;
}
StoreInfoDTO storeLocationInfo = new StoreInfoDTO();
BeanUtils.copyProperties(storeInfo, storeLocationInfo);
//计算距离
if(null != longitude && null != latitude){
double lon2 = storeInfo.getLongitude().doubleValue();
double lat2 = storeInfo.getLatitude().doubleValue();
Double distance = aMapWebApiCallService.getDistance(longitude,latitude,lon2,lat2);//计算两个坐标的距离
storeLocationInfo.setDistance(distance.intValue());
}
storeList.add(storeLocationInfo);
}
}
return storeList;
}