feat(jpa): add JPA entities and repositories aligned to Flyway; chore(deps): remove unused AMQP deps

This commit is contained in:
Your Name
2025-09-30 21:01:26 +08:00
parent e8fc04886e
commit 2f5f819c0d
11 changed files with 287 additions and 9 deletions

View File

@@ -36,10 +36,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
@@ -89,11 +85,6 @@
<version>0.7.3</version> <version>0.7.3</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>

View File

@@ -0,0 +1,62 @@
package com.mosquito.project.persistence.entity;
import jakarta.persistence.*;
import java.time.OffsetDateTime;
@Entity
@Table(name = "activities")
public class ActivityEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 255)
private String name;
@Column(name = "start_time_utc", nullable = false)
private OffsetDateTime startTimeUtc;
@Column(name = "end_time_utc", nullable = false)
private OffsetDateTime endTimeUtc;
@Column(name = "target_users_config", columnDefinition = "jsonb")
private String targetUsersConfig;
@Column(name = "page_content_config", columnDefinition = "jsonb")
private String pageContentConfig;
@Column(name = "reward_calculation_mode", length = 50)
private String rewardCalculationMode;
@Column(length = 50)
private String status;
@Column(name = "created_at")
private OffsetDateTime createdAt;
@Column(name = "updated_at")
private OffsetDateTime updatedAt;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public OffsetDateTime getStartTimeUtc() { return startTimeUtc; }
public void setStartTimeUtc(OffsetDateTime startTimeUtc) { this.startTimeUtc = startTimeUtc; }
public OffsetDateTime getEndTimeUtc() { return endTimeUtc; }
public void setEndTimeUtc(OffsetDateTime endTimeUtc) { this.endTimeUtc = endTimeUtc; }
public String getTargetUsersConfig() { return targetUsersConfig; }
public void setTargetUsersConfig(String targetUsersConfig) { this.targetUsersConfig = targetUsersConfig; }
public String getPageContentConfig() { return pageContentConfig; }
public void setPageContentConfig(String pageContentConfig) { this.pageContentConfig = pageContentConfig; }
public String getRewardCalculationMode() { return rewardCalculationMode; }
public void setRewardCalculationMode(String rewardCalculationMode) { this.rewardCalculationMode = rewardCalculationMode; }
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
public OffsetDateTime getCreatedAt() { return createdAt; }
public void setCreatedAt(OffsetDateTime createdAt) { this.createdAt = createdAt; }
public OffsetDateTime getUpdatedAt() { return updatedAt; }
public void setUpdatedAt(OffsetDateTime updatedAt) { this.updatedAt = updatedAt; }
}

View File

@@ -0,0 +1,41 @@
package com.mosquito.project.persistence.entity;
import jakarta.persistence.*;
@Entity
@Table(name = "activity_rewards")
public class ActivityRewardEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "activity_id", nullable = false)
private Long activityId;
@Column(name = "invite_threshold", nullable = false)
private Integer inviteThreshold;
@Column(name = "reward_type", nullable = false, length = 50)
private String rewardType;
@Column(name = "reward_value", nullable = false, length = 255)
private String rewardValue;
@Column(name = "skip_validation", nullable = false)
private Boolean skipValidation = Boolean.FALSE;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public Long getActivityId() { return activityId; }
public void setActivityId(Long activityId) { this.activityId = activityId; }
public Integer getInviteThreshold() { return inviteThreshold; }
public void setInviteThreshold(Integer inviteThreshold) { this.inviteThreshold = inviteThreshold; }
public String getRewardType() { return rewardType; }
public void setRewardType(String rewardType) { this.rewardType = rewardType; }
public String getRewardValue() { return rewardValue; }
public void setRewardValue(String rewardValue) { this.rewardValue = rewardValue; }
public Boolean getSkipValidation() { return skipValidation; }
public void setSkipValidation(Boolean skipValidation) { this.skipValidation = skipValidation; }
}

View File

@@ -0,0 +1,47 @@
package com.mosquito.project.persistence.entity;
import jakarta.persistence.*;
import java.time.OffsetDateTime;
@Entity
@Table(name = "api_keys")
public class ApiKeyEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 255)
private String name;
@Column(name = "key_hash", nullable = false, length = 255, unique = true)
private String keyHash;
@Column(nullable = false, length = 255)
private String salt;
@Column(name = "created_at")
private OffsetDateTime createdAt;
@Column(name = "revoked_at")
private OffsetDateTime revokedAt;
@Column(name = "last_used_at")
private OffsetDateTime lastUsedAt;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getKeyHash() { return keyHash; }
public void setKeyHash(String keyHash) { this.keyHash = keyHash; }
public String getSalt() { return salt; }
public void setSalt(String salt) { this.salt = salt; }
public OffsetDateTime getCreatedAt() { return createdAt; }
public void setCreatedAt(OffsetDateTime createdAt) { this.createdAt = createdAt; }
public OffsetDateTime getRevokedAt() { return revokedAt; }
public void setRevokedAt(OffsetDateTime revokedAt) { this.revokedAt = revokedAt; }
public OffsetDateTime getLastUsedAt() { return lastUsedAt; }
public void setLastUsedAt(OffsetDateTime lastUsedAt) { this.lastUsedAt = lastUsedAt; }
}

