Skip to content

Commit

Permalink
Merge pull request #229 from SKY-HORSE-MAN-POWER/develop
Browse files Browse the repository at this point in the history
[DEPLOYMENT] 경매 종료 시간 도달 시, 마지막 라운드 여부 추가
  • Loading branch information
chanchanwoong authored Jun 26, 2024
2 parents c79fa57 + 96c355e commit 648e250
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
17 changes: 16 additions & 1 deletion src/main/java/com/skyhorsemanpower/auction/domain/RoundInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ public class RoundInfo {
private Long numberOfParticipants;
private Long leftNumberOfParticipants;
private LocalDateTime createdAt;
private LocalDateTime auctionEndTime;
private Boolean isLastRound;

@Builder
public RoundInfo(String auctionUuid, Integer round, LocalDateTime roundStartTime, LocalDateTime roundEndTime,
BigDecimal incrementUnit, BigDecimal price, Boolean isActive, Long numberOfParticipants,
Long leftNumberOfParticipants, LocalDateTime createdAt) {
Long leftNumberOfParticipants, LocalDateTime createdAt,
LocalDateTime auctionEndTime, Boolean isLastRound) {
this.auctionUuid = auctionUuid;
this.round = round;
this.roundStartTime = roundStartTime;
Expand All @@ -45,13 +48,19 @@ public RoundInfo(String auctionUuid, Integer round, LocalDateTime roundStartTime
this.numberOfParticipants = numberOfParticipants;
this.leftNumberOfParticipants = leftNumberOfParticipants;
this.createdAt = LocalDateTime.now();
this.auctionEndTime = auctionEndTime;
this.isLastRound = isLastRound;
}

public static RoundInfo nextRoundUpdate(RoundInfo roundInfo) {
Integer nextRound = roundInfo.getRound() + 1;
LocalDateTime nextRoundStartTime = LocalDateTime.now().plusSeconds(StandbyTimeEnum.SECONDS_15.getSecond());
LocalDateTime nextRoundEndTime = nextRoundStartTime.plusSeconds(RoundTimeEnum.SECONDS_60.getSecond());
BigDecimal nextPrice = roundInfo.getPrice().add(roundInfo.getIncrementUnit());
LocalDateTime auctionEndTime = roundInfo.getAuctionEndTime();

// nextRoundStartTime <= auctionEndTime <= nextRoundEndTime 인 경우 다음 라운드가 마지막 라운드
boolean isLastRound = nextRoundStartTime.isBefore(auctionEndTime) && auctionEndTime.isBefore(nextRoundEndTime);

return RoundInfo.builder()
.auctionUuid(roundInfo.getAuctionUuid())
Expand All @@ -63,6 +72,8 @@ public static RoundInfo nextRoundUpdate(RoundInfo roundInfo) {
.isActive(false) // 대기 상태로 변경
.numberOfParticipants(roundInfo.getNumberOfParticipants())
.leftNumberOfParticipants(roundInfo.getNumberOfParticipants())
.auctionEndTime(roundInfo.getAuctionEndTime())
.isLastRound(isLastRound)
.build();
}

Expand All @@ -79,6 +90,8 @@ public static RoundInfo currentRoundUpdate(RoundInfo roundInfo) {
.isActive(true)
.numberOfParticipants(roundInfo.getNumberOfParticipants())
.leftNumberOfParticipants(nextNumberOfParticipants)
.auctionEndTime(roundInfo.getAuctionEndTime())
.isLastRound(roundInfo.getIsLastRound())
.build();
}

Expand All @@ -93,6 +106,8 @@ public static RoundInfo setIsActiveTrue(RoundInfo roundInfo) {
.isActive(true)
.numberOfParticipants(roundInfo.getNumberOfParticipants())
.leftNumberOfParticipants(roundInfo.getLeftNumberOfParticipants())
.auctionEndTime(roundInfo.getAuctionEndTime())
.isLastRound(roundInfo.getIsLastRound())
.createdAt(LocalDateTime.now())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.skyhorsemanpower.auction.domain.RoundInfo;
import com.skyhorsemanpower.auction.kafka.data.dto.InitialAuctionDto;
import com.skyhorsemanpower.auction.repository.RoundInfoRepository;
import com.skyhorsemanpower.auction.status.AuctionTimeEnum;
import com.skyhorsemanpower.auction.status.RoundTimeEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -56,6 +57,7 @@ private void initialRoundInfo(InitialAuctionDto initialAuctionDto) {
// Instant 타입을 LocalDateTime 변환
LocalDateTime roundStartTime = DateTimeConverter.
instantToLocalDateTime(initialAuctionDto.getAuctionStartTime());
LocalDateTime auctionEndTime = roundStartTime.plusMinutes(AuctionTimeEnum.MINUTES_120.getMinute());

RoundInfo roundinfo = RoundInfo.builder()
.auctionUuid(initialAuctionDto.getAuctionUuid())
Expand All @@ -68,6 +70,8 @@ private void initialRoundInfo(InitialAuctionDto initialAuctionDto) {
.numberOfParticipants((long) initialAuctionDto.getNumberOfEventParticipants())
.leftNumberOfParticipants((long) initialAuctionDto.getNumberOfEventParticipants())
.createdAt(LocalDateTime.now())
.auctionEndTime(auctionEndTime)
.isLastRound(false)
.build();

log.info("Initial round_info >>> {}", roundinfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ public KafkaTemplate<String, Object> kafkaTemplate() {
@Bean
public NewTopic auctionCloseTopic() {
return TopicBuilder.name(Topics.Constant.AUCTION_CLOSE)
.partitions(1)
.replicas(1)
.partitions(2)
.replicas(2)
.config(TopicConfig.RETENTION_MS_CONFIG, String.valueOf(172800000))
.build();
}

@Bean
public NewTopic alarmTopic() {
return TopicBuilder.name(Topics.Constant.ALARM)
.partitions(1)
.replicas(1)
.partitions(2)
.replicas(2)
.config(TopicConfig.RETENTION_MS_CONFIG, String.valueOf(172800000))
.build();
}
Expand Down

0 comments on commit 648e250

Please sign in to comment.