苍穹外卖--用户统计功能实现
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.vo.TurnoverReportVO;
|
||||
import com.sky.vo.UserReportVO;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@@ -12,4 +13,12 @@ public interface ReportService {
|
||||
* @return
|
||||
*/
|
||||
TurnoverReportVO getTurnoverStatistics(LocalDate begin, LocalDate end);
|
||||
|
||||
/**
|
||||
* 用户统计
|
||||
* @param begin
|
||||
* @param end
|
||||
* @return
|
||||
*/
|
||||
UserReportVO getUserStatistics(LocalDate begin, LocalDate end);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.sky.service.impl;
|
||||
|
||||
import com.sky.entity.Orders;
|
||||
import com.sky.mapper.OrderMapper;
|
||||
import com.sky.mapper.UserMapper;
|
||||
import com.sky.service.ReportService;
|
||||
import com.sky.vo.TurnoverReportVO;
|
||||
import com.sky.vo.UserReportVO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -22,6 +24,9 @@ public class ReportServiceImpl implements ReportService {
|
||||
@Autowired
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 统计指定时间内每天的营业额数据
|
||||
@@ -69,4 +74,49 @@ public class ReportServiceImpl implements ReportService {
|
||||
|
||||
return turnoverReportVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户统计
|
||||
* @param begin
|
||||
* @param end
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public UserReportVO getUserStatistics(LocalDate begin, LocalDate end) {
|
||||
//根据对应的日期,将当天的所有已完成的订单查询出来,并统计总金额(sum)
|
||||
List<LocalDate> dateList = new ArrayList<>();
|
||||
dateList.add(begin);
|
||||
//不停地创建日期对象,直到end
|
||||
while (!begin.equals(end)){
|
||||
begin = begin.plusDays(1);
|
||||
dateList.add(begin);
|
||||
}
|
||||
|
||||
//定义2个集合,分别保存总用户数量和新用户数量
|
||||
//select count(1) from user where create_time < ?;
|
||||
//select count(1) from user where create_time < ? and create_time > ?;
|
||||
List<Integer> totalUserList = new ArrayList<>();
|
||||
List<Integer> newUserList = new ArrayList<>();
|
||||
|
||||
for (LocalDate localDate : dateList) {
|
||||
//根据指定的日期查询,当日的总用户数和新用户数
|
||||
LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
|
||||
LocalDateTime endTime = LocalDateTime.of(localDate, LocalTime.MAX);
|
||||
Map map = new HashMap();
|
||||
map.put("end", endTime);
|
||||
Integer totalUserCount = userMapper.countByMap(map);
|
||||
totalUserList.add(totalUserCount);
|
||||
map.put("begin", beginTime);
|
||||
Integer newUserCount = userMapper.countByMap(map);
|
||||
newUserList.add(newUserCount);
|
||||
}
|
||||
//封装返回结果
|
||||
UserReportVO userReportVO = UserReportVO.builder()
|
||||
.dateList(StringUtils.join(dateList, ","))
|
||||
.totalUserList(StringUtils.join(totalUserList, ","))
|
||||
.newUserList(StringUtils.join(newUserList, ","))
|
||||
.build();
|
||||
|
||||
return userReportVO;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user