|
@@ -1,14 +1,15 @@
|
|
|
package com.ruoyi.app.unifiedorder;
|
|
package com.ruoyi.app.unifiedorder;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ruoyi.app.unifiedorder.dto.UnifiedOrderListItem;
|
|
import com.ruoyi.app.unifiedorder.dto.UnifiedOrderListItem;
|
|
|
import com.ruoyi.app.unifiedorder.dto.UnifiedOrderPageView;
|
|
import com.ruoyi.app.unifiedorder.dto.UnifiedOrderPageView;
|
|
|
-import com.ruoyi.system.domain.InfoUser;
|
|
|
|
|
import com.ruoyi.system.domain.PosOrder;
|
|
import com.ruoyi.system.domain.PosOrder;
|
|
|
|
|
+import com.ruoyi.system.domain.PosStore;
|
|
|
import com.ruoyi.system.domain.flash.FlashDeliveryOrder;
|
|
import com.ruoyi.system.domain.flash.FlashDeliveryOrder;
|
|
|
-import com.ruoyi.system.mapper.InfoUserMapper;
|
|
|
|
|
import com.ruoyi.system.mapper.PosOrderMapper;
|
|
import com.ruoyi.system.mapper.PosOrderMapper;
|
|
|
|
|
+import com.ruoyi.system.mapper.PosStoreMapper;
|
|
|
import com.ruoyi.system.mapper.flash.FlashDeliveryOrderMapper;
|
|
import com.ruoyi.system.mapper.flash.FlashDeliveryOrderMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
@@ -39,14 +40,14 @@ public class UnifiedOrderQueryService {
|
|
|
|
|
|
|
|
private final PosOrderMapper posOrderMapper;
|
|
private final PosOrderMapper posOrderMapper;
|
|
|
private final FlashDeliveryOrderMapper flashOrderMapper;
|
|
private final FlashDeliveryOrderMapper flashOrderMapper;
|
|
|
- private final InfoUserMapper infoUserMapper;
|
|
|
|
|
|
|
+ private final PosStoreMapper posStoreMapper;
|
|
|
|
|
|
|
|
public UnifiedOrderQueryService(PosOrderMapper posOrderMapper,
|
|
public UnifiedOrderQueryService(PosOrderMapper posOrderMapper,
|
|
|
FlashDeliveryOrderMapper flashOrderMapper,
|
|
FlashDeliveryOrderMapper flashOrderMapper,
|
|
|
- InfoUserMapper infoUserMapper) {
|
|
|
|
|
|
|
+ PosStoreMapper posStoreMapper) {
|
|
|
this.posOrderMapper = posOrderMapper;
|
|
this.posOrderMapper = posOrderMapper;
|
|
|
this.flashOrderMapper = flashOrderMapper;
|
|
this.flashOrderMapper = flashOrderMapper;
|
|
|
- this.infoUserMapper = infoUserMapper;
|
|
|
|
|
|
|
+ this.posStoreMapper = posStoreMapper;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 查询统一列表:size 服务端钳制 1-50;cursor 为空表示首页。 */
|
|
/** 查询统一列表:size 服务端钳制 1-50;cursor 为空表示首页。 */
|
|
@@ -74,11 +75,11 @@ public class UnifiedOrderQueryService {
|
|
|
List<Row> displayed = hasMore ? rows.subList(0, limit) : rows;
|
|
List<Row> displayed = hasMore ? rows.subList(0, limit) : rows;
|
|
|
|
|
|
|
|
UnifiedOrderPageView view = new UnifiedOrderPageView();
|
|
UnifiedOrderPageView view = new UnifiedOrderPageView();
|
|
|
- Map<Long, String> storeNames = storeNamesOf(displayed);
|
|
|
|
|
|
|
+ Map<Long, PosStore> stores = storesOf(displayed);
|
|
|
List<UnifiedOrderListItem> items = new ArrayList<>(displayed.size());
|
|
List<UnifiedOrderListItem> items = new ArrayList<>(displayed.size());
|
|
|
for (Row row : displayed) {
|
|
for (Row row : displayed) {
|
|
|
items.add(row.takeaway() != null
|
|
items.add(row.takeaway() != null
|
|
|
- ? takeawayItem(row.takeaway(), storeNames)
|
|
|
|
|
|
|
+ ? takeawayItem(row.takeaway(), stores)
|
|
|
: flashItem(row.flash(), userId));
|
|
: flashItem(row.flash(), userId));
|
|
|
}
|
|
}
|
|
|
view.setList(items);
|
|
view.setList(items);
|
|
@@ -130,25 +131,26 @@ public class UnifiedOrderQueryService {
|
|
|
return wrapper;
|
|
return wrapper;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Map<Long, String> storeNamesOf(List<Row> displayed) {
|
|
|
|
|
- Set<Long> shopIds = new HashSet<>();
|
|
|
|
|
|
|
+ /** 外卖条目按门店 ID 批量查 pos_store,一次回填店铺名称/头像。 */
|
|
|
|
|
+ private Map<Long, PosStore> storesOf(List<Row> displayed) {
|
|
|
|
|
+ Set<Long> mdIds = new HashSet<>();
|
|
|
for (Row row : displayed) {
|
|
for (Row row : displayed) {
|
|
|
- if (row.takeaway() != null && row.takeaway().getShId() != null) {
|
|
|
|
|
- shopIds.add(row.takeaway().getShId());
|
|
|
|
|
|
|
+ if (row.takeaway() != null && row.takeaway().getMdId() != null) {
|
|
|
|
|
+ mdIds.add(row.takeaway().getMdId());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- Map<Long, String> names = new HashMap<>();
|
|
|
|
|
- if (!shopIds.isEmpty()) {
|
|
|
|
|
- for (InfoUser user : infoUserMapper.selectBatchIds(shopIds)) {
|
|
|
|
|
- if (user != null && user.getUserId() != null) {
|
|
|
|
|
- names.put(user.getUserId(), user.getNickName());
|
|
|
|
|
|
|
+ Map<Long, PosStore> stores = new HashMap<>();
|
|
|
|
|
+ if (!mdIds.isEmpty()) {
|
|
|
|
|
+ for (PosStore store : posStoreMapper.selectBatchIds(mdIds)) {
|
|
|
|
|
+ if (store != null && store.getId() != null) {
|
|
|
|
|
+ stores.put(store.getId().longValue(), store);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return names;
|
|
|
|
|
|
|
+ return stores;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private UnifiedOrderListItem takeawayItem(PosOrder order, Map<Long, String> storeNames) {
|
|
|
|
|
|
|
+ private UnifiedOrderListItem takeawayItem(PosOrder order, Map<Long, PosStore> stores) {
|
|
|
UnifiedOrderListItem item = new UnifiedOrderListItem();
|
|
UnifiedOrderListItem item = new UnifiedOrderListItem();
|
|
|
item.setSourceType("takeaway");
|
|
item.setSourceType("takeaway");
|
|
|
item.setRole("sender");
|
|
item.setRole("sender");
|
|
@@ -164,11 +166,35 @@ public class UnifiedOrderQueryService {
|
|
|
item.setPayStatus(order.getPayStatus());
|
|
item.setPayStatus(order.getPayStatus());
|
|
|
item.setPayType(order.getPayType());
|
|
item.setPayType(order.getPayType());
|
|
|
item.setAfterSaleStatus(order.getAfterSaleStatus());
|
|
item.setAfterSaleStatus(order.getAfterSaleStatus());
|
|
|
- item.setStoreName(order.getShId() == null ? null : storeNames.get(order.getShId()));
|
|
|
|
|
|
|
+ // 店铺已删或 mdId 缺失时回退订单创建时的快照 posName/logo
|
|
|
|
|
+ PosStore store = order.getMdId() == null ? null : stores.get(order.getMdId());
|
|
|
|
|
+ item.setStoreName(store != null ? store.getPosName() : order.getPosName());
|
|
|
|
|
+ item.setStoreAvatar(store != null ? store.getLogo() : order.getLogo());
|
|
|
|
|
+ item.setGoodsCount(takeawayGoodsCount(order.getFood()));
|
|
|
item.setCollectPayment(order.getCollectPayment());
|
|
item.setCollectPayment(order.getCollectPayment());
|
|
|
return item;
|
|
return item;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** 商品件数:food 快照数组各行 number 求和;food 为空或非法返回 null。 */
|
|
|
|
|
+ private Integer takeawayGoodsCount(String food) {
|
|
|
|
|
+ if (food == null || food.isBlank()) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSONArray rows = JSONArray.parseArray(food);
|
|
|
|
|
+ int count = 0;
|
|
|
|
|
+ for (int i = 0; i < rows.size(); i++) {
|
|
|
|
|
+ Integer num = rows.getJSONObject(i).getInteger("number");
|
|
|
|
|
+ if (num != null) {
|
|
|
|
|
+ count += num;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return count;
|
|
|
|
|
+ } catch (RuntimeException e) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private UnifiedOrderListItem flashItem(FlashDeliveryOrder order, Long userId) {
|
|
private UnifiedOrderListItem flashItem(FlashDeliveryOrder order, Long userId) {
|
|
|
UnifiedOrderListItem item = new UnifiedOrderListItem();
|
|
UnifiedOrderListItem item = new UnifiedOrderListItem();
|
|
|
item.setSourceType("flash");
|
|
item.setSourceType("flash");
|