You've already forked FrameTour-BE
添加订单统计方法
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.ycwl.basic.controller.pc;
|
||||
|
||||
import com.ycwl.basic.model.mobile.statistic.req.CommonQueryReq;
|
||||
import com.ycwl.basic.model.pc.statistics.resp.OrderStatisticsResp;
|
||||
import com.ycwl.basic.service.mobile.AppStatisticsService;
|
||||
import com.ycwl.basic.service.pc.StatisticsService;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
@@ -26,7 +27,7 @@ public class StatisticsController {
|
||||
|
||||
/**
|
||||
* 智能获取扫码访问人数统计数据(自动选择粒度)
|
||||
* @param query 查询参数(包含景区ID、开始时间、结束时间)
|
||||
* @param query 查询参数(包含景区ID、开始时间、结束时间;如果scenicId为空则统计全部景区,否则统计指定景区)
|
||||
* @return 统计数据(超过7天返回日期级别,否则返回小时级别)
|
||||
*/
|
||||
@PostMapping("/scanCodeMemberChart")
|
||||
@@ -43,4 +44,14 @@ public class StatisticsController {
|
||||
public ApiResponse getStatisticsTwo(@RequestBody CommonQueryReq query) {
|
||||
return appStatisticsService.twoStatistics(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单统计数据(包含订单数量和金额、推送订单数量、现场订单数量)
|
||||
* @param query 查询参数(包含景区ID、开始时间、结束时间;如果scenicId为空则统计全部景区,否则统计指定景区)
|
||||
* @return 统计数据(totalOrderCount: 总订单数量, totalOrderAmount: 总订单金额, pushOrderCount: 推送订单数量, sceneOrderCount: 现场订单数量)
|
||||
*/
|
||||
@PostMapping("/orderStatistics")
|
||||
public ApiResponse<OrderStatisticsResp> getOrderStatistics(@RequestBody CommonQueryReq query) {
|
||||
return ApiResponse.success(statisticsService.getOrderStatistics(query));
|
||||
}
|
||||
}
|
@@ -106,4 +106,11 @@ public interface StatisticsMapper {
|
||||
List<HashMap<String, String>> scanCodeMemberChartByHour(CommonQueryReq query);
|
||||
|
||||
List<HashMap<String, String>> scanCodeMemberChartByDate(CommonQueryReq query);
|
||||
|
||||
/**
|
||||
* 统计订单数量和金额(包含推送订单和现场订单)
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
com.ycwl.basic.model.pc.statistics.resp.OrderStatisticsResp getOrderStatistics(CommonQueryReq query);
|
||||
}
|
||||
|
@@ -0,0 +1,34 @@
|
||||
package com.ycwl.basic.model.pc.statistics.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 订单统计响应对象
|
||||
* @Author:longbinbin
|
||||
* @Date:2024/12/12
|
||||
*/
|
||||
@Data
|
||||
public class OrderStatisticsResp {
|
||||
|
||||
/**
|
||||
* 总订单数量(来自order表,status=1或2的已支付订单)
|
||||
*/
|
||||
private Integer totalOrderCount;
|
||||
|
||||
/**
|
||||
* 总订单金额(单位:元,来自order表)
|
||||
*/
|
||||
private BigDecimal totalOrderAmount;
|
||||
|
||||
/**
|
||||
* 推送订单数量(来自statistics表,type=3)
|
||||
*/
|
||||
private Integer pushOrderCount;
|
||||
|
||||
/**
|
||||
* 现场订单数量(来自statistics表,type=4)
|
||||
*/
|
||||
private Integer sceneOrderCount;
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
package com.ycwl.basic.service.pc;
|
||||
|
||||
import com.ycwl.basic.model.mobile.statistic.req.CommonQueryReq;
|
||||
import com.ycwl.basic.model.pc.statistics.resp.OrderStatisticsResp;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -17,4 +18,11 @@ public interface StatisticsService {
|
||||
* @return 统计数据(超过7天返回日期级别,否则返回小时级别)
|
||||
*/
|
||||
List<HashMap<String, String>> getScanCodeMemberChartAuto(CommonQueryReq query);
|
||||
|
||||
/**
|
||||
* 获取订单统计数据(包含订单数量和金额、推送订单数量、现场订单数量)
|
||||
* @param query 查询参数(包含景区ID、开始时间、结束时间;如果scenicId为空则统计全部景区,否则统计指定景区)
|
||||
* @return 统计数据(totalOrderCount: 总订单数量, totalOrderAmount: 总订单金额, pushOrderCount: 推送订单数量, sceneOrderCount: 现场订单数量)
|
||||
*/
|
||||
OrderStatisticsResp getOrderStatistics(CommonQueryReq query);
|
||||
}
|
@@ -2,6 +2,7 @@ package com.ycwl.basic.service.pc.impl;
|
||||
|
||||
import com.ycwl.basic.mapper.StatisticsMapper;
|
||||
import com.ycwl.basic.model.mobile.statistic.req.CommonQueryReq;
|
||||
import com.ycwl.basic.model.pc.statistics.resp.OrderStatisticsResp;
|
||||
import com.ycwl.basic.service.pc.StatisticsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -74,4 +75,30 @@ public class StatisticsServiceImpl implements StatisticsService {
|
||||
return getScanCodeMemberChartByHour(query);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderStatisticsResp getOrderStatistics(CommonQueryReq query) {
|
||||
// 时间参数兜底与规范化
|
||||
if (query.getStartTime() == null && query.getEndTime() == null) {
|
||||
// 默认查询今天:00:00:00 - 23:59:59
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime startOfDay = now.withHour(0).withMinute(0).withSecond(0).withNano(0);
|
||||
LocalDateTime endOfDay = now.withHour(23).withMinute(59).withSecond(59).withNano(0);
|
||||
query.setStartTime(Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant()));
|
||||
query.setEndTime(Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant()));
|
||||
} else {
|
||||
if (query.getEndTime() != null) {
|
||||
// 保证 endTime 为当天最后一秒
|
||||
LocalDateTime endDateTime = query.getEndTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||
LocalDateTime endOfDay = endDateTime.withHour(23).withMinute(59).withSecond(59).withNano(0);
|
||||
query.setEndTime(Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant()));
|
||||
} else if (query.getStartTime() != null) {
|
||||
// 仅传 startTime 时,将 endTime 置为 startTime 当天的 23:59:59
|
||||
LocalDateTime startDateTime = query.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||
LocalDateTime endOfStartDay = startDateTime.withHour(23).withMinute(59).withSecond(59).withNano(0);
|
||||
query.setEndTime(Date.from(endOfStartDay.atZone(ZoneId.systemDefault()).toInstant()));
|
||||
}
|
||||
}
|
||||
return statisticsMapper.getOrderStatistics(query);
|
||||
}
|
||||
}
|
@@ -486,5 +486,44 @@
|
||||
) order_data ON order_data.date_key = date_series.DATE_KEY
|
||||
ORDER BY date_series.date_value
|
||||
</select>
|
||||
<select id="getOrderStatistics" resultType="com.ycwl.basic.model.pc.statistics.resp.OrderStatisticsResp">
|
||||
SELECT
|
||||
COALESCE(order_stats.total_count, 0) AS totalOrderCount,
|
||||
COALESCE(order_stats.total_amount, 0) AS totalOrderAmount,
|
||||
COALESCE(stats_data.push_count, 0) AS pushOrderCount,
|
||||
COALESCE(stats_data.scene_count, 0) AS sceneOrderCount
|
||||
FROM (
|
||||
SELECT
|
||||
COUNT(1) AS total_count,
|
||||
SUM(pay_price) AS total_amount
|
||||
FROM `order`
|
||||
WHERE (status = 1 OR status = 2)
|
||||
<if test="scenicId != null">
|
||||
AND scenic_id = #{scenicId}
|
||||
</if>
|
||||
<if test="startTime != null">
|
||||
AND create_at >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
AND create_at <= #{endTime}
|
||||
</if>
|
||||
) order_stats
|
||||
CROSS JOIN (
|
||||
SELECT
|
||||
SUM(CASE WHEN type = 3 THEN 1 ELSE 0 END) AS push_count,
|
||||
SUM(CASE WHEN type = 4 THEN 1 ELSE 0 END) AS scene_count
|
||||
FROM statistics
|
||||
WHERE type IN (3, 4)
|
||||
<if test="scenicId != null">
|
||||
AND scenic_id = #{scenicId}
|
||||
</if>
|
||||
<if test="startTime != null">
|
||||
AND create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
AND create_time <= #{endTime}
|
||||
</if>
|
||||
) stats_data
|
||||
</select>
|
||||
|
||||
</mapper>
|
Reference in New Issue
Block a user