Merge pull request '3803-shelvingThrowError' (#1) from 3803-shelvingThrowError into master
gitea/smart-tag/pipeline/head This commit looks good Details

Reviewed-on: #1
This commit is contained in:
Alex Moreno 2022-04-04 09:57:54 +00:00
commit 8b748c843e
18 changed files with 2537 additions and 255 deletions

View File

@ -1,7 +1,7 @@
const mysql = require('mysql');
const mysql = require('mysql2/promise');
const config = require('../config');
const con = mysql.createConnection({
module.exports = mysql.createPool({
user: config.db.user,
password: config.db.password,
host: config.db.host, // 'test-db.verdnatura.es',
@ -9,5 +9,3 @@ const con = mysql.createConnection({
database: config.db.database,
insecureAuth: true
});
exports.con = con;

View File

@ -1,6 +1,6 @@
const con = require('./connect.js');
con.con.connect(function(err) {
con.connect(function(err) {
if (err) throw err;
let sql = `CREATE TABLE vn.smartTag (
code varchar(12) NOT NULL,
@ -13,7 +13,7 @@ con.con.connect(function(err) {
ENGINE=InnoDB
DEFAULT CHARSET=utf8
COLLATE=utf8_general_ci;`;
con.con.query(sql, function(err, result) {
con.query(sql, function(err, result) {
if (err) throw err;
});
});

View File

@ -1,13 +1,9 @@
const con = require('./connect');
function insertSmartTag(smartTagFk, shelving, level) {
let sql = `INSERT INTO vn.smartTag (code, shelvingFk, level)
VALUES ('${smartTagFk}', '${shelving}', ${level})
module.exports = function insertSmartTag(smartTagFk, shelving, level) {
const sql = `INSERT INTO vn.smartTag (code, shelvingFk, level)
VALUES (?, ?, ?)
ON DUPLICATE KEY
UPDATE shelvingFk = '${shelving}', level = ${level};`;
con.con.query(sql, function(err, result) {
if (err)
console.log(err);
});
}
exports.insertSmartTag = insertSmartTag;
UPDATE shelvingFk = ?, level = ?;`;
return con.query(sql, [smartTagFk, shelving, level, shelving, level]);
};

View File

@ -1,9 +1,7 @@
const con = require('./connect');
function insertTicket(ticket, smartTag) {
let sql = `UPDATE vn.ticketCollection SET smartTagFk = '${smartTag}' WHERE ticketFk = ${ticket}`;
con.con.query(sql, function(err, result) {
if (err) throw err;
});
const sql = `UPDATE vn.ticketCollection SET smartTagFk = ? WHERE ticketFk = ?`;
return con.query(sql, [smartTag, ticket]);
}
exports.insertTicket = insertTicket;

View File

@ -1,12 +0,0 @@
const con = require('./connect');
function maxWagon(collectionFk, callback) {
let consSql = `SELECT MAX(tc.wagon) AS MaxWagons
FROM ticketCollection tc
WHERE tc.collectionFk = ${collectionFk}`;
con.con.query(consSql, function(err, result, fields) {
callback(null, result);
});
}
exports.maxWagon = maxWagon;

View File

@ -12,7 +12,7 @@ con.con.connect(function(err) {
('A0A3B8299CD3', 'DEF', 3),
('A0A3B8299CD4', 'DEF', 4)
;`;
con.con.query(sql, function(err, result) {
con.query(sql, function(err, result) {
if (err) throw err;
});
});

View File

@ -1,11 +1,7 @@
const con = require('./connect');
function selectCollectionSmartTag(collectionFk, callback) {
let consSql = `SELECT * FROM vn.collectionSmartTag WHERE collectionFk = ${collectionFk};`;
con.con.query(consSql, function(err, result, fields) {
callback(null, result);
});
}
exports.selectCollectionSmartTag = selectCollectionSmartTag;
module.exports = function selectCollectionSmartTag(collectionFk) {
const sql = `SELECT * FROM vn.collectionSmartTag WHERE collectionFk = ?;`;
return con.query(sql, collectionFk);
};

View File

@ -1,11 +1,7 @@
const con = require('./connect');
function select(ticket, callback) {
let consSql = `SELECT * FROM vn.collectionSmartTag WHERE ticketFk = ${ticket}`;
con.con.query(consSql, function(err, result, fields) {
callback(null, result);
});
}
exports.select = select;
module.exports = function selectTicket(ticket) {
const sql = `SELECT * FROM vn.collectionSmartTag WHERE ticketFk = ?`;
return con.query(sql, ticket);
};

View File

@ -11,85 +11,58 @@ router.get('/:smartTagFk&:shelving&:level', async(req, res) => {
const smartTagFk = req.params.smartTagFk;// valido = "A0A3B82"+ 4 CARACTERES HEXADECIMALES (0-F)
const shelving = req.params.shelving;// valido = 3 CARACTERES LETRAS (A-Z)
const level = req.params.level;
const result = bindShelvingTag(smartTagFk, shelving, level);
const shelvingId = shelving + level;
if (result == 'INVALID_PLATE')
res.json({message: 'MATRICULA INCORRECTA'});
else if (result == 'INVALID_TAG_CODE')
res.json({message: 'CODIGO DE ETIQUETA INCORRECTO'});
else
res.json({message: 'SUCCESS'});
filter.isSmartTag(smartTagFk);
await filter.isShelving(shelving);
// Vinculamos la etiqueta con la balda del carry y en la base de datos
await insertShelving(shelvingId, smartTagFk); // al carry en ESL CLOUD SYSTEM
insertSmartTag(smartTagFk, shelving, level); // en vn.smartTag
res.json({message: 'SUCCESS'});
});
module.exports = router;
// Vinculamos la etiqueta con la balda del carry y en la base de datos
function bindShelvingTag(smartTagFk, shelving, level) {
let shelvingId = shelving + level;
if (filter.isSmartTag(smartTagFk)) {
if (filter.isShelving(shelving)) {
insertShelving(shelvingId, smartTagFk); // al carry en ESL CLOUD SYSTEM
insertSmartTag.insertSmartTag(smartTagFk, shelving, level); // en vn.smartTag
} else
return 'INVALID_PLATE';
} else
return 'INVALID_TAG_CODE';
}
// Creamos un "articulo", que sera el que luego modificaremos para añadirle un ticket
async function insertShelving(shelvingId, smartTagFk) {
(async() => {
const info = await dataLogIn.dataLogIn;
let key = info.data.token;
let currentUser = info.data.currentUser;
(async() => {
const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
json: {
agencyId: currentUser.agencyId,
merchantId: currentUser.merchantId,
storeId: config.storeId,
unitName: currentUser.unitName,
itemList: [
{
attrCategory: 'verdnatura', // Plantilla
attrName: 'withOutTicket', // Tipo de Plantilla
barCode: shelvingId, // Matricula + nivel --> Cod.Barras artículo
itemTitle: 'tagWithOutTicket',
qrCode: shelvingId
}
]
},
responseType: 'json',
headers: {
'Authorization': key
}
});
await bindShelving(smartTagFk, shelvingId);
})();
})();
}
const info = await dataLogIn.dataLogIn;
const key = info.data.token;
const currentUser = info.data.currentUser;
// Creamos la etiqueta con su vinculada con el ShelvingId al articulo
async function bindShelving(smartTagFk, shelvingId) {
(async() => {
const info = await dataLogIn.dataLogIn;
let key = info.data.token;
(async() => {
const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/bind/batchBind', { // eslint-disable-line
json: {
storeId: config.storeId,
tagItemBinds: [{
eslBarcode: smartTagFk,
itemBarcode: shelvingId
}
]
},
responseType: 'json',
headers: {
'Authorization': key
await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
json: {
agencyId: currentUser.agencyId,
merchantId: currentUser.merchantId,
storeId: config.storeId,
unitName: currentUser.unitName,
itemList: [
{
attrCategory: 'verdnatura', // Plantilla
attrName: 'withOutTicket', // Tipo de Plantilla
barCode: shelvingId, // Matricula + nivel --> Cod.Barras artículo
itemTitle: 'tagWithOutTicket',
qrCode: shelvingId
}
});
})();
})();
]
},
responseType: 'json',
headers: {
'Authorization': key
}
});
await got.post('http://app.etiquetaselectronicas.com:9999/bind/batchBind', { // eslint-disable-line
json: {
storeId: config.storeId,
tagItemBinds: [{
eslBarcode: smartTagFk,
itemBarcode: shelvingId
}
]
},
responseType: 'json',
headers: {
'Authorization': key
}
});
}
exports.bindShelving = bindShelving;

View File

@ -1,61 +1,51 @@
const express = require('express');
const router = express.Router(); // eslint-disable-line
const select = require('../db/selectCollection');
const collectionSmartTag = require('../db/selectCollection');
const dataLogIn = require('../server');
const got = require('got');
// const insertTicketDB = require('../db/insertTicket');
router.get('/:collectionFk', async(req, res) => {
const collectionFk = req.params.collectionFk;
ticketShelving(collectionFk);
const [collection] = await collectionSmartTag(collectionFk);
await insertTicket(collection);
res.json({message: 'SUCCESS'});
});
module.exports = router;
function ticketShelving(collectionFk) {// parametro collectionFk
select.selectCollectionSmartTag(collectionFk, function(err, data) {
insertTicket(data);
});
}
function insertTicket(consultaSql) {
const dataLogIn = require('../server');
const got = require('got');
(async() => {
const info = await dataLogIn.dataLogIn;
let key = info.data.token;
let currentUser = info.data.currentUser;
(async() => {
for (let i = 0; i < consultaSql.length; i++) {
const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
json: {
agencyId: currentUser.agencyId,
merchantId: currentUser.merchantId,
storeId: currentUser.storeId,
unitName: currentUser.unitName,
itemList: [
{
attrCategory: 'verdnatura',
attrName: 'withTicket',
barCode: consultaSql[i].shelvingFk + consultaSql[i].level, // Matricula + nivel
itemTitle: 'tagWithTicket',
productCode: consultaSql[i].ticketFk, // Ticket
qrCode: consultaSql[i].ticketFk,
custFeature1: consultaSql[i].clientFk, // Cliente
custFeature2: consultaSql[i].agencyFk, // Agencia de transporte
custFeature3: '', // consultaSql[i].workerFk, // Trabajador
custFeature4: consultaSql[i].wagon, // Wagon
}
]
},
responseType: 'json',
headers: {
'Authorization': key
async function insertTicket(collection) {
const info = await dataLogIn.dataLogIn;
const key = info.data.token;
const currentUser = info.data.currentUser;
for (let i = 0; i < collection.length; i++) {
await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
json: {
agencyId: currentUser.agencyId,
merchantId: currentUser.merchantId,
storeId: currentUser.storeId,
unitName: currentUser.unitName,
itemList: [
{
attrCategory: 'verdnatura',
attrName: 'withTicket',
barCode: collection[i].shelvingFk + collection[i].level, // Matricula + nivel
itemTitle: 'tagWithTicket',
productCode: collection[i].ticketFk, // Ticket
qrCode: collection[i].ticketFk,
custFeature1: collection[i].clientFk, // Cliente
custFeature2: collection[i].agencyFk, // Agencia de transporte
custFeature3: '', // collection[i].workerFk, // Trabajador
custFeature4: collection[i].wagon, // Wagon
}
});
]
},
responseType: 'json',
headers: {
'Authorization': key
}
})();
})();
});
}
}
exports.insertTicket = insertTicket;

View File

@ -1,44 +1,36 @@
const express = require('express');
const router = express.Router(); // eslint-disable-line
const select = require('../db/selectTicket');
const selectTicket = require('../db/selectTicket');
const config = require('../config');
const dataLogIn = require('../server');
const got = require('got');
router.get('/:ticket', async(req, res) => {
const ticket = req.params.ticket;
const ticketId = req.params.ticket;
const ticket = selectTicket(ticketId);
await insertFlash(ticket);
searchTicket(ticket);
res.json({message: 'SUCCESS'});
});
module.exports = router;
function searchTicket(ticket) {// parametro ticketFk
select.select(ticket, function(err, data) {
insertFlash(data);
async function insertFlash(ticket) {
const info = await dataLogIn.dataLogIn;
const key = info.data.token;
await got.post('http://app.etiquetaselectronicas.com:9999/led/excuteLed', { // eslint-disable-line
json: {
storeId: config.storeId,
lightCololr: 8,
lightTime: 30,
targetExecution: ticket[0].shelvingFk + ticket[0].level + '/tagWithTicket',
lightFrequency: 1
},
responseType: 'json',
headers: {
'Authorization': key
}
});
}
function insertFlash(qrySql) {
const dataLogIn = require('../server');
const got = require('got');
(async() => {
const info = await dataLogIn.dataLogIn;
let key = info.data.token;
(async() => {
const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/led/excuteLed', { // eslint-disable-line
json: {
storeId: config.storeId,
lightCololr: 8,
lightTime: 30,
targetExecution: qrySql[0].shelvingFk + qrySql[0].level + '/tagWithTicket',
lightFrequency: 1
},
responseType: 'json',
headers: {
'Authorization': key
}
});
})();
})();
}

View File

@ -1,4 +1,4 @@
const info = (async() => {
module.exports = (async() => {
const config = require('../config');
const encrypt = require('../utilities/encrypted');
const got = require('got');
@ -13,5 +13,3 @@ const info = (async() => {
});
return body;
})();
exports.info = info;

View File

@ -1,18 +0,0 @@
const express = require('express');
const router = express.Router(); // eslint-disable-line
router.get('/:collectionFk', async(req, res) => {
const maxWagon = require('../db/maxWagon__');
// var collectionFk = '273449';
const collectionFk = req.params.collectionFk;
maxWagon.maxWagon(collectionFk, function(err, max) {
let maxWagons = max[0].MaxWagons;
res.json({
message: 'SUCCESS',
maxWagons: maxWagons
});
});
});
module.exports = router;

2408
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,8 @@
"express": "^4.17.1",
"got": "^11.8.2",
"ip": "^1.1.5",
"mysql": "^2.18.1"
"mysql": "^2.18.1",
"mysql2": "^2.3.3",
"mysql2-promise": "^0.1.4"
}
}

View File

@ -1,15 +1,11 @@
const express = require('express');
const logIn = require('./methods/logIn');
const con = require('./db/connect');
const config = require('./config');
const app = express();
const dataLogIn = logIn.info;
const dataLogIn = logIn;
exports.dataLogIn = dataLogIn;
con.con.connect(function(err) {});
// app.use('/getNumShelving', require('./methods/setCollection__'));
app.use('/bindShelving', require('./methods/bindShelvingTag')); // smartTagFk, shelving, level
app.use('/insertTicket', require('./methods/bindTicketShelving')); // collectionFk

View File

@ -1,6 +1,5 @@
const crypto = require('crypto');
const got = require('got');
// const config = require('../config');
const encryptPassword = async password => {
const {body} = await got.get('http://app.etiquetaselectronicas.com:9999/user/getErpPublicKey', {

View File

@ -1,24 +1,16 @@
const con = require('../db/connect');
function isSmartTag(toFilter) {
const exp = /^A0A3B82[A-F0-9]{5}$/;
return exp.test(toFilter);
if (!exp.test(toFilter))
throw new Error('CODIGO DE ETIQUETA INCORRECTO');
}
let n = true;
function isShelving(toFilter) {
if (!Array.isArray(toFilter)) {
let s = toFilter;
toFilter = Array;
toFilter[0] = s;
}
const exp = /^[A-Z]{3}$/;
for (let i = 0; i < toFilter.length; i++) {
let state = exp.test(toFilter[i]);
if (state == false)
n = false;
}
if (n == false)
return false;
else
return true;
async function isShelving(shelving) {
const sql = `SELECT * FROM vn.shelving WHERE code = ?`;
const [response] = await con.query(sql, shelving);
if (response.length == 0)
throw new Error('CODIGO MATRICULA INCORRECTO');
}
exports.isSmartTag = isSmartTag;
exports.isShelving = isShelving;