feat: 股票集中显示股票对应的得分
This commit is contained in:
@@ -2,10 +2,11 @@ package com.lanyuanxiaoyao.leopard.core.entity;
|
||||
|
||||
import com.lanyuanxiaoyao.leopard.core.Constants;
|
||||
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.ManyToMany;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
@@ -31,7 +32,7 @@ public class StockCollection extends SimpleEntity {
|
||||
@Column(nullable = false)
|
||||
private String description;
|
||||
|
||||
@ManyToMany
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
@ToString.Exclude
|
||||
private Set<Stock> stocks;
|
||||
private Set<StockScore> scores;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.lanyuanxiaoyao.leopard.core.entity;
|
||||
|
||||
import com.lanyuanxiaoyao.leopard.core.Constants;
|
||||
import com.lanyuanxiaoyao.service.template.entity.SimpleEntity;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
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.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@ToString(callSuper = true)
|
||||
@FieldNameConstants
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@DynamicInsert
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(name = Constants.DATABASE_PREFIX + "stock_score")
|
||||
public class StockScore extends SimpleEntity {
|
||||
@ManyToOne
|
||||
private Stock stock;
|
||||
@ManyToOne
|
||||
private StockCollection collection;
|
||||
private Double score;
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.lanyuanxiaoyao.leopard.core.task;
|
||||
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.StockCollection;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.StockScore;
|
||||
import com.lanyuanxiaoyao.leopard.core.repository.StockCollectionRepository;
|
||||
import com.lanyuanxiaoyao.leopard.core.service.selector.PyramidStockSelector;
|
||||
import com.lanyuanxiaoyao.leopard.core.service.selector.StockSelector;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -33,13 +33,23 @@ public class PyramidSelect extends TaskRunner {
|
||||
|
||||
@Transactional(rollbackFor = Throwable.class)
|
||||
@Override
|
||||
public String process(Map<String, Object> params, StepUpdater updater) throws Exception {
|
||||
public String process(Map<String, Object> params, StepUpdater updater) {
|
||||
var candidates = pyramidStockSelector.select(new PyramidStockSelector.Request(LocalDate.now().getYear(), 50));
|
||||
|
||||
var collection = new StockCollection();
|
||||
collection.setName("金字塔选股");
|
||||
collection.setDescription("金字塔选股");
|
||||
collection.setStocks(candidates.stream().map(StockSelector.Candidate::stock).collect(Collectors.toSet()));
|
||||
collection.setScores(
|
||||
candidates.stream()
|
||||
.map(candidate -> {
|
||||
var score = new StockScore();
|
||||
score.setStock(candidate.stock());
|
||||
score.setScore(candidate.score());
|
||||
score.setCollection(collection);
|
||||
return score;
|
||||
})
|
||||
.collect(Collectors.toSet())
|
||||
);
|
||||
stockCollectionRepository.save(collection);
|
||||
|
||||
return """
|
||||
|
||||
Reference in New Issue
Block a user