From 53e14c1919c4a3112f963689d0ce75fa08831021 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期六, 19 八月 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;
+
+    /** 鎵�灞炶澶噄d */
+    @Excel(name = "鎵�灞炶澶噄d")
+    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);
+
+    /**
+     * 鍒犻櫎閫氶亾绠$悊鎸夎澶嘔D
+     *
+     * @param deviceId 鎵�灞炶澶嘔D
+     * @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 鎵�灞炶澶嘔D
+     * @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 鎵�灞炶澶嘔D
+     * @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 @@
 
     //鍋滄褰曞儚-涓嶄笂浼爉inio
     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());//杞崲鎴恇ase64涓�
         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