From 53e14c1919c4a3112f963689d0ce75fa08831021 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: Sat, 19 Aug 2023 12:32:20 +0800
Subject: [PATCH] 增加通道管理业务 修改相机部分实体字段

---
 ard-work/src/main/java/com/ruoyi/device/hiksdk/util/hikSdkUtil/LoginResultCallBack.java |   27 ++
 ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java     |    2 
 ard-work/src/main/java/com/ruoyi/device/channel/controller/ArdChannelController.java    |  110 ++++++++++
 ard-work/src/main/java/com/ruoyi/device/camera/domain/ArdCameras.java                   |   25 +
 ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java           |    6 
 ard-work/src/main/java/com/ruoyi/device/hiksdk/util/hikSdkUtil/HCNetSDK.java            |    3 
 ard-work/src/main/resources/mapper/device/ArdCamerasMapper.xml                          |   12 
 ard-work/src/main/resources/mapper/device/ArdChannelMapper.xml                          |   69 ++++++
 ard-work/src/main/java/com/ruoyi/device/channel/service/impl/ArdChannelServiceImpl.java |   99 +++++++++
 ard-work/src/main/java/com/ruoyi/device/channel/service/IArdChannelService.java         |   68 ++++++
 ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java   |   48 ++++
 ard-work/src/main/java/com/ruoyi/device/channel/domain/ArdChannel.java                  |   79 +++++++
 ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java  |   36 ++
 ard-work/src/main/java/com/ruoyi/device/channel/mapper/ArdChannelMapper.java            |   69 ++++++
 14 files changed, 630 insertions(+), 23 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java b/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java
index e0efc82..b3c6f7e 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java
@@ -137,7 +137,7 @@
             Map option = new HashMap();
             option.put("value", item.getId());
             option.put("label", item.getName());
-            option.put("channel", item.getChannel());
+            option.put("channel", item.getChanNo());
             List timeList = ardVideoInspectTaskService.getCameraIdleTimeList(item.getId());
             option.put("idleTimeList", timeList);//空闲时间段
             options.add(option);
diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/domain/ArdCameras.java b/ard-work/src/main/java/com/ruoyi/device/camera/domain/ArdCameras.java
index 472f2b5..cfdf554 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/domain/ArdCameras.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/domain/ArdCameras.java
@@ -1,5 +1,6 @@
 package com.ruoyi.device.camera.domain;
 
+import com.ruoyi.device.channel.domain.ArdChannel;
 import com.sun.jna.Structure;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -8,6 +9,7 @@
 import com.ruoyi.common.core.domain.BaseEntity;
 
 import java.util.Date;
+import java.util.List;
 
 /**
  * 相机设备对象 ard_cameras
@@ -72,11 +74,7 @@
     @Excel(name = "光电类型")
     private String gdtype;
 
-    /**
-     * 通道号
-     */
-    @Excel(name = "通道号")
-    private Integer channel;
+
 
     /**
      * 经度
@@ -175,4 +173,21 @@
     private Integer loginId;
     private String operatorId;
     private Date operatorExpired;
+    /**
+     * 通道号
+     */
+    private Integer chanNo;
+    /**
+     * 起始通道号
+     */
+    private Integer startDChan;
+    /**
+     * 通道数
+     */
+    @Excel(name = "通道数")
+    private Integer chanNum;
+    /**
+     * 通道
+     */
+    private List<ArdChannel> channelList;
 }
diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
index 85cf727..88b4637 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
@@ -11,7 +11,11 @@
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.uuid.IdUtils;
 import com.ruoyi.device.camera.domain.CameraCmd;
+import com.ruoyi.device.channel.domain.ArdChannel;
+import com.ruoyi.device.channel.mapper.ArdChannelMapper;
+import com.ruoyi.device.channel.service.IArdChannelService;
 import com.ruoyi.device.hiksdk.common.GlobalVariable;
+import com.ruoyi.device.hiksdk.service.IHikClientService;
 import com.ruoyi.scheduling.domian.SchedulingParam;
 import com.ruoyi.system.domain.SysConfig;
 import com.ruoyi.utils.tools.ArdTool;
@@ -43,6 +47,10 @@
     private SysDeptMapper sysDeptMapper;
     @Resource
     private RedisCache redisCache;
+    @Resource
+    private IHikClientService hikClientService;
+    @Resource
+    private ArdChannelMapper ardChannelMapper;
 
 
     @PostConstruct
