dbo.openai_edictos_dia_TBB

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

6
Name Data Type Length Description
@accion varchar 20
@fecha date 3
@fecha_hasta date 3
@userID int 4
@cliente int 4
@topReg int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

CREATE OR ALTER PROCEDURE dbo.openai_edictos_dia_TBB
    @accion VARCHAR(20),
    @fecha DATE,
    @fecha_hasta DATE = NULL,
    @userID INT,
    @cliente INT = NULL,
    @topReg INT = 1000 
AS
BEGIN
    SET @accion = UPPER(@accion)

    IF (@fecha_hasta IS NULL)  
    BEGIN
        SET @fecha_hasta = getdate()
    END
    
    IF(@accion = 'BUSQUEDA_DEFAULT')
    BEGIN
        UPDATE edictos_ia 
      SET user_id_taken = @userID, started_taken = getdate() 
     WHERE id_fide IN (   SELECT TOP (@topReg) id_fide FROM edictos_ia 
         WHERE (user_id_taken iS NULL OR user_id_taken= @userID) AND procesado = 0 -- AND finished_taken IS NULL  
           and isnull(convert(varchar,edictos_ia.contenido_archivo),'') != ''
        AND convert(DATE,created) BETWEEN @fecha AND @fecha_hasta )

        SELECT TOP (@topReg) fecha_publicacion, fuente, id_fide, contenido_archivo 
    FROM edictos_ia 
         WHERE user_id_taken = @userID AND procesado = 0

    END 

    IF(@accion = 'BUSQUEDA_CRON')
    BEGIN  
 /*
         SELECT 
             TOP (@topReg) fecha_publicacion, fuente, id_fide, contenido_archivo 
         FROM 
             edictos_ia 
         WHERE 
             convert(DATE,created) = @fecha  
  and isnull(convert(varchar,edictos_ia.contenido_archivo),'') != ''
     */


   UPDATE edictos_ia 
      SET user_id_taken = @userID, started_taken = getdate() 
     WHERE id_fide IN (   SELECT TOP (@topReg) id_fide FROM edictos_ia 
         WHERE (user_id_taken iS NULL OR user_id_taken= @userID) AND procesado = 0 -- AND finished_taken IS NULL  
           and isnull(convert(varchar,edictos_ia.contenido_archivo),'') != ''
        AND convert(DATE,created) = @fecha   )


        SELECT 
            TOP (@topReg) fecha_publicacion, fuente, id_fide, contenido_archivo 
        FROM 
            edictos_ia 
        WHERE 
             convert(DATE,created) = @fecha  
    and user_id_taken = @userID AND procesado = 0
   

 END

    IF(@accion = 'EDICTOS_POR_CLIENTE')
    BEGIN 
  -- marco los cuits que voy a tomar de edictos_cuits_a_procesar    
        UPDATE edictos_cuits_a_procesar 
        SET edictos_cuits_a_procesar.user_id_taken = @userID, edictos_cuits_a_procesar.taken_date=getdate()
        WHERE id IN (SELECT TOP (@topReg) id 
                 FROM edictos_cuits_a_procesar where cliente = @cliente 
          and procesado = 0 
       and (edictos_cuits_a_procesar.user_id_taken iS NULL OR edictos_cuits_a_procesar.user_id_taken= @userID)
     order by id)
 
  -- marco los edictos que voy a tomar de edictos_ia, de los cuits marcados  
  UPDATE edictos_ia 
  SET user_id_taken = @userID, started_taken = getdate() 
     WHERE id_fide IN (   SELECT id_fide FROM edictos_ia 
         WHERE documento_soc in (select cuit 
                                   from [edictos_cuits_a_procesar] cuits 
                                  where cuits.cliente = @cliente 
                  and cuits.procesado = 0 
               and cuits.user_id_taken = @userID) 
           and (edictos_ia.user_id_taken IS NULL OR edictos_ia.user_id_taken= @userID) 
        and edictos_ia.procesado = 0 
        and isnull(convert(varchar,edictos_ia.contenido_archivo),'') != '')

  -- select de los edictos marcados 
        SELECT documento_soc, fecha_publicacion, fuente, id_fide, contenido_archivo 
          FROM edictos_ia 
          WHERE edictos_ia.user_id_taken = @userID
   and edictos_ia.procesado = 0 
      and isnull(convert(varchar,edictos_ia.contenido_archivo),'') != ''
   and documento_soc in (select cuit 
               from [edictos_cuits_a_procesar] cuits 
               where cuits.cliente = @cliente 
          and cuits.procesado = 0 --> se lo podemos sacar, por si se corto el proceso que habia marcado edictos_cuits_a_procesar como procesado = 1 pero todavia no esta procesado en edictos_ia
          and cuits.user_id_taken = @userID) 
   
        order by fecha_publicacion
  
  -- marco como procesados los cuits a procesar marcados
  UPDATE edictos_cuits_a_procesar
           SET procesado = 1 
         WHERE cliente = @cliente and procesado = 0 and user_id_taken = @userID

    END


 IF(@accion = 'BUSQUEDA_VACIOS')
    BEGIN 
  /*UPDATE edictos_ia 
      SET user_id_taken = @userID, started_taken = getdate() 
    WHERE id_fide IN (   SELECT TOP (@topReg) id_fide FROM edictos_ia 
     WHERE (user_id_taken iS NULL /*OR user_id_taken= @userID*/
) AND procesado = 0 
       and isnull(convert(varchar,edictos_ia.contenido_archivo),'') != ''
   and ISNULL(documento_soc,'') = '' 
   and ISNULL(razon_social,'') = '' 
   and ISNULL(fuente,'') != 'SAN LUIS'
   and ISNULL(fuente,'') != 'CARGA BACKEND'
   ORDER BY id_fide) 
  
          SELECT TOP (@topReg) fecha_publicacion, fuente, id_fide, contenido_archivo 
           FROM edictos_ia 
          WHERE user_id_taken = @userID AND procesado = 0
   */

  declare @procesar table (id int) 
  INSERT INTO @procesar (id)
    SELECT TOP (@topReg) id_fide FROM edictos_ia 
         WHERE (user_id_taken iS NULL) AND procesado = 0 and isnull(enviado_procesar,0) = 0
           and isnull(convert(varchar,edictos_ia.contenido_archivo),'') != ''
        and ISNULL(documento_soc,'') = '' 
        and ISNULL(razon_social,'') = '' 
        and ISNULL(fuente,'') != 'SAN LUIS'
        and ISNULL(fuente,'') != 'CARGA BACKEND'
        ORDER BY id_fide


  UPDATE edictos_ia 
     SET user_id_taken = @userID, started_taken = getdate(), enviado_procesar = 1
   WHERE id_fide IN (select id from @procesar) 
 
        SELECT fecha_publicacion, fuente, id_fide, contenido_archivo 
          FROM edictos_ia 
         WHERE id_fide IN (select id from @procesar) 


 END

END

GO

Used By

No items found