This commit is contained in:
YAS\29473
2026-01-04 08:40:56 +08:00
parent 2347445e74
commit ccd2f96466
3 changed files with 76 additions and 46 deletions

View File

@@ -6302,25 +6302,23 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
.orderStatus(dto.getOrderStatus()) .orderStatus(dto.getOrderStatus())
.build(); .build();
// 分页参数处理 // 1. 分页参数处理
int pageNum = dto.getPageNum() == null || dto.getPageNum() <= 0 ? 1 : dto.getPageNum(); int pageNum = dto.getPageNum() == null || dto.getPageNum() <= 0 ? 1 : dto.getPageNum();
int pageSize = dto.getPageSize() == null || dto.getPageSize() <= 0 ? 10 : dto.getPageSize(); int pageSize = dto.getPageSize() == null || dto.getPageSize() <= 0 ? 10 : dto.getPageSize();
// 使用聚合 SQL 统计订单数量和总金额 // 2. 分页查询订单列表
OrderStatisticsVO statistics = orderBasicInfoMapper.countBusinessOrderStatistics(queryOrderDTO);
// 订单数量和总金额的为空判断
long orderCount = statistics != null && statistics.getOrderCount() != null
? statistics.getOrderCount() : 0L;
BigDecimal totalOrderAmount = statistics != null && statistics.getOrderAmount() != null
? statistics.getOrderAmount() : BigDecimal.ZERO;
// 分页查询订单列表
PageHelper.startPage(pageNum, pageSize); PageHelper.startPage(pageNum, pageSize);
List<OrderListVO> orderListVOS = selectOrderBasicInfoList(queryOrderDTO); List<OrderListVO> orderListVOS = selectOrderBasicInfoList(queryOrderDTO);
PageInfo<OrderListVO> pageInfo = new PageInfo<>(orderListVOS); PageInfo<OrderListVO> pageInfo = new PageInfo<>(orderListVOS);
// 转换为BusinessOrderListVO long orderCount = pageInfo.getTotal();
// 3. 统计总金额(使用聚合 SQL避免查询所有数据到内存
OrderStatisticsVO statistics = orderBasicInfoMapper.countBusinessOrderStatistics(queryOrderDTO);
BigDecimal totalOrderAmount = statistics != null && statistics.getOrderAmount() != null
? statistics.getOrderAmount() : BigDecimal.ZERO;
//4. 转换为 BusinessOrderListVO
List<BusinessOrderListVO> businessOrderList = orderListVOS.stream() List<BusinessOrderListVO> businessOrderList = orderListVOS.stream()
.map(order -> BusinessOrderListVO.builder() .map(order -> BusinessOrderListVO.builder()
.createTime(order.getCreateTime()) .createTime(order.getCreateTime())
@@ -6334,8 +6332,8 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
.build()) .build())
.collect(Collectors.toList()); .collect(Collectors.toList());
// 构建分页响应 // 5. 构建分页响应
com.jsowell.common.core.page.PageResponse pageResponse = com.jsowell.common.core.page.PageResponse.builder() PageResponse pageResponse = PageResponse.builder()
.pageNum(pageNum) .pageNum(pageNum)
.pageSize(pageSize) .pageSize(pageSize)
.total(pageInfo.getTotal()) .total(pageInfo.getTotal())
@@ -6343,12 +6341,11 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
.list(businessOrderList) .list(businessOrderList)
.build(); .build();
// 构建返回结果 // 6. 构建返回结果
return BusinessOrderQueryResultVO.builder() return BusinessOrderQueryResultVO.builder()
.orderCount(orderCount) .orderCount(orderCount)
.orderAmount(totalOrderAmount) .orderAmount(totalOrderAmount)
.pageResponse(pageResponse) .pageResponse(pageResponse)
.orderList(businessOrderList)
.build(); .build();
} }

View File

@@ -35,9 +35,5 @@ public class BusinessOrderQueryResultVO {
*/ */
private PageResponse pageResponse; private PageResponse pageResponse;
/**
* 订单列表
*/
private List<BusinessOrderListVO> orderList;
} }

View File

