refactor #1

Merged
joan merged 1 commits from 5144-arc-start into master 2023-01-27 08:18:28 +00:00
3 changed files with 11 additions and 19 deletions

View File

@ -1,3 +1,4 @@
arcId: 1
port: 1234
ip: 1.2.3.4
env: dev
@ -9,5 +10,5 @@ db:
database: srt
user: user
password: password
multipleStatements: true
multipleStatements: false
insecureAuth: true

View File

@ -1,22 +1,13 @@
import con from '../db/connect.js';
export default async rfids => {
let response;
if (!rfids.length) return console.logger.warning({error: 'NOT_PARSED_RFIDS', rfids});
export default async(rfids, arcId) => {
const codes = new Set();
for (let rfid of rfids)
codes.add(parseInt(rfid.code));
codes.add(rfid.code);
console.logger.info('CALL PALLET_BUILD', codes, ' TOTAL: ', codes.size);
console.logger.info('PRINTING...');
response = await con.query(`CALL vn.expeditionPallet_build(JSON_ARRAY(?), ?, @pallet);SELECT @pallet;`, [Array.from(codes), 19294]);
const pallet = response[0][1][0]['@pallet'];
if (pallet) {
console.logger.info('PRINTING', pallet);
await con.query(`CALL vn.expeditionPallet_printLabel(?);`, [pallet]);
} else
const palletId = await con.query(`CALL vn.expeditionPallet_build(JSON_ARRAY(?), ?, ?, @palletId);`, [Array.from(codes), arcId, null]);
if (!palletId)
console.logger.info({error: 'ERROR_CREATING_PALLET', expeditions: rfids});
};

View File

@ -17,7 +17,7 @@ export default async(conf, cb) => {
if (parsed)
rfidbuffer = rfidbuffer.concat(parsed);
debug();
debug(parsed);
if (rfidbuffer && rfidbuffer.length && parsed && parsed.length) {
clearInterval(interval);
@ -32,12 +32,12 @@ export default async(conf, cb) => {
function createPallet() {
clearInterval(interval); // try remove
if (!rfidbuffer.length) return;
newPallet(rfidbuffer);
newPallet(rfidbuffer, conf.arcId);
rfidbuffer = [];
rfidbufferSet = [new Set(), new Set(), new Set(), new Set()];
}
function debug() {
function debug(parsed) {
if (conf.env != 'dev') return;
let totalBuffer = rfidbuffer.map(rfid => rfid.code);
let totalBufferSet = new Set(totalBuffer);
@ -53,7 +53,7 @@ export default async(conf, cb) => {
console.log('UNIQUE READ ANTENNA:', rfidbufferSet[0].size, rfidbufferSet[1].size, rfidbufferSet[2].size, rfidbufferSet[3].size);
for (const [index, set] of rfidbufferSet.entries()) {
if (((set.size * 100) / totalBufferSet.size) < 25)
console.log('[WARNING_ANTENNA]: ', index, ' ONLY ', set.size);
console.log('[WARNING_ANTENNA]: ', index + 1, ' ONLY ', set.size);
}
console.log('----------------------------------------------------------------');