homolog #1
@@ -93,7 +93,7 @@ export class UserService {
|
||||
' WHERE PCEMPR.CODFILIAL = PCFILIAL.CODIGO (+)' +
|
||||
' AND PCPARAMFILIAL.CODFILIAL = \'99\' ' +
|
||||
' AND PCPARAMFILIAL.NOME = \'CON_CODSETORGERENTELOJA\' ' +
|
||||
' AND PCEMPR.EMAIL = :username AND PCEMPR.SENHABD = CRYPT(:password, USUARIOBD)';
|
||||
' AND PCEMPR.USUARIOBD = :username AND PCEMPR.SENHABD = CRYPT(:password, USUARIOBD)';
|
||||
|
||||
const users = await queryRunner.manager
|
||||
.query(sql, [user.email, user.password]);
|
||||
@@ -142,7 +142,7 @@ export class UserService {
|
||||
.query(sqlDiasSemEntrega, [Number.parseInt(users[0].deliveryTime)]);
|
||||
|
||||
const days = Number.parseInt(deliveryDays2[0].days) +
|
||||
( noDeliveryDays.length > 0 ? Number.parseInt(noDeliveryDays[0].daysNoDelivery) : 0 );
|
||||
(noDeliveryDays.length > 0 ? Number.parseInt(noDeliveryDays[0].daysNoDelivery) : 0);
|
||||
|
||||
const userDb = users[0];
|
||||
console.log(userDb);
|
||||
|
||||
@@ -1355,7 +1355,7 @@ export class Pcclient {
|
||||
@Column({ name: 'ORGAOPUBMUNICIPAL' })
|
||||
orgaopubmunicipal: string;
|
||||
|
||||
@Column({ name: 'CODCIDADECOM' })
|
||||
@Column({ name: 'CODCIDADECOM' })
|
||||
codcidadecom: number;
|
||||
|
||||
@Column({ name: 'CODPROMOCAOMED' })
|
||||
@@ -1622,8 +1622,8 @@ export class Pcclient {
|
||||
@Column({ name: 'CODCONDCOMERCIAL' })
|
||||
codcondcomercial: string;
|
||||
|
||||
@Column({ name: 'MEIOCOMUNICACAO' })
|
||||
meiocomunicacao: string;
|
||||
// @Column({ name: 'MEIOCOMUNICACAO' })
|
||||
// meiocomunicacao: string;
|
||||
|
||||
@Column({ name: 'CODGRUPOCOMERCIALMED' })
|
||||
codgrupocomercialmed: number;
|
||||
|
||||
@@ -44,7 +44,7 @@ export class CustomerService {
|
||||
' ,pccidade.codibge as "ibgeCode" ' +
|
||||
' ,pcclient.dtnasc as "birthdate" ' +
|
||||
' ,pcclient.codatv1 as "ramoId" ' +
|
||||
' ,pcclient.meiocomunicacao as "communicate" ' +
|
||||
// ' ,pcclient.meiocomunicacao as "communicate" ' +
|
||||
' ,pcclient.latitude as "latitude" ' +
|
||||
' ,pcclient.longitude as "longitude" ' +
|
||||
' ,pcclient.codmunicipio as "ibgeCode" ' +
|
||||
@@ -102,14 +102,14 @@ export class CustomerService {
|
||||
' ,pcclient.telent as "phone" ' +
|
||||
' ,pcclient.telcelent as "cellPhone" ' +
|
||||
' ,pcclient.ieent as "numberState" ' +
|
||||
' ,pcclient.codcategoria as "categoryId" ' +
|
||||
' ,pcclient.codsubcategoria as "subCategoryId" ' +
|
||||
// ' ,pcclient.codcategoria as "categoryId" ' +
|
||||
// ' ,pcclient.codsubcategoria as "subCategoryId" ' +
|
||||
' ,pcclient.codpraca as "placeId" ' +
|
||||
' ,pcclient.codusur1 as "sellerId" ' +
|
||||
' ,pccidade.codibge as "ibgeCode" ' +
|
||||
' ,pcclient.dtnasc as "birthdate" ' +
|
||||
' ,pcclient.codatv1 as "ramoId" ' +
|
||||
' ,pcclient.meiocomunicacao as "communicate" ' +
|
||||
// ' ,pcclient.meiocomunicacao as "communicate" ' +
|
||||
' ,pcclient.latitude as "latitude" ' +
|
||||
' ,pcclient.longitude as "longitude" ' +
|
||||
' ,pcclient.codmunicipio as "ibgeCode" ' +
|
||||
@@ -158,7 +158,7 @@ export class CustomerService {
|
||||
' ,pccidade.codibge as "ibgeCode" ' +
|
||||
' ,pcclient.dtnasc as "birthdate" ' +
|
||||
' ,pcclient.codatv1 as "ramoId" ' +
|
||||
' ,pcclient.meiocomunicacao as "communicate" ' +
|
||||
//' ,pcclient.meiocomunicacao as "communicate" ' +
|
||||
' ,pcclient.latitude as "latitude" ' +
|
||||
' ,pcclient.longitude as "longitude" ' +
|
||||
' ,pcclient.codmunicipio as "ibgeCode" ' +
|
||||
@@ -173,7 +173,7 @@ export class CustomerService {
|
||||
FROM PCPRACA
|
||||
WHERE PCPRACA.CODPRACA = ${customer[0].placeId}`);
|
||||
|
||||
return {...customer[0], place: place[0]};
|
||||
return { ...customer[0], place: place[0] };
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
@@ -267,16 +267,16 @@ export class CustomerService {
|
||||
newCustomer.telcelent = customer.cellPhone;
|
||||
newCustomer.celularwhatsapp = customer.cellPhone;
|
||||
newCustomer.codusur1 = customer.sellerId;
|
||||
newCustomer.codatv1 = ( customer.ramo != null && customer.ramo.id > 0 ) ? customer.ramo.id : newCustomer.codatv1;
|
||||
newCustomer.codatv1 = (customer.ramo != null && customer.ramo.id > 0) ? customer.ramo.id : newCustomer.codatv1;
|
||||
//Endereço de entrega
|
||||
newCustomer.cepent = customer.zipCode;
|
||||
newCustomer.enderent = customer.address.toUpperCase();
|
||||
newCustomer.numeroent = customer.addressNumber;
|
||||
if ( customer.complement !== null && customer.complement.length > 80 ) {
|
||||
newCustomer.complementoent = customer.complement.substring(0, 80 ).toUpperCase();
|
||||
if (customer.complement !== null && customer.complement.length > 80) {
|
||||
newCustomer.complementoent = customer.complement.substring(0, 80).toUpperCase();
|
||||
} else {
|
||||
if ( customer.complement != null ) {
|
||||
newCustomer.complementoent = customer.complement.toUpperCase();
|
||||
if (customer.complement != null) {
|
||||
newCustomer.complementoent = customer.complement.toUpperCase();
|
||||
}
|
||||
}
|
||||
newCustomer.bairroent = customer.neighborhood.toUpperCase();
|
||||
@@ -286,10 +286,10 @@ export class CustomerService {
|
||||
newCustomer.cepcom = customer.zipCode;
|
||||
newCustomer.endercom = customer.address.toUpperCase();
|
||||
newCustomer.numerocom = customer.addressNumber.toUpperCase();
|
||||
if ( customer.complement !== null && customer.complement.length > 80 ) {
|
||||
newCustomer.complementocom = customer.complement.substring(0, 80 ).toUpperCase();
|
||||
if (customer.complement !== null && customer.complement.length > 80) {
|
||||
newCustomer.complementocom = customer.complement.substring(0, 80).toUpperCase();
|
||||
} else {
|
||||
if ( customer.complement != null ) {
|
||||
if (customer.complement != null) {
|
||||
newCustomer.complementocom = customer.complement.toUpperCase();
|
||||
}
|
||||
}
|
||||
@@ -300,10 +300,10 @@ export class CustomerService {
|
||||
newCustomer.cepcob = customer.zipCode;
|
||||
newCustomer.endercob = customer.address.toUpperCase();
|
||||
newCustomer.numerocob = customer.addressNumber;
|
||||
if ( customer.complement !== null && customer.complement.length > 80 ) {
|
||||
newCustomer.complementocob = customer.complement.substring(0, 80 ).toUpperCase();
|
||||
if (customer.complement !== null && customer.complement.length > 80) {
|
||||
newCustomer.complementocob = customer.complement.substring(0, 80).toUpperCase();
|
||||
} else {
|
||||
if ( customer.complement ) {
|
||||
if (customer.complement) {
|
||||
newCustomer.complementocob = customer.complement.toUpperCase();
|
||||
}
|
||||
}
|
||||
@@ -317,7 +317,7 @@ export class CustomerService {
|
||||
newCustomer.codmunicipio = Number.parseInt(customer.ibgeCode);
|
||||
newCustomer.codcidadecom = newCustomer.codcidade;
|
||||
newCustomer.dtnasc = customer.birthdate;
|
||||
newCustomer.meiocomunicacao = customer.communicate;
|
||||
// newCustomer.meiocomunicacao = customer.communicate;
|
||||
newCustomer.codfunccad = customer.idUser;
|
||||
newCustomer.codfunccadastro = customer.idUser;
|
||||
newCustomer.codfuncultalter = customer.idUser;
|
||||
@@ -341,7 +341,7 @@ export class CustomerService {
|
||||
city: customer.city, state: customer.state,
|
||||
allowMessage: customer.allowMessage, cellPhone: customer.cellPhone,
|
||||
category: customer.category, subCategory: customer.subCategory,
|
||||
place: customer.place, ramo: customer.ramo, meiocomunicacao: customer.communicate,
|
||||
place: customer.place, ramo: customer.ramo, /*meiocomunicacao: customer.communicate,*/
|
||||
latitude: customer.latitude, longitude: customer.longitude, ibgeCode: customer.ibgeCode,
|
||||
addressType: customer.addressType,
|
||||
};
|
||||
@@ -361,7 +361,7 @@ export class CustomerService {
|
||||
city: customer.city, state: customer.state,
|
||||
allowMessage: customer.allowMessage, cellPhone: customer.cellPhone,
|
||||
category: customer.category, subCategory: customer.subCategory,
|
||||
place: customer.place, meiocomunicacao: customer.communicate,
|
||||
place: customer.place, /*meiocomunicacao: customer.communicate,*/
|
||||
ramo: customer.ramo, latitude: customer.latitude, longitude: customer.longitude,
|
||||
ibgeCode: customer.ibgeCode, addressType: customer.addressType,
|
||||
};
|
||||
@@ -378,7 +378,7 @@ export class CustomerService {
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
try {
|
||||
console.log("MEIO DE COMUNICACAO: " + client.meiocomunicacao);
|
||||
//console.log("MEIO DE COMUNICACAO: " + client.meiocomunicacao);
|
||||
await queryRunner.manager
|
||||
.createQueryBuilder()
|
||||
.update(Pcclient)
|
||||
@@ -419,7 +419,7 @@ export class CustomerService {
|
||||
codcidadecom: client.codcidade,
|
||||
dtnasc: client.dtnasc,
|
||||
codatv1: client.codatv1,
|
||||
meiocomunicacao: client.meiocomunicacao,
|
||||
// meiocomunicacao: client.meiocomunicacao,
|
||||
codfuncultalter: client.codfuncultalter,
|
||||
dtultalter: client.dtultalter,
|
||||
latitude: client.latitude,
|
||||
@@ -434,7 +434,7 @@ export class CustomerService {
|
||||
await queryRunner.rollbackTransaction();
|
||||
throw err;
|
||||
} finally {
|
||||
if ( queryRunner.isTransactionActive) {
|
||||
if (queryRunner.isTransactionActive) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
}
|
||||
await queryRunner.release();
|
||||
@@ -533,12 +533,12 @@ export class CustomerService {
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
try {
|
||||
|
||||
await connection.connect();
|
||||
await connection.connect();
|
||||
|
||||
await queryRunner.connect();
|
||||
await queryRunner.connect();
|
||||
|
||||
// lets now open a new transaction:
|
||||
await queryRunner.startTransaction();
|
||||
// lets now open a new transaction:
|
||||
await queryRunner.startTransaction();
|
||||
|
||||
|
||||
let sql = `SELECT PROXNUMCLI as "proxnumcli" FROM PCCONSUM WHERE 1 = 1 FOR UPDATE`;
|
||||
@@ -566,14 +566,14 @@ export class CustomerService {
|
||||
|
||||
} catch (err) {
|
||||
// since we have errors let's rollback changes we made
|
||||
if ( queryRunner.isTransactionActive) {
|
||||
if (queryRunner.isTransactionActive) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
}
|
||||
console.log(err);
|
||||
return -1;
|
||||
|
||||
} finally {
|
||||
if ( queryRunner.isTransactionActive) {
|
||||
if (queryRunner.isTransactionActive) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
}
|
||||
// you need to release query runner which is manually created:
|
||||
@@ -603,7 +603,7 @@ export class CustomerService {
|
||||
console.log(err);
|
||||
throw err;
|
||||
} finally {
|
||||
if ( queryRunner.isTransactionActive) {
|
||||
if (queryRunner.isTransactionActive) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
}
|
||||
await queryRunner.release();
|
||||
|
||||
@@ -20,10 +20,10 @@ import Redis = require('ioredis');
|
||||
@Injectable()
|
||||
export class SalesService {
|
||||
|
||||
constructor(
|
||||
@Inject('REDIS_CLIENT') private readonly redisClient: Redis.Redis,
|
||||
private readonly customerService: CustomerService
|
||||
) {}
|
||||
constructor(
|
||||
@Inject('REDIS_CLIENT') private readonly redisClient: Redis.Redis,
|
||||
private readonly customerService: CustomerService
|
||||
) { }
|
||||
|
||||
|
||||
async GetProducts2(store: string, pageSize: number, pageNumber: number, filter: FilterProduct = null,) {
|
||||
@@ -367,88 +367,88 @@ export class SalesService {
|
||||
pageSize: number,
|
||||
pageNumber: number,
|
||||
urlDepartment: string
|
||||
): Promise<any> {
|
||||
): Promise<any> {
|
||||
const cacheKey =
|
||||
'searchByDepartment:' +
|
||||
store +
|
||||
'_' +
|
||||
pageSize +
|
||||
'_' +
|
||||
pageNumber +
|
||||
'_' +
|
||||
urlDepartment;
|
||||
'searchByDepartment:' +
|
||||
store +
|
||||
'_' +
|
||||
pageSize +
|
||||
'_' +
|
||||
pageNumber +
|
||||
'_' +
|
||||
urlDepartment;
|
||||
const lockKey = 'lock:' + cacheKey;
|
||||
const lockTimeout = 30; // lock expira em 30 segundos
|
||||
|
||||
try {
|
||||
const cachedResult = await this.redisClient.get(cacheKey);
|
||||
if (cachedResult) {
|
||||
console.log('Retornando resultado do cache (searchByDepartment)');
|
||||
return JSON.parse(cachedResult);
|
||||
}
|
||||
const cachedResult = await this.redisClient.get(cacheKey);
|
||||
if (cachedResult) {
|
||||
console.log('Retornando resultado do cache (searchByDepartment)');
|
||||
return JSON.parse(cachedResult);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Erro ao acessar o Redis no searchByDepartment:', err?.message || err);
|
||||
console.error('Erro ao acessar o Redis no searchByDepartment:', err?.message || err);
|
||||
}
|
||||
|
||||
const lockValue = Date.now() + lockTimeout * 1000 + 1;
|
||||
let acquiredLock: string | null = null;
|
||||
try {
|
||||
acquiredLock = await this.redisClient.set(lockKey, lockValue, 'NX', 'EX', lockTimeout);
|
||||
acquiredLock = await this.redisClient.set(lockKey, lockValue, 'NX', 'EX', lockTimeout);
|
||||
} catch (err) {
|
||||
console.error('Erro ao adquirir lock no Redis (searchByDepartment):', err?.message || err);
|
||||
console.error('Erro ao adquirir lock no Redis (searchByDepartment):', err?.message || err);
|
||||
}
|
||||
|
||||
if (acquiredLock === 'OK') {
|
||||
const connectionDb = new Connection(connectionOptions);
|
||||
await connectionDb.connect();
|
||||
const queryRunner = connectionDb.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
if (pageSize === 0) pageSize = 50;
|
||||
if (pageNumber === 0) pageNumber = 1;
|
||||
const offSet = (pageNumber - 1) * pageSize;
|
||||
|
||||
let products = await queryRunner.manager
|
||||
.getRepository(SalesProduct)
|
||||
.createQueryBuilder('esvlistaprodutos')
|
||||
.where('"esvlistaprodutos".urldepartamento = :urlDepartment', { urlDepartment })
|
||||
.andWhere('("esvlistaprodutos".codfilial = :codfilial OR :codfilial = \'99\')', { codfilial: store })
|
||||
.limit(pageSize)
|
||||
.offset(offSet)
|
||||
.orderBy('"esvlistaprodutos".DESCRICAO', 'ASC')
|
||||
.getMany();
|
||||
|
||||
products = this.createListImages(products);
|
||||
|
||||
const connectionDb = new Connection(connectionOptions);
|
||||
await connectionDb.connect();
|
||||
const queryRunner = connectionDb.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
await this.redisClient.set(cacheKey, JSON.stringify(products), 'EX', 3600);
|
||||
} catch (cacheErr) {
|
||||
console.error('Erro ao salvar o resultado no cache (searchByDepartment):', cacheErr?.message || cacheErr);
|
||||
}
|
||||
if (pageSize === 0) pageSize = 50;
|
||||
if (pageNumber === 0) pageNumber = 1;
|
||||
const offSet = (pageNumber - 1) * pageSize;
|
||||
|
||||
return products;
|
||||
} catch (error) {
|
||||
console.error('Erro ao executar a query no searchByDepartment:', error?.message || error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connectionDb.close();
|
||||
let products = await queryRunner.manager
|
||||
.getRepository(SalesProduct)
|
||||
.createQueryBuilder('esvlistaprodutos')
|
||||
.where('"esvlistaprodutos".urldepartamento = :urlDepartment', { urlDepartment })
|
||||
.andWhere('("esvlistaprodutos".codfilial = :codfilial OR :codfilial = \'99\')', { codfilial: store })
|
||||
.limit(pageSize)
|
||||
.offset(offSet)
|
||||
.orderBy('"esvlistaprodutos".DESCRICAO', 'ASC')
|
||||
.getMany();
|
||||
|
||||
try {
|
||||
const currentLockValue = await this.redisClient.get(lockKey);
|
||||
if (currentLockValue === lockValue.toString()) {
|
||||
await this.redisClient.del(lockKey);
|
||||
}
|
||||
} catch (lockErr) {
|
||||
console.error('Erro ao liberar o lock do Redis (searchByDepartment):', lockErr?.message || lockErr);
|
||||
products = this.createListImages(products);
|
||||
|
||||
try {
|
||||
await this.redisClient.set(cacheKey, JSON.stringify(products), 'EX', 3600);
|
||||
} catch (cacheErr) {
|
||||
console.error('Erro ao salvar o resultado no cache (searchByDepartment):', cacheErr?.message || cacheErr);
|
||||
}
|
||||
|
||||
return products;
|
||||
} catch (error) {
|
||||
console.error('Erro ao executar a query no searchByDepartment:', error?.message || error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connectionDb.close();
|
||||
|
||||
try {
|
||||
const currentLockValue = await this.redisClient.get(lockKey);
|
||||
if (currentLockValue === lockValue.toString()) {
|
||||
await this.redisClient.del(lockKey);
|
||||
}
|
||||
} catch (lockErr) {
|
||||
console.error('Erro ao liberar o lock do Redis (searchByDepartment):', lockErr?.message || lockErr);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log('Lock não adquirido (searchByDepartment), aguardando e tentando novamente...');
|
||||
await this.sleep(1000);
|
||||
return this.searchByDepartment(store, pageSize, pageNumber, urlDepartment);
|
||||
console.log('Lock não adquirido (searchByDepartment), aguardando e tentando novamente...');
|
||||
await this.sleep(1000);
|
||||
return this.searchByDepartment(store, pageSize, pageNumber, urlDepartment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1211,67 +1211,67 @@ export class SalesService {
|
||||
const lockKey = 'departments_lock';
|
||||
const lockTimeout = 30;
|
||||
|
||||
try {
|
||||
const cachedDepartments = await this.redisClient.get(cacheKey);
|
||||
if (cachedDepartments) {
|
||||
console.log('Buscando departamentos no Redis');
|
||||
return JSON.parse(cachedDepartments);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Erro ao acessar o Redis (cache):', err);
|
||||
}
|
||||
const lockValue = Date.now() + lockTimeout * 1000 + 1;
|
||||
// try {
|
||||
// const cachedDepartments = await this.redisClient.get(cacheKey);
|
||||
// if (cachedDepartments) {
|
||||
// console.log('Buscando departamentos no Redis');
|
||||
// return JSON.parse(cachedDepartments);
|
||||
// }
|
||||
// } catch (err) {
|
||||
// console.error('Erro ao acessar o Redis (cache):', err);
|
||||
// }
|
||||
const lockValue = Date.now() + lockTimeout * 1000 + 1;
|
||||
const acquiredLock = await this.redisClient.set(lockKey, lockValue, 'NX', 'EX', lockTimeout);
|
||||
|
||||
if (acquiredLock === 'OK') {
|
||||
const connectionDb = new Connection(connectionOptions);
|
||||
await connectionDb.connect();
|
||||
const queryRunner = connectionDb.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
|
||||
try {
|
||||
const departments = await queryRunner.manager
|
||||
.getRepository(Esvdepartamento)
|
||||
.createQueryBuilder('Esvdepartamento')
|
||||
.innerJoinAndSelect('Esvdepartamento.secoes', 'secoes')
|
||||
.innerJoinAndSelect('secoes.categorias', 'categorias')
|
||||
.where('"Esvdepartamento".tituloecommerce is not null')
|
||||
.orderBy('"Esvdepartamento".tituloecommerce, "secoes".tituloecommerce, "categorias".tituloecommerce')
|
||||
.getMany();
|
||||
const connectionDb = new Connection(connectionOptions);
|
||||
await connectionDb.connect();
|
||||
const queryRunner = connectionDb.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
|
||||
try {
|
||||
await this.redisClient.set(cacheKey, JSON.stringify(departments), 'EX', 3600);
|
||||
} catch (cacheErr) {
|
||||
console.error('Erro ao armazenar dados no Redis:', cacheErr);
|
||||
}
|
||||
const departments = await queryRunner.manager
|
||||
.getRepository(Esvdepartamento)
|
||||
.createQueryBuilder('Esvdepartamento')
|
||||
.innerJoinAndSelect('Esvdepartamento.secoes', 'secoes')
|
||||
.leftJoinAndSelect('secoes.categorias', 'categorias')
|
||||
.where('"Esvdepartamento".tituloecommerce is not null')
|
||||
.orderBy('"Esvdepartamento".tituloecommerce, "secoes".tituloecommerce, "categorias".tituloecommerce')
|
||||
.getMany();
|
||||
|
||||
return departments;
|
||||
} catch (dbErr) {
|
||||
console.error('Erro na consulta ao banco de dados:', dbErr);
|
||||
throw dbErr;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connectionDb.close();
|
||||
try {
|
||||
await this.redisClient.set(cacheKey, JSON.stringify(departments), 'EX', 3600);
|
||||
} catch (cacheErr) {
|
||||
console.error('Erro ao armazenar dados no Redis:', cacheErr);
|
||||
}
|
||||
|
||||
// Libera o lock somente se ainda for o proprietário
|
||||
try {
|
||||
const currentLockValue = await this.redisClient.get(lockKey);
|
||||
if (currentLockValue === lockValue.toString()) {
|
||||
await this.redisClient.del(lockKey);
|
||||
}
|
||||
} catch (lockErr) {
|
||||
console.error('Erro ao liberar o lock do Redis:', lockErr);
|
||||
return departments;
|
||||
} catch (dbErr) {
|
||||
console.error('Erro na consulta ao banco de dados:', dbErr);
|
||||
throw dbErr;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connectionDb.close();
|
||||
|
||||
// Libera o lock somente se ainda for o proprietário
|
||||
try {
|
||||
const currentLockValue = await this.redisClient.get(lockKey);
|
||||
if (currentLockValue === lockValue.toString()) {
|
||||
await this.redisClient.del(lockKey);
|
||||
}
|
||||
} catch (lockErr) {
|
||||
console.error('Erro ao liberar o lock do Redis:', lockErr);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log('Lock não adquirido, aguardando a liberação...');
|
||||
await this.sleep(1000); // aguarda 1 segundo
|
||||
return this.getDepartments();
|
||||
console.log('Lock não adquirido, aguardando a liberação...');
|
||||
await this.sleep(1000); // aguarda 1 segundo
|
||||
return this.getDepartments();
|
||||
}
|
||||
}
|
||||
private sleep(ms: number): Promise<void> {
|
||||
}
|
||||
private sleep(ms: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1488,7 +1488,7 @@ export class SalesService {
|
||||
WHERE ID = '${cartId}'`;
|
||||
|
||||
await queryRunner.manager
|
||||
.query(sql);
|
||||
.query(sql);
|
||||
await queryRunner.commitTransaction();
|
||||
} catch (err) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
@@ -1580,7 +1580,7 @@ export class SalesService {
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = `SELECT ESF_CALCULAR_PRAZO_ENTREGA_PROGRAMADA(TO_DATE('${saleDate}', 'DD-MM-YYYY'), ${invoiceStoreId}, ${placeId}, '${cartId}') AS "days" FROM DUAL`;
|
||||
// const sql = `SELECT ESF_CALCULAR_PRAZO_ENTREGA(TO_DATE('${saleDate}', 'DD-MM-YYYY')) AS "days" FROM DUAL`;
|
||||
// const sql = `SELECT ESF_CALCULAR_PRAZO_ENTREGA(TO_DATE('${saleDate}', 'DD-MM-YYYY')) AS "days" FROM DUAL`;
|
||||
const timeDays = await queryRunner.query(sql);
|
||||
|
||||
const sqlRetiraPosterior = `SELECT ( PROXIMO_DIA_UTIL(TO_DATE('${saleDate}', 'DD-MM-YYYY'), '4') - TRUNC(SYSDATE) ) AS "days" FROM DUAL`;
|
||||
|
||||
Reference in New Issue
Block a user