Skip to content

Commit

Permalink
Merge pull request #108 from CoolPeace-yanolza/develop
Browse files Browse the repository at this point in the history
01-12 오전 배포
  • Loading branch information
whdgns5059 authored Jan 12, 2024
2 parents 46e9608 + f111098 commit 0b48831
Show file tree
Hide file tree
Showing 24 changed files with 371 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface AccommodationRepository extends JpaRepository<Accommodation, Long> {
public interface AccommodationRepository extends JpaRepository<Accommodation, Long>,AccommodationRepositoryCustom{

List<Accommodation> findAllByMember(Member member);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.coolpeace.domain.accommodation.repository;

import com.coolpeace.domain.accommodation.entity.Accommodation;
import java.util.List;

public interface AccommodationRepositoryCustom {

List<Accommodation> findAllBySigunguName(String name);

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

import static com.coolpeace.domain.accommodation.entity.QAccommodation.accommodation;

import com.coolpeace.domain.accommodation.entity.Accommodation;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;

public class AccommodationRepositoryImpl implements AccommodationRepositoryCustom {

private JPAQueryFactory jpaQueryFactory;

public AccommodationRepositoryImpl(JPAQueryFactory jpaQueryFactory) {
this.jpaQueryFactory = jpaQueryFactory;
}

@Override
public List<Accommodation> findAllBySigunguName(String name) {
return jpaQueryFactory.selectFrom(accommodation)
.where(accommodation.sigungu.name.eq(name)).fetch();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.coolpeace.domain.coupon.dto.request.validator;

import com.coolpeace.domain.coupon.dto.request.CouponRegisterRequest;
import com.coolpeace.domain.coupon.dto.request.CouponUpdateRequest;
import com.coolpeace.domain.coupon.entity.type.DiscountType;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

@Component
public class CouponUpdateRequestValidator implements Validator {
@Override
public boolean supports(Class<?> clazz) {
return CouponUpdateRequest.class.equals(clazz);
}

@Override
public void validate(Object target, Errors errors) {
CouponRegisterRequest request = (CouponRegisterRequest) target;

// 할인 유형
if (request.discountType().equals(DiscountType.FIXED_PRICE)) {
if (request.discountValue() < 100) {
errors.reject("discountValue",
"정액 할인일 경우 값을 100 이상으로 설정해야 합니다.");
}
} else {
if (request.discountValue() > 100) {
errors.reject("discountValue",
"정률 할인일 경우 값을 100 이하로 설정해야 합니다.");
}
}

// 특정 객실 등록
if (!request.registerAllRoom()) {
if (CollectionUtils.isEmpty(request.registerRooms())) {
errors.reject("registerRooms.empty",
"등록할 객실 리스트가 비어 있습니다.");
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static CouponResponse from(Coupon coupon) {
coupon.getCouponNumber(),
coupon.getCouponStatus().getValue(),
false, // 프로모션이 개발되면 추후 수정 예정
coupon.getConcatTitle(),
coupon.getCouponTitle(),
coupon.getDiscountType().getValue(),
coupon.getDiscountValue(),
coupon.getCustomerType().getValue(),
Expand Down
24 changes: 8 additions & 16 deletions src/main/java/com/coolpeace/domain/coupon/entity/Coupon.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
import com.coolpeace.domain.room.entity.Room;
import com.coolpeace.global.common.BaseTimeEntity;
import jakarta.persistence.*;
import java.text.NumberFormat;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

@Getter
@Entity
Expand Down Expand Up @@ -136,13 +138,10 @@ public static Coupon from(
}

public String getCouponTitle() {
NumberFormat numberFormat = NumberFormat.getInstance();
if (this.discountType.equals(DiscountType.FIXED_PRICE)) {
return this.customerType.getValue() + " " + numberFormat.format(this.discountValue)
+ "원 할인";
}
return this.customerType.getValue() + " " + numberFormat.format(this.discountValue)
+ "% 할인";
return switch (this.discountType) {
case FIXED_PRICE -> String.format("%s %d원 할인", customerType.getValue(), discountValue);
case FIXED_RATE -> String.format("%s %d%% 할인", customerType.getValue(), discountValue);
};
}

public void generateCouponNumber(CouponIssuerType couponIssuerType, Long id) {
Expand Down Expand Up @@ -190,11 +189,4 @@ public void updateCoupon(
this.exposureEndDate = Optional.ofNullable(exposureEndDate).orElse(this.exposureEndDate);
updateCouponStatusByExposureDate();
}

public String getConcatTitle() {
return switch (this.discountType) {
case FIXED_PRICE -> String.format("%s %d원 할인", customerType.getValue(), discountValue);
case FIXED_RATE -> String.format("%s %d%% 할인", customerType.getValue(), discountValue);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import com.coolpeace.domain.accommodation.entity.Accommodation;
import com.coolpeace.domain.coupon.entity.Coupon;
import com.coolpeace.domain.member.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;

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> findAllByMemberAndAccommodation(Member member, Accommodation accommodation);
List<Coupon> findAllByAccommodation(Accommodation accommodation);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import lombok.Setter;

@Getter
@Setter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class LocalCouponDownload {
Expand All @@ -29,6 +28,12 @@ public class LocalCouponDownload {

private String thirdCouponTitle;

private Long firstCouponId;

private Long secondCouponId;

private Long thirdCouponId;

public LocalCouponDownload(String region) {
this.region = region;
}
Expand All @@ -41,4 +46,46 @@ public LocalCouponDownload(Long id, String region, String firstCouponTitle,
this.secondCouponTitle = secondCouponTitle;
this.thirdCouponTitle = thirdCouponTitle;
}

public void init(String couponTitle, Long couponId) {
this.firstCouponTitle = couponTitle;
this.secondCouponTitle = couponTitle;
this.thirdCouponTitle = couponTitle;
this.firstCouponId = couponId;
this.secondCouponId = couponId;
this.thirdCouponId = couponId;
}

public void setFirstCoupon(String firstCouponTitle, Long firstCouponId) {
this.firstCouponTitle = firstCouponTitle;
this.firstCouponId = firstCouponId;
}

public void setSecondCoupon(String secondCouponTitle, Long secondCouponId) {
this.secondCouponTitle = secondCouponTitle;
this.secondCouponId = secondCouponId;
}

public void setThirdCoupon(String thirdCouponTitle, Long thirdCouponId) {
this.thirdCouponTitle = thirdCouponTitle;
this.thirdCouponId = thirdCouponId;
}

public void setAllCoupon(String firstCouponTitle, Long firstCouponId,
LocalCouponDownload localCouponDownload) {
this.firstCouponTitle = firstCouponTitle;
this.firstCouponId = firstCouponId;
this.secondCouponTitle = localCouponDownload.getFirstCouponTitle();
this.secondCouponId = localCouponDownload.getFirstCouponId();
this.thirdCouponTitle = localCouponDownload.getSecondCouponTitle();
this.thirdCouponId = localCouponDownload.getSecondCouponId();
}
public void setSecondAndThirdCoupon(String secondCouponTitle, Long secondCouponId,
LocalCouponDownload localCouponDownload) {
this.secondCouponTitle = secondCouponTitle;
this.secondCouponId = secondCouponId;
this.thirdCouponTitle = localCouponDownload.getSecondCouponTitle();
this.thirdCouponId = localCouponDownload.getSecondCouponId();
}

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

import com.coolpeace.domain.accommodation.entity.Accommodation;
import com.coolpeace.domain.accommodation.repository.AccommodationRepository;
import com.coolpeace.domain.coupon.entity.Coupon;
import com.coolpeace.domain.coupon.repository.CouponRepository;
import com.coolpeace.domain.member.entity.Member;
import com.coolpeace.domain.reservation.entity.Reservation;
Expand Down Expand Up @@ -58,21 +59,21 @@ public void updateSales(){

public void updateCoupon(){
List<Accommodation> accommodations = accommodationRepository.findAll();
int downloadCount = 0;
int usedCount = 0;
int day = LocalDate.now().getDayOfMonth();

for (Accommodation accommodation : accommodations) {
accommodations.forEach(accommodation -> {
int downloadCount = 0;
int usedCount = 0;
Member member = accommodation.getMember();
/* 쿠폰 변경 후, 적용 예정
* ...
* */
List<Coupon> coupons = couponRepository.findAllByAccommodation(accommodation);
for (Coupon coupon : coupons) {
downloadCount += coupon.getDownloadCount();
usedCount += coupon.getUseCount();
}
DailyStatistics dailyStatistics = dailyStatisticsRepository
.findByAccommodationAndStatisticsDay(accommodation,day)
.orElse(new DailyStatistics(day,member, accommodation));
dailyStatistics.setCoupon(downloadCount, usedCount);
}

});
}

public void updateSettlement(){
Expand Down
Loading

0 comments on commit 0b48831

Please sign in to comment.