Skip to content

Commit

Permalink
[RELEASE] v24.12.01.01
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 authored Dec 4, 2024
2 parents 6d59750 + 01bbabd commit c74fa24
Show file tree
Hide file tree
Showing 50 changed files with 826 additions and 306 deletions.
3 changes: 3 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ resolved:
📸 스크린샷
----

🚩 추가된 SQL 운영계 실행계획
---

🤖 테스트 체크리스트
----
- [ ] 체크 미완료
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import com.few.api.repo.dao.article.command.InsertFullArticleRecordCommand
import com.few.api.repo.dao.article.query.*
import com.few.api.repo.dao.article.record.*
import com.few.data.common.code.MemberType
import jooq.jooq_dsl.tables.ArticleIfo
import jooq.jooq_dsl.tables.ArticleMst
import jooq.jooq_dsl.tables.MappingWorkbookArticle
import jooq.jooq_dsl.tables.Member
import jooq.jooq_dsl.tables.*
import jooq.jooq_dsl.tables.MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE
import org.jooq.*
import org.jooq.impl.DSL
import org.springframework.cache.annotation.Cacheable
Expand Down Expand Up @@ -163,4 +161,23 @@ class ArticleDao(
)
.where(ArticleIfo.ARTICLE_IFO.ARTICLE_MST_ID.eq(query.articleId))
.and(ArticleIfo.ARTICLE_IFO.DELETED_AT.isNull)

fun selectArticleIdsByWorkbookIdLimitDay(query: SelectAritlceIdByWorkbookIdAndDayQuery): ArticleIdRecord {
return selectArticleIdByWorkbookIdLimitDayQuery(query)
.fetch()
.map { it[MAPPING_WORKBOOK_ARTICLE.ARTICLE_ID] }
.let { ArticleIdRecord(it) }
}

fun selectArticleIdByWorkbookIdLimitDayQuery(query: SelectAritlceIdByWorkbookIdAndDayQuery) =
dslContext
.select(MAPPING_WORKBOOK_ARTICLE.ARTICLE_ID)
.from(MAPPING_WORKBOOK_ARTICLE)
.join(ArticleMst.ARTICLE_MST)
.on(MAPPING_WORKBOOK_ARTICLE.ARTICLE_ID.eq(ArticleMst.ARTICLE_MST.ID))
.where(MAPPING_WORKBOOK_ARTICLE.WORKBOOK_ID.eq(query.workbookId))
.and(ArticleMst.ARTICLE_MST.DELETED_AT.isNull)
.orderBy(MAPPING_WORKBOOK_ARTICLE.DAY_COL.asc())
.limit(query.day)
.query
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,57 @@
package com.few.api.repo.dao.article

import com.few.api.repo.dao.article.TempTable.ARTICLE_ID_COLUMN
import com.few.api.repo.dao.article.TempTable.ARTICLE_VIEW_COUNT_OFFSET_TABLE
import com.few.api.repo.dao.article.TempTable.ARTICLE_VIEW_COUNT_OFFSET_TABLE_ARTICLE_ID
import com.few.api.repo.dao.article.TempTable.ARTICLE_VIEW_COUNT_OFFSET_TABLE_CATEGORY_CD
import com.few.api.repo.dao.article.TempTable.ARTICLE_VIEW_COUNT_OFFSET_TABLE_VIEW_COUNT
import com.few.api.repo.dao.article.TempTable.EMAIL_VIEW_COUNT_TABLE
import com.few.api.repo.dao.article.TempTable.EMAIL_VIEW_COUNT_TABLE_ARTICLE_ID
import com.few.api.repo.dao.article.TempTable.EMAIL_VIEW_COUNT_TABLE_VIEW_COUNT
import com.few.api.repo.dao.article.TempTable.OFFSET_COLUMN
import com.few.api.repo.dao.article.TempTable.ROW_RANK_TABLE
import com.few.api.repo.dao.article.TempTable.ROW_RANK_TABLE_ARTICLE_ID
import com.few.api.repo.dao.article.TempTable.ROW_RANK_TABLE_OFFSET
import com.few.api.repo.dao.article.TempTable.TOTAL_VIEW_COUNT_TABLE
import com.few.api.repo.dao.article.TempTable.TOTAL_VIEW_COUNT_TABLE_ARTICLE_ID
import com.few.api.repo.dao.article.TempTable.TOTAL_VIEW_COUNT_TABLE_VIEW_COUNT
import com.few.api.repo.dao.article.TempTable.VIEW_COUNT_COLUMN
import com.few.api.repo.dao.article.command.ArticleViewCountCommand
import com.few.api.repo.dao.article.query.ArticleViewCountQuery
import com.few.api.repo.dao.article.query.SelectArticlesOrderByViewsQuery
import com.few.api.repo.dao.article.query.SelectRankByViewsQuery
import com.few.api.repo.dao.article.record.SelectArticleViewsRecord
import com.few.data.common.code.CategoryType
import jooq.jooq_dsl.tables.ArticleViewCount.ARTICLE_VIEW_COUNT
import jooq.jooq_dsl.tables.SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY
import org.jooq.DSLContext
import org.jooq.impl.DSL.*
import org.springframework.stereotype.Repository

