diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PlatformChannel.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PlatformChannel.java new file mode 100644 index 00000000..7b6dc0da --- /dev/null +++ b/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; +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlatformController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlatformController.java index 2bf5ed68..8a73a2ff 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlatformController.java +++ b/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 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 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 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(), "写入数据库失败"); -// } - } - - } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/bean/UpdateChannelParam.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/bean/UpdateChannelParam.java index 4bd50a91..30c7c0ca 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/bean/UpdateChannelParam.java +++ b/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 channelReduces; - - public String getPlatformId() { - return platformId; - } - - public void setPlatformId(String platformId) { - this.platformId = platformId; - } - - public List getChannelReduces() { - return channelReduces; - } - - public void setChannelReduces(List 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 channelIds; } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/CommonGBChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/CommonGBChannelMapper.java index f487bb70..1db92e19 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/CommonGBChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/CommonGBChannelMapper.java @@ -223,55 +223,6 @@ public interface CommonGBChannelMapper { "") int updateStatus(List 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 queryByPlatformId(@Param("platformId") Integer platformId); - - @Update(value = {" ") - int addChannels(@Param("platformId") String platformId, @Param("channelReducesToAdd") List channelReducesToAdd); + int addChannels(@Param("platformId") Integer platformId, @Param("channelList") List channelList); @Delete("") + List 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("") + List queryNotShare(@Param("platformId") Integer platformId, List channelIds); + + @Select("") + List queryShare(@Param("platformId") Integer platformId, List channelIds); + + @Delete("") + int removeChannels(@Param("platformId") Integer platformId, List channelList); + } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlatformChannelService.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlatformChannelService.java index a1aa502e..b50dbda2 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlatformChannelService.java +++ b/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 channelReduces, String catalogId); + PageInfo queryChannelList(int page, int count, String query, Boolean online, Integer platformId, Boolean hasShare); - /** - * 移除目录下的所有通道 - * @param platformId - * @param catalogId - * @return - */ - int delAllChannelForGB(String platformId, String catalogId); + int addAllChannel(Integer platformId); + + int removeAllChannel(Integer platformId); + + int addChannels(Integer platformId, List channelIds); + + int removeChannels(Integer platformId, List channelIds); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java index 8fcefeea..0a509763 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java +++ b/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); } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformChannelServiceImpl.java index 61b2d75a..b98389c6 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformChannelServiceImpl.java +++ b/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 @@ -33,137 +27,82 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { @Autowired private PlatformChannelMapper platformChannelMapper; - @Autowired - TransactionDefinition transactionDefinition; - - @Autowired - DataSourceTransactionManager dataSourceTransactionManager; - - @Autowired - private SubscribeHolder subscribeHolder; - - - @Autowired - private DeviceChannelMapper deviceChannelMapper; - - @Autowired - private PlatformMapper platformMapper; - @Autowired EventPublisher eventPublisher; + @Override - public int updateChannelForGB(String platformId, List channelReduces, String catalogId) { - Platform platform = platformMapper.getParentPlatByServerGBId(platformId); - if (platform == null) { - log.warn("更新级联通道信息时未找到平台{}的信息", platformId); - return 0; - } - Map deviceAndChannels = new HashMap<>(); - for (ChannelReduce channelReduce : channelReduces) { - channelReduce.setCatalogId(catalogId); - deviceAndChannels.put(channelReduce.getId(), channelReduce); - } - List deviceAndChannelList = new ArrayList<>(deviceAndChannels.keySet()); - // 查询当前已经存在的 - List channelIds = platformChannelMapper.findChannelRelatedPlatform(platformId, channelReduces); - if (deviceAndChannelList != null) { - deviceAndChannelList.removeAll(channelIds); - } - for (Integer channelId : channelIds) { - deviceAndChannels.remove(channelId); - } - List 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()); - } - - if (result) { - //事务回滚 - dataSourceTransactionManager.rollback(transactionStatus); - allCount = 0; - }else { - log.info("[关联通道]国标通道 平台:{}, 正在存入数据库", platformId); - dataSourceTransactionManager.commit(transactionStatus); - - } - SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(platformId); - if (catalogSubscribe != null) { - List deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId, platform); - if (deviceChannelList != null) { - eventPublisher.catalogEventPublish(platform.getId(), deviceChannelList, CatalogEvent.ADD); - } - } - log.info("[关联通道]国标通道 平台:{}, 存入数据库成功", platformId); - } - return allCount; - } - - private List getDeviceChannelListByChannelReduceList(List channelReduces, String catalogId, Platform platform) { - List 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; + public PageInfo queryChannelList(int page, int count, String query, Boolean online, Integer platformId, Boolean hasShare) { + PageHelper.startPage(page, count); + List all = platformChannelMapper.queryForPlatformSearch(platformId, query, online, hasShare); + return new PageInfo<>(all); } @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 addAllChannel(Integer platformId) { + List 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; + } - List deviceChannels = platformChannelMapper.queryAllChannelInCatalog(platformId, catalogId); - eventPublisher.catalogEventPublish(platform.getId(), deviceChannels, CatalogEvent.DEL); + @Override + public int addChannels(Integer platformId, List channelIds) { + List 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); + } + } + return result; + } - return platformChannelMapper.delChannelForGBByCatalogId(platformId, catalogId); + @Override + public int removeAllChannel(Integer platformId) { + List 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 removeChannels(Integer platformId, List channelIds) { + List 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); + } + } + return result; } } diff --git a/web_src/src/components/PlatformList.vue b/web_src/src/components/PlatformList.vue index f60abe9b..a2ff6b54 100755 --- a/web_src/src/components/PlatformList.vue +++ b/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({ diff --git a/web_src/src/components/dialog/shareChannelAdd.vue b/web_src/src/components/dialog/shareChannelAdd.vue index 1425d4a8..725abefa 100755 --- a/web_src/src/components/dialog/shareChannelAdd.vue +++ b/web_src/src/components/dialog/shareChannelAdd.vue @@ -27,7 +27,9 @@ 移除 - + 全部添加 + 全部移除 + 刷新 @@ -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;