@@ -111,7 +119,20 @@
         ardCameras.setCreateTime(DateUtils.getNowDate());
         ardCameras.setUserId(SecurityUtils.getUserId());
         redisCache.setCacheObject(getCacheKey(ardCameras.getId()), ardCameras);
-        return ardCamerasMapper.insertArdCameras(ardCameras);
+        int i = ardCamerasMapper.insertArdCameras(ardCameras);
+        if (i > 0) {
+//            //删除当前相机的所有通道
+//            ardChannelMapper.deleteArdChannelByDeviceId(ardCameras.getId());
+//            //获取相机通道
+//            List<ArdChannel> ipChannelList = hikClientService.getCameraChannelList(ardCameras);
+//            if (ipChannelList.size() > 0) {
+//                for (ArdChannel channel : ipChannelList) {
+//                    channel.setId(IdUtils.simpleUUID());
+//                    ardChannelMapper.insertArdChannel(channel);
+//                }
+//            }
+        }
+        return i;
     }
 
     /**
@@ -143,6 +164,8 @@
         if (res > 0) {
             for (String id : ids) {
                 redisCache.deleteObject(getCacheKey(id));
+                //删除当前相机的所有通道
+                ardChannelMapper.deleteArdChannelByDeviceId(id);
             }
         }
         return res;
@@ -156,7 +179,12 @@
      */
     @Override
     public int deleteArdCamerasById(String id) {
-        return ardCamerasMapper.deleteArdCamerasById(id);
+        int i = ardCamerasMapper.deleteArdCamerasById(id);
+        if (i > 0) {
+            //删除当前相机的所有通道
+            ardChannelMapper.deleteArdChannelByDeviceId(id);
+        }
+        return i;
     }
 
     public List findOptions(ArdCameras ardCameras) {
@@ -249,7 +277,7 @@
                 }
                 if (distance != 0.0 && distance <= camera.getCamMaxVisibleDistance()) {
                     distanceMap.put(camera.getId(), distance);
-                    camera.setChannel(ArdTool.getChannelBydayNightTime(dayNightTime));
+                    camera.setChanNo(ArdTool.getChannelBydayNightTime(dayNightTime));
                     ardCameras.put(distance, camera);
                 }
 
@@ -292,7 +320,7 @@
                 double[] camPosition = new double[]{camera.getLongitude(), camera.getLatitude()};
                 double distance = GisTool.getDistance(new double[]{longitude, latitude}, camPosition);
                 if (distance <= radius) {
-                    camera.setChannel(ArdTool.getChannelBydayNightTime(dayNightTime));
+                    camera.setChanNo(ArdTool.getChannelBydayNightTime(dayNightTime));
                     ardCameras.add(camera);
                 }
             }
