diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java index 030840eb5..d953ba674 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java @@ -6302,10 +6302,32 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService { long orderCount = pageInfo.getTotal(); - // 3. 统计总金额(使用聚合 SQL,避免查询所有数据到内存 - OrderStatisticsVO statistics = orderBasicInfoMapper.countBusinessOrderStatistics(queryOrderDTO); - BigDecimal totalOrderAmount = statistics != null && statistics.getOrderAmount() != null - ? statistics.getOrderAmount() : BigDecimal.ZERO; + // 3. 统计总金额 (分批处理) + BigDecimal totalOrderAmount = BigDecimal.ZERO; + int batchSize = 500; // 每批最多 500 个站点ID + if (stationIdList.size() > batchSize) { + // 分批查询统计 + List> batches = Lists.partition(stationIdList, batchSize); + for (List batch : batches) { + QueryOrderDTO batchDTO = QueryOrderDTO.builder() + .stationIdList(batch) + .startTime(dto.getCreateTime()) + .endTime(dto.getEndTime()) + .orderStatus(dto.getOrderStatus()) + .startMode(dto.getStartMode()) + .stationName(dto.getStationName()) + .build(); + OrderStatisticsVO batchStatistics = orderBasicInfoMapper.countBusinessOrderStatistics(batchDTO); + if (batchStatistics != null && batchStatistics.getOrderAmount() != null) { + totalOrderAmount = totalOrderAmount.add(batchStatistics.getOrderAmount()); + } + } + } else { + // 直接查询 + OrderStatisticsVO statistics = orderBasicInfoMapper.countBusinessOrderStatistics(queryOrderDTO); + totalOrderAmount = statistics != null && statistics.getOrderAmount() != null + ? statistics.getOrderAmount() : BigDecimal.ZERO; + } //4. 转换为 BusinessOrderListVO List businessOrderList = orderListVOS.stream() diff --git a/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml index 8ff44cc20..572b53354 100644 --- a/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml +++ b/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml @@ -1934,6 +1934,46 @@ join pile_station_info t3 on t1.station_id = t3.id and t3.del_flag = '0' join order_detail t4 on t4.order_code = t1.order_code and t4.del_flag = '0' where t1.del_flag = '0' + + + and t1.station_id in + + #{stationId} + + + + and t1.station_id not in + + #{excludeStationId} + + + + and t1.create_time = ]]> #{startTime,jdbcType=VARCHAR} + + + and t1.create_time #{endTime,jdbcType=VARCHAR} + + + and t1.order_status = #{orderStatus,jdbcType=VARCHAR} + + + and t1.start_mode = #{startMode,jdbcType=VARCHAR} + + + and t3.station_name like concat('%', #{stationName,jdbcType=VARCHAR}, '%') + + + and t3.dept_id in + + #{stationDeptId} + + + + and t1.order_code = #{orderCode,jdbcType=VARCHAR} + + + and t1.transaction_code = #{transactionCode,jdbcType=VARCHAR} + and t1.pile_sn = #{pileSn,jdbcType=VARCHAR} @@ -1943,15 +1983,6 @@ and t1.member_id = #{memberId,jdbcType=VARCHAR} - - and t1.order_status = #{orderStatus,jdbcType=VARCHAR} - - - and t1.order_code = #{orderCode,jdbcType=VARCHAR} - - - and t1.transaction_code = #{transactionCode,jdbcType=VARCHAR} - and t2.mobile_number = #{mobileNumber,jdbcType=VARCHAR} @@ -1961,12 +1992,6 @@ and t1.station_id = #{stationId,jdbcType=VARCHAR} - - and t1.create_time = ]]> #{startTime,jdbcType=VARCHAR} - - - and t1.create_time #{endTime,jdbcType=VARCHAR} - and t1.settlement_time = ]]> #{startSettleTime,jdbcType=VARCHAR} @@ -1985,30 +2010,6 @@ and t1.pay_mode = #{payMode,jdbcType=VARCHAR} - - and t3.dept_id in - - #{stationDeptId} - - - - and t1.station_id not in - - #{excludeStationId} - - - - and t1.station_id in - - #{stationId} - - - - and t1.start_mode = #{startMode,jdbcType=VARCHAR} - - - and t3.station_name like concat('%', #{stationName,jdbcType=VARCHAR}, '%') - order by t1.create_time desc @@ -2087,62 +2088,53 @@ resultType="com.jsowell.pile.vo.web.OrderStatisticsVO"> SELECT COUNT(*) AS orderCount, - IFNULL(SUM(order_amount), 0) AS orderAmount - FROM ( - SELECT DISTINCT - t1.order_code, - t1.order_amount - FROM order_basic_info t1 - LEFT JOIN member_basic_info t2 - ON t1.member_id = t2.member_id - AND t2.del_flag = '0' + IFNULL(SUM(t1.order_amount), 0) AS orderAmount + FROM order_basic_info t1 + JOIN pile_station_info t3 ON t1.station_id = t3.id AND t3.del_flag = '0' - JOIN order_detail t4 - ON t4.order_code = t1.order_code - AND t4.del_flag = '0' - WHERE t1.del_flag = '0' - - AND t1.order_status = #{orderStatus,jdbcType=VARCHAR} - - - AND t1.merchant_id = #{merchantId,jdbcType=VARCHAR} - - - AND t1.station_id = #{stationId,jdbcType=VARCHAR} - - - AND t1.create_time = ]]> #{startTime,jdbcType=VARCHAR} - - - AND t1.create_time #{endTime,jdbcType=VARCHAR} - - - AND t1.station_id IN - - #{stationId} - - - - AND t1.start_mode = #{startMode,jdbcType=VARCHAR} - - - AND t3.station_name LIKE CONCAT('%', #{stationName,jdbcType=VARCHAR}, '%') - - - AND t3.dept_id IN - - #{stationDeptId} - - - - AND t1.station_id NOT IN - - #{excludeStationId} - - - ) AS temp + + WHERE t1.del_flag = '0' + + AND t1.station_id IN + + #{stationId} + + + + AND t1.station_id NOT IN + + #{excludeStationId} + + + + AND t1.order_status = #{orderStatus,jdbcType=VARCHAR} + + + AND t1.start_mode = #{startMode,jdbcType=VARCHAR} + + + AND t1.create_time = ]]> #{startTime,jdbcType=VARCHAR} + + + AND t1.create_time #{endTime,jdbcType=VARCHAR} + + + AND t1.merchant_id = #{merchantId,jdbcType=VARCHAR} + + + AND t1.station_id = #{stationId,jdbcType=VARCHAR} + + + AND t3.station_name LIKE CONCAT('%', #{stationName,jdbcType=VARCHAR}, '%') + + + AND t3.dept_id IN + + #{stationDeptId} + +