Skip to content

Commit

Permalink
Merge pull request #134 from CoolPeace-yanolza/develop
Browse files Browse the repository at this point in the history
1.18 배포
  • Loading branch information
KwonJuHwan authored Jan 18, 2024
2 parents bbb570d + 892f534 commit 9028167
Show file tree
Hide file tree
Showing 37 changed files with 332 additions and 186 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.coolpeace.domain.batch.job;

import com.coolpeace.domain.batch.tasklet.CompleteSettlementTasklet;
import com.coolpeace.domain.batch.tasklet.CouponDownloadTop3Tasklet;
import com.coolpeace.domain.batch.tasklet.LocalCouponAvgTasklet;
import com.coolpeace.domain.batch.tasklet.LocalCouponDownloadTasklet;
Expand Down Expand Up @@ -30,8 +29,7 @@ public Job monthlyStatisticsJob(JobRepository jobRepository,
PlatformTransactionManager platformTransactionManager) {
log.info("월간 통계 집계 시작");
return new JobBuilder("monthlyStatisticsJob", jobRepository)
.start(completeSettlementStep(jobRepository,platformTransactionManager))
.next(monthlySumStep(jobRepository, platformTransactionManager))
.start(monthlySumStep(jobRepository, platformTransactionManager))
.next(localCouponDownloadStep(jobRepository, platformTransactionManager))
.next(couponDownloadTop3Step(jobRepository,platformTransactionManager))
.next(localCouponAvgStep(jobRepository,platformTransactionManager))
Expand Down Expand Up @@ -70,17 +68,6 @@ public Step couponDownloadTop3Step(JobRepository jobRepository,
.build();
}

@Bean
public Step completeSettlementStep(JobRepository jobRepository,
PlatformTransactionManager platformTransactionManager) {
log.info("completeSettlement step start");
return new StepBuilder("completeSettlementStep", jobRepository)
.tasklet(new CompleteSettlementTasklet(monthlyStatisticsService),
platformTransactionManager)
.listener(customStepListener)
.build();
}

@Bean
public Step localCouponAvgStep(JobRepository jobRepository,
PlatformTransactionManager platformTransactionManager) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CouponDownloadTop3Tasklet implements Tasklet, StepExecutionListener
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
log.info("쿠폰 Tasklet 시작");
monthlyStatisticsService.updateCouponDownloadTop3();
monthlyStatisticsService.updateCouponDownloadTop3(0,0);

return RepeatStatus.FINISHED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CouponTasklet implements Tasklet, StepExecutionListener {
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
log.info("쿠폰 Tasklet 시작");
dailyStatisticsService.updateCoupon();
dailyStatisticsService.updateCoupon(0,0,0);

return RepeatStatus.FINISHED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class LocalCouponAvgTasklet implements Tasklet, StepExecutionListener {
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
log.info("지역 쿠폰 평균 갯수 Tasklet 시작");
monthlyStatisticsService.updateLocalCouponAvg();
monthlyStatisticsService.updateLocalCouponAvg(0,0);

return RepeatStatus.FINISHED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class LocalCouponDownloadTasklet implements Tasklet, StepExecutionListene
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
log.info("지역 쿠폰 다운로드 Tasklet 시작");
monthlyStatisticsService.updateLocalCouponDownload();
monthlyStatisticsService.updateLocalCouponDownload(0,0);
return RepeatStatus.FINISHED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class MonthlySumTasklet implements Tasklet, StepExecutionListener {
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
log.info("일간 통계 합 Tasklet 시작");
monthlyStatisticsService.updateMonthlySum();
monthlyStatisticsService.updateMonthlySum(0,0);

return RepeatStatus.FINISHED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ReservationTasklet implements Tasklet, StepExecutionListener {
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
log.info("매출 Tasklet 시작");
dailyStatisticsService.updateSales();
dailyStatisticsService.updateSales(0,0,0);

return RepeatStatus.FINISHED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class SettlementTasklet implements Tasklet, StepExecutionListener {
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
log.info("정산 Tasklet 시작");
dailyStatisticsService.updateSettlement();
dailyStatisticsService.updateSettlement(0,0,0);

return RepeatStatus.FINISHED;
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/coolpeace/domain/coupon/entity/Coupon.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ private void updateCouponStatusByExposureDate() {
if (this.betweenExposureDate(LocalDate.now())) {
this.changeCouponStatus(CouponStatusType.EXPOSURE_ON);
} else {
this.changeCouponStatus(CouponStatusType.EXPOSURE_WAIT);
if (LocalDate.now().isAfter(exposureEndDate)) {
this.changeCouponStatus(CouponStatusType.EXPOSURE_END);
} else {
this.changeCouponStatus(CouponStatusType.EXPOSURE_WAIT);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

public interface CouponRepository extends JpaRepository<Coupon,Long>,CouponRepositoryCustom {
boolean existsByMemberIdAndCouponNumber(Long memberId, String couponNumber);
List<Coupon> findAllByAccommodation(Accommodation accommodation);
List<Coupon> findAllByExposureStartDateGreaterThanEqual(LocalDate localDate);
List<Coupon> findAllByAccommodationAndExposureStartDateGreaterThanEqual(Accommodation accommodation,LocalDate localDate);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.coolpeace.domain.coupon.repository;


import com.coolpeace.domain.accommodation.entity.Accommodation;
import com.coolpeace.domain.coupon.dto.request.SearchCouponParams;
import com.coolpeace.domain.coupon.entity.Coupon;
import com.coolpeace.domain.coupon.entity.type.CouponStatusType;
import java.time.LocalDate;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;

Expand All @@ -29,5 +31,6 @@ public interface CouponRepositoryCustom {

List<Coupon> expiration3days(Long memberId,Long accommodationId);

List<Coupon> findAllByExposureDate(Accommodation accommodation, LocalDate localDate);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.coolpeace.domain.coupon.repository;

import com.coolpeace.domain.accommodation.entity.Accommodation;
import com.coolpeace.domain.coupon.dto.request.SearchCouponParams;
import com.coolpeace.domain.coupon.entity.Coupon;
import com.coolpeace.domain.coupon.entity.type.CouponStatusType;
Expand Down Expand Up @@ -96,9 +97,10 @@ public List<Coupon> findRecentCouponByMemberId(Long memberId) {
return jpaQueryFactory.selectFrom(coupon)
.leftJoin(coupon.couponRooms, couponRooms).fetchJoin()
.leftJoin(couponRooms.room, room).fetchJoin()
.where(coupon.member.id.eq(memberId))
.where(coupon.member.id.eq(memberId),
coupon.couponStatus.eq(CouponStatusType.EXPOSURE_END))
.orderBy(coupon.createdAt.desc())
.limit(4)
.limit(6)
.fetch();
}

Expand Down Expand Up @@ -151,4 +153,12 @@ public List<Coupon> expiration3days(Long memberId, Long accommodationId) {
.and(coupon.exposureEndDate.before(LocalDate.now().plusDays(3))))
.fetch();
}

@Override
public List<Coupon> findAllByExposureDate(Accommodation accommodation, LocalDate localDate) {
return jpaQueryFactory.selectFrom(coupon)
.where(coupon.accommodation.eq(accommodation)
.and(coupon.exposureStartDate.before(localDate))
.and(coupon.exposureEndDate.after(localDate))).fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


Expand Down Expand Up @@ -57,7 +58,8 @@ public ResponseEntity<?> couponCountAvg(@PathVariable("accommodation_id") Long a

@GetMapping("/{accommodation_id}/reports/year")
public ResponseEntity<?> byYearCumulativeData(@PathVariable("accommodation_id") Long accommodationId,
@AuthJwtPrincipal JwtPrincipal jwtPrincipal,int year){
@AuthJwtPrincipal JwtPrincipal jwtPrincipal,
@RequestParam int year){
return ResponseEntity.ok().body(dashboardService
.byYearCumulativeData(year, jwtPrincipal.getMemberId(), accommodationId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.coolpeace.domain.member.entity.Member;
import com.coolpeace.domain.member.exception.MemberNotFoundException;
import com.coolpeace.domain.member.repository.MemberRepository;
import com.coolpeace.domain.settlement.entity.SearchDate;
import com.coolpeace.domain.statistics.entity.DailyStatistics;
import com.coolpeace.domain.statistics.entity.LocalCouponDownload;
import com.coolpeace.domain.statistics.entity.MonthlyStatistics;
Expand All @@ -24,8 +25,6 @@
import com.coolpeace.domain.statistics.repository.DailyStatisticsRepository;
import com.coolpeace.domain.statistics.repository.LocalCouponDownloadRepository;
import com.coolpeace.domain.statistics.repository.MonthlyStatisticsRepository;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -44,9 +43,9 @@ public class DashboardService {

public List<MonthlyDataResponse> monthlyData(String memberId, Long accommodationId) {
Accommodation accommodation = checkAccommodationMatchMember(memberId, accommodationId);
SearchDate searchDate = SearchDate.getsearchDate();

int[] last6Months = findLast6Months(LocalDate.now().getYear(),
LocalDate.now().getMonth().getValue());
int[] last6Months = findLast6Months(searchDate.year(), searchDate.month());
List<MonthlyStatistics> last6monthsMonthlyStatistics =
monthlyStatisticsRepository.findLast6monthsMonthlyStatistics
(accommodation, last6Months[0], last6Months[1], last6Months[2], last6Months[3]);
Expand All @@ -67,10 +66,11 @@ public WeeklyCouponResponse weeklyCoupon(String memberId, Long accommodationId)

public MonthlyCouponDownloadResponse downloadCouponTop3(String memberId, Long accommodationId) {
Accommodation accommodation = checkAccommodationMatchMember(memberId, accommodationId);
SearchDate searchDate = SearchDate.getsearchDate();

MonthlyStatistics monthlyStatistics = monthlyStatisticsRepository
.findByAccommodationAndStatisticsYearAndStatisticsMonth(accommodation,
LocalDateTime.now().getYear(), LocalDateTime.now().getMonth().getValue())
.findByAccommodationAndStatisticsYearAndStatisticsMonth(accommodation, searchDate.year(),
searchDate.month())
.orElseThrow(MonthlyStatisticsNotFoundException::new);

return MonthlyCouponDownloadResponse.from(monthlyStatistics.getLocalCouponDownload());
Expand All @@ -79,10 +79,13 @@ public MonthlyCouponDownloadResponse downloadCouponTop3(String memberId, Long ac

public CouponCountAvgResponse couponCountAvg(String memberId,Long accommodationId) {
Accommodation accommodation = checkAccommodationMatchMember(memberId, accommodationId);
SearchDate searchDate = SearchDate.getsearchDate();
String address = accommodation.getSigungu().getName();
AccommodationType type = accommodation.getAccommodationType();
LocalCouponDownload localCouponDownload = localCouponDownloadRepository
.findByRegion(address).orElseThrow(LocalCouponDownloadNotFoundException::new);
.findByRegionAndStatisticsYearAndStatisticsMonth
(address,searchDate.year(), searchDate.month())
.orElseThrow(LocalCouponDownloadNotFoundException::new);

return getCouponCountAvgResponse(type, localCouponDownload, address);
}
Expand Down Expand Up @@ -153,9 +156,9 @@ private CouponCountAvgResponse getCouponCountAvgResponse(AccommodationType type
localCouponDownload.getHotelAndResortAccommodationCount(), address);
}

public int[] findLast6Months(int year, int month) {
if (month >= 7) return new int[]{year, month - 6, year, month - 1};
private int[] findLast6Months(int year, int month) {
if (month >= 7) return new int[]{year, month - 6, year, month};
if (month == 1) return new int[]{year - 1, 7, year - 1, 12};
return new int[]{year - 1, 6 + month, year, month - 1};
return new int[]{year - 1, 6 + month, year, month};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
import java.util.List;

public interface ReservationRepositoryCustom {
List<Reservation> findByAccommodation(Accommodation accommodation);
List<Reservation> findByAccommodation(int year, int month, int day, Accommodation accommodation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.coolpeace.domain.room.entity.RoomReservation;
import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

public class ReservationRepositoryImpl implements ReservationRepositoryCustom{
Expand All @@ -18,10 +20,14 @@ public ReservationRepositoryImpl(EntityManager entityManager) {
}

@Override
public List<Reservation> findByAccommodation(Accommodation accommodation) {
public List<Reservation> findByAccommodation(int year, int month, int day,Accommodation accommodation) {
LocalDateTime startDate = LocalDateTime.of(year, month, day, 0,0);
LocalDateTime endDate = LocalDateTime.of(year, month, day, 23,59);

return jpaQueryFactory.selectFrom(roomReservation)
.where(roomReservation.room.accommodation.eq(accommodation)).fetch().stream()
.where(roomReservation.room.accommodation.eq(accommodation)
.and(roomReservation.reservation.startDate
.between(startDate,endDate))).fetch().stream()
.map(RoomReservation::getReservation).toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import com.coolpeace.global.jwt.security.JwtPrincipal;
import com.coolpeace.global.resolver.AuthJwtPrincipal;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -33,7 +32,7 @@ public ResponseEntity<?> searchSettlement(
@PathVariable("accommodation_id") Long accommodationId,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int pageSize,
SearchSettlementParams searchSettlementParams,
@Valid SearchSettlementParams searchSettlementParams,
@AuthJwtPrincipal JwtPrincipal jwtPrincipal) {
return ResponseEntity.ok().body(settlementService.searchSettlement
(jwtPrincipal.getMemberId(), accommodationId, searchSettlementParams,page,pageSize));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

import com.coolpeace.domain.settlement.repository.OrderBy;


public record SearchSettlementParams(
String startDate,
String endDate,
OrderBy orderBy
String start,
String end,
OrderBy order
){

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.coolpeace.domain.settlement.entity;

import java.time.LocalDate;

public record SearchDate(int year, int month) {
public static SearchDate getsearchDate() {
LocalDate localDate = LocalDate.now().minusMonths(1);
int year = localDate.getYear();
int month= localDate.getMonthValue();
return new SearchDate(year, month);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.coolpeace.domain.settlement.repository;

public enum OrderBy {
COUPON_USE_DATE("couponUseDate"),
SUM_PRICE("sumPrice"),
COMPLETE_AT("completeAt"),
COUPON_COUNT("couponCount");
COUPON_USE_DATE("쿠폰 사용일"),
SUM_PRICE("합산 정산 금액"),
COMPLETE_AT("정산 완료일"),
COUPON_COUNT("사용 건수");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import com.coolpeace.domain.accommodation.entity.Accommodation;
import com.coolpeace.domain.settlement.entity.Settlement;
import java.time.LocalDate;
import java.util.List;

public interface SettlementRepositoryCustom {
List<Settlement> findAllByAccommodationForDailyUpdate(Accommodation accommodation);
List<Settlement> findAllByAccommodationForDailyUpdate(LocalDate localDate,Accommodation accommodation);
}
Loading

0 comments on commit 9028167

Please sign in to comment.