| @@ -43,8 +43,8 @@ class AdminLiveRoomQueryRepository(private val queryFactory: JPAQueryFactory) { | |||||||
|             .selectFrom(liveRoom) |             .selectFrom(liveRoom) | ||||||
|             .where( |             .where( | ||||||
|                 liveRoom.isActive.isTrue |                 liveRoom.isActive.isTrue | ||||||
|                     .and(liveRoom.channelName.isNotNull) |                     .and(liveRoom.channelName.isNull) | ||||||
|                     .and(liveRoom.beginDateTime.loe(LocalDateTime.now().minusHours(12))) |                     .and(liveRoom.beginDateTime.loe(LocalDateTime.now().minusHours(4))) | ||||||
|             ) |             ) | ||||||
|             .fetch() |             .fetch() | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -0,0 +1,26 @@ | |||||||
|  | package kr.co.vividnext.sodalive.creator.admin.calculate | ||||||
|  |  | ||||||
|  | import kr.co.vividnext.sodalive.common.ApiResponse | ||||||
|  | import kr.co.vividnext.sodalive.common.SodaException | ||||||
|  | import kr.co.vividnext.sodalive.member.Member | ||||||
|  | import org.springframework.security.access.prepost.PreAuthorize | ||||||
|  | import org.springframework.security.core.annotation.AuthenticationPrincipal | ||||||
|  | import org.springframework.web.bind.annotation.GetMapping | ||||||
|  | import org.springframework.web.bind.annotation.RequestMapping | ||||||
|  | import org.springframework.web.bind.annotation.RequestParam | ||||||
|  | import org.springframework.web.bind.annotation.RestController | ||||||
|  |  | ||||||
|  | @RestController | ||||||
|  | @PreAuthorize("hasRole('CREATOR')") | ||||||
|  | @RequestMapping("/creator-admin/calculate") | ||||||
|  | class CreatorAdminCalculateController(private val service: CreatorAdminCalculateService) { | ||||||
|  |     @GetMapping("/live") | ||||||
|  |     fun getCalculateLive( | ||||||
|  |         @RequestParam startDateStr: String, | ||||||
|  |         @RequestParam endDateStr: String, | ||||||
|  |         @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? | ||||||
|  |     ) = run { | ||||||
|  |         if (member == null) throw SodaException("로그인 정보를 확인해주세요.") | ||||||
|  |         ApiResponse.ok(service.getCalculateLive(startDateStr, endDateStr, member)) | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,61 @@ | |||||||
|  | package kr.co.vividnext.sodalive.creator.admin.calculate | ||||||
|  |  | ||||||
|  | import com.querydsl.core.types.dsl.Expressions | ||||||
|  | import com.querydsl.jpa.impl.JPAQueryFactory | ||||||
|  | import kr.co.vividnext.sodalive.admin.calculate.GetCalculateLiveQueryData | ||||||
|  | import kr.co.vividnext.sodalive.admin.calculate.QGetCalculateLiveQueryData | ||||||
|  | import kr.co.vividnext.sodalive.can.use.QUseCan.useCan | ||||||
|  | import kr.co.vividnext.sodalive.can.use.QUseCanCalculate.useCanCalculate | ||||||
|  | import kr.co.vividnext.sodalive.can.use.UseCanCalculateStatus | ||||||
|  | import kr.co.vividnext.sodalive.live.room.QLiveRoom.liveRoom | ||||||
|  | import kr.co.vividnext.sodalive.member.QMember.member | ||||||
|  | import org.springframework.stereotype.Repository | ||||||
|  | import java.time.LocalDateTime | ||||||
|  |  | ||||||
|  | @Repository | ||||||
|  | class CreatorAdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) { | ||||||
|  |     fun getCalculateLive( | ||||||
|  |         startDate: LocalDateTime, | ||||||
|  |         endDate: LocalDateTime, | ||||||
|  |         memberId: Long | ||||||
|  |     ): List<GetCalculateLiveQueryData> { | ||||||
|  |         val formattedDate = Expressions.stringTemplate( | ||||||
|  |             "DATE_FORMAT({0}, {1})", | ||||||
|  |             Expressions.dateTimeTemplate( | ||||||
|  |                 LocalDateTime::class.java, | ||||||
|  |                 "CONVERT_TZ({0},{1},{2})", | ||||||
|  |                 liveRoom.beginDateTime, | ||||||
|  |                 "UTC", | ||||||
|  |                 "Asia/Seoul" | ||||||
|  |             ), | ||||||
|  |             "%Y-%m-%d" | ||||||
|  |         ) | ||||||
|  |  | ||||||
|  |         return queryFactory | ||||||
|  |             .select( | ||||||
|  |                 QGetCalculateLiveQueryData( | ||||||
|  |                     member.email, | ||||||
|  |                     member.nickname, | ||||||
|  |                     formattedDate, | ||||||
|  |                     liveRoom.title, | ||||||
|  |                     liveRoom.price, | ||||||
|  |                     useCan.canUsage, | ||||||
|  |                     useCanCalculate.id.count(), | ||||||
|  |                     useCanCalculate.can.sum() | ||||||
|  |                 ) | ||||||
|  |             ) | ||||||
|  |             .from(useCanCalculate) | ||||||
|  |             .innerJoin(useCanCalculate.useCan, useCan) | ||||||
|  |             .innerJoin(useCan.room, liveRoom) | ||||||
|  |             .innerJoin(liveRoom.member, member) | ||||||
|  |             .where( | ||||||
|  |                 useCanCalculate.status.eq(UseCanCalculateStatus.RECEIVED) | ||||||
|  |                     .and(useCanCalculate.recipientCreatorId.eq(memberId)) | ||||||
|  |                     .and(liveRoom.beginDateTime.goe(startDate)) | ||||||
|  |                     .and(liveRoom.beginDateTime.loe(endDate)) | ||||||
|  |             ) | ||||||
|  |             .groupBy(liveRoom.id, useCan.canUsage) | ||||||
|  |             .orderBy(formattedDate.desc()) | ||||||
|  |             .fetch() | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,75 @@ | |||||||
|  | package kr.co.vividnext.sodalive.creator.admin.calculate | ||||||
|  |  | ||||||
|  | import kr.co.vividnext.sodalive.admin.calculate.GetCalculateLiveResponse | ||||||
|  | import kr.co.vividnext.sodalive.can.use.CanUsage | ||||||
|  | import kr.co.vividnext.sodalive.member.Member | ||||||
|  | import org.springframework.stereotype.Service | ||||||
|  | import java.time.LocalDate | ||||||
|  | import java.time.ZoneId | ||||||
|  | import java.time.format.DateTimeFormatter | ||||||
|  | import kotlin.math.roundToInt | ||||||
|  |  | ||||||
|  | @Service | ||||||
|  | class CreatorAdminCalculateService(private val repository: CreatorAdminCalculateQueryRepository) { | ||||||
|  |     fun getCalculateLive(startDateStr: String, endDateStr: String, member: Member): List<GetCalculateLiveResponse> { | ||||||
|  |         val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") | ||||||
|  |         val startDate = LocalDate.parse(startDateStr, dateTimeFormatter).atTime(0, 0, 0) | ||||||
|  |             .atZone(ZoneId.of("Asia/Seoul")) | ||||||
|  |             .withZoneSameInstant(ZoneId.of("UTC")) | ||||||
|  |             .toLocalDateTime() | ||||||
|  |  | ||||||
|  |         val endDate = LocalDate.parse(endDateStr, dateTimeFormatter).atTime(23, 59, 59) | ||||||
|  |             .atZone(ZoneId.of("Asia/Seoul")) | ||||||
|  |             .withZoneSameInstant(ZoneId.of("UTC")) | ||||||
|  |             .toLocalDateTime() | ||||||
|  |  | ||||||
|  |         return repository | ||||||
|  |             .getCalculateLive(startDate, endDate, member.id!!) | ||||||
|  |             .asSequence() | ||||||
|  |             .map { | ||||||
|  |                 val canUsageStr = if (it.canUsage == CanUsage.LIVE) { | ||||||
|  |                     "유료" | ||||||
|  |                 } else { | ||||||
|  |                     "후원" | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 val numberOfPeople = if (it.canUsage == CanUsage.LIVE) { | ||||||
|  |                     it.memberCount.toInt() | ||||||
|  |                 } else { | ||||||
|  |                     0 | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) | ||||||
|  |                 val totalKrw = it.totalAmount * 100 | ||||||
|  |  | ||||||
|  |                 // 결제수수료 : 6.6% | ||||||
|  |                 val paymentFee = totalKrw * 0.066f | ||||||
|  |  | ||||||
|  |                 // 정산금액 = (원화 - 결제수수료) 의 70% | ||||||
|  |                 val settlementAmount = (totalKrw.toFloat() - paymentFee) * 0.7 | ||||||
|  |  | ||||||
|  |                 // 원천세 = 정산금액의 3.3% | ||||||
|  |                 val tax = settlementAmount * 0.033 | ||||||
|  |  | ||||||
|  |                 // 입금액 | ||||||
|  |                 val depositAmount = settlementAmount - tax | ||||||
|  |  | ||||||
|  |                 GetCalculateLiveResponse( | ||||||
|  |                     email = it.email, | ||||||
|  |                     nickname = it.nickname, | ||||||
|  |                     date = it.date, | ||||||
|  |                     title = it.title, | ||||||
|  |                     entranceFee = it.entranceFee, | ||||||
|  |                     canUsageStr = canUsageStr, | ||||||
|  |                     numberOfPeople = numberOfPeople, | ||||||
|  |                     totalAmount = it.totalAmount, | ||||||
|  |                     totalKrw = totalKrw, | ||||||
|  |                     paymentFee = paymentFee.roundToInt(), | ||||||
|  |                     settlementAmount = settlementAmount.roundToInt(), | ||||||
|  |                     tax = tax.roundToInt(), | ||||||
|  |                     depositAmount = depositAmount.roundToInt() | ||||||
|  |                 ) | ||||||
|  |             } | ||||||
|  |             .toList() | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user