diff --git a/ard-work/src/main/java/com/ruoyi/device/channel/controller/ArdChannelController.java b/ard-work/src/main/java/com/ruoyi/device/channel/controller/ArdChannelController.java
new file mode 100644
index 0000000..8e67631
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/device/channel/controller/ArdChannelController.java
@@ -0,0 +1,110 @@
+package com.ruoyi.device.channel.controller;
+
+import java.util.List;
+import javax.servlet.http.HttpServletResponse;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.device.channel.domain.ArdChannel;
+import com.ruoyi.device.channel.service.IArdChannelService;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.page.TableDataInfo;
+
+/**
+ * 通道管理Controller
+ * 
+ * @author ard
+ * @date 2023-08-19
+ */
+@RestController
+@RequestMapping("/device/channel")
+@Api(tags = "通道管理接口")
+public class ArdChannelController extends BaseController
+{
+    @Autowired
+    private IArdChannelService ardChannelService;
+
+    /**
+     * 查询通道管理列表
+     */
+    @ApiOperation("查询通道管理列表")
+    @PreAuthorize("@ss.hasPermi('device:channel:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(ArdChannel ardChannel)
+    {
+        startPage();
+        List<ArdChannel> list = ardChannelService.selectArdChannelList(ardChannel);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出通道管理列表
+     */
+    @PreAuthorize("@ss.hasPermi('device:channel:export')")
+    @Log(title = "通道管理", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, ArdChannel ardChannel)
+    {
+        List<ArdChannel> list = ardChannelService.selectArdChannelList(ardChannel);
+        ExcelUtil<ArdChannel> util = new ExcelUtil<ArdChannel>(ArdChannel.class);
+        util.exportExcel(response, list, "通道管理数据");
+    }
+
+    /**
+     * 获取通道管理详细信息
+     */
+    @ApiOperation("获取通道管理详细信息")
+    @PreAuthorize("@ss.hasPermi('device:channel:query')")
+    @GetMapping(value = "/{id}")
+    public AjaxResult getInfo(@PathVariable("id") String id)
+    {
+        return success(ardChannelService.selectArdChannelById(id));
+    }
+
+    /**
+     * 新增通道管理
+     */
+    @PreAuthorize("@ss.hasPermi('device:channel:add')")
+    @Log(title = "通道管理", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody ArdChannel ardChannel)
+    {
+        return toAjax(ardChannelService.insertArdChannel(ardChannel));
+    }
+
+    /**
+     * 修改通道管理
+     */
+    @PreAuthorize("@ss.hasPermi('device:channel:edit')")
+    @Log(title = "通道管理", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody ArdChannel ardChannel)
+    {
+        return toAjax(ardChannelService.updateArdChannel(ardChannel));
+    }
+
+    /**
+     * 删除通道管理
+     */
+    @PreAuthorize("@ss.hasPermi('device:channel:remove')")
+    @Log(title = "通道管理", businessType = BusinessType.DELETE)
+	@DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable String[] ids)
+    {
+        return toAjax(ardChannelService.deleteArdChannelByIds(ids));
+    }
+}
diff --git a/ard-work/src/main/java/com/ruoyi/device/channel/domain/ArdChannel.java b/ard-work/src/main/java/com/ruoyi/device/channel/domain/ArdChannel.java
new file mode 100644
index 0000000..c376811
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/device/channel/domain/ArdChannel.java
@@ -0,0 +1,79 @@
+package com.ruoyi.device.channel.domain;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+
+/**
+ * 通道管理对象 ard_channel
+ * 
+ * @author ard
+ * @date 2023-08-19
+ */
+public class ArdChannel extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** id */
+    private String id;
+
+    /** 通道名称 */
+    @Excel(name = "通道名称")
+    private String name;
+
+    /** 通道号 */
+    @Excel(name = "通道号")
+    private Integer chanNo;
+
+    /** 所属设备id */
+    @Excel(name = "所属设备id")
+    private String deviceId;
+
+    public void setId(String id) 
+    {
+        this.id = id;
+    }
+
+    public String getId() 
+    {
+        return id;
+    }
+    public void setName(String name) 
+    {
+        this.name = name;
+    }
+
+    public String getName() 
+    {
+        return name;
+    }
+    public void setChanNo(Integer chanNo) 
+    {
+        this.chanNo = chanNo;
+    }
+
+    public Integer getChanNo() 
+    {
+        return chanNo;
+    }
+    public void setDeviceId(String deviceId) 
+    {
+        this.deviceId = deviceId;
+    }
+
+    public String getDeviceId() 
+    {
+        return deviceId;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
+            .append("id", getId())
+            .append("name", getName())
+            .append("chanNo", getChanNo())
+            .append("deviceId", getDeviceId())
+            .toString();
+    }
+}
diff --git a/ard-work/src/main/java/com/ruoyi/device/channel/mapper/ArdChannelMapper.java b/ard-work/src/main/java/com/ruoyi/device/channel/mapper/ArdChannelMapper.java
new file mode 100644
index 0000000..7823474
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/device/channel/mapper/ArdChannelMapper.java
@@ -0,0 +1,69 @@
+package com.ruoyi.device.channel.mapper;
+
+import java.util.List;
+import com.ruoyi.device.channel.domain.ArdChannel;
+
+/**
+ * 通道管理Mapper接口
+ * 
+ * @author ard
+ * @date 2023-08-19
+ */
+public interface ArdChannelMapper 
+{
+    /**
+     * 查询通道管理
+     * 
+     * @param id 通道管理主键
+     * @return 通道管理
+     */
+    public ArdChannel selectArdChannelById(String id);
+
+    /**
+     * 查询通道管理列表
+     * 
+     * @param ardChannel 通道管理
+     * @return 通道管理集合
+     */
+    public List<ArdChannel> selectArdChannelList(ArdChannel ardChannel);
+
+    /**
+     * 新增通道管理
+     * 
+     * @param ardChannel 通道管理
+     * @return 结果
+     */
+    public int insertArdChannel(ArdChannel ardChannel);
+
+    /**
+     * 修改通道管理
+     * 
+     * @param ardChannel 通道管理
+     * @return 结果
+     */
+    public int updateArdChannel(ArdChannel ardChannel);
+
+    /**
+     * 删除通道管理
+     * 
+     * @param id 通道管理主键
+     * @return 结果
+     */
+    public int deleteArdChannelById(String id);
+
+    /**
+     * 批量删除通道管理
+     * 
+     * @param ids 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteArdChannelByIds(String[] ids);
+
+    /**
+     * 删除通道管理按设备ID
+     *
+     * @param deviceId 所属设备ID
+     * @return 结果
+     */
+    public int deleteArdChannelByDeviceId(String deviceId);
+}
diff --git a/ard-work/src/main/java/com/ruoyi/device/channel/service/IArdChannelService.java b/ard-work/src/main/java/com/ruoyi/device/channel/service/IArdChannelService.java
new file mode 100644
index 0000000..e926827
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/device/channel/service/IArdChannelService.java
@@ -0,0 +1,68 @@
+package com.ruoyi.device.channel.service;
+
+import java.util.List;
+import com.ruoyi.device.channel.domain.ArdChannel;
+
+/**
+ * 通道管理Service接口
+ * 
+ * @author ard
+ * @date 2023-08-19
+ */
+public interface IArdChannelService 
+{
+    /**
+     * 查询通道管理
+     * 
+     * @param id 通道管理主键
+     * @return 通道管理
+     */
+    public ArdChannel selectArdChannelById(String id);
+
+    /**
+     * 查询通道管理列表
+     * 
+     * @param ardChannel 通道管理
+     * @return 通道管理集合
+     */
+    public List<ArdChannel> selectArdChannelList(ArdChannel ardChannel);
+
+    /**
+     * 新增通道管理
+     * 
+     * @param ardChannel 通道管理
+     * @return 结果
+     */
+    public int insertArdChannel(ArdChannel ardChannel);
+
+    /**
+     * 修改通道管理
+     * 
+     * @param ardChannel 通道管理
+     * @return 结果
+     */
+    public int updateArdChannel(ArdChannel ardChannel);
+
+    /**
+     * 批量删除通道管理
+     * 
+     * @param ids 需要删除的通道管理主键集合
+     * @return 结果
+     */
+    public int deleteArdChannelByIds(String[] ids);
+
+    /**
+     * 删除通道管理信息
+     * 
+     * @param id 通道管理主键
+     * @return 结果
+     */
+    public int deleteArdChannelById(String id);
+    /**
+     * 删除通道管理信息
+     *
+     * @param deviceId 所属设备ID
+     * @return 结果
+     */
+     public int deleteArdChannelByDeviceId(String deviceId);
+}
diff --git a/ard-work/src/main/java/com/ruoyi/device/channel/service/impl/ArdChannelServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/channel/service/impl/ArdChannelServiceImpl.java
new file mode 100644
index 0000000..44ec3b3
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/device/channel/service/impl/ArdChannelServiceImpl.java
@@ -0,0 +1,99 @@
+package com.ruoyi.device.channel.service.impl;
+
+import java.util.List;
+
+import com.ruoyi.common.utils.uuid.IdUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.ruoyi.device.channel.mapper.ArdChannelMapper;
+import com.ruoyi.device.channel.domain.ArdChannel;
+import com.ruoyi.device.channel.service.IArdChannelService;
+
+/**
+ * 通道管理Service业务层处理
+ *
+ * @author ard
+ * @date 2023-08-19
+ */
+@Service
+public class ArdChannelServiceImpl implements IArdChannelService {
+    @Autowired
+    private ArdChannelMapper ardChannelMapper;
+
+    /**
+     * 查询通道管理
+     *
+     * @param id 通道管理主键
+     * @return 通道管理
+     */
+    @Override
+    public ArdChannel selectArdChannelById(String id) {
+        return ardChannelMapper.selectArdChannelById(id);
+    }
+
+    /**
+     * 查询通道管理列表
+     *
+     * @param ardChannel 通道管理
+     * @return 通道管理
+     */
+    @Override
+    public List<ArdChannel> selectArdChannelList(ArdChannel ardChannel) {
+        return ardChannelMapper.selectArdChannelList(ardChannel);
+    }
+
+    /**
+     * 新增通道管理
+     *
+     * @param ardChannel 通道管理
+     * @return 结果
+     */
+    @Override
+    public int insertArdChannel(ArdChannel ardChannel) {
+                ardChannel.setId(IdUtils.simpleUUID());
+            return ardChannelMapper.insertArdChannel(ardChannel);
+    }
+
+    /**
+     * 修改通道管理
+     *
+     * @param ardChannel 通道管理
+     * @return 结果
+     */
+    @Override
+    public int updateArdChannel(ArdChannel ardChannel) {
+        return ardChannelMapper.updateArdChannel(ardChannel);
+    }
+
+    /**
+     * 批量删除通道管理
+     *
+     * @param ids 需要删除的通道管理主键
+     * @return 结果
+     */
+    @Override
+    public int deleteArdChannelByIds(String[] ids) {
+        return ardChannelMapper.deleteArdChannelByIds(ids);
+    }
+
+    /**
+     * 删除通道管理信息
+     *
+     * @param id 通道管理主键
+     * @return 结果
+     */
+    @Override
+    public int deleteArdChannelById(String id) {
+        return ardChannelMapper.deleteArdChannelById(id);
+    }
+    /**
+     * 删除通道管理信息
+     *
+     * @param deviceId 所属设备ID
+     * @return 结果
+     */
+    @Override
+    public int deleteArdChannelByDeviceId(String deviceId) {
+        return ardChannelMapper.deleteArdChannelByDeviceId(deviceId);
+    }
+}
diff --git a/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java b/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java
index 2d43e0e..4826aba 100644
--- a/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java
+++ b/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java
@@ -2,6 +2,9 @@
 
 import com.ruoyi.device.camera.domain.ArdCameras;
 import com.ruoyi.device.camera.domain.CameraCmd;
