监控节点 xml写入数据库 存储过程
USE [Appserver] GO /****** Object: StoredProcedure [AppServer].[ImportNodeRelationData] Script Date: 08/05/2013 19:15:56 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO
ALTER procedure [AppServer].[ImportNodeRelationData] @ClientId uniqueidentifier, @RelationDataXML ntext, @TimeCreated datetime, @WriteToLog bit, @ResultValue int output --执行结果0:执行成功,-1:操作客户端不存在,-2:插入存在错误 AS declare @m_Code varchar(50) declare @m_Name varchar(50) declare @m_CoreId uniqueidentifier declare @m_BoxCode varchar(50) declare @m_IPAddress varchar(50) declare @m_ProductModel varchar(50) declare @m_OprationType varchar(50) declare @m_OldNodeCode varchar(50) declare @m_IDNumber int declare @m_ZoneCode varchar(50) declare @m_AnchorPointCode varchar(50) declare @m_CANIP varchar(50) declare @m_AVCodecPort int declare @m_MainCameraCode varchar(50) declare @m_BesideCamera1Code varchar(50) declare @m_BesideCamera2Code varchar(50) declare @m_BesideCamera3Code varchar(50) declare @m_BesideCamera4Code varchar(50) declare @m_AudioCodecIP varchar(50) declare @m_IOControllerIP varchar(50) declare @m_IOControllerPort int declare @m_CoreIdNull uniqueidentifier declare @m_BoxId uniqueidentifier declare @m_CANId uniqueidentifier declare @m_ZoneId uniqueidentifier declare @m_AnchorPointId uniqueidentifier declare @m_GlobalId uniqueidentifier declare @m_AVCodecId uniqueidentifier declare @m_IOControllerId uniqueidentifier declare @m_SwitchId uniqueidentifier declare @m_MainCameraID uniqueidentifier declare @m_BesideCamera1ID uniqueidentifier declare @m_BesideCamera2ID uniqueidentifier declare @m_BesideCamera3ID uniqueidentifier declare @m_BesideCamera4ID uniqueidentifier declare @m_BelongTo varchar(50) declare @m_RowNum int declare @m_PtzCameraId varchar(50) declare @m_PtzPresetId varchar(50) declare @m_AimetisCameraCode int declare @m_AimetisPolicyId int declare @m_LeftCameraId varchar(50) declare @m_RightCameraId varchar(50) declare @m_LeftCameragid uniqueidentifier declare @m_RightCameragid uniqueidentifier declare @m_MainCameragid uniqueidentifier declare @m_PtzCameragid uniqueidentifier begin IF NOT EXISTS(SELECT 1 FROM AppServer.ClientInfo WHERE ClientId=@ClientId ) BEGIN SET @ResultValue=-1 return; END set @ResultValue=0; set @m_CoreIdNull='00000000-0000-0000-0000-000000000000'; --创建临时表 IF EXISTS (SELECT 1 FROM tempdb.dbo.sysobjects WHERE id = object_id('tempdb..#ImportNodeErrorDataTempTable') AND TYPE = 'U') DROP TABLE #ImportNodeErrorDataTempTable CREATE TABLE #ImportNodeErrorDataTempTable ( ErrorId uniqueidentifier, [Key] varchar(100), Row int, ErrorType varchar(100), BelongTo varchar(100)); DECLARE @hdoc int EXEC sp_xml_preparedocument @hdoc OUTPUT, @RelationDataXML
--IOControllers begin Set @m_BelongTo='IOControllers'; Set @m_RowNum=0; declare cur_resulttmp cursor for select Code,Name,CoreId,BoxCode,IPAddress,ProductModel,OprationType,OldNodeCode FROM OPENXML (@hdoc, '/NodeRelation/IOControllers/IOController',1) WITH (Code varchar(50),Name varchar(50),CoreId uniqueidentifier,BoxCode varchar(50),IPAddress varchar(50), ProductModel varchar(50),OprationType varchar(50),OldNodeCode varchar(50)); open cur_resulttmp fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_BoxCode,@m_IPAddress,@m_ProductModel,@m_OprationType,@m_OldNodeCode; while @@fetch_status=0 begin begin transaction IF @m_CoreId IS NULL BEGIN set @m_CoreId=@m_CoreIdNull; END IF @m_BoxCode IS NULL BEGIN set @m_BoxId=NULL; END ELSE BEGIN SELECT @m_BoxId=BoxId FROM AppServer.DeviceControlBox where Code=@m_BoxCode; IF @m_BoxId IS NULL BEGIN set @m_BoxId=newid(); Insert into AppServer.DeviceControlBox(BoxId,Code,Text) values(@m_BoxId,@m_BoxCode,'控制箱'+@m_BoxCode); END END IF @m_OprationType='ADD' BEGIN IF NOT EXISTS(SELECT * FROM AppServer.NodeIndex where Code=@m_Code and NodeType='IOController') BEGIN Insert into AppServer.NodeIndex(GlobalId,BoxId,CoreNodeId,Code,Name,NodeType,IPAddress,ProductModel) values(NEWID(),@m_BoxId,@m_CoreId,@m_Code,@m_Name,'IOController',@m_IPAddress,@m_ProductModel); END ELSE BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_Code,@m_RowNum,'KeyExist',@m_BelongTo); END END --ELSE IF @m_OprationType='Modify' --BEGIN -- IF EXISTS(SELECT * FROM AppServer.NodeIndex where Code=@m_OldNodeCode and nodetype='IOController') -- BEGIN -- IF NOT EXISTS(SELECT * FROM AppServer.NodeIndex where Code=@m_Code and @m_OldNodeCode<>@m_Code and nodetype='IOController') -- BEGIN -- UpDate AppServer.NodeIndex Set BoxId=@m_BoxId,CoreNodeId=@m_CoreId,Code=@m_Code, -- Name=@m_Name,IPAddress=@m_IPAddress,ProductModel=@m_ProductModel where Code=@m_OldNodeCode and nodetype='IOController'; -- END -- ELSE -- BEGIN -- Set @ResultValue=-2; -- Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) -- values(newid(),@m_Code,@m_RowNum,'KeyExist',@m_BelongTo); -- END -- END -- ELSE -- BEGIN -- Set @ResultValue=-2; -- Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) -- values(newid(),@m_OldNodeCode,@m_RowNum,'RecordNotExist',@m_BelongTo); -- END --END commit transaction; SET @m_RowNum=@m_RowNum+1; --SET @m_Code=NULL; --SET @m_Name=NULL; --SET @m_CoreId=NULL; --SET @m_BoxCode=NULL; --SET @m_IPAddress=NULL; --SET @m_ProductModel=NULL; --SET @m_OprationType=NULL; --SET @m_OldNodeCode=NULL; SET @m_BoxId=NULL; fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_BoxCode,@m_IPAddress,@m_ProductModel,@m_OprationType,@m_OldNodeCode; end close cur_resulttmp deallocate cur_resulttmp; END --CANs begin Set @m_BelongTo='CANs'; Set @m_RowNum=0; declare cur_resulttmp cursor for select Code,Name,CoreId,BoxCode,IPAddress,IOControllerIP,IOControllerPort,OprationType,OldNodeCode FROM OPENXML (@hdoc, '/NodeRelation/CANs/CAN',1) WITH (Code varchar(50),Name varchar(50),CoreId uniqueidentifier,BoxCode varchar(50),IPAddress varchar(50),IOControllerIP varchar(50),IOControllerPort int,OprationType varchar(50),OldNodeCode varchar(50)); open cur_resulttmp fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_BoxCode,@m_IPAddress,@m_IOControllerIP,@m_IOControllerPort,@m_OprationType,@m_OldNodeCode; while @@fetch_status=0 begin begin transaction IF @m_CoreId IS NULL BEGIN set @m_CoreId=@m_CoreIdNull; END IF @m_BoxCode IS NULL BEGIN set @m_BoxId=NULL; END ELSE BEGIN SELECT @m_BoxId=BoxId FROM AppServer.DeviceControlBox where Code=@m_BoxCode; IF @m_BoxId IS NULL BEGIN set @m_BoxId=newid(); Insert into AppServer.DeviceControlBox(BoxId,Code,Text) values(@m_BoxId,@m_BoxCode,'控制箱'+@m_BoxCode); END END IF @m_IOControllerIP IS NULL BEGIN set @m_IOControllerId=NULL; END ELSE BEGIN SELECT @m_IOControllerId=GlobalId FROM AppServer.NodeIndex where IPAddress=@m_IOControllerIP and NodeType='IOController'; IF @m_IOControllerId IS NULL BEGIN set @m_IOControllerId=newid(); Insert into AppServer.NodeIndex(GlobalId,CoreNodeId,Code,Name,NodeType,IPAddress) values(@m_IOControllerId,@m_CoreIdNull,@m_Code+'-IOController',@m_Code+'-IOController','IOController',@m_IOControllerIP); END END IF (@m_IOControllerPort IS NULL) or (@m_IOControllerId IS NULL) BEGIN set @m_SwitchId=NULL; END ELSE BEGIN Select @m_SwitchId=GlobalId from AppServer.NodeIndex a,AppServer.NodeDataLinkRelation b where a.globalid=b.childnodeid and b.parentnodeid=@m_IOControllerId and a.idnumber=@m_IOControllerPort and nodetype='Switch'; IF (@m_SwitchId IS NULL) BEGIN set @m_SwitchId=NEWID(); Insert into AppServer.NodeIndex(GlobalId,CoreNodeId,Code,Name,NodeType,IDNumber) values(@m_SwitchId,@m_CoreIdNull,@m_IOControllerIP+'-'+Convert(varchar(50),@m_IOControllerPort),@m_IOControllerIP+'-'+Convert(varchar(50),@m_IOControllerPort),'Switch',@m_IOControllerPort); Insert into AppServer.NodeConnectRelation(ConnectionId,ParentNodeId,ChildNodeId) values(NEWID(),@m_IOControllerId,@m_SwitchId); Insert into AppServer.NodeDataLinkRelation(DataLinkId,ParentNodeId,ChildNodeId) values(NEWID(),@m_IOControllerId,@m_SwitchId); END END IF (@m_OprationType='ADD') BEGIN IF NOT EXISTS(SELECT * FROM AppServer.NodeIndex where Code=@m_Code and NodeType='CAN') BEGIN set @m_GlobalId=NEWID(); Insert into AppServer.NodeIndex(GlobalId,BoxId,CoreNodeId,Code,Name,NodeType,IPAddress,IDNumber) values(@m_GlobalId,@m_BoxId,@m_CoreId,@m_Code,@m_Name,'CAN',@m_IPAddress,@m_IOControllerPort); IF (@m_IOControllerId IS NOT NULL) BEGIN --添加数据连接关系 IF NOT EXISTS(SELECT * FROM AppServer.NodeConnectRelation where ParentNodeId=@m_IOControllerId and ChildNodeId=@m_GlobalId) BEGIN Insert into AppServer.NodeConnectRelation(ConnectionId,ParentNodeId,ChildNodeId) values(NEWID(),@m_IOControllerId,@m_GlobalId); END --添加物理连接关系 IF NOT EXISTS(SELECT * FROM AppServer.NodeDataLinkRelation where ParentNodeId=@m_IOControllerId and ChildNodeId=@m_GlobalId) BEGIN Insert into AppServer.NodeDataLinkRelation(DataLinkId,ParentNodeId,ChildNodeId) values(NEWID(),@m_IOControllerId,@m_GlobalId); END END --添加电源关系 IF (@m_SwitchId IS NOT NULL) BEGIN IF NOT EXISTS(SELECT * FROM AppServer.NodePowerSupplyRelation where PowerNodeId=@m_SwitchId and ElectricityNodeId=@m_GlobalId) BEGIN Insert into AppServer.NodePowerSupplyRelation(PowerSupplyId,PowerNodeId,ElectricityNodeId) values(NEWID(),@m_SwitchId,@m_GlobalId); END END END ELSE BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_Code,@m_RowNum,'KeyExist',@m_BelongTo); END END --ELSE IF (@m_OprationType='Modify') --BEGIN --END commit transaction; SET @m_RowNum=@m_RowNum+1; --SET @m_Code=NULL; --SET @m_Name=NULL; --SET @m_CoreId=NULL; --SET @m_BoxCode=NULL; --SET @m_IPAddress=NULL; --SET @m_IOControllerIP=NULL; --SET @m_IOControllerPort=NULL; --SET @m_OprationType=NULL; --SET @m_OldNodeCode=NULL; SET @m_BoxId=NULL; SET @m_IOControllerId=NULL; SET @m_SwitchId=NULL; set @m_GlobalId=NULL; fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_BoxCode,@m_IPAddress,@m_IOControllerIP,@m_IOControllerPort,@m_OprationType,@m_OldNodeCode; end close cur_resulttmp deallocate cur_resulttmp; END --AudioVideoCodecs begin Set @m_BelongTo='AudioVideoCodecs'; Set @m_RowNum=0; declare cur_resulttmp cursor for select Code,Name,CoreId,BoxCode,IPAddress,ProductModel,OprationType,OldNodeCode FROM OPENXML (@hdoc, '/NodeRelation/AudioVideoCodecs/AudioVideoCodec',1) WITH (Code varchar(50),Name varchar(50),CoreId uniqueidentifier,BoxCode varchar(50),IPAddress varchar(50),ProductModel varchar(50),OprationType varchar(50),OldNodeCode varchar(50)); open cur_resulttmp fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_BoxCode,@m_IPAddress,@m_ProductModel,@m_OprationType,@m_OldNodeCode; while @@fetch_status=0 begin begin transaction IF @m_CoreId IS NULL BEGIN set @m_CoreId=@m_CoreIdNull; END IF @m_BoxCode IS NULL BEGIN set @m_BoxId=NULL; END ELSE BEGIN SELECT @m_BoxId=BoxId FROM AppServer.DeviceControlBox where Code=@m_BoxCode; IF @m_BoxId IS NULL BEGIN set @m_BoxId=newid(); Insert into AppServer.DeviceControlBox(BoxId,Code,Text) values(@m_BoxId,@m_BoxCode,'控制箱'+@m_BoxCode); END END IF (@m_OprationType='ADD') BEGIN IF NOT EXISTS(SELECT * FROM AppServer.NodeIndex where Code=@m_Code and NodeType='AudioVideoCodec') BEGIN set @m_GlobalId=NEWID(); IF @m_CoreId IS NULL BEGIN set @m_CoreId=@m_CoreIdNull; END Insert into AppServer.NodeIndex(GlobalId,BoxId,CoreNodeId,Code,Name,NodeType,IPAddress,ProductModel) values(@m_GlobalId,@m_BoxId,@m_CoreId,@m_Code,@m_Name,'AudioVideoCodec',@m_IPAddress,@m_ProductModel); END ELSE BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_Code,@m_RowNum,'KeyExist',@m_BelongTo); END END --ELSE IF (@m_OprationType='Modify') --BEGIN --END commit transaction; SET @m_RowNum=@m_RowNum+1; SET @m_BoxId=NULL; set @m_GlobalId=NULL; fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_BoxCode,@m_IPAddress,@m_ProductModel,@m_OprationType,@m_OldNodeCode; end close cur_resulttmp deallocate cur_resulttmp; END --SensorControllers begin Set @m_BelongTo='SensorControllers'; Set @m_RowNum=0; declare cur_resulttmp cursor for select Code,Name,CoreId,BoxCode,IDNumber,ZoneCode,AnchorPointCode,CANIP,ProductModel,PtzCameraId,PtzPresetId,OprationType,OldNodeCode FROM OPENXML (@hdoc, '/NodeRelation/SensorControllers/SensorController',1) WITH (Code varchar(50),Name varchar(50),CoreId uniqueidentifier,BoxCode varchar(50),IDNumber int,ZoneCode varchar(50),AnchorPointCode varchar(50),CANIP varchar(50),ProductModel varchar(50),PtzCameraId varchar(50),PtzPresetId varchar(50),OprationType varchar(50),OldNodeCode varchar(50)); open cur_resulttmp fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_BoxCode,@m_IDNumber,@m_ZoneCode,@m_AnchorPointCode,@m_CANIP,@m_ProductModel,@m_PtzCameraId,@m_PtzPresetId,@m_OprationType,@m_OldNodeCode; while @@fetch_status=0 begin begin transaction IF @m_CoreId IS NULL BEGIN set @m_CoreId=@m_CoreIdNull; END IF @m_BoxCode IS NULL BEGIN set @m_BoxId=NULL; END ELSE BEGIN SELECT @m_BoxId=BoxId FROM AppServer.DeviceControlBox where Code=@m_BoxCode; IF @m_BoxId IS NULL BEGIN set @m_BoxId=newid(); Insert into AppServer.DeviceControlBox(BoxId,Code,Text) values(@m_BoxId,@m_BoxCode,'控制箱'+@m_BoxCode); END END IF @m_CANIP IS NULL BEGIN set @m_CANId=NULL; END ELSE BEGIN SELECT @m_CANId=GlobalId FROM AppServer.NodeIndex where IPAddress=@m_CANIP and NodeType='CAN'; IF @m_CANId IS NULL BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_CANIP,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END END IF @m_ZoneCode IS NULL BEGIN set @m_ZoneId=NULL; END ELSE BEGIN SELECT @m_ZoneId=ZoneId FROM AppServer.DeviceDefenceZone where Code=@m_ZoneCode; IF @m_ZoneId IS NULL BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_ZoneCode,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END END IF @m_AnchorPointCode IS NULL BEGIN set @m_AnchorPointId=NULL; END ELSE BEGIN SELECT @m_AnchorPointId=AnchorPointId FROM AppServer.AnchorPoint where Code=@m_AnchorPointCode; IF @m_AnchorPointId IS NULL BEGIN set @m_AnchorPointId=newid(); Insert into AppServer.AnchorPoint(AnchorPointId,Code,Text) values(@m_AnchorPointId,@m_AnchorPointCode,@m_AnchorPointCode); END END IF (@m_CANId IS NOT NULL) AND (@m_ZoneId IS NOT NULL) BEGIN IF (@m_OprationType='ADD') BEGIN set @m_PtzCameragid=NULL; SELECT @m_PtzCameragid=GlobalId FROM AppServer.NodeIndex where Code=@m_PtzCameraId and NodeType='Camera' IF NOT EXISTS(SELECT * FROM AppServer.NodeIndex where Code=@m_Code and NodeType='SensorController') BEGIN IF(@m_PtzCameraId IS NULL OR @m_PtzCameragid IS NOT NULL) BEGIN IF((@m_PtzCameraId IS NULL and @m_PtzPresetId IS NULL)OR(@m_PtzCameraId IS NOT NULL and @m_PtzPresetId IS NOT NULL)) BEGIN set @m_GlobalId=NEWID(); IF @m_CoreId IS NULL BEGIN set @m_CoreId=@m_CoreIdNull; END Insert into AppServer.NodeIndex(GlobalId,BoxId,CoreNodeId,Code,Name,NodeType,IDNumber,ProductModel) values(@m_GlobalId,@m_BoxId,@m_CoreId,@m_Code,@m_Name,'SensorController',@m_IDNumber,@m_ProductModel); --添加防区关系 IF NOT EXISTS(SELECT * FROM AppServer.NodeInDDZ where ZoneId=@m_ZoneId and NodeId=@m_GlobalId) BEGIN Insert into AppServer.NodeInDDZ(NDLId,ZoneId,NodeId,IsMain) values(NEWID(),@m_ZoneId,@m_GlobalId,0); END --添加数据连接关系 IF NOT EXISTS(SELECT * FROM AppServer.NodeConnectRelation where ParentNodeId=@m_CANId and ChildNodeId=@m_GlobalId) BEGIN Insert into AppServer.NodeConnectRelation(ConnectionId,ParentNodeId,ChildNodeId) values(NEWID(),@m_CANId,@m_GlobalId); END --添加物理连接关系 IF NOT EXISTS(SELECT * FROM AppServer.NodeDataLinkRelation where ParentNodeId=@m_CANId and ChildNodeId=@m_GlobalId) BEGIN Insert into AppServer.NodeDataLinkRelation(DataLinkId,ParentNodeId,ChildNodeId) values(NEWID(),@m_CANId,@m_GlobalId); END --添加柱子关系 IF (@m_AnchorPointId IS NOT NULL) BEGIN IF NOT EXISTS(SELECT * FROM AppServer.NodeLocationRelation where AnchorPointId=@m_AnchorPointId and NodeGlobalId=@m_GlobalId) BEGIN Insert into AppServer.NodeLocationRelation(LocationRefId,AnchorPointId,NodeGlobalId) values(NEWID(),@m_AnchorPointId,@m_GlobalId); END END --添加信息扩展 set @m_MainCameragid=NULL; SELECT @m_MainCameragid=GlobalId FROM AppServer.NodeIndex where Code=@m_Code and NodeType='SensorController' IF (@m_MainCameragid IS NOT NULL AND(@m_PtzCameraId IS NOT NULL and @m_PtzPresetId IS NOT NULL)) BEGIN Insert into AppServer.ExtNodeInfo(NodeId,ExtDeviceId,ExtVarChar3) values(@m_MainCameragid,@m_PtzPresetId,@m_PtzCameragid) END END ELSE BEGIN IF(@m_PtzCameraId IS NULL) BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_PtzCameraId,@m_RowNum,'CanNotyBeEmept',@m_BelongTo); END ELSE BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_PtzPresetId,@m_RowNum,'CanNotyBeEmept',@m_BelongTo); END END END ELSE BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_PtzCameraId,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END END ELSE BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_Code,@m_RowNum,'KeyExist',@m_BelongTo); END END --ELSE IF (@m_OprationType='Modify') --BEGIN --END END commit transaction; SET @m_RowNum=@m_RowNum+1; SET @m_BoxId=NULL; SET @m_CANId=NULL; SET @m_ZoneId=NULL; SET @m_AnchorPointId=NULL; set @m_GlobalId=NULL; fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_BoxCode,@m_IDNumber,@m_ZoneCode,@m_AnchorPointCode,@m_CANIP,@m_ProductModel,@m_PtzCameraId,@m_PtzPresetId,@m_OprationType,@m_OldNodeCode; end close cur_resulttmp deallocate cur_resulttmp; END --Cameras begin Set @m_BelongTo='Cameras'; Set @m_RowNum=0; declare cur_resulttmp cursor for select Code,Name,CoreId,BoxCode,IPAddress,AVCodecPort,AnchorPointCode,PtzCameraId,PtzPresetId,AimetisCameraCode,AimetisPolicyId,LeftCameraId,RightCameraId,OprationType,OldNodeCode FROM OPENXML (@hdoc, '/NodeRelation/Cameras/Camera',1) WITH (Code varchar(50),Name varchar(50),CoreId uniqueidentifier,BoxCode varchar(50),IPAddress varchar(50),AVCodecPort int,AnchorPointCode varchar(50),PtzCameraId varchar(50),PtzPresetId varchar(50),AimetisCameraCode int,AimetisPolicyId int,LeftCameraId varchar(50),RightCameraId varchar(50),OprationType varchar(50),OldNodeCode varchar(50)); open cur_resulttmp fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_BoxCode,@m_IPAddress,@m_AVCodecPort,@m_AnchorPointCode,@m_PtzCameraId,@m_PtzPresetId,@m_AimetisCameraCode,@m_AimetisPolicyId,@m_LeftCameraId,@m_RightCameraId,@m_OprationType,@m_OldNodeCode; while @@fetch_status=0 begin begin transaction IF @m_CoreId IS NULL BEGIN set @m_CoreId=@m_CoreIdNull; END IF @m_AnchorPointCode IS NULL BEGIN set @m_AnchorPointId=NULL; END ELSE BEGIN SELECT @m_AnchorPointId=AnchorPointId FROM AppServer.AnchorPoint where Code=@m_AnchorPointCode; IF @m_AnchorPointId IS NULL BEGIN set @m_AnchorPointId=newid(); Insert into AppServer.AnchorPoint(AnchorPointId,Code,Text) values(@m_AnchorPointId,@m_AnchorPointCode,@m_AnchorPointCode); END END IF @m_IPAddress IS NULL BEGIN set @m_AVCodecId=NULL; END ELSE BEGIN SELECT @m_AVCodecId=GlobalId FROM AppServer.NodeIndex where IPAddress=@m_IPAddress and NodeType='AudioVideoCodec'; IF @m_AVCodecId IS NULL BEGIN set @m_AVCodecId=newid(); Insert into AppServer.NodeIndex(GlobalId,CoreNodeId,Code,Name,NodeType,IPAddress) values(@m_AVCodecId,@m_CoreIdNull,@m_Code+'-AVCodec',@m_Code+'-AVCodec','AudioVideoCodec',@m_IPAddress); END END IF (@m_OprationType='ADD') BEGIN set @m_MainCameragid=NULL; set @m_PtzCameragid=NULL; set @m_RightCameragid=NULL; set @m_LeftCameragid=NULL; SELECT @m_MainCameragid=GlobalId FROM AppServer.NodeIndex where Code=@m_Code and NodeType='Camera' SELECT @m_LeftCameragid=GlobalId FROM AppServer.NodeIndex where Code=@m_LeftCameraId and NodeType='Camera' SELECT @m_RightCameragid=GlobalId FROM AppServer.NodeIndex where Code=@m_RightCameraId and NodeType='Camera' SELECT @m_PtzCameragid=GlobalId FROM AppServer.NodeIndex where Code=@m_PtzCameraId and NodeType='Camera' IF (@m_MainCameragid IS NULL) BEGIN IF (@m_LeftCameraId IS NULL OR @m_LeftCameragid IS NOT NULL) BEGIN IF(@m_RightCameraId IS NULL OR @m_RightCameragid IS NOT NULL) BEGIN IF(@m_PtzCameraId IS NULL OR @m_PtzCameragid IS NOT NULL) BEGIN IF((@m_PtzCameraId IS NULL and @m_PtzPresetId IS NULL)OR(@m_PtzCameraId IS NOT NULL and @m_PtzPresetId IS NOT NULL)) BEGIN IF((@m_AimetisCameraCode IS NULL and @m_AimetisPolicyId IS NULL)OR(@m_AimetisCameraCode IS NOT NULL and @m_AimetisPolicyId IS NOT NULL)) BEGIN IF @m_AVCodecPort IS NULL BEGIN set @m_AVCodecPort=0; END set @m_GlobalId=newid(); Insert into AppServer.NodeIndex(GlobalId,CoreNodeId,Code,Name,NodeType,IDNumber) values(@m_GlobalId,@m_CoreId,@m_Code,@m_Name,'Camera',@m_AVCodecPort); IF (@m_AVCodecId IS NOT NULL) BEGIN --添加数据连接关系 IF NOT EXISTS(SELECT * FROM AppServer.NodeConnectRelation where ParentNodeId=@m_AVCodecId and ChildNodeId=@m_GlobalId) BEGIN Insert into AppServer.NodeConnectRelation(ConnectionId,ParentNodeId,ChildNodeId) values(NEWID(),@m_AVCodecId,@m_GlobalId); END --添加物理连接关系 IF NOT EXISTS(SELECT * FROM AppServer.NodeDataLinkRelation where ParentNodeId=@m_AVCodecId and ChildNodeId=@m_GlobalId) BEGIN Insert into AppServer.NodeDataLinkRelation(DataLinkId,ParentNodeId,ChildNodeId) values(NEWID(),@m_AVCodecId,@m_GlobalId); END --添加柱子关系 IF (@m_AnchorPointId IS NOT NULL) BEGIN IF NOT EXISTS(SELECT * FROM AppServer.NodeLocationRelation where AnchorPointId=@m_AnchorPointId and NodeGlobalId=@m_GlobalId) BEGIN Insert into AppServer.NodeLocationRelation(LocationRefId,AnchorPointId,NodeGlobalId) values(NEWID(),@m_AnchorPointId,@m_GlobalId); END END --添加信息扩展 IF (@m_MainCameragid IS NOT NULL AND(@m_LeftCameraId IS NOT NULL OR @m_RightCameraId IS NULL OR(@m_PtzCameraId IS NOT NULL and @m_PtzPresetId IS NOT NULL)OR(@m_AimetisCameraCode IS NOT NULL and @m_AimetisPolicyId IS NOT NULL))) BEGIN Insert into AppServer.ExtNodeInfo(NodeId,ExtVarChar1,ExtVarChar2,ExtDeviceId,ExtVarChar3,ExtInt1,ExtInt2) values(@m_MainCameragid,@m_LeftCameragid,@m_RightCameragid,@m_PtzPresetId,@m_PtzCameragid,@m_AimetisPolicyId,@m_AimetisCameraCode) END END END ELSE BEGIN IF(@m_AimetisCameraCode IS NULL) BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_AimetisCameraCode,@m_RowNum,'CanNotyBeEmept',@m_BelongTo); END ELSE BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_AimetisPolicyId,@m_RowNum,'CanNotyBeEmept',@m_BelongTo); END END END ELSE BEGIN IF(@m_PtzCameraId IS NULL) BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_PtzCameraId,@m_RowNum,'CanNotyBeEmept',@m_BelongTo); END ELSE BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_PtzPresetId,@m_RowNum,'CanNotyBeEmept',@m_BelongTo); END END END ELSE BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_PtzCameraId,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END END ELSE BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_RightCameraId,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END END ELSE BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_LeftCameraId,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END END ELSE BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_Code,@m_RowNum,'KeyExist',@m_BelongTo); END END --ELSE IF (@m_OprationType='Modify') --BEGIN --END commit transaction; SET @m_RowNum=@m_RowNum+1; SET @m_AnchorPointId=NULL; SET @m_AVCodecId=NULL; set @m_GlobalId=NULL; fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_BoxCode,@m_IPAddress,@m_AVCodecPort,@m_AnchorPointCode,@m_PtzCameraId,@m_PtzPresetId,@m_AimetisCameraCode,@m_AimetisPolicyId,@m_LeftCameraId,@m_RightCameraId,@m_OprationType,@m_OldNodeCode; end close cur_resulttmp deallocate cur_resulttmp; END --DefenceCameras begin Set @m_BelongTo='DefenceCameras'; Set @m_RowNum=0; declare cur_resulttmp cursor for select ZoneCode,MainCameraCode,BesideCamera1Code,BesideCamera2Code,BesideCamera3Code,BesideCamera4Code FROM OPENXML (@hdoc, '/NodeRelation/DefenceCameras/DefenceCamera',1) WITH (ZoneCode varchar(50),MainCameraCode varchar(50),BesideCamera1Code varchar(50),BesideCamera2Code varchar(50),BesideCamera3Code varchar(50),BesideCamera4Code varchar(50)); open cur_resulttmp fetch next from cur_resulttmp into @m_ZoneCode, @m_MainCameraCode, @m_BesideCamera1Code, @m_BesideCamera2Code, @m_BesideCamera3Code, @m_BesideCamera4Code; while @@fetch_status=0 begin begin transaction IF @m_ZoneCode IS NULL BEGIN set @m_ZoneId=NULL; END ELSE BEGIN SELECT @m_ZoneId=ZoneId FROM AppServer.DeviceDefenceZone where Code=@m_ZoneCode; END IF @m_MainCameraCode IS NULL BEGIN set @m_MainCameraID=NULL; END ELSE BEGIN SELECT @m_MainCameraID=GlobalId FROM AppServer.NodeIndex where Code=@m_MainCameraCode and NodeType='Camera'; IF @m_MainCameraID IS NULL BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_MainCameraCode,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END END IF @m_BesideCamera1Code IS NULL BEGIN set @m_BesideCamera1ID=NULL; END ELSE BEGIN SELECT @m_BesideCamera1ID=GlobalId FROM AppServer.NodeIndex where Code=@m_BesideCamera1Code and NodeType='Camera'; IF @m_BesideCamera1ID IS NULL BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_BesideCamera1Code,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END END IF @m_BesideCamera2Code IS NULL BEGIN set @m_BesideCamera2ID=NULL; END ELSE BEGIN SELECT @m_BesideCamera2ID=GlobalId FROM AppServer.NodeIndex where Code=@m_BesideCamera2Code and NodeType='Camera'; IF @m_BesideCamera2ID IS NULL BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_BesideCamera2Code,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END END IF @m_BesideCamera3Code IS NULL BEGIN set @m_BesideCamera3ID=NULL; END ELSE BEGIN SELECT @m_BesideCamera3ID=GlobalId FROM AppServer.NodeIndex where Code=@m_BesideCamera3Code and NodeType='Camera'; IF @m_BesideCamera3ID IS NULL BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_BesideCamera3Code,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END END IF @m_BesideCamera4Code IS NULL BEGIN set @m_BesideCamera4ID=NULL; END ELSE BEGIN SELECT @m_BesideCamera4ID=GlobalId FROM AppServer.NodeIndex where Code=@m_BesideCamera4Code and NodeType='Camera'; IF @m_BesideCamera4ID IS NULL BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_BesideCamera4Code,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END END IF (@m_ZoneId IS NOT NULL) BEGIN Delete From AppServer.NodeInDDZ where NDLId in(select NDLId from AppServer.NodeInDDZ a,AppServer.NodeIndex b where a.nodeid=b.globalid and b.nodetype='Camera') and ZoneId=@m_ZoneId; IF (@m_MainCameraID IS NOT NULL) BEGIN Insert into AppServer.NodeInDDZ(NDLId,ZoneId,NodeId,IsMain) values(NEWID(),@m_ZoneId,@m_MainCameraID,1); END IF (@m_BesideCamera1ID IS NOT NULL) BEGIN Insert into AppServer.NodeInDDZ(NDLId,ZoneId,NodeId,IsMain) values(NEWID(),@m_ZoneId,@m_BesideCamera1ID,0); END IF (@m_BesideCamera2ID IS NOT NULL) BEGIN Insert into AppServer.NodeInDDZ(NDLId,ZoneId,NodeId,IsMain) values(NEWID(),@m_ZoneId,@m_BesideCamera2ID,0); END IF (@m_BesideCamera3ID IS NOT NULL) BEGIN Insert into AppServer.NodeInDDZ(NDLId,ZoneId,NodeId,IsMain) values(NEWID(),@m_ZoneId,@m_BesideCamera3ID,0); END IF (@m_BesideCamera4ID IS NOT NULL) BEGIN Insert into AppServer.NodeInDDZ(NDLId,ZoneId,NodeId,IsMain) values(NEWID(),@m_ZoneId,@m_BesideCamera4ID,0); END END ELSE BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_ZoneCode,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END commit transaction; SET @m_RowNum=@m_RowNum+1; SET @m_ZoneId=NULL; SET @m_MainCameraID=NULL; SET @m_BesideCamera1ID=NULL; SET @m_BesideCamera2ID=NULL; SET @m_BesideCamera3ID=NULL; SET @m_BesideCamera4ID=NULL; fetch next from cur_resulttmp into @m_ZoneCode, @m_MainCameraCode, @m_BesideCamera1Code, @m_BesideCamera2Code, @m_BesideCamera3Code, @m_BesideCamera4Code; end close cur_resulttmp deallocate cur_resulttmp; END --IntelligentVideos begin Set @m_BelongTo='IntelligentVideos'; Set @m_RowNum=0; declare cur_resulttmp cursor for select Code,Name,CoreId,BoxCode,IPAddress,AVCodecPort,ZoneCode,OprationType,OldNodeCode FROM OPENXML (@hdoc, '/NodeRelation/IntelligentVideos/IntelligentVideo',1) WITH (Code varchar(50),Name varchar(50),CoreId uniqueidentifier,BoxCode varchar(50),IPAddress varchar(50),AVCodecPort int,ZoneCode varchar(50),OprationType varchar(50),OldNodeCode varchar(50)); open cur_resulttmp fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_BoxCode,@m_IPAddress,@m_AVCodecPort,@m_ZoneCode,@m_OprationType,@m_OldNodeCode; while @@fetch_status=0 begin begin transaction IF @m_CoreId IS NULL BEGIN set @m_CoreId=@m_CoreIdNull; END IF @m_ZoneCode IS NULL BEGIN set @m_ZoneId=NULL; END ELSE BEGIN SELECT @m_ZoneId=ZoneId FROM AppServer.DeviceDefenceZone where Code=@m_ZoneCode; IF @m_ZoneId IS NULL BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_ZoneCode,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END END IF @m_IPAddress IS NULL BEGIN set @m_AVCodecId=NULL; END ELSE BEGIN SELECT @m_AVCodecId=GlobalId FROM AppServer.NodeIndex where IPAddress=@m_IPAddress and NodeType='AudioVideoCodec'; IF @m_AVCodecId IS NULL BEGIN set @m_AVCodecId=newid(); Insert into AppServer.NodeIndex(GlobalId,CoreNodeId,Code,Name,NodeType,IPAddress) values(@m_AVCodecId,@m_CoreIdNull,@m_Code+'-AudioVideoCodec',@m_Code+'-AudioVideoCodec','AudioVideoCodec',@m_IPAddress); END END
IF (@m_OprationType='ADD') BEGIN IF NOT EXISTS(SELECT * FROM AppServer.NodeIndex where Code=@m_Code and NodeType='IntelligentVideo') BEGIN IF @m_AVCodecPort IS NULL BEGIN set @m_AVCodecPort=0; END set @m_GlobalId=NEWID(); Insert into AppServer.NodeIndex(GlobalId,CoreNodeId,Code,Name,NodeType,IDNumber) values(@m_GlobalId,@m_CoreId,@m_Code,@m_Name,'IntelligentVideo',@m_AVCodecPort); IF (@m_ZoneId IS NOT NULL) BEGIN --添加防区关系 IF NOT EXISTS(SELECT * FROM AppServer.NodeInDDZ where ZoneId=@m_ZoneId and NodeId=@m_GlobalId) BEGIN Insert into AppServer.NodeInDDZ(NDLId,ZoneId,NodeId,IsMain) values(NEWID(),@m_ZoneId,@m_GlobalId,0); END END IF (@m_AVCodecId IS NOT NULL) BEGIN --添加数据连接关系 IF NOT EXISTS(SELECT * FROM AppServer.NodeConnectRelation where ParentNodeId=@m_AVCodecId and ChildNodeId=@m_GlobalId) BEGIN Insert into AppServer.NodeConnectRelation(ConnectionId,ParentNodeId,ChildNodeId) values(NEWID(),@m_AVCodecId,@m_GlobalId); END --添加物理连接关系 IF NOT EXISTS(SELECT * FROM AppServer.NodeDataLinkRelation where ParentNodeId=@m_AVCodecId and ChildNodeId=@m_GlobalId) BEGIN Insert into AppServer.NodeDataLinkRelation(DataLinkId,ParentNodeId,ChildNodeId) values(NEWID(),@m_AVCodecId,@m_GlobalId); END END END ELSE BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_Code,@m_RowNum,'KeyExist',@m_BelongTo); END END --ELSE IF (@m_OprationType='Modify') --BEGIN --END
commit transaction; SET @m_RowNum=@m_RowNum+1; SET @m_ZoneId=NULL; SET @m_AVCodecId=NULL; SET @m_GlobalId=NULL; fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_BoxCode,@m_IPAddress,@m_AVCodecPort,@m_ZoneCode,@m_OprationType,@m_OldNodeCode; end close cur_resulttmp deallocate cur_resulttmp; END --Speakers begin Set @m_BelongTo='Speakers'; Set @m_RowNum=0; declare cur_resulttmp cursor for select Code,Name,CoreId,ZoneCode,AnchorPointCode,AudioCodecIP,IOControllerIP,IOControllerPort,OprationType,OldNodeCode FROM OPENXML (@hdoc, '/NodeRelation/Speakers/Speaker',1) WITH (Code varchar(50),Name varchar(50),CoreId uniqueidentifier,ZoneCode varchar(50),AnchorPointCode varchar(50),AudioCodecIP varchar(50),IOControllerIP varchar(50),IOControllerPort int,OprationType varchar(50),OldNodeCode varchar(50)); open cur_resulttmp fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_ZoneCode,@m_AnchorPointCode,@m_AudioCodecIP,@m_IOControllerIP,@m_IOControllerPort,@m_OprationType,@m_OldNodeCode; while @@fetch_status=0 begin begin transaction IF @m_CoreId IS NULL BEGIN set @m_CoreId=@m_CoreIdNull; END IF @m_ZoneCode IS NULL BEGIN set @m_ZoneId=NULL; END ELSE BEGIN SELECT @m_ZoneId=ZoneId FROM AppServer.DeviceDefenceZone where Code=@m_ZoneCode; IF @m_ZoneId IS NULL BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_ZoneCode,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END END IF @m_AnchorPointCode IS NULL BEGIN set @m_AnchorPointId=NULL; END ELSE BEGIN SELECT @m_AnchorPointId=AnchorPointId FROM AppServer.AnchorPoint where Code=@m_AnchorPointCode; IF @m_AnchorPointId IS NULL BEGIN set @m_AnchorPointId=newid(); Insert into AppServer.AnchorPoint(AnchorPointId,Code,Text) values(@m_AnchorPointId,@m_AnchorPointCode,@m_AnchorPointCode); END END IF @m_AudioCodecIP IS NULL BEGIN set @m_AVCodecId=NULL; END ELSE BEGIN SELECT @m_AVCodecId=GlobalId FROM AppServer.NodeIndex where IPAddress=@m_AudioCodecIP and NodeType='AudioVideoCodec'; IF @m_AVCodecId IS NULL BEGIN set @m_AVCodecId=newid(); Insert into AppServer.NodeIndex(GlobalId,CoreNodeId,Code,Name,NodeType,IPAddress) values(@m_AVCodecId,@m_CoreIdNull,@m_Code+'-AVCodec',@m_Code+'-AVCodec','AudioVideoCodec',@m_AudioCodecIP); END END IF @m_IOControllerIP IS NULL BEGIN set @m_IOControllerId=NULL; END ELSE BEGIN SELECT @m_IOControllerId=GlobalId FROM AppServer.NodeIndex where IPAddress=@m_IOControllerIP and NodeType='IOController'; IF @m_IOControllerId IS NULL BEGIN set @m_IOControllerId=newid(); Insert into AppServer.NodeIndex(GlobalId,CoreNodeId,Code,Name,NodeType,IPAddress) values(@m_IOControllerId,@m_CoreIdNull,@m_Code+'-IOController',@m_Code+'-IOController','IOController',@m_IOControllerIP); END END IF (@m_IOControllerPort IS NULL) or (@m_IOControllerId IS NULL) BEGIN set @m_SwitchId=NULL; END ELSE BEGIN Select @m_SwitchId=GlobalId from AppServer.NodeIndex a,AppServer.NodeDataLinkRelation b where a.globalid=b.childnodeid and b.parentnodeid=@m_IOControllerId and a.idnumber=@m_IOControllerPort and nodetype='Switch'; IF (@m_SwitchId IS NULL) BEGIN set @m_SwitchId=NEWID(); Insert into AppServer.NodeIndex(GlobalId,CoreNodeId,Code,Name,NodeType,IDNumber) values(@m_SwitchId,@m_CoreIdNull,@m_IOControllerIP+'-'+Convert(varchar(50),@m_IOControllerPort),@m_IOControllerIP+'-'+Convert(varchar(50),@m_IOControllerPort),'Switch',@m_IOControllerPort); Insert into AppServer.NodeConnectRelation(ConnectionId,ParentNodeId,ChildNodeId) values(NEWID(),@m_IOControllerId,@m_SwitchId); Insert into AppServer.NodeDataLinkRelation(DataLinkId,ParentNodeId,ChildNodeId) values(NEWID(),@m_IOControllerId,@m_SwitchId); END END IF (@m_OprationType='ADD') BEGIN Select @m_GlobalId=GlobalId from AppServer.NodeIndex where Code=@m_Code and NodeType='Speaker'; IF @m_GlobalId IS NULL BEGIN set @m_GlobalId=newid(); Insert into AppServer.NodeIndex(GlobalId,CoreNodeId,Code,Name,NodeType,IDNumber) values(@m_GlobalId,@m_CoreId,@m_Code,@m_Name,'Speaker',0); END IF @m_IOControllerPort IS NULL BEGIN set @m_IOControllerPort=0; END IF (@m_AVCodecId IS NOT NULL) BEGIN --添加数据连接关系 IF NOT EXISTS(SELECT * FROM AppServer.NodeConnectRelation where ParentNodeId=@m_AVCodecId and ChildNodeId=@m_GlobalId) BEGIN Insert into AppServer.NodeConnectRelation(ConnectionId,ParentNodeId,ChildNodeId) values(NEWID(),@m_AVCodecId,@m_GlobalId); END --添加物理连接关系 IF NOT EXISTS(SELECT * FROM AppServer.NodeDataLinkRelation where ParentNodeId=@m_AVCodecId and ChildNodeId=@m_GlobalId) BEGIN Insert into AppServer.NodeDataLinkRelation(DataLinkId,ParentNodeId,ChildNodeId) values(NEWID(),@m_AVCodecId,@m_GlobalId); END END --添加防区关系 IF (@m_ZoneId IS NOT NULL) BEGIN IF NOT EXISTS(SELECT * FROM AppServer.NodeInDDZ where ZoneId=@m_ZoneId and NodeId=@m_GlobalId) BEGIN Insert into AppServer.NodeInDDZ(NDLId,ZoneId,NodeId,IsMain) values(newid(),@m_ZoneId,@m_GlobalId,0); END END --添加柱子关系 IF (@m_AnchorPointId IS NOT NULL) BEGIN IF NOT EXISTS(SELECT * FROM AppServer.NodeLocationRelation where AnchorPointId=@m_AnchorPointId and NodeGlobalId=@m_GlobalId) BEGIN Insert into AppServer.NodeLocationRelation(LocationRefId,AnchorPointId,NodeGlobalId) values(NEWID(),@m_AnchorPointId,@m_GlobalId); END END --添加电源关系 IF (@m_SwitchId IS NOT NULL) BEGIN IF NOT EXISTS(SELECT * FROM AppServer.NodePowerSupplyRelation where PowerNodeId=@m_SwitchId and ElectricityNodeId=@m_GlobalId) BEGIN Insert into AppServer.NodePowerSupplyRelation(PowerSupplyId,PowerNodeId,ElectricityNodeId) values(NEWID(),@m_SwitchId,@m_GlobalId); END END END --ELSE IF (@m_OprationType='Modify') --BEGIN --END commit transaction; SET @m_RowNum=@m_RowNum+1; SET @m_ZoneId=NULL; SET @m_AnchorPointId=NULL; SET @m_AVCodecId=NULL; SET @m_IOControllerId=NULL; SET @m_SwitchId=NULL; SET @m_GlobalId=NULL; fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_ZoneCode,@m_AnchorPointCode,@m_AudioCodecIP,@m_IOControllerIP,@m_IOControllerPort,@m_OprationType,@m_OldNodeCode; end close cur_resulttmp deallocate cur_resulttmp; END --Lights begin Set @m_BelongTo='Lights'; Set @m_RowNum=0; declare cur_resulttmp cursor for select Code,Name,CoreId,ZoneCode,AnchorPointCode,IOControllerIP,IOControllerPort,OprationType,OldNodeCode FROM OPENXML (@hdoc, '/NodeRelation/Lights/Light',1) WITH (Code varchar(50),Name varchar(50),CoreId uniqueidentifier,ZoneCode varchar(50),AnchorPointCode varchar(50),IOControllerIP varchar(50),IOControllerPort int,OprationType varchar(50),OldNodeCode varchar(50)); open cur_resulttmp fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_ZoneCode,@m_AnchorPointCode,@m_IOControllerIP,@m_IOControllerPort,@m_OprationType,@m_OldNodeCode; while @@fetch_status=0 begin begin transaction IF @m_CoreId IS NULL BEGIN set @m_CoreId=@m_CoreIdNull; END IF @m_ZoneCode IS NULL BEGIN set @m_ZoneId=NULL; END ELSE BEGIN SELECT @m_ZoneId=ZoneId FROM AppServer.DeviceDefenceZone where Code=@m_ZoneCode; IF @m_ZoneId IS NULL BEGIN Set @ResultValue=-2; Insert into #ImportNodeErrorDataTempTable(ErrorId,[Key],Row,ErrorType,BelongTo) values(newid(),@m_ZoneCode,@m_RowNum,'ForeignkeyNotExist',@m_BelongTo); END END IF @m_AnchorPointCode IS NULL BEGIN set @m_AnchorPointId=NULL; END ELSE BEGIN SELECT @m_AnchorPointId=AnchorPointId FROM AppServer.AnchorPoint where Code=@m_AnchorPointCode; IF @m_AnchorPointId IS NULL BEGIN set @m_AnchorPointId=newid(); Insert into AppServer.AnchorPoint(AnchorPointId,Code,Text) values(@m_AnchorPointId,@m_AnchorPointCode,@m_AnchorPointCode); END END IF @m_IOControllerIP IS NULL BEGIN set @m_IOControllerId=NULL; END ELSE BEGIN SELECT @m_IOControllerId=GlobalId FROM AppServer.NodeIndex where IPAddress=@m_IOControllerIP and NodeType='IOController'; IF @m_IOControllerId IS NULL BEGIN set @m_IOControllerId=newid(); Insert into AppServer.NodeIndex(GlobalId,CoreNodeId,Code,Name,NodeType,IPAddress) values(@m_IOControllerId,@m_CoreIdNull,@m_Code+'-IOController',@m_Code+'-IOController','IOController',@m_IOControllerIP); END END IF (@m_IOControllerPort IS NULL) or (@m_IOControllerId IS NULL) BEGIN set @m_SwitchId=NULL; END ELSE BEGIN Select @m_SwitchId=GlobalId from AppServer.NodeIndex a,AppServer.NodeDataLinkRelation b where a.globalid=b.childnodeid and b.parentnodeid=@m_IOControllerId and a.idnumber=@m_IOControllerPort and nodetype='Switch'; IF (@m_SwitchId IS NULL) BEGIN set @m_SwitchId=NEWID(); Insert into AppServer.NodeIndex(GlobalId,CoreNodeId,Code,Name,NodeType,IDNumber) values(@m_SwitchId,@m_CoreIdNull,@m_IOControllerIP+'-'+Convert(varchar(50),@m_IOControllerPort),@m_IOControllerIP+'-'+Convert(varchar(50),@m_IOControllerPort),'Switch',@m_IOControllerPort); Insert into AppServer.NodeConnectRelation(ConnectionId,ParentNodeId,ChildNodeId) values(NEWID(),@m_IOControllerId,@m_SwitchId); Insert into AppServer.NodeDataLinkRelation(DataLinkId,ParentNodeId,ChildNodeId) values(NEWID(),@m_IOControllerId,@m_SwitchId); END END IF (@m_OprationType='ADD') BEGIN Select @m_GlobalId=GlobalId from AppServer.NodeIndex where Code=@m_Code and NodeType='Light'; IF @m_GlobalId IS NULL BEGIN set @m_GlobalId=newid(); Insert into AppServer.NodeIndex(GlobalId,CoreNodeId,Code,Name,NodeType,IDNumber) values(@m_GlobalId,@m_CoreId,@m_Code,@m_Name,'Light',0); END --添加防区关系 IF (@m_ZoneId IS NOT NULL) BEGIN IF NOT EXISTS(SELECT * FROM AppServer.NodeInDDZ where ZoneId=@m_ZoneId and NodeId=@m_GlobalId) BEGIN Insert into AppServer.NodeInDDZ(NDLId,ZoneId,NodeId,IsMain) values(newid(),@m_ZoneId,@m_GlobalId,0); END END --添加柱子关系 IF (@m_AnchorPointId IS NOT NULL) BEGIN IF NOT EXISTS(SELECT * FROM AppServer.NodeLocationRelation where AnchorPointId=@m_AnchorPointId and NodeGlobalId=@m_GlobalId) BEGIN Insert into AppServer.NodeLocationRelation(LocationRefId,AnchorPointId,NodeGlobalId) values(NEWID(),@m_AnchorPointId,@m_GlobalId); END END --添加电源关系 IF (@m_SwitchId IS NOT NULL) BEGIN IF NOT EXISTS(SELECT * FROM AppServer.NodePowerSupplyRelation where PowerNodeId=@m_SwitchId and ElectricityNodeId=@m_GlobalId) BEGIN Insert into AppServer.NodePowerSupplyRelation(PowerSupplyId,PowerNodeId,ElectricityNodeId) values(NEWID(),@m_SwitchId,@m_GlobalId); END END END --ELSE IF (@m_OprationType='Modify') --BEGIN --END commit transaction; SET @m_RowNum=@m_RowNum+1; SET @m_ZoneId=NULL; SET @m_AnchorPointId=NULL; SET @m_IOControllerId=NULL; SET @m_SwitchId=NULL; SET @m_GlobalId=NULL; SET @m_IOControllerPort=NULL; fetch next from cur_resulttmp into @m_Code,@m_Name,@m_CoreId,@m_ZoneCode,@m_AnchorPointCode,@m_IOControllerIP,@m_IOControllerPort,@m_OprationType,@m_OldNodeCode; end close cur_resulttmp deallocate cur_resulttmp; END EXEC sp_xml_removedocument @hdoc Select * From #ImportNodeErrorDataTempTable; DROP TABLE #ImportNodeErrorDataTempTable; IF (@WriteToLog=1) BEGIN EXEC AppServer.SaveSystemEventLog2 @ClientId=@ClientId,@EventType='CLIENT_ImportNodeZoneRelationData',@TimeCreated=@TimeCreated,@EventData=@RelationDataXML END end
监控节点 xml写入数据库 存储过程的更多相关文章
- log4j.xml写入数据库,只有SQL和参数,无其他信息
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE log4j:configuration SY ...
- 如何将XML文件写入数据库
将xml文件转成string public string XMLDocumentToString(XmlDocument doc) { MemoryStream stream = new Memory ...
- php通过存储过程传入汉字参数并写入数据库
写入数据库,汉字为???样式的乱码,后根据网上介绍的方法,参数前加N,数据库汉字内容变成空白. 解决方法,在PHP中先转为base64,再在mysql中base64解码,前提先保证mysql中有bas ...
- SQLSERVER监控复制并使用数据库邮件功能发告警邮件
SQLSERVER监控复制并使用数据库邮件功能发告警邮件 最近熬出病来了,都说IT行业伤不起,不说了,说回今天的正题 正题 上个月月底的时候因为要搬迁机房,需要将一个数据信息数据库先搬到我们的机房,然 ...
- 互联网级监控系统必备-时序数据库之Influxdb集群及踩过的坑
上篇博文中,我们介绍了做互联网级监控系统的必备-Influxdb的关键特性.数据读写.应用场景: 互联网级监控系统必备-时序数据库之Influxdb 本文中,我们介绍Influxdb数据库集群的搭建, ...
- 批量插入数据, 将DataTable里的数据批量写入数据库的方法
大量数据导入操作, 也就是直接将DataTable里的内容写入到数据库 通用方法: 拼接Insert语句, 好土鳖 1. MS Sql Server: 使用SqlBulkCopy 2. MySql ...
- 【繁星Code】如何在EF将实体注释写入数据库中
最近在项目中需要把各个字段的释义写到数据库中,该项目已经上线很长时间了,数据库中的字段没有上千也有上百个,要是一个项目一个项目打开然后再去找对应字段查看什么意思,估计要到明年过年了.由于项目中使用En ...
- logback日志写入数据库(mysql)配置
如题 建议将日志级别设置为ERROR.这样可以避免存储过多的数据到数据中. 1 logback 配置文件(如下) <?xml version="1.0" encoding ...
- (OAF)jdeveloper集成log4j并将日志输出到指定文件并写入数据库
参考: How to configure Log4j in JDev 11g Ever wanted to use log4j in your adf project ? Well though Or ...
随机推荐
- 单机,伪分布式,完全分布式-----搭建Hadoop大数据平台
Hadoop大数据——随着计算机技术的发展,互联网的普及,信息的积累已经到了一个非常庞大的地步,信息的增长也在不断的加快.信息更是爆炸性增长,收集,检索,统计这些信息越发困难,必须使用新的技术来解决这 ...
- c++多线程基础2(命名空间 this_thread)
整理自:zh.cppreference.com/w/cpp/thread std::this_thread::yield: 定义于头文件 <thread> 函数原型:void yield( ...
- spring 学习(一):使用 intellijIDEA 创建 maven 工程进行 Spring ioc 测试
spring学习(一):使用 intellijIDEA 创建 maven 工程进行 Spring ioc 测试 ioc 概念 控制反转(Inversion of Control,缩写为IOC),是面向 ...
- Django 使用第三方服务发送电子邮件
在 Django 网站中使用 mailgun 的邮件收发服务. 1.在 mailgun 官网上注册个账号(免费,免费账号每个月有10000条收发邮件的服务,对我来说已经完全够用了),注册完成后界面如图 ...
- 「BZOJ1433」[ZJOI2009] 假期的宿舍(二分图,网络流)
题目描述 学校放假了 · · · · · · 有些同学回家了,而有些同学则有以前的好朋友来探访,那么住宿就是一个问题.比如 A 和 B 都是学校的学生,A 要回家,而 C 来看B,C 与 A 不认识. ...
- jquery.from帮助类
/** * 将form里面的内容序列化成json * 相同的checkbox用分号拼接起来 * @param {obj} 需要拼接在后面的json对象 * @method serializeJson ...
- Qt 学习之路 2(38):存储容器
Qt 学习之路 2(38):存储容器 豆子 2013年1月14日 Qt 学习之路 2 38条评论 存储容器(containers)有时候也被称为集合(collections),是能够在内存中存储其它特 ...
- C++_基础3-循环和关系表达式
这一部分内容节选自<C++ Primer Plus>的第五章 程序需要有执行重复的操作和进行决策的工具. ========================================= ...
- C# 关于时区的操作
有关时区自动更新的 在注册表以下路径,start键值3,4表示自动/不自动更新 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tza ...
- 04-树6 Complete Binary Search Tree (30 分)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...