From 3ffba1c2e8bdcdb42faecb9446050dd91e804436 Mon Sep 17 00:00:00 2001 From: Choi-Seong-Hyeok Date: Mon, 4 Mar 2024 01:55:12 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EC=BF=A0=ED=8F=B0=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=EB=B9=84=EC=9C=A8=20API=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AdminCouponController.java | 7 +++++ .../app/coupon/dto/CouponUsageRateDto.java | 29 +++++++++++++++++++ .../app/coupon/mapper/CouponMapper.java | 3 ++ .../app/coupon/mapper/MemberCouponMapper.java | 4 +++ .../app/coupon/service/CouponService.java | 8 +++++ src/main/resources/mapper/CouponMapper.xml | 15 ++++++++++ 6 files changed, 66 insertions(+) create mode 100644 src/main/java/com/hyundai/app/coupon/dto/CouponUsageRateDto.java diff --git a/src/main/java/com/hyundai/app/coupon/controller/AdminCouponController.java b/src/main/java/com/hyundai/app/coupon/controller/AdminCouponController.java index 6de9a91..22ec55e 100644 --- a/src/main/java/com/hyundai/app/coupon/controller/AdminCouponController.java +++ b/src/main/java/com/hyundai/app/coupon/controller/AdminCouponController.java @@ -2,6 +2,7 @@ import com.hyundai.app.common.AdventureOfHeendyResponse; import com.hyundai.app.coupon.domain.Coupon; +import com.hyundai.app.coupon.dto.CouponUsageRateDto; import com.hyundai.app.coupon.service.CouponService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -32,4 +33,10 @@ public AdventureOfHeendyResponse> findCouponList() { int storeId = 1; return AdventureOfHeendyResponse.success("쿠폰 목록을 가져왔습니다.", couponService.findCouponList(storeId)); } + + @ApiOperation("쿠폰 사용률 통계 조회 API") + @GetMapping("/statistics") + public AdventureOfHeendyResponse> findCouponUsageRates() { + return AdventureOfHeendyResponse.success("쿠폰 사용률 통계를 가져왔습니다.", couponService.findCouponUsageRates()); + } } diff --git a/src/main/java/com/hyundai/app/coupon/dto/CouponUsageRateDto.java b/src/main/java/com/hyundai/app/coupon/dto/CouponUsageRateDto.java new file mode 100644 index 0000000..8372d44 --- /dev/null +++ b/src/main/java/com/hyundai/app/coupon/dto/CouponUsageRateDto.java @@ -0,0 +1,29 @@ +package com.hyundai.app.coupon.dto; + +import com.hyundai.app.coupon.enumType.CouponType; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +/** + * @author 최성혁 + * @since 2024/03/04 + * 쿠폰사용비율 DTO + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CouponUsageRateDto { + private CouponType couponType; + private int totalIssued; + private int totalUsed; + private double usageRate; + + public void setUsageRate(double usageRate) { + BigDecimal bd = new BigDecimal(usageRate).setScale(2, RoundingMode.HALF_UP); + this.usageRate = bd.doubleValue(); + } +} diff --git a/src/main/java/com/hyundai/app/coupon/mapper/CouponMapper.java b/src/main/java/com/hyundai/app/coupon/mapper/CouponMapper.java index 68e75de..e00b987 100644 --- a/src/main/java/com/hyundai/app/coupon/mapper/CouponMapper.java +++ b/src/main/java/com/hyundai/app/coupon/mapper/CouponMapper.java @@ -1,6 +1,7 @@ package com.hyundai.app.coupon.mapper; import com.hyundai.app.coupon.domain.Coupon; +import com.hyundai.app.coupon.dto.CouponUsageRateDto; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -17,4 +18,6 @@ public interface CouponMapper { Coupon findById(int couponId); List findMemberCouponList(String memberId); + + List findCouponUsageRates(); } diff --git a/src/main/java/com/hyundai/app/coupon/mapper/MemberCouponMapper.java b/src/main/java/com/hyundai/app/coupon/mapper/MemberCouponMapper.java index 0fad3d8..abcaf71 100644 --- a/src/main/java/com/hyundai/app/coupon/mapper/MemberCouponMapper.java +++ b/src/main/java/com/hyundai/app/coupon/mapper/MemberCouponMapper.java @@ -1,6 +1,9 @@ package com.hyundai.app.coupon.mapper; import com.hyundai.app.coupon.domain.MemberCoupon; +import com.hyundai.app.coupon.dto.CouponUsageRateDto; + +import java.util.List; /** * @author 엄상은 @@ -9,4 +12,5 @@ */ public interface MemberCouponMapper { void saveMemberCoupon(MemberCoupon memberCoupon); + } diff --git a/src/main/java/com/hyundai/app/coupon/service/CouponService.java b/src/main/java/com/hyundai/app/coupon/service/CouponService.java index e38c379..2f10acc 100644 --- a/src/main/java/com/hyundai/app/coupon/service/CouponService.java +++ b/src/main/java/com/hyundai/app/coupon/service/CouponService.java @@ -1,8 +1,11 @@ package com.hyundai.app.coupon.service; import com.hyundai.app.coupon.domain.Coupon; +import com.hyundai.app.coupon.domain.MemberCoupon; +import com.hyundai.app.coupon.dto.CouponUsageRateDto; import com.hyundai.app.coupon.enumType.CouponType; import com.hyundai.app.coupon.mapper.CouponMapper; +import com.hyundai.app.coupon.mapper.MemberCouponMapper; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -37,4 +40,9 @@ public List findMemberCouponList(String memberId) { } return couponList; } + + public List findCouponUsageRates() { + return couponMapper.findCouponUsageRates(); + } + } diff --git a/src/main/resources/mapper/CouponMapper.xml b/src/main/resources/mapper/CouponMapper.xml index 5938e65..8fa39e7 100644 --- a/src/main/resources/mapper/CouponMapper.xml +++ b/src/main/resources/mapper/CouponMapper.xml @@ -44,4 +44,19 @@ FROM member_coupon WHERE member_id = #{memberId}) + + +