+import com.ruoyi.device.channel.domain.ArdChannel;
+
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -103,4 +106,7 @@
 
     //停止录像-不上传minio
     void recordStopNotToMinio(CameraCmd cmd);
+
+    //获取相机通道信息
+    public List<ArdChannel> getCameraChannelList(ArdCameras camera);
 }
diff --git a/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java
index 60c0b26..5c35e6d 100644
--- a/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java
@@ -1,9 +1,12 @@
 package com.ruoyi.device.hiksdk.service.impl;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.ruoyi.common.annotation.SdkOperate;
 import com.ruoyi.common.utils.file.FileUtils;
 import com.ruoyi.device.camera.domain.CameraCmd;
 import com.ruoyi.device.camera.service.IArdCamerasService;
+import com.ruoyi.device.channel.domain.ArdChannel;
+import com.ruoyi.device.channel.service.IArdChannelService;
 import com.ruoyi.device.hiksdk.common.GlobalVariable;
 import com.ruoyi.device.camera.domain.ArdCameras;
 import com.ruoyi.device.hiksdk.config.MinioClientSingleton;
@@ -13,11 +16,14 @@
 import com.ruoyi.device.hiksdk.util.hikSdkUtil.LoginResultCallBack;
 import com.ruoyi.storage.minio.utils.MinioUtils;
 import com.sun.jna.Native;
