Prechádzať zdrojové kódy

feat: ERP店铺列表增加已绑定/未绑定筛选

- 后端: listAll 新增 boundStatus 参数,通过 t_device.erp_shop_id 判断
- 前端: 页面新增绑定状态下拉筛选

Co-Authored-By: Claude <noreply@anthropic.com>
skyline 1 deň pred
rodič
commit
806143b56a

+ 1 - 1
haha-admin-web/src/api/erpShop.ts

@@ -11,7 +11,7 @@ export const syncErpShops = () =>
   http.request<Result>("post", "/erp-shops/sync");
 
 /** 分页获取已缓存的 ERP 店铺列表 */
-export const getErpShopList = (params: { keyword?: string; page: number; pageSize: number }) =>
+export const getErpShopList = (params: { keyword?: string; boundStatus?: number; page: number; pageSize: number }) =>
   http.request<Result>("get", "/erp-shops", { params });
 
 /** 绑定设备与 ERP 店铺 */

+ 12 - 0
haha-admin-web/src/views/erp-shop/index.vue

@@ -24,6 +24,7 @@ const syncing = ref(false);
 const autoBinding = ref(false);
 const unbindingAll = ref(false);
 const keyword = ref("");
+const boundStatus = ref<number | undefined>(undefined);
 const dataList = ref<any[]>([]);
 const total = ref(0);
 const pagination = reactive({ currentPage: 1, pageSize: 10 });
@@ -38,6 +39,7 @@ async function fetchList() {
   try {
     const res = await getErpShopList({
       keyword: keyword.value || undefined,
+      boundStatus: boundStatus.value,
       page: pagination.currentPage,
       pageSize: pagination.pageSize
     });
@@ -201,6 +203,16 @@ onMounted(() => {
     <div class="px-6 pt-4 flex items-center justify-between">
       <h2 class="text-lg font-semibold">ERP 店铺管理</h2>
       <div class="flex items-center gap-3">
+        <el-select
+          v-model="boundStatus"
+          placeholder="绑定状态"
+          clearable
+          class="w-[140px]!"
+          @change="handleSearch"
+        >
+          <el-option label="已绑定" :value="1" />
+          <el-option label="未绑定" :value="0" />
+        </el-select>
         <el-input
           v-model="keyword"
           placeholder="搜索店铺名称或卖家账号"

+ 2 - 1
haha-admin/src/main/java/com/haha/admin/controller/ErpShopController.java

@@ -42,9 +42,10 @@ public class ErpShopController {
     @RequirePermission("erp:shop:read")
     @GetMapping
     public Result<PageResult<ErpShop>> list(@RequestParam(required = false) String keyword,
+                                             @RequestParam(required = false) Integer boundStatus,
                                              @RequestParam(defaultValue = "1") int page,
                                              @RequestParam(defaultValue = "10") int pageSize) {
-        IPage<ErpShop> pageResult = erpShopService.listAll(keyword, page, pageSize);
+        IPage<ErpShop> pageResult = erpShopService.listAll(keyword, boundStatus, page, pageSize);
         return Result.success("查询成功", PageResult.of(pageResult));
     }
 

+ 1 - 1
haha-service/src/main/java/com/haha/service/ErpShopService.java

@@ -11,7 +11,7 @@ public interface ErpShopService extends IService<ErpShop> {
 
     void syncFromErp();
 
-    IPage<ErpShop> listAll(String keyword, int page, int pageSize);
+    IPage<ErpShop> listAll(String keyword, Integer boundStatus, int page, int pageSize);
 
     void bindDevice(Long deviceId, Long erpShopId);
 

+ 27 - 1
haha-service/src/main/java/com/haha/service/impl/ErpShopServiceImpl.java

@@ -33,7 +33,9 @@ import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Service
@@ -106,7 +108,7 @@ public class ErpShopServiceImpl extends ServiceImpl<ErpShopMapper, ErpShop> impl
     }
 
     @Override
-    public IPage<ErpShop> listAll(String keyword, int page, int pageSize) {
+    public IPage<ErpShop> listAll(String keyword, Integer boundStatus, int page, int pageSize) {
         LambdaQueryWrapper<ErpShop> wrapper = new LambdaQueryWrapper<ErpShop>()
                 .eq(ErpShop::getStatus, 1);
         if (StringUtils.hasText(keyword)) {
@@ -115,6 +117,30 @@ public class ErpShopServiceImpl extends ServiceImpl<ErpShopMapper, ErpShop> impl
                     .or()
                     .like(ErpShop::getNickName, keyword));
         }
+
+        // 已绑定/未绑定筛选:通过 t_device.erp_shop_id 关联判断
+        if (boundStatus != null) {
+            List<Device> boundDevices = deviceMapper.selectList(new LambdaQueryWrapper<Device>()
+                    .isNotNull(Device::getErpShopId)
+                    .select(Device::getErpShopId));
+            Set<Long> boundErpShopIds = boundDevices.stream()
+                    .map(Device::getErpShopId).filter(Objects::nonNull).collect(Collectors.toSet());
+
+            if (boundStatus == 1) {
+                // 已绑定
+                if (boundErpShopIds.isEmpty()) {
+                    // 没有任何设备已绑定,返回空页
+                    return new Page<>(page, pageSize);
+                }
+                wrapper.in(ErpShop::getErpShopId, boundErpShopIds);
+            } else {
+                // 未绑定
+                if (!boundErpShopIds.isEmpty()) {
+                    wrapper.notIn(ErpShop::getErpShopId, boundErpShopIds);
+                }
+            }
+        }
+
         return page(new Page<>(page, pageSize), wrapper.orderByAsc(ErpShop::getShopName));
     }