@@ -1997,6 +1997,12 @@
#{excludeStationId} #{excludeStationId}
</foreach> </foreach>
</if> </if>
<if test="stationIdList != null and stationIdList.size() != 0">
and station_id in
<foreach collection="stationIdList" item="stationId" open="(" separator="," close=")">
#{stationId}
</foreach>
</if>
order by t1.create_time desc order by t1.create_time desc
</select> </select>
@@ -2066,34 +2072,65 @@
order by t1.create_time desc order by t1.create_time desc
</select> </select>
<!--
统计订单数量和总金额(用于运营端小程序)
使用子查询去重,确保与分页查询 selectOrderBasicInfoList 的条件一致
包含相同的 JOIN 条件order_detail、pile_station_info和过滤条件
-->
<select id="countBusinessOrderStatistics" parameterType="com.jsowell.pile.dto.QueryOrderDTO" <select id="countBusinessOrderStatistics" parameterType="com.jsowell.pile.dto.QueryOrderDTO"
resultType="com.jsowell.pile.vo.web.OrderStatisticsVO"> resultType="com.jsowell.pile.vo.web.OrderStatisticsVO">
select SELECT
COUNT(*) as orderCount, COUNT(*) AS orderCount,
IFNULL(SUM(order_amount), 0) as orderAmount IFNULL(SUM(order_amount), 0) AS orderAmount
from order_basic_info FROM (
where del_flag = '0' SELECT DISTINCT
<if test="orderStatus != null and orderStatus != ''"> t1.order_code,
and order_status = #{orderStatus,jdbcType=VARCHAR} t1.order_amount
</if> FROM order_basic_info t1
<if test="merchantId != null and merchantId != ''"> LEFT JOIN member_basic_info t2
and merchant_id = #{merchantId,jdbcType=VARCHAR} ON t1.member_id = t2.member_id
</if> AND t2.del_flag = '0'
<if test="stationId != null and stationId != ''"> JOIN pile_station_info t3
and station_id = #{stationId,jdbcType=VARCHAR} ON t1.station_id = t3.id
</if> AND t3.del_flag = '0'
<if test="startTime != null and startTime != ''"> JOIN order_detail t4
and create_time <![CDATA[ >= ]]> #{startTime,jdbcType=VARCHAR} ON t4.order_code = t1.order_code
</if> AND t4.del_flag = '0'
<if test="endTime != null and endTime != ''"> WHERE t1.del_flag = '0'
and create_time <![CDATA[ <= ]]> #{endTime,jdbcType=VARCHAR} <if test="orderStatus != null and orderStatus != ''">
</if> AND t1.order_status = #{orderStatus,jdbcType=VARCHAR}
<if test="stationIdList != null and stationIdList.size() != 0"> </if>
and station_id in <if test="merchantId != null and merchantId != ''">
<foreach collection="stationIdList" item="stationId" open="(" separator="," close=")"> AND t1.merchant_id = #{merchantId,jdbcType=VARCHAR}
#{stationId} </if>
</foreach> <if test="stationId != null and stationId != ''">
</if> AND t1.station_id = #{stationId,jdbcType=VARCHAR}
</if>
<if test="startTime != null and startTime != ''">
AND t1.create_time <![CDATA[ >= ]]> #{startTime,jdbcType=VARCHAR}
</if>
<if test="endTime != null and endTime != ''">
AND t1.create_time <![CDATA[ <= ]]> #{endTime,jdbcType=VARCHAR}
</if>
<if test="stationIdList != null and stationIdList.size() != 0">
AND t1.station_id IN
<foreach collection="stationIdList" item="stationId" open="(" separator="," close=")">
#{stationId}
</foreach>
</if>
<if test="stationDeptIds != null and stationDeptIds.size() != 0">
AND t3.dept_id IN
<foreach collection="stationDeptIds" item="stationDeptId" open="(" separator="," close=")">
#{stationDeptId}
</foreach>
</if>
<if test="excludeStationIdList != null and excludeStationIdList.size() != 0">
AND t1.station_id NOT IN
<foreach collection="excludeStationIdList" item="excludeStationId" open="(" separator="," close=")">
#{excludeStationId}
</foreach>
</if>
) AS temp
</select> </select>
<select id="selectOrderBasicInfoById" parameterType="Long" resultMap="OrderBasicInfoOrderDetailResult"> <select id="selectOrderBasicInfoById" parameterType="Long" resultMap="OrderBasicInfoOrderDetailResult">