관리자
- 크리에이터 정산 추가데이터 insert, select 추가
This commit is contained in:
		| @@ -0,0 +1,16 @@ | |||||||
|  | package kr.co.vividnext.sodalive.admin.calculate.ratio | ||||||
|  |  | ||||||
|  | data class CreateCreatorSettlementRatioRequest( | ||||||
|  |     val memberId: Long, | ||||||
|  |     val subsidy: Int, | ||||||
|  |     val liveSettlementRatio: Int, | ||||||
|  |     val contentSettlementRatio: Int, | ||||||
|  |     val communitySettlementRatio: Int | ||||||
|  | ) { | ||||||
|  |     fun toEntity() = CreatorSettlementRatio( | ||||||
|  |         subsidy = subsidy, | ||||||
|  |         liveSettlementRatio = liveSettlementRatio, | ||||||
|  |         contentSettlementRatio = contentSettlementRatio, | ||||||
|  |         communitySettlementRatio = communitySettlementRatio | ||||||
|  |     ) | ||||||
|  | } | ||||||
| @@ -0,0 +1,20 @@ | |||||||
|  | package kr.co.vividnext.sodalive.admin.calculate.ratio | ||||||
|  |  | ||||||
|  | import kr.co.vividnext.sodalive.common.BaseEntity | ||||||
|  | import kr.co.vividnext.sodalive.member.Member | ||||||
|  | import javax.persistence.Entity | ||||||
|  | import javax.persistence.FetchType | ||||||
|  | import javax.persistence.JoinColumn | ||||||
|  | import javax.persistence.OneToOne | ||||||
|  |  | ||||||
|  | @Entity | ||||||
|  | data class CreatorSettlementRatio( | ||||||
|  |     val subsidy: Int, | ||||||
|  |     val liveSettlementRatio: Int, | ||||||
|  |     val contentSettlementRatio: Int, | ||||||
|  |     val communitySettlementRatio: Int | ||||||
|  | ) : BaseEntity() { | ||||||
|  |     @OneToOne(fetch = FetchType.LAZY) | ||||||
|  |     @JoinColumn(name = "member_id", nullable = false) | ||||||
|  |     var member: Member? = null | ||||||
|  | } | ||||||
| @@ -0,0 +1,30 @@ | |||||||
|  | package kr.co.vividnext.sodalive.admin.calculate.ratio | ||||||
|  |  | ||||||
|  | import kr.co.vividnext.sodalive.common.ApiResponse | ||||||
|  | import org.springframework.data.domain.Pageable | ||||||
|  | import org.springframework.security.access.prepost.PreAuthorize | ||||||
|  | import org.springframework.web.bind.annotation.GetMapping | ||||||
|  | import org.springframework.web.bind.annotation.PostMapping | ||||||
|  | import org.springframework.web.bind.annotation.RequestBody | ||||||
|  | import org.springframework.web.bind.annotation.RequestMapping | ||||||
|  | import org.springframework.web.bind.annotation.RestController | ||||||
|  |  | ||||||
|  | @RestController | ||||||
|  | @PreAuthorize("hasRole('ADMIN')") | ||||||
|  | @RequestMapping("/admin/calculate/ratio") | ||||||
|  | class CreatorSettlementRatioController(private val service: CreatorSettlementRatioService) { | ||||||
|  |     @PostMapping | ||||||
|  |     fun createCreatorSettlementRatio( | ||||||
|  |         @RequestBody request: CreateCreatorSettlementRatioRequest | ||||||
|  |     ) = ApiResponse.ok(service.createCreatorSettlementRatio(request)) | ||||||
|  |  | ||||||
|  |     @GetMapping | ||||||
|  |     fun getCreatorSettlementRatio( | ||||||
|  |         pageable: Pageable | ||||||
|  |     ) = ApiResponse.ok( | ||||||
|  |         service.getCreatorSettlementRatio( | ||||||
|  |             offset = pageable.offset, | ||||||
|  |             limit = pageable.pageSize.toLong() | ||||||
|  |         ) | ||||||
|  |     ) | ||||||
|  | } | ||||||
| @@ -0,0 +1,46 @@ | |||||||
|  | package kr.co.vividnext.sodalive.admin.calculate.ratio | ||||||
|  |  | ||||||
|  | import com.querydsl.jpa.impl.JPAQueryFactory | ||||||
|  | import kr.co.vividnext.sodalive.admin.calculate.ratio.QCreatorSettlementRatio.creatorSettlementRatio | ||||||
|  | import kr.co.vividnext.sodalive.member.QMember.member | ||||||
|  | import org.springframework.data.jpa.repository.JpaRepository | ||||||
|  |  | ||||||
|  | interface CreatorSettlementRatioRepository : | ||||||
|  |     JpaRepository<CreatorSettlementRatio, Long>, | ||||||
|  |     CreatorSettlementRatioQueryRepository | ||||||
|  |  | ||||||
|  | interface CreatorSettlementRatioQueryRepository { | ||||||
|  |     fun getCreatorSettlementRatio(offset: Long, limit: Long): List<GetCreatorSettlementRatioItem> | ||||||
|  |     fun getCreatorSettlementRatioTotalCount(): Int | ||||||
|  | } | ||||||
|  |  | ||||||
|  | class CreatorSettlementRatioQueryRepositoryImpl( | ||||||
|  |     private val queryFactory: JPAQueryFactory | ||||||
|  | ) : CreatorSettlementRatioQueryRepository { | ||||||
|  |     override fun getCreatorSettlementRatio(offset: Long, limit: Long): List<GetCreatorSettlementRatioItem> { | ||||||
|  |         return queryFactory | ||||||
|  |             .select( | ||||||
|  |                 QGetCreatorSettlementRatioItem( | ||||||
|  |                     member.nickname, | ||||||
|  |                     creatorSettlementRatio.subsidy, | ||||||
|  |                     creatorSettlementRatio.liveSettlementRatio, | ||||||
|  |                     creatorSettlementRatio.contentSettlementRatio, | ||||||
|  |                     creatorSettlementRatio.communitySettlementRatio | ||||||
|  |                 ) | ||||||
|  |             ) | ||||||
|  |             .from(creatorSettlementRatio) | ||||||
|  |             .innerJoin(creatorSettlementRatio.member, member) | ||||||
|  |             .orderBy(creatorSettlementRatio.id.asc()) | ||||||
|  |             .offset(offset) | ||||||
|  |             .limit(limit) | ||||||
|  |             .fetch() | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     override fun getCreatorSettlementRatioTotalCount(): Int { | ||||||
|  |         return queryFactory | ||||||
|  |             .select(creatorSettlementRatio.id) | ||||||
|  |             .from(creatorSettlementRatio) | ||||||
|  |             .fetch() | ||||||
|  |             .size | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,37 @@ | |||||||
|  | package kr.co.vividnext.sodalive.admin.calculate.ratio | ||||||
|  |  | ||||||
|  | import kr.co.vividnext.sodalive.common.SodaException | ||||||
|  | import kr.co.vividnext.sodalive.member.MemberRepository | ||||||
|  | import kr.co.vividnext.sodalive.member.MemberRole | ||||||
|  | import org.springframework.data.repository.findByIdOrNull | ||||||
|  | import org.springframework.stereotype.Service | ||||||
|  | import org.springframework.transaction.annotation.Transactional | ||||||
|  |  | ||||||
|  | @Service | ||||||
|  | class CreatorSettlementRatioService( | ||||||
|  |     private val repository: CreatorSettlementRatioRepository, | ||||||
|  |     private val memberRepository: MemberRepository | ||||||
|  | ) { | ||||||
|  |     @Transactional | ||||||
|  |     fun createCreatorSettlementRatio(request: CreateCreatorSettlementRatioRequest) { | ||||||
|  |         val creatorSettlementRatio = request.toEntity() | ||||||
|  |  | ||||||
|  |         val creator = memberRepository.findByIdOrNull(request.memberId) | ||||||
|  |             ?: throw SodaException("잘못된 크리에이터 입니다.") | ||||||
|  |  | ||||||
|  |         if (creator.role != MemberRole.CREATOR) { | ||||||
|  |             throw SodaException("잘못된 크리에이터 입니다.") | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         creatorSettlementRatio.member = creator | ||||||
|  |         repository.save(creatorSettlementRatio) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Transactional(readOnly = true) | ||||||
|  |     fun getCreatorSettlementRatio(offset: Long, limit: Long): GetCreatorSettlementRatioResponse { | ||||||
|  |         val totalCount = repository.getCreatorSettlementRatioTotalCount() | ||||||
|  |         val items = repository.getCreatorSettlementRatio(offset, limit) | ||||||
|  |  | ||||||
|  |         return GetCreatorSettlementRatioResponse(totalCount, items) | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,16 @@ | |||||||
|  | package kr.co.vividnext.sodalive.admin.calculate.ratio | ||||||
|  |  | ||||||
|  | import com.querydsl.core.annotations.QueryProjection | ||||||
|  |  | ||||||
|  | data class GetCreatorSettlementRatioResponse( | ||||||
|  |     val totalCount: Int, | ||||||
|  |     val items: List<GetCreatorSettlementRatioItem> | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | data class GetCreatorSettlementRatioItem @QueryProjection constructor( | ||||||
|  |     val nickname: String, | ||||||
|  |     val subsidy: Int, | ||||||
|  |     val liveSettlementRatio: Int, | ||||||
|  |     val contentSettlementRatio: Int, | ||||||
|  |     val communitySettlementRatio: Int | ||||||
|  | ) | ||||||
		Reference in New Issue
	
	Block a user