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 4e8b41b..d40542c 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 @@ -61,6 +61,13 @@ public class StoreController { return Result.success(storeService.getOne(id)); } + @GetMapping("/app/get") + @GlobalInterceptor(checkAppUserLogin = true) + @ApiOperation(value = "获取门店详情(APP)", notes = "获取门店详情") + public Result getStoreForApp(String id) { + return Result.success(storeService.getStoreForApp(id)); + } + @PostMapping("/add") @GlobalInterceptor(checkAdminLogin = true) @ApiOperation(value = "添加门店(PC)", notes = "添加门店") diff --git a/luoo_user/src/main/java/com/luoo/user/dao/StoreDao.java b/luoo_user/src/main/java/com/luoo/user/dao/StoreDao.java index ea5e473..eb24dea 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/StoreDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/StoreDao.java @@ -3,7 +3,13 @@ package com.luoo.user.dao; import com.luoo.user.pojo.Store; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; -public interface StoreDao extends JpaRepository , JpaSpecificationExecutor { +public interface StoreDao extends JpaRepository, JpaSpecificationExecutor { + + @Modifying + @Query(value = "update tb_store set visit_count = visit_count + 1 where id = ?1", nativeQuery = true) + public void addVisitCount(String id); } \ No newline at end of file diff --git a/luoo_user/src/main/java/com/luoo/user/listener/StoreVisitCountListener.java b/luoo_user/src/main/java/com/luoo/user/listener/StoreVisitCountListener.java new file mode 100644 index 0000000..13521af --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/listener/StoreVisitCountListener.java @@ -0,0 +1,29 @@ +package com.luoo.user.listener; + +import com.luoo.user.service.StoreService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.rabbit.annotation.RabbitHandler; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @program: luoo_parent + * @description: 门店浏览次数记录 + * @author: yawei.huang + * @create: 2024-08-22 08:43 + **/ +@Component +@RabbitListener(queues = "store_visit") +@Slf4j +public class StoreVisitCountListener { + + @Autowired + private StoreService storeService; + + @RabbitHandler + public void executeDraw(String id) { + log.info("store_visit-id:{}", id); + storeService.addVisitCount(id); + } +} diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/Store.java b/luoo_user/src/main/java/com/luoo/user/pojo/Store.java index 7988bc5..4e7f95b 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/Store.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/Store.java @@ -79,4 +79,8 @@ public class Store extends JPABasePojo { @Column(name = "status") @ApiModelProperty(value = "门店状态 1-合作中 2-停止合作") private Integer status; + + @Column(name = "visit_count") + @ApiModelProperty(value = "门店访问量") + private Integer visitCount; } \ No newline at end of file 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 368b657..80db7e5 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 @@ -16,6 +16,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import enums.StoreEnums; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.geo.Distance; @@ -51,12 +52,15 @@ public class StoreService { private final UserInfoService userInfoService; - public StoreService(StoreDao storeDao, JPAQueryFactory jpaQueryFactory, RegionService regionService, RedisTemplate redisTemplate, UserInfoService userInfoService) { + private final RabbitTemplate rabbitTemplate; + + public StoreService(StoreDao storeDao, JPAQueryFactory jpaQueryFactory, RegionService regionService, RedisTemplate redisTemplate, UserInfoService userInfoService, RabbitTemplate rabbitTemplate) { this.storeDao = storeDao; this.jpaQueryFactory = jpaQueryFactory; this.regionService = regionService; this.redisTemplate = redisTemplate; this.userInfoService = userInfoService; + this.rabbitTemplate = rabbitTemplate; } @Transactional(rollbackFor = Exception.class) @@ -94,6 +98,39 @@ public class StoreService { return storeDao.findById(id).orElse(null); } + public StoreAppVO getStoreForApp(String id) { + + QStore qStore = QStore.store; + + rabbitTemplate.convertAndSend("store_visit", id); + + // 只显示合作中的门店 + return 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 + )).from(qStore) + .where( + (qStore.id.eq(id)) + .and(qStore.status.eq(StoreEnums.STORE_STATUS_COOPERATION.getCode()))) + .fetchOne(); + } + + @Transactional(rollbackFor = Exception.class) + public void addVisitCount(String id) { + storeDao.addVisitCount(id); + } + // 列表页-PC public PageResult getList(StoreSearchDto storeSearchDto, Integer page, Integer size) { BooleanBuilder booleanBuilder = new BooleanBuilder(); 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 5549815..14b6b11 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 @@ -69,10 +69,13 @@ public class StoreAppVO implements Serializable { @ApiModelProperty(value = "距离") private Double distance; + @ApiModelProperty(value = "门店访问量") + private Integer visitCount; + 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) { + 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) { this.id = id; this.name = name; this.regionId = regionId; @@ -85,5 +88,6 @@ public class StoreAppVO implements Serializable { this.openingHours = openingHours; this.background = background; this.description = description; + this.visitCount = visitCount; } } \ No newline at end of file diff --git a/luoo_user/src/main/java/com/luoo/user/vo/store/StorePCVO.java b/luoo_user/src/main/java/com/luoo/user/vo/store/StorePCVO.java index a4087bd..4000397 100644 --- a/luoo_user/src/main/java/com/luoo/user/vo/store/StorePCVO.java +++ b/luoo_user/src/main/java/com/luoo/user/vo/store/StorePCVO.java @@ -68,6 +68,9 @@ public class StorePCVO implements Serializable { @ApiModelProperty(value = "门店状态 1-合作中 2-停止合作") private Integer status; + @ApiModelProperty(value = "门店访问量") + private Integer visitCount; + @Transient Region region; @@ -75,7 +78,7 @@ public class StorePCVO implements Serializable { public StorePCVO() { } - public StorePCVO(String id, String name, Integer regionId, String address, String lng, String lat, String contact, String phone, String tel, String openingHours, String background, String description, LocalDateTime createTime, Integer status) { + public StorePCVO(String id, String name, Integer regionId, String address, String lng, String lat, String contact, String phone, String tel, String openingHours, String background, String description, LocalDateTime createTime, Integer status, Integer visitCount) { this.id = id; this.name = name; this.regionId = regionId; @@ -90,5 +93,6 @@ public class StorePCVO implements Serializable { this.description = description; this.createTime = createTime; this.status = status; + this.visitCount = visitCount; } } \ No newline at end of file diff --git a/luoo_user/src/main/resources/sql/20240815.sql b/luoo_user/src/main/resources/sql/20240815.sql index 7aa6997..cc57dfd 100644 --- a/luoo_user/src/main/resources/sql/20240815.sql +++ b/luoo_user/src/main/resources/sql/20240815.sql @@ -2,4 +2,11 @@ alter table tb_task_point add action varchar(50) null comment 'APP动作'; alter table tb_task_point - add task_point_id varchar(20) null comment 'tb_task_point表id'; \ No newline at end of file + add task_point_id varchar(20) null comment 'tb_task_point表id'; + +alter table tb_store + add visit_count int null comment '浏览次数'; + +alter table tb_store + alter column visit_count set default 0; +