|
|
@@ -47,7 +47,12 @@ public class StockHistoryServiceImpl implements StockHistoryService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 查询总数
|
|
|
+ // 查询全量统计(分母统一为有隔日数据的记录)
|
|
|
+ Map<String, Object> stats = stockPoolMapper.selectPoolHistoryStats(startDate, endDate, poolType);
|
|
|
+ long successCount = stats != null && stats.get("successCount") != null ? ((Number) stats.get("successCount")).longValue() : 0;
|
|
|
+ long failCount = stats != null && stats.get("failCount") != null ? ((Number) stats.get("failCount")).longValue() : 0;
|
|
|
+
|
|
|
+ // 总记录数(含无隔日数据的,用于分页)
|
|
|
int total = stockPoolMapper.countPoolHistory(startDate, endDate, poolType);
|
|
|
|
|
|
// 计算总页数
|
|
|
@@ -57,6 +62,8 @@ public class StockHistoryServiceImpl implements StockHistoryService {
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
result.put("list", list);
|
|
|
result.put("total", total);
|
|
|
+ result.put("successCount", successCount);
|
|
|
+ result.put("failCount", failCount);
|
|
|
result.put("pageNum", pageNum);
|
|
|
result.put("pageSize", pageSize);
|
|
|
result.put("pages", pages);
|
|
|
@@ -67,47 +74,23 @@ public class StockHistoryServiceImpl implements StockHistoryService {
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> queryHistoryStats(LocalDate startDate, LocalDate endDate, Integer poolType) {
|
|
|
- // 查询所有数据(不分页)
|
|
|
- List<StockHistoryVO> allList = stockPoolMapper.selectPoolHistory(
|
|
|
- startDate, endDate, poolType, 0, Integer.MAX_VALUE
|
|
|
- );
|
|
|
-
|
|
|
- // 计算每条记录的成功/失败状态并统计
|
|
|
- int successCount = 0;
|
|
|
- int failCount = 0;
|
|
|
- java.math.BigDecimal totalTrend = java.math.BigDecimal.ZERO;
|
|
|
- int trendCount = 0;
|
|
|
+ Map<String, Object> stats = stockPoolMapper.selectPoolHistoryStats(startDate, endDate, poolType);
|
|
|
|
|
|
- for (StockHistoryVO vo : allList) {
|
|
|
- if (vo.getNextDayHighTrend() != null) {
|
|
|
- // 累加涨幅用于计算平均值
|
|
|
- totalTrend = totalTrend.add(vo.getNextDayHighTrend());
|
|
|
- trendCount++;
|
|
|
+ long totalCount = stats != null && stats.get("totalCount") != null ? ((Number) stats.get("totalCount")).longValue() : 0;
|
|
|
+ long successCount = stats != null && stats.get("successCount") != null ? ((Number) stats.get("successCount")).longValue() : 0;
|
|
|
+ long failCount = stats != null && stats.get("failCount") != null ? ((Number) stats.get("failCount")).longValue() : 0;
|
|
|
|
|
|
- if (vo.getNextDayHighTrend().compareTo(new java.math.BigDecimal("2")) >= 0) {
|
|
|
- successCount++;
|
|
|
- } else if (vo.getNextDayHighTrend().compareTo(new java.math.BigDecimal("-3")) <= 0) {
|
|
|
- failCount++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ String successRate = totalCount > 0 ? String.format("%.1f%%", (successCount * 100.0 / totalCount)) : "0%";
|
|
|
|
|
|
- int total = allList.size();
|
|
|
- String successRate = total > 0 ? String.format("%.1f%%", (successCount * 100.0 / total)) : "0%";
|
|
|
-
|
|
|
- // 计算平均收益率
|
|
|
- String avgTrend = "0%";
|
|
|
- if (trendCount > 0) {
|
|
|
- java.math.BigDecimal avg = totalTrend.divide(
|
|
|
- new java.math.BigDecimal(trendCount),
|
|
|
- 2,
|
|
|
- java.math.RoundingMode.HALF_UP
|
|
|
- );
|
|
|
+ String avgTrend = "+0%";
|
|
|
+ if (stats != null && stats.get("avgTrend") != null) {
|
|
|
+ java.math.BigDecimal avg = new java.math.BigDecimal(stats.get("avgTrend").toString())
|
|
|
+ .setScale(2, java.math.RoundingMode.HALF_UP);
|
|
|
avgTrend = String.format("%+.2f%%", avg);
|
|
|
}
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("totalCount", total);
|
|
|
+ result.put("totalCount", totalCount);
|
|
|
result.put("successCount", successCount);
|
|
|
result.put("failCount", failCount);
|
|
|
result.put("successRate", successRate);
|