+import com.sun.jna.NativeLong;
 import com.sun.jna.Platform;
 import com.sun.jna.Pointer;
 import com.sun.jna.ptr.IntByReference;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+
 import java.util.Base64;
 import javax.annotation.Resource;
 import java.io.*;
@@ -26,6 +32,7 @@
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.stream.Collectors;
 
 import static com.ruoyi.device.hiksdk.util.hikSdkUtil.HCNetSDK.*;
 
@@ -125,7 +132,7 @@
         GlobalVariable.loginMap.remove(camera.getId());
         GlobalVariable.loginMap.put(camera.getId(), lUserID);
         camera.setLoginId(lUserID);
-        camera.setChannel((int) m_strDeviceInfo.byStartChan);
+        camera.setStartDChan((int) m_strDeviceInfo.byStartChan);
         return camera;
     }
 
@@ -1093,7 +1100,7 @@
         log.debug("-----------这里开始图片存入内存----------" + is);
 
         Base64.Encoder decoder = Base64.getEncoder();
-      //  BASE64Encoder encoder = new BASE64Encoder();
+        //  BASE64Encoder encoder = new BASE64Encoder();
         String png_base64 = decoder.encodeToString(jpegBuffer.array());//转换成base64串
         png_base64 = png_base64.replaceAll("\n", "").replaceAll("\r", "");//删除 \r\n
         log.debug("-----------处理完成截图数据----------");
