Commit d26b049b authored by shiyu's avatar shiyu

平均价格

parent 1c326896
...@@ -9,5 +9,5 @@ public class Chart implements Entity { ...@@ -9,5 +9,5 @@ public class Chart implements Entity {
private List<String> xData; private List<String> xData;
private List<Object> values; private List<Double> values;
} }
...@@ -69,7 +69,7 @@ public class QueryPriceServiceImpl implements QueryPriceService { ...@@ -69,7 +69,7 @@ public class QueryPriceServiceImpl implements QueryPriceService {
dto.setEndBidTime(nowMills); dto.setEndBidTime(nowMills);
List<BidRecord> bidRecordList = bidRecordDao.queryByCid(dto); List<BidRecord> bidRecordList = bidRecordDao.queryByCid(dto);
List<String> xData = new ArrayList<>(); List<String> xData = new ArrayList<>();
List<Object> valueList = new ArrayList<>(); List<Double> valueList = new ArrayList<>();
double totalPrice = 0; double totalPrice = 0;
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("details", CategoryVo.of(category)); map.put("details", CategoryVo.of(category));
...@@ -81,12 +81,21 @@ public class QueryPriceServiceImpl implements QueryPriceService { ...@@ -81,12 +81,21 @@ public class QueryPriceServiceImpl implements QueryPriceService {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String time = date.format(formatter); String time = date.format(formatter);
xData.add(time); xData.add(time);
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 = 0; double averagePrice = 0;
int maxTimeNum = 0;
if (!CollectionUtils.isEmpty(bidRecordList)) { if (!CollectionUtils.isEmpty(bidRecordList)) {
averagePrice = totalPrice / bidRecordList.size(); String maxTime = xData.get(xData.size() -1);
for (int i =0; i<xData.size(); i++) {
if (xData.get(i).equals(maxTime)) {
maxTimeNum = maxTimeNum + 1;
totalPrice += valueList.get(i);
}
}
averagePrice = totalPrice / maxTimeNum;
map.put("averagePrice", StringUtil.formatAmount(String.valueOf(Math.round(averagePrice * 10000))));
Instant instant = Instant.ofEpochSecond(bidRecordList.get(bidRecordList.size() - 1).getBidTime()); Instant instant = Instant.ofEpochSecond(bidRecordList.get(bidRecordList.size() - 1).getBidTime());
LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
...@@ -96,7 +105,7 @@ public class QueryPriceServiceImpl implements QueryPriceService { ...@@ -96,7 +105,7 @@ public class QueryPriceServiceImpl implements QueryPriceService {
chart.setXData(xData); chart.setXData(xData);
chart.setValues(valueList); chart.setValues(valueList);
map.put("chart", chart); map.put("chart", chart);
map.put("averagePrice", StringUtil.formatAmount(String.valueOf(Math.round(averagePrice))));
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