Ver Fonte

完成通道共享

648540858 há 1 ano atrás
pai
commit
326025ee85

+ 10 - 0
src/main/java/com/genersoft/iot/vmp/gb28181/bean/PlatformChannel.java

@@ -0,0 +1,10 @@
+package com.genersoft.iot.vmp.gb28181.bean;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class PlatformChannel extends CommonGBChannel{
+    private int platformId;
+}

+ 15 - 59
src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlatformController.java

@@ -1,6 +1,5 @@
 package com.genersoft.iot.vmp.gb28181.controller;
 
-import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.genersoft.iot.vmp.common.VideoManagerConstants;
 import com.genersoft.iot.vmp.conf.DynamicTask;
@@ -9,12 +8,11 @@ import com.genersoft.iot.vmp.conf.UserSetting;
 import com.genersoft.iot.vmp.conf.exception.ControllerException;
 import com.genersoft.iot.vmp.conf.security.JwtUtils;
 import com.genersoft.iot.vmp.gb28181.bean.*;
-import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelReduce;
 import com.genersoft.iot.vmp.gb28181.controller.bean.UpdateChannelParam;
-import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
 import com.genersoft.iot.vmp.gb28181.service.IDeviceChannelService;
 import com.genersoft.iot.vmp.gb28181.service.IPlatformChannelService;
 import com.genersoft.iot.vmp.gb28181.service.IPlatformService;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import com.genersoft.iot.vmp.utils.DateUtil;
@@ -33,7 +31,6 @@ import org.springframework.web.bind.annotation.*;
 import javax.sip.InvalidArgumentException;
 import javax.sip.SipException;
 import java.text.ParseException;
-import java.util.List;
 
 /**
  * 级联平台管理
@@ -289,17 +286,6 @@ public class PlatformController {
         return parentPlatform != null;
     }
 
-    /**
-     * 分页查询级联平台的所有所有通道
-     *
-     * @param page        当前页
-     * @param count       每页条数
-     * @param platformId  上级平台ID
-     * @param query       查询内容
-     * @param online      是否在线
-     * @param channelType 通道类型
-     * @return
-     */
     @Operation(summary = "分页查询级联平台的所有所有通道", security = @SecurityRequirement(name = JwtUtils.HEADER))
     @Parameter(name = "page", description = "当前页", required = true)
     @Parameter(name = "count", description = "每页条数", required = true)
