fix(agent-ratio): 에이전트 정산 비율 수정 충돌 처리를 안정화한다
This commit is contained in:
@@ -27,7 +27,7 @@ class AdminAgentSettlementRatioService(
|
||||
|
||||
val ratio = request.toEntity()
|
||||
ratio.member = agent
|
||||
saveRatioOrThrow(request, ratio)
|
||||
saveRatioOrThrow(ratio)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -39,11 +39,11 @@ class AdminAgentSettlementRatioService(
|
||||
?: throw SodaException(messageKey = "partner.agent.ratio.not_found")
|
||||
validateNewEffectiveFrom(existing.effectiveFrom, request.effectiveFrom)
|
||||
existing.close(request.effectiveFrom)
|
||||
repository.save(existing)
|
||||
repository.saveAndFlush(existing)
|
||||
|
||||
val ratio = request.toEntity()
|
||||
ratio.member = agent
|
||||
saveRatioOrThrow(request, ratio)
|
||||
saveRatioOrThrow(ratio)
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@@ -95,16 +95,20 @@ class AdminAgentSettlementRatioService(
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveRatioOrThrow(
|
||||
request: CreateAgentSettlementRatioRequest,
|
||||
ratio: AgentSettlementRatio
|
||||
) {
|
||||
private fun saveRatioOrThrow(ratio: AgentSettlementRatio) {
|
||||
try {
|
||||
repository.saveAndFlush(ratio)
|
||||
} catch (e: DataIntegrityViolationException) {
|
||||
repository.findFirstByMemberIdAndEffectiveToIsNull(request.memberId)
|
||||
?: throw e
|
||||
throw SodaException(messageKey = "partner.agent.ratio.invalid_effective_from")
|
||||
if (isActiveRatioConflict(e)) {
|
||||
throw SodaException(messageKey = "partner.agent.ratio.invalid_effective_from")
|
||||
}
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
private fun isActiveRatioConflict(exception: Throwable): Boolean {
|
||||
return generateSequence(exception) { it.cause }
|
||||
.mapNotNull { it.message }
|
||||
.any { it.contains("uk_agent_settlement_ratio_member_active") }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user