feat(settlement): 국가별 정산 비율과 적용 기간을 정의한다
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
package kr.co.vividnext.sodalive.v2.settlement.adapter.config
|
||||
|
||||
import kr.co.vividnext.sodalive.v2.settlement.domain.CountrySettlementPolicy
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
||||
@Configuration
|
||||
class CountrySettlementConfiguration {
|
||||
@Bean
|
||||
fun countrySettlementPolicy(): CountrySettlementPolicy = CountrySettlementPolicy()
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package kr.co.vividnext.sodalive.v2.settlement.adapter.out.persistence
|
||||
|
||||
import com.querydsl.core.types.dsl.CaseBuilder
|
||||
import com.querydsl.core.types.dsl.DateTimeExpression
|
||||
import com.querydsl.core.types.dsl.NumberExpression
|
||||
import com.querydsl.core.types.dsl.StringExpression
|
||||
import kr.co.vividnext.sodalive.v2.settlement.domain.CountrySettlementPolicy
|
||||
import org.springframework.stereotype.Component
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Component
|
||||
class CountrySettlementExpressions(private val policy: CountrySettlementPolicy) {
|
||||
fun newPolicyCan(eventAt: DateTimeExpression<LocalDateTime>, can: NumberExpression<Int>): NumberExpression<Int> =
|
||||
CaseBuilder().`when`(eventAt.goe(policy.effectiveAtUtc)).then(can).otherwise(0).sum().coalesce(0)
|
||||
|
||||
fun newPolicyWeightedRatioCan(
|
||||
eventAt: DateTimeExpression<LocalDateTime>,
|
||||
can: NumberExpression<Int>,
|
||||
creatorCountry: StringExpression,
|
||||
transactionCountry: StringExpression,
|
||||
individualRatio: NumberExpression<Int>? = null
|
||||
): NumberExpression<Long> {
|
||||
val creator = CaseBuilder().`when`(creatorCountry.isNull.or(creatorCountry.trim().eq("")))
|
||||
.then("KR").otherwise(creatorCountry)
|
||||
val transaction = CaseBuilder().`when`(transactionCountry.isNull.or(transactionCountry.trim().eq("")))
|
||||
.then("KR").otherwise(transactionCountry)
|
||||
val defaultRatio = CaseBuilder()
|
||||
.`when`(creator.eq("KR").and(eventAt.lt(policy.koreanDefaultRateEndExclusiveUtc))).then(75).otherwise(70)
|
||||
val sameCountryRatio = individualRatio?.coalesce(defaultRatio) ?: defaultRatio
|
||||
val ratio = CaseBuilder().`when`(creator.ne(transaction)).then(50).otherwise(sameCountryRatio)
|
||||
return CaseBuilder().`when`(eventAt.goe(policy.effectiveAtUtc))
|
||||
.then(can.longValue().multiply(ratio.longValue())).otherwise(0L).sum().coalesce(0L)
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package kr.co.vividnext.sodalive.v2.settlement.domain
|
||||
|
||||
import java.time.LocalDateTime
|
||||
|
||||
class CountrySettlementPolicy {
|
||||
val effectiveAtUtc: LocalDateTime = LocalDateTime.of(2026, 10, 31, 15, 0)
|
||||
val koreanDefaultRateEndExclusiveUtc: LocalDateTime = LocalDateTime.of(2026, 12, 31, 15, 0)
|
||||
|
||||
fun resolveNewRatio(
|
||||
creatorCountry: String?,
|
||||
transactionCountry: String?,
|
||||
individualRatio: Int?,
|
||||
eventAt: LocalDateTime
|
||||
): Int {
|
||||
val creator = creatorCountry?.takeUnless { it.isBlank() } ?: "KR"
|
||||
val transaction = transactionCountry?.takeUnless { it.isBlank() } ?: "KR"
|
||||
if (creator != transaction) {
|
||||
return 50
|
||||
}
|
||||
return individualRatio ?: if (creator == "KR" && eventAt.isBefore(koreanDefaultRateEndExclusiveUtc)) 75 else 70
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user