관리자
- 커뮤니티 게시물 정산 API 추가
This commit is contained in:
		| @@ -34,4 +34,18 @@ class AdminCalculateController(private val service: AdminCalculateService) { | |||||||
|         @RequestParam startDateStr: String, |         @RequestParam startDateStr: String, | ||||||
|         @RequestParam endDateStr: String |         @RequestParam endDateStr: String | ||||||
|     ) = ApiResponse.ok(service.getCalculateContentDonationList(startDateStr, endDateStr)) |     ) = ApiResponse.ok(service.getCalculateContentDonationList(startDateStr, endDateStr)) | ||||||
|  |  | ||||||
|  |     @GetMapping("/community-post") | ||||||
|  |     fun getCalculateCommunityPost( | ||||||
|  |         @RequestParam startDateStr: String, | ||||||
|  |         @RequestParam endDateStr: String, | ||||||
|  |         pageable: Pageable | ||||||
|  |     ) = ApiResponse.ok( | ||||||
|  |         service.getCalculateCommunityPost( | ||||||
|  |             startDateStr, | ||||||
|  |             endDateStr, | ||||||
|  |             pageable.offset, | ||||||
|  |             pageable.pageSize.toLong() | ||||||
|  |         ) | ||||||
|  |     ) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ import kr.co.vividnext.sodalive.can.use.CanUsage | |||||||
| import kr.co.vividnext.sodalive.can.use.QUseCan.useCan | import kr.co.vividnext.sodalive.can.use.QUseCan.useCan | ||||||
| import kr.co.vividnext.sodalive.content.QAudioContent.audioContent | import kr.co.vividnext.sodalive.content.QAudioContent.audioContent | ||||||
| import kr.co.vividnext.sodalive.content.order.QOrder.order | import kr.co.vividnext.sodalive.content.order.QOrder.order | ||||||
|  | import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.QCreatorCommunity.creatorCommunity | ||||||
| import kr.co.vividnext.sodalive.live.room.QLiveRoom.liveRoom | import kr.co.vividnext.sodalive.live.room.QLiveRoom.liveRoom | ||||||
| import kr.co.vividnext.sodalive.member.QMember.member | import kr.co.vividnext.sodalive.member.QMember.member | ||||||
| import org.springframework.stereotype.Repository | import org.springframework.stereotype.Repository | ||||||
| @@ -152,4 +153,35 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) { | |||||||
|             .orderBy(member.id.asc(), donationFormattedDate.desc()) |             .orderBy(member.id.asc(), donationFormattedDate.desc()) | ||||||
|             .fetch() |             .fetch() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     fun getCalculateCommunityPostList( | ||||||
|  |         startDate: LocalDateTime?, | ||||||
|  |         endDate: LocalDateTime?, | ||||||
|  |         offset: Long, | ||||||
|  |         limit: Long | ||||||
|  |     ): List<GetCalculateCommunityPostQueryData> { | ||||||
|  |         val formattedDate = getFormattedDate(useCan.createdAt) | ||||||
|  |         return queryFactory | ||||||
|  |             .select( | ||||||
|  |                 QGetCalculateCommunityPostQueryData( | ||||||
|  |                     member.nickname, | ||||||
|  |                     Expressions.stringTemplate("substring({0}, 1, 10)", creatorCommunity.content), | ||||||
|  |                     formattedDate, | ||||||
|  |                     useCan.id.count(), | ||||||
|  |                     useCan.can.add(useCan.rewardCan).sum() | ||||||
|  |                 ) | ||||||
|  |             ) | ||||||
|  |             .from(useCan) | ||||||
|  |             .innerJoin(useCan.communityPost, creatorCommunity) | ||||||
|  |             .innerJoin(creatorCommunity.member, member) | ||||||
|  |             .where( | ||||||
|  |                 useCan.isRefund.isFalse | ||||||
|  |                     .and(useCan.canUsage.eq(CanUsage.PAID_COMMUNITY_POST)) | ||||||
|  |                     .and(useCan.createdAt.goe(startDate)) | ||||||
|  |                     .and(useCan.createdAt.loe(endDate)) | ||||||
|  |             ) | ||||||
|  |             .groupBy(formattedDate, creatorCommunity.id) | ||||||
|  |             .orderBy(member.id.asc(), formattedDate.desc()) | ||||||
|  |             .fetch() | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.admin.calculate | |||||||
|  |  | ||||||
| import kr.co.vividnext.sodalive.can.use.CanUsage | import kr.co.vividnext.sodalive.can.use.CanUsage | ||||||
| import kr.co.vividnext.sodalive.content.order.OrderType | import kr.co.vividnext.sodalive.content.order.OrderType | ||||||
|  | import kr.co.vividnext.sodalive.extensions.convertLocalDateTime | ||||||
| import org.springframework.cache.annotation.Cacheable | import org.springframework.cache.annotation.Cacheable | ||||||
| import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||||
| import org.springframework.transaction.annotation.Transactional | import org.springframework.transaction.annotation.Transactional | ||||||
| @@ -266,4 +267,37 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor | |||||||
|             } |             } | ||||||
|             .toList() |             .toList() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     fun getCalculateCommunityPost( | ||||||
|  |         startDateStr: String, | ||||||
|  |         endDateStr: String, | ||||||
|  |         offset: Long, | ||||||
|  |         limit: Long | ||||||
|  |     ): List<GetCalculateCommunityPostResponse> { | ||||||
|  |         val startDate = startDateStr.convertLocalDateTime() | ||||||
|  |         val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59) | ||||||
|  |  | ||||||
|  |         return repository | ||||||
|  |             .getCalculateCommunityPostList(startDate, endDate, offset, limit) | ||||||
|  |             .map { | ||||||
|  |                 val totalKrw = it.totalCan * 100 | ||||||
|  |                 val paymentFee = totalKrw * 0.066f | ||||||
|  |                 val settlementAmount = (totalKrw.toFloat() - paymentFee) * 0.7 | ||||||
|  |                 val tax = settlementAmount * 0.033 | ||||||
|  |                 val depositAmount = settlementAmount - tax | ||||||
|  |  | ||||||
|  |                 GetCalculateCommunityPostResponse( | ||||||
|  |                     nickname = it.nickname, | ||||||
|  |                     title = it.title, | ||||||
|  |                     date = it.date, | ||||||
|  |                     numberOfPurchase = it.numberOfPurchase.toInt(), | ||||||
|  |                     totalCan = it.totalCan, | ||||||
|  |                     totalKrw = totalKrw, | ||||||
|  |                     paymentFee = paymentFee.roundToInt(), | ||||||
|  |                     settlementAmount = settlementAmount.roundToInt(), | ||||||
|  |                     tax = tax.roundToInt(), | ||||||
|  |                     depositAmount = depositAmount.roundToInt() | ||||||
|  |                 ) | ||||||
|  |             } | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,9 +1,26 @@ | |||||||
| package kr.co.vividnext.sodalive.extensions | package kr.co.vividnext.sodalive.extensions | ||||||
|  |  | ||||||
|  | import java.time.LocalDate | ||||||
| import java.time.LocalDateTime | import java.time.LocalDateTime | ||||||
|  | import java.time.ZoneId | ||||||
| import java.time.format.DateTimeFormatter | import java.time.format.DateTimeFormatter | ||||||
|  |  | ||||||
| fun String.convertLocalDateTime(format: String): LocalDateTime { | fun String.convertLocalDateTime(format: String): LocalDateTime { | ||||||
|     val dateTimeFormatter = DateTimeFormatter.ofPattern(format) |     val dateTimeFormatter = DateTimeFormatter.ofPattern(format) | ||||||
|     return LocalDateTime.parse(this, dateTimeFormatter) |     return LocalDateTime.parse(this, dateTimeFormatter) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | fun String.convertLocalDateTime( | ||||||
|  |     format: String = "yyyy-MM-dd", | ||||||
|  |     currentTimeZoneStr: String = "ASIA/Seoul", | ||||||
|  |     hour: Int = 0, | ||||||
|  |     minute: Int = 0, | ||||||
|  |     second: Int = 0 | ||||||
|  | ): LocalDateTime { | ||||||
|  |     val dateTimeFormatter = DateTimeFormatter.ofPattern(format) | ||||||
|  |     return LocalDate.parse(this, dateTimeFormatter) | ||||||
|  |         .atTime(hour, minute, second) | ||||||
|  |         .atZone(ZoneId.of(currentTimeZoneStr)) | ||||||
|  |         .withZoneSameInstant(ZoneId.of("UTC")) | ||||||
|  |         .toLocalDateTime() | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user