feat(agent-ratio): 에이전트 정산 비율 관리 기능을 추가한다
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package kr.co.vividnext.sodalive.partner.agent.ratio
|
||||
|
||||
import kr.co.vividnext.sodalive.common.BaseEntity
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import java.time.LocalDateTime
|
||||
import javax.persistence.Column
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.FetchType
|
||||
import javax.persistence.JoinColumn
|
||||
import javax.persistence.ManyToOne
|
||||
|
||||
@Entity
|
||||
class AgentSettlementRatio(
|
||||
var settlementRatio: Int,
|
||||
@Column(nullable = false)
|
||||
var effectiveFrom: LocalDateTime
|
||||
) : BaseEntity() {
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "member_id", nullable = false)
|
||||
var member: Member? = null
|
||||
|
||||
var effectiveTo: LocalDateTime? = null
|
||||
|
||||
fun close(effectiveTo: LocalDateTime) {
|
||||
this.effectiveTo = effectiveTo
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package kr.co.vividnext.sodalive.partner.agent.ratio
|
||||
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory
|
||||
import kr.co.vividnext.sodalive.member.QMember.member
|
||||
import kr.co.vividnext.sodalive.partner.agent.ratio.QAgentSettlementRatio.agentSettlementRatio
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
|
||||
interface AgentSettlementRatioRepository :
|
||||
JpaRepository<AgentSettlementRatio, Long>,
|
||||
AgentSettlementRatioQueryRepository {
|
||||
fun findFirstByMemberIdAndEffectiveToIsNull(memberId: Long): AgentSettlementRatio?
|
||||
fun findAllByMemberIdOrderByEffectiveFromAsc(memberId: Long): List<AgentSettlementRatio>
|
||||
}
|
||||
|
||||
interface AgentSettlementRatioQueryRepository {
|
||||
fun getAgentSettlementRatio(offset: Long, limit: Long): List<GetAgentSettlementRatioItem>
|
||||
fun getAgentSettlementRatioTotalCount(): Int
|
||||
}
|
||||
|
||||
class AgentSettlementRatioQueryRepositoryImpl(
|
||||
private val queryFactory: JPAQueryFactory
|
||||
) : AgentSettlementRatioQueryRepository {
|
||||
override fun getAgentSettlementRatio(offset: Long, limit: Long): List<GetAgentSettlementRatioItem> {
|
||||
return queryFactory
|
||||
.select(
|
||||
QGetAgentSettlementRatioItem(
|
||||
member.id,
|
||||
member.nickname,
|
||||
agentSettlementRatio.settlementRatio,
|
||||
agentSettlementRatio.effectiveFrom,
|
||||
agentSettlementRatio.effectiveTo
|
||||
)
|
||||
)
|
||||
.from(agentSettlementRatio)
|
||||
.innerJoin(agentSettlementRatio.member, member)
|
||||
.orderBy(agentSettlementRatio.id.asc())
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
.fetch()
|
||||
}
|
||||
|
||||
override fun getAgentSettlementRatioTotalCount(): Int {
|
||||
return queryFactory
|
||||
.select(agentSettlementRatio.id.count())
|
||||
.from(agentSettlementRatio)
|
||||
.fetchOne()
|
||||
?.toInt()
|
||||
?: 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package kr.co.vividnext.sodalive.partner.agent.ratio
|
||||
|
||||
import java.time.LocalDateTime
|
||||
|
||||
data class CreateAgentSettlementRatioRequest(
|
||||
val memberId: Long,
|
||||
val settlementRatio: Int,
|
||||
val effectiveFrom: LocalDateTime
|
||||
) {
|
||||
fun toEntity() = AgentSettlementRatio(
|
||||
settlementRatio = settlementRatio,
|
||||
effectiveFrom = effectiveFrom
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package kr.co.vividnext.sodalive.partner.agent.ratio
|
||||
|
||||
import com.querydsl.core.annotations.QueryProjection
|
||||
import java.time.LocalDateTime
|
||||
|
||||
data class GetAgentSettlementRatioResponse(
|
||||
val totalCount: Int,
|
||||
val items: List<GetAgentSettlementRatioItem>
|
||||
)
|
||||
|
||||
data class GetAgentSettlementRatioItem @QueryProjection constructor(
|
||||
val memberId: Long,
|
||||
val nickname: String,
|
||||
val settlementRatio: Int,
|
||||
val effectiveFrom: LocalDateTime,
|
||||
val effectiveTo: LocalDateTime?
|
||||
)
|
||||
Reference in New Issue
Block a user