object TempTable {
const val ARTICLE_ID_COLUMN = "ARTICLE_ID"
const val VIEW_COUNT_COLUMN = "VIEW_COUNT"
const val OFFSET_COLUMN = "OFFSET"
const val CATEGORY_CD_COLUMN = "CATEGORY_CD"

const val ROW_RANK_TABLE = "row_rank_tb"
const val ROW_RANK_TABLE_ARTICLE_ID = "$ROW_RANK_TABLE.$ARTICLE_ID_COLUMN"
const val ROW_RANK_TABLE_OFFSET = "$ROW_RANK_TABLE.$OFFSET_COLUMN"

const val EMAIL_VIEW_COUNT_TABLE = "evc"
const val EMAIL_VIEW_COUNT_TABLE_ARTICLE_ID = "$EMAIL_VIEW_COUNT_TABLE.$ARTICLE_ID_COLUMN"
const val EMAIL_VIEW_COUNT_TABLE_VIEW_COUNT = "$EMAIL_VIEW_COUNT_TABLE.$VIEW_COUNT_COLUMN"

const val TOTAL_VIEW_COUNT_TABLE = "tvc"
const val TOTAL_VIEW_COUNT_TABLE_ARTICLE_ID = "$TOTAL_VIEW_COUNT_TABLE.$ARTICLE_ID_COLUMN"
const val TOTAL_VIEW_COUNT_TABLE_VIEW_COUNT = "$TOTAL_VIEW_COUNT_TABLE.$VIEW_COUNT_COLUMN"

const val ARTICLE_VIEW_COUNT_OFFSET_TABLE = "article_view_count_offset_tb"
const val ARTICLE_VIEW_COUNT_OFFSET_TABLE_ARTICLE_ID = "$ARTICLE_VIEW_COUNT_OFFSET_TABLE.$ARTICLE_ID_COLUMN"
const val ARTICLE_VIEW_COUNT_OFFSET_TABLE_VIEW_COUNT = "$ARTICLE_VIEW_COUNT_OFFSET_TABLE.$VIEW_COUNT_COLUMN"
const val ARTICLE_VIEW_COUNT_OFFSET_TABLE_CATEGORY_CD = "$ARTICLE_VIEW_COUNT_OFFSET_TABLE.$CATEGORY_CD_COLUMN"
}

