feat: 股票集中显示股票对应的得分
This commit is contained in:
@@ -3,18 +3,18 @@ package com.lanyuanxiaoyao.leopard.server.controller;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.StockCollection;
|
||||
import com.lanyuanxiaoyao.leopard.core.service.StockCollectionService;
|
||||
import com.lanyuanxiaoyao.leopard.core.service.StockService;
|
||||
import com.lanyuanxiaoyao.leopard.server.entity.StockDetailVo;
|
||||
import com.lanyuanxiaoyao.leopard.server.entity.StockScoreVo;
|
||||
import com.lanyuanxiaoyao.service.template.controller.GlobalResponse;
|
||||
import com.lanyuanxiaoyao.service.template.controller.SimpleControllerSupport;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("stock_collection")
|
||||
public class StockCollectionController extends SimpleControllerSupport<StockCollection, StockCollectionController.SaveItem, StockCollectionController.ListItem, StockCollectionController.DetailItem> {
|
||||
public class StockCollectionController extends SimpleControllerSupport<StockCollection, Void, StockCollectionController.ListItem, StockCollectionController.DetailItem> {
|
||||
private final StockService stockService;
|
||||
|
||||
public StockCollectionController(StockCollectionService service, StockService stockService) {
|
||||
@@ -23,16 +23,13 @@ public class StockCollectionController extends SimpleControllerSupport<StockColl
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function<SaveItem, StockCollection> saveItemMapper() {
|
||||
return item -> {
|
||||
var collection = new StockCollection();
|
||||
collection.setId(item.id());
|
||||
collection.setName(item.name());
|
||||
collection.setDescription(item.description());
|
||||
var stocks = stockService.list(item.stockIds());
|
||||
collection.setStocks(new HashSet<>(stocks));
|
||||
return collection;
|
||||
};
|
||||
public GlobalResponse<Long> save(Void unused) throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function<Void, StockCollection> saveItemMapper() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,7 +38,7 @@ public class StockCollectionController extends SimpleControllerSupport<StockColl
|
||||
collection.getId(),
|
||||
collection.getName(),
|
||||
collection.getDescription(),
|
||||
collection.getStocks().size()
|
||||
collection.getScores().size()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,22 +48,15 @@ public class StockCollectionController extends SimpleControllerSupport<StockColl
|
||||
collection.getId(),
|
||||
collection.getName(),
|
||||
collection.getDescription(),
|
||||
collection.getStocks().size(),
|
||||
collection.getStocks()
|
||||
collection.getScores().size(),
|
||||
collection.getScores()
|
||||
.stream()
|
||||
.map(StockDetailVo::of)
|
||||
.collect(Collectors.toSet())
|
||||
.map(StockScoreVo::of)
|
||||
.sorted(Comparator.comparing(StockScoreVo::score).reversed())
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
|
||||
public record SaveItem(
|
||||
Long id,
|
||||
String name,
|
||||
String description,
|
||||
Set<Long> stockIds
|
||||
) {
|
||||
}
|
||||
|
||||
public record ListItem(
|
||||
Long id,
|
||||
String name,
|
||||
@@ -80,7 +70,7 @@ public class StockCollectionController extends SimpleControllerSupport<StockColl
|
||||
String name,
|
||||
String description,
|
||||
Integer count,
|
||||
Set<StockDetailVo> stocks
|
||||
List<StockScoreVo> scores
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.lanyuanxiaoyao.leopard.server.entity;
|
||||
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.Stock;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.StockScore;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250917
|
||||
*/
|
||||
public record StockScoreVo(
|
||||
Long id,
|
||||
String code,
|
||||
String name,
|
||||
String fullname,
|
||||
Stock.Market market,
|
||||
String industry,
|
||||
LocalDate listedDate,
|
||||
Double score
|
||||
) {
|
||||
public static StockScoreVo of(StockScore score) {
|
||||
return new StockScoreVo(
|
||||
score.getStock().getId(),
|
||||
score.getStock().getCode(),
|
||||
score.getStock().getName(),
|
||||
score.getStock().getFullname(),
|
||||
score.getStock().getMarket(),
|
||||
score.getStock().getIndustry(),
|
||||
score.getStock().getListedDate(),
|
||||
score.getScore()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user