View File

@@ -0,0 +1,47 @@
package com.mosquito.project.persistence.entity;
import jakarta.persistence.*;
import java.time.LocalDate;
@Entity
@Table(name = "daily_activity_stats")
public class DailyActivityStatsEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "activity_id", nullable = false)
private Long activityId;
@Column(name = "stat_date", nullable = false)
private LocalDate statDate;
@Column(name = "views", nullable = false)
private Integer views;
@Column(name = "shares", nullable = false)
private Integer shares;
@Column(name = "new_registrations", nullable = false)
private Integer newRegistrations;
@Column(name = "conversions", nullable = false)
private Integer conversions;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public Long getActivityId() { return activityId; }
public void setActivityId(Long activityId) { this.activityId = activityId; }
public LocalDate getStatDate() { return statDate; }
public void setStatDate(LocalDate statDate) { this.statDate = statDate; }
public Integer getViews() { return views; }
public void setViews(Integer views) { this.views = views; }
public Integer getShares() { return shares; }
public void setShares(Integer shares) { this.shares = shares; }
public Integer getNewRegistrations() { return newRegistrations; }
public void setNewRegistrations(Integer newRegistrations) { this.newRegistrations = newRegistrations; }
public Integer getConversions() { return conversions; }
public void setConversions(Integer conversions) { this.conversions = conversions; }
}

View File

@@ -0,0 +1,37 @@
package com.mosquito.project.persistence.entity;
import jakarta.persistence.*;
import java.math.BigDecimal;
@Entity
@Table(name = "multi_level_reward_rules")
public class MultiLevelRewardRuleEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "activity_id", nullable = false)
private Long activityId;
@Column(nullable = false)
private Integer level;
@Column(name = "reward_value", nullable = false, precision = 10, scale = 2)
private BigDecimal rewardValue;
@Column(name = "is_percentage")
private Boolean percentage;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public Long getActivityId() { return activityId; }
public void setActivityId(Long activityId) { this.activityId = activityId; }
public Integer getLevel() { return level; }
public void setLevel(Integer level) { this.level = level; }
public BigDecimal getRewardValue() { return rewardValue; }
public void setRewardValue(BigDecimal rewardValue) { this.rewardValue = rewardValue; }
public Boolean getPercentage() { return percentage; }
public void setPercentage(Boolean percentage) { this.percentage = percentage; }
}

View File

@@ -0,0 +1,8 @@
package com.mosquito.project.persistence.repository;
import com.mosquito.project.persistence.entity.ActivityEntity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ActivityRepository extends JpaRepository<ActivityEntity, Long> {
}

View File

@@ -0,0 +1,11 @@
package com.mosquito.project.persistence.repository;
import com.mosquito.project.persistence.entity.ActivityRewardEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface ActivityRewardRepository extends JpaRepository<ActivityRewardEntity, Long> {
List<ActivityRewardEntity> findByActivityIdOrderByInviteThresholdAsc(Long activityId);
}

View File

@@ -0,0 +1,11 @@
package com.mosquito.project.persistence.repository;
import com.mosquito.project.persistence.entity.ApiKeyEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional;
public interface ApiKeyRepository extends JpaRepository<ApiKeyEntity, Long> {
Optional<ApiKeyEntity> findByKeyHash(String keyHash);
}

View File

@@ -0,0 +1,12 @@
package com.mosquito.project.persistence.repository;
import com.mosquito.project.persistence.entity.DailyActivityStatsEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import java.time.LocalDate;
import java.util.Optional;
public interface DailyActivityStatsRepository extends JpaRepository<DailyActivityStatsEntity, Long> {
Optional<DailyActivityStatsEntity> findByActivityIdAndStatDate(Long activityId, LocalDate statDate);
}

View File

@@ -0,0 +1,11 @@
package com.mosquito.project.persistence.repository;
import com.mosquito.project.persistence.entity.MultiLevelRewardRuleEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface MultiLevelRewardRuleRepository extends JpaRepository<MultiLevelRewardRuleEntity, Long> {
List<MultiLevelRewardRuleEntity> findByActivityIdOrderByLevelAsc(Long activityId);
}