feat: 拆分数据库的内容到core,方便独立模块使用
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package com.lanyuanxiaoyao.leopard.core;
|
||||
|
||||
/**
|
||||
* 静态字段
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250829
|
||||
*/
|
||||
public interface Constants {
|
||||
String DATABASE_PREFIX = "leopard_";
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.lanyuanxiaoyao.leopard.core;
|
||||
|
||||
import com.blinkfox.fenix.EnableFenix;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableFenix
|
||||
@EntityScan(basePackageClasses = {JpaConfiguration.class})
|
||||
public class JpaConfiguration {
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.lanyuanxiaoyao.leopard.core.entity;
|
||||
|
||||
import com.lanyuanxiaoyao.leopard.core.Constants;
|
||||
import com.lanyuanxiaoyao.service.template.entity.SimpleEntity;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import java.time.LocalDate;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.SoftDelete;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@ToString(callSuper = true)
|
||||
@FieldNameConstants
|
||||
@Entity
|
||||
@SoftDelete
|
||||
@DynamicUpdate
|
||||
@DynamicInsert
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(name = Constants.DATABASE_PREFIX + "daily")
|
||||
public class Daily extends SimpleEntity {
|
||||
@Column(nullable = false)
|
||||
private LocalDate tradeDate;
|
||||
@Comment("开盘价")
|
||||
private Double open;
|
||||
@Comment("最高价")
|
||||
private Double high;
|
||||
@Comment("最低价")
|
||||
private Double low;
|
||||
@Comment("收盘价")
|
||||
private Double close;
|
||||
@Comment("昨收价")
|
||||
private Double previousClose;
|
||||
@Comment("涨跌额")
|
||||
private Double priceChangeAmount;
|
||||
@Comment("涨跌幅")
|
||||
private Double priceFluctuationRange;
|
||||
@Comment("成交量")
|
||||
private Double volume;
|
||||
@Comment("成交额")
|
||||
private Double turnover;
|
||||
@Comment("除权因子")
|
||||
private Double factor;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(nullable = false)
|
||||
@ToString.Exclude
|
||||
private Stock stock;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.lanyuanxiaoyao.leopard.core.entity;
|
||||
|
||||
import com.lanyuanxiaoyao.leopard.core.Constants;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.base.SimpleEnum;
|
||||
import com.lanyuanxiaoyao.service.template.entity.SimpleEntity;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Set;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.SoftDelete;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
* 股票
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250828
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@ToString(callSuper = true)
|
||||
@FieldNameConstants
|
||||
@Entity
|
||||
@SoftDelete
|
||||
@DynamicUpdate
|
||||
@DynamicInsert
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(name = Constants.DATABASE_PREFIX + "stock")
|
||||
public class Stock extends SimpleEntity {
|
||||
@Column(unique = true, nullable = false)
|
||||
@Comment("股票代码")
|
||||
private String code;
|
||||
@Column(nullable = false)
|
||||
@Comment("股票名称")
|
||||
private String name;
|
||||
@Column(nullable = false)
|
||||
@Comment("股票全称")
|
||||
private String fullname;
|
||||
@Column(nullable = false)
|
||||
@Comment("交易市场")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Market market;
|
||||
@Comment("行业")
|
||||
private String industry;
|
||||
@Comment("上市日期")
|
||||
private LocalDate listedDate;
|
||||
|
||||
@OneToMany(mappedBy = "stock", cascade = CascadeType.REMOVE)
|
||||
@ToString.Exclude
|
||||
private Set<Daily> dailies;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum Market implements SimpleEnum {
|
||||
SSE("上交所"),
|
||||
SZSE("深交所"),
|
||||
BSE("北交所");
|
||||
|
||||
private final String chineseName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.lanyuanxiaoyao.leopard.core.entity;
|
||||
|
||||
import com.lanyuanxiaoyao.leopard.core.Constants;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.base.SimpleEnum;
|
||||
import com.lanyuanxiaoyao.service.template.entity.SimpleEntity;
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Lob;
|
||||
import jakarta.persistence.Table;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.SoftDelete;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
* 任务
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250829
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@ToString(callSuper = true)
|
||||
@FieldNameConstants
|
||||
@Entity
|
||||
@SoftDelete
|
||||
@DynamicUpdate
|
||||
@DynamicInsert
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(name = Constants.DATABASE_PREFIX + "task")
|
||||
public class Task extends SimpleEntity {
|
||||
@Column(nullable = false)
|
||||
@Comment("任务名称")
|
||||
private String name;
|
||||
@Lob
|
||||
@Comment("任务描述")
|
||||
private String description;
|
||||
@Lob
|
||||
@Basic(fetch = FetchType.LAZY)
|
||||
@ToString.Exclude
|
||||
@Comment("错误信息")
|
||||
private String error;
|
||||
@Lob
|
||||
@Basic(fetch = FetchType.LAZY)
|
||||
@ToString.Exclude
|
||||
@Comment("任务结果")
|
||||
private String result;
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Comment("任务状态")
|
||||
private Status status = Status.RUNNING;
|
||||
@Comment("任务开始时间")
|
||||
private LocalDateTime launchedTime;
|
||||
@Comment("任务结束时间")
|
||||
private LocalDateTime finishedTime;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum Status implements SimpleEnum {
|
||||
RUNNING("执行中"),
|
||||
SUCCESS("成功"),
|
||||
FAILURE("失败"),
|
||||
CANCELED("取消");
|
||||
|
||||
private final String chineseName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.lanyuanxiaoyao.leopard.core.entity;
|
||||
|
||||
import com.lanyuanxiaoyao.leopard.core.Constants;
|
||||
import com.lanyuanxiaoyao.service.template.entity.SimpleEntity;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.SoftDelete;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@ToString(callSuper = true)
|
||||
@FieldNameConstants
|
||||
@Entity
|
||||
@SoftDelete
|
||||
@DynamicUpdate
|
||||
@DynamicInsert
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(name = Constants.DATABASE_PREFIX + "task_template")
|
||||
public class TaskTemplate extends SimpleEntity {
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
@Column(nullable = false, length = 500)
|
||||
private String description;
|
||||
@Column(nullable = false)
|
||||
private String chain;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.lanyuanxiaoyao.leopard.core.entity.base;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250829
|
||||
*/
|
||||
public interface SimpleEnum {
|
||||
String getChineseName();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.lanyuanxiaoyao.leopard.core.repository;
|
||||
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.Daily;
|
||||
import com.lanyuanxiaoyao.service.template.repository.SimpleRepository;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface DailyRepository extends SimpleRepository<Daily> {
|
||||
@Query("select distinct daily.tradeDate from Daily daily")
|
||||
List<LocalDate> findDistinctTradeDate();
|
||||
|
||||
@Query("select distinct daily.tradeDate from Daily daily where daily.stock.id = ?1")
|
||||
List<LocalDate> findDistinctTradeDateByStockId(Long stockId);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.lanyuanxiaoyao.leopard.core.repository;
|
||||
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.Stock;
|
||||
import com.lanyuanxiaoyao.service.template.repository.SimpleRepository;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250828
|
||||
*/
|
||||
@Repository
|
||||
public interface StockRepository extends SimpleRepository<Stock> {
|
||||
@Query("select distinct stock.industry from Stock stock where stock.industry is not null")
|
||||
List<String> findDistinctIndustries();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.lanyuanxiaoyao.leopard.core.repository;
|
||||
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.Task;
|
||||
import com.lanyuanxiaoyao.service.template.repository.SimpleRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250829
|
||||
*/
|
||||
@Repository
|
||||
public interface TaskRepository extends SimpleRepository<Task> {
|
||||
@Modifying
|
||||
@Query("update Task task set task.status = com.lanyuanxiaoyao.leopard.core.entity.Task.Status.FAILURE where task.status = com.lanyuanxiaoyao.leopard.core.entity.Task.Status.RUNNING")
|
||||
void updateAllRunningTaskToFailure();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.lanyuanxiaoyao.leopard.core.repository;
|
||||
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.TaskTemplate;
|
||||
import com.lanyuanxiaoyao.service.template.repository.SimpleRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface TaskTemplateRepository extends SimpleRepository<TaskTemplate> {
|
||||
}
|
||||
Reference in New Issue
Block a user