临时提交
This commit is contained in:
@@ -218,7 +218,6 @@ public class CommonGBChannel {
|
||||
private String updateTime;
|
||||
|
||||
|
||||
|
||||
public String encode(){
|
||||
return encode(null);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "国标通道关联分组表ID")
|
||||
public class CommonGBChannelWitchGroupChannelId extends CommonGBChannel {
|
||||
|
||||
private int groupChannelId;
|
||||
|
||||
}
|
||||
48
src/main/java/com/genersoft/iot/vmp/gb28181/bean/GbCode.java
Normal file
48
src/main/java/com/genersoft/iot/vmp/gb28181/bean/GbCode.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 国标编码对象
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "国标编码对象")
|
||||
public class GbCode {
|
||||
|
||||
@Schema(description = "中心编码,由监控中心所在地的行政区划代码确定,符合GB/T2260—2007的要求")
|
||||
private String civilCode;
|
||||
|
||||
@Schema(description = "行业编码")
|
||||
private String industryCode;
|
||||
|
||||
@Schema(description = "类型编码")
|
||||
private String typeCode;
|
||||
|
||||
@Schema(description = "网络标识")
|
||||
private String netCode;
|
||||
|
||||
@Schema(description = "序号")
|
||||
private String sn;
|
||||
|
||||
/**
|
||||
* 解析国标编号
|
||||
*/
|
||||
public static GbCode decode(String code){
|
||||
if (code == null || code.trim().length() != 20) {
|
||||
return null;
|
||||
}
|
||||
code = code.trim();
|
||||
GbCode gbCode = new GbCode();
|
||||
gbCode.setCivilCode(code.substring(0, 8));
|
||||
gbCode.setIndustryCode(code.substring(9, 10));
|
||||
gbCode.setTypeCode(code.substring(11, 13));
|
||||
gbCode.setNetCode(code.substring(14, 15));
|
||||
gbCode.setSn(code.substring(15, 20));
|
||||
return gbCode;
|
||||
}
|
||||
|
||||
public String ecode(){
|
||||
return civilCode + industryCode + typeCode + netCode + sn;
|
||||
}
|
||||
}
|
||||
59
src/main/java/com/genersoft/iot/vmp/gb28181/bean/Group.java
Normal file
59
src/main/java/com/genersoft/iot/vmp/gb28181/bean/Group.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* 业务分组
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "业务分组")
|
||||
public class Group implements Comparable<Group>{
|
||||
/**
|
||||
* 数据库自增ID
|
||||
*/
|
||||
@Schema(description = "数据库自增ID")
|
||||
private int id;
|
||||
|
||||
/**
|
||||
* 区域国标编号
|
||||
*/
|
||||
@Schema(description = "区域国标编号")
|
||||
private String deviceId;
|
||||
|
||||
/**
|
||||
* 区域名称
|
||||
*/
|
||||
@Schema(description = "区域名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 父区域国标ID
|
||||
*/
|
||||
@Schema(description = "父区域国标ID")
|
||||
private String parentDeviceId;
|
||||
|
||||
/**
|
||||
* 所属的业务分组国标编号
|
||||
*/
|
||||
@Schema(description = "所属的业务分组国标编号")
|
||||
private String businessGroup;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Schema(description = "更新时间")
|
||||
private String updateTime;
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull Group region) {
|
||||
return Integer.compare(Integer.parseInt(this.deviceId), Integer.parseInt(region.getDeviceId()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 业务分组
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "业务分组树")
|
||||
public class GroupTree {
|
||||
|
||||
/**
|
||||
* 数据库Id
|
||||
*/
|
||||
@Schema(description = "数据库Id")
|
||||
private int dbId;
|
||||
|
||||
/**
|
||||
* 区域国标编号
|
||||
*/
|
||||
@Schema(description = "区域国标编号")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 区域名称
|
||||
*/
|
||||
@Schema(description = "区域名称")
|
||||
private String label;
|
||||
|
||||
/**
|
||||
* 父区域国标ID
|
||||
*/
|
||||
@Schema(description = "父区域国标ID")
|
||||
private String parentDeviceId;
|
||||
|
||||
@Schema(description = "是否有子节点")
|
||||
private boolean isLeaf;
|
||||
|
||||
@Schema(description = "类型, 行政区划:0 摄像头: 1")
|
||||
private int type;
|
||||
|
||||
|
||||
|
||||
public static GroupTree getInstance(Region region) {
|
||||
GroupTree regionTree = new GroupTree();
|
||||
regionTree.setId(region.getDeviceId());
|
||||
regionTree.setLabel(region.getName());
|
||||
regionTree.setParentDeviceId(region.getParentDeviceId());
|
||||
regionTree.setType(0);
|
||||
if (region.getDeviceId().length() < 8) {
|
||||
regionTree.setLeaf(false);
|
||||
}else {
|
||||
regionTree.setLeaf(true);
|
||||
}
|
||||
return regionTree;
|
||||
}
|
||||
|
||||
public static GroupTree getInstance(CommonGBChannel channel) {
|
||||
GroupTree regionTree = new GroupTree();
|
||||
regionTree.setId(channel.getGbDeviceId());
|
||||
regionTree.setLabel(channel.getGbName());
|
||||
regionTree.setParentDeviceId(channel.getGbCivilCode());
|
||||
regionTree.setType(1);
|
||||
regionTree.setLeaf(true);
|
||||
return regionTree;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.genersoft.iot.vmp.gb28181.controller;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Group;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GroupTree;
|
||||
import com.genersoft.iot.vmp.gb28181.service.IGroupService;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "分组管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/group")
|
||||
public class GroupController {
|
||||
|
||||
@Autowired
|
||||
private IGroupService groupService;
|
||||
|
||||
@Operation(summary = "添加区域")
|
||||
@Parameter(name = "group", description = "group", required = true)
|
||||
@ResponseBody
|
||||
@PostMapping("/add")
|
||||
public void add(@RequestBody Group group){
|
||||
groupService.add(group);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询区域")
|
||||
@Parameter(name = "query", description = "要搜索的内容", required = true)
|
||||
@Parameter(name = "parent", description = "所属分组编号", required = true)
|
||||
@ResponseBody
|
||||
@GetMapping("/tree/list")
|
||||
public List<GroupTree> queryForTree(
|
||||
@RequestParam(required = false) String query,
|
||||
@RequestParam(required = false) String parent
|
||||
){
|
||||
if (ObjectUtils.isEmpty(parent)) {
|
||||
parent = null;
|
||||
}
|
||||
if (ObjectUtils.isEmpty(query)) {
|
||||
query = null;
|
||||
}
|
||||
return groupService.queryForTree(query, parent);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新区域")
|
||||
@Parameter(name = "group", description = "Group", required = true)
|
||||
@ResponseBody
|
||||
@PostMapping("/update")
|
||||
public void update(@RequestBody Group group){
|
||||
groupService.update(group);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除区域")
|
||||
@Parameter(name = "deviceId", description = "区域编码", required = true)
|
||||
@ResponseBody
|
||||
@DeleteMapping("/delete")
|
||||
public void delete(String deviceId){
|
||||
Assert.hasLength(deviceId, "区域编码(deviceId)不需要存在");
|
||||
boolean result = groupService.deleteByDeviceId(deviceId);
|
||||
if (!result) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "移除失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "根据区域Id查询区域")
|
||||
@Parameter(name = "groupDeviceId", description = "分组节点编号", required = true)
|
||||
@ResponseBody
|
||||
@GetMapping("/one")
|
||||
public Group queryGroupByDeviceId(
|
||||
@RequestParam(required = true) String deviceId
|
||||
){
|
||||
Assert.hasLength(deviceId, "");
|
||||
return groupService.queryGroupByDeviceId(deviceId);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所属的分组下的分组")
|
||||
@Parameter(name = "parent", description = "所属的分组", required = false)
|
||||
@ResponseBody
|
||||
@GetMapping("/base/child/list")
|
||||
public List<Group> getAllChild(@RequestParam(required = false) String parent){
|
||||
if (ObjectUtils.isEmpty(parent)) {
|
||||
parent = null;
|
||||
}
|
||||
return groupService.getAllChild(parent);
|
||||
}
|
||||
|
||||
@Operation(summary = "从通道中同步分组")
|
||||
@ResponseBody
|
||||
@GetMapping("/sync")
|
||||
public void sync(){
|
||||
groupService.syncFromChannel();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.genersoft.iot.vmp.gb28181.dao;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Region;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.RegionTree;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.dao.provider.ChannelProvider;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
@@ -356,4 +354,14 @@ public interface CommonGBChannelMapper {
|
||||
|
||||
@SelectProvider(type = ChannelProvider.class, method = "queryByGbDeviceIds")
|
||||
List<CommonGBChannel> queryByGbDeviceIds(List<Integer> deviceIds);
|
||||
|
||||
@SelectProvider(type = ChannelProvider.class, method = "queryByGroupList")
|
||||
List<CommonGBChannelWitchGroupChannelId> queryByGroupList(List<Group> groupList);
|
||||
|
||||
@Delete(value = {" <script>" +
|
||||
" delete from wvp_common_group_channel" +
|
||||
" where id in " +
|
||||
" <foreach collection='channels' item='item' open='(' separator=',' close=')' > #{item.groupChannelId}</foreach>" +
|
||||
"</script>"})
|
||||
int batchDeleteGroup(List<CommonGBChannelWitchGroupChannelId> channels);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.genersoft.iot.vmp.gb28181.dao;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Group;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Group;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GroupTree;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Mapper
|
||||
public interface GroupMapper {
|
||||
|
||||
@Insert("INSERT INTO wvp_common_group (device_id, name, parent_device_id, business_group, create_time, update_time) " +
|
||||
"VALUES (#{deviceId}, #{name}, #{parentDeviceId}, #{businessGroup}, #{createTime}, #{updateTime})")
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
|
||||
void add(Group group);
|
||||
|
||||
@Delete("DELETE FROM wvp_common_group WHERE id=#{id}")
|
||||
int delete(@Param("id") int id);
|
||||
|
||||
@Update(" UPDATE wvp_common_group " +
|
||||
" SET update_time=#{updateTime}, device_id=#{deviceId}, name=#{name}, parent_device_id=#{parentDeviceId}, business_group=#{businessGroup}" +
|
||||
" WHERE id = #{id}")
|
||||
int update(Group group);
|
||||
|
||||
@Select(value = {" <script>" +
|
||||
"SELECT * from wvp_common_group WHERE 1=1 " +
|
||||
" <if test='query != null'> AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))</if> " +
|
||||
" <if test='parentId != null and businessGroupId != null '> AND parent_device_id = #{parentId} AND business_group=#{businessGroup} </if> " +
|
||||
"ORDER BY id " +
|
||||
" </script>"})
|
||||
List<Group> query(@Param("query") String query, @Param("parentId") String parentId, @Param("businessGroup") String businessGroup);
|
||||
|
||||
@Select("SELECT * from wvp_common_group WHERE parent_device_id = #{parentId} AND business_group=#{businessGroup} ORDER BY id ")
|
||||
List<Group> getChildren(@Param("parentId") String parentId , @Param("businessGroup") String businessGroup);
|
||||
|
||||
@Select("SELECT * from wvp_common_group WHERE id = #{id} ")
|
||||
Group queryOne(@Param("id") int id);
|
||||
|
||||
@Select(" select coalesce(dc.gb_civil_code, dc.civil_code) as civil_code " +
|
||||
" from wvp_device_channel dc " +
|
||||
" where coalesce(dc.gb_civil_code, dc.civil_code) not in " +
|
||||
" (select device_id from wvp_common_group)")
|
||||
List<String> getUninitializedCivilCode();
|
||||
|
||||
@Select(" <script>" +
|
||||
" SELECT device_id from wvp_common_group " +
|
||||
" where device_id in " +
|
||||
" <foreach collection='codes' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
|
||||
" </script>")
|
||||
List<String> queryInList(Set<String> codes);
|
||||
|
||||
|
||||
@Insert(" <script>" +
|
||||
" INSERT INTO wvp_common_group (" +
|
||||
" device_id," +
|
||||
" name, " +
|
||||
" parent_device_id," +
|
||||
" create_time," +
|
||||
" update_time) " +
|
||||
" VALUES " +
|
||||
" <foreach collection='groupList' index='index' item='item' separator=','> " +
|
||||
" (#{item.deviceId}, #{item.name}, #{item.parentDeviceId},#{item.createTime},#{item.updateTime})" +
|
||||
" </foreach> " +
|
||||
" </script>")
|
||||
int batchAdd(List<Group> groupList);
|
||||
|
||||
@Select(" <script>" +
|
||||
" SELECT " +
|
||||
" device_id as id," +
|
||||
" name as label, " +
|
||||
" parent_device_id," +
|
||||
" id as db_id," +
|
||||
" 0 as type," +
|
||||
" false as is_leaf" +
|
||||
" from wvp_common_group " +
|
||||
" where " +
|
||||
" <if test='parentId != null'> parent_device_id = #{parentId} </if> " +
|
||||
" <if test='parentId == null'> parent_device_id is null </if> " +
|
||||
" <if test='query != null'> AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))</if> " +
|
||||
" </script>")
|
||||
List<GroupTree> queryForTree(@Param("query") String query, @Param("parentId") String parentId);
|
||||
|
||||
@Select("SELECT * from wvp_common_group WHERE device_id = #{deviceId} and business_group = #{businessGroup}")
|
||||
Group queryOneByDeviceId(@Param("deviceId") String deviceId, @Param("businessGroup") String businessGroup);
|
||||
|
||||
@Delete("<script>" +
|
||||
" DELETE FROM wvp_common_group WHERE id in " +
|
||||
" <foreach collection='allChildren' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
|
||||
" </script>")
|
||||
void batchDelete(List<Group> allChildren);
|
||||
|
||||
@Select("SELECT * from wvp_common_group WHERE device_id = #{businessGroup} and business_group = #{businessGroup} ")
|
||||
Group queryBusinessGroup(@Param("businessGroup") String businessGroup);
|
||||
|
||||
@Select("SELECT * from wvp_common_group WHERE business_group = #{businessGroup} ")
|
||||
List<Group> queryByBusinessGroup(@Param("businessGroup") String businessGroup);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.genersoft.iot.vmp.gb28181.dao.provider;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Group;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -10,65 +11,68 @@ public class ChannelProvider {
|
||||
|
||||
public String getBaseSelectSql(){
|
||||
return "select\n" +
|
||||
" id as gb_id,\n" +
|
||||
" device_db_id as gb_device_db_id,\n" +
|
||||
" stream_push_id,\n" +
|
||||
" stream_proxy_id,\n" +
|
||||
" create_time,\n" +
|
||||
" update_time,\n" +
|
||||
" coalesce(gb_device_id, device_id) as gb_device_id,\n" +
|
||||
" coalesce(gb_name, name) as gb_name,\n" +
|
||||
" coalesce(gb_manufacturer, manufacturer) as gb_manufacturer,\n" +
|
||||
" coalesce(gb_model, model) as gb_model,\n" +
|
||||
" coalesce(gb_owner, owner) as gb_owner,\n" +
|
||||
" wdc.id as gb_id,\n" +
|
||||
" wdc.device_db_id as gb_device_db_id,\n" +
|
||||
" wcg.id as group_channel_id,\n" +
|
||||
" wdc.stream_push_id,\n" +
|
||||
" wdc.stream_proxy_id,\n" +
|
||||
" wdc.create_time,\n" +
|
||||
" wdc.update_time,\n" +
|
||||
" coalesce(wdc.gb_device_id, wdc.device_id) as gb_device_id,\n" +
|
||||
" coalesce(wdc.gb_name, wdc.name) as gb_name,\n" +
|
||||
" coalesce(wdc.gb_manufacturer, 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" +
|
||||
" gb_civil_code,\n" +
|
||||
" coalesce(gb_block, block) as gb_block,\n" +
|
||||
" coalesce(gb_address, address) as gb_address,\n" +
|
||||
" coalesce(gb_parental, parental) as gb_parental,\n" +
|
||||
" coalesce(gb_parent_id, parent_id) as gb_parent_id,\n" +
|
||||
" coalesce(gb_safety_way, safety_way) as gb_safety_way,\n" +
|
||||
" coalesce(gb_register_way, register_way) as gb_register_way,\n" +
|
||||
" coalesce(gb_cert_num, cert_num) as gb_cert_num,\n" +
|
||||
" coalesce(gb_certifiable, certifiable) as gb_certifiable,\n" +
|
||||
" coalesce(gb_err_code, err_code) as gb_err_code,\n" +
|
||||
" coalesce(gb_end_time, end_time) as gb_end_time,\n" +
|
||||
" coalesce(gb_secrecy, secrecy) as gb_secrecy,\n" +
|
||||
" coalesce(gb_ip_address, ip_address) as gb_ip_address,\n" +
|
||||
" coalesce(gb_port, port) as gb_port,\n" +
|
||||
" coalesce(gb_password, password) as gb_password,\n" +
|
||||
" coalesce(gb_status, status) as gb_status,\n" +
|
||||
" coalesce(gb_longitude, longitude) as gb_longitude,\n" +
|
||||
" coalesce(gb_latitude, latitude) as gb_latitude,\n" +
|
||||
" coalesce(gb_ptz_type, ptz_type) as gb_ptz_type,\n" +
|
||||
" coalesce(gb_position_type, position_type) as gb_position_type,\n" +
|
||||
" coalesce(gb_room_type, room_type) as gb_room_type,\n" +
|
||||
" coalesce(gb_use_type, use_type) as gb_use_type,\n" +
|
||||
" coalesce(gb_supply_light_type, supply_light_type) as gb_supply_light_type,\n" +
|
||||
" coalesce(gb_direction_type, direction_type) as gb_direction_type,\n" +
|
||||
" coalesce(gb_resolution, resolution) as gb_resolution,\n" +
|
||||
" coalesce(gb_business_group_id, business_group_id) as gb_business_group_id,\n" +
|
||||
" coalesce(gb_download_speed, download_speed) as gb_download_speed,\n" +
|
||||
" coalesce(gb_svc_space_support_mod, svc_space_support_mod) as gb_svc_space_support_mod,\n" +
|
||||
" coalesce(gb_svc_time_support_mode,svc_time_support_mode) as gb_svc_time_support_mode\n" +
|
||||
" from wvp_device_channel\n"
|
||||
" coalesce(wdc.gb_block, wdc.block) as gb_block,\n" +
|
||||
" coalesce(wdc.gb_address, wdc.address) as gb_address,\n" +
|
||||
" coalesce(wdc.gb_parental, wdc.parental) as gb_parental,\n" +
|
||||
" wcg.device_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, port) wdc.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" +
|
||||
" wcg.business_group 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\n" +
|
||||
" left jon wvp_common_group_channel wcgc on wcgc.channel_id = wdc.id\n" +
|
||||
" left jon wvp_common_group wcg on wcgc.group_id = wcg.id\n"
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
public String queryByDeviceId(Map<String, Object> params ){
|
||||
return getBaseSelectSql() + " where gb_device_id = #{gbDeviceId} or device_id = #{gbDeviceId}";
|
||||
return getBaseSelectSql() + " where wdc.gb_device_id = #{gbDeviceId} or wdc.device_id = #{gbDeviceId}";
|
||||
}
|
||||
|
||||
public String queryById(Map<String, Object> params ){
|
||||
return getBaseSelectSql() + " where id = #{gbId}";
|
||||
return getBaseSelectSql() + " where wdc.id = #{gbId}";
|
||||
}
|
||||
|
||||
public String queryByStreamPushId(Map<String, Object> params ){
|
||||
return getBaseSelectSql() + " where stream_push_id = #{streamPushId}";
|
||||
return getBaseSelectSql() + " where wdc.stream_push_id = #{streamPushId}";
|
||||
}
|
||||
|
||||
public String queryByStreamProxyId(Map<String, Object> params ){
|
||||
return getBaseSelectSql() + " where stream_proxy_id = #{streamProxyId}";
|
||||
return getBaseSelectSql() + " where wdc.stream_proxy_id = #{streamProxyId}";
|
||||
}
|
||||
|
||||
|
||||
@@ -77,21 +81,21 @@ public class ChannelProvider {
|
||||
sqlBuild.append(getBaseSelectSql());
|
||||
sqlBuild.append(" where 1 = 1 ");
|
||||
if (params.get("query") != null) {
|
||||
sqlBuild.append(" AND (coalesce(gb_device_id, device_id) LIKE concat('%',#{query},'%')" +
|
||||
" OR coalesce(gb_name, name) LIKE concat('%',#{query},'%') )")
|
||||
sqlBuild.append(" AND (coalesce(wdc.gb_device_id, device_id) LIKE concat('%',#{query},'%')" +
|
||||
" OR coalesce(wdc.gb_name, name) LIKE concat('%',#{query},'%') )")
|
||||
;
|
||||
}
|
||||
if (params.get("online") != null && (Boolean)params.get("online")) {
|
||||
sqlBuild.append(" AND coalesce(gb_status, status) = 'ON'");
|
||||
sqlBuild.append(" AND coalesce(wdc.gb_status, status) = 'ON'");
|
||||
}
|
||||
if (params.get("online") != null && !(Boolean)params.get("online")) {
|
||||
sqlBuild.append(" AND coalesce(gb_status, status) = 'OFF'");
|
||||
sqlBuild.append(" AND coalesce(wdc.gb_status, status) = 'OFF'");
|
||||
}
|
||||
if (params.get("hasCivilCode") != null && (Boolean)params.get("hasCivilCode")) {
|
||||
sqlBuild.append(" AND gb_civil_code is not null");
|
||||
sqlBuild.append(" AND wdc.gb_civil_code is not null");
|
||||
}
|
||||
if (params.get("hasCivilCode") != null && !(Boolean)params.get("hasCivilCode")) {
|
||||
sqlBuild.append(" AND gb_civil_code is null");
|
||||
sqlBuild.append(" AND wdc.gb_civil_code is null");
|
||||
}
|
||||
return sqlBuild.toString();
|
||||
}
|
||||
@@ -99,7 +103,7 @@ public class ChannelProvider {
|
||||
public String queryInListByStatus(Map<String, Object> params ){
|
||||
StringBuilder sqlBuild = new StringBuilder();
|
||||
sqlBuild.append(getBaseSelectSql());
|
||||
sqlBuild.append("where gb_status=#{status} and id in ( ");
|
||||
sqlBuild.append("where wdc.gb_status=#{status} and wdc.id in ( ");
|
||||
|
||||
List<CommonGBChannel> commonGBChannelList = (List<CommonGBChannel>)params.get("ids");
|
||||
boolean first = true;
|
||||
@@ -117,7 +121,7 @@ public class ChannelProvider {
|
||||
public String queryByIds(Map<String, Object> params ){
|
||||
StringBuilder sqlBuild = new StringBuilder();
|
||||
sqlBuild.append(getBaseSelectSql());
|
||||
sqlBuild.append("where id in ( ");
|
||||
sqlBuild.append("where wdc.id in ( ");
|
||||
|
||||
Collection<Integer> ids = (Collection<Integer>)params.get("ids");
|
||||
boolean first = true;
|
||||
@@ -135,7 +139,7 @@ public class ChannelProvider {
|
||||
public String queryByGbDeviceIds(Map<String, Object> params ){
|
||||
StringBuilder sqlBuild = new StringBuilder();
|
||||
sqlBuild.append(getBaseSelectSql());
|
||||
sqlBuild.append("where device_db_id in ( ");
|
||||
sqlBuild.append("where wdc.device_db_id in ( ");
|
||||
|
||||
Collection<Integer> ids = (Collection<Integer>)params.get("deviceIds");
|
||||
boolean first = true;
|
||||
@@ -155,13 +159,13 @@ public class ChannelProvider {
|
||||
sqlBuild.append(getBaseSelectSql());
|
||||
sqlBuild.append("where ");
|
||||
if (params.get("civilCode") != null) {
|
||||
sqlBuild.append(" gb_civil_code = #{civilCode} ");
|
||||
sqlBuild.append(" wdc.gb_civil_code = #{civilCode} ");
|
||||
if (params.get("ids") != null) {
|
||||
sqlBuild.append(" OR ");
|
||||
}
|
||||
}
|
||||
if (params.get("ids") != null) {
|
||||
sqlBuild.append(" id in ( ");
|
||||
sqlBuild.append(" wdc.id in ( ");
|
||||
Collection<Integer> ids = (Collection<Integer>)params.get("ids");
|
||||
boolean first = true;
|
||||
for (Integer id : ids) {
|
||||
@@ -179,7 +183,26 @@ public class ChannelProvider {
|
||||
public String queryByCivilCode(Map<String, Object> params ){
|
||||
StringBuilder sqlBuild = new StringBuilder();
|
||||
sqlBuild.append(getBaseSelectSql());
|
||||
sqlBuild.append("where gb_civil_code = #{civilCode} ");
|
||||
sqlBuild.append("where wdc.gb_civil_code = #{civilCode} ");
|
||||
return sqlBuild.toString() ;
|
||||
}
|
||||
|
||||
public String queryByGroupList(Map<String, Object> params ){
|
||||
StringBuilder sqlBuild = new StringBuilder();
|
||||
sqlBuild.append(getBaseSelectSql());
|
||||
|
||||
sqlBuild.append(" wcg.id in ( ");
|
||||
Collection<Group> ids = (Collection<Group>)params.get("groupList");
|
||||
boolean first = true;
|
||||
for (Group group : ids) {
|
||||
if (!first) {
|
||||
sqlBuild.append(",");
|
||||
}
|
||||
sqlBuild.append(group.getId());
|
||||
first = false;
|
||||
}
|
||||
sqlBuild.append(" )");
|
||||
|
||||
return sqlBuild.toString() ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.genersoft.iot.vmp.gb28181.service;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Group;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GroupTree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface IGroupService {
|
||||
|
||||
void add(Group group);
|
||||
|
||||
boolean deleteByDeviceId(String deviceId, String groupId);
|
||||
|
||||
/**
|
||||
* 更新区域
|
||||
*/
|
||||
void update(Group group);
|
||||
|
||||
List<Group> getAllChild(String parent);
|
||||
|
||||
Group queryGroupByDeviceId(String regionDeviceId);
|
||||
|
||||
List<GroupTree> queryForTree(String query, String parent);
|
||||
|
||||
void syncFromChannel();
|
||||
|
||||
boolean delete(int id);
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package com.genersoft.iot.vmp.gb28181.service.impl;
|
||||
|
||||
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.service.IGroupService;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 区域管理类
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class GroupServiceImpl implements IGroupService {
|
||||
|
||||
@Autowired
|
||||
private GroupMapper groupManager;
|
||||
|
||||
@Autowired
|
||||
private CommonGBChannelMapper commonGBChannelMapper;
|
||||
|
||||
@Override
|
||||
public void add(Group group) {
|
||||
Assert.notNull(group, "参数不可为NULL");
|
||||
Assert.notNull(group.getDeviceId(), "设备编号不可为NULL");
|
||||
Assert.isTrue(group.getDeviceId().trim().length() == 20, "设备编号必须为20位");
|
||||
Assert.isTrue(group.getParentDeviceId().trim().length() == 20, "父级编号错误");
|
||||
Assert.notNull(group.getName(), "设备编号不可为NULL");
|
||||
|
||||
GbCode decode = GbCode.decode(group.getDeviceId());
|
||||
Assert.notNull(decode, "设备编号不满足国标定义");
|
||||
// 根据字段判断此处应使用什么规则校验
|
||||
if (ObjectUtils.isEmpty(group.getParentDeviceId())) {
|
||||
if (ObjectUtils.isEmpty(group.getBusinessGroup())) {
|
||||
// 如果是建立业务分组,那么编号必须20位,且10-13必须为215,
|
||||
Assert.isTrue("215".equals(decode.getTypeCode()), "创建业务分组时设备编号11-13位应使用215");
|
||||
group.setBusinessGroup(group.getDeviceId());
|
||||
}else {
|
||||
// 建立第一个虚拟组织
|
||||
Assert.isTrue("216".equals(decode.getTypeCode()), "创建虚拟组织时设备编号11-13位应使用216");
|
||||
}
|
||||
}else {
|
||||
// 建立第一个虚拟组织
|
||||
Assert.isTrue("216".equals(decode.getTypeCode()), "创建虚拟组织时设备编号11-13位应使用216");
|
||||
}
|
||||
if (!ObjectUtils.isEmpty(group.getBusinessGroup())) {
|
||||
// 校验业务分组是否存在
|
||||
Group businessGroup = groupManager.queryBusinessGroup(group.getBusinessGroup());
|
||||
Assert.notNull(businessGroup, "所属的业务分组分组不存在");
|
||||
}
|
||||
if (!ObjectUtils.isEmpty(group.getParentDeviceId())) {
|
||||
Group groupInDb = groupManager.queryOneByDeviceId(group.getParentDeviceId(), group.getBusinessGroup());
|
||||
Assert.notNull(groupInDb, "所属的上级分组分组不存在");
|
||||
}
|
||||
group.setCreateTime(DateUtil.getNow());
|
||||
group.setUpdateTime(DateUtil.getNow());
|
||||
groupManager.add(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteByDeviceId(String deviceId, String groupId) {
|
||||
Assert.notNull(deviceId, "设备编号不可为NULL");
|
||||
Assert.notNull(groupId, "业务分组不可为NULL");
|
||||
GbCode gbCode = GbCode.decode(deviceId);
|
||||
|
||||
Group businessGroup = groupManager.queryBusinessGroup(groupId);
|
||||
Assert.notNull(businessGroup, "业务分组不存在");
|
||||
// 待删除的分组
|
||||
List<Group> groupList;
|
||||
// 是否需要清理业务分组字段
|
||||
if (gbCode.getTypeCode().equals("215")) {
|
||||
// 删除业务分组
|
||||
// 获取所有的虚拟组织
|
||||
groupList = groupManager.queryByBusinessGroup(deviceId);
|
||||
if (groupList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
// 删除虚拟组织
|
||||
Group group = groupManager.queryOneByDeviceId(deviceId, groupId);
|
||||
Assert.notNull(group, "分组不存在");
|
||||
// 获取所有子分组
|
||||
groupList = queryAllChildren(deviceId, groupId);
|
||||
if (groupList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
List<CommonGBChannelWitchGroupChannelId> channels = commonGBChannelMapper.queryByGroupList(groupList);
|
||||
if (channels.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
commonGBChannelMapper.batchDeleteGroup(channels);
|
||||
|
||||
// TODO 待定 是否需要发送catalog事件,还是等分配的时候发送UPDATE事件
|
||||
groupManager.batchDelete(groupList);
|
||||
return true;
|
||||
}
|
||||
|
||||
private List<Group> queryAllChildren(String deviceId, String groupId) {
|
||||
List<Group> children = groupManager.getChildren(deviceId, groupId);
|
||||
if (ObjectUtils.isEmpty(children)) {
|
||||
return children;
|
||||
}
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
children.addAll(queryAllChildren(children.get(i).getDeviceId(), groupId));
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Group group) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Group> getAllChild(String parent) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group queryGroupByDeviceId(String regionDeviceId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GroupTree> queryForTree(String query, String parent) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncFromChannel() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(int id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user