diff --git a/luoo_user/pom.xml b/luoo_user/pom.xml index e76306f..7c413bc 100644 --- a/luoo_user/pom.xml +++ b/luoo_user/pom.xml @@ -148,6 +148,12 @@ compile + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.4.5 + + com.querydsl diff --git a/luoo_user/src/main/java/com/luoo/user/controller/StoreController.java b/luoo_user/src/main/java/com/luoo/user/controller/StoreController.java index d40542c..4a6b69c 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/StoreController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/StoreController.java @@ -3,6 +3,8 @@ package com.luoo.user.controller; import annotation.GlobalInterceptor; import api.PageResult; import api.Result; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import com.luoo.user.dto.store.StoreAddDto; import com.luoo.user.dto.store.StoreSearchDto; import com.luoo.user.dto.store.StoreUpdateDto; @@ -45,13 +47,19 @@ public class StoreController { return Result.success(storeService.getList(storeSearchDto, page, size)); } - @PostMapping("/app/list") + @PostMapping("/app/list/{page}/{size}") @ApiOperation(value = "获取门店列表(APP)", notes = "获取门店列表") @GlobalInterceptor(checkAppUserLogin = true) - public Result> getStoreList( - @ApiParam(value = "查询内容") @RequestBody StoreSearchDto storeSearchDto + public Result> getStoreList( + @ApiParam(value = "查询内容") @RequestBody StoreSearchDto storeSearchDto, + @ApiParam(value = "页码", required = true) @PathVariable Integer page, + @ApiParam(value = "每页条数", required = true) @PathVariable Integer size ) { - return Result.success(storeService.getListForApp(storeSearchDto)); + PageHelper.startPage(page, size); + List listForApp = storeService.getListForApp(storeSearchDto); + PageInfo pageInfo = new PageInfo(listForApp); + PageResult result = new PageResult<>(pageInfo.getTotal(), listForApp); + return Result.success(result); } @GetMapping("/get") diff --git a/luoo_user/src/main/java/com/luoo/user/mapper/StoreMapper.java b/luoo_user/src/main/java/com/luoo/user/mapper/StoreMapper.java new file mode 100644 index 0000000..8be7340 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/mapper/StoreMapper.java @@ -0,0 +1,13 @@ +package com.luoo.user.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.luoo.user.dto.store.StoreSearchDto; +import com.luoo.user.pojo.Store; +import com.luoo.user.vo.store.StoreAppVO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface StoreMapper extends BaseMapper { + public List getListForApp(@Param("storeSearchDto") StoreSearchDto storeSearchDto); +} diff --git a/luoo_user/src/main/java/com/luoo/user/service/StoreService.java b/luoo_user/src/main/java/com/luoo/user/service/StoreService.java index e658d0e..dd0d697 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/StoreService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/StoreService.java @@ -4,6 +4,7 @@ import api.PageResult; import com.luoo.user.dao.StoreDao; import com.luoo.user.dto.store.StoreSearchDto; import com.luoo.user.dto.store.StoreUpdateDto; +import com.luoo.user.mapper.StoreMapper; import com.luoo.user.pojo.QStore; import com.luoo.user.pojo.Region; import com.luoo.user.pojo.Store; @@ -54,13 +55,16 @@ public class StoreService { private final RabbitTemplate rabbitTemplate; - public StoreService(StoreDao storeDao, JPAQueryFactory jpaQueryFactory, RegionService regionService, RedisTemplate redisTemplate, UserInfoService userInfoService, RabbitTemplate rabbitTemplate) { + private final StoreMapper storeMapper; + + public StoreService(StoreDao storeDao, JPAQueryFactory jpaQueryFactory, RegionService regionService, RedisTemplate redisTemplate, UserInfoService userInfoService, RabbitTemplate rabbitTemplate, StoreMapper storeMapper) { this.storeDao = storeDao; this.jpaQueryFactory = jpaQueryFactory; this.regionService = regionService; this.redisTemplate = redisTemplate; this.userInfoService = userInfoService; this.rabbitTemplate = rabbitTemplate; + this.storeMapper = storeMapper; } @Transactional(rollbackFor = Exception.class) @@ -188,67 +192,72 @@ public class StoreService { } public List getListForApp(StoreSearchDto storeSearchDto) { - BooleanBuilder booleanBuilder = new BooleanBuilder(); - QStore qStore = QStore.store; - // APP只查询合作中的门店 storeSearchDto.setStatus(StoreEnums.STORE_STATUS_COOPERATION.getCode()); - checkCondition(booleanBuilder, qStore, storeSearchDto); - - List storeList = jpaQueryFactory.select(Projections.constructor(StoreAppVO.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.visitCount, - qStore.introduction, - qStore.code - )).from(qStore) - .where(booleanBuilder) - .orderBy(qStore.createTime.desc()) - .fetch(); - - double lng = storeSearchDto.getLng() == null ? 0 : Double.parseDouble(storeSearchDto.getLng()); - double lat = storeSearchDto.getLng() == null ? 0 : 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 == null ? "" : byId.getNickName()); - store.setContactAvatar(byId == null ? "" : byId.getAvatar()); - } - - redisTemplate.opsForGeo().add(String.valueOf(uuid), - new Point(Double.parseDouble(store.getLng()), Double.parseDouble(store.getLat())), - "location"); - Double distance = getDistance(String.valueOf(uuid), "current", "location"); - log.info("distance:{}", distance); - store.setDistance(distance); - }); - - // 按StoreAppVO.getDistance从近到远排序,生成新的list - storeList.sort((o1, o2) -> { - if (o1.getDistance() == null) { - return 1; - } - if (o2.getDistance() == null) { - return -1; - } - return o1.getDistance().compareTo(o2.getDistance()); - }); - redisTemplate.delete(String.valueOf(uuid)); + List storeList = storeMapper.getListForApp(storeSearchDto); + + +// BooleanBuilder booleanBuilder = new BooleanBuilder(); +// QStore qStore = QStore.store; +// // APP只查询合作中的门店 +// storeSearchDto.setStatus(StoreEnums.STORE_STATUS_COOPERATION.getCode()); +// checkCondition(booleanBuilder, qStore, storeSearchDto); +// +// List storeList = jpaQueryFactory.select(Projections.constructor(StoreAppVO.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.visitCount, +// qStore.introduction, +// qStore.code +// )).from(qStore) +// .where(booleanBuilder) +// .orderBy(qStore.createTime.desc()) +// .fetch(); +// +// double lng = storeSearchDto.getLng() == null ? 0 : Double.parseDouble(storeSearchDto.getLng()); +// double lat = storeSearchDto.getLng() == null ? 0 : 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 == null ? "" : byId.getNickName()); +// store.setContactAvatar(byId == null ? "" : byId.getAvatar()); +// } +// +// redisTemplate.opsForGeo().add(String.valueOf(uuid), +// new Point(Double.parseDouble(store.getLng()), Double.parseDouble(store.getLat())), +// "location"); +// Double distance = getDistance(String.valueOf(uuid), "current", "location"); +// log.info("distance:{}", distance); +// store.setDistance(distance); +// +// }); +// +// // 按StoreAppVO.getDistance从近到远排序,生成新的list +// storeList.sort((o1, o2) -> { +// if (o1.getDistance() == null) { +// return 1; +// } +// if (o2.getDistance() == null) { +// return -1; +// } +// return o1.getDistance().compareTo(o2.getDistance()); +// }); +// redisTemplate.delete(String.valueOf(uuid)); return storeList; diff --git a/luoo_user/src/main/java/com/luoo/user/vo/store/StoreAppVO.java b/luoo_user/src/main/java/com/luoo/user/vo/store/StoreAppVO.java index 940d345..171975d 100644 --- a/luoo_user/src/main/java/com/luoo/user/vo/store/StoreAppVO.java +++ b/luoo_user/src/main/java/com/luoo/user/vo/store/StoreAppVO.java @@ -81,7 +81,7 @@ public class StoreAppVO implements Serializable { public StoreAppVO() { } - public StoreAppVO(String id, String name, Integer regionId, String address, String lng, String lat, String contact, String phone, String tel, String openingHours, String background, String description, Region region, Double distance, Integer visitCount, String introduction, String code) { + public StoreAppVO(String id, String name, Integer regionId, String address, String lng, String lat, String contact, String phone, String tel, String openingHours, String background, String description, Integer visitCount, String introduction, String code) { this.id = id; this.name = name; this.regionId = regionId; @@ -94,8 +94,6 @@ public class StoreAppVO implements Serializable { this.openingHours = openingHours; this.background = background; this.description = description; - this.region = region; - this.distance = distance; this.visitCount = visitCount; this.introduction = introduction; this.code = code; diff --git a/luoo_user/src/main/resources/mapper/StoreMapper.xml b/luoo_user/src/main/resources/mapper/StoreMapper.xml new file mode 100644 index 0000000..2e99839 --- /dev/null +++ b/luoo_user/src/main/resources/mapper/StoreMapper.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file