@@ -1386,4 +1393,41 @@
             log.error("录像停止异常" + ex.getMessage());
         }
     }
+
+    //获取IP通道
+    @Override
+    public List<ArdChannel> getCameraChannelList(ArdCameras camera) {
+        /*获取通道*/
+        List<ArdChannel> channelList = new ArrayList<>();
+        try {
+            Integer chanNum = camera.getChanNum();
+            Integer startDChan = camera.getStartDChan();
+            if (chanNum > 0) {
+                // 获取通道号
+                for (int iChannum = 0; iChannum < chanNum; iChannum++) {
+                    ArdChannel ardChannel = new ArdChannel();
+                    int channum = iChannum + startDChan+1;
+                    HCNetSDK.NET_DVR_PICCFG_V40 strPicCfg = new HCNetSDK.NET_DVR_PICCFG_V40();
+                    strPicCfg.dwSize = strPicCfg.size();
+                    strPicCfg.write();
+                    Pointer pStrPicCfg = strPicCfg.getPointer();
+                    NativeLong lChannel = new NativeLong(channum);
+                    IntByReference pInt = new IntByReference(0);
+                    boolean b_GetPicCfg = hCNetSDK.NET_DVR_GetDVRConfig(camera.getLoginId(), HCNetSDK.NET_DVR_GET_PICCFG_V40, lChannel.intValue(),
+                            pStrPicCfg, strPicCfg.size(), pInt);
+                    if (b_GetPicCfg) {
+                        strPicCfg.read();
+                        String channelName = new String(strPicCfg.sChanName, "GBK").trim();
+                        ardChannel.setName(channelName);
+                    }
+                    ardChannel.setDeviceId(camera.getId());
+                    ardChannel.setChanNo(iChannum + 1);
+                    channelList.add(ardChannel);
+                }
+            }
+        } catch (Exception ex) {
+            log.error("获取相机通道异常:" + ex.getMessage());
+        }
+        return channelList;
+    }
 }
