Bladeren bron

企业端后台设备状态功能bug修复

oyq28 2 jaren geleden
bovenliggende
commit
b0df14727a

+ 2 - 0
imcs-bt-be/imcs-tenant-biz/src/main/java/com/github/zuihou/tenant/service/ProductionresourceService.java

@@ -114,4 +114,6 @@ public interface ProductionresourceService extends SuperCacheService<Productionr
     public String getGatherSQL();
 
     IPage<Productionresource> selcetPage(PageParams<ProductionresourcePageDTO> params);
+
+    Map<String, String> getEquRunInfo(Long id);
 }

+ 17 - 0
imcs-bt-be/imcs-tenant-biz/src/main/java/com/github/zuihou/tenant/service/impl/ProductionresourceServiceImpl.java

@@ -753,6 +753,23 @@ public class ProductionresourceServiceImpl extends SuperCacheServiceImpl<Product
         return null;
     }
 
+    @Override
+    public Map<String, String> getEquRunInfo(Long equId) {
+        HashMap<String, String> resultMap = new HashMap<>();
+        Boolean exist = redisTemplate.hasKey("equStatus" + equId);
+        if (exist) {
+            String status = (String) redisTemplate.opsForHash().get("equStatus" + equId, "status");
+            if (status.equals("2")) {
+                String errMsg = (String) redisTemplate.opsForHash().get("equStatus" + equId, "errMsg");
+                resultMap.put("errMsg", errMsg);
+            }
+            resultMap.put("equStatus", status);
+        } else {
+            resultMap.put("equStatus", "0");
+        }
+        return resultMap;
+    }
+
 
     /**
      * 设置汉字。状态等等

+ 46 - 3
imcs-bt-be/imcs-tenant-controller/src/main/java/com/github/zuihou/tenant/controller/ProductionresourceController.java

@@ -2,6 +2,7 @@ package com.github.zuihou.tenant.controller;
 
 import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.github.zuihou.authority.service.auth.UserService;
 import com.github.zuihou.base.R;
 import com.github.zuihou.base.controller.SuperCacheController;
 import com.github.zuihou.base.request.PageParams;
@@ -16,6 +17,9 @@ import com.github.zuihou.tenant.dto.ProductionresourceUpdateDTO;
 import com.github.zuihou.tenant.entity.Productionline;
 import com.github.zuihou.tenant.entity.Productionresource;
 import com.github.zuihou.tenant.service.ProductionresourceService;
+import com.github.zuihou.tenant.util.CommonUtil;
+import com.github.zuihou.utils.SpringUtils;
+import com.google.common.collect.Lists;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -26,6 +30,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -46,6 +51,7 @@ import java.util.Map;
 @Api(value = "Productionresource", tags = "边缘盒子、生产资源管理")
 @SysLog(enabled = true)
 public class ProductionresourceController extends SuperCacheController<ProductionresourceService, Long, Productionresource, ProductionresourcePageDTO, ProductionresourceSaveDTO, ProductionresourceUpdateDTO> {
+
     @Override
     public void query(PageParams<ProductionresourcePageDTO> params, IPage<Productionresource> page, Long defSize) {
         ProductionresourcePageDTO data = params.getModel();
@@ -67,7 +73,12 @@ public class ProductionresourceController extends SuperCacheController<Productio
                 .geHeader(Productionresource::getCreateTime, data.getCreateTime_st())
                 .leFooter(Productionresource::getCreateTime, data.getCreateTime_ed())
                 .orderByDesc(Productionresource::getCreateTime);
-        baseService.pageList(page, wrapper);
+        IPage<Productionresource> iPage  = baseService.pageList(page, wrapper);
+        iPage.getRecords().forEach(item->{
+            Map<String, String> resultMap = baseService.getEquRunInfo(item.getId());
+            item.setOnlineStatus(resultMap.get("equStatus"));
+        });
+
     }
 
     @ApiOperation(value = "租户端查询生产资源", notes = "租户端查询生产资源(通过视图)")
@@ -190,7 +201,39 @@ public class ProductionresourceController extends SuperCacheController<Productio
     }
 
 
-
-
+    @ApiOperation(value = "获取设备状态统计", notes = "获取设备状态统计")
+    @PostMapping("/equStatistics")
+    public R<Map<String, Integer>> equStatistics(){
+        Map<String, Integer> map = new HashMap<String, Integer>(){
+            {
+                put("onLineCount", 0);
+                put("offlineCount", 0);
+                put("exceptCount", 0);
+            }
+        };
+        LbqWrapper<Productionresource> lbqWrapper = Wraps.<Productionresource>lbQ();
+        Long userId = BaseContextHandler.getUserId();
+        UserService userService = (UserService) SpringUtils.getBean(UserService.class);
+        //获取用户权限访问机构
+        Map<String, Object> orgMap = userService.getDataScopeById(userId);
+        List<Long> orgIds = orgMap.containsKey("orgIds")? (List)orgMap.get("orgIds") : Lists.newArrayList();
+        if(orgIds.size()>0) {
+            lbqWrapper.in(Productionresource::getOrgId, orgIds);
+        }
+
+        List<Productionresource> list = baseService.list(lbqWrapper);
+        list.stream().forEach(item->{
+            Map<String, String> resultMap = baseService.getEquRunInfo(item.getId());
+            String equStatus =  resultMap.get("equStatus");
+            if(equStatus.equals("0")){
+                map.put("offlineCount", map.get("offlineCount")+1);
+            }else if(equStatus.equals("1")){
+                map.put("onLineCount", map.get("onLineCount")+1);
+            }else{
+                map.put("exceptCount", map.get("exceptCount")+1);
+            }
+        });
+        return R.success(map);
+    }
 
 }