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_2025
@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
and isnull(convert(varchar,edictos_ia.contenido_archivo),'') != ''
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),'') != ''
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
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
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.openai_edictos_dia_TBB_2025
@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
and isnull(convert(varchar,edictos_ia.contenido_archivo),'') != ''
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),'') != ''
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
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
END
GO
Depends On
2Used By
No items found