@@ -309,11 +295,11 @@ public class PlatformController {
     @Parameter(name = "hasShare", description = "是否已经共享")
     @GetMapping("/channel/list")
     @ResponseBody
-    public PageInfo<CommonGBChannel> channelList(int page, int count,
-                                                 @RequestParam(required = false) Integer platformId,
-                                                 @RequestParam(required = false) String query,
-                                                 @RequestParam(required = false) Boolean online,
-                                                 @RequestParam(required = false) Boolean hasShare) {
+    public PageInfo<PlatformChannel> queryChannelList(int page, int count,
+                                                      @RequestParam(required = false) Integer platformId,
+                                                      @RequestParam(required = false) String query,
+                                                      @RequestParam(required = false) Boolean online,
+                                                      @RequestParam(required = false) Boolean hasShare) {
 
         Assert.notNull(platformId, "上级平台的数据ID不可为NULL");
         if (ObjectUtils.isEmpty(query)) {
@@ -323,29 +309,22 @@ public class PlatformController {
         return platformChannelService.queryChannelList(page, count, query, online, platformId, hasShare);
     }
 
-    /**
-     * 向上级平台添加国标通道
-     *
-     * @param param 通道关联参数
-     * @return
-     */
     @Operation(summary = "向上级平台添加国标通道", security = @SecurityRequirement(name = JwtUtils.HEADER))
-    @PostMapping("/update_channel_for_gb")
+    @PostMapping("/channel/add")
     @ResponseBody
-    public void updateChannelForGB(@RequestBody UpdateChannelParam param) {
+    public void addChannel(@RequestBody UpdateChannelParam param) {
 
         if (log.isDebugEnabled()) {
             log.debug("给上级平台添加国标通道API调用");
         }
         int result = 0;
-        if (param.getChannelReduces() == null || param.getChannelReduces().size() == 0) {
+        if (param.getChannelIds() == null || param.getChannelIds().isEmpty()) {
             if (param.isAll()) {
                 log.info("[国标级联]添加所有通道到上级平台, {}", param.getPlatformId());
-                List<ChannelReduce> allChannelForDevice = deviceChannelService.queryAllChannelList(param.getPlatformId());
-                result = platformChannelService.updateChannelForGB(param.getPlatformId(), allChannelForDevice, param.getCatalogId());
+                result = platformChannelService.addAllChannel(param.getPlatformId());
             }
         }else {
-            result = platformChannelService.updateChannelForGB(param.getPlatformId(), param.getChannelReduces(), param.getCatalogId());
+            result = platformChannelService.addChannels(param.getPlatformId(), param.getChannelIds());
         }
         if (result <= 0) {
             throw new ControllerException(ErrorCode.ERROR100);
@@ -359,7 +338,7 @@ public class PlatformController {
      * @return
      */
     @Operation(summary = "从上级平台移除国标通道", security = @SecurityRequirement(name = JwtUtils.HEADER))
-    @DeleteMapping("/del_channel_for_gb")
+    @DeleteMapping("/channel/remove")
     @ResponseBody
     public void delChannelForGB(@RequestBody UpdateChannelParam param) {
 
@@ -367,39 +346,16 @@ public class PlatformController {
             log.debug("给上级平台删除国标通道API调用");
         }
         int result = 0;
-        if (param.getChannelReduces() == null || param.getChannelReduces().size() == 0) {
+        if (param.getChannelIds() == null || param.getChannelIds().isEmpty()) {
             if (param.isAll()) {
                 log.info("[国标级联]移除所有通道,上级平台, {}", param.getPlatformId());
-                result = platformChannelService.delAllChannelForGB(param.getPlatformId(), param.getCatalogId());
+                result = platformChannelService.removeAllChannel(param.getPlatformId());
             }
         }else {
-            result = storager.delChannelForGB(param.getPlatformId(), param.getChannelReduces());
+            result = platformChannelService.removeChannels(param.getPlatformId(), param.getChannelIds());
         }
         if (result <= 0) {
             throw new ControllerException(ErrorCode.ERROR100);
         }
     }
-
-    /**
-     * 删除关联
-     *
-     * @param platformCatalog 关联的信息
-     * @return
-     */
-    @Operation(summary = "删除关联", security = @SecurityRequirement(name = JwtUtils.HEADER))
-    @DeleteMapping("/catalog/relation/del")
-    @ResponseBody
-    public void delRelation(@RequestBody PlatformCatalog platformCatalog) {
-
-        if (log.isDebugEnabled()) {
-            log.debug("删除关联,{}", JSON.toJSONString(platformCatalog));
-        }
-//        int delResult = storager.delRelation(platformCatalog);
-//
-//        if (delResult <= 0) {
-//            throw new ControllerException(ErrorCode.ERROR100.getCode(), "写入数据库失败");
-//        }
-    }
-
-
 }

+ 7 - 43
src/main/java/com/genersoft/iot/vmp/gb28181/controller/bean/UpdateChannelParam.java

@@ -1,57 +1,21 @@
 package com.genersoft.iot.vmp.gb28181.controller.bean;
 
 import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
 
 import java.util.List;
 
-/**
- * 通道关联参数
- * @author lin
- */
+@Data
 @Schema(description = "通道关联参数")
 public class UpdateChannelParam {
 
-    @Schema(description = "上级平台的国标编号")
-    private String platformId;
+    @Schema(description = "上级平台的数据库ID")
+    private Integer platformId;
 
-    @Schema(description = "目录的国标编号")
-    private String catalogId;
 
-    @Schema(description = "处理所有通道")
+    @Schema(description = "关联所有通道")
     private boolean all;
 
-    @Schema(description = "")
-    private List<ChannelReduce> channelReduces;
-
-    public String getPlatformId() {
-        return platformId;
-    }
-
-    public void setPlatformId(String platformId) {
-        this.platformId = platformId;
-    }
-
-    public List<ChannelReduce> getChannelReduces() {
-        return channelReduces;
-    }
-
-    public void setChannelReduces(List<ChannelReduce> channelReduces) {
-        this.channelReduces = channelReduces;
-    }
-
-    public String getCatalogId() {
-        return catalogId;
-    }
-
-    public void setCatalogId(String catalogId) {
-        this.catalogId = catalogId;
-    }
-
-    public boolean isAll() {
-        return all;
-    }
-
-    public void setAll(boolean all) {
-        this.all = all;
-    }
+    @Schema(description = "待关联的通道ID")
+    List<Integer> channelIds;
 }

+ 2 - 96
src/main/java/com/genersoft/iot/vmp/gb28181/dao/CommonGBChannelMapper.java

@@ -223,55 +223,6 @@ public interface CommonGBChannelMapper {
             "</script>")
     int updateStatus(List<CommonGBChannel> commonGBChannels);
 
-    @Select(value = {"select\n" +
-            "    wdc.id as gb_id,\n" +
-            "    wdc.device_db_id,\n" +
-            "    wdc.create_time,\n" +
-            "    wdc.update_time,\n" +
-            "    wdc.sub_count,\n" +
-            "    wdc.stream_id,\n" +
-            "    wdc.has_audio,\n" +
-            "    wdc.gps_time,\n" +
-            "    wdc.stream_identification,\n" +
-            "    coalesce(wpgc.device_id, wdc.gb_device_id, wdc.device_id) as gb_device_id,\n" +
-            "    coalesce(wpgc.name, wdc.gb_name, wdc.name) as gb_name,\n" +
-            "    coalesce(wdc.gb_manufacturer, wdc.manufacturer) as gb_manufacturer,\n" +
-            "    coalesce(wdc.gb_model, wdc.model) as gb_model,\n" +
-            "    coalesce(wdc.gb_owner, wdc.owner) as gb_owner,\n" +
-            "    coalesce(wdc.gb_civil_code, wdc.civil_code) as gb_civil_code,\n" +
-            "    coalesce(wdc.gb_block, wdc.block) as gb_block,\n" +
-            "    coalesce(wdc.gb_address, wdc.address) as gb_address,\n" +
-            "    coalesce(wpgc.parental, wdc.gb_parental, wdc.parental) as gb_parental,\n" +
-            "    coalesce(wpgc.parent_id, wdc.gb_parent_id, wdc.parent_id) as gb_parent_id,\n" +
-            "    coalesce(wdc.gb_safety_way, wdc.safety_way) as gb_safety_way,\n" +
-            "    coalesce(wdc.gb_register_way, wdc.register_way) as gb_register_way,\n" +
-            "    coalesce(wdc.gb_cert_num, wdc.cert_num) as gb_cert_num,\n" +
-            "    coalesce(wdc.gb_certifiable, wdc.certifiable) as gb_certifiable,\n" +
-            "    coalesce(wdc.gb_err_code, wdc.err_code) as gb_err_code,\n" +
-            "    coalesce(wdc.gb_end_time, wdc.end_time) as gb_end_time,\n" +
-            "    coalesce(wdc.gb_secrecy, wdc.secrecy) as gb_secrecy,\n" +
-            "    coalesce(wdc.gb_ip_address, wdc.ip_address) as gb_ip_address,\n" +
-            "    coalesce(wdc.gb_port, wdc.port) as gb_port,\n" +
-            "    coalesce(wdc.gb_password, wdc.password) as gb_password,\n" +
-            "    coalesce(wdc.gb_status, wdc.status) as gb_status,\n" +
-            "    coalesce(wdc.gb_longitude, wdc.longitude) as gb_longitude,\n" +
-            "    coalesce(wdc.gb_latitude, wdc.latitude) as gb_latitude,\n" +
-            "    coalesce(wdc.gb_ptz_type, wdc.ptz_type) as gb_ptz_type,\n" +
-            "    coalesce(wdc.gb_position_type, wdc.position_type) as gb_position_type,\n" +
-            "    coalesce(wdc.gb_room_type, wdc.room_type) as gb_room_type,\n" +
-            "    coalesce(wdc.gb_use_type, wdc.use_type) as gb_use_type,\n" +
-            "    coalesce(wdc.gb_supply_light_type, wdc.supply_light_type) as gb_supply_light_type,\n" +
-            "    coalesce(wdc.gb_direction_type, wdc.direction_type) as gb_direction_type,\n" +
-            "    coalesce(wdc.gb_resolution, wdc.resolution) as gb_resolution,\n" +
-            "    coalesce(wpgc.business_group_id, wdc.gb_business_group_id, wdc.business_group_id) as gb_business_group_id,\n" +
-            "    coalesce(wdc.gb_download_speed, wdc.download_speed) as gb_download_speed,\n" +
-            "    coalesce(wdc.gb_svc_space_support_mod, wdc.svc_space_support_mod) as gb_svc_space_support_mod,\n" +
-            "    coalesce(wdc.gb_svc_time_support_mode,wdc.svc_time_support_mode) as gb_svc_time_support_mode\n" +
-            "from wvp_device_channel wdc left join wvp_platform_gb_channel wpgc on wdc.id = wpgc.device_channel_id\n" +
-            "where wpgc.platform_id = #{platformId}"})
-    List<CommonGBChannel> queryByPlatformId(@Param("platformId") Integer platformId);
-
-
     @Update(value = {" <script>" +
             " UPDATE wvp_device_channel " +
             " SET update_time=#{updateTime}, gb_device_id = null, gb_name = null, gb_manufacturer = null," +
@@ -500,56 +451,11 @@ public interface CommonGBChannelMapper {
             "    coalesce(wpgc.svc_time_support_mode, wdc.gb_svc_time_support_mode, wdc.svc_time_support_mode) as gb_svc_time_support_mode\n" +
             " from wvp_device_channel wdc" +
             " left join wvp_platform_gb_channel wpgc on wdc.id = wpgc.device_channel_id" +
-            " where wpgc.platform_id = #{platformId}"
+            " where wpgc.platform_id = #{platformId} "
 
     )
     List<CommonGBChannel> queryWithPlatform(@Param("platformId") Integer platformId);
 
-    @Select("select\n" +
-            "    wdc.id as gb_id,\n" +
-            "    wdc.device_db_id as gb_device_db_id,\n" +
-            "    wdc.stream_push_id,\n" +
-            "    wdc.stream_proxy_id,\n" +
-            "    wdc.create_time,\n" +
-            "    wdc.update_time,\n" +
-            "    coalesce(wpgc.device_id, wdc.gb_device_id, wdc.device_id) as gb_device_id,\n" +
-            "    coalesce(wpgc.name, wdc.gb_name, wdc.name) as gb_name,\n" +
-            "    coalesce(wpgc.manufacturer, wdc.gb_manufacturer, wdc.manufacturer) as gb_manufacturer,\n" +
-            "    coalesce(wpgc.model, wdc.gb_model, wdc.model) as gb_model,\n" +
-            "    coalesce(wpgc.owner, wdc.gb_owner, wdc.owner) as gb_owner,\n" +
-            "    coalesce(wpgc.civil_code, wdc.gb_civil_code, wdc.civil_code),\n" +
-            "    coalesce(wpgc.block, wdc.gb_block, wdc.block) as gb_block,\n" +
-            "    coalesce(wpgc.address, wdc.gb_address, wdc.address) as gb_address,\n" +
-            "    coalesce(wpgc.parental, wdc.gb_parental, wdc.parental) as gb_parental,\n" +
-            "    coalesce(wpgc.parent_id, wdc.gb_parent_id, wdc.parent_id) as gb_parent_id,\n" +
-            "    coalesce(wpgc.safety_way, wdc.gb_safety_way, wdc.safety_way) as gb_safety_way,\n" +
-            "    coalesce(wpgc.register_way, wdc.gb_register_way, wdc.register_way) as gb_register_way,\n" +
-            "    coalesce(wpgc.cert_num, wdc.gb_cert_num, wdc.cert_num) as gb_cert_num,\n" +
-            "    coalesce(wpgc.certifiable, wdc.gb_certifiable, wdc.certifiable) as gb_certifiable,\n" +
-            "    coalesce(wpgc.err_code, wdc.gb_err_code, wdc.err_code) as gb_err_code,\n" +
-            "    coalesce(wpgc.end_time, wdc.gb_end_time, wdc.end_time) as gb_end_time,\n" +
-            "    coalesce(wpgc.secrecy, wdc.gb_secrecy, wdc.secrecy) as gb_secrecy,\n" +
-            "    coalesce(wpgc.ip_address, wdc.gb_ip_address, wdc.ip_address) as gb_ip_address,\n" +
-            "    coalesce(wpgc.port, wdc.gb_port, wdc.port) as gb_port,\n" +
-            "    coalesce(wpgc.password, wdc.gb_password, wdc.password) as gb_password,\n" +
-            "    coalesce(wpgc.status, wdc.gb_status, wdc.status) as gb_status,\n" +
-            "    coalesce(wpgc.longitude, wdc.gb_longitude, wdc.longitude) as gb_longitude,\n" +
-            "    coalesce(wpgc.latitude, wdc.gb_latitude, wdc.latitude) as gb_latitude,\n" +
-            "    coalesce(wpgc.ptz_type, wdc.gb_ptz_type, wdc.ptz_type) as gb_ptz_type,\n" +
-            "    coalesce(wpgc.position_type, wdc.gb_position_type, wdc.position_type) as gb_position_type,\n" +
-            "    coalesce(wpgc.room_type, wdc.gb_room_type, wdc.room_type) as gb_room_type,\n" +
-            "    coalesce(wpgc.use_type, wdc.gb_use_type, wdc.use_type) as gb_use_type,\n" +
-            "    coalesce(wpgc.supply_light_type, wdc.gb_supply_light_type, wdc.supply_light_type) as gb_supply_light_type,\n" +
-            "    coalesce(wpgc.direction_type, wdc.gb_direction_type, wdc.direction_type) as gb_direction_type,\n" +
-            "    coalesce(wpgc.resolution, wdc.gb_resolution, wdc.resolution) as gb_resolution,\n" +
-            "    coalesce(wpgc.business_group_id, wdc.gb_business_group_id, wdc.business_group_id) as gb_business_group_id,\n" +
-            "    coalesce(wpgc.download_speed, wdc.gb_download_speed, wdc.download_speed) as gb_download_speed,\n" +
-            "    coalesce(wpgc.svc_space_support_mod, wdc.gb_svc_space_support_mod, wdc.svc_space_support_mod) as gb_svc_space_support_mod,\n" +
-            "    coalesce(wpgc.svc_time_support_mode, wdc.gb_svc_time_support_mode, wdc.svc_time_support_mode) as gb_svc_time_support_mode\n" +
-            " from wvp_device_channel wdc" +
-            " left join wvp_platform_gb_channel wpgc on wdc.id = wpgc.device_channel_id" +
-            " where wpgc.platform_id = #{platformId} and coalesce(wpgc.device_id, wdc.gb_device_id, wdc.device_id) = #{channelDeviceId}"
 
-    )
-    CommonGBChannel queryOneWithPlatform(@Param("platformId") Integer platformId, @Param("channelDeviceId") String channelDeviceId);
+
 }

+ 228 - 4
src/main/java/com/genersoft/iot/vmp/gb28181/dao/PlatformChannelMapper.java

@@ -25,12 +25,12 @@ public interface PlatformChannelMapper {
     List<Integer> findChannelRelatedPlatform(@Param("platformId") String platformId, @Param("channelReduces") List<ChannelReduce> channelReduces);
 
     @Insert("<script> "+
-            "INSERT INTO wvp_platform_gb_channel (platform_id, device_channel_id, catalog_id) VALUES" +
-            "<foreach collection='channelReducesToAdd'  item='item' separator=','>" +
-            " (#{platformId}, #{item.id} , #{item.catalogId} )" +
+            "INSERT INTO wvp_platform_gb_channel (platform_id, device_channel_id) VALUES" +
+            "<foreach collection='channelList'  item='item' separator=','>" +
+            " (#{platformId}, #{item.gbId} )" +
             "</foreach>" +
             "</script>")
-    int addChannels(@Param("platformId") String platformId, @Param("channelReducesToAdd") List<ChannelReduce> channelReducesToAdd);
+    int addChannels(@Param("platformId") Integer platformId, @Param("channelList") List<CommonGBChannel> channelList);
 
     @Delete("<script> "+
             "DELETE from wvp_platform_gb_channel WHERE platform_id=#{platformId} AND device_channel_id in" +
@@ -119,4 +119,228 @@ public interface PlatformChannelMapper {
 
     @Select("SELECT pgc.platform_id from wvp_platform_gb_channel pgc left join wvp_device_channel dc on dc.id = pgc.device_channel_id WHERE dc.device_id=#{channelId}")
     List<Integer> queryParentPlatformByChannelId(@Param("channelId") String channelId);
+
+
+
+    @Select("<script>" +
+            " select " +
+            "    wdc.id as gb_id,\n" +
+            "    wdc.device_db_id as gb_device_db_id,\n" +
+            "    wdc.stream_push_id,\n" +
+            "    wdc.stream_proxy_id,\n" +
+            "    wdc.create_time,\n" +
+            "    wdc.update_time,\n" +
+            "    coalesce(wpgc.device_id, wdc.gb_device_id, wdc.device_id) as gb_device_id,\n" +
+            "    coalesce(wpgc.name, wdc.gb_name, wdc.name) as gb_name,\n" +
+            "    coalesce(wpgc.manufacturer, wdc.gb_manufacturer, wdc.manufacturer) as gb_manufacturer,\n" +
+            "    coalesce(wpgc.model, wdc.gb_model, wdc.model) as gb_model,\n" +
+            "    coalesce(wpgc.owner, wdc.gb_owner, wdc.owner) as gb_owner,\n" +
+            "    coalesce(wpgc.civil_code, wdc.gb_civil_code, wdc.civil_code),\n" +
+            "    coalesce(wpgc.block, wdc.gb_block, wdc.block) as gb_block,\n" +
+            "    coalesce(wpgc.address, wdc.gb_address, wdc.address) as gb_address,\n" +
+            "    coalesce(wpgc.parental, wdc.gb_parental, wdc.parental) as gb_parental,\n" +
+            "    coalesce(wpgc.parent_id, wdc.gb_parent_id, wdc.parent_id) as gb_parent_id,\n" +
+            "    coalesce(wpgc.safety_way, wdc.gb_safety_way, wdc.safety_way) as gb_safety_way,\n" +
+            "    coalesce(wpgc.register_way, wdc.gb_register_way, wdc.register_way) as gb_register_way,\n" +
+            "    coalesce(wpgc.cert_num, wdc.gb_cert_num, wdc.cert_num) as gb_cert_num,\n" +
+            "    coalesce(wpgc.certifiable, wdc.gb_certifiable, wdc.certifiable) as gb_certifiable,\n" +
+            "    coalesce(wpgc.err_code, wdc.gb_err_code, wdc.err_code) as gb_err_code,\n" +
+            "    coalesce(wpgc.end_time, wdc.gb_end_time, wdc.end_time) as gb_end_time,\n" +
+            "    coalesce(wpgc.secrecy, wdc.gb_secrecy, wdc.secrecy) as gb_secrecy,\n" +
+            "    coalesce(wpgc.ip_address, wdc.gb_ip_address, wdc.ip_address) as gb_ip_address,\n" +
+            "    coalesce(wpgc.port, wdc.gb_port, wdc.port) as gb_port,\n" +
+            "    coalesce(wpgc.password, wdc.gb_password, wdc.password) as gb_password,\n" +
+            "    coalesce(wpgc.status, wdc.gb_status, wdc.status) as gb_status,\n" +
+            "    coalesce(wpgc.longitude, wdc.gb_longitude, wdc.longitude) as gb_longitude,\n" +
+            "    coalesce(wpgc.latitude, wdc.gb_latitude, wdc.latitude) as gb_latitude,\n" +
+            "    coalesce(wpgc.ptz_type, wdc.gb_ptz_type, wdc.ptz_type) as gb_ptz_type,\n" +
+            "    coalesce(wpgc.position_type, wdc.gb_position_type, wdc.position_type) as gb_position_type,\n" +
+            "    coalesce(wpgc.room_type, wdc.gb_room_type, wdc.room_type) as gb_room_type,\n" +
+            "    coalesce(wpgc.use_type, wdc.gb_use_type, wdc.use_type) as gb_use_type,\n" +
+            "    coalesce(wpgc.supply_light_type, wdc.gb_supply_light_type, wdc.supply_light_type) as gb_supply_light_type,\n" +
+            "    coalesce(wpgc.direction_type, wdc.gb_direction_type, wdc.direction_type) as gb_direction_type,\n" +
+            "    coalesce(wpgc.resolution, wdc.gb_resolution, wdc.resolution) as gb_resolution,\n" +
+            "    coalesce(wpgc.business_group_id, wdc.gb_business_group_id, wdc.business_group_id) as gb_business_group_id,\n" +
+            "    coalesce(wpgc.download_speed, wdc.gb_download_speed, wdc.download_speed) as gb_download_speed,\n" +
+            "    coalesce(wpgc.svc_space_support_mod, wdc.gb_svc_space_support_mod, wdc.svc_space_support_mod) as gb_svc_space_support_mod,\n" +
+            "    coalesce(wpgc.svc_time_support_mode, wdc.gb_svc_time_support_mode, wdc.svc_time_support_mode) as gb_svc_time_support_mode, \n" +
+            "    wpgc.platform_id " +
+            " from wvp_device_channel wdc" +
+            " left join wvp_platform_gb_channel wpgc on wdc.id = wpgc.device_channel_id and wpgc.platform_id = #{platformId}" +
+            " where  1=1" +
+            " <if test='query != null'> AND (coalesce(wpgc.device_id, wdc.gb_device_id, wdc.device_id) LIKE concat('%',#{query},'%') " +
+            " OR coalesce(wpgc.name, wdc.gb_name, wdc.name)  LIKE concat('%',#{query},'%'))</if> " +
+            " <if test='online == true'> AND coalesce(wpgc.status, wdc.gb_status, wdc.status) = 'ON'</if> " +
+            " <if test='online == false'> AND coalesce(wpgc.status, wdc.gb_status, wdc.status) = 'OFF'</if> " +
+            " <if test='hasShare == true'> AND wpgc.platform_id = #{platformId}</if> " +
+            " <if test='hasShare == false'> AND wpgc.platform_id is null</if> " +
+
+            "</script>")
+    List<PlatformChannel> queryForPlatformSearch(@Param("platformId") Integer platformId, @Param("query") String query,
+                                                 @Param("online") Boolean online, @Param("hasShare") Boolean hasShare);
+
+    @Select("select\n" +
+            "    wdc.id as gb_id,\n" +
+            "    wdc.device_db_id as gb_device_db_id,\n" +
+            "    wdc.stream_push_id,\n" +
+            "    wdc.stream_proxy_id,\n" +
+            "    wdc.create_time,\n" +
+            "    wdc.update_time,\n" +
+            "    coalesce(wpgc.device_id, wdc.gb_device_id, wdc.device_id) as gb_device_id,\n" +
+            "    coalesce(wpgc.name, wdc.gb_name, wdc.name) as gb_name,\n" +
+            "    coalesce(wpgc.manufacturer, wdc.gb_manufacturer, wdc.manufacturer) as gb_manufacturer,\n" +
+            "    coalesce(wpgc.model, wdc.gb_model, wdc.model) as gb_model,\n" +
+            "    coalesce(wpgc.owner, wdc.gb_owner, wdc.owner) as gb_owner,\n" +
+            "    coalesce(wpgc.civil_code, wdc.gb_civil_code, wdc.civil_code),\n" +
+            "    coalesce(wpgc.block, wdc.gb_block, wdc.block) as gb_block,\n" +
+            "    coalesce(wpgc.address, wdc.gb_address, wdc.address) as gb_address,\n" +
+            "    coalesce(wpgc.parental, wdc.gb_parental, wdc.parental) as gb_parental,\n" +
+            "    coalesce(wpgc.parent_id, wdc.gb_parent_id, wdc.parent_id) as gb_parent_id,\n" +
+            "    coalesce(wpgc.safety_way, wdc.gb_safety_way, wdc.safety_way) as gb_safety_way,\n" +
+            "    coalesce(wpgc.register_way, wdc.gb_register_way, wdc.register_way) as gb_register_way,\n" +
+            "    coalesce(wpgc.cert_num, wdc.gb_cert_num, wdc.cert_num) as gb_cert_num,\n" +
+            "    coalesce(wpgc.certifiable, wdc.gb_certifiable, wdc.certifiable) as gb_certifiable,\n" +
+            "    coalesce(wpgc.err_code, wdc.gb_err_code, wdc.err_code) as gb_err_code,\n" +
+            "    coalesce(wpgc.end_time, wdc.gb_end_time, wdc.end_time) as gb_end_time,\n" +
+            "    coalesce(wpgc.secrecy, wdc.gb_secrecy, wdc.secrecy) as gb_secrecy,\n" +
+            "    coalesce(wpgc.ip_address, wdc.gb_ip_address, wdc.ip_address) as gb_ip_address,\n" +
+            "    coalesce(wpgc.port, wdc.gb_port, wdc.port) as gb_port,\n" +
+            "    coalesce(wpgc.password, wdc.gb_password, wdc.password) as gb_password,\n" +
+            "    coalesce(wpgc.status, wdc.gb_status, wdc.status) as gb_status,\n" +
+            "    coalesce(wpgc.longitude, wdc.gb_longitude, wdc.longitude) as gb_longitude,\n" +
+            "    coalesce(wpgc.latitude, wdc.gb_latitude, wdc.latitude) as gb_latitude,\n" +
+            "    coalesce(wpgc.ptz_type, wdc.gb_ptz_type, wdc.ptz_type) as gb_ptz_type,\n" +
+            "    coalesce(wpgc.position_type, wdc.gb_position_type, wdc.position_type) as gb_position_type,\n" +
+            "    coalesce(wpgc.room_type, wdc.gb_room_type, wdc.room_type) as gb_room_type,\n" +
+            "    coalesce(wpgc.use_type, wdc.gb_use_type, wdc.use_type) as gb_use_type,\n" +
+            "    coalesce(wpgc.supply_light_type, wdc.gb_supply_light_type, wdc.supply_light_type) as gb_supply_light_type,\n" +
+            "    coalesce(wpgc.direction_type, wdc.gb_direction_type, wdc.direction_type) as gb_direction_type,\n" +
+            "    coalesce(wpgc.resolution, wdc.gb_resolution, wdc.resolution) as gb_resolution,\n" +
+            "    coalesce(wpgc.business_group_id, wdc.gb_business_group_id, wdc.business_group_id) as gb_business_group_id,\n" +
+            "    coalesce(wpgc.download_speed, wdc.gb_download_speed, wdc.download_speed) as gb_download_speed,\n" +
+            "    coalesce(wpgc.svc_space_support_mod, wdc.gb_svc_space_support_mod, wdc.svc_space_support_mod) as gb_svc_space_support_mod,\n" +
+            "    coalesce(wpgc.svc_time_support_mode, wdc.gb_svc_time_support_mode, wdc.svc_time_support_mode) as gb_svc_time_support_mode\n" +
+            " from wvp_device_channel wdc" +
+            " left join wvp_platform_gb_channel wpgc on wdc.id = wpgc.device_channel_id" +
+            " where wpgc.platform_id = #{platformId} and coalesce(wpgc.device_id, wdc.gb_device_id, wdc.device_id) = #{channelDeviceId}"
+
+    )
+    CommonGBChannel queryOneWithPlatform(@Param("platformId") Integer platformId, @Param("channelDeviceId") String channelDeviceId);
+
+
+    @Select("<script>" +
+            " select " +
+            "    wdc.id as gb_id,\n" +
+            "    wdc.device_db_id as gb_device_db_id,\n" +
+            "    wdc.stream_push_id,\n" +
+            "    wdc.stream_proxy_id,\n" +
+            "    wdc.create_time,\n" +
+            "    wdc.update_time,\n" +
+            "    coalesce(wpgc.device_id, wdc.gb_device_id, wdc.device_id) as gb_device_id,\n" +
+            "    coalesce(wpgc.name, wdc.gb_name, wdc.name) as gb_name,\n" +
+            "    coalesce(wpgc.manufacturer, wdc.gb_manufacturer, wdc.manufacturer) as gb_manufacturer,\n" +
+            "    coalesce(wpgc.model, wdc.gb_model, wdc.model) as gb_model,\n" +
+            "    coalesce(wpgc.owner, wdc.gb_owner, wdc.owner) as gb_owner,\n" +
+            "    coalesce(wpgc.civil_code, wdc.gb_civil_code, wdc.civil_code),\n" +
+            "    coalesce(wpgc.block, wdc.gb_block, wdc.block) as gb_block,\n" +
+            "    coalesce(wpgc.address, wdc.gb_address, wdc.address) as gb_address,\n" +
+            "    coalesce(wpgc.parental, wdc.gb_parental, wdc.parental) as gb_parental,\n" +
+            "    coalesce(wpgc.parent_id, wdc.gb_parent_id, wdc.parent_id) as gb_parent_id,\n" +
+            "    coalesce(wpgc.safety_way, wdc.gb_safety_way, wdc.safety_way) as gb_safety_way,\n" +
+            "    coalesce(wpgc.register_way, wdc.gb_register_way, wdc.register_way) as gb_register_way,\n" +
+            "    coalesce(wpgc.cert_num, wdc.gb_cert_num, wdc.cert_num) as gb_cert_num,\n" +
+            "    coalesce(wpgc.certifiable, wdc.gb_certifiable, wdc.certifiable) as gb_certifiable,\n" +
+            "    coalesce(wpgc.err_code, wdc.gb_err_code, wdc.err_code) as gb_err_code,\n" +
+            "    coalesce(wpgc.end_time, wdc.gb_end_time, wdc.end_time) as gb_end_time,\n" +
+            "    coalesce(wpgc.secrecy, wdc.gb_secrecy, wdc.secrecy) as gb_secrecy,\n" +
+            "    coalesce(wpgc.ip_address, wdc.gb_ip_address, wdc.ip_address) as gb_ip_address,\n" +
+            "    coalesce(wpgc.port, wdc.gb_port, wdc.port) as gb_port,\n" +
+            "    coalesce(wpgc.password, wdc.gb_password, wdc.password) as gb_password,\n" +
+            "    coalesce(wpgc.status, wdc.gb_status, wdc.status) as gb_status,\n" +
+            "    coalesce(wpgc.longitude, wdc.gb_longitude, wdc.longitude) as gb_longitude,\n" +
+            "    coalesce(wpgc.latitude, wdc.gb_latitude, wdc.latitude) as gb_latitude,\n" +
+            "    coalesce(wpgc.ptz_type, wdc.gb_ptz_type, wdc.ptz_type) as gb_ptz_type,\n" +
+            "    coalesce(wpgc.position_type, wdc.gb_position_type, wdc.position_type) as gb_position_type,\n" +
+            "    coalesce(wpgc.room_type, wdc.gb_room_type, wdc.room_type) as gb_room_type,\n" +
+            "    coalesce(wpgc.use_type, wdc.gb_use_type, wdc.use_type) as gb_use_type,\n" +
+            "    coalesce(wpgc.supply_light_type, wdc.gb_supply_light_type, wdc.supply_light_type) as gb_supply_light_type,\n" +
+            "    coalesce(wpgc.direction_type, wdc.gb_direction_type, wdc.direction_type) as gb_direction_type,\n" +
+            "    coalesce(wpgc.resolution, wdc.gb_resolution, wdc.resolution) as gb_resolution,\n" +
+            "    coalesce(wpgc.business_group_id, wdc.gb_business_group_id, wdc.business_group_id) as gb_business_group_id,\n" +
+            "    coalesce(wpgc.download_speed, wdc.gb_download_speed, wdc.download_speed) as gb_download_speed,\n" +
+            "    coalesce(wpgc.svc_space_support_mod, wdc.gb_svc_space_support_mod, wdc.svc_space_support_mod) as gb_svc_space_support_mod,\n" +
+            "    coalesce(wpgc.svc_time_support_mode, wdc.gb_svc_time_support_mode, wdc.svc_time_support_mode) as gb_svc_time_support_mode\n" +
+            " from wvp_device_channel wdc" +
+            " left join wvp_platform_gb_channel wpgc on wdc.id = wpgc.device_channel_id and wpgc.platform_id = #{platformId}" +
+            " where  wpgc.platform_id is null" +
+            "<if test='channelIds != null'> AND wdc.id in <foreach item='item' index='index' collection='channelIds' open='(' separator=',' close=')'>" +
+            "#{item} " +
+            "</foreach> </if>" +
+
+            "</script>")
+    List<CommonGBChannel> queryNotShare(@Param("platformId") Integer platformId, List<Integer> channelIds);
+
+    @Select("<script>" +
+            " select " +
+            "    wdc.id as gb_id,\n" +
+            "    wdc.device_db_id as gb_device_db_id,\n" +
+            "    wdc.stream_push_id,\n" +
+            "    wdc.stream_proxy_id,\n" +
+            "    wdc.create_time,\n" +
+            "    wdc.update_time,\n" +
+            "    coalesce(wpgc.device_id, wdc.gb_device_id, wdc.device_id) as gb_device_id,\n" +
+            "    coalesce(wpgc.name, wdc.gb_name, wdc.name) as gb_name,\n" +
+            "    coalesce(wpgc.manufacturer, wdc.gb_manufacturer, wdc.manufacturer) as gb_manufacturer,\n" +
+            "    coalesce(wpgc.model, wdc.gb_model, wdc.model) as gb_model,\n" +
+            "    coalesce(wpgc.owner, wdc.gb_owner, wdc.owner) as gb_owner,\n" +
+            "    coalesce(wpgc.civil_code, wdc.gb_civil_code, wdc.civil_code),\n" +
+            "    coalesce(wpgc.block, wdc.gb_block, wdc.block) as gb_block,\n" +
+            "    coalesce(wpgc.address, wdc.gb_address, wdc.address) as gb_address,\n" +
+            "    coalesce(wpgc.parental, wdc.gb_parental, wdc.parental) as gb_parental,\n" +
+            "    coalesce(wpgc.parent_id, wdc.gb_parent_id, wdc.parent_id) as gb_parent_id,\n" +
+            "    coalesce(wpgc.safety_way, wdc.gb_safety_way, wdc.safety_way) as gb_safety_way,\n" +
+            "    coalesce(wpgc.register_way, wdc.gb_register_way, wdc.register_way) as gb_register_way,\n" +
+            "    coalesce(wpgc.cert_num, wdc.gb_cert_num, wdc.cert_num) as gb_cert_num,\n" +
+            "    coalesce(wpgc.certifiable, wdc.gb_certifiable, wdc.certifiable) as gb_certifiable,\n" +
+            "    coalesce(wpgc.err_code, wdc.gb_err_code, wdc.err_code) as gb_err_code,\n" +
+            "    coalesce(wpgc.end_time, wdc.gb_end_time, wdc.end_time) as gb_end_time,\n" +
+            "    coalesce(wpgc.secrecy, wdc.gb_secrecy, wdc.secrecy) as gb_secrecy,\n" +
+            "    coalesce(wpgc.ip_address, wdc.gb_ip_address, wdc.ip_address) as gb_ip_address,\n" +
+            "    coalesce(wpgc.port, wdc.gb_port, wdc.port) as gb_port,\n" +
+            "    coalesce(wpgc.password, wdc.gb_password, wdc.password) as gb_password,\n" +
+            "    coalesce(wpgc.status, wdc.gb_status, wdc.status) as gb_status,\n" +
+            "    coalesce(wpgc.longitude, wdc.gb_longitude, wdc.longitude) as gb_longitude,\n" +
+            "    coalesce(wpgc.latitude, wdc.gb_latitude, wdc.latitude) as gb_latitude,\n" +
+            "    coalesce(wpgc.ptz_type, wdc.gb_ptz_type, wdc.ptz_type) as gb_ptz_type,\n" +
+            "    coalesce(wpgc.position_type, wdc.gb_position_type, wdc.position_type) as gb_position_type,\n" +
+            "    coalesce(wpgc.room_type, wdc.gb_room_type, wdc.room_type) as gb_room_type,\n" +
+            "    coalesce(wpgc.use_type, wdc.gb_use_type, wdc.use_type) as gb_use_type,\n" +
+            "    coalesce(wpgc.supply_light_type, wdc.gb_supply_light_type, wdc.supply_light_type) as gb_supply_light_type,\n" +
+            "    coalesce(wpgc.direction_type, wdc.gb_direction_type, wdc.direction_type) as gb_direction_type,\n" +
+            "    coalesce(wpgc.resolution, wdc.gb_resolution, wdc.resolution) as gb_resolution,\n" +
+            "    coalesce(wpgc.business_group_id, wdc.gb_business_group_id, wdc.business_group_id) as gb_business_group_id,\n" +
+            "    coalesce(wpgc.download_speed, wdc.gb_download_speed, wdc.download_speed) as gb_download_speed,\n" +
+            "    coalesce(wpgc.svc_space_support_mod, wdc.gb_svc_space_support_mod, wdc.svc_space_support_mod) as gb_svc_space_support_mod,\n" +
+            "    coalesce(wpgc.svc_time_support_mode, wdc.gb_svc_time_support_mode, wdc.svc_time_support_mode) as gb_svc_time_support_mode\n" +
+            " from wvp_device_channel wdc" +
+            " left join wvp_platform_gb_channel wpgc on wdc.id = wpgc.device_channel_id" +
+            " where  wpgc.platform_id = #{platformId}" +
+            "<if test='channelIds != null'> AND wdc.id in " +
+            "   <foreach item='item' index='index' collection='channelIds' open='(' separator=',' close=')'>" +
+            "   #{item} " +
+            "   </foreach> " +
+            "</if>" +
+            "</script>")
+    List<CommonGBChannel> queryShare(@Param("platformId") Integer platformId, List<Integer> channelIds);
+
+    @Delete("<script> " +
+            "DELETE from wvp_platform_gb_channel WHERE platform_id=#{platformId} " +
+            "<if test='channelList != null'> AND device_channel_id in " +
+            "   <foreach item='item' index='index' collection='channelList' open='(' separator=',' close=')'>" +
+            "   #{item.gbId} " +
+            "   </foreach> " +
+            "</if>" +
+            "</script>")
+    int removeChannels(@Param("platformId") Integer platformId, List<CommonGBChannel> channelList);
+
 }

+ 11 - 17
src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlatformChannelService.java

@@ -1,6 +1,7 @@
 package com.genersoft.iot.vmp.gb28181.service;
 
-import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelReduce;
+import com.genersoft.iot.vmp.gb28181.bean.PlatformChannel;
+import com.github.pagehelper.PageInfo;
 
 import java.util.List;
 
@@ -10,20 +11,13 @@ import java.util.List;
  */
 public interface IPlatformChannelService {
 
-    /**
-     * 更新目录下的通道
-     * @param platformId 平台编号
-     * @param channelReduces 通道信息
-     * @param catalogId 目录编号
-     * @return
-     */
-    int updateChannelForGB(String platformId, List<ChannelReduce> channelReduces, String catalogId);
-
-    /**
-     * 移除目录下的所有通道
-     * @param platformId
-     * @param catalogId
-     * @return
-     */
-    int delAllChannelForGB(String platformId, String catalogId);
+    PageInfo<PlatformChannel> queryChannelList(int page, int count, String query, Boolean online, Integer platformId, Boolean hasShare);
+
+    int addAllChannel(Integer platformId);
+
+    int removeAllChannel(Integer platformId);
+
+    int addChannels(Integer platformId, List<Integer> channelIds);
+
+    int removeChannels(Integer platformId, List<Integer> channelIds);
 }

+ 5 - 1
src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java

@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.conf.exception.ControllerException;
 import com.genersoft.iot.vmp.gb28181.bean.*;
 import com.genersoft.iot.vmp.gb28181.dao.CommonGBChannelMapper;
 import com.genersoft.iot.vmp.gb28181.dao.GroupMapper;
+import com.genersoft.iot.vmp.gb28181.dao.PlatformChannelMapper;
 import com.genersoft.iot.vmp.gb28181.dao.RegionMapper;
 import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
@@ -34,6 +35,9 @@ public class GbChannelServiceImpl implements IGbChannelService {
     @Autowired
     private CommonGBChannelMapper commonGBChannelMapper;
 
+    @Autowired
+    private PlatformChannelMapper platformChannelMapper;
+
     @Autowired
     private RegionMapper regionMapper;
 
@@ -635,6 +639,6 @@ public class GbChannelServiceImpl implements IGbChannelService {
 
     @Override
     public CommonGBChannel queryOneWithPlatform(Integer platformId, String channelDeviceId) {
-        return commonGBChannelMapper.queryOneWithPlatform(platformId, channelDeviceId);
+        return platformChannelMapper.queryOneWithPlatform(platformId, channelDeviceId);
     }
 }

+ 68 - 129
src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformChannelServiceImpl.java

@@ -1,26 +1,20 @@
 package com.genersoft.iot.vmp.gb28181.service.impl;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
-import com.genersoft.iot.vmp.gb28181.bean.*;
+import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
+import com.genersoft.iot.vmp.gb28181.bean.PlatformChannel;
+import com.genersoft.iot.vmp.gb28181.dao.PlatformChannelMapper;
 import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
 import com.genersoft.iot.vmp.gb28181.service.IPlatformChannelService;
-import com.genersoft.iot.vmp.gb28181.dao.DeviceChannelMapper;
-import com.genersoft.iot.vmp.gb28181.dao.PlatformMapper;
-import com.genersoft.iot.vmp.gb28181.dao.PlatformChannelMapper;
-import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelReduce;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.datasource.DataSourceTransactionManager;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.TransactionDefinition;
-import org.springframework.transaction.TransactionStatus;
-import org.springframework.util.ObjectUtils;
+import org.springframework.util.Assert;
 
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author lin
@@ -34,136 +28,81 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
     private PlatformChannelMapper platformChannelMapper;
 
     @Autowired
-    TransactionDefinition transactionDefinition;
-
-    @Autowired
-    DataSourceTransactionManager dataSourceTransactionManager;
-
-    @Autowired
-    private SubscribeHolder subscribeHolder;
-
-
-    @Autowired
-    private DeviceChannelMapper deviceChannelMapper;
+    EventPublisher eventPublisher;
 
-    @Autowired
-    private PlatformMapper platformMapper;
 
-    @Autowired
-    EventPublisher eventPublisher;
+    @Override
+    public PageInfo<PlatformChannel> queryChannelList(int page, int count, String query, Boolean online, Integer platformId, Boolean hasShare) {
+        PageHelper.startPage(page, count);
+        List<PlatformChannel> all = platformChannelMapper.queryForPlatformSearch(platformId, query, online, hasShare);
+        return new PageInfo<>(all);
+    }
 
     @Override
-    public int updateChannelForGB(String platformId, List<ChannelReduce> channelReduces, String catalogId) {
-        Platform platform = platformMapper.getParentPlatByServerGBId(platformId);
-        if (platform == null) {
-            log.warn("更新级联通道信息时未找到平台{}的信息", platformId);
-            return 0;
-        }
-        Map<Integer, ChannelReduce> deviceAndChannels = new HashMap<>();
-        for (ChannelReduce channelReduce : channelReduces) {
-            channelReduce.setCatalogId(catalogId);
-            deviceAndChannels.put(channelReduce.getId(), channelReduce);
-        }
-        List<Integer> deviceAndChannelList = new ArrayList<>(deviceAndChannels.keySet());
-        // 查询当前已经存在的
-        List<Integer> channelIds = platformChannelMapper.findChannelRelatedPlatform(platformId, channelReduces);
-        if (deviceAndChannelList != null) {
-            deviceAndChannelList.removeAll(channelIds);
-        }
-        for (Integer channelId : channelIds) {
-            deviceAndChannels.remove(channelId);
-        }
-        List<ChannelReduce> channelReducesToAdd = new ArrayList<>(deviceAndChannels.values());
-        // 对剩下的数据进行存储
-        int allCount = 0;
-        boolean result = false;
-        TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
-        int limitCount = 50;
-        if (channelReducesToAdd.size() > 0) {
-            if (channelReducesToAdd.size() > limitCount) {
-                for (int i = 0; i < channelReducesToAdd.size(); i += limitCount) {
-                    int toIndex = i + limitCount;
-                    if (i + limitCount > channelReducesToAdd.size()) {
-                        toIndex = channelReducesToAdd.size();
-                    }
-                    int count = platformChannelMapper.addChannels(platformId, channelReducesToAdd.subList(i, toIndex));
-                    result = result || count < 0;
-                    allCount += count;
-                    log.info("[关联通道]国标通道 平台:{}, 共需关联通道数:{}, 已关联:{}", platformId, channelReducesToAdd.size(), toIndex);
-                }
-            }else {
-                allCount = platformChannelMapper.addChannels(platformId, channelReducesToAdd);
-                result = result || allCount < 0;
-                log.info("[关联通道]国标通道 平台:{}, 关联通道数:{}", platformId, channelReducesToAdd.size());
+    public int addAllChannel(Integer platformId) {
+        List<CommonGBChannel> channelListNotShare = platformChannelMapper.queryNotShare(platformId, null);
+        Assert.notEmpty(channelListNotShare, "所有通道已共享");
+        int result = platformChannelMapper.addChannels(platformId, channelListNotShare);
+        if (result > 0) {
+            // 发送消息
+            try {
+                // 发送catalog
+                eventPublisher.catalogEventPublish(platformId, channelListNotShare, CatalogEvent.ADD);
+            } catch (Exception e) {
+                log.warn("[关联全部通道] 发送失败,数量:{}", channelListNotShare.size(), e);
             }
+        }
+        return result;
+    }
 
-            if (result) {
-                //事务回滚
-                dataSourceTransactionManager.rollback(transactionStatus);
-                allCount = 0;
-            }else {
-                log.info("[关联通道]国标通道 平台:{}, 正在存入数据库", platformId);
-                dataSourceTransactionManager.commit(transactionStatus);
-
-            }
-            SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(platformId);
-            if (catalogSubscribe != null) {
-                List<CommonGBChannel> deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId, platform);
-                if (deviceChannelList != null) {
-                    eventPublisher.catalogEventPublish(platform.getId(), deviceChannelList, CatalogEvent.ADD);
-                }
+    @Override
+    public int addChannels(Integer platformId, List<Integer> channelIds) {
+        List<CommonGBChannel> channelListNotShare = platformChannelMapper.queryNotShare(platformId, channelIds);
+        Assert.notEmpty(channelListNotShare, "通道已共享");
+        int result = platformChannelMapper.addChannels(platformId, channelListNotShare);
+        if (result > 0) {
+            // 发送消息
+            try {
+                // 发送catalog
+                eventPublisher.catalogEventPublish(platformId, channelListNotShare, CatalogEvent.ADD);
+            } catch (Exception e) {
+                log.warn("[关联通道] 发送失败,数量:{}", channelListNotShare.size(), e);
             }
-            log.info("[关联通道]国标通道 平台:{}, 存入数据库成功", platformId);
         }
-        return allCount;
+        return result;
     }
 
-    private List<CommonGBChannel> getDeviceChannelListByChannelReduceList(List<ChannelReduce> channelReduces, String catalogId, Platform platform) {
-        List<CommonGBChannel> deviceChannelList = new ArrayList<>();
-//        if (!channelReduces.isEmpty()){
-//            PlatformCatalog catalog = catalogManager.selectByPlatFormAndCatalogId(platform.getServerGBId(),catalogId);
-//            if (catalog == null && catalogId.equals(platform.getDeviceGBId())) {
-//                for (ChannelReduce channelReduce : channelReduces) {
-//                    DeviceChannel deviceChannel = deviceChannelMapper.getOne(channelReduce.getId());
-//                    deviceChannel.setParental(0);
-//                    deviceChannel.setCivilCode(platform.getServerGBDomain());
-//                    deviceChannelList.add(deviceChannel);
-//                }
-//                return deviceChannelList;
-//            } else if (catalog == null && !catalogId.equals(platform.getDeviceGBId())) {
-//                log.warn("未查询到目录{}的信息", catalogId);
-//                return null;
-//            }
-//            for (ChannelReduce channelReduce : channelReduces) {
-//                DeviceChannel deviceChannel = deviceChannelMapper.getOne(channelReduce.getId());
-//                deviceChannel.setParental(0);
-//                deviceChannel.setCivilCode(catalog.getCivilCode());
-//                deviceChannel.setParentId(catalog.getParentId());
-//                deviceChannel.setBusinessGroupId(catalog.getBusinessGroupId());
-//                deviceChannelList.add(deviceChannel);
-//            }
-//        }
-        return deviceChannelList;
+    @Override
+    public int removeAllChannel(Integer platformId) {
+        List<CommonGBChannel> channelListNotShare = platformChannelMapper.queryNotShare(platformId,  null);
+        Assert.notEmpty(channelListNotShare, "未共享任何通道");
+        int result = platformChannelMapper.removeChannels(platformId, channelListNotShare);
+        if (result > 0) {
+            // 发送消息
+            try {
+                // 发送catalog
+                eventPublisher.catalogEventPublish(platformId, channelListNotShare, CatalogEvent.DEL);
+            } catch (Exception e) {
+                log.warn("[移除全部关联通道] 发送失败,数量:{}", channelListNotShare.size(), e);
+            }
+        }
+        return result;
     }
 
     @Override
-    public int delAllChannelForGB(String platformId, String catalogId) {
-
-        int result;
-        if (platformId == null) {
-            return 0;
-        }
-        Platform platform = platformMapper.getParentPlatByServerGBId(platformId);
-        if (platform == null) {
-            return 0;
-        }
-        if (ObjectUtils.isEmpty(catalogId)) {
-           catalogId = null;
+    public int removeChannels(Integer platformId, List<Integer> channelIds) {
+        List<CommonGBChannel> channelList = platformChannelMapper.queryShare(platformId, channelIds);
+        Assert.notEmpty(channelList, "所选通道未共享");
+        int result = platformChannelMapper.removeChannels(platformId, channelList);
+        if (result > 0) {
+            // 发送消息
+            try {
+                // 发送catalog
+                eventPublisher.catalogEventPublish(platformId, channelList, CatalogEvent.DEL);
+            } catch (Exception e) {
+                log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e);
+            }
         }
-
-        List<CommonGBChannel> deviceChannels = platformChannelMapper.queryAllChannelInCatalog(platformId, catalogId);
-        eventPublisher.catalogEventPublish(platform.getId(), deviceChannels, CatalogEvent.DEL);
-
-        return platformChannelMapper.delChannelForGBByCatalogId(platformId, catalogId);
+        return result;
     }
 }

+ 1 - 1
web_src/src/components/PlatformList.vue

@@ -153,7 +153,7 @@ export default {
         });
     },
     chooseChannel: function(platform) {
-      this.$refs.shareChannel.openDialog(platform.serverGBId, this.initData)
+      this.$refs.shareChannel.openDialog(platform.id, this.initData)
     },
     initData: function() {
       this.$axios({

+ 75 - 3
web_src/src/components/dialog/shareChannelAdd.vue

@@ -27,7 +27,9 @@
           <el-button v-if="hasShare ==='true'" size="mini" type="danger" @click="remove()">
             移除
           </el-button>
-          <el-button icon="el-icon-refresh-right" circle size="mini" @click="getChannelList()"></el-button>
+          <el-button size="mini" @click="addAll()">全部添加</el-button>
+          <el-button size="mini" @click="removeAll()">全部移除</el-button>
+          <el-button size="mini" @click="getChannelList()">刷新</el-button>
         </div>
       </div>
     </div>
@@ -86,6 +88,7 @@
 export default {
   name: 'shareChannelAdd',
   components: {},
+  props: [ 'platformId'],
   data() {
     return {
       channelList: [],
@@ -190,6 +193,42 @@ export default {
         this.$message.error(error)
         this.loading = false
       });
+    },
+    addAll: function (row) {
+      this.$confirm("确定全部添加?", '提示', {
+        dangerouslyUseHTMLString: true,
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        this.loading = true
+
+        this.$axios({
+          method: 'post',
+          url: `/api/platform/channel/add`,
+          data: {
+            platformId: this.platformId,
+            all: true
+          }
+        }).then((res)=> {
+          if (res.data.code === 0) {
+            this.$message.success("保存成功")
+            this.getChannelList()
+          }else {
+            this.$message.error(res.data.msg)
+          }
+          this.loading = false
+        }).catch((error)=> {
+          this.$message.error(error)
+          this.loading = false
+        });
+      }).catch(() => {
+      });
+
+
+
+
+
     },
     remove: function (row) {
       let channels = []
@@ -203,9 +242,10 @@ export default {
       this.loading = true
 
       this.$axios({
-        method: 'post',
-        url: `/api/platform/channel/delete`,
+        method: 'delete',
+        url: `/api/platform/channel/remove`,
         data: {
+          platformId: this.platformId,
           channelIds: channels
         }
       }).then((res)=> {
@@ -221,6 +261,38 @@ export default {
         this.loading = false
       });
     },
+    removeAll: function (row) {
+
+      this.$confirm("确定全部移除?", '提示', {
+        dangerouslyUseHTMLString: true,
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        this.loading = true
+        this.$axios({
+          method: 'delete',
+          url: `/api/platform/channel/remove`,
+          data: {
+            platformId: this.platformId,
+            all: true
+          }
+        }).then((res)=> {
+          if (res.data.code === 0) {
+            this.$message.success("保存成功")
+            this.getChannelList()
+          }else {
+            this.$message.error(res.data.msg)
+          }
+          this.loading = false
+        }).catch((error)=> {
+          this.$message.error(error)
+          this.loading = false
+        });
+      }).catch(() => {
+      });
+
+    },
     search: function () {
       this.currentPage = 1;
       this.total = 0;