|
|
@@ -6,12 +6,12 @@ import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ruoyi.app.unifiedorder.dto.UnifiedOrderListItem;
|
|
|
import com.ruoyi.app.unifiedorder.dto.UnifiedOrderPageView;
|
|
|
-import com.ruoyi.system.domain.InfoUser;
|
|
|
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.FlashDeliveryStatus;
|
|
|
-import com.ruoyi.system.mapper.InfoUserMapper;
|
|
|
import com.ruoyi.system.mapper.PosOrderMapper;
|
|
|
+import com.ruoyi.system.mapper.PosStoreMapper;
|
|
|
import com.ruoyi.system.mapper.flash.FlashDeliveryOrderMapper;
|
|
|
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
|
@@ -43,9 +43,9 @@ class UnifiedOrderQueryServiceTest {
|
|
|
|
|
|
private final PosOrderMapper posOrderMapper = mock(PosOrderMapper.class);
|
|
|
private final FlashDeliveryOrderMapper flashOrderMapper = mock(FlashDeliveryOrderMapper.class);
|
|
|
- private final InfoUserMapper infoUserMapper = mock(InfoUserMapper.class);
|
|
|
+ private final PosStoreMapper posStoreMapper = mock(PosStoreMapper.class);
|
|
|
private final UnifiedOrderQueryService service =
|
|
|
- new UnifiedOrderQueryService(posOrderMapper, flashOrderMapper, infoUserMapper);
|
|
|
+ new UnifiedOrderQueryService(posOrderMapper, flashOrderMapper, posStoreMapper);
|
|
|
|
|
|
@BeforeAll
|
|
|
static void initializeTableMetadata() {
|
|
|
@@ -183,22 +183,24 @@ class UnifiedOrderQueryServiceTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- void takeawayItemsCarryStoreNameFromSingleBatchLookup() {
|
|
|
+ void takeawayItemsCarryStoreNameAndAvatarFromSingleBatchLookup() {
|
|
|
PosOrder first = takeaway(21L, 3000L);
|
|
|
- first.setShId(55L);
|
|
|
+ first.setMdId(55L);
|
|
|
PosOrder second = takeaway(22L, 2000L);
|
|
|
- second.setShId(56L);
|
|
|
+ second.setMdId(56L);
|
|
|
PosOrder third = takeaway(23L, 1000L);
|
|
|
- third.setShId(55L);
|
|
|
+ third.setMdId(55L);
|
|
|
doReturn(pageOf(List.of(first, second, third))).when(posOrderMapper).selectPage(any(), any());
|
|
|
doReturn(pageOf(List.of())).when(flashOrderMapper).selectPage(any(), any());
|
|
|
- InfoUser shopA = new InfoUser();
|
|
|
- shopA.setUserId(55L);
|
|
|
- shopA.setNickName("店铺A");
|
|
|
- InfoUser shopB = new InfoUser();
|
|
|
- shopB.setUserId(56L);
|
|
|
- shopB.setNickName("店铺B");
|
|
|
- when(infoUserMapper.selectBatchIds(anyCollection())).thenReturn(List.of(shopA, shopB));
|
|
|
+ PosStore shopA = new PosStore();
|
|
|
+ shopA.setId(55);
|
|
|
+ shopA.setPosName("店铺A");
|
|
|
+ shopA.setLogo("http://img/a.png");
|
|
|
+ PosStore shopB = new PosStore();
|
|
|
+ shopB.setId(56);
|
|
|
+ shopB.setPosName("店铺B");
|
|
|
+ shopB.setLogo("http://img/b.png");
|
|
|
+ when(posStoreMapper.selectBatchIds(anyCollection())).thenReturn(List.of(shopA, shopB));
|
|
|
|
|
|
UnifiedOrderPageView view = service.query(USER_ID, UnifiedOrderTab.ALL, OrderSource.TAKEAWAY, null, 10);
|
|
|
|
|
|
@@ -206,7 +208,44 @@ class UnifiedOrderQueryServiceTest {
|
|
|
assertEquals("店铺A", view.getList().get(0).getStoreName());
|
|
|
assertEquals("店铺B", view.getList().get(1).getStoreName());
|
|
|
assertEquals("店铺A", view.getList().get(2).getStoreName());
|
|
|
- verify(infoUserMapper, times(1)).selectBatchIds(anyCollection());
|
|
|
+ assertEquals("http://img/a.png", view.getList().get(0).getStoreAvatar());
|
|
|
+ assertEquals("http://img/b.png", view.getList().get(1).getStoreAvatar());
|
|
|
+ verify(posStoreMapper, times(1)).selectBatchIds(anyCollection());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void takeawayFallsBackToOrderSnapshotWhenStoreMissing() {
|
|
|
+ PosOrder order = takeaway(21L, 3000L);
|
|
|
+ order.setMdId(404L);
|
|
|
+ order.setPosName("快照店铺");
|
|
|
+ order.setLogo("http://img/snap.png");
|
|
|
+ doReturn(pageOf(List.of(order))).when(posOrderMapper).selectPage(any(), any());
|
|
|
+ doReturn(pageOf(List.of())).when(flashOrderMapper).selectPage(any(), any());
|
|
|
+ when(posStoreMapper.selectBatchIds(anyCollection())).thenReturn(List.of());
|
|
|
+
|
|
|
+ UnifiedOrderPageView view = service.query(USER_ID, UnifiedOrderTab.ALL, OrderSource.TAKEAWAY, null, 10);
|
|
|
+
|
|
|
+ assertEquals("快照店铺", view.getList().get(0).getStoreName());
|
|
|
+ assertEquals("http://img/snap.png", view.getList().get(0).getStoreAvatar());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void takeawayGoodsCountSumsFoodNumberFields() {
|
|
|
+ PosOrder order = takeaway(21L, 3000L);
|
|
|
+ order.setFood("[{\"name\":\"餐A\",\"number\":2},{\"name\":\"餐B\",\"number\":3}]");
|
|
|
+ PosOrder emptyFood = takeaway(22L, 2000L);
|
|
|
+ PosOrder brokenFood = takeaway(23L, 1000L);
|
|
|
+ brokenFood.setFood("not-json");
|
|
|
+ doReturn(pageOf(List.of(order, emptyFood, brokenFood)))
|
|
|
+ .when(posOrderMapper).selectPage(any(), any());
|
|
|
+ doReturn(pageOf(List.of())).when(flashOrderMapper).selectPage(any(), any());
|
|
|
+ when(posStoreMapper.selectBatchIds(anyCollection())).thenReturn(List.of());
|
|
|
+
|
|
|
+ UnifiedOrderPageView view = service.query(USER_ID, UnifiedOrderTab.ALL, OrderSource.TAKEAWAY, null, 10);
|
|
|
+
|
|
|
+ assertEquals(5, view.getList().get(0).getGoodsCount());
|
|
|
+ assertNull(view.getList().get(1).getGoodsCount());
|
|
|
+ assertNull(view.getList().get(2).getGoodsCount());
|
|
|
}
|
|
|
|
|
|
@Test
|