Prechádzať zdrojové kódy

设备增加搜索 名称或id

谭斌 1 rok pred
rodič
commit
c5afc1de2b

+ 31 - 1
device-api-service/src/main/java/com/xy/service/DeviceInfoServiceImpl.java

@@ -669,7 +669,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
     @Override
     @ApiOperation("小程序-商户设备首页列表")
     public R<List<DeviceInfoDto.MercHomeListVO>> mercHomeList(DeviceInfoDto.MercHomeQueryDTO dto) {
-
+        String searchKey = dto.getSearchKey();
         Long mercId = dto.getMercId();
         String deviceName = dto.getDeviceName();
         Long deviceId = dto.getDeviceId();
@@ -679,6 +679,23 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
         } else {
             dto.setActiveState("1");
         }
+        List<Long> searchDeviceIds = new ArrayList<>();
+        if (StrUtil.isNotEmpty(searchKey)) {
+            //名称或者编号搜索设备
+            List<DeviceInfo> list = list(Wrappers.<DeviceInfo>lambdaQuery()
+                    .eq(DeviceInfo::getMercId, mercId)
+                    .and(wrapper -> wrapper
+                            .eq(DeviceInfo::getDeviceId, deviceId)
+                            .or()
+                            .likeRight(DeviceInfo::getDeviceName, searchKey)
+                    )
+            );
+            if (CollUtil.isEmpty(list)) {
+                return R.ok(new ArrayList<>());
+            }
+            searchDeviceIds = list.stream().map(DeviceInfo::getDeviceId).collect(Collectors.toList());
+        }
+
 
         List<Long> myDeviceIds = dto.getDeviceIdList();
 
@@ -706,6 +723,19 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
         }
         if (CollUtil.isNotEmpty(deviceIdList)) {
             dto.setDeviceIdList(deviceIdList);
+            List<Long> queryDeviceIds = new ArrayList<>();
+            if (CollUtil.isNotEmpty(searchDeviceIds)) {
+                searchDeviceIds.forEach(id -> {
+                    if (deviceIdList.contains(id)) {
+                        queryDeviceIds.add(id);
+                    }
+                });
+                //无符合权限的搜索设备,返空
+                if (CollUtil.isEmpty(queryDeviceIds)) {
+                    return R.ok(new ArrayList<>());
+                }
+            }
+
         } else {
             return R.ok(new ArrayList<>());
         }

+ 4 - 0
device-api/src/main/java/com/xy/dto/DeviceInfoDto.java

@@ -655,6 +655,10 @@ public class DeviceInfoDto {
         @ApiModelProperty(value = "设备名称")
         private String deviceName;
 
+        @ApiModelProperty(value = "搜索关键词")
+        private String searchKey;
+
+
         @ApiModelProperty("设备编号")
         private Long deviceId;