Browse Source

Foi acrescentado uma flag na tabela ast_bilhetes para previnir que chamadas sejam importadas antes de ser realizado a correcao do numero de destino

1.8-dev
douglas.strappasson 1 year ago
parent
commit
f1c2155feb
  1. 38
      asterisk/var_lib_asterisk/scripts/manutencaoDB/importaBilhetes.php
  2. 7
      projeto/base/sql/versao-1.8.1.sql

38
asterisk/var_lib_asterisk/scripts/manutencaoDB/importaBilhetes.php

@ -148,8 +148,9 @@ function ImportaAstEventosDacs($dbcon) {
function ImportaAstBilhetes($dbcon) { function ImportaAstBilhetes($dbcon) {
global $numBilhetes; global $numBilhetes;
$query = "drop table if exists tb_parametros; $query = "drop table if exists tb_parametros;
create temporary table tb_parametros as create temporary table tb_parametros as
select (select min(id) mun_padrao from pbx_municipios where to_ascii(nome_localidade) = (select to_ascii(prm_mun_padrao) from pbx_parametros) and uf = (select prm_uf_padrao from pbx_parametros)) as mun_padrao, (select prm_ddd_padrao from pbx_parametros) as prm_ddd_padrao; select (select min(id) mun_padrao from pbx_municipios where to_ascii(nome_localidade) = (select to_ascii(prm_mun_padrao) from pbx_parametros)
and uf = (select prm_uf_padrao from pbx_parametros)) as mun_padrao, (select prm_ddd_padrao from pbx_parametros) as prm_ddd_padrao;
-- MELHOR DESEMPENHO EM PESQUISA DE MUNICIPIO PARA CELULAR -- MELHOR DESEMPENHO EM PESQUISA DE MUNICIPIO PARA CELULAR
drop table if exists tb_municipios; create temporary table tb_municipios as select min(id) as id, codigo_ddd from pbx_municipios group by codigo_ddd; drop table if exists tb_municipios; create temporary table tb_municipios as select min(id) as id, codigo_ddd from pbx_municipios group by codigo_ddd;
@ -166,10 +167,8 @@ select (select min(id) mun_padrao from pbx_municipios where to_ascii(nome_local
when(33)then (select mun_padrao from tb_parametros) when(33)then (select mun_padrao from tb_parametros)
when(34)then (select min(id) from tb_municipios where codigo_ddd = ast.prefixo) when(34)then (select min(id) from tb_municipios where codigo_ddd = ast.prefixo)
else 0 end else 0 end
end as id_municipio end as id_municipio
from ( from ( select *,
select *,
case prf.tipo_chamada case prf.tipo_chamada
when(21)then strtoint(((select prm_ddd_padrao::text from tb_parametros) || substring(prf.dst,1,4))) when(21)then strtoint(((select prm_ddd_padrao::text from tb_parametros) || substring(prf.dst,1,4)))
when(22)then strtoint(substring(substring(prf.dst,'..........$'), 1,6)) when(22)then strtoint(substring(substring(prf.dst,'..........$'), 1,6))
@ -183,10 +182,10 @@ select (select min(id) mun_padrao from pbx_municipios where to_ascii(nome_local
0 0
end as prefixo, end as prefixo,
strtoint(substring(prf.dst,'....$')) as sufixo, case when(exists(select '' from ast_eventos_dacs where uid2 = prf.uniqueid))then 'S' else 'N' end as flag_fila strtoint(substring(prf.dst,'....$')) as sufixo, case when(exists(select '' from ast_eventos_dacs where uid2 = prf.uniqueid))then 'S' else 'N' end as flag_fila
from ( from (
select id_bilhetes, direcao, select id_bilhetes, direcao,
case direcao case direcao
when('E')then sonumero(src) when('E')then sonumero(src)
when('S')then sonumero(dst) when('S')then sonumero(dst)
else else
'-' '-'
@ -195,24 +194,23 @@ select (select min(id) mun_padrao from pbx_municipios where to_ascii(nome_local
case when(direcao = 'I')then 1 case when(direcao = 'I')then 1
else else
tipoligacao(trim(case when(direcao = 'E')then sonumero(src) else sonumero(dst) end), case when(direcao = 'E')then true else false end) tipoligacao(trim(case when(direcao = 'E')then sonumero(src) else sonumero(dst) end), case when(direcao = 'E')then true else false end)
end as tipo_chamada end as tipo_chamada
from ast_bilhetes a from ast_bilhetes a
where not exists(select '' from pbx_bilhetes where id_bilhetes = a.id_bilhetes) where not exists(select '' from pbx_bilhetes where id_bilhetes = a.id_bilhetes)
) as prf and a.corrige_numero_destino = TRUE
) as prf
) as ast; ) as ast;
create index \"tb_tipo_ligacaoIdBilhetes\" on tb_tipo_ligacao(id_bilhetes); create index \"tb_tipo_ligacaoIdBilhetes\" on tb_tipo_ligacao(id_bilhetes);
insert insert into pbx_bilhetes(
into pbx_bilhetes( id_bilhetes, calldate, clid, dst, dcontext, channel, dstchannel, lastapp, lastdata, duration, billsec, disposition, tipo_chamada, accountcode, uniqueid, userfield, data_bilhete, id_municipio, ramal_origem, fora_horario, flag_fila, src)
id_bilhetes, calldate, clid, dst, dcontext, channel, dstchannel, lastapp, lastdata, duration, billsec, disposition, tipo_chamada, accountcode, uniqueid, userfield, data_bilhete, id_municipio, ramal_origem, fora_horario, flag_fila, src) select a.id_bilhetes, calldate, clid, a.dst, dcontext, channel, dstchannel, lastapp, lastdata, duration, billsec, disposition, b.tipo_chamada, accountcode, a.uniqueid, userfield, calldate::date, b.id_municipio, ramal_origem, fora_horario, b.flag_fila, CASE WHEN(direcao = 'S')THEN coalesce(ramal_origem, src) ELSE src END AS src
select a.id_bilhetes, calldate, clid, a.dst, dcontext, channel, dstchannel, lastapp, lastdata, duration, billsec, disposition, b.tipo_chamada, accountcode, a.uniqueid, userfield, calldate::date, b.id_municipio, ramal_origem, fora_horario, b.flag_fila, CASE WHEN(direcao = 'S')THEN coalesce(ramal_origem, src) ELSE src END AS src from ast_bilhetes a, tb_tipo_ligacao b
from ast_bilhetes a, tb_tipo_ligacao b where b.id_bilhetes = a.id_bilhetes;
where b.id_bilhetes = a.id_bilhetes;
update ast_bilhetes a update ast_bilhetes a
set tipo_chamada = b.tipo_chamada, set tipo_chamada = b.tipo_chamada,
flag_fila = b.flag_fila, flag_fila = b.flag_fila,
id_municipio = b.id_municipio id_municipio = b.id_municipio
from tb_tipo_ligacao b from tb_tipo_ligacao b
@ -275,7 +273,7 @@ function CorrigeNumeroDestino($dbcon) {
) AS bilhetes_bilhetes GROUP BY uniqueid; ) AS bilhetes_bilhetes GROUP BY uniqueid;
UPDATE ast_bilhetes UPDATE ast_bilhetes
SET dst = ast_corrige_destino.dst, amaflags = 99 SET dst = ast_corrige_destino.dst, amaflags = 99, corrige_numero_destino = TRUE
FROM ast_corrige_destino FROM ast_corrige_destino
WHERE ast_bilhetes.uniqueid = ast_corrige_destino.uid WHERE ast_bilhetes.uniqueid = ast_corrige_destino.uid
AND coalesce(ast_corrige_destino.dst, '') <> '';"; AND coalesce(ast_corrige_destino.dst, '') <> '';";

7
projeto/base/sql/versao-1.8.1.sql

@ -1,3 +1,8 @@
-- Correcao dados tipo preco -- Correcao dados tipo preco
update pbx_tarifa_tipo_preco set ttp_descricao = 'Móvel Local' where ttp_id = 'vc3'; update pbx_tarifa_tipo_preco set ttp_descricao = 'Móvel Local' where ttp_id = 'vc3';
update pbx_tarifa_tipo_preco set ttp_descricao = 'Móvel Interurbano' where ttp_id = 'vc4'; update pbx_tarifa_tipo_preco set ttp_descricao = 'Móvel Interurbano' where ttp_id = 'vc4';
-- acrescenta flag que identifica se o numero de destino foi corrigido no script importaBilhetes através da funcao CorrigeNumeroDestino
-- o objetivo é evitar que ligações sejam gravadas na tabela pbx_bilhetes com o numero de destino incorreto.
ALTER TABLE ast_bilhetes
ADD corrige_numero_destino BOOLEAN DEFAULT FALSE;
Loading…
Cancel
Save