\ No newline at end of file
diff --git a/ard-work/src/main/java/com/ruoyi/device/hiksdk/util/hikSdkUtil/HCNetSDK.java b/ard-work/src/main/java/com/ruoyi/device/hiksdk/util/hikSdkUtil/HCNetSDK.java
index ebc20ec..a07c6d0 100644
--- a/ard-work/src/main/java/com/ruoyi/device/hiksdk/util/hikSdkUtil/HCNetSDK.java
+++ b/ard-work/src/main/java/com/ruoyi/device/hiksdk/util/hikSdkUtil/HCNetSDK.java
@@ -2252,7 +2252,8 @@
     public static class NET_DVR_IPCHANINFO extends HIKSDKStructure {/* IP通道匹配参数 */
         public byte byEnable;                    /* 该通道是否启用 */
         public byte byIPID;                    /* IP设备ID 取值1- MAX_IP_DEVICE */
-        public byte byChannel;                    /* 通道号 */
+        public byte byChannel;                  /* 通道号 */
+        public byte byIPIDHigh;
         public byte[] byres = new byte[33];                    /* 保留 */
 
 
diff --git a/ard-work/src/main/java/com/ruoyi/device/hiksdk/util/hikSdkUtil/LoginResultCallBack.java b/ard-work/src/main/java/com/ruoyi/device/hiksdk/util/hikSdkUtil/LoginResultCallBack.java
index 476c083..bbe9c52 100644
--- a/ard-work/src/main/java/com/ruoyi/device/hiksdk/util/hikSdkUtil/LoginResultCallBack.java
+++ b/ard-work/src/main/java/com/ruoyi/device/hiksdk/util/hikSdkUtil/LoginResultCallBack.java
@@ -3,13 +3,18 @@
 import com.ruoyi.alarm.global.domain.GuidePriorityQueue;
 import com.ruoyi.alarm.global.domain.GuideTask;
 import com.ruoyi.common.utils.spring.SpringUtils;
+import com.ruoyi.common.utils.uuid.IdUtils;
 import com.ruoyi.device.camera.domain.ArdCameras;
 import com.ruoyi.device.camera.service.IArdCamerasService;
+import com.ruoyi.device.channel.domain.ArdChannel;
+import com.ruoyi.device.channel.service.IArdChannelService;
 import com.ruoyi.device.hiksdk.common.GlobalVariable;
+import com.ruoyi.device.hiksdk.service.IHikClientService;
 import com.sun.jna.Pointer;
 import lombok.extern.slf4j.Slf4j;
 
 import java.util.Comparator;
+import java.util.List;
 import java.util.concurrent.PriorityBlockingQueue;
 
 /**
@@ -30,6 +35,9 @@
 
     @Override
     public int invoke(int lUserID, int dwResult, HCNetSDK.NET_DVR_DEVICEINFO_V30 lpDeviceinfo, Pointer pUser) {
+        IArdChannelService ardChannelService = SpringUtils.getBean(IArdChannelService.class);
+        IHikClientService hikClientService = SpringUtils.getBean(IHikClientService.class);
+        IArdCamerasService ardCamerasService = SpringUtils.getBean(IArdCamerasService.class);
         if (GlobalVariable.loginMap.containsKey(camera.getId())) {
             GlobalVariable.loginMap.remove(camera.getId());
         }
@@ -37,17 +45,28 @@
             GlobalVariable.loginMap.put(camera.getId(), lUserID);
             log.debug(camera.getIp() + ":" + camera.getPort() + "登录成功");
             camera.setLoginId(lUserID);
-            camera.setChannel((int) lpDeviceinfo.byChanNum);
+            camera.setChanNum((int) lpDeviceinfo.byChanNum);
+            camera.setStartDChan((int)lpDeviceinfo.byStartDChan);
+
+            //获取最新通道
+            List<ArdChannel> cameraChannelList = hikClientService.getCameraChannelList(camera);
+            if(cameraChannelList.size()>0) {
+                //删除管理通道
+                ardChannelService.deleteArdChannelByDeviceId(camera.getId());
+                for (ArdChannel channel : cameraChannelList) {
+                    channel.setId(IdUtils.simpleUUID());
+                    ardChannelService.insertArdChannel(channel);
+                }
+            }
             //创建引导队列
             Comparator<GuideTask> comparator = GuidePriorityQueue.getComparator();
-            PriorityBlockingQueue<GuideTask> priorityQueue = new PriorityBlockingQueue<>(1000,comparator);
+            PriorityBlockingQueue<GuideTask> priorityQueue = new PriorityBlockingQueue<>(1000, comparator);
             GuidePriorityQueue.cameraQueueMap.put(camera.getId(), priorityQueue);
         } else {
             log.debug(camera.getIp() + ":" + camera.getPort() + "登录失败");
-            camera.setChannel(0);
+            camera.setChanNum(0);
             camera.setLoginId(-1);
         }
-        IArdCamerasService ardCamerasService = SpringUtils.getBean(IArdCamerasService.class);
         ardCamerasService.updateArdCameras(camera);
         return 1;
     }
diff --git a/ard-work/src/main/resources/mapper/device/ArdCamerasMapper.xml b/ard-work/src/main/resources/mapper/device/ArdCamerasMapper.xml
index 90c8603..4e17b31 100644
--- a/ard-work/src/main/resources/mapper/device/ArdCamerasMapper.xml
+++ b/ard-work/src/main/resources/mapper/device/ArdCamerasMapper.xml
@@ -13,7 +13,7 @@
         <result property="username" column="username"/>
         <result property="password" column="password"/>
         <result property="gdtype" column="gdtype"/>
-        <result property="channel" column="channel"/>
+        <result property="chanNum" column="channel"/>
         <result property="longitude" column="longitude"/>
         <result property="latitude" column="latitude"/>
         <result property="altitude" column="altitude"/>
@@ -78,7 +78,7 @@
             <if test="username != null  and username != ''">and c.username like '%'||#{username}||'%'</if>
             <if test="password != null  and password != ''">and c.password = #{password}</if>
             <if test="gdtype != null  and gdtype != ''">and c.gdtype = #{gdtype}</if>
-            <if test="channel != null ">and c.channel = #{channel}</if>
+            <if test="chanNum != null ">and c.channel = #{chanNum}</if>
             <if test="longitude != null ">and c.longitude = #{longitude}</if>
             <if test="latitude != null ">and c.latitude = #{latitude}</if>
             <if test="altitude != null ">and c.altitude = #{altitude}</if>
@@ -111,7 +111,7 @@
             <if test="username != null  and username != ''">and c.username like '%'||#{username}||'%'</if>
             <if test="password != null  and password != ''">and c.password = #{password}</if>
             <if test="gdtype != null  and gdtype != ''">and c.gdtype = #{gdtype}</if>
-            <if test="channel != null ">and c.channel = #{channel}</if>
+            <if test="chanNum != null ">and c.channel = #{chanNum}</if>
             <if test="longitude != null ">and c.longitude = #{longitude}</if>
             <if test="latitude != null ">and c.latitude = #{latitude}</if>
             <if test="altitude != null ">and c.altitude = #{altitude}</if>
@@ -148,7 +148,7 @@
             <if test="username != null">username,</if>
             <if test="password != null">password,</if>
             <if test="gdtype != null">gdtype,</if>
-            <if test="channel != null">channel,</if>
+            <if test="chanNum != null">channel,</if>
             <if test="longitude != null">longitude,</if>
             <if test="latitude != null">latitude,</if>
             <if test="altitude != null">altitude,</if>
@@ -179,7 +179,7 @@
             <if test="username != null">#{username},</if>
             <if test="password != null">#{password},</if>
             <if test="gdtype != null">#{gdtype},</if>
-            <if test="channel != null">#{channel},</if>
+            <if test="chanNum != null">#{chanNum},</if>
             <if test="longitude != null">#{longitude},</if>
             <if test="latitude != null">#{latitude},</if>
             <if test="altitude != null">#{altitude},</if>
@@ -213,7 +213,7 @@
             <if test="username != null">username = #{username},</if>
             <if test="password != null">password = #{password},</if>
             <if test="gdtype != null">gdtype = #{gdtype},</if>
-            <if test="channel != null">channel = #{channel},</if>
+            <if test="chanNum != null">channel = #{chanNum},</if>
             <if test="longitude != null">longitude = #{longitude},</if>
             <if test="latitude != null">latitude = #{latitude},</if>
             <if test="altitude != null">altitude = #{altitude},</if>
diff --git a/ard-work/src/main/resources/mapper/device/ArdChannelMapper.xml b/ard-work/src/main/resources/mapper/device/ArdChannelMapper.xml
new file mode 100644
index 0000000..333dbe6
--- /dev/null
+++ b/ard-work/src/main/resources/mapper/device/ArdChannelMapper.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.device.channel.mapper.ArdChannelMapper">
+    
+    <resultMap type="ArdChannel" id="ArdChannelResult">
+        <result property="id"    column="id"    />
+        <result property="name"    column="name"    />
+        <result property="chanNo"    column="chan_no"    />
+        <result property="deviceId"    column="device_id"    />
+    </resultMap>
+
+    <sql id="selectArdChannelVo">
+        select id, name, chan_no, device_id from ard_channel
+    </sql>
+
+    <select id="selectArdChannelList" parameterType="ArdChannel" resultMap="ArdChannelResult">
+        <include refid="selectArdChannelVo"/>
+        <where>
+            <if test="deviceId!=null">device_id=#{deviceId}</if>
+        </where>
+    </select>
+    
+    <select id="selectArdChannelById" parameterType="String" resultMap="ArdChannelResult">
+        <include refid="selectArdChannelVo"/>
+        where id = #{id}
+    </select>
+        
+    <insert id="insertArdChannel" parameterType="ArdChannel">
+        insert into ard_channel
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="id != null">id,</if>
+            <if test="name != null">name,</if>
+            <if test="chanNo != null">chan_no,</if>
+            <if test="deviceId != null">device_id,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="id != null">#{id},</if>
+            <if test="name != null">#{name},</if>
+            <if test="chanNo != null">#{chanNo},</if>
+            <if test="deviceId != null">#{deviceId},</if>
+         </trim>
+    </insert>
+
+    <update id="updateArdChannel" parameterType="ArdChannel">
+        update ard_channel
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="name != null">name = #{name},</if>
+            <if test="chanNo != null">chan_no = #{chanNo},</if>
+            <if test="deviceId != null">device_id = #{deviceId},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteArdChannelById" parameterType="String">
+        delete from ard_channel where id = #{id}
+    </delete>
+
+    <delete id="deleteArdChannelByIds" parameterType="String">
+        delete from ard_channel where id in 
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+    <delete id="deleteArdChannelByDeviceId" parameterType="String">
+        delete from ard_channel where device_id = #{deviceId}
+    </delete>
+</mapper>
\ No newline at end of file

--
Gitblit v1.9.3