package com.genersoft.iot.vmp.storager.dao;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannelInPlatform;
import com.genersoft.iot.vmp.gb28181.vo.DeviceChannelVO;
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
import com.genersoft.iot.vmp.vmanager.gb28181.vo.PageVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;
/**
* 用于存储设备通道信息
*/
@Mapper
@Repository
public interface DeviceChannelMapper {
@Insert("INSERT INTO device_channel (coordinate,channelId, deviceId, name, manufacture, model, owner, civilCode, block, " +
"address, parental, parentId, safetyWay, registerWay, certNum, certifiable, errCode, secrecy, " +
"ipAddress, port, password, PTZType, status, streamId, longitude, latitude, longitudeGcj02, latitudeGcj02, " +
"longitudeWgs84, latitudeWgs84, hasAudio, createTime, updateTime, businessGroupId, gpsTime) " +
"VALUES (ST_GeomFromText(${coordinate}),'${channelId}', '${deviceId}', '${name}', '${manufacture}', '${model}', '${owner}', '${civilCode}', '${block}'," +
"'${address}', ${parental}, '${parentId}', ${safetyWay}, ${registerWay}, '${certNum}', ${certifiable}, ${errCode}, '${secrecy}', " +
"'${ipAddress}', ${port}, '${password}', ${PTZType}, ${status}, '${streamId}', ${longitude}, ${latitude}, ${longitudeGcj02}, " +
"${latitudeGcj02}, ${longitudeWgs84}, ${latitudeWgs84}, ${hasAudio}, '${createTime}', '${updateTime}', '${businessGroupId}', '${gpsTime}')")
int add(DeviceChannel channel);
@Update(value = {" "})
int update(DeviceChannel channel);
/**
* 查询设备列表信息
* @param deviceId
* @param parentChannelId
* @param query
* @param type
* @param hasSubChannel
* @param dwbh
* @param online
* @return
*/
@Select(value = {" "})
List queryChannelsCar(String deviceId,
String parentChannelId,
String query,
String type,
Boolean hasSubChannel,
String dwbh,
Boolean online);
@Select(value = {" "})
List SpatialQueryList(String range, String query);
@Select(value = {" "})
List queryChannels(String deviceId,
String parentChannelId,
String query,
Boolean hasSubChannel,
Boolean online,
String deptId);
@Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND channelId=#{channelId}")
DeviceChannel queryChannel(String deviceId, String channelId);
@Delete("DELETE FROM device_channel WHERE deviceId=#{deviceId}")
int cleanChannelsByDeviceId(String deviceId);
@Delete("DELETE FROM device_channel WHERE deviceId=#{deviceId} AND channelId=#{channelId}")
int del(String deviceId, String channelId);
@Update(value = {"UPDATE device_channel SET streamId=null WHERE deviceId=#{deviceId} AND channelId=#{channelId}"})
void stopPlay(String deviceId, String channelId);
@Update(value = {"UPDATE device_channel SET streamId=#{streamId} WHERE deviceId=#{deviceId} AND channelId=#{channelId}"})
void startPlay(String deviceId, String channelId, String streamId);
@Select(value = {" "})
List queryChannelListInAll(String query, Boolean online, Boolean hasSubChannel, String platformId, String catalogId);
@Select(value = {" "})
List queryChannelByPlatformId(String platformId);
@Select("SELECT * FROM device_channel WHERE channelId=#{channelId}")
List queryChannelByChannelId( String channelId);
@Update(value = {"UPDATE device_channel SET status=0 WHERE deviceId=#{deviceId} AND channelId=#{channelId}"})
void offline(String deviceId, String channelId);
@Update(value = {"UPDATE device_channel SET status=0 WHERE deviceId=#{deviceId}"})
void offlineByDeviceId(String deviceId);
@Insert("")
int batchAdd(List addChannels);
@Update(value = {"UPDATE device_channel SET status=1 WHERE deviceId=#{deviceId} AND channelId=#{channelId}"})
void online(String deviceId, String channelId);
@Update({""})
int batchUpdate(List updateChannels);
@Select(value = {" "})
List queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String parentChannelId, String query,
Boolean hasSubChannel, Boolean online, int start, int limit);
@Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND status=1")
List queryOnlineChannelsByDeviceId(String deviceId);
@Delete(value = {" "})
int cleanChannelsNotInList(String deviceId, List channels);
@Update(" update device_channel" +
" set subCount = (select *" +
" from (select count(0)" +
" from device_channel" +
" where deviceId = #{deviceId} and parentId = #{channelId}) as temp)" +
" where deviceId = #{deviceId} " +
" and channelId = #{channelId}")
int updateChannelSubCount(String deviceId, String channelId);
@Update(value = {" "})
void updatePosition(DeviceChannel deviceChannel);
@Select("SELECT * FROM device_channel WHERE length(trim(streamId)) > 0")
List getAllChannelInPlay();
@Select("select * from device_channel where longitude*latitude > 0 and deviceId = #{deviceId}")
List getAllChannelWithCoordinate(String deviceId);
@Select(value = {" "})
List getChannelsWithCivilCodeAndLength(String deviceId, String parentId, Integer length);
@Select(value = {" "})
List getChannelsByCivilCode(String deviceId, String parentId);
@Select("select min(length(channelId)) as minLength " +
"from device_channel " +
"where deviceId=#{deviceId}")
Integer getChannelMinLength(String deviceId);
@Select("select * from device_channel where deviceId=#{deviceId} and civilCode not in " +
"(select civilCode from device_channel where deviceId=#{deviceId} group by civilCode)")
List getChannelWithoutCiviCode(String deviceId);
@Select("select * from device_channel where deviceId=#{deviceId} and SUBSTRING(channelId, 11, 3)=#{typeCode}")
List getBusinessGroups(String deviceId, String typeCode);
@Select("select dc.id, dc.channelId, dc.deviceId, dc.name, dc.manufacture,dc.model,dc.owner, pc.civilCode,dc.block, " +
" dc.address, '0' as parental,'0' as channelType, pc.id as parentId, dc.safetyWay, dc.registerWay,dc.certNum, dc.certifiable, " +
" dc.errCode,dc.endTime, dc.secrecy, dc.ipAddress, dc.port, dc.PTZType, dc.password, dc.status, " +
" dc.longitudeWgs84 as longitude, dc.latitudeWgs84 as latitude, pc.businessGroupId " +
" from device_channel dc" +
" left join platform_gb_channel pgc on dc.id = pgc.deviceChannelId" +
" left join platform_catalog pc on pgc.catalogId = pc.id and pgc.platformId = pc.platformId" +
" where pgc.platformId=#{serverGBId}")
List queryChannelWithCatalog(String serverGBId);
@Select("select * from device_channel where deviceId = #{deviceId}")
List queryAllChannels(String deviceId);
/**
* 获取辖区名称
* @param dwbh
* @return
*/
@Select("select dept_name from srjw.blade_dept where id = #{dwbh}")
String getDeptNameByDwbh(@Param("dwbh") String dwbh);
/**
* 查询当前辖区对应的设备通道ids
* @param deptName 辖区名称
* @return
*/
@Select("select channelId from wvp.device_channel where name like concat(concat('%',#{deptName}),'%')")
List getIdsListByDeptName(@Param("deptName") String deptName);
/**
* 查询所有
* @param deviceId
* @param parentChannelId
* @param query
* @param hasSubChannel
* @param dwbh
* @param online
* @return
*/
@Select(value = {" "})
List queryChannelsAllByOnline(String deviceId,
String parentChannelId,
String query,
Boolean hasSubChannel,
String dwbh,
Boolean online);
/**
* 查询巡逻路线数据
* @param id
* @return
*/
@Select("select ST_ASTEXT(positions) from srjw.sys_range where id = #{id}")
String getRangeInfoById(@Param("id") String id);
/**
* 判断该点在哪个派出所
* @param point 点
* @return
*/
@Select("SELECT police_station_id FROM srjw.police_station_info WHERE ST_Intersects(geom,ST_GeomFromText(${point},4326))")
List getPoliceStationInfo(@Param("point") String point);
/**
* 查询是否存在绑定关系数据
* @param id
* @param deptId
* @return
*/
@Select("select count(*) from wvp.device_channel_dept where device_channel_id = #{id} and dept_id = #{deptId}")
int queryExistByDeptIdAndDeviceChannelId(@Param("id") Integer id,@Param("deptId") String deptId);
/**
* 更新绑定
* @param deviceChannelId
* @param deptId
*/
@Insert("insert into wvp.device_channel_dept(device_channel_id,dept_id) values(#{deviceChannelId},#{deptId})")
void saveHandleBindPosition(@Param("deviceChannelId") Integer deviceChannelId,@Param("deptId") String deptId);
/**
* 更新绑定
* @param deviceChannelId
* @param deptId
*/
@Update("update wvp.device_channel_dept set dept_id = #{deptId} where device_channel_id = #{deviceChannelId}")
void updateHandleBindPosition(@Param("deviceChannelId") Integer deviceChannelId,@Param("deptId") String deptId);
/**
* 查询手台列表数据
* @param deviceId
* @param o
* @param query
* @param hasSubChannel
* @param dwbh 单位编号
* @param online 是否在线
* @return
*/
@Select(value = {" "})
List queryTalkBackEquipment(String deviceId, Object o, String query, Boolean hasSubChannel, String dwbh, Boolean online);
/**
* 查询执法记录仪列表数据
* @param deviceId
* @param o
* @param query
* @param hasSubChannel
* @param dwbh 单位编号
* @param online 是否在线
* @return
*/
@Select(value = {" "})
List queryChannelsPoliceCamera(String deviceId, Object o, String query, Boolean hasSubChannel, String dwbh, Boolean online);
/**
* 查询派出所名称--摄像头,警车
* @param id 设备id
* @return
*/
@Select("select bd.dept_name from device_channel_dept dcd join srjw.blade_dept bd on bd.id = dcd.dept_id where device_channel_id = #{id}")
String getDeptNameByDeviceChannelId(@Param("id") int id);
/**
* 查询派出所名称 -- 手台
* @param id 手台编号
* @return
*/
@Select("select bd.dept_name from sys_talk_back_equipment_info dcd join srjw.blade_dept bd on bd.id = dcd.dept_id where terminal_number = #{id}")
String getDeptNameByTalkBackEquipmentId(@Param("id")String id);
/**
* 查询派出所名称--执法记录仪
* @param id 设备id
* @return
*/
@Select("select bd.dept_name from device_channel_dept_police_camera dcd join srjw.blade_dept bd on bd.id = dcd.dept_id where device_channel_police_camera_id = #{id}")
String getDeptNameByDeviceChannelPoloiceCameraId(@Param("id")int id);
}