|
|
@@ -19,6 +19,7 @@ import shop.alien.entity.store.*;
|
|
|
import shop.alien.entity.store.dto.LifeUserOrderDto;
|
|
|
import shop.alien.entity.store.excelVo.LifeUserOrderExcelVo;
|
|
|
import shop.alien.entity.store.excelVo.util.ExcelGenerator;
|
|
|
+import shop.alien.entity.store.vo.LifeUserOrderListWithStatisticsVO;
|
|
|
import shop.alien.entity.store.vo.LifeUserOrderVo;
|
|
|
import shop.alien.entity.store.vo.StoreInfoVo;
|
|
|
import shop.alien.entity.store.vo.WebSocketVo;
|
|
|
@@ -1002,6 +1003,226 @@ public class LifeUserOrderService extends ServiceImpl<LifeUserOrderMapper, LifeU
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 全部订单类型标识
|
|
|
+ */
|
|
|
+ private static final String ALL_COUPON_TYPE = "-1";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除标记:未删除
|
|
|
+ */
|
|
|
+ private static final Integer DELETE_FLAG_NOT_DELETED = 0;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 默认订单数量
|
|
|
+ */
|
|
|
+ private static final Long DEFAULT_ORDER_COUNT = 0L;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Map key:订单状态
|
|
|
+ */
|
|
|
+ private static final String KEY_ORDER_STATUS = "orderStatus";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Map key:订单数量
|
|
|
+ */
|
|
|
+ private static final String KEY_ORDER_COUNT = "orderCount";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 时间格式后缀:开始时间
|
|
|
+ */
|
|
|
+ private static final String TIME_START_SUFFIX = " 00:00:00";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 时间格式后缀:结束时间
|
|
|
+ */
|
|
|
+ private static final String TIME_END_SUFFIX = " 23:59:59";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询用户订单列表(包含各状态订单数量统计)
|
|
|
+ *
|
|
|
+ * @param page 页码
|
|
|
+ * @param size 每页数量
|
|
|
+ * @param userId 用户id
|
|
|
+ * @param storeId 商户id
|
|
|
+ * @param couponType 订单类型
|
|
|
+ * @param orderStatus 订单状态
|
|
|
+ * @param name 订单名称
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @return 订单列表及统计信息
|
|
|
+ */
|
|
|
+ public LifeUserOrderListWithStatisticsVO queryUserOrderListWithStatistics(
|
|
|
+ Integer page, Integer size, String userId, String storeId, String couponType,
|
|
|
+ String orderStatus, String name, String startTime, String endTime) {
|
|
|
+ // 查询订单列表
|
|
|
+ IPage<LifeUserOrderVo> orderList = queryUserOrderList(page, size, userId, storeId,
|
|
|
+ couponType, orderStatus, name, startTime, endTime);
|
|
|
+
|
|
|
+ // 构建统计查询条件
|
|
|
+ QueryWrapper<LifeUserOrderVo> statisticsQueryWrapper = buildStatisticsQueryWrapper(
|
|
|
+ userId, storeId, couponType, name, startTime, endTime);
|
|
|
+
|
|
|
+ // 统计各状态订单数量
|
|
|
+ List<Map<String, Object>> statusCountList = lifeUserOrderMapper.countOrdersByStatus(statisticsQueryWrapper);
|
|
|
+
|
|
|
+ // 构建返回结果
|
|
|
+ LifeUserOrderListWithStatisticsVO result = new LifeUserOrderListWithStatisticsVO();
|
|
|
+ result.setOrderList(orderList);
|
|
|
+
|
|
|
+ // 初始化各状态订单数量
|
|
|
+ initializeStatusCounts(result);
|
|
|
+
|
|
|
+ // 填充各状态订单数量
|
|
|
+ fillStatusCounts(result, statusCountList);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建统计查询条件
|
|
|
+ * <p>
|
|
|
+ * 与列表查询条件相同,但不包含状态筛选、分页和分组
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param userId 用户id
|
|
|
+ * @param storeId 商户id
|
|
|
+ * @param couponType 订单类型
|
|
|
+ * @param name 订单名称
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @return 查询条件包装器
|
|
|
+ */
|
|
|
+ private QueryWrapper<LifeUserOrderVo> buildStatisticsQueryWrapper(String userId, String storeId,
|
|
|
+ String couponType, String name,
|
|
|
+ String startTime, String endTime) {
|
|
|
+ QueryWrapper<LifeUserOrderVo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(org.apache.commons.lang3.StringUtils.isNotBlank(userId), "luo.user_id", userId);
|
|
|
+ queryWrapper.eq(org.apache.commons.lang3.StringUtils.isNotBlank(storeId), "luo.store_id", storeId);
|
|
|
+ queryWrapper.eq(null != couponType && !ALL_COUPON_TYPE.equals(couponType), "luo.coupon_type", couponType);
|
|
|
+ queryWrapper.like(org.apache.commons.lang3.StringUtils.isNotBlank(name), "tc.coupon_name", name);
|
|
|
+ queryWrapper.gt(org.apache.commons.lang3.StringUtils.isNotBlank(startTime),
|
|
|
+ "luo.created_time", startTime + TIME_START_SUFFIX);
|
|
|
+ queryWrapper.lt(org.apache.commons.lang3.StringUtils.isNotBlank(endTime),
|
|
|
+ "luo.created_time", endTime + TIME_END_SUFFIX);
|
|
|
+ queryWrapper.eq("luo.delete_flag", DELETE_FLAG_NOT_DELETED);
|
|
|
+ return queryWrapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化各状态订单数量为0
|
|
|
+ *
|
|
|
+ * @param result 结果对象
|
|
|
+ */
|
|
|
+ private void initializeStatusCounts(LifeUserOrderListWithStatisticsVO result) {
|
|
|
+ result.setWaitPayCount(DEFAULT_ORDER_COUNT);
|
|
|
+ result.setWaitUseCount(DEFAULT_ORDER_COUNT);
|
|
|
+ result.setUsedCount(DEFAULT_ORDER_COUNT);
|
|
|
+ result.setExpireCount(DEFAULT_ORDER_COUNT);
|
|
|
+ result.setCancelCount(DEFAULT_ORDER_COUNT);
|
|
|
+ result.setRefundCount(DEFAULT_ORDER_COUNT);
|
|
|
+ result.setRefundFailedCount(DEFAULT_ORDER_COUNT);
|
|
|
+ result.setCompleteCount(DEFAULT_ORDER_COUNT);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充各状态订单数量
|
|
|
+ *
|
|
|
+ * @param result 结果对象
|
|
|
+ * @param statusCountList 状态统计列表
|
|
|
+ */
|
|
|
+ private void fillStatusCounts(LifeUserOrderListWithStatisticsVO result,
|
|
|
+ List<Map<String, Object>> statusCountList) {
|
|
|
+ if (statusCountList == null || statusCountList.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Map<String, Object> item : statusCountList) {
|
|
|
+ Integer status = getIntegerValue(item.get(KEY_ORDER_STATUS));
|
|
|
+ Long count = getLongValue(item.get(KEY_ORDER_COUNT));
|
|
|
+ if (status != null && count != null) {
|
|
|
+ setStatusCount(result, status, count);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据订单状态设置对应的数量
|
|
|
+ *
|
|
|
+ * @param result 结果对象
|
|
|
+ * @param status 订单状态
|
|
|
+ * @param count 订单数量
|
|
|
+ */
|
|
|
+ private void setStatusCount(LifeUserOrderListWithStatisticsVO result, Integer status, Long count) {
|
|
|
+ if (OrderStatusEnum.WAIT_PAY.getStatus().equals(status)) {
|
|
|
+ result.setWaitPayCount(count);
|
|
|
+ } else if (OrderStatusEnum.WAIT_USE.getStatus().equals(status)) {
|
|
|
+ result.setWaitUseCount(count);
|
|
|
+ } else if (OrderStatusEnum.USED.getStatus().equals(status)) {
|
|
|
+ result.setUsedCount(count);
|
|
|
+ } else if (OrderStatusEnum.EXPIRE.getStatus().equals(status)) {
|
|
|
+ result.setExpireCount(count);
|
|
|
+ } else if (OrderStatusEnum.CANCEL.getStatus().equals(status)) {
|
|
|
+ result.setCancelCount(count);
|
|
|
+ } else if (OrderStatusEnum.REFUND.getStatus().equals(status)) {
|
|
|
+ result.setRefundCount(count);
|
|
|
+ } else if (OrderStatusEnum.REFUND_FAILED.getStatus().equals(status)) {
|
|
|
+ result.setRefundFailedCount(count);
|
|
|
+ } else if (OrderStatusEnum.COMPLETE.getStatus().equals(status)) {
|
|
|
+ result.setCompleteCount(count);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从Map中获取Integer值
|
|
|
+ * <p>
|
|
|
+ * 支持Integer、Long、Number类型的转换
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param value 对象值,可能为Integer、Long或其他Number类型
|
|
|
+ * @return Integer值,如果value为null或无法转换则返回null
|
|
|
+ */
|
|
|
+ private Integer getIntegerValue(Object value) {
|
|
|
+ if (value == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (value instanceof Integer) {
|
|
|
+ return (Integer) value;
|
|
|
+ }
|
|
|
+ if (value instanceof Long) {
|
|
|
+ return ((Long) value).intValue();
|
|
|
+ }
|
|
|
+ if (value instanceof Number) {
|
|
|
+ return ((Number) value).intValue();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从Map中获取Long值
|
|
|
+ * <p>
|
|
|
+ * 支持Long、Integer、Number类型的转换
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param value 对象值,可能为Long、Integer或其他Number类型
|
|
|
+ * @return Long值,如果value为null或无法转换则返回null
|
|
|
+ */
|
|
|
+ private Long getLongValue(Object value) {
|
|
|
+ if (value == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (value instanceof Long) {
|
|
|
+ return (Long) value;
|
|
|
+ }
|
|
|
+ if (value instanceof Integer) {
|
|
|
+ return ((Integer) value).longValue();
|
|
|
+ }
|
|
|
+ if (value instanceof Number) {
|
|
|
+ return ((Number) value).longValue();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 查询用户订单详情
|
|
|
*
|
|
|
* @param orderId
|