《苍穹外卖》项目学习笔记
介绍
官网地址:Apache ECharts
入门案例
官方文档:快速上手 - 使用手册 - Apache ECharts
具体应用:营业额统计
Controller层:
@RestController
@RequestMapping("/admin/report")
@Api(tags = "数据统计相关接口")
@Slf4j
public class ReportController {
@Autowired
private ReportService reportService;
@GetMapping("/turnoverStatistics")
@ApiOperation("营业额统计")
public Result<TurnoverReportVO> turnoverStatistics(
@DateTimeFormat(pattern="yyyy-MM-dd")LocalDate begin,
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
return Result.success(reportService.getTurnoverStatistics(begin,end));
}
}
Service:
public interface ReportService {
public TurnoverReportVO getTurnoverStatistics(LocalDate begin, LocalDate end);
}
ServiceImpl
@Service
@Slf4j
public class ReportServiceImpl implements ReportService {
@Autowired
private OrderMapper orderMapper;
public TurnoverReportVO getTurnoverStatistics(LocalDate begin, LocalDate end){
//当前集合用于存放从begin到end范围内的每天的日期
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){
//查询date日期对应的营业额数据,营业额是指,状态为“已完成”的订单金额合计
LocalDateTime beginTime=LocalDateTime.of(date, LocalTime.MIN);
LocalDateTime endTime=LocalDateTime.of(date,LocalTime.MAX);
//select sum(amount) from orders where order_time >beginTime and order_time<endTime and status=5
Map map=new HashMap();
map.put("begin",beginTime);
map.put("end",endTime);
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();
}
OrderMapper.java:
/**
* 查询营业额
* @param map
* @return
*/
Double sumByMap(Map map);
OrderMapper.xml
<select id="sumByMap" resultType="java.lang.Double">
select sum(amount) from orders
<where>
<if test="begin!=null">
and order_time > #{begin}
</if>
<if test="end!=null">
and order_time < #{end}
</if>
<if test="status!=null">
and status=#{status}
</if>
</where>
</select>