Commit 91c07744 authored by shiyu's avatar shiyu

折线图

parent bdc0bbcb
...@@ -22,6 +22,7 @@ import org.slf4j.Logger; ...@@ -22,6 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.time.*; import java.time.*;
...@@ -68,6 +69,9 @@ public class QueryPriceServiceImpl implements QueryPriceService { ...@@ -68,6 +69,9 @@ public class QueryPriceServiceImpl implements QueryPriceService {
List<String> xData = new ArrayList<>(); List<String> xData = new ArrayList<>();
List<Object> valueList = new ArrayList<>(); List<Object> valueList = new ArrayList<>();
double totalPrice = 0; double totalPrice = 0;
Map<String, Object> map = new HashMap<>();
map.put("details", CategoryVo.of(category));
for (BidRecord bidRecord : bidRecordList) { for (BidRecord bidRecord : bidRecordList) {
int bidTime = bidRecord.getBidTime(); int bidTime = bidRecord.getBidTime();
Instant instant = Instant.ofEpochSecond(bidTime); Instant instant = Instant.ofEpochSecond(bidTime);
...@@ -78,18 +82,19 @@ public class QueryPriceServiceImpl implements QueryPriceService { ...@@ -78,18 +82,19 @@ public class QueryPriceServiceImpl implements QueryPriceService {
totalPrice += (bidRecord.getPrice() / (double)100); totalPrice += (bidRecord.getPrice() / (double)100);
valueList.add(bidRecord.getPrice() / (double)100 / (double)10000); valueList.add(bidRecord.getPrice() / (double)100 / (double)10000);
} }
double averagePrice = totalPrice / bidRecordList.size(); double averagePrice = 0;
if (!CollectionUtils.isEmpty(bidRecordList)) {
averagePrice = totalPrice / bidRecordList.size();
Instant instant = Instant.ofEpochSecond(bidRecordList.get(bidRecordList.size() - 1).getBidTime());
LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
map.put("priceUpdateTime", date.format(formatter));
}
Chart chart = new Chart(); Chart chart = new Chart();
chart.setXData(xData); chart.setXData(xData);
chart.setValues(valueList); chart.setValues(valueList);
Map<String, Object> map = new HashMap<>();
map.put("details", CategoryVo.of(category));
map.put("chart", chart); map.put("chart", chart);
map.put("averagePrice", averagePrice); map.put("averagePrice", averagePrice);
Instant instant = Instant.ofEpochSecond(bidRecordList.get(bidRecordList.size() - 1).getBidTime());
LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
map.put("priceUpdateTime", date.format(formatter));
return Result.success(map); return Result.success(map);
} catch (Exception e) { } catch (Exception e) {
logger.error("查询类目价格详情失败:{}", e); logger.error("查询类目价格详情失败:{}", e);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment