|
@@ -1,6 +1,8 @@
|
|
|
package com.ruoyi.system.service.impl;
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
|
|
|
|
+import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.LinkedHashSet;
|
|
import java.util.LinkedHashSet;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -9,6 +11,8 @@ import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
@@ -16,9 +20,11 @@ import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.system.mapper.PushMessageMapper;
|
|
import com.ruoyi.system.mapper.PushMessageMapper;
|
|
|
import com.ruoyi.system.mapper.PosOrderMapper;
|
|
import com.ruoyi.system.mapper.PosOrderMapper;
|
|
|
import com.ruoyi.system.mapper.flash.FlashDeliveryOrderMapper;
|
|
import com.ruoyi.system.mapper.flash.FlashDeliveryOrderMapper;
|
|
|
|
|
+import com.ruoyi.system.mapper.flash.FlashDeliveryOrderImageMapper;
|
|
|
import com.ruoyi.system.domain.PosOrder;
|
|
import com.ruoyi.system.domain.PosOrder;
|
|
|
import com.ruoyi.system.domain.PushMessage;
|
|
import com.ruoyi.system.domain.PushMessage;
|
|
|
import com.ruoyi.system.domain.flash.FlashDeliveryOrder;
|
|
import com.ruoyi.system.domain.flash.FlashDeliveryOrder;
|
|
|
|
|
+import com.ruoyi.system.domain.flash.FlashDeliveryOrderImage;
|
|
|
import com.ruoyi.system.service.IPushMessageService;
|
|
import com.ruoyi.system.service.IPushMessageService;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -39,6 +45,9 @@ public class PushMessageServiceImpl extends ServiceImpl<BaseMapper<PushMessage>,
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FlashDeliveryOrderMapper flashDeliveryOrderMapper;
|
|
private FlashDeliveryOrderMapper flashDeliveryOrderMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FlashDeliveryOrderImageMapper flashDeliveryOrderImageMapper;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询推送消息
|
|
* 查询推送消息
|
|
|
*
|
|
*
|
|
@@ -134,7 +143,8 @@ public class PushMessageServiceImpl extends ServiceImpl<BaseMapper<PushMessage>,
|
|
|
: flashDeliveryOrderMapper.selectList(new LambdaQueryWrapper<FlashDeliveryOrder>().in(FlashDeliveryOrder::getOrderNo, flashOrderNos))
|
|
: flashDeliveryOrderMapper.selectList(new LambdaQueryWrapper<FlashDeliveryOrder>().in(FlashDeliveryOrder::getOrderNo, flashOrderNos))
|
|
|
.stream().filter(order -> order.getOrderNo() != null)
|
|
.stream().filter(order -> order.getOrderNo() != null)
|
|
|
.collect(Collectors.toMap(FlashDeliveryOrder::getOrderNo, Function.identity(), (first, second) -> first));
|
|
.collect(Collectors.toMap(FlashDeliveryOrder::getOrderNo, Function.identity(), (first, second) -> first));
|
|
|
- fillOrderInfo(messages, foodOrders, flashOrders);
|
|
|
|
|
|
|
+ Map<Long, String> flashFirstImages = firstSenderImages(flashOrders.values());
|
|
|
|
|
+ fillOrderInfo(messages, foodOrders, flashOrders, flashFirstImages);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 收集当页消息的订单指针:push_type=1 归入外卖单号,push_type=3 归入闪送单号。 */
|
|
/** 收集当页消息的订单指针:push_type=1 归入外卖单号,push_type=3 归入闪送单号。 */
|
|
@@ -157,9 +167,9 @@ public class PushMessageServiceImpl extends ServiceImpl<BaseMapper<PushMessage>,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 按指针把商家名/地址写回消息;订单已删或不存在的消息保持原样。 */
|
|
|
|
|
|
|
+ /** 按指针把商家名/地址/缩略图写回消息;订单已删或不存在的消息保持原样。 */
|
|
|
private void fillOrderInfo(List<PushMessage> messages, Map<String, PosOrder> foodOrders,
|
|
private void fillOrderInfo(List<PushMessage> messages, Map<String, PosOrder> foodOrders,
|
|
|
- Map<String, FlashDeliveryOrder> flashOrders)
|
|
|
|
|
|
|
+ Map<String, FlashDeliveryOrder> flashOrders, Map<Long, String> flashFirstImages)
|
|
|
{
|
|
{
|
|
|
for (PushMessage message : messages)
|
|
for (PushMessage message : messages)
|
|
|
{
|
|
{
|
|
@@ -174,6 +184,7 @@ public class PushMessageServiceImpl extends ServiceImpl<BaseMapper<PushMessage>,
|
|
|
{
|
|
{
|
|
|
message.setShopName(order.getPosName());
|
|
message.setShopName(order.getPosName());
|
|
|
message.setShAddress(order.getShAddress());
|
|
message.setShAddress(order.getShAddress());
|
|
|
|
|
+ message.setOrderImage(firstFoodImage(order.getFood()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else if (Integer.valueOf(3).equals(message.getPushType()))
|
|
else if (Integer.valueOf(3).equals(message.getPushType()))
|
|
@@ -185,8 +196,88 @@ public class PushMessageServiceImpl extends ServiceImpl<BaseMapper<PushMessage>,
|
|
|
message.setPickupAddressDetail(order.getPickupAddressDetail());
|
|
message.setPickupAddressDetail(order.getPickupAddressDetail());
|
|
|
message.setDeliveryAddress(order.getDeliveryAddress());
|
|
message.setDeliveryAddress(order.getDeliveryAddress());
|
|
|
message.setDeliveryAddressDetail(order.getDeliveryAddressDetail());
|
|
message.setDeliveryAddressDetail(order.getDeliveryAddressDetail());
|
|
|
|
|
+ if (order.getId() != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ message.setOrderImage(flashFirstImages.get(order.getId()));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 外卖订单缩略图:food 快照数组第一行的 image 键(行结构由 App 下单传入,
|
|
|
|
|
+ * 含 id/name/image/price/otherPrice/number 等);food 为空或非法返回 null。
|
|
|
|
|
+ */
|
|
|
|
|
+ private String firstFoodImage(String food)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (StringUtils.isEmpty(food))
|
|
|
|
|
+ {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ JSONArray rows = JSONArray.parseArray(food);
|
|
|
|
|
+ if (rows == null || rows.isEmpty())
|
|
|
|
|
+ {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject first = rows.getJSONObject(0);
|
|
|
|
|
+ String image = first == null ? null : first.getString("image");
|
|
|
|
|
+ return StringUtils.isEmpty(image) ? null : image;
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception e)
|
|
|
|
|
+ {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 闪送订单缩略图:批量查寄件凭证(SENDER),每单取 sortOrder 最小的一张;无凭证返回空。 */
|
|
|
|
|
+ private Map<Long, String> firstSenderImages(Collection<FlashDeliveryOrder> orders)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (orders == null || orders.isEmpty())
|
|
|
|
|
+ {
|
|
|
|
|
+ return Collections.emptyMap();
|
|
|
|
|
+ }
|
|
|
|
|
+ Set<Long> orderIds = new LinkedHashSet<>();
|
|
|
|
|
+ for (FlashDeliveryOrder order : orders)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (order != null && order.getId() != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ orderIds.add(order.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (orderIds.isEmpty())
|
|
|
|
|
+ {
|
|
|
|
|
+ return Collections.emptyMap();
|
|
|
|
|
+ }
|
|
|
|
|
+ List<FlashDeliveryOrderImage> images = flashDeliveryOrderImageMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<FlashDeliveryOrderImage>()
|
|
|
|
|
+ .in(FlashDeliveryOrderImage::getOrderId, orderIds)
|
|
|
|
|
+ .eq(FlashDeliveryOrderImage::getProofType, "SENDER"));
|
|
|
|
|
+ if (images == null || images.isEmpty())
|
|
|
|
|
+ {
|
|
|
|
|
+ return Collections.emptyMap();
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<Long, FlashDeliveryOrderImage> firstImages = new HashMap<>();
|
|
|
|
|
+ for (FlashDeliveryOrderImage image : images)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (image == null || image.getOrderId() == null || StringUtils.isEmpty(image.getImageUrl())
|
|
|
|
|
+ || !"SENDER".equals(image.getProofType()))
|
|
|
|
|
+ {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ firstImages.merge(image.getOrderId(), image,
|
|
|
|
|
+ (current, candidate) -> sortKey(candidate) < sortKey(current) ? candidate : current);
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<Long, String> result = new HashMap<>();
|
|
|
|
|
+ firstImages.forEach((orderId, image) -> result.put(orderId, image.getImageUrl()));
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 凭证展示顺序;sortOrder 缺失时排最后。 */
|
|
|
|
|
+ private int sortKey(FlashDeliveryOrderImage image)
|
|
|
|
|
+ {
|
|
|
|
|
+ return image.getSortOrder() == null ? Integer.MAX_VALUE : image.getSortOrder();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|