Skip to content

Commit

Permalink
Merge pull request #129 from CoolPeace-yanolza/develop
Browse files Browse the repository at this point in the history
01-18 배포
  • Loading branch information
whdgns5059 authored Jan 18, 2024
2 parents 39f4d2a + e26abfe commit bbb570d
Show file tree
Hide file tree
Showing 38 changed files with 720 additions and 264 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ tasks.register("copyTextToSecurity") {
doLast {
def openapi3File = file(openapi3Path)
def securityFile = file("src/test/resources/security.yaml")
openapi3File.append securityFile.text
if (!openapi3File.text.contains("securitySchemes")) {
openapi3File.append securityFile.text
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
package com.coolpeace.domain.accommodation.entity;

import com.coolpeace.domain.accommodation.entity.type.AccommodationType;
import com.coolpeace.domain.coupon.entity.Coupon;
import com.coolpeace.domain.member.entity.Member;
import com.coolpeace.domain.room.entity.Room;
import com.coolpeace.global.common.BaseTimeEntity;
import jakarta.persistence.*;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -32,13 +43,19 @@ public class Accommodation extends BaseTimeEntity {

private String address;

@Enumerated(EnumType.STRING)
private AccommodationType accommodationType;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@OneToMany(mappedBy = "accommodation", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<Room> rooms = new ArrayList<>();

@OneToMany(mappedBy = "accommodation", fetch = FetchType.LAZY)
private List<Coupon> coupons = new ArrayList<>();

public Accommodation(Long id, String name, String address, Member member) {
this.id = id;
this.name = name;
Expand All @@ -58,4 +75,8 @@ public static Accommodation from(String name, Sido sido, Sigungu sigungu, String
return new Accommodation(name, sido, sigungu, address, member);
}

public void setType(AccommodationType accommodationType) {
this.accommodationType = accommodationType;
}

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

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum AccommodationType {

MOTEL,
HOTEL,
RESORT,
PENSION,
VILLA

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
import com.coolpeace.domain.batch.tasklet.MonthlySumTasklet;
import com.coolpeace.domain.statistics.service.MonthlyStatisticsService;
Expand All @@ -14,7 +15,6 @@
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.parameters.P;
import org.springframework.transaction.PlatformTransactionManager;

@Slf4j
Expand All @@ -34,6 +34,7 @@ public Job monthlyStatisticsJob(JobRepository jobRepository,
.next(monthlySumStep(jobRepository, platformTransactionManager))
.next(localCouponDownloadStep(jobRepository, platformTransactionManager))
.next(couponDownloadTop3Step(jobRepository,platformTransactionManager))
.next(localCouponAvgStep(jobRepository,platformTransactionManager))
.build();
}

Expand Down Expand Up @@ -80,4 +81,14 @@ public Step completeSettlementStep(JobRepository jobRepository,
.build();
}

@Bean
public Step localCouponAvgStep(JobRepository jobRepository,
PlatformTransactionManager platformTransactionManager) {
log.info("LocalCouponAvg step start");
return new StepBuilder("localCouponAvgStep", jobRepository)
.tasklet(new LocalCouponAvgTasklet(monthlyStatisticsService),
platformTransactionManager)
.listener(customStepListener)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.stereotype.Component;

@Slf4j
@RequiredArgsConstructor
@Transactional
@Component
public class CompleteSettlementTasklet implements Tasklet, StepExecutionListener {
private final MonthlyStatisticsService monthlyStatisticsService;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package com.coolpeace.domain.batch.tasklet;

import com.coolpeace.domain.statistics.service.DailyStatisticsService;
import com.coolpeace.domain.statistics.service.MonthlyStatisticsService;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.stereotype.Component;

@Slf4j
@RequiredArgsConstructor
@Transactional
@Component
public class CouponDownloadTop3Tasklet implements Tasklet, StepExecutionListener {

private final MonthlyStatisticsService monthlyStatisticsService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.stereotype.Component;

@Slf4j
@RequiredArgsConstructor
@Transactional
@Component
public class CouponTasklet implements Tasklet, StepExecutionListener {

private final DailyStatisticsService dailyStatisticsService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.coolpeace.domain.batch.tasklet;

import com.coolpeace.domain.statistics.service.DailyStatisticsService;
import com.coolpeace.domain.statistics.service.MonthlyStatisticsService;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.stereotype.Component;

@Slf4j
@RequiredArgsConstructor
@Component
public class LocalCouponAvgTasklet implements Tasklet, StepExecutionListener {

private final MonthlyStatisticsService monthlyStatisticsService;

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
log.info("지역 쿠폰 평균 갯수 Tasklet 시작");
monthlyStatisticsService.updateLocalCouponAvg();

return RepeatStatus.FINISHED;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

@Builder
public record CouponDailyResponse(
int conditionNum,
CouponDailyCondition condition,
List<String> couponTitles
) {
public static CouponDailyResponse from(CouponDailyCondition condition,List<String> couponTitles) {
return new CouponDailyResponse(condition, couponTitles);
public static CouponDailyResponse from(int conditionNum, CouponDailyCondition condition,List<String> couponTitles) {
return new CouponDailyResponse(conditionNum, condition, couponTitles);
}
public static CouponDailyResponse from(CouponDailyCondition condition) {
return new CouponDailyResponse(condition, Collections.emptyList());
public static CouponDailyResponse from(int conditionNum, CouponDailyCondition condition) {
return new CouponDailyResponse(conditionNum, condition, Collections.emptyList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.coolpeace.domain.accommodation.entity.Accommodation;
import com.coolpeace.domain.coupon.entity.Coupon;
import java.time.LocalDate;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CouponRepository extends JpaRepository<Coupon,Long>,CouponRepositoryCustom {
boolean existsByMemberIdAndCouponNumber(Long memberId, String couponNumber);
List<Coupon> findAllByAccommodation(Accommodation accommodation);
List<Coupon> findAllByExposureStartDateGreaterThanEqual(LocalDate localDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,23 @@ public class CouponQueryService {

private final CouponRepository couponRepository;

/* 메소드 복잡도를 낮추는 방법 고안 중 */
public CouponDailyResponse dailyReport(String jwtPrincipal, Long accommodationId) {
Long memberId = Long.valueOf(jwtPrincipal);
if (Boolean.TRUE.equals(couponRepository.noRegister(memberId, accommodationId))) {
return CouponDailyResponse.from(CouponDailyCondition.NO_REGISTER);
return CouponDailyResponse.from(1,CouponDailyCondition.NO_REGISTER);
}
List<Coupon> expiration3daysCoupons = couponRepository.expiration3days(memberId,
accommodationId);
if (!expiration3daysCoupons.isEmpty()) {
return CouponDailyResponse.from(CouponDailyCondition.EXPIRATION_3DAYS,
return CouponDailyResponse.from(3, CouponDailyCondition.EXPIRATION_3DAYS,
expiration3daysCoupons.stream().map(Coupon::getCouponTitle).toList());
}
if (Boolean.TRUE.equals(couponRepository.noExposure(memberId, accommodationId))) {
return CouponDailyResponse.from(CouponDailyCondition.NO_EXPOSURE);
return CouponDailyResponse.from(2, CouponDailyCondition.NO_EXPOSURE);
}

List<Coupon> exposureCoupons = couponRepository.exposureCoupons(memberId, accommodationId);
return CouponDailyResponse.from(CouponDailyCondition.NO_CONDITION,
return CouponDailyResponse.from(4, CouponDailyCondition.NO_CONDITION,
exposureCoupons.stream().map(Coupon::getCouponTitle).toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.coolpeace.domain.dashboard.service.DashboardService;
import com.coolpeace.global.jwt.security.JwtPrincipal;
import com.coolpeace.global.resolver.AuthJwtPrincipal;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -42,12 +41,20 @@ public ResponseEntity<?> dailyCouponReport(@PathVariable("accommodation_id") Lon
.dailyReport(jwtPrincipal.getMemberId(), accommodationId));
}

@GetMapping("/{accommodation_id}/coupons/download")
@GetMapping("/{accommodation_id}/coupons/local/download")
public ResponseEntity<?> downloadCouponTop3(@PathVariable("accommodation_id") Long accommodationId,
@AuthJwtPrincipal JwtPrincipal jwtPrincipal){
return ResponseEntity.ok().body(dashboardService
.downloadCouponTop3(jwtPrincipal.getMemberId(), accommodationId));
}

@GetMapping("/{accommodation_id}/coupons/local/count")
public ResponseEntity<?> couponCountAvg(@PathVariable("accommodation_id") Long accommodationId,
@AuthJwtPrincipal JwtPrincipal jwtPrincipal){
return ResponseEntity.ok().body(dashboardService
.couponCountAvg(jwtPrincipal.getMemberId(), accommodationId));
}

@GetMapping("/{accommodation_id}/reports/year")
public ResponseEntity<?> byYearCumulativeData(@PathVariable("accommodation_id") Long accommodationId,
@AuthJwtPrincipal JwtPrincipal jwtPrincipal,int year){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.coolpeace.domain.dashboard.dto.response;

public record CouponCountAvgResponse(
String address,
String couponAvg
) {
public static CouponCountAvgResponse from(int couponCount, int accommodationCount,
String address) {
String couponAvg = "0";
if(accommodationCount!=0){
couponAvg = String.format("%.1f", ((double)couponCount / accommodationCount));
}
return new CouponCountAvgResponse(address, couponAvg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@


import com.coolpeace.domain.accommodation.entity.Accommodation;
import com.coolpeace.domain.accommodation.entity.type.AccommodationType;
import com.coolpeace.domain.accommodation.exception.AccommodationNotFoundException;
import com.coolpeace.domain.accommodation.exception.AccommodationNotMatchMemberException;
import com.coolpeace.domain.accommodation.repository.AccommodationRepository;
import com.coolpeace.domain.coupon.repository.CouponRepository;
import com.coolpeace.domain.dashboard.dto.response.ByYearCumulativeDataResponse;
import com.coolpeace.domain.dashboard.dto.response.CouponCountAvgResponse;
import com.coolpeace.domain.dashboard.dto.response.CumulativeDataResponse;
import com.coolpeace.domain.dashboard.dto.response.MonthlyCouponDownloadResponse;
import com.coolpeace.domain.dashboard.dto.response.MonthlyDataLightResponse;
Expand All @@ -16,9 +17,12 @@
import com.coolpeace.domain.member.exception.MemberNotFoundException;
import com.coolpeace.domain.member.repository.MemberRepository;
import com.coolpeace.domain.statistics.entity.DailyStatistics;
import com.coolpeace.domain.statistics.entity.LocalCouponDownload;
import com.coolpeace.domain.statistics.entity.MonthlyStatistics;
import com.coolpeace.domain.statistics.exception.LocalCouponDownloadNotFoundException;
import com.coolpeace.domain.statistics.exception.MonthlyStatisticsNotFoundException;
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;
Expand All @@ -36,6 +40,7 @@ public class DashboardService {
private final DailyStatisticsRepository dailyStatisticsRepository;
private final MemberRepository memberRepository;
private final AccommodationRepository accommodationRepository;
private final LocalCouponDownloadRepository localCouponDownloadRepository;

public List<MonthlyDataResponse> monthlyData(String memberId, Long accommodationId) {
Accommodation accommodation = checkAccommodationMatchMember(memberId, accommodationId);
Expand Down Expand Up @@ -72,6 +77,17 @@ public MonthlyCouponDownloadResponse downloadCouponTop3(String memberId, Long ac

}

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

return getCouponCountAvgResponse(type, localCouponDownload, address);
}


public ByYearCumulativeDataResponse byYearCumulativeData(int year, String memberId, Long accommodationId) {
Accommodation accommodation = checkAccommodationMatchMember(memberId, accommodationId);
List<MonthlyStatistics> monthlyStatisticsList = monthlyStatisticsRepository
Expand Down Expand Up @@ -123,6 +139,20 @@ public Accommodation checkAccommodationMatchMember(String memberId, Long accommo
return accommodation;
}

private CouponCountAvgResponse getCouponCountAvgResponse(AccommodationType type,
LocalCouponDownload localCouponDownload, String address) {
if (type.equals(AccommodationType.MOTEL)) {
return CouponCountAvgResponse.from(localCouponDownload.getMotelCouponCount(),
localCouponDownload.getMotelAccommodationCount(), address);
}
if (type.equals(AccommodationType.PENSION) || (type.equals(AccommodationType.VILLA))) {
return CouponCountAvgResponse.from(localCouponDownload.getPensionAndVillaCouponCount(),
localCouponDownload.getPensionAndVillaAccommodationCount(), address);
}
return CouponCountAvgResponse.from(localCouponDownload.getHotelAndResortCouponCount(),
localCouponDownload.getHotelAndResortAccommodationCount(), address);
}

public int[] findLast6Months(int year, int month) {
if (month >= 7) return new int[]{year, month - 6, year, month - 1};
if (month == 1) return new int[]{year - 1, 7, year - 1, 12};
Expand Down
Loading

0 comments on commit bbb570d

Please sign in to comment.