|
|
|
@ -7,6 +7,7 @@ import com.luoo.user.dto.store.StoreUpdateDto;
|
|
|
|
|
import com.luoo.user.pojo.QStore;
|
|
|
|
|
import com.luoo.user.pojo.Region;
|
|
|
|
|
import com.luoo.user.pojo.Store;
|
|
|
|
|
import com.luoo.user.pojo.UserInfo;
|
|
|
|
|
import com.luoo.user.vo.store.StoreAppVO;
|
|
|
|
|
import com.luoo.user.vo.store.StorePCVO;
|
|
|
|
|
import com.querydsl.core.BooleanBuilder;
|
|
|
|
@ -16,6 +17,7 @@ import enums.StoreEnums;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.geo.Distance;
|
|
|
|
|
import org.springframework.data.geo.Point;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
@ -47,12 +49,14 @@ public class StoreService {
|
|
|
|
|
|
|
|
|
|
private final RedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
|
|
private final UserInfoService userInfoService;
|
|
|
|
|
|
|
|
|
|
public StoreService(StoreDao storeDao, JPAQueryFactory jpaQueryFactory, RegionService regionService, RedisTemplate redisTemplate) {
|
|
|
|
|
public StoreService(StoreDao storeDao, JPAQueryFactory jpaQueryFactory, RegionService regionService, RedisTemplate redisTemplate, UserInfoService userInfoService) {
|
|
|
|
|
this.storeDao = storeDao;
|
|
|
|
|
this.jpaQueryFactory = jpaQueryFactory;
|
|
|
|
|
this.regionService = regionService;
|
|
|
|
|
this.redisTemplate = redisTemplate;
|
|
|
|
|
this.userInfoService = userInfoService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 增删改查
|
|
|
|
@ -93,18 +97,18 @@ public class StoreService {
|
|
|
|
|
Pageable pageable = PageRequest.of(page - 1, size);
|
|
|
|
|
|
|
|
|
|
List<StorePCVO> storeList = jpaQueryFactory.select(Projections.constructor(StorePCVO.class,
|
|
|
|
|
qStore.id,
|
|
|
|
|
qStore.name,
|
|
|
|
|
qStore.regionId,
|
|
|
|
|
qStore.address,
|
|
|
|
|
qStore.lng,
|
|
|
|
|
qStore.lat,
|
|
|
|
|
qStore.contact,
|
|
|
|
|
qStore.phone,
|
|
|
|
|
qStore.tel,
|
|
|
|
|
qStore.openingHours,
|
|
|
|
|
qStore.background,
|
|
|
|
|
qStore.description
|
|
|
|
|
qStore.id,
|
|
|
|
|
qStore.name,
|
|
|
|
|
qStore.regionId,
|
|
|
|
|
qStore.address,
|
|
|
|
|
qStore.lng,
|
|
|
|
|
qStore.lat,
|
|
|
|
|
qStore.contact,
|
|
|
|
|
qStore.phone,
|
|
|
|
|
qStore.tel,
|
|
|
|
|
qStore.openingHours,
|
|
|
|
|
qStore.background,
|
|
|
|
|
qStore.description
|
|
|
|
|
)).from(qStore)
|
|
|
|
|
.where(booleanBuilder)
|
|
|
|
|
.orderBy(qStore.createTime.desc())
|
|
|
|
@ -148,13 +152,20 @@ public class StoreService {
|
|
|
|
|
.orderBy(qStore.createTime.desc())
|
|
|
|
|
.fetch();
|
|
|
|
|
|
|
|
|
|
Double lng = Double.parseDouble(storeSearchDto.getLng());
|
|
|
|
|
Double lat = Double.parseDouble(storeSearchDto.getLat());
|
|
|
|
|
double lng = Double.parseDouble(storeSearchDto.getLng());
|
|
|
|
|
double lat = Double.parseDouble(storeSearchDto.getLat());
|
|
|
|
|
|
|
|
|
|
UUID uuid = UUID.randomUUID();
|
|
|
|
|
redisTemplate.opsForGeo().add(String.valueOf(uuid), new Point(lng, lat), "current");
|
|
|
|
|
|
|
|
|
|
storeList.forEach(store -> {
|
|
|
|
|
String contact = store.getContact();
|
|
|
|
|
if (StringUtils.isNotBlank(contact)) {
|
|
|
|
|
UserInfo byId = userInfoService.findById(contact);
|
|
|
|
|
store.setContactNickName(byId.getNickName());
|
|
|
|
|
store.setContactAvatar(byId.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redisTemplate.opsForGeo().add(String.valueOf(uuid),
|
|
|
|
|
new Point(Double.parseDouble(store.getLng()), Double.parseDouble(store.getLat())),
|
|
|
|
|
"location");
|
|
|
|
@ -176,12 +187,12 @@ public class StoreService {
|
|
|
|
|
});
|
|
|
|
|
redisTemplate.delete(String.valueOf(uuid));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return storeList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Double getDistance(String key, String currentLocaltion, String location) {
|
|
|
|
|
Double distance = redisTemplate.opsForGeo().distance(key, currentLocaltion, location, RedisGeoCommands.DistanceUnit.KILOMETERS).getValue();
|
|
|
|
|
return distance;
|
|
|
|
|
return redisTemplate.opsForGeo().distance(key, currentLocaltion, location, RedisGeoCommands.DistanceUnit.KILOMETERS).getValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|