Skip to content

Commit

Permalink
Ajuste sincronismo
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfl2007 committed Sep 20, 2024
1 parent d313de7 commit f998520
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/cron-jobs/cron-jobs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export class CronJobsService {
/**
* Gera na quinta, paga na sexta.
*/
//TODO: GERAR PAGAMENTO SEXTA
async generateRemessaEmpresa(debug?: ICronjobDebug) {
const METHOD = 'generateRemessaEmpresa';
try {
Expand Down Expand Up @@ -390,7 +391,13 @@ export class CronJobsService {
const startDate = subDays(new Date(), 30);
const today = new Date();
this.logger.log(`Sincronizando TransacaoViews entre ${formatDateYMD(startDate)} e ${formatDateYMD(today)}`, method);
await this.cnabService.syncTransacaoViewOrdemPgto({ dataOrdem_between: [startDate, today] });
const consorcios:string[]=[];
if(method === 'generateRemessaVan'){
consorcios.push('STPC');
consorcios.push('STPL');
}

await this.cnabService.syncTransacaoViewOrdemPgto({ consorcio: consorcios , dataOrdem_between: [startOfDay(startDate),endOfDay(today)] });
this.logger.log(`Trefa finalizada com sucesso.`, method);
} catch (error) {
this.logger.error('Erro ao executar tarefa.', error?.stack, method);
Expand Down
1 change: 1 addition & 0 deletions src/transacao-view/interfaces/sync-form-ordem.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface ISyncOrdemPgto {
/** [startDate, endDate] */
dataOrdem_between?: [Date, Date];
consorcio?:string[];
nomeFavorecido?: string[];
}
15 changes: 11 additions & 4 deletions src/transacao-view/transacao-view.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IPreviousDaysArgs } from './interfaces/previous-days-args';
import { ISyncOrdemPgto } from './interfaces/sync-form-ordem.interface';
import { ITransacaoView, TransacaoView } from './transacao-view.entity';
import { formatDateYMD } from 'src/utils/date-utils';
import { endOfDay, startOfDay } from 'date-fns';

export interface TransacaoViewFindRawOptions {
where: {
Expand Down Expand Up @@ -66,10 +67,16 @@ export class TransacaoViewRepository {
public async syncOrdemPgto(args?: ISyncOrdemPgto) {
const METHOD = 'syncOrdemPgto';
const where: string[] = [];
if (args?.dataOrdem_between) {
if (args?.dataOrdem_between) {
const [start, end] = args.dataOrdem_between.map((d) => d.toISOString());
where.push(`DATE(tv."datetimeTransacao") BETWEEN (DATE('${start}') - INTERVAL '1 DAY') AND '${end}'`);
where.push(`DATE(tv."datetimeTransacao") BETWEEN (DATE('${start}') - INTERVAL '1 DAY')
AND '${end}'`);
}

if(args?.consorcio){
where.push(` it."nomeConsorcio" in('${args.consorcio.join("','")}')`)
}

if (args?.nomeFavorecido?.length) {
where.push(`cf.nome ILIKE ANY(ARRAY['%${args.nomeFavorecido.join("%', '%")}%'])`);
}
Expand Down Expand Up @@ -101,8 +108,8 @@ export class TransacaoViewRepository {
WHERE (1=1) ${where.length ? `AND ${where.join(' AND ')}` : ''}
ORDER BY tv.id ASC, ita.id DESC
) associados
WHERE id = associados.tv_id
`;
WHERE id = associados.tv_id `;

this.logger.debug('query: ' + compactQuery(query), METHOD);
const queryRunner = this.dataSource.createQueryRunner();
await queryRunner.connect();
Expand Down

0 comments on commit f998520

Please sign in to comment.