Browse Source

查询单兵设备在离线

459242451@qq.com 3 years ago
parent
commit
f8f98a32f6

+ 46 - 19
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhdd/SingleDeviceController.java

@@ -1,20 +1,9 @@
 package com.ruoyi.web.controller.zhdd;
 
-import java.util.List;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
-
-import lombok.RequiredArgsConstructor;
-import javax.servlet.http.HttpServletResponse;
-import javax.validation.constraints.*;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.validation.annotation.Validated;
-import com.ruoyi.common.annotation.RepeatSubmit;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
 import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.annotation.RepeatSubmit;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.validate.AddGroup;
@@ -22,12 +11,32 @@ import com.ruoyi.common.core.validate.EditGroup;
 import com.ruoyi.common.core.validate.QueryGroup;
 import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.zhdd.domain.vo.SingleDeviceVo;
 import com.ruoyi.zhdd.domain.bo.SingleDeviceBo;
+import com.ruoyi.zhdd.domain.vo.SingleDeviceVo;
+import com.ruoyi.zhdd.service.IDhService;
 import com.ruoyi.zhdd.service.ISingleDeviceService;
-import com.ruoyi.common.core.page.TableDataInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 单兵数据信息Controller
@@ -43,6 +52,7 @@ import io.swagger.annotations.ApiOperation;
 public class SingleDeviceController extends BaseController {
 
     private final ISingleDeviceService iSingleDeviceService;
+    private final IDhService dhService;
 
     /**
      * 查询单兵数据信息列表
@@ -50,7 +60,24 @@ public class SingleDeviceController extends BaseController {
     @ApiOperation("查询单兵数据信息列表")
     @GetMapping("/list")
     public AjaxResult<Map<String, SingleDeviceVo>> list(@Validated(QueryGroup.class) SingleDeviceBo bo) {
+        bo.setDataSource(3);
         List<SingleDeviceVo> singleDeviceVos = iSingleDeviceService.queryList(bo);
+        // 查询大华设备的在离线
+        JSONArray ecsArr = dhService.querySingleStat();
+        if (ecsArr.size() > 0) {
+            Map<String, JSONObject> collect2 = ecsArr.stream().collect(Collectors.toMap(i -> {
+                JSONObject a = (JSONObject) i;
+                return a.getStr("deviceCode");
+            }, object -> (JSONObject) object));
+            for (SingleDeviceVo singleDeviceVo : singleDeviceVos) {
+                JSONObject jsonObject = collect2.get(singleDeviceVo.getDeviceCode());
+                if (jsonObject != null) {
+                    singleDeviceVo.setStat(jsonObject.getStr("stat"));
+                } else {
+                    singleDeviceVo.setStat("offline");
+                }
+            }
+        }
         Map<String, SingleDeviceVo> collect = singleDeviceVos.stream().collect(Collectors.toMap(SingleDeviceVo::getDeviceCode, a -> a));
         return AjaxResult.success(collect);
     }
@@ -74,7 +101,7 @@ public class SingleDeviceController extends BaseController {
     @PreAuthorize("@ss.hasPermi('zhdd:singleDevice:query')")
     @GetMapping("/{userId}")
     public AjaxResult<SingleDeviceVo> getInfo(@NotNull(message = "主键不能为空")
-                                                  @PathVariable("userId") String userId) {
+                                              @PathVariable("userId") String userId) {
         return AjaxResult.success(iSingleDeviceService.queryById(userId));
     }
 
@@ -107,10 +134,10 @@ public class SingleDeviceController extends BaseController {
      */
     @ApiOperation("删除单兵数据信息")
     @PreAuthorize("@ss.hasPermi('zhdd:singleDevice:remove')")
-    @Log(title = "单兵数据信息" , businessType = BusinessType.DELETE)
+    @Log(title = "单兵数据信息", businessType = BusinessType.DELETE)
     @DeleteMapping("/{userIds}")
     public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
-                                       @PathVariable String[] userIds) {
+                                   @PathVariable String[] userIds) {
         return toAjax(iSingleDeviceService.deleteWithValidByIds(Arrays.asList(userIds), true) ? 1 : 0);
     }
 }

+ 5 - 0
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/domain/vo/SingleDeviceVo.java

@@ -123,5 +123,10 @@ public class SingleDeviceVo {
 
     private String channelId;
 
+    /**
+     * 在离线()
+     */
+    private String stat;
+
 
 }

+ 4 - 0
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/service/IDhService.java

@@ -1,5 +1,7 @@
 package com.ruoyi.zhdd.service;
 
+import cn.hutool.json.JSONArray;
+
 /**
  * @Description: TODO
  * @Author: huangcheng
@@ -20,4 +22,6 @@ public interface IDhService {
     void tokenKeepalive(String token);
 
     Object getDeviceTree();
+
+    JSONArray querySingleStat();
 }

+ 27 - 0
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/service/impl/DhServiceImpl.java

@@ -158,6 +158,33 @@ public class DhServiceImpl implements IDhService {
         return newList;
     }
 
+    @Override
+    public JSONArray querySingleStat() {
+        Map<String, Object> param = new HashMap<>();
+        param.put("orgCode", "S4NbecfYB1DGB68AN187Q8");
+        param.put("isSubOrg", 1);
+        param.put("page", 1);
+        param.put("pageSize", 3000);
+        String get = "";
+        try {
+            get = HttpRequest.get("http://10.55.134.3:8314/videoService/devicesManager/searchDevices")
+                .header("X-Subject-Token", this.getToken())
+                .form(param)
+                .timeout(-1)
+                .execute().body();
+        } catch (Exception e) {
+            log.error("大华单兵设备状态请求异常:{}", e.getMessage());
+            return new JSONArray();
+        }
+        JSONObject getJson = JSONUtil.parseObj(get);
+        if (getJson.containsKey("code")) {
+            // 说明有错误
+            log.error("获取大华单兵设备状态出错:{}", getJson);
+            return new JSONArray();
+        }
+        return getJson.getJSONArray("results");
+    }
+
     private JSONArray getList(Map<String, Object> param) {
         param.put("nodeType", 1);
         param.put("typeCode", "01;0;ALL;ALL");