You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

69 lines
3.0 KiB

#!/usr/bin/php -q
<?php
include('bd.php');
include('funcoes/shared.php');
include('util/util.php');
$query = "drop table if exists vds_chamadas_confere;
drop table if exists vds_protcolos_confere;
select * into vds_protcolos_confere from vds_protcolos a where coalesce(a.prt_proto_parceiro, '') <> '' and exists(select '' from vds_ver_proto where proto = a.prt_proto_parceiro);
create index \"idx_vds_protcolos_confere_emp_uid\" on vds_protcolos_confere(emp_id, uid);
create index \"idx_vds_protcolos_confere_prt_proto\" on vds_protcolos_confere(prt_proto_parceiro);
select * into vds_chamadas_confere from vds_chamadas a where exists(select '' from vds_protcolos_confere where emp_id = a.emp_id and uid = a.uid);
create index \"idx_vds_chamadas_confere_emp_uid\" on vds_chamadas_confere(emp_id, uid);
select b.emp_id, d.emp_razao_social, d.emp_cnpj, d.emp_vpn, d.emp_diretorio_ftp, b.uid, b.data_reg::date as data, a.proto, a.existe, a.file_name, a.id_proto, c.chm_calldate,
'/hdaux/ftp/algar/audios/' || d.emp_diretorio_ftp || '/' || to_char(c.chm_calldate::date, 'yyyy/mm/dd') || '/' ||b.prt_proto_parceiro || '.WAV' as origem,
'/hdaux/ftp/algar/audios/' || d.emp_diretorio_ftp || '/' || to_char(c.chm_calldate::date, 'yyyy/mm/dd') || '/' || b.prt_proto_parceiro || '_' || b.uid || '.WAV' as destino
from vds_ver_proto a
inner join vds_protcolos_confere b on b.prt_proto_parceiro = a.proto
inner join (select emp_id, chm_calldate, uid from vds_chamadas_confere where chm_data_bilhete >= '2020-01-01') c on c.emp_id = b.emp_id and c.uid = b.uid
inner join vds_empresas d on d.emp_id = c.emp_id;";
$result = pg_query($query);
while ($dados = pg_fetch_array($result, null, PGSQL_ASSOC)) {
$id = $dados["id_proto"];
$origem = $dados["origem"];
$destino = $dados["destino"];
$controle = 9;
$arq = 'NE';
if (file_exists($destino)) {
$controle = 1;
$arq = $destino;
} else if (file_exists($origem)) {
$controle = 2;
$arq = $origem;
}
$query = "update vds_ver_proto set existe = '{$controle}', file_name = '{$arq}' where id_proto = '{$id}'\n";
@pg_query($query);
echo $query;
usleep(300);
}
echo "Fim.\n";
//exec("chown -R algar:algar /hdaux");
/*
select a.id_unk,
a.emp_id,
a.chm_calldate,
'/hdaux/ftp/algar/audios/' || b.emp_diretorio_ftp || '/' || to_char(a.chm_calldate::date, 'yyyy/mm/dd') || '/' || c.prt_proto_parceiro || '.WAV' as origem,
'/hdaux/ftp/algar/audios/' || b.emp_diretorio_ftp || '/' || to_char(a.chm_calldate::date, 'yyyy/mm/dd') || '/' || c.prt_proto_parceiro || '_' || a.uid || '.WAV' as destino
from vds_chamadas a, vds_empresas b, vds_protcolos c, vds_classificacoes d
where b.emp_id = a.emp_id
and c.uid = a.uid
and d.uid = c.uid
and a.chm_data_bilhete >= (now()::date -3)
and a.chm_data_bilhete < (now()::date)
and coalesce(a.chm_controle, 9) = 9
and d.clas_descricao = 'VENDA'
and c.prt_proto_parceiro <> ''
*/