Kaynağa Gözat

餐桌码列表返回门店名称

qmj 2 gün önce
ebeveyn
işleme
85ef8987a3

+ 18 - 0
ruoyi-admin/src/main/java/com/ruoyi/app/tableqrcode/TableQrcodeController.java

@@ -24,6 +24,9 @@ import org.springframework.web.bind.annotation.*;
 
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 /**
@@ -238,6 +241,21 @@ public class TableQrcodeController extends BaseController
 
         }
         List<TableQrcode> list = tableQrcodeService.list(query);
+        Set<Long> storeIds = list.stream()
+                .map(TableQrcode::getStoreId)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+        if (!storeIds.isEmpty())
+        {
+            Map<Long, String> storeNames = posStoreService.listByIds(storeIds).stream()
+                    .filter(store -> store.getId() != null)
+                    .collect(Collectors.toMap(
+                            store -> store.getId().longValue(),
+                            PosStore::getPosName,
+                            (first, second) -> first));
+            list.forEach(tableQrcode -> tableQrcode.setStoreName(
+                    tableQrcode.getStoreId() == null ? null : storeNames.get(tableQrcode.getStoreId())));
+        }
         return success(list);
     }
 

+ 89 - 0
ruoyi-admin/src/test/java/com/ruoyi/app/tableqrcode/TableQrcodeControllerTest.java

@@ -0,0 +1,89 @@
+package com.ruoyi.app.tableqrcode;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.MessageUtils;
+import com.ruoyi.system.domain.InfoUser;
+import com.ruoyi.system.domain.PosStore;
+import com.ruoyi.system.domain.TableQrcode;
+import com.ruoyi.system.service.IInfoUserService;
+import com.ruoyi.system.service.IPosStoreService;
+import com.ruoyi.system.service.ITableQrcodeService;
+import com.ruoyi.system.utils.JwtUtil;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+class TableQrcodeControllerTest {
+
+    private TableQrcodeController controller;
+    private ITableQrcodeService tableQrcodeService;
+    private IInfoUserService infoUserService;
+    private IPosStoreService posStoreService;
+    private MockedStatic<MessageUtils> messages;
+
+    @BeforeEach
+    void setUp() {
+        controller = new TableQrcodeController();
+        tableQrcodeService = mock(ITableQrcodeService.class);
+        infoUserService = mock(IInfoUserService.class);
+        posStoreService = mock(IPosStoreService.class);
+        ReflectionTestUtils.setField(controller, "tableQrcodeService", tableQrcodeService);
+        ReflectionTestUtils.setField(controller, "infoUserService", infoUserService);
+        ReflectionTestUtils.setField(controller, "posStoreService", posStoreService);
+
+        messages = mockStatic(MessageUtils.class);
+        messages.when(() -> MessageUtils.message(anyString()))
+                .thenAnswer(invocation -> invocation.getArgument(0));
+    }
+
+    @AfterEach
+    void tearDown() {
+        messages.close();
+    }
+
+    @Test
+    void listIncludesStoreNameForStoreCodesAndLeavesPublicCodesEmpty() {
+        InfoUser merchant = new InfoUser();
+        merchant.setUserId(101L);
+        merchant.setUserType("4");
+        merchant.setStoreId(11L);
+        when(infoUserService.selectInfoUserByUserId(101L)).thenReturn(merchant);
+
+        TableQrcode storeCode = new TableQrcode();
+        storeCode.setId(1L);
+        storeCode.setStoreId(11L);
+        TableQrcode publicCode = new TableQrcode();
+        publicCode.setId(2L);
+        when(tableQrcodeService.list(org.mockito.ArgumentMatchers
+                .<Wrapper<TableQrcode>>any())).thenReturn(List.of(storeCode, publicCode));
+
+        PosStore store = new PosStore();
+        store.setId(11);
+        store.setPosName("烧烤摊");
+        when(posStoreService.listByIds(any())).thenReturn(List.of(store));
+
+        AjaxResult result = controller.list(tokenFor(101L), null, null, null, null);
+
+        @SuppressWarnings("unchecked")
+        List<TableQrcode> data = (List<TableQrcode>) result.get(AjaxResult.DATA_TAG);
+        assertEquals("烧烤摊", data.get(0).getStoreName());
+        assertNull(data.get(1).getStoreName());
+    }
+
+    private static String tokenFor(Long userId) {
+        return JwtUtil.setToken(String.valueOf(userId), "merchant");
+    }
+}

+ 3 - 3
specs/002-table-qrcode/tasks.md

@@ -116,9 +116,9 @@
 
 ## Phase 8: 餐桌码列表补全门店名称(2026-08-24)
 
-- [ ] T025 为 `TableQrcodeController.list` 增加回归测试,验证关联门店的餐桌码返回正确 `storeName`,无 `storeId` 的公用码返回 `null` — `ruoyi-admin/src/test/java/com/ruoyi/app/tableqrcode/TableQrcodeControllerTest.java`
-- [ ] T026 保留现有权限查询,在列表返回前批量查询涉及的门店并回填 `storeName`,不得逐条查库 — `ruoyi-admin/src/main/java/com/ruoyi/app/tableqrcode/TableQrcodeController.java`
-- [ ] T027 使用 JDK 21 运行 `TableQrcodeControllerTest`、受影响模块构建及差异检查
+- [x] T025 为 `TableQrcodeController.list` 增加回归测试,验证关联门店的餐桌码返回正确 `storeName`,无 `storeId` 的公用码返回 `null` — `ruoyi-admin/src/test/java/com/ruoyi/app/tableqrcode/TableQrcodeControllerTest.java`
+- [x] T026 保留现有权限查询,在列表返回前批量查询涉及的门店并回填 `storeName`,不得逐条查库 — `ruoyi-admin/src/main/java/com/ruoyi/app/tableqrcode/TableQrcodeController.java`
+- [x] T027 使用 JDK 21 运行 `TableQrcodeControllerTest`、受影响模块构建及差异检查
 
 ---