From 9332f15ee8189307cb668653550b306f77577400 Mon Sep 17 00:00:00 2001 From: Jisang Lee Date: Mon, 29 Jan 2024 12:56:52 +0900 Subject: [PATCH 1/3] =?UTF-8?q?#217=20fix:=20=ED=86=B5=EA=B3=84=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20=ED=98=B8=ED=99=98=EC=84=B1=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 개발에서 사용하던 H2 DB와 AWS RDS에서 사용하는 Maria DB간의 쿼리 호환성 문제로 인하여 통계 쿼리가 정상 작동하지 않는 문제 수정 --- .../coupon/config/MockStatisticsInit.java | 5 ++- .../CouponStatisticsRepository.java | 37 ++++++++----------- .../RevenueStatisticsRepository.java | 16 ++++---- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/config/MockStatisticsInit.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/config/MockStatisticsInit.java index f2901b7b..fba68658 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/config/MockStatisticsInit.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/config/MockStatisticsInit.java @@ -32,7 +32,7 @@ @Configuration @RequiredArgsConstructor @Transactional -@Profile("prod") +@Profile("local") public class MockStatisticsInit { private final CouponStatisticsRepository couponStatisticsRepository; @@ -49,7 +49,8 @@ public void run(ApplicationArguments args) throws Exception { if (!couponStatisticsRepository.existsById(1L)) { makeCouponStatistics(); } - if (!revenueStatisticsRepository.existsById(1L)) { + if (!revenueStatisticsRepository.existsById(1L) || + !revenueTotalRepository.existsById(1L)) { createRevenueStatistics(); } } diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/CouponStatisticsRepository.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/CouponStatisticsRepository.java index 6af464cd..294ec16c 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/CouponStatisticsRepository.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/CouponStatisticsRepository.java @@ -10,30 +10,25 @@ public interface CouponStatisticsRepository extends JpaRepository { String couponQuery = """ - select t.id, t.total, u.used, t.total - u.used as stock - from (select ac.id as id, sum(ci.quantity) as total - from coupon_issuance ci - left join room rm on ci.room_id = rm.id - left join coupon cp on cp.id = ci.coupon_id - left join accommodation ac on rm.accommodation_id = ac.id - where rm.deleted_at is null - and ac.deleted_at is null - and cp.deleted_at is null + select t.id, + coalesce(t.total, 0) as total, + coalesce(u.used, 0) as used, + coalesce(t.total - u.used, t.total, 0) as stock + from (select ac.id, coalesce(sum(ci.quantity), 0) as total + from accommodation ac + join room rm on ac.id = rm.accommodation_id + left join coupon_issuance ci on rm.id = ci.room_id + left join coupon cp on ci.coupon_id = cp.id + where cp.deleted_at is null group by ac.id) t - inner join - (select ac.id as id, count(*) as used - from room rm - left join reservation_room rr on rr.room_id = rm.id + left join + (select ac.id, coalesce(count(*), 0) as used + from accommodation ac + join room rm on ac.id = rm.accommodation_id + left join reservation_room rr on rm.id = rr.room_id left join reservation rv on rr.id = rv.reservation_room_id - left join coupon_redeem cr on rv.id = cr.reservation_id - left join accommodation ac on rm.accommodation_id = ac.id where rv.is_coupon_used = true - and rm.deleted_at is null - and ac.deleted_at is null - and not exists(select 1 - from coupon cp - inner join coupon_redeem cr on cr.coupon_id = cp.id - where cp.deleted_at is not null) + and rv.status != 'CANCELLED' group by ac.id) u on t.id = u.id """; diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/RevenueStatisticsRepository.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/RevenueStatisticsRepository.java index 36e08273..217a4421 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/RevenueStatisticsRepository.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/RevenueStatisticsRepository.java @@ -11,12 +11,12 @@ public interface RevenueStatisticsRepository extends JpaRepository { String revenueSQL = """ - select ac.id as id, + select ac.id, py.created_at as revenueDate, - coalesce(sum(case when py.discount_amount != 0 then py.total_amount else 0 end), - 0) as couponRevenue, coalesce(sum(case when py.discount_amount = 0 then py.total_amount else 0 end), - 0) as regularRevenue + 0) as regularRevenue, + coalesce(sum(case when py.discount_amount != 0 then py.total_amount else 0 end), + 0) as couponRevenue from reservation_room rr left join reservation rv on rr.id = rv.reservation_room_id left join payment py on rv.payment_id = py.id @@ -24,12 +24,10 @@ public interface RevenueStatisticsRepository extends JpaRepository createRevenueStatistics( From e9fc659a09648aa460f6a60691ae1c14c3061c5c Mon Sep 17 00:00:00 2001 From: Jisang Lee Date: Mon, 29 Jan 2024 12:56:52 +0900 Subject: [PATCH 2/3] =?UTF-8?q?#217=20fix:=20=ED=86=B5=EA=B3=84=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20=ED=98=B8=ED=99=98=EC=84=B1=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 개발에서 사용하던 H2 DB와 AWS RDS에서 사용하는 Maria DB간의 쿼리 호환성 문제로 인하여 통계 쿼리가 정상 작동하지 않는 문제 수정 --- .../coupon/config/MockStatisticsInit.java | 3 +- .../CouponStatisticsRepository.java | 37 ++++++++----------- .../RevenueStatisticsRepository.java | 16 ++++---- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/config/MockStatisticsInit.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/config/MockStatisticsInit.java index f2901b7b..54a6bd9b 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/config/MockStatisticsInit.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/config/MockStatisticsInit.java @@ -49,7 +49,8 @@ public void run(ApplicationArguments args) throws Exception { if (!couponStatisticsRepository.existsById(1L)) { makeCouponStatistics(); } - if (!revenueStatisticsRepository.existsById(1L)) { + if (!revenueStatisticsRepository.existsById(1L) || + !revenueTotalRepository.existsById(1L)) { createRevenueStatistics(); } } diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/CouponStatisticsRepository.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/CouponStatisticsRepository.java index 6af464cd..294ec16c 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/CouponStatisticsRepository.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/CouponStatisticsRepository.java @@ -10,30 +10,25 @@ public interface CouponStatisticsRepository extends JpaRepository { String couponQuery = """ - select t.id, t.total, u.used, t.total - u.used as stock - from (select ac.id as id, sum(ci.quantity) as total - from coupon_issuance ci - left join room rm on ci.room_id = rm.id - left join coupon cp on cp.id = ci.coupon_id - left join accommodation ac on rm.accommodation_id = ac.id - where rm.deleted_at is null - and ac.deleted_at is null - and cp.deleted_at is null + select t.id, + coalesce(t.total, 0) as total, + coalesce(u.used, 0) as used, + coalesce(t.total - u.used, t.total, 0) as stock + from (select ac.id, coalesce(sum(ci.quantity), 0) as total + from accommodation ac + join room rm on ac.id = rm.accommodation_id + left join coupon_issuance ci on rm.id = ci.room_id + left join coupon cp on ci.coupon_id = cp.id + where cp.deleted_at is null group by ac.id) t - inner join - (select ac.id as id, count(*) as used - from room rm - left join reservation_room rr on rr.room_id = rm.id + left join + (select ac.id, coalesce(count(*), 0) as used + from accommodation ac + join room rm on ac.id = rm.accommodation_id + left join reservation_room rr on rm.id = rr.room_id left join reservation rv on rr.id = rv.reservation_room_id - left join coupon_redeem cr on rv.id = cr.reservation_id - left join accommodation ac on rm.accommodation_id = ac.id where rv.is_coupon_used = true - and rm.deleted_at is null - and ac.deleted_at is null - and not exists(select 1 - from coupon cp - inner join coupon_redeem cr on cr.coupon_id = cp.id - where cp.deleted_at is not null) + and rv.status != 'CANCELLED' group by ac.id) u on t.id = u.id """; diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/RevenueStatisticsRepository.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/RevenueStatisticsRepository.java index 36e08273..217a4421 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/RevenueStatisticsRepository.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/RevenueStatisticsRepository.java @@ -11,12 +11,12 @@ public interface RevenueStatisticsRepository extends JpaRepository { String revenueSQL = """ - select ac.id as id, + select ac.id, py.created_at as revenueDate, - coalesce(sum(case when py.discount_amount != 0 then py.total_amount else 0 end), - 0) as couponRevenue, coalesce(sum(case when py.discount_amount = 0 then py.total_amount else 0 end), - 0) as regularRevenue + 0) as regularRevenue, + coalesce(sum(case when py.discount_amount != 0 then py.total_amount else 0 end), + 0) as couponRevenue from reservation_room rr left join reservation rv on rr.id = rv.reservation_room_id left join payment py on rv.payment_id = py.id @@ -24,12 +24,10 @@ public interface RevenueStatisticsRepository extends JpaRepository createRevenueStatistics( From 4fc0e0788b759d00eee7fae45fb71d74398c61d9 Mon Sep 17 00:00:00 2001 From: Jisang Lee Date: Mon, 29 Jan 2024 13:24:56 +0900 Subject: [PATCH 3/3] =?UTF-8?q?#217=20refactor:=20application=20runner?= =?UTF-8?q?=EC=9D=98=20=ED=99=98=EA=B2=BD=20=EC=84=A4=EC=A0=95=EC=9D=B4=20?= =?UTF-8?q?local=EB=A1=9C=20=EB=90=98=EC=96=B4=20=EC=9E=88=EB=8D=98=20?= =?UTF-8?q?=EA=B2=83=EC=9D=84=20prod=EB=A1=9C=20=EC=88=98=EC=A0=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../upjuyanolja/domain/coupon/config/MockStatisticsInit.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/config/MockStatisticsInit.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/config/MockStatisticsInit.java index fba68658..54a6bd9b 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/config/MockStatisticsInit.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/config/MockStatisticsInit.java @@ -32,7 +32,7 @@ @Configuration @RequiredArgsConstructor @Transactional -@Profile("local") +@Profile("prod") public class MockStatisticsInit { private final CouponStatisticsRepository couponStatisticsRepository;