zhongrj
2024-05-10 b63dccee424ee9dfb8944ead15ff084ff62d63fa
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/hk/controller/HkController.java
@@ -4,7 +4,12 @@
import cn.gistack.sm.hk.constant.ProtocolConstant;
import cn.gistack.sm.hk.service.HkService;
import cn.gistack.sm.hk.vo.HkVO;
import cn.gistack.sm.hk.vo.VideoVO;
import cn.gistack.sm.sjztmd.service.IAttResBaseService;
import cn.gistack.sm.sjztmd.vo.AttResAdVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.protobuf.ServiceException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
@@ -13,6 +18,8 @@
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static cn.gistack.sm.hk.util.GetCameraUtils.*;
@@ -30,6 +37,8 @@
public class HkController {
   private final HkService hkService;
   private final IAttResBaseService attResBaseService;
   /**
    * 分页列表查询
@@ -63,7 +72,9 @@
         HkConstant.previewURLs,
         hk.getCameraIndexCode(),
         ProtocolConstant.WS,
         expand);
         null==hk.getTransmode()?1:hk.getTransmode(),
         expand,
         null==hk.getStreamType()?1:hk.getStreamType());
      if (null!=result) {
         JSONObject jsonObject = JSONObject.parseObject(result);
         Map map = (Map) jsonObject.get("data");
@@ -91,7 +102,9 @@
         HkConstant.previewURLs,
         hk.getCameraIndexCode(),
         hk.getProtocol(),
         expand);
         null==hk.getTransmode()?1:hk.getTransmode(),
         expand,
         null==hk.getStreamType()?1:hk.getStreamType());
      if (null!=result) {
         JSONObject jsonObject = JSONObject.parseObject(result);
         Map map = (Map) jsonObject.get("data");
@@ -119,7 +132,9 @@
         HkConstant.previewURLs,
         hk.getCameraIndexCode(),
         ProtocolConstant.HLS,
         expand);
         null==hk.getTransmode()?1:hk.getTransmode(),
         expand,
         null==hk.getStreamType()?1:hk.getStreamType());
      if (null!=result) {
         JSONObject jsonObject = JSONObject.parseObject(result);
         Map map = (Map) jsonObject.get("data");
@@ -228,6 +243,7 @@
      jsonBody.put("cameraIndexCode", hk.getCameraIndexCode());
      jsonBody.put("protocol", hk.getProtocol());
      jsonBody.put("recordLocation", "1");
      jsonBody.put("transmode", null==hk.getTransmode()?1:hk.getTransmode());
      jsonBody.put("beginTime", hk.getBeginTime());
      jsonBody.put("endTime", hk.getEndTime());
      String body = jsonBody.toJSONString();
@@ -252,7 +268,9 @@
       */
      JSONObject jsonBody = new JSONObject();
      jsonBody.put("cameraIndexCode", hk.getCameraIndexCode());
      jsonBody.put("streamType",null==hk.getStreamType()?1:hk.getStreamType());
      jsonBody.put("protocol", hk.getProtocol());
      jsonBody.put("transmode", null==hk.getTransmode()?1:hk.getTransmode());
      String body = jsonBody.toJSONString();
      /**
@@ -268,7 +286,7 @@
    * @param hk 查询参数
    * @return
    */
   @ApiOperation(value = "海康设备-获取海康摄像头语音对讲url", notes = "海康设备-获取海康摄像头语音对讲url")
   @ApiOperation(value = "海康设备-设置监控点的预置点信息", notes = "海康设备-设置监控点的预置点信息")
   @GetMapping(value = "/presetsAddition")
   public R presetsAddition(HkVO hk) {
      /**
@@ -287,4 +305,87 @@
      return R.data(common(null==hk.getType()?1:hk.getType(),HkConstant.presetsAdditionURLs, body));
   }
   /**
    * 删除监控点的预置点信息
    * @param hk 查询参数
    * @return
    */
   @ApiOperation(value = "海康设备-删除监控点的预置点信息", notes = "海康设备-删除监控点的预置点信息")
   @GetMapping(value = "/presetsDeletion")
   public R presetsDeletion(HkVO hk) {
      /**
       * 组装请求参数
       */
      JSONObject jsonBody = new JSONObject();
      jsonBody.put("cameraIndexCode", hk.getCameraIndexCode());
      jsonBody.put("presetIndex", hk.getPresetIndex());
      String body = jsonBody.toJSONString();
      /**
       * 调用接口并返回数据
       * post请求application/json类型参数;
       */
      return R.data(common(null==hk.getType()?1:hk.getType(),HkConstant.presetsDeletionURLs, body));
   }
   /**
    * 同步水库设备信息
    * @param hk 水库设备
    * @return
    */
   @ApiOperation(value = "海康设备-同步水库设备信息", notes = "海康设备-同步水库设备信息")
   @PostMapping(value = "/syncVideo")
   public R syncVideo(@RequestBody HkVO hk) {
      // 通过水库编号获取区域(区县)名称
      AttResAdVO info = attResBaseService.getWaterRegionInfoByResGuid(hk.getRegionIndexCode());
      // 判断该水库同一个区县下是否存在同水库名称的,如果是存在多个,水库名称前面拼上乡镇名称
      String resName = setWaterName(hk,info);
      // 设置区域名称
      hk.setRegionName(info.getCountyName());
      // 判断
      // 通过区域名称查询对应的区域编号
      String rootRegionId = hkService.regionNodesByParams(hk);
      if (null!= rootRegionId && !rootRegionId.equals("")){
         // 更新
         /**
          * 组装请求参数
          */
         List<VideoVO> list = new ArrayList<>();
         VideoVO video = new VideoVO();
         video.setRegionName(resName);
         video.setRegionIndexCode(hk.getRegionIndexCode());
         video.setParentIndexCode(rootRegionId);
         video.setRegionType(10);
         list.add(video);
         String body = JSON.toJSONString(list);
         /**
          * 调用接口并返回数据
          * post请求application/json类型参数;
          */
         JSONObject jsonObject = JSONObject.parseObject(common(null == hk.getType() ? 2 : hk.getType(), HkConstant.batchAddURLs, body));
         // 返回
         return R.data(200,jsonObject,null);
      }else {
         // 当前水库行政区域不匹配
         return R.data(400,"当前水库行政区域不匹配","当前水库行政区域不匹配");
      }
   }
   /**
    * 设置水库名称( 判断该水库同一个区县下是否存在同水库名称的,如果是存在多个,水库名称前面拼上乡镇名称)
    * @param hk
    * @param info
    * @return
    */
   private String setWaterName(HkVO hk, AttResAdVO info) {
      // 根据水库名称、所在区域查询改水库的数量
      Integer number = attResBaseService.getWaterCountByResNameAndCountyName(hk.getRegionName(),info.getCountyCode());
      if (number>1){
         return  hk.getRegionName() + "(" + info.getTownName() + ")";
      }else {
         return hk.getRegionName();
      }
   }
}