redis缓存hset, hget, hPutAll 在业务场景中使用
package com.miniso.pintea.core.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.miniso.pintea.common.constant.redis.CoreRedisConstant;
import com.miniso.pintea.common.util.JsonUtil;
import com.miniso.pintea.core.constant.StoreDailyStatus;
import com.miniso.pintea.core.constant.StoreStatus;
import com.miniso.pintea.core.dto.*;
import com.miniso.pintea.core.entity.StoreInformation;
import com.miniso.pintea.core.mapper.StoreInformationMapper;
import com.miniso.pintea.core.service.StoreInformationService;
import com.miniso.pintea.core.third.service.AMapWebApiCallService;
import com.miniso.pintea.core.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.text.Collator;
import java.text.MessageFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* <p>
* 门店信息 服务实现类
* </p>
*
* @author chenqixuan
* @since 2021-02-24
*/
@Slf4j
@Service
public class StoreInformationServiceImpl implements StoreInformationService {
@Autowired
private RedisUtil redisUtil;
@Autowired
private StoreInformationMapper storeInformationMapper;
@Autowired
private AMapWebApiCallService aMapWebApiCallService;
@Value("${store.location.distance}")
private Integer storeDistance;
@Override
public List<StoreLocationInfo> getNearbyStoreList4Sf(NearbyStoreRequestDTO nearbyStoreRequestDto, String city,String district, int pageNum, int pageSize) {
List<StoreLocationInfo> storeLocationInfos = new ArrayList<>();
Integer limitDistance = 10000;
if(null != storeDistance){
limitDistance = storeDistance;//查附近多少公里的默认设置为10公里(单位米)
}
try {
city = city.endsWith("市") || city.endsWith("州") || city.endsWith("区") ? city.substring(0, city.length() - 1) : city;
Double longitudeN = nearbyStoreRequestDto.getReceiverLng();
Double latitudeN = nearbyStoreRequestDto.getReceiverLat();
List<StoreInformation> storeInfoList = getAllStoreInfoRedis();//从缓存取数据
if(null != storeInfoList && storeInfoList.size() > 0){
if(StringUtils.isNotBlank(city)){
//城市
String finalCity = city;
storeInfoList = storeInfoList.stream().filter(s-> s.getStoreCity() == null ? false : s.getStoreCity().contains(finalCity)).collect(Collectors.toList());
}
if(StringUtils.isNotBlank(district)){
//区域
storeInfoList = storeInfoList.stream().filter(s-> s.getStoreDistrict() == null ? false : s.getStoreDistrict().contains(district)).collect(Collectors.toList());
}
for (StoreInformation storeInfo : storeInfoList) {
StoreLocationInfo storeLocationInfo = new Store