shenyijian
2024-06-21 f20611265f7d34fd4fbcdfdaff6cb9cccd0b25fc
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/hk/service/impl/HkServiceImpl.java
@@ -8,6 +8,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.logging.log4j.util.Strings;
import org.springblade.core.mp.support.Query;
import org.springframework.stereotype.Service;
@@ -54,11 +55,11 @@
      // 获取根区域编号
      String rootRegionId = getRootRegionId(hk);
      // 查询摄像头统计数据(需要有在线状态)
      hashMap.put("total",getCameraStatisticCount(rootRegionId,null));
      hashMap.put("onlineTotal",getCameraStatisticCount(rootRegionId,1));
      hashMap.put("offlineTotal",getCameraStatisticCount(rootRegionId,0));
      hashMap.put("total",getCameraStatisticCount(hk.getType(),rootRegionId,null));
      hashMap.put("onlineTotal",getCameraStatisticCount(hk.getType(),rootRegionId,1));
      hashMap.put("offlineTotal",getCameraStatisticCount(hk.getType(),rootRegionId,0));
      // 查询摄像头集合数据
      hashMap.put("list",getCameraStatisticList(rootRegionId, hk,query));
      hashMap.put("list",getCameraStatisticList(hk.getType(),rootRegionId, hk,query));
      // 返回数据
      return hashMap;
   }
@@ -90,7 +91,7 @@
    * @param cameraIndexCode
    * @return
    */
   private String getCameraAddress(String regionIndexCode,String cameraIndexCode) {
   private String getCameraAddress(Integer type,String regionIndexCode,String cameraIndexCode) {
      // 组装请求参数
      JSONObject jsonBody = new JSONObject();
      jsonBody.put("regionIndexCodes", Arrays.asList(regionIndexCode));
@@ -102,7 +103,7 @@
      list.add(map);
      jsonBody.put("expressions", list);
      String body = jsonBody.toJSONString();
      String result = GetCameraUtils.common(regionInfoUrls, body);
      String result = GetCameraUtils.common(type,regionInfoUrls, body);
      // 数据处理
      JSONObject jsonObject = JSONObject.parseObject(result);
      JSONObject data = (JSONObject) jsonObject.get("data");
@@ -117,12 +118,12 @@
    * @param cameraIndexCode
    * @return
    */
   private JSONObject getCameraDetail(String cameraIndexCode) {
   private JSONObject getCameraDetail(Integer type,String cameraIndexCode) {
      // 组装请求参数
      JSONObject jsonBody = new JSONObject();
      jsonBody.put("cameraIndexCode", cameraIndexCode);
      String body = jsonBody.toJSONString();
      String result = GetCameraUtils.common(camerasIndexCodeUrls, body);
      String result = GetCameraUtils.common(type,camerasIndexCodeUrls, body);
      // 数据处理
      JSONObject jsonObject = JSONObject.parseObject(result);
      // 返回
@@ -136,7 +137,7 @@
    * @param query
    * @return
    */
   private JSONObject getCameraStatisticList(String regionId, HkVO hk,Query query) {
   private JSONObject getCameraStatisticList(Integer type,String regionId, HkVO hk,Query query) {
      // 组装请求参数
      JSONObject jsonBody = new JSONObject();
      jsonBody.put("regionId", regionId);
@@ -146,7 +147,7 @@
         jsonBody.put("status",hk.getStatus());
      }
      String body = jsonBody.toJSONString();
      String result = GetCameraUtils.common(onlineCameraGetUrls, body);
      String result = GetCameraUtils.common(type,onlineCameraGetUrls, body);
      // 数据处理
      JSONObject jsonObject = JSONObject.parseObject(result);
      // 返回数据
@@ -159,7 +160,7 @@
    * @param status
    * @return
    */
   private String getCameraStatisticCount(String regionId,Integer status) {
   private String getCameraStatisticCount(Integer type,String regionId,Integer status) {
      // 组装请求参数
      JSONObject jsonBody = new JSONObject();
      jsonBody.put("regionId", regionId);
@@ -167,7 +168,7 @@
         jsonBody.put("status",status);
      }
      String body = jsonBody.toJSONString();
      String result = GetCameraUtils.common(onlineCameraGetUrls, body);
      String result = GetCameraUtils.common(type,onlineCameraGetUrls, body);
      // 数据处理
      JSONObject jsonObject = JSONObject.parseObject(result);
      JSONObject data = (JSONObject) jsonObject.get("data");
@@ -179,11 +180,11 @@
    * 获取根节点区域信息
    * @param hk
    */
   private String getRootRegionId(HkVO hk) {
   public String getRootRegionId(HkVO hk) {
      // 组装请求参数
      JSONObject jsonBody = new JSONObject();
      String body = jsonBody.toJSONString();
      String result = GetCameraUtils.common(regionsRootUrls, body);
      String result = GetCameraUtils.common(null==hk.getType()?1:hk.getType(),regionsRootUrls, body);
      // 数据处理
      JSONObject jsonObject = JSONObject.parseObject(result);
      JSONObject data = (JSONObject) jsonObject.get("data");
@@ -191,4 +192,52 @@
      // 返回
      return indexCode;
   }
   /**
    * 查询区域列表v2
    * @param hk
    */
   public String regionNodesByParams(HkVO hk) {
      // 先按地市查询对应的区域code
      String parentIndexCode = getIndexCodeByRegionName(hk,hk.getCityName(),null);
      if (!Strings.isBlank(parentIndexCode)) {
         return getIndexCodeByRegionName(hk,hk.getRegionName(),parentIndexCode);
      }
      // 返回
      return null;
   }
   /**
    * 按区域名称查询对应的区域code
    * @param hk
    * @param regionName
    * @param parentIndexCode
    * @return
    */
   private String getIndexCodeByRegionName(HkVO hk,String regionName,String parentIndexCode) {
      String indexCode = "";
      // 组装请求参数
      JSONObject jsonBody = new JSONObject();
      jsonBody.put("resourceType", "region");
      jsonBody.put("regionName", regionName);
      if (!Strings.isBlank(parentIndexCode)){
         jsonBody.put("parentIndexCodes", new ArrayList<>(){{
            add(parentIndexCode);
         }});
      }
      jsonBody.put("pageNo", 1);
      jsonBody.put("pageSize", 10);
      String body = jsonBody.toJSONString();
      String result = GetCameraUtils.common(null==hk.getType()?1:hk.getType(),regionNodesByParamsURLs, body);
      // 数据处理
      JSONObject jsonObject = JSONObject.parseObject(result);
      JSONObject data = jsonObject.getJSONObject("data");
      JSONArray list = data.getJSONArray("list");
      if (list.size()>0){
         indexCode = list.getJSONObject(0).getString("indexCode");
      }
      // 返回
      return indexCode;
   }
}