ReportController
@GetMapping("/top10")
@ApiOperation("销售额Top10")
public Result<SalesTop10ReportVO> top10(
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
log.info("销售额Top10:begin:{}, end:{}", begin, end);
SalesTop10ReportVO top10 = reportService.getSalesTop10(begin, end);
return Result.success(top10);
}
ReportService
SalesTop10ReportVO getSalesTop10(LocalDate begin, LocalDate end);
ReportServiceImpl
@Override
public SalesTop10ReportVO getSalesTop10(LocalDate begin, LocalDate end) {
LocalDateTime beginTime = LocalDateTime.of(begin, LocalTime.MIN);
LocalDateTime endTime = LocalDateTime.of(end, LocalTime.MAX);
List<String> nameList = new ArrayList<>();
List<Integer> numberList = new ArrayList<>();
List<GoodsSalesDTO> salesTop = orderMapper.getSalesTop(beginTime, endTime);
for (GoodsSalesDTO goodsSalesDTO : salesTop) {
log.info("goodsSalesDTO:{}", goodsSalesDTO);
nameList.add(goodsSalesDTO.getName());
numberList.add(goodsSalesDTO.getNumber());
}
String nameJoin = StringUtils.join(nameList, ",");
String numberJoin = StringUtils.join(numberList, ",");
return SalesTop10ReportVO.builder()
.nameList(nameJoin)
.numberList(numberJoin)
.build();
}
OrderMapper
List<GoodsSalesDTO> getSalesTop(LocalDateTime begin, LocalDateTime end);
OrderMapper.xml
<select id="getSalesTop" resultType="com.sky.dto.GoodsSalesDTO">
select od.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 o.order_time > #{begin}
</if>
<if test="end != null">
and o.order_time < #{end}
</if>
group by od.name
order by number desc
limit 0,10
</select>