@Repository
class ArticleViewCountDao(
private val dslContext: DSLContext,
Expand Down Expand Up @@ -53,18 +94,40 @@ class ArticleViewCountDao(
}

fun selectRankByViewsQuery(query: SelectRankByViewsQuery) = dslContext
.select(field("row_rank_tb.offset", Long::class.java))
.select(field(ROW_RANK_TABLE_OFFSET, Long::class.java))
.from(
dslContext.select(
ARTICLE_VIEW_COUNT.ARTICLE_ID,
field(TOTAL_VIEW_COUNT_TABLE_ARTICLE_ID, Long::class.java).`as`(ARTICLE_ID_COLUMN),
rowNumber().over(
orderBy(ARTICLE_VIEW_COUNT.VIEW_COUNT.desc(), ARTICLE_VIEW_COUNT.ARTICLE_ID.desc())
).`as`("offset")
).from(ARTICLE_VIEW_COUNT)
.where(ARTICLE_VIEW_COUNT.DELETED_AT.isNull)
.asTable("row_rank_tb")
)
.where(field("row_rank_tb.${ARTICLE_VIEW_COUNT.ARTICLE_ID.name}")!!.eq(query.articleId))
orderBy(
field(TOTAL_VIEW_COUNT_TABLE_VIEW_COUNT).desc(),
field(TOTAL_VIEW_COUNT_TABLE_ARTICLE_ID).desc()
)
).`as`(OFFSET_COLUMN)
).from(
dslContext.select(
ARTICLE_VIEW_COUNT.ARTICLE_ID,
ARTICLE_VIEW_COUNT.VIEW_COUNT.plus(
ifnull(field(EMAIL_VIEW_COUNT_TABLE_VIEW_COUNT, Long::class.java), 0)
).`as`(VIEW_COUNT_COLUMN)
).from(ARTICLE_VIEW_COUNT)
.leftJoin(
dslContext.select(
SEND_ARTICLE_EVENT_HISTORY.ARTICLE_ID,
count(SEND_ARTICLE_EVENT_HISTORY.ARTICLE_ID).`as`(VIEW_COUNT_COLUMN)
).from(
SEND_ARTICLE_EVENT_HISTORY
).groupBy(
SEND_ARTICLE_EVENT_HISTORY.ARTICLE_ID
).asTable(EMAIL_VIEW_COUNT_TABLE)
).on(
ARTICLE_VIEW_COUNT.ARTICLE_ID.eq(
field(EMAIL_VIEW_COUNT_TABLE_ARTICLE_ID, Long::class.java)
)
)
.asTable(TOTAL_VIEW_COUNT_TABLE)
).asTable(ROW_RANK_TABLE)
).where(field(ROW_RANK_TABLE_ARTICLE_ID).eq(query.articleId))
.query

