Skip to content

Commit

Permalink
fix: prevent duplicate TransacaoView
Browse files Browse the repository at this point in the history
  • Loading branch information
yxuo committed Jul 22, 2024
1 parent bd9c9be commit c9f74ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/bigquery/repositories/bigquery-transacao.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export class BigqueryTransacaoRepository {
t.id_operadora,
o.documento AS operadoraCpfCnpj,
c.cnpj AS consorcioCnpj,
(${qArgs.countQuery}) AS count,
'ok' AS status
FROM \`${qArgs.transacao}\` t\n
LEFT JOIN \`rj-smtr.cadastro.operadoras\` o ON o.id_operadora = t.id_operadora
Expand All @@ -95,7 +94,9 @@ export class BigqueryTransacaoRepository {
'\n' +
qArgs.joinIntegracao +
'\n' +
(qArgs.qWhere.length ? `WHERE ${qArgs.qWhere}\n` : '') +
(qArgs.qWhere.length
? `WHERE (${qArgs.qWhere} AND o.documento = '59675748753')\n`
: '') +
`\nORDER BY datetime_processamento DESC` +
(qArgs?.limit !== undefined ? `\nLIMIT ${qArgs.limit + 1}` : '') +
(qArgs?.offset !== undefined ? `\nOFFSET ${qArgs.offset}` : '');
Expand All @@ -108,10 +109,8 @@ export class BigqueryTransacaoRepository {
// Remove unwanted keys and remove last item (all null if empty)
let transacoes: BigqueryTransacao[] = queryResult.map((i) => {
delete i.status;
delete i.count;
return i;
});
transacoes.pop();
transacoes = this.mapBqTransacao(transacoes);

return {
Expand Down
5 changes: 3 additions & 2 deletions src/cnab/cnab.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { forChunk, getChunks } from 'src/utils/array-utils';
import { CustomLogger } from 'src/utils/custom-logger';
import { yearMonthDayToDate } from 'src/utils/date-utils';
import { asNumber } from 'src/utils/pipe-utils';
import { Between, DeepPartial } from 'typeorm';
import { Between, DeepPartial, In } from 'typeorm';
import { ArquivoPublicacao } from './entity/arquivo-publicacao.entity';
import { ClienteFavorecido } from './entity/cliente-favorecido.entity';
import { ItemTransacaoAgrupado } from './entity/pagamento/item-transacao-agrupado.entity';
Expand Down Expand Up @@ -179,7 +179,8 @@ export class CnabService {
) {
continue;
}
await this.transacaoViewService.save(tr);
const existing = await this.transacaoViewService.find({ idTransacao: tr.idTransacao });
await this.transacaoViewService.saveMany(existing, [tr]);
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/cron-jobs/cron-jobs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,19 @@ export class CronJobsService implements OnModuleInit, OnModuleLoad {
}

async onModuleLoad() {
await this.updateTransacaoView();
const THIS_CLASS_WITH_METHOD = 'CronJobsService.onModuleLoad';
// await this.saveTransacoesJae1(0, 'Todos', new Date());
// await this.saveAndSendRemessa(
// new Date(),
// false,
// true,
// 101,
// 0,
// new Date('2024-07-05'),
// );
// await this.cnabService.updateTransacaoViewBigquery();
// await this.cnabService.compareTransacaoViewPublicacao(14);

this.jobsConfig.push(
{
Expand Down Expand Up @@ -230,8 +242,8 @@ export class CronJobsService implements OnModuleInit, OnModuleLoad {
*/
async updateTransacaoView() {
const METHOD = this.updateTransacaoView.name;
const startDate = subDays(startOfDay(new Date()), 1);
const endDate = subDays(endOfDay(new Date()), 1);
const startDate = subDays(startOfDay(new Date()), 30);
const endDate = subDays(endOfDay(new Date()), 0);

try {
this.logger.log('Iniciando tarefa.', METHOD);
Expand Down

0 comments on commit c9f74ae

Please sign in to comment.