store tag update
This commit is contained in:
parent
8ef8fa9e95
commit
5c8100ee02
@ -28,6 +28,8 @@ public class TagService implements TagUseCase {
|
|||||||
|
|
||||||
private final TagRepositoryPort tagRepositoryPort;
|
private final TagRepositoryPort tagRepositoryPort;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TopClickedTagResponse> getTopClickedTags() {
|
public List<TopClickedTagResponse> getTopClickedTags() {
|
||||||
log.info("가장 많이 클릭된 상위 5개 태그 조회 시작");
|
log.info("가장 많이 클릭된 상위 5개 태그 조회 시작");
|
||||||
|
|||||||
@ -0,0 +1,52 @@
|
|||||||
|
package com.ktds.hi.store.infra.gateway.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 매장별 태그 클릭 통계 엔티티
|
||||||
|
* 어떤 매장에서 어떤 태그가 얼마나 클릭되었는지 저장
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "store_tag_clicks")
|
||||||
|
@Getter
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class StoreTagClickEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "store_id", nullable = false)
|
||||||
|
private Long storeId;
|
||||||
|
|
||||||
|
@Column(name = "tag_id", nullable = false)
|
||||||
|
private Long tagId;
|
||||||
|
|
||||||
|
@Column(name = "click_count")
|
||||||
|
@Builder.Default
|
||||||
|
private Long clickCount = 0L;
|
||||||
|
|
||||||
|
@Column(name = "created_at")
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@Column(name = "updated_at")
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 클릭 수 증가
|
||||||
|
*/
|
||||||
|
public void incrementClickCount() {
|
||||||
|
this.clickCount = this.clickCount != null ? this.clickCount + 1 : 1L;
|
||||||
|
this.updatedAt = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
protected void onCreate() {
|
||||||
|
this.createdAt = LocalDateTime.now();
|
||||||
|
this.updatedAt = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
package com.ktds.hi.store.infra.gateway.repository;
|
||||||
|
|
||||||
|
|
||||||
|
import com.ktds.hi.store.infra.gateway.entity.StoreTagClickEntity;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface StoreTagClickJpaRepository extends JpaRepository<StoreTagClickEntity, Long> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 특정 매장의 가장 많이 클릭된 태그 5개 조회
|
||||||
|
*/
|
||||||
|
@Query("SELECT stc FROM StoreTagClickEntity stc WHERE stc.storeId = :storeId " +
|
||||||
|
"ORDER BY stc.clickCount DESC")
|
||||||
|
List<StoreTagClickEntity> findTop5TagsByStoreIdOrderByClickCountDesc(
|
||||||
|
@Param("storeId") Long storeId, PageRequest pageRequest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 전체 매장에서 가장 많이 클릭된 태그 5개 조회
|
||||||
|
*/
|
||||||
|
@Query("SELECT stc.tagId, SUM(stc.clickCount) as totalClicks " +
|
||||||
|
"FROM StoreTagClickEntity stc " +
|
||||||
|
"GROUP BY stc.tagId " +
|
||||||
|
"ORDER BY totalClicks DESC")
|
||||||
|
List<Object[]> findTop5TagsGloballyOrderByClickCount(PageRequest pageRequest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 매장별 태그별 클릭 통계 조회
|
||||||
|
*/
|
||||||
|
Optional<StoreTagClickEntity> findByStoreIdAndTagId(Long storeId, Long tagId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 특정 매장의 모든 태그 클릭 통계 조회
|
||||||
|
*/
|
||||||
|
List<StoreTagClickEntity> findByStoreIdOrderByClickCountDesc(Long storeId);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user