用户统计
This commit is contained in:
parent
9c27154677
commit
18eb840ecc
|
@ -3,6 +3,7 @@ package com.sky.controller.admin;
|
||||||
import com.sky.result.Result;
|
import com.sky.result.Result;
|
||||||
import com.sky.service.ReportService;
|
import com.sky.service.ReportService;
|
||||||
import com.sky.vo.TurnoverReportVO;
|
import com.sky.vo.TurnoverReportVO;
|
||||||
|
import com.sky.vo.UserReportVO;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -31,10 +32,24 @@ public class ReportController {
|
||||||
*/
|
*/
|
||||||
@ApiOperation("营业额统计")
|
@ApiOperation("营业额统计")
|
||||||
@GetMapping("/turnoverStatistics")
|
@GetMapping("/turnoverStatistics")
|
||||||
public Result<TurnoverReportVO> turnoverReport(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
|
public Result<TurnoverReportVO> turnoverReport(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
|
|
||||||
log.info("营业额统计,开始时间:{};结束时间:{}", begin, end);
|
log.info("营业额统计,开始时间:{};结束时间:{}", begin, end);
|
||||||
TurnoverReportVO turnoverStatistics = reportService.getTurnoverStatistics(begin, end);
|
TurnoverReportVO turnoverStatistics = reportService.getTurnoverStatistics(begin, end);
|
||||||
return Result.success(turnoverStatistics);
|
return Result.success(turnoverStatistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户统计
|
||||||
|
*
|
||||||
|
* @param begin 看起始时间
|
||||||
|
* @param end 结束时间
|
||||||
|
* @return UserReportVO
|
||||||
|
*/
|
||||||
|
@ApiOperation("用户统计")
|
||||||
|
@GetMapping("/userStatistics")
|
||||||
|
public Result<UserReportVO> userStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
|
||||||
|
log.info("用户统计,开始时间:{};结束时间:{}", begin, end);
|
||||||
|
UserReportVO userStatistics = reportService.getUserStatistics(begin, end);
|
||||||
|
return Result.success(userStatistics);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package com.sky.mapper;
|
||||||
import com.sky.entity.User;
|
import com.sky.entity.User;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface UserMapper {
|
public interface UserMapper {
|
||||||
|
|
||||||
|
@ -28,4 +30,12 @@ public interface UserMapper {
|
||||||
* @return User
|
* @return User
|
||||||
*/
|
*/
|
||||||
User getById(Long userId);
|
User getById(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据动态条件统计用户数量
|
||||||
|
*
|
||||||
|
* @param map
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Integer countByMap(Map map);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.sky.service;
|
package com.sky.service;
|
||||||
|
|
||||||
import com.sky.vo.TurnoverReportVO;
|
import com.sky.vo.TurnoverReportVO;
|
||||||
|
import com.sky.vo.UserReportVO;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
@ -13,4 +14,13 @@ public interface ReportService {
|
||||||
* @return TurnoverReportVO
|
* @return TurnoverReportVO
|
||||||
*/
|
*/
|
||||||
TurnoverReportVO getTurnoverStatistics(LocalDate begin, LocalDate end);
|
TurnoverReportVO getTurnoverStatistics(LocalDate begin, LocalDate end);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户统计
|
||||||
|
*
|
||||||
|
* @param begin 看起始时间
|
||||||
|
* @param end 结束时间
|
||||||
|
* @return UserReportVO
|
||||||
|
*/
|
||||||
|
UserReportVO getUserStatistics(LocalDate begin, LocalDate end);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,10 @@ package com.sky.service.impl;
|
||||||
|
|
||||||
import com.sky.entity.Orders;
|
import com.sky.entity.Orders;
|
||||||
import com.sky.mapper.OrderMapper;
|
import com.sky.mapper.OrderMapper;
|
||||||
|
import com.sky.mapper.UserMapper;
|
||||||
import com.sky.service.ReportService;
|
import com.sky.service.ReportService;
|
||||||
import com.sky.vo.TurnoverReportVO;
|
import com.sky.vo.TurnoverReportVO;
|
||||||
|
import com.sky.vo.UserReportVO;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@ -13,11 +15,14 @@ import java.time.LocalDateTime;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ReportServiceImpl implements ReportService {
|
public class ReportServiceImpl implements ReportService {
|
||||||
@Resource
|
@Resource
|
||||||
private OrderMapper orderMapper;
|
private OrderMapper orderMapper;
|
||||||
|
@Resource
|
||||||
|
private UserMapper userMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 营业额统计
|
* 营业额统计
|
||||||
|
@ -53,4 +58,45 @@ public class ReportServiceImpl implements ReportService {
|
||||||
|
|
||||||
return TurnoverReportVO.builder().dateList(StringUtils.join(dateArrayList, ",")).turnoverList(StringUtils.join(turnoverList, ",")).build();
|
return TurnoverReportVO.builder().dateList(StringUtils.join(dateArrayList, ",")).turnoverList(StringUtils.join(turnoverList, ",")).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户统计
|
||||||
|
*
|
||||||
|
* @param begin 看起始时间
|
||||||
|
* @param end 结束时间
|
||||||
|
* @return UserReportVO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public UserReportVO getUserStatistics(LocalDate begin, LocalDate end) {
|
||||||
|
List<LocalDate> dateList = new ArrayList<>();
|
||||||
|
dateList.add(begin);
|
||||||
|
|
||||||
|
while (!begin.equals(end)) {
|
||||||
|
begin = begin.plusDays(1);
|
||||||
|
dateList.add(begin);
|
||||||
|
}
|
||||||
|
// 存放每天的新增用户数量
|
||||||
|
ArrayList<Integer> newUserList = new ArrayList<>();
|
||||||
|
// 存放每天总用户数量
|
||||||
|
List<Integer> totalUserList = new ArrayList<>();
|
||||||
|
for (LocalDate date : dateList) {
|
||||||
|
LocalDateTime beginTime = LocalDateTime.of(date, LocalTime.MIN);
|
||||||
|
LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);
|
||||||
|
|
||||||
|
HashMap map = new HashMap<>();
|
||||||
|
map.put("end", endTime);
|
||||||
|
// 总用户数量
|
||||||
|
Integer totalUser = userMapper.countByMap(map);
|
||||||
|
map.put("begin", beginTime);
|
||||||
|
// 新增用户数量
|
||||||
|
Integer newUser = userMapper.countByMap(map);
|
||||||
|
totalUserList.add(totalUser);
|
||||||
|
newUserList.add(newUser);
|
||||||
|
}
|
||||||
|
return UserReportVO.builder()
|
||||||
|
.dateList(StringUtils.join(dateList, ","))
|
||||||
|
.totalUserList(StringUtils.join(totalUserList, ","))
|
||||||
|
.newUserList(StringUtils.join(newUserList, ","))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,18 @@
|
||||||
from user
|
from user
|
||||||
where id = #{id};
|
where id = #{id};
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据动态条件统计用户数量 -->
|
||||||
|
<select id="countByMap" resultType="java.lang.Integer">
|
||||||
|
select count(id)
|
||||||
|
from user
|
||||||
|
<where>
|
||||||
|
<if test="begin != null">
|
||||||
|
and create_time > #{begin}
|
||||||
|
</if>
|
||||||
|
<if test="end != null">
|
||||||
|
and create_time < #{end}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue