Skip to content

Commit

Permalink
feat: 포즈 집계처리
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Aug 3, 2024
1 parent afdcace commit ced65ff
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 6 deletions.
22 changes: 16 additions & 6 deletions sql/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ CREATE TABLE `image_metadata`
`modified_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '수정일',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=200000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE INDEX uid ON image_metadata (uid);
CREATE INDEX type ON image_metadata (type);
CREATE INDEX idx__uid__type ON image_metadata (uid, type);

-- 문의하기
CREATE TABLE `discussion`
Expand All @@ -142,8 +141,7 @@ CREATE TABLE `discussion`
`modified_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '수정일',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=200000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE INDEX uid ON discussion (uid);

CREATE INDEX idx__uid ON discussion (uid);

-- 문의하기 답변
CREATE TABLE `discussion_comment`
Expand All @@ -157,5 +155,17 @@ CREATE TABLE `discussion_comment`
`modified_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '수정일',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=200000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE INDEX discussion_id ON discussion_comment (discussion_id);
CREATE INDEX uid ON discussion_comment (uid);
CREATE INDEX idx__discussion_id ON discussion_comment (discussion_id);
CREATE INDEX idx__uid ON discussion_comment (uid);

-- 포즈 카운트 집계
CREATE TABLE `pose_count`
(
`id` bigint NOT NULL AUTO_INCREMENT,
`uid` bigint NOT NULL COMMENT 'uid',
`total_count` text NOT NULL COMMENT '집계 데이터',
`date` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '기준 날짜',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE INDEX idx__uid__date ON pose_count (uid, date);
CREATE INDEX idx__date ON pose_count (date);
25 changes: 25 additions & 0 deletions src/main/kotlin/com/hero/alignlab/domain/pose/domain/PoseCount.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.hero.alignlab.domain.pose.domain

import jakarta.persistence.*
import java.time.LocalDate

@Entity
@Table(name = "pose_count")
class PoseCount(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
val id: Long = -1,

@Column(name = "uid")
val uid: Long,

/** 집계 데이터 */
@Column(name = "total_count")
@Convert(converter = PoseTotalCountConverter::class)
val totalCount: PoseTotalCount,

/** 기준 날짜 */
@Column(name = "`date`")
val date: LocalDate,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.hero.alignlab.domain.pose.domain

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import java.io.Serializable

/** 집계 데이터를 관리 */
@JsonIgnoreProperties(ignoreUnknown = true)
data class PoseTotalCount(
val count: Map<PoseType, Int>,
) : Serializable
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.hero.alignlab.domain.pose.domain

import com.fasterxml.jackson.module.kotlin.readValue
import com.hero.alignlab.common.extension.mapper
import jakarta.persistence.AttributeConverter
import jakarta.persistence.Converter

@Converter
class PoseTotalCountConverter : AttributeConverter<PoseTotalCount, String> {
override fun convertToDatabaseColumn(attribute: PoseTotalCount): String {
return mapper.writeValueAsString(attribute)
}

override fun convertToEntityAttribute(dbData: String): PoseTotalCount {
return mapper.readValue(dbData)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.hero.alignlab.domain.pose.infrastructure

import com.hero.alignlab.domain.pose.domain.PoseCount
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
import org.springframework.transaction.annotation.Transactional

@Transactional(readOnly = true)
@Repository
interface PoseCountRepository : JpaRepository<PoseCount, Long>

0 comments on commit ced65ff

Please sign in to comment.