Переглянути джерело

解决设备状态查询的bug

oyq28 2 роки тому
батько
коміт
db8aa08e5e

+ 2 - 0
imcs-bt-be/imcs-business-biz/src/main/java/com/github/zuihou/business/productionresource/service/ProductionTenantResourceService.java

@@ -25,4 +25,6 @@ public interface ProductionTenantResourceService extends SuperService<Production
     List<EquGoodsDto> getEquGoods(Long equId);
 
     HashMap<String, String> getEquRunInfo(Long equId);
+
+    List<String> getEquStatusIds(String onlineStatus);
 }

+ 12 - 0
imcs-bt-be/imcs-business-biz/src/main/java/com/github/zuihou/business/productionresource/service/impl/ProductionTenantResourceServiceImpl.java

@@ -16,6 +16,8 @@ import org.springframework.stereotype.Service;
 
 import java.util.HashMap;
 import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -60,4 +62,14 @@ public class ProductionTenantResourceServiceImpl extends SuperServiceImpl<Produc
         }
         return resultMap;
     }
+
+    @Override
+    public List<String> getEquStatusIds(String onlineStatus) {
+        Set<String> keys = redisTemplate.keys("equStatus" + "*");
+        List<String> list=keys.stream().filter(key->{
+            String status = (String) redisTemplate.opsForHash().get(key, "status");
+            return status.equals(onlineStatus);
+        }).map(item->item.replace("equStatus","")).collect(Collectors.toList());
+        return list;
+    }
 }

+ 7 - 1
imcs-bt-be/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/productionresource/ProductionResourceController.java

@@ -30,6 +30,7 @@ import com.github.zuihou.utils.DateUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
@@ -87,9 +88,14 @@ public class ProductionResourceController extends SuperController<ProductionTena
         ProductionResource model = BeanUtil.toBean(data, ProductionResource.class);
         QueryWrap<ProductionResource> wrap = this.handlerWrapper(null, params);
         LbqWrapper<ProductionResource> wrapper = wrap.lambda();
-        wrapper.like(ProductionResource::getName, model.getName()).like(ProductionResource::getStatus, model.getStatus()).eq(ProductionResource::getOnlineStatus, model.getOnlineStatus()).eq(ProductionResource::getPlaceId, model.getPlaceId())
+        wrapper.like(ProductionResource::getName, model.getName()).like(ProductionResource::getStatus, model.getStatus()).eq(ProductionResource::getPlaceId, model.getPlaceId())
                 .eq(ProductionResource::getAreaId, model.getAreaId())
                 .orderByDesc(ProductionResource::getCreateTime);
+        if(StringUtils.isNotEmpty(model.getOnlineStatus())){
+            //获取特定状态下的设备Id
+            List<String> ids = baseService.getEquStatusIds(model.getOnlineStatus());
+            wrapper.in(ProductionResource::getId, ids);
+        }
         IPage<ProductionResource> iPage = baseService.pageList(page, wrapper);
 
         String date = DateUtil.dateToString(new Date());