133 lines
3.9 KiB
Transact-SQL
133 lines
3.9 KiB
Transact-SQL
-- Schema: C6MartPeriodico
|
|
-- Stored Procedure: SP_PreTotaliReportGenerazioneZip
|
|
|
|
|
|
|
|
|
|
--exec C6MartPeriodico.SP_PreTotaliReportGenerazioneZip 960, 1
|
|
|
|
CREATE procedure [C6MartPeriodico].[SP_PreTotaliReportGenerazioneZip]
|
|
@reportPerZip int,
|
|
@isLotto1 int = 0
|
|
AS
|
|
|
|
set nocount on
|
|
|
|
create table #result (
|
|
totReportGenerati int,
|
|
isUltimoZip int
|
|
)
|
|
|
|
declare @totReportGenerati int
|
|
declare @isUltimoZip int
|
|
|
|
declare @KO int
|
|
set @KO = 0
|
|
declare @err varchar(500)
|
|
set @err = ''
|
|
|
|
--exec [C6MartPeriodico].[SP_TotaliReportGenerazioneZip] 960, 1
|
|
|
|
insert into #result exec [C6MartPeriodico].[SP_TotaliReportGenerazioneZip] @reportPerZip, @isLotto1
|
|
|
|
select @totReportGenerati = totReportGenerati, @isUltimoZip = isUltimoZip from #result
|
|
|
|
if @isLotto1 = 1
|
|
begin
|
|
if @isUltimoZip = 2
|
|
begin
|
|
if (select count(*) from [C6MartPeriodico].WHITELIST_ZIP WHERE Pacchetto_Zip is null) = 0
|
|
begin
|
|
set @KO = 1
|
|
set @err = 'Nel primo lotto non c''è da fare il file Approval, ma la procedura ''SP_TotaliReportGenerazioneZip'' ha restituito lo stato 2'
|
|
end
|
|
end
|
|
if @isUltimoZip = 1
|
|
begin
|
|
if (select count(*) from [C6MartPeriodico].WHITELIST_ZIP WHERE Pacchetto_Zip is null) > 0
|
|
begin
|
|
set @KO = 1
|
|
set @err = 'Nel primo lotto c''è da fare il file Approval, ma la procedura ''SP_TotaliReportGenerazioneZip'' ha restituito lo stato 1'
|
|
end
|
|
end
|
|
if @isUltimoZip not in (1, 2)
|
|
begin
|
|
set @KO = 1
|
|
set @err = 'Nel primo lotto, la procedura ''SP_TotaliReportGenerazioneZip'' ha restituito lo stato inconsistente ' + convert(varchar(10), @isUltimoZip)
|
|
end
|
|
end
|
|
else
|
|
begin
|
|
if @isUltimoZip <> 1
|
|
begin
|
|
set @KO = 1
|
|
set @err = 'Per il lotto successivo, la procedura ''SP_TotaliReportGenerazioneZip'' ha restituito lo stato inconsistente ' + convert(varchar(10), @isUltimoZip)
|
|
end
|
|
end
|
|
|
|
print '@isLotto1 = ' + convert(varchar(10), @isLotto1)
|
|
print '@isUltimoZip = ' + convert(varchar(10), @isUltimoZip)
|
|
print '@KO = ' + convert(varchar(10), @KO)
|
|
print '@err = ''' + @err + ''''
|
|
|
|
if @KO = 0
|
|
begin
|
|
|
|
if @isUltimoZip in (1, 2)
|
|
begin
|
|
declare @num_stato_report_1 int
|
|
declare @num_elab_4 int
|
|
|
|
select @num_stato_report_1 = COUNT(*)
|
|
from C6MartPeriodico.controllo_trimestrale
|
|
where stato_report in (1) --1
|
|
|
|
select @num_elab_4 = COUNT(*)
|
|
from C6MartPeriodico.CRUSCOTTO_CONTRATTISEI
|
|
where elab in(4)
|
|
|
|
if @num_stato_report_1 <> @num_elab_4
|
|
begin
|
|
set @KO = 1
|
|
set @err = 'Controllare gli stati: Controllo_Trimestrale ha ' + convert(varchar(100), @num_stato_report_1) + ' report con stato_report = 1, Cruscotto_ContrattiSEI ha ' + convert(varchar(100), @num_elab_4) + ' con elab = 4'
|
|
end
|
|
end
|
|
end
|
|
|
|
if @KO = 0
|
|
begin
|
|
|
|
print 'Controllo su tabella C6MartPeriodico.Gestione_Zip_FTP'
|
|
declare @maxIdElaborazione int
|
|
|
|
select @maxIdElaborazione = max(FkIdElaborazioneZip) from [C6MartPeriodico].[gestione_zip_ftp]
|
|
|
|
if( select count(*)
|
|
from (
|
|
SELECT TOP (1) [id]
|
|
,[nomefile]
|
|
,[dataInvio]
|
|
,[flagInvio]
|
|
,[nomeCartella]
|
|
,[ID_ELAB]
|
|
,[DateCopyToSend]
|
|
,[FKIDElaborazioneZIP]
|
|
FROM [C6MartPeriodico].[gestione_zip_ftp]
|
|
where
|
|
FkIdElaborazioneZip = @maxIdElaborazione
|
|
and
|
|
DateCopyToSend is null
|
|
order by 1 desc, 3 desc) a
|
|
) > 0
|
|
begin
|
|
set @KO = 1
|
|
set @err = 'Situazione incongruente sulla tabella ''[C6MartPeriodico].[gestione_zip_ftp]'''
|
|
end
|
|
end
|
|
|
|
if @KO = 0
|
|
begin
|
|
print 'Controllo su tabella C6MartPeriodico.Elaborazioni_ZIP'
|
|
|
|
--modifica del 17/10/2018 per gestire il caso in cui il file di approval è stato inviato ma l'intero
|