This commit is contained in:
llopis15 2021-03-16 12:25:32 +01:00
parent 0051c7e9aa
commit 970ebd93a0
8 changed files with 73 additions and 68 deletions

View File

@ -4,11 +4,11 @@ const filter = require('./filter');
const insertDB = require('./db/insertDB')
function bindShelvingTag(barcode, shelving, level){
if(filter.filterBarcode(barcode)){
if(filter.filterShelving(shelving)){
if(filter.isBarcode(barcode)){
if(filter.isShelving(shelving)){
bindShelving.bindShelving(barcode, shelving, level);
insertShelving.insertShelving(shelving, level);
insertDB.insertDB(barcode, shelving, level);
//insertDB.insertDB(barcode, shelving, level);
}else{
console.log("¡MATRICULA INCORRECTA!")
}

View File

@ -1,20 +1,25 @@
const insert = require('./insertTicket');
const filter = require('./filter');
const select = require('./db/selectDB')
const select = require('./db/selectDB');
const maxWagon = require('./db/maxWagon');
var barcode = "A0A3B820690F";
var shelving = "BCD";///introducida por el usuario O en leida de la bbdd?
var collectionFk = '254';
//var shelving = "BCD";///introducida por el usuario O en leida de la bbdd?
var collectionFk = '274286';
function ticketCollection(collectionFk, shelving){//parametro collectionFk
function ticketCollection(collectionFk){//parametro collectionFk
select.select(collectionFk, function(err,data){
if(filter.filterShelving(shelving)){
insert.insertTicket(data, shelving)
}
else{
console.log("¡MATRICULA INCORRECTA!")
}
maxWagon.maxWagon(collectionFk,function(err,max){
console.log('Entra')
//aqui iria una función para pedir el numero de shelvings correspondientes
var shelving = ['ABC','DFG','HIJ']
//if(filter.isShelving(shelving)){
insert.insertTicket(data, shelving, 1)
//}else{
//console.log("¡MATRICULA INCORRECTA!")
//}
});
});
}
ticketCollection(collectionFk, shelving);
ticketCollection(collectionFk);

View File

@ -3,8 +3,11 @@ CREATE TABLE vn.smartTag (
shelvingFk varchar(10) NULL,
`level` int(11) NULL,
CONSTRAINT `PRIMARY` PRIMARY KEY (code)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci;
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci;
ALTER TABLE vn.smartTag MODIFY COLUMN shelvingFk varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL NULL;
ALTER TABLE vn.smartTag ADD CONSTRAINT smartTag_FK FOREIGN KEY (shelvingFk) REFERENCES vn.shelving(code);

14
db/maxWagon.js Normal file
View File

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

View File

@ -1,17 +0,0 @@
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', {
});
const publicKey=`-----BEGIN PUBLIC KEY-----\n${JSON.parse(body).data}\n-----END PUBLIC KEY-----`;
const externKey = {
key: publicKey,
padding: crypto.constants.RSA_PKCS1_PADDING
};
let buffer = Buffer.from(password);
return crypto.publicEncrypt(externKey, buffer).toString("base64");
};
exports.encryptPassword = encryptPassword;

View File

@ -1,10 +1,10 @@
function filterBarcode(toFilter){
function isBarcode(toFilter){
const exp = /^A0A3B82[A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9]$/
return exp.test(toFilter)
}
function filterShelving(toFilter){
function isShelving(toFilter){
const exp = /^[A-Z][A-Z][A-Z]$/
return exp.test(toFilter)
}
exports.filterBarcode = filterBarcode;
exports.filterShelving = filterShelving;
exports.isBarcode = isBarcode;
exports.isShelving = isShelving;

View File

@ -1,4 +1,4 @@
function insertTicket(consultaSql, shelving){
function insertTicket(consultaSql, shelving, max){
const config = require('./config');
const got = require('got');
(async() => {
@ -8,31 +8,33 @@ function insertTicket(consultaSql, shelving){
(async() => {
for(var i=0;i<consultaSql.length;i++){
for(var j=0;j<consultaSql[i].Level.toString().length;j++){
const { body } = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', {
json: {
agencyId: currentUser.agencyId,
merchantId: currentUser.merchantId,
storeId: currentUser.storeId,
unitName: currentUser.unitName,
itemList: [
{
attrCategory: "verdnatura",
attrName: "conTicket",
barCode: shelving + consultaSql[i].Level.toString().charAt(j),//Matricula + nivel
itemTitle: "Etiqueta Con ticket",
productCode: consultaSql[i].Ticket, //Ticket
custFeature1: consultaSql[i].Client, //Client
custFeature2: consultaSql[i].Agency //Agencia de transporte
}
]
},
responseType: 'json',
headers: {
"Authorization": key
}
})
console.log(body)
for(var j=0;j<max;j++){
for(var k=0;k<consultaSql[k].Level.toString().length;k++){
const { body } = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', {
json: {
agencyId: currentUser.agencyId,
merchantId: currentUser.merchantId,
storeId: currentUser.storeId,
unitName: currentUser.unitName,
itemList: [
{
attrCategory: "verdnatura",
attrName: "conTicket",
barCode: shelving[j] + consultaSql[i].Level.toString().charAt(k),//Matricula + nivel
itemTitle: "Etiqueta Con ticket",
productCode: consultaSql[i].Ticket, //Ticket
custFeature1: consultaSql[i].Client, //Client
custFeature2: consultaSql[i].Agency //Agencia de transporte
}
]
},
responseType: 'json',
headers: {
"Authorization": key
}
})
console.log(body + ':' + consultaSql[i].Ticket)
}
}
}
})();

View File

@ -1,6 +1,6 @@
const crypto = require('crypto');
const got = require('got');
const config = require('./config');
const config = require('../config');
const encryptPassword = async(password) => {
const { body } = await got.get('http://app.etiquetaselectronicas.com:9999/user/getErpPublicKey', {
@ -14,6 +14,4 @@ const encryptPassword = async(password) => {
return crypto.publicEncrypt(externKey, buffer).toString("base64");
};
//rebase
exports.encryptPassword = encryptPassword;