Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
faa3865da1
|
@ -20,7 +20,11 @@ module.exports = Self => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
|
||||||
// Get files checksum
|
// Get files checksum
|
||||||
const files = await Self.rawSql('SELECT name, checksum, keyValue FROM edi.fileConfig');
|
const tx = await Self.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const files = await Self.rawSql('SELECT name, checksum, keyValue FROM edi.fileConfig', null, options);
|
||||||
|
|
||||||
const updatableFiles = [];
|
const updatableFiles = [];
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
|
@ -51,13 +55,11 @@ module.exports = Self => {
|
||||||
const tables = await Self.rawSql(`
|
const tables = await Self.rawSql(`
|
||||||
SELECT fileName, toTable, file
|
SELECT fileName, toTable, file
|
||||||
FROM edi.tableConfig
|
FROM edi.tableConfig
|
||||||
WHERE file IN (?)`, [fileNames]);
|
WHERE file IN (?)`, [fileNames], options);
|
||||||
|
|
||||||
for (const table of tables) {
|
for (const table of tables) {
|
||||||
const fileName = table.file;
|
const fileName = table.file;
|
||||||
|
|
||||||
console.debug(`Downloading file ${fileName}...`);
|
|
||||||
|
|
||||||
remoteFile = `codes/${fileName}.ZIP`;
|
remoteFile = `codes/${fileName}.ZIP`;
|
||||||
tempDir = `${tempPath}/${fileName}`;
|
tempDir = `${tempPath}/${fileName}`;
|
||||||
tempFile = `${tempPath}/${fileName}.zip`;
|
tempFile = `${tempPath}/${fileName}.zip`;
|
||||||
|
@ -66,30 +68,34 @@ module.exports = Self => {
|
||||||
await fs.readFile(tempFile);
|
await fs.readFile(tempFile);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'ENOENT') {
|
if (error.code === 'ENOENT') {
|
||||||
|
console.debug(`Downloading file ${fileName}...`);
|
||||||
const downloadOutput = await downloadFile(remoteFile, tempFile);
|
const downloadOutput = await downloadFile(remoteFile, tempFile);
|
||||||
if (downloadOutput.error)
|
if (downloadOutput.error)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.debug(`Extracting file ${fileName}...`);
|
await extractFile(fileName, tempFile, tempDir);
|
||||||
await extractFile(tempFile, tempDir);
|
|
||||||
|
|
||||||
console.debug(`Updating table ${table.toTable}...`);
|
console.debug(`Updating table ${table.toTable}...`);
|
||||||
await dumpData(tempDir, table);
|
await dumpData(tempDir, table, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update files checksum
|
// Update files checksum
|
||||||
for (const file of updatableFiles) {
|
for (const file of updatableFiles) {
|
||||||
|
console.log(`Updating file ${file.name} checksum...`);
|
||||||
await Self.rawSql(`
|
await Self.rawSql(`
|
||||||
UPDATE edi.fileConfig
|
UPDATE edi.fileConfig
|
||||||
SET checksum = ?
|
SET checksum = ?
|
||||||
WHERE name = ?`,
|
WHERE name = ?`,
|
||||||
[file.checksum, file.name]);
|
[file.checksum, file.name], options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await tx.commit();
|
||||||
|
|
||||||
// Clean files
|
// Clean files
|
||||||
try {
|
try {
|
||||||
|
console.debug(`Cleaning files...`);
|
||||||
await fs.remove(tempPath);
|
await fs.remove(tempPath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code !== 'ENOENT')
|
if (error.code !== 'ENOENT')
|
||||||
|
@ -97,6 +103,10 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let ftpClient;
|
let ftpClient;
|
||||||
|
@ -126,9 +136,9 @@ module.exports = Self => {
|
||||||
|
|
||||||
const response = await new Promise((resolve, reject) => {
|
const response = await new Promise((resolve, reject) => {
|
||||||
ftpClient.exec((err, response) => {
|
ftpClient.exec((err, response) => {
|
||||||
if (response.error) {
|
if (err || response.error) {
|
||||||
console.debug(`Error downloading checksum file... ${response.error}`);
|
console.debug(`Error downloading checksum file... ${response.error}`);
|
||||||
reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(response);
|
resolve(response);
|
||||||
|
@ -159,9 +169,9 @@ module.exports = Self => {
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
ftpClient.exec((err, response) => {
|
ftpClient.exec((err, response) => {
|
||||||
if (response.error) {
|
if (err || response.error) {
|
||||||
console.debug(`Error downloading file... ${response.error}`);
|
console.debug(`Error downloading file... ${response.error}`);
|
||||||
reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(response);
|
resolve(response);
|
||||||
|
@ -169,11 +179,12 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function extractFile(tempFile, tempDir) {
|
async function extractFile(fileName, tempFile, tempDir) {
|
||||||
const JSZip = require('jszip');
|
const JSZip = require('jszip');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.mkdir(tempDir);
|
await fs.mkdir(tempDir);
|
||||||
|
console.debug(`Extracting file ${fileName}...`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code !== 'EEXIST')
|
if (error.code !== 'EEXIST')
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -196,42 +207,13 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function dumpData(tempDir, table) {
|
async function dumpData(tempDir, table, options) {
|
||||||
const toTable = table.toTable;
|
const toTable = table.toTable;
|
||||||
const baseName = table.fileName;
|
const baseName = table.fileName;
|
||||||
|
|
||||||
const firstEntry = entries[0];
|
console.log(`Emptying table ${toTable}...`);
|
||||||
const entryName = firstEntry.entryName;
|
|
||||||
const startIndex = (entryName.length - 10);
|
|
||||||
const endIndex = (entryName.length - 4);
|
|
||||||
const dateString = entryName.substring(startIndex, endIndex);
|
|
||||||
|
|
||||||
const lastUpdated = new Date();
|
|
||||||
|
|
||||||
let updated = null;
|
|
||||||
if (file.updated) {
|
|
||||||
updated = new Date(file.updated);
|
|
||||||
updated.setHours(0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Format string date to a date object
|
|
||||||
lastUpdated.setFullYear(`20${dateString.substring(4, 6)}`);
|
|
||||||
lastUpdated.setMonth(parseInt(dateString.substring(2, 4)) - 1);
|
|
||||||
lastUpdated.setDate(dateString.substring(0, 2));
|
|
||||||
lastUpdated.setHours(0, 0, 0, 0);
|
|
||||||
|
|
||||||
if (updated && lastUpdated <= updated) {
|
|
||||||
console.debug(`Table ${toTable} already updated, skipping...`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const tx = await Self.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
const tableName = `edi.${toTable}`;
|
const tableName = `edi.${toTable}`;
|
||||||
await Self.rawSql(`DELETE FROM ??`, [tableName], options);
|
await Self.rawSql(`DELETE FROM ??`, [tableName]);
|
||||||
|
|
||||||
const dirFiles = await fs.readdir(tempDir);
|
const dirFiles = await fs.readdir(tempDir);
|
||||||
const files = dirFiles.filter(file => file.startsWith(baseName));
|
const files = dirFiles.filter(file => file.startsWith(baseName));
|
||||||
|
@ -251,11 +233,6 @@ module.exports = Self => {
|
||||||
`, [new Date(), baseName], options);
|
`, [new Date(), baseName], options);
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.commit();
|
|
||||||
} catch (error) {
|
|
||||||
tx.rollback();
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
console.log(`Updated table ${toTable}\n`);
|
console.log(`Updated table ${toTable}\n`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,7 +40,8 @@
|
||||||
</vn-button>
|
</vn-button>
|
||||||
</div>
|
</div>
|
||||||
<vn-button icon="refresh"
|
<vn-button icon="refresh"
|
||||||
ng-click="$ctrl.model.refresh()"
|
ng-click="$ctrl.refresh()"
|
||||||
|
disabled="$ctrl.isRefreshing"
|
||||||
vn-tooltip="Refresh">
|
vn-tooltip="Refresh">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -511,6 +511,12 @@ export default class SmartTable extends Component {
|
||||||
return this.model.save()
|
return this.model.save()
|
||||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refresh() {
|
||||||
|
this.isRefreshing = true;
|
||||||
|
this.model.refresh()
|
||||||
|
.then(() => this.isRefreshing = false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SmartTable.$inject = ['$element', '$scope', '$transclude'];
|
SmartTable.$inject = ['$element', '$scope', '$transclude'];
|
||||||
|
|
|
@ -164,6 +164,10 @@ module.exports = Self => {
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.filter');
|
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.filter');
|
||||||
|
|
||||||
|
stmts.push(`SET @_optimizer_search_depth = @@optimizer_search_depth`);
|
||||||
|
stmts.push(`SET SESSION optimizer_search_depth = 0`);
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(
|
stmt = new ParameterizedSQL(
|
||||||
`CREATE TEMPORARY TABLE tmp.filter
|
`CREATE TEMPORARY TABLE tmp.filter
|
||||||
(PRIMARY KEY (id))
|
(PRIMARY KEY (id))
|
||||||
|
@ -207,7 +211,7 @@ module.exports = Self => {
|
||||||
LEFT JOIN province p ON p.id = a.provinceFk
|
LEFT JOIN province p ON p.id = a.provinceFk
|
||||||
LEFT JOIN warehouse w ON w.id = t.warehouseFk
|
LEFT JOIN warehouse w ON w.id = t.warehouseFk
|
||||||
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
|
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||||
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
STRAIGHT_JOIN ticketState ts ON ts.ticketFk = t.id
|
||||||
LEFT JOIN state st ON st.id = ts.stateFk
|
LEFT JOIN state st ON st.id = ts.stateFk
|
||||||
LEFT JOIN client c ON c.id = t.clientFk
|
LEFT JOIN client c ON c.id = t.clientFk
|
||||||
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
|
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
|
||||||
|
@ -224,6 +228,8 @@ module.exports = Self => {
|
||||||
stmt.merge(conn.makeWhere(filter.where));
|
stmt.merge(conn.makeWhere(filter.where));
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
|
|
||||||
|
stmts.push(`SET SESSION optimizer_search_depth = @_optimizer_search_depth`);
|
||||||
|
|
||||||
// Get client debt balance
|
// Get client debt balance
|
||||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt');
|
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt');
|
||||||
stmts.push(`
|
stmts.push(`
|
||||||
|
|
|
@ -147,16 +147,12 @@ describe('SalesMonitor salesFilter()', () => {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const ctx = {req: {accessToken: {userId: 9}}, args: {pending: false}};
|
const ctx = {req: {accessToken: {userId: 9}}, args: {pending: false}};
|
||||||
const filter = {};
|
const filter = {order: 'alertLevel ASC'};
|
||||||
const result = await models.SalesMonitor.salesFilter(ctx, filter, options);
|
const result = await models.SalesMonitor.salesFilter(ctx, filter, options);
|
||||||
const firstRow = result[0];
|
const firstRow = result[0];
|
||||||
const secondRow = result[1];
|
|
||||||
const thirdRow = result[2];
|
|
||||||
|
|
||||||
expect(result.length).toEqual(12);
|
expect(result.length).toEqual(12);
|
||||||
expect(firstRow.state).toEqual('Entregado');
|
expect(firstRow.alertLevel).not.toEqual(0);
|
||||||
expect(secondRow.state).toEqual('Entregado');
|
|
||||||
expect(thirdRow.state).toEqual('Entregado');
|
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -7,6 +7,5 @@ SELECT
|
||||||
JOIN pgc ON pgc.code = iot.pgcFk
|
JOIN pgc ON pgc.code = iot.pgcFk
|
||||||
LEFT JOIN pgcEqu pe ON pe.equFk = pgc.code
|
LEFT JOIN pgcEqu pe ON pe.equFk = pgc.code
|
||||||
JOIN invoiceOut io ON io.id = iot.invoiceOutFk
|
JOIN invoiceOut io ON io.id = iot.invoiceOutFk
|
||||||
LEFT JOIN ticket t ON t.refFk = io.ref
|
WHERE io.ref = ?
|
||||||
WHERE t.refFk = ?
|
|
||||||
ORDER BY iot.id
|
ORDER BY iot.id
|
Loading…
Reference in New Issue