fun selectArticlesOrderByViews(query: SelectArticlesOrderByViewsQuery): List<SelectArticleViewsRecord> {
Expand All @@ -74,19 +137,43 @@ class ArticleViewCountDao(

fun selectArticlesOrderByViewsQuery(query: SelectArticlesOrderByViewsQuery) = dslContext
.select(
field("article_view_count_offset_tb.article_id").`as`(SelectArticleViewsRecord::articleId.name),
field("article_view_count_offset_tb.view_count").`as`(SelectArticleViewsRecord::views.name)
field(ARTICLE_VIEW_COUNT_OFFSET_TABLE_ARTICLE_ID).`as`(SelectArticleViewsRecord::articleId.name),
field(ARTICLE_VIEW_COUNT_OFFSET_TABLE_VIEW_COUNT).`as`(SelectArticleViewsRecord::views.name)
).from(
dslContext.select()
.from(ARTICLE_VIEW_COUNT)
.where(ARTICLE_VIEW_COUNT.DELETED_AT.isNull)
.orderBy(ARTICLE_VIEW_COUNT.VIEW_COUNT.desc(), ARTICLE_VIEW_COUNT.ARTICLE_ID.desc())
.limit(query.offset, Long.MAX_VALUE)
.asTable("article_view_count_offset_tb")
dslContext.select(
ARTICLE_VIEW_COUNT.ARTICLE_ID,
ARTICLE_VIEW_COUNT.VIEW_COUNT.plus(
ifnull(field(EMAIL_VIEW_COUNT_TABLE_VIEW_COUNT, Long::class.java), 0)
).`as`(VIEW_COUNT_COLUMN),
ARTICLE_VIEW_COUNT.CATEGORY_CD
).from(ARTICLE_VIEW_COUNT)
.leftJoin(
dslContext.select(
SEND_ARTICLE_EVENT_HISTORY.ARTICLE_ID,
count(SEND_ARTICLE_EVENT_HISTORY.ARTICLE_ID).`as`(VIEW_COUNT_COLUMN)
).from(
SEND_ARTICLE_EVENT_HISTORY
).groupBy(
SEND_ARTICLE_EVENT_HISTORY.ARTICLE_ID
).asTable(
EMAIL_VIEW_COUNT_TABLE
)
).on(
ARTICLE_VIEW_COUNT.ARTICLE_ID.eq(
field(
EMAIL_VIEW_COUNT_TABLE_ARTICLE_ID,
Long::class.java
)
)
).orderBy(
field(VIEW_COUNT_COLUMN, Long::class.java).desc(),
ARTICLE_VIEW_COUNT.ARTICLE_ID.desc()
).limit(query.offset, Long.MAX_VALUE)
.asTable(ARTICLE_VIEW_COUNT_OFFSET_TABLE)
).where(
when {
(query.category == CategoryType.All) -> noCondition()
else -> field("article_view_count_offset_tb.category_cd").eq(query.category.code)
else -> field(ARTICLE_VIEW_COUNT_OFFSET_TABLE_CATEGORY_CD).eq(query.category.code)
}
).limit(11)
.query
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.few.api.repo.dao.article.query

data class SelectAritlceIdByWorkbookIdAndDayQuery(
val workbookId: Long,
val day: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.few.api.repo.dao.article.record

data class ArticleIdRecord(
val articleIds: List<Long>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.few.api.repo.dao.problem

import com.few.api.repo.dao.problem.command.InsertProblemsCommand
import com.few.api.repo.dao.problem.query.SelectProblemAnswerQuery
import com.few.api.repo.dao.problem.query.SelectProblemIdByArticleIdsQuery
import com.few.api.repo.dao.problem.query.SelectProblemQuery
import com.few.api.repo.dao.problem.query.SelectProblemsByArticleIdQuery
import com.few.api.repo.dao.problem.record.ProblemIdAndArticleIdRecord
import com.few.api.repo.dao.problem.record.ProblemIdsRecord
import com.few.api.repo.dao.problem.record.SelectProblemAnswerRecord
import com.few.api.repo.dao.problem.record.SelectProblemRecord
Expand All @@ -28,7 +30,8 @@ class ProblemDao(
Problem.PROBLEM.ID.`as`(SelectProblemRecord::id.name),
Problem.PROBLEM.TITLE.`as`(SelectProblemRecord::title.name),
DSL.field("JSON_UNQUOTE({0})", String::class.java, Problem.PROBLEM.CONTENTS)
.`as`(SelectProblemRecord::contents.name)
.`as`(SelectProblemRecord::contents.name),
Problem.PROBLEM.ARTICLE_ID.`as`(SelectProblemRecord::articleId.name)
)
.from(Problem.PROBLEM)
.where(Problem.PROBLEM.ID.eq(query.problemId))
Expand Down Expand Up @@ -77,4 +80,18 @@ class ProblemDao(
.set(Problem.PROBLEM.CONTENTS, JSON.valueOf(contentsJsonMapper.toJson(it.contents)))
.set(Problem.PROBLEM.ANSWER, it.answer)
.set(Problem.PROBLEM.EXPLANATION, it.explanation)

fun selectProblemIdByArticleIds(query: SelectProblemIdByArticleIdsQuery): List<ProblemIdAndArticleIdRecord> {
return selectProblemIdByArticleIdsQuery(query)
.fetchInto(ProblemIdAndArticleIdRecord::class.java)
}

fun selectProblemIdByArticleIdsQuery(query: SelectProblemIdByArticleIdsQuery) = dslContext
.select(
Problem.PROBLEM.ID.`as`(ProblemIdAndArticleIdRecord::problemId.name),
Problem.PROBLEM.ARTICLE_ID.`as`(ProblemIdAndArticleIdRecord::articleId.name)
)
.from(Problem.PROBLEM)
.where(Problem.PROBLEM.ARTICLE_ID.`in`(query.articleIds))
.and(Problem.PROBLEM.DELETED_AT.isNull)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.few.api.repo.dao.problem

import com.few.api.repo.dao.problem.command.InsertSubmitHistoryCommand
import com.few.api.repo.dao.problem.query.SelectSubmittedProblemIdsQuery
import com.few.api.repo.dao.problem.record.SubmittedProblemIdsRecord
import jooq.jooq_dsl.Tables.SUBMIT_HISTORY
import org.jooq.DSLContext
import org.springframework.stereotype.Repository
Expand All @@ -24,4 +26,18 @@ class SubmitHistoryDao(
.set(SUBMIT_HISTORY.MEMBER_ID, command.memberId)
.set(SUBMIT_HISTORY.SUBMIT_ANS, command.submitAns)
.set(SUBMIT_HISTORY.IS_SOLVED, command.isSolved)

fun selectProblemIdByProblemIds(query: SelectSubmittedProblemIdsQuery): SubmittedProblemIdsRecord {
return selectProblemIdByProblemIdsQuery(query)
.fetch()
.map { it[SUBMIT_HISTORY.PROBLEM_ID] }
.let { SubmittedProblemIdsRecord(it) }
}

fun selectProblemIdByProblemIdsQuery(query: SelectSubmittedProblemIdsQuery) = dslContext
.select(SUBMIT_HISTORY.PROBLEM_ID)
.from(SUBMIT_HISTORY)
.where(SUBMIT_HISTORY.PROBLEM_ID.`in`(query.problemIds))
.and(SUBMIT_HISTORY.MEMBER_ID.eq(query.memberId))
.and(SUBMIT_HISTORY.DELETED_AT.isNull)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.few.api.repo.dao.problem.query

data class SelectProblemIdByArticleIdsQuery(
val articleIds: Set<Long>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.few.api.repo.dao.problem.query

data class SelectSubmittedProblemIdsQuery(
val memberId: Long,
val problemIds: List<Long>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.few.api.repo.dao.problem.record

data class ProblemIdAndArticleIdRecord(
val problemId: Long,
val articleId: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ data class SelectProblemRecord(
val id: Long,
val title: String,
val contents: String,
val articleId: Long,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.few.api.repo.dao.problem.record

data class SubmittedProblemIdsRecord(
val problemIds: List<Long>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,18 @@ class SubscriptionDao(
.from(SUBSCRIPTION)
.where(SUBSCRIPTION.MEMBER_ID.eq(query.memberId))
.and(SUBSCRIPTION.DELETED_AT.isNull)

fun selectWorkbookIdAndProgressByMember(query: SelectSubscriptionSendStatusQuery): List<SubscriptionProgressRecord> {
return selectWorkbookIdAndProgressByMemberQuery(query)
.fetchInto(SubscriptionProgressRecord::class.java)
}

fun selectWorkbookIdAndProgressByMemberQuery(query: SelectSubscriptionSendStatusQuery) =
dslContext.select(
SUBSCRIPTION.TARGET_WORKBOOK_ID.`as`(SubscriptionProgressRecord::workbookId.name),
SUBSCRIPTION.PROGRESS.add(1).`as`(SubscriptionProgressRecord::day.name)
)
.from(SUBSCRIPTION)
.where(SUBSCRIPTION.MEMBER_ID.eq(query.memberId))
.and(SUBSCRIPTION.DELETED_AT.isNull)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.few.api.repo.dao.subscription.record

data class SubscriptionProgressRecord(
val workbookId: Long,
val day: Int,
)
Loading

0 comments on commit c74fa24

Please sign in to comment.