Apache ECharts
前端技术。
营业额统计
还是比较简单的。
用户统计
订单统计
以上所有需求。难点在于对时间类的处理:
// 接收格式
@GetMapping("/turnoverStatistics")
@ApiOperation("营业额统计")
public Result<TurnoverReportVO> turnoverStatistics(
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
log.info("营业额统计:{},{}", begin, end);
return Result.success(reportService.getTurnoverStatistics(begin, end));
}
//日期扩展到时分秒
@Override
public TurnoverReportVO getTurnoverStatistics(LocalDate begin, LocalDate end) {
// deteList: 开始日期,到结束日期
List<LocalDate> dateList = new ArrayList<>();
dateList.add(begin);
while (!begin.equals(end)){
begin = begin.plusDays(1);
dateList.add(begin);
}
List<Double> turnoverList = new ArrayList<>();
for (LocalDate date : dateList) {
LocalDateTime dateBegin = LocalDateTime.of(date, LocalTime.MIN);
LocalDateTime dateEnd = LocalDateTime.of(date, LocalTime.MAX);
Map map = new HashMap();
map.put("begin", dateBegin);
map.put("end", dateEnd);
map.put("status", Orders.COMPLETED);
Double turnover = orderMapper.sumByMap(map);
turnover = turnover == null ? 0.0 : turnover;
turnoverList.add(turnover);
}
return TurnoverReportVO.builder()
.dateList(StringUtils.join(dateList, ","))
.turnoverList(StringUtils.join(turnoverList, ","))
.build();
}
销量排名Top10
难点在于查询数据库设计。
order_detail一张表不够,还需要确定对应的订单是否是完成状态。——》连接查询
<select id="getSalesTop10" resultType="com.sky.dto.GoodsSalesDTO">
select od.name name, sum(od.number) number
from order_detail od, orders o
where od.order_id = o.id and o.status=5
<if test="begin != null">
and order_time > #{begin}
</if>
<if test="end != null">
and order_time < #{end}
</if>
group by od.name
order by number desc
limit 0,10
</select>