-
Notifications
You must be signed in to change notification settings - Fork 0
[KW-416] Kw 416/feat/dashboard summary api #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a1a7cd9
KW-416/feat: building enter log domain์ visit category ์ถ๊ฐ
midday2612 0924bce
KW-416/feat: dailyRetainedSnapshot ๋๋ฉ์ธ ์ค๊ณ
midday2612 8954094
KW-416/feat: ๋์๋ณด๋ ์๋ฅ์ธ์ api ์ค๊ณ
midday2612 d286dd5
KW-416/chore: redis key ttl ์ค์
midday2612 5f82553
KW-416/feat: daily snapshot ์ค์ผ์ค๋ง
midday2612 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/main/java/com/doubleo/passservice/domain/log/consumer/RetainedCountConsumer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package com.doubleo.passservice.domain.log.consumer; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
| import javax.annotation.PostConstruct; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.data.redis.connection.stream.*; | ||
| import org.springframework.data.redis.core.RedisTemplate; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| @Slf4j | ||
| public class RetainedCountConsumer { | ||
|
|
||
| private final RedisTemplate<String, String> redisTemplate; | ||
|
|
||
| private static final String STREAM_KEY = "building:enter:stream"; | ||
| private static final String GROUP = "retained-counter-group"; | ||
| private static final String CONSUMER = "retained-counter-consumer"; | ||
|
|
||
| @PostConstruct | ||
| public void createGroup() { | ||
| try { | ||
| redisTemplate.opsForStream().createGroup(STREAM_KEY, ReadOffset.latest(), GROUP); | ||
| } catch (Exception e) { | ||
| if (!e.getMessage().contains("BUSYGROUP")) { | ||
| log.error("Failed to create Redis Stream Group", e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Scheduled(fixedDelay = 300000) | ||
| public void consume() { | ||
| List<MapRecord<String, Object, Object>> records = | ||
| redisTemplate | ||
| .opsForStream() | ||
| .read( | ||
| Consumer.from(GROUP, CONSUMER), | ||
| StreamReadOptions.empty().count(10).block(Duration.ofSeconds(1)), | ||
| StreamOffset.create(STREAM_KEY, ReadOffset.lastConsumed())); | ||
|
|
||
| if (records == null) return; | ||
|
|
||
| for (MapRecord<String, Object, Object> record : records) { | ||
| try { | ||
| Map<String, String> map = | ||
| record.getValue().entrySet().stream() | ||
| .collect( | ||
| Collectors.toMap( | ||
| e -> e.getKey().toString(), | ||
| e -> e.getValue().toString())); | ||
|
|
||
| String tenantId = map.get("tenantId"); | ||
| String direction = map.get("direction"); | ||
| String visitCategory = map.get("visitCategory"); | ||
| String timestamp = map.get("timestamp"); | ||
|
|
||
| String date = timestamp.substring(0, 10); | ||
| String redisKey = | ||
| String.format( | ||
| "visit:count:%s:%s:%s:%s", | ||
| tenantId, date, visitCategory, direction); | ||
|
|
||
| redisTemplate.opsForValue().increment(redisKey); | ||
|
|
||
| redisTemplate.expire(redisKey, Duration.ofDays(1)); | ||
|
|
||
| redisTemplate.opsForStream().acknowledge(STREAM_KEY, GROUP, record.getId()); | ||
|
|
||
| } catch (Exception e) { | ||
| log.error("Error processing stream message", e); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...in/java/com/doubleo/passservice/domain/log/dto/request/CreateBuildingEnterLogRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| package com.doubleo.passservice.domain.log.dto.request; | ||
|
|
||
| import com.doubleo.passservice.domain.log.domain.Direction; | ||
| import com.doubleo.passservice.domain.pass.enums.VisitCategory; | ||
|
|
||
| public record CreateBuildingEnterLogRequest( | ||
| String tenantId, | ||
| Long buildingId, | ||
| Long memberId, | ||
| String memberName, | ||
| Long passId, | ||
| Direction direction) {} | ||
| Direction direction, | ||
| VisitCategory visitCategory) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,5 @@ | |
|
|
||
| public enum VisitCategory { | ||
| PATIENT, | ||
| GUARDIAN, | ||
| TEMPORARY | ||
| GUARDIAN | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/doubleo/passservice/domain/stats/domain/DailyRetainedSnapshot.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.doubleo.passservice.domain.stats.domain; | ||
|
|
||
| import com.doubleo.passservice.domain.common.model.BaseEntity; | ||
| import com.doubleo.passservice.domain.pass.enums.VisitCategory; | ||
| import jakarta.persistence.*; | ||
| import java.time.LocalDate; | ||
| import lombok.*; | ||
|
|
||
| @Entity | ||
| @Table( | ||
| name = "daily_retained_snapshot", | ||
| uniqueConstraints = { | ||
| @UniqueConstraint(columnNames = {"snapshot_date", "tenant_id", "visit_category"}) | ||
| }) | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public class DailyRetainedSnapshot extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "snapshot_id") | ||
| private Long id; | ||
|
|
||
| @Column(name = "snapshot_date", nullable = false) | ||
| private LocalDate snapshotDate; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "visit_category", nullable = false) | ||
| private VisitCategory visitCategory; | ||
|
|
||
| @Column(name = "retained_count", nullable = false) | ||
| private int retainedCount; | ||
|
|
||
| public DailyRetainedSnapshot( | ||
| String tenantId, | ||
| LocalDate snapshotDate, | ||
| VisitCategory visitCategory, | ||
| int retainedCount) { | ||
| this.tenantId = tenantId; | ||
| this.snapshotDate = snapshotDate; | ||
| this.visitCategory = visitCategory; | ||
| this.retainedCount = retainedCount; | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
...in/java/com/doubleo/passservice/domain/stats/dto/response/RetainedStatusInfoResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.doubleo.passservice.domain.stats.dto.response; | ||
|
|
||
| import com.doubleo.passservice.domain.pass.enums.VisitCategory; | ||
|
|
||
| public record RetainedStatusInfoResponse( | ||
| VisitCategory category, int entered, int exited, int remaining) {} |
13 changes: 13 additions & 0 deletions
13
...java/com/doubleo/passservice/domain/stats/repository/DailyRetainedSnapshotRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.doubleo.passservice.domain.stats.repository; | ||
|
|
||
| import com.doubleo.passservice.domain.pass.enums.VisitCategory; | ||
| import com.doubleo.passservice.domain.stats.domain.DailyRetainedSnapshot; | ||
| import java.time.LocalDate; | ||
| import java.util.Optional; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface DailyRetainedSnapshotRepository | ||
| extends JpaRepository<DailyRetainedSnapshot, Long> { | ||
| Optional<DailyRetainedSnapshot> findBySnapshotDateAndTenantIdAndVisitCategory( | ||
| LocalDate snapshotDate, String tenantId, VisitCategory visitCategory); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P4: ๋ฐฉ๋ฌธ์ ๊ตฌ๋ฌธ์ ์ํ enum ์ด๋ผ๋ฉด visitorCategory๋ ๊ด์ฐฎ์๋ณด์ ๋๋ค!