SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_RDS_RecipeSignature]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[sp_RDS_RecipeSignature]
GO
-- =============================================
-- Author:      Vitacore (с)
-- Create date: 2018-07-02
-- Description: Отправка XML рецепта
-- =============================================
CREATE PROCEDURE [dbo].[sp_RDS_RecipeSignature]
    @ID uniqueidentifier = null,
    @User uniqueidentifier = null,
    @QueueName varchar(100) = 'RDSSync'
AS
BEGIN

    SET NOCOUNT ON;

    -- Отправка
    INSERT INTO [AKUZ].[T_RABBIT_SEND_OBJECT]
        ([RabbitSendObjectID] ,[QueueName] ,[Content] ,[MessageID] ,[Headers] ,[ContentEncoding] ,[Type] ,[UserID] ,[State] ,[CreateDateTime] ,[OwnerID],[CorrelationId])
    select NewID()--(<RabbitSendObjectID, uniqueidentifier,>
          ,@QueueName--,<QueueName, varchar(255),>
          ,dbo.ConvertTextToBinaryZip(rs.XmlData, '')--,<Content, text,>
          ,null--,<MessageID, varchar(255),>
          ,null--,<Headers, varchar(255),>
          ,'utf-8'--,<ContentEncoding, varchar(255),>
          ,case
				when rs.DataState = 1 then 'SIGNED_RECIPE'
				else 'RECIPE'
		  end--,<Type, varchar(255),>
          ,ISNULL(@User, rs.CreatedUser)--,<UserID, varchar(255),>
          ,0--,<State, int,>)
          ,rs.SignatureDateTime--,<CreateDateTime, datetime,>)
          ,rs.RecipeSignatureID--,<OwnerID, varchar(255),>
          ,rs.RecipeSignatureID--,<CorrelationId, varchar(255),>
	from AKUZ.T_RECIPE_SIGNATURE rs
	where rs.RecipeSignatureID = @ID
END
GO