|
3 | 3 | import PodoeMarket.podoemarket.admin.dto.request.PlayTypeRequestDTO; |
4 | 4 | import PodoeMarket.podoemarket.admin.dto.response.OrderManagementResponseDTO; |
5 | 5 | import PodoeMarket.podoemarket.admin.dto.response.ProductManagementResponseDTO; |
| 6 | +import PodoeMarket.podoemarket.admin.dto.response.StatisticsResponseDTO; |
6 | 7 | import PodoeMarket.podoemarket.common.entity.OrderItemEntity; |
7 | 8 | import PodoeMarket.podoemarket.common.entity.OrdersEntity; |
8 | 9 | import PodoeMarket.podoemarket.common.entity.ProductEntity; |
9 | 10 | import PodoeMarket.podoemarket.common.entity.UserEntity; |
10 | 11 | import PodoeMarket.podoemarket.common.entity.type.OrderStatus; |
11 | 12 | import PodoeMarket.podoemarket.common.entity.type.ProductStatus; |
12 | 13 | import PodoeMarket.podoemarket.common.entity.type.StageType; |
13 | | -import PodoeMarket.podoemarket.common.repository.OrderItemRepository; |
14 | | -import PodoeMarket.podoemarket.common.repository.OrderRepository; |
15 | | -import PodoeMarket.podoemarket.common.repository.ProductRepository; |
| 14 | +import PodoeMarket.podoemarket.common.repository.*; |
16 | 15 | import PodoeMarket.podoemarket.service.MailSendService; |
17 | 16 | import com.amazonaws.services.s3.AmazonS3; |
18 | 17 | import com.amazonaws.services.s3.model.AmazonS3Exception; |
@@ -45,6 +44,8 @@ public class AdminService { |
45 | 44 | private final ProductRepository productRepo; |
46 | 45 | private final OrderRepository orderRepo; |
47 | 46 | private final OrderItemRepository orderItemRepo; |
| 47 | + private final UserRepository userRepo; |
| 48 | + private final ReviewRepository reviewRepo; |
48 | 49 | private final AmazonS3 amazonS3; |
49 | 50 | private final MailSendService mailSendService; |
50 | 51 |
|
@@ -302,4 +303,51 @@ public void updateWriter(UUID productId, String writer) { |
302 | 303 | throw new RuntimeException("상품 제목 업데이트 실패", e); |
303 | 304 | } |
304 | 305 | } |
| 306 | + |
| 307 | + public StatisticsResponseDTO getStatistics() { |
| 308 | + try { |
| 309 | + return StatisticsResponseDTO.builder() |
| 310 | + .userCnt(getUserCount()) |
| 311 | + .scriptCnt(getScriptCount()) |
| 312 | + .viewCnt(getViewCount()) |
| 313 | + .reviewCnt(getReviewCount()) |
| 314 | + .build(); |
| 315 | + } catch (Exception e) { |
| 316 | + throw new RuntimeException("통계 조회 실패", e); |
| 317 | + } |
| 318 | + } |
| 319 | + |
| 320 | + // ================= private method ================= |
| 321 | + |
| 322 | + private Long getUserCount() { |
| 323 | + try { |
| 324 | + return userRepo.count(); |
| 325 | + } catch (Exception e) { |
| 326 | + throw new RuntimeException("유저 카운트 조회 실패", e); |
| 327 | + } |
| 328 | + } |
| 329 | + |
| 330 | + private Long getScriptCount() { |
| 331 | + try { |
| 332 | + return productRepo.count(); |
| 333 | + } catch (Exception e) { |
| 334 | + throw new RuntimeException("작품 카운트 조회 실패", e); |
| 335 | + } |
| 336 | + } |
| 337 | + |
| 338 | + private Long getViewCount() { |
| 339 | + try { |
| 340 | + return productRepo.sumViewCount(); |
| 341 | + } catch (Exception e) { |
| 342 | + throw new RuntimeException("조회수 카운트 조회 실패", e); |
| 343 | + } |
| 344 | + } |
| 345 | + |
| 346 | + private Long getReviewCount() { |
| 347 | + try { |
| 348 | + return reviewRepo.count(); |
| 349 | + } catch (Exception e) { |
| 350 | + throw new RuntimeException("후기 카운트 조회 실패", e); |
| 351 | + } |
| 352 | + } |
305 | 353 | } |
0 commit comments