7265 lines
330 KiB
Java
7265 lines
330 KiB
Java
|
|
package it.acxent.cc;
|
||
|
|
|
||
|
|
import it.acxent.anag.Clifor;
|
||
|
|
import it.acxent.anag.ListinoArticolo;
|
||
|
|
import it.acxent.art.Articolo;
|
||
|
|
import it.acxent.art.ArticoloCR;
|
||
|
|
import it.acxent.art.ArticoloFornitore;
|
||
|
|
import it.acxent.art.Marca;
|
||
|
|
import it.acxent.art.StatoUsato;
|
||
|
|
import it.acxent.common.CrontabInterface;
|
||
|
|
import it.acxent.common.StatusMsg;
|
||
|
|
import it.acxent.db.ApplParmFull;
|
||
|
|
import it.acxent.db.DBAdapter;
|
||
|
|
import it.acxent.db.ResParm;
|
||
|
|
import it.acxent.mail.MailAccount;
|
||
|
|
import it.acxent.mail.MailMessage;
|
||
|
|
import it.acxent.mail.MailProperties;
|
||
|
|
import it.acxent.mail.MailService;
|
||
|
|
import it.acxent.util.Debug;
|
||
|
|
import it.acxent.util.DoubleOperator;
|
||
|
|
import it.acxent.util.StringTokenizer;
|
||
|
|
import it.acxent.util.Timer;
|
||
|
|
import it.acxent.util.Vectumerator;
|
||
|
|
import it.acxent.util.XLSFileReader;
|
||
|
|
import java.io.BufferedReader;
|
||
|
|
import java.io.File;
|
||
|
|
import java.io.FileReader;
|
||
|
|
import java.sql.Date;
|
||
|
|
import java.sql.Timestamp;
|
||
|
|
import java.text.NumberFormat;
|
||
|
|
import java.util.Calendar;
|
||
|
|
import java.util.HashSet;
|
||
|
|
import javax.mail.Address;
|
||
|
|
import javax.mail.Message;
|
||
|
|
import javax.mail.Multipart;
|
||
|
|
import javax.mail.internet.InternetAddress;
|
||
|
|
import javax.mail.internet.MimeBodyPart;
|
||
|
|
import javax.mail.internet.MimeMessage;
|
||
|
|
import javax.xml.parsers.DocumentBuilder;
|
||
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||
|
|
import org.w3c.dom.Document;
|
||
|
|
import org.w3c.dom.Element;
|
||
|
|
import org.w3c.dom.Node;
|
||
|
|
import org.w3c.dom.NodeList;
|
||
|
|
|
||
|
|
public class CCImport extends Debug implements CrontabInterface {
|
||
|
|
private static final long serialVersionUID = 4217105704596337740L;
|
||
|
|
|
||
|
|
private Attivita attivita;
|
||
|
|
|
||
|
|
public static final long INGRAM_TIPO_IMPORT_LISTINO = 0L;
|
||
|
|
|
||
|
|
public static final long INGRAM_TIPO_IMPORT_DISPO = 1L;
|
||
|
|
|
||
|
|
public static final long INGRAM_TIPO_IMPORT_SIAE = 2L;
|
||
|
|
|
||
|
|
private static final int FORNITORE_COMPUTERGROSS = 1970;
|
||
|
|
|
||
|
|
private static final int FORNITORE_DATAMATIC = 1971;
|
||
|
|
|
||
|
|
private static final int FORNITORE_ESPRINET = 1973;
|
||
|
|
|
||
|
|
private static final int FORNITORE_INGRAMMICRO = 1995;
|
||
|
|
|
||
|
|
private static final int FORNITORE_LOGICOM = 1997;
|
||
|
|
|
||
|
|
private static final int FORNITORE_FLEXIT = 2001;
|
||
|
|
|
||
|
|
private static final int FORNITORE_BREVI = 2111;
|
||
|
|
|
||
|
|
private static final int FORNITORE_RUNNER = 2117;
|
||
|
|
|
||
|
|
private static final int FORNITORE_BESTIT = 2131;
|
||
|
|
|
||
|
|
public static boolean threadImportCGross = false;
|
||
|
|
|
||
|
|
public static boolean threadImportFlexit = false;
|
||
|
|
|
||
|
|
public static boolean threadImportDatamatic = false;
|
||
|
|
|
||
|
|
public static boolean threadImportEsprinet = false;
|
||
|
|
|
||
|
|
public static boolean threadImportBrevi = false;
|
||
|
|
|
||
|
|
public static boolean threadImportIngramMicro = false;
|
||
|
|
|
||
|
|
public static boolean threadImportRunner = false;
|
||
|
|
|
||
|
|
public static boolean threadImportBestit = false;
|
||
|
|
|
||
|
|
public static boolean threadImportLocicom = false;
|
||
|
|
|
||
|
|
public static boolean threadGoogleMerchant = false;
|
||
|
|
|
||
|
|
public static boolean threadTrovaprezzi = false;
|
||
|
|
|
||
|
|
class ThreadImportComputerGross extends Thread {
|
||
|
|
private static final String CGROSS_URL = "212.19.96.117";
|
||
|
|
|
||
|
|
private static final String CGROSS_URL_sftp = "sftp.computergross.it";
|
||
|
|
|
||
|
|
private static final String CGROSS_USER = "82596";
|
||
|
|
|
||
|
|
private static final String CGROSS_PWD = "2t2bebql";
|
||
|
|
|
||
|
|
private static final String CGROSS_PWD_new = "wLT0%3n*aK5<eABo";
|
||
|
|
|
||
|
|
private static final int CGROSS_SFTP_PORT = 2022;
|
||
|
|
|
||
|
|
private static final String CGROSS_FILENAME = "LISTINO_82596.ZIP";
|
||
|
|
|
||
|
|
private final String TAG_THREAD_MSG = "IMPORT CGROSS ";
|
||
|
|
|
||
|
|
private ApplParmFull apFull;
|
||
|
|
|
||
|
|
private boolean sendEmail;
|
||
|
|
|
||
|
|
private String fileZipWeb = null;
|
||
|
|
|
||
|
|
public ThreadImportComputerGross(ApplParmFull apFull, String fileZip, boolean sendEmail) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.sendEmail = sendEmail;
|
||
|
|
this.fileZipWeb = fileZip;
|
||
|
|
if (!CCImport.isThreadCgrossAttivo()) {
|
||
|
|
CCImport.threadImportCGross = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void importGiornalieroZipCSV(String l_fileNameZip) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
boolean isNuovo = false;
|
||
|
|
String serie = "";
|
||
|
|
long l_id_tipoDaDafinire = 1L;
|
||
|
|
String targetDir = this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("DOCBASE").getTesto();
|
||
|
|
String fileCsv = targetDir + targetDir;
|
||
|
|
long l_id_fornitore = 1970L;
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
HashSet<Long> hsMarche = new HashSet<>();
|
||
|
|
HashSet<Long> hsTipi = new HashSet<>();
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
if (debug) {
|
||
|
|
fileCsv = "/Users/acolzi/Documents/webapps/cc/_tmp/LISTINO_82596.CSV";
|
||
|
|
} else {
|
||
|
|
new File(fileCsv).delete();
|
||
|
|
DBAdapter.unzip(l_fileNameZip, targetDir);
|
||
|
|
}
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT CGROSS ", "Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, l_id_fornitore);
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
reader = new BufferedReader(new FileReader(fileCsv));
|
||
|
|
if (reader != null) {
|
||
|
|
reader.readLine();
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
Marca marca = new Marca(this.apFull);
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
isNuovo = false;
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, ";", '"');
|
||
|
|
if (st.countToken() >= 6) {
|
||
|
|
String l_marcaDesc = st.getToken(0);
|
||
|
|
marca.findByDescrizioneImport(l_marcaDesc);
|
||
|
|
if (marca.getId_marca() > 0L) {
|
||
|
|
long dispoL, l1;
|
||
|
|
double prezzo, streetprice;
|
||
|
|
Date dataInizioPromo, dataFinePromo;
|
||
|
|
if (!hsMarche.contains(Long.valueOf(marca.getId_marca()))) {
|
||
|
|
hsMarche.add(Long.valueOf(marca.getId_marca()));
|
||
|
|
System.out.println("NUOVA marca GESTITA: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(5).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "CG_" + l_articoloCodiceFornitore;
|
||
|
|
String l_articoloCodiceProduttore = st.getToken(6).trim();
|
||
|
|
String l_codiceEan = st.getToken(4).trim();
|
||
|
|
if (l_codiceEan.length() < 13)
|
||
|
|
l_codiceEan = DBAdapter.zeroLeft(l_codiceEan, 13);
|
||
|
|
if (l_codiceEan.equals("0000000000000") || l_codiceEan.indexOf("99999999") >= 0)
|
||
|
|
l_codiceEan = "";
|
||
|
|
String l_categoriaImport = st.getToken(1).trim();
|
||
|
|
if (!st.getToken(1).trim().equals(st.getToken(2).trim()))
|
||
|
|
l_categoriaImport = l_categoriaImport + " " + l_categoriaImport;
|
||
|
|
if (!st.getToken(1).trim().equals(st.getToken(3).trim()) &&
|
||
|
|
!st.getToken(2).trim().equals(st.getToken(3).trim()))
|
||
|
|
l_categoriaImport = l_categoriaImport + " " + l_categoriaImport;
|
||
|
|
art.resetBean();
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("CG_6TR83ET"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(l_id_fornitore, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_codiceEan.isEmpty())
|
||
|
|
art.findByCodiceEanSerie(l_codiceEan, serie);
|
||
|
|
if (art.getId_articolo() == 0L && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.findByCodiceProduttoreMarca(l_articoloCodiceProduttore, marca.getId_marca());
|
||
|
|
String urlImmagine = "";
|
||
|
|
if (st.countToken() > 7);
|
||
|
|
String l_nome = st.getToken(7).trim();
|
||
|
|
String appoggiaPrezzo = st.getToken(12).trim();
|
||
|
|
String appoggiaStreetPrice = st.getToken(11).trim();
|
||
|
|
String inizioPromo = st.getToken(16).trim();
|
||
|
|
String finePromo = st.getToken(17).trim();
|
||
|
|
String dispo = st.getToken(20).trim();
|
||
|
|
String dispoFutura = st.getToken(21).trim();
|
||
|
|
l_descrizioneTecnica = "";
|
||
|
|
try {
|
||
|
|
prezzo = Double.valueOf(appoggiaPrezzo.replace(',', '.'));
|
||
|
|
streetprice = Double.valueOf(appoggiaStreetPrice.replace(',', '.'));
|
||
|
|
if (!inizioPromo.equals("0")) {
|
||
|
|
cal.set(1, Integer.valueOf(inizioPromo.substring(0, 4)).intValue());
|
||
|
|
cal.set(2, Integer.valueOf(inizioPromo.substring(4, 6)) - 1);
|
||
|
|
cal.set(5, Integer.valueOf(inizioPromo.substring(6, 8)).intValue());
|
||
|
|
dataInizioPromo = new Date(cal.getTimeInMillis());
|
||
|
|
} else {
|
||
|
|
dataInizioPromo = null;
|
||
|
|
}
|
||
|
|
if (!finePromo.equals("0")) {
|
||
|
|
cal.set(1, Integer.valueOf(finePromo.substring(0, 4)).intValue());
|
||
|
|
cal.set(2, Integer.valueOf(finePromo.substring(4, 6)) - 1);
|
||
|
|
cal.set(5, Integer.valueOf(finePromo.substring(6, 8)).intValue());
|
||
|
|
cal.add(6, -1);
|
||
|
|
dataFinePromo = new Date(cal.getTimeInMillis());
|
||
|
|
} else {
|
||
|
|
dataFinePromo = null;
|
||
|
|
}
|
||
|
|
if (dispo.startsWith(",")) {
|
||
|
|
dispoL = 0L;
|
||
|
|
} else {
|
||
|
|
dispoL = Long.parseLong(dispo.substring(0, dispo.indexOf(',')));
|
||
|
|
}
|
||
|
|
if (dispoFutura.startsWith(",")) {
|
||
|
|
long dispoFuturaL = 0L;
|
||
|
|
} else {
|
||
|
|
long dispoFuturaL = Long.parseLong(dispoFutura.substring(0, dispoFutura.indexOf(',')));
|
||
|
|
}
|
||
|
|
l1 = 0L;
|
||
|
|
if (dispoL + l1 > 0L) {
|
||
|
|
salvaArticoloNuovo = true;
|
||
|
|
} else {
|
||
|
|
salvaArticoloNuovo = false;
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato: " + appoggiaPrezzo + "\n" + currentLine + "\n");
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
if (art.getId_tipo() != 1L && !hsTipi.contains(Long.valueOf(art.getId_tipo())))
|
||
|
|
hsTipi.add(Long.valueOf(art.getId_tipo()));
|
||
|
|
System.out.print("*");
|
||
|
|
if (debug);
|
||
|
|
art.aggiornaCodiciAlternativi(false);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCategoriaImport().indexOf(l_categoriaImport) < 0)
|
||
|
|
art.setCategoriaImport(art.getCategoriaImport() + art.getCategoriaImport());
|
||
|
|
if (marca.getId_marca() > 0L && art.getId_marca() == 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else if (salvaArticoloNuovo) {
|
||
|
|
double percentualeRicarico;
|
||
|
|
isNuovo = true;
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(l_id_tipoDaDafinire);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setCategoriaImport(l_categoriaImport);
|
||
|
|
art.setId_marca(0L);
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setCostoNetto(prezzo);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (prezzo <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCodiciAlternativi().length() > 50)
|
||
|
|
System.out.println(art.getCodice() + " " + art.getCodice());
|
||
|
|
if (marca.getId_marca() > 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setId_fornitoreCostoNuovo(l_id_fornitore);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. Nuovo: " + l_articoloCodiceAlternativoFornitore + " - " +
|
||
|
|
art.getDescrizione() + " - " + rp.getMsg() + " - ");
|
||
|
|
artNuovoKO++;
|
||
|
|
} else {
|
||
|
|
artNuovo++;
|
||
|
|
if (urlImmagine != null && !urlImmagine.isEmpty() && urlImmagine.endsWith(".jpg"))
|
||
|
|
art.caricaImmaginaDaRemoto(urlImmagine);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L && prezzo > 0.0D) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(l_id_fornitore, art.getId_articolo(), -1L);
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(l_id_fornitore);
|
||
|
|
af.setCostoVecchio(af.getCostoTotale());
|
||
|
|
af.setCosto(prezzo);
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
af.setDispSede(dispoL);
|
||
|
|
af.setDispCash(l1);
|
||
|
|
af.setFlgPromo((dataFinePromo == null) ? 0L : 1L);
|
||
|
|
af.setStreetPrice(streetprice);
|
||
|
|
af.setDataInizioPromo(dataInizioPromo);
|
||
|
|
af.setDataFinePromo(dataFinePromo);
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
art.aggiornaPrezziEDispoByFornitori(streetprice, isNuovo);
|
||
|
|
if (art.getFlgModImportazione() == 2L) {
|
||
|
|
prezzoModificato++;
|
||
|
|
} else if (art.getFlgModImportazione() == 3L) {
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (art.getFlgEscludiWebArt() == 2L) {
|
||
|
|
articoloSospeso++;
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
sb = new StringBuilder(" Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE CGROSS " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT CGROSS ", sb.toString());
|
||
|
|
}
|
||
|
|
rp = Articolo.updateArticoloNonTrovati(this.apFull, "IMPORT CGROSS ", l_id_fornitore, hsMarche, hsTipi);
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! IMPORT CGROSS record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT CGROSS ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import Articolo e Prezzi COMPUTER GROSS " + serie + " avvenuta correttamente. - File:" + fileCsv + " - Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
sb.append(" - Update articoli non trovati: - ");
|
||
|
|
sb.append(rp.getMsg());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import Articolo e Prezzi CGROSS " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void run() {
|
||
|
|
boolean debug = false;
|
||
|
|
Timer timer = new Timer();
|
||
|
|
timer.start();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT CGROSS ", "...inizio ...");
|
||
|
|
String serverSftp = "sftp.computergross.it";
|
||
|
|
String user = "82596";
|
||
|
|
String passNew = "wLT0%3n*aK5<eABo";
|
||
|
|
String serie = "";
|
||
|
|
String l_fileZip = "LISTINO_82596.ZIP";
|
||
|
|
long l_id_fornitore = 1970L;
|
||
|
|
System.out.println("##############\n IMPORT CGROSS " + serie + "\nSTART: " + String.valueOf(timer.getTStart()));
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
String targetDir = this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("DOCBASE").getTesto();
|
||
|
|
String l_fileNameZip = targetDir + targetDir;
|
||
|
|
if (this.fileZipWeb == null || this.fileZipWeb.isEmpty()) {
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT CGROSS ", "Download nuovo file " + l_fileNameZip);
|
||
|
|
new File(l_fileNameZip).delete();
|
||
|
|
rp = DBAdapter.getFileViaSFtp(serverSftp, 2022, user, passNew, l_fileZip, l_fileNameZip);
|
||
|
|
} else {
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT CGROSS ", "File zip caricato via web: " + this.fileZipWeb);
|
||
|
|
l_fileNameZip = this.fileZipWeb;
|
||
|
|
}
|
||
|
|
if (rp.getStatus())
|
||
|
|
importGiornalieroZipCSV(l_fileNameZip);
|
||
|
|
timer.stop();
|
||
|
|
rp.setMsg("Import concluso. DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
if (this.sendEmail)
|
||
|
|
CCImport.this.sendArticoliCambiatiByEmail(this.apFull, rp.getMsg(), l_id_fornitore);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT CGROSS ", rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, "IMPORT CGROSS ");
|
||
|
|
CCImport.threadImportCGross = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgEbay() == 1L) {
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
bean.startThreadAllineaEbay(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgAmz() == 1L) {
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
bean.startThreadAllineaAmz(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
@Deprecated
|
||
|
|
class ThreadImportDatamaticOLD extends Thread {
|
||
|
|
private ApplParmFull apFull;
|
||
|
|
|
||
|
|
private String fileCsvlarge;
|
||
|
|
|
||
|
|
private final String TAG_THREAD_MSG = "IMPORT ALSO ";
|
||
|
|
|
||
|
|
private boolean sendEmail;
|
||
|
|
|
||
|
|
private static final long l_id_fornitore = 1971L;
|
||
|
|
|
||
|
|
private static final long l_id_tipoDaDafinire = 1L;
|
||
|
|
|
||
|
|
public ThreadImportDatamaticOLD(ApplParmFull apFull, String fileXls, boolean sendEmail) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.fileCsvlarge = fileXls;
|
||
|
|
this.sendEmail = sendEmail;
|
||
|
|
if (!CCImport.isThreadDatamaticAttivo()) {
|
||
|
|
CCImport.threadImportDatamatic = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void run() {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
String TAG_THREAD_MSG = "IMPORT ALSO ";
|
||
|
|
Timer timer = new Timer();
|
||
|
|
timer.start();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ALSO ", "...inizio ...");
|
||
|
|
String serie = "";
|
||
|
|
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
|
||
|
|
System.out.println("##############\nIMPORT ALSO " + serie + "\nSTART: " + start.toString());
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
BufferedReader reader = null;
|
||
|
|
String targetDir = this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("DOCBASE").getTesto();
|
||
|
|
String fileCsv = this.fileCsvlarge.substring(this.fileCsvlarge.lastIndexOf('/') + 1);
|
||
|
|
String l_fileName = this.fileCsvlarge;
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/" + fileCsv;
|
||
|
|
boolean isLarge = false, isUtenteFinale = false, isXls = false;
|
||
|
|
if (l_fileName.toLowerCase().endsWith("xls")) {
|
||
|
|
isXls = true;
|
||
|
|
} else {
|
||
|
|
try {
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
String currentLine = reader.readLine();
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, ";", '"');
|
||
|
|
if (st.countToken() == 8) {
|
||
|
|
isLarge = true;
|
||
|
|
} else if (st.countToken() == 12) {
|
||
|
|
isUtenteFinale = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setException(e);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
if (isXls)
|
||
|
|
rp = importXls(l_fileName);
|
||
|
|
if (isLarge) {
|
||
|
|
rp = importLarge(l_fileName);
|
||
|
|
} else if (isUtenteFinale) {
|
||
|
|
rp = importUtenteFinale(l_fileName);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
timer.stop();
|
||
|
|
rp.setMsg("Import concluso. DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
if (this.sendEmail)
|
||
|
|
CCImport.this.sendArticoliCambiatiByEmail(this.apFull, rp.getMsg(), 1971L);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ALSO ", rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, "IMPORT ALSO ");
|
||
|
|
CCImport.threadImportDatamatic = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importLarge(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
long SOSPENDI_DOPO_N_GG = this.apFull.getParm("CC_SOSPENDI_DOPO_N_GG_NO_IMPORT").getNumeroLong();
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/large.csv";
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ALSO ", "Large: Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 1971L);
|
||
|
|
String currentLine = "";
|
||
|
|
int colCodiceVendor = 0;
|
||
|
|
int colCodiceEan = 1;
|
||
|
|
int colCodiceFornitore = 2;
|
||
|
|
int colNome = 3;
|
||
|
|
int colPrezzo = 6;
|
||
|
|
int colPrezzoPromo = 7;
|
||
|
|
int colDispoCentrale = 4;
|
||
|
|
int colDispoCash = 5;
|
||
|
|
try {
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
reader.readLine();
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
isPromo = false;
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, ";", '"');
|
||
|
|
if (st.countToken() >= 6) {
|
||
|
|
long dispoL, dispoCashL, dispoTotL;
|
||
|
|
double prezzo;
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(colCodiceFornitore).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "DM_" + l_articoloCodiceFornitore;
|
||
|
|
String l_articoloCodiceProduttore = st.getToken(colCodiceVendor).trim();
|
||
|
|
String l_codiceEan = st.getToken(colCodiceEan).trim();
|
||
|
|
if (l_codiceEan.length() < 13)
|
||
|
|
l_codiceEan = DBAdapter.zeroLeft(l_codiceEan, 13);
|
||
|
|
if (l_codiceEan.equals("0000000000000") || l_codiceEan.indexOf("99999999") >= 0)
|
||
|
|
l_codiceEan = "";
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("CG_7DB75EA"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(1971L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_codiceEan.isEmpty())
|
||
|
|
art.findByCodiceEanSerie(l_codiceEan, serie);
|
||
|
|
String urlImmagine = "";
|
||
|
|
if (st.countToken() > 7);
|
||
|
|
String l_nome = st.getToken(colNome).trim();
|
||
|
|
String appoggiaPrezzo = st.getToken(colPrezzo).trim();
|
||
|
|
if (!st.getToken(colPrezzoPromo).trim().equals("0,00"))
|
||
|
|
isPromo = true;
|
||
|
|
String dispo = st.getToken(colDispoCentrale).trim();
|
||
|
|
String dispoCash = st.getToken(colDispoCash).trim();
|
||
|
|
l_descrizioneTecnica = "";
|
||
|
|
try {
|
||
|
|
prezzo = Double.valueOf(appoggiaPrezzo.replace(',', '.'));
|
||
|
|
dispoL = Long.parseLong(dispo);
|
||
|
|
dispoCashL = Long.parseLong(dispoCash);
|
||
|
|
dispoTotL = dispoL + dispoCashL;
|
||
|
|
if (dispoTotL > 0L) {
|
||
|
|
salvaArticoloNuovo = true;
|
||
|
|
} else {
|
||
|
|
salvaArticoloNuovo = false;
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato: " + appoggiaPrezzo + "\n" + currentLine + "\n");
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (debug);
|
||
|
|
if (dispoTotL > 0L) {
|
||
|
|
if (art.getCostoNetto() != prezzo) {
|
||
|
|
art.setFlgModImportazione(2L);
|
||
|
|
prezzoModificato++;
|
||
|
|
} else {
|
||
|
|
art.setCostoNuovo(0.0D);
|
||
|
|
art.setFlgModImportazione(3L);
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
double streetprice = art.getStreetPrice();
|
||
|
|
} else {
|
||
|
|
art.setFlgModImportazione(3L);
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
art.aggiornaCodiciAlternativi(false);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L && prezzo > 0.0D) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(1971L, art.getId_articolo(), -1L);
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(1971L);
|
||
|
|
af.setCostoVecchio(af.getCostoTotale());
|
||
|
|
af.setCosto(prezzo);
|
||
|
|
af.setStreetPrice(af.getStreetPrice());
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
af.setDispCash(dispoCashL);
|
||
|
|
af.setDispSede(dispoL);
|
||
|
|
af.setFlgPromo(isPromo ? 1L : 0L);
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
double dispoF = af.getDispoFornitoriByArticolo(art.getId_articolo());
|
||
|
|
art.setQuantita(dispoF);
|
||
|
|
if (dispoF == 0.0D) {
|
||
|
|
if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
art.setFlgEscludiWebArt(2L);
|
||
|
|
articoloSospeso++;
|
||
|
|
}
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 2L && art.getId_tipo() > 0L) {
|
||
|
|
art.setFlgEscludiWebArt(0L);
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
art.superSave();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Large: Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE DATAMATIC " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ALSO ", sb.toString());
|
||
|
|
}
|
||
|
|
if (SOSPENDI_DOPO_N_GG > 0L)
|
||
|
|
bean.update("UPDATE ARTICOLO SET flgEscludiWebArt=2,flgEscludiWeb=2 WHERE codice LIKE '" + serie + "%' and flgModImportazione = 0 and DATEDIFF(CURDATE(), dataUltimoImport)>=" + SOSPENDI_DOPO_N_GG + ";");
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! IMPORT ALSO record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ALSO ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import Articolo e Prezzi DATAMATIC " + serie + " avvenuta correttamente. Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import Articolo e Prezzi DATAMATIC " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importUtenteFinale(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/utenteFinale.csv";
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ALSO ", "Utente Finale: Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 1971L);
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
reader.readLine();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
Marca marca = new Marca(this.apFull);
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, ";", '"');
|
||
|
|
if (st.countToken() >= 12) {
|
||
|
|
String l_marcaDesc = st.getToken(3);
|
||
|
|
marca.findByDescrizioneImport(l_marcaDesc);
|
||
|
|
if (marca.getId_marca() > 0L) {
|
||
|
|
double streetprice;
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(0).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "DM_" + l_articoloCodiceFornitore;
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("DM_HPW1A53A"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(1971L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
String urlImmagine = "";
|
||
|
|
if (st.countToken() > 7);
|
||
|
|
String l_nome = st.getToken(1).trim();
|
||
|
|
String appoggiaStreetPrice = st.getToken(9).trim();
|
||
|
|
try {
|
||
|
|
streetprice = Double.valueOf(appoggiaStreetPrice.replace(',', '.'));
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato: " + appoggiaStreetPrice + "\n" + currentLine + "\n");
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (debug);
|
||
|
|
if (art.getCodice().equals("0000004221"))
|
||
|
|
System.out.println(l_articoloCodiceFornitore);
|
||
|
|
if (streetprice > 0.0D && art.getStreetPrice() != streetprice) {
|
||
|
|
art.setStreetPrice(streetprice);
|
||
|
|
if (streetprice <= 0.0D || art.getPrezzoArticolo(null).getPrezzoBase() <= streetprice) {
|
||
|
|
art.setFlgModImportazione(3L);
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
art.setFlgModImportazione(3L);
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (marca.getId_marca() > 0L && art.getId_marca() == 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
if (rp.getStatus() && art.getId_articolo() > 0L) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(1971L, art.getId_articolo(), -1L);
|
||
|
|
if (streetprice != 0.0D && af.getStreetPrice() != streetprice) {
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(1971L);
|
||
|
|
af.setStreetPrice(streetprice);
|
||
|
|
rp = af.save();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else if (salvaArticoloNuovo) {
|
||
|
|
double percentualeRicarico;
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
if (marca.getId_marca() > 0L && art.getId_marca() == 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (streetprice <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
ListinoArticolo lab = art.getListinoArticoloBase();
|
||
|
|
lab.setPrezzoLA(streetprice);
|
||
|
|
lab.save();
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. Nuovo: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
artNuovoKO++;
|
||
|
|
} else {
|
||
|
|
artNuovo++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
System.out.println("marca scartata: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Utente Finale: Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE DATAMATIC " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ALSO ", sb.toString());
|
||
|
|
}
|
||
|
|
bean.update("UPDATE ARTICOLO SET flgEscludiWebArt=2,flgEscludiWeb=2 WHERE codice LIKE '" + serie + "%' and flgModImportazione = 0 and quantita <=0;");
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! IMPORT ALSO record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ALSO ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import Articolo e Prezzi DATAMATIC " + serie + " avvenuta correttamente. Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import Utente Finale (street price) DATAMATIC " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importXlsOLD(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
HashSet<Long> hsMarche = new HashSet<>();
|
||
|
|
HashSet<Long> hsTipi = new HashSet<>();
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
String fileCsv = l_fileName + ".csv";
|
||
|
|
rp = DBAdapter.convertXlsToCsv(this.apFull, l_fileName, fileCsv);
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
l_fileName = fileCsv;
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/largeXLS.csv";
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ALSO ", "Large: Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 1971L);
|
||
|
|
int colCodiceVendor = 0;
|
||
|
|
int colCodiceEan = -1;
|
||
|
|
int colCodiceFornitore = 1;
|
||
|
|
int colNome = 2;
|
||
|
|
int colPrezzo = 5;
|
||
|
|
int colDispoCentrale = 3;
|
||
|
|
int colDispoCash = 4;
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
reader.readLine();
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
isPromo = false;
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, ";", '"');
|
||
|
|
if (st.countToken() >= 6) {
|
||
|
|
String l_codiceEan;
|
||
|
|
long dispoL, dispoCashL, dispoTotL;
|
||
|
|
double prezzo;
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(colCodiceFornitore).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "DM_" + l_articoloCodiceFornitore;
|
||
|
|
String l_articoloCodiceProduttore = st.getToken(colCodiceVendor).trim();
|
||
|
|
if (colCodiceEan < 0) {
|
||
|
|
l_codiceEan = "";
|
||
|
|
} else {
|
||
|
|
l_codiceEan = st.getToken(colCodiceEan).trim();
|
||
|
|
if (l_codiceEan.length() < 13)
|
||
|
|
l_codiceEan = DBAdapter.zeroLeft(l_codiceEan, 13);
|
||
|
|
if (l_codiceEan.equals("0000000000000") || l_codiceEan.indexOf("99999999") >= 0)
|
||
|
|
l_codiceEan = "";
|
||
|
|
}
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("CG_7DB75EA"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(1971L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
String urlImmagine = "";
|
||
|
|
if (st.countToken() > 7);
|
||
|
|
String l_nome = st.getToken(colNome).trim();
|
||
|
|
String appoggiaPrezzo = st.getToken(colPrezzo).trim();
|
||
|
|
if (!st.getToken(7).trim().equals("0,00"))
|
||
|
|
isPromo = true;
|
||
|
|
String dispo = st.getToken(colDispoCentrale).trim();
|
||
|
|
String dispoCash = st.getToken(colDispoCash).trim();
|
||
|
|
l_descrizioneTecnica = "";
|
||
|
|
try {
|
||
|
|
prezzo = Double.valueOf(appoggiaPrezzo.replace(',', '.'));
|
||
|
|
dispoL = Long.parseLong(dispo);
|
||
|
|
dispoCashL = Long.parseLong(dispoCash);
|
||
|
|
dispoTotL = dispoL + dispoCashL;
|
||
|
|
if (dispoTotL > 0L) {
|
||
|
|
salvaArticoloNuovo = true;
|
||
|
|
} else {
|
||
|
|
salvaArticoloNuovo = false;
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato: " + appoggiaPrezzo + "\n" + currentLine + "\n");
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (art.getId_tipo() != 1L && !hsTipi.contains(Long.valueOf(art.getId_tipo())))
|
||
|
|
hsTipi.add(Long.valueOf(art.getId_tipo()));
|
||
|
|
if (!hsMarche.contains(Long.valueOf(art.getId_marca()))) {
|
||
|
|
hsMarche.add(Long.valueOf(art.getId_marca()));
|
||
|
|
System.out.println("NUOVA marca GESTITA: " + art.getMarca().getDescrizione());
|
||
|
|
}
|
||
|
|
if (debug);
|
||
|
|
if (dispoTotL > 0L) {
|
||
|
|
if (art.getCostoNetto() != prezzo) {
|
||
|
|
art.setFlgModImportazione(2L);
|
||
|
|
prezzoModificato++;
|
||
|
|
} else {
|
||
|
|
art.setCostoNuovo(0.0D);
|
||
|
|
art.setFlgModImportazione(3L);
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
double streetprice = art.getStreetPrice();
|
||
|
|
} else {
|
||
|
|
art.setFlgModImportazione(3L);
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
art.aggiornaCodiciAlternativi(false);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L && prezzo > 0.0D) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(1971L, art.getId_articolo(), -1L);
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(1971L);
|
||
|
|
af.setCostoVecchio(af.getCostoTotale());
|
||
|
|
af.setCosto(prezzo);
|
||
|
|
af.setStreetPrice(af.getStreetPrice());
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
af.setDispCash(dispoCashL);
|
||
|
|
af.setDispSede(dispoL);
|
||
|
|
af.setFlgPromo(isPromo ? 1L : 0L);
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
double dispoF = af.getDispoFornitoriByArticolo(art.getId_articolo());
|
||
|
|
art.setQuantita(dispoF);
|
||
|
|
if (dispoF == 0.0D) {
|
||
|
|
if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
art.setFlgEscludiWebArt(2L);
|
||
|
|
articoloSospeso++;
|
||
|
|
}
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 2L && art.getId_tipo() > 0L) {
|
||
|
|
art.setFlgEscludiWebArt(0L);
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
art.superSave();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Large: Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE DATAMATIC " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ALSO ", sb.toString());
|
||
|
|
}
|
||
|
|
rp = Articolo.updateArticoloNonTrovati(this.apFull, "IMPORT ALSO ", 1971L, hsMarche, hsTipi);
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! IMPORT ALSO record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ALSO ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import Articolo e Prezzi DATAMATIC " + serie + " avvenuta correttamente. - File:" + l_fileName + " - Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
sb.append(" - Update articoli non trovati: - ");
|
||
|
|
sb.append(rp.getMsg());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import Articolo e Prezzi DATAMATIC " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importXls(String l_fileName) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class ThreadImportEsprinet extends Thread {
|
||
|
|
private ApplParmFull apFull;
|
||
|
|
|
||
|
|
private String fileCsvlarge;
|
||
|
|
|
||
|
|
private final String TAG_THREAD_MSG = "IMPORT ESPRINET ";
|
||
|
|
|
||
|
|
private boolean sendEmail;
|
||
|
|
|
||
|
|
private static final long l_id_fornitore = 1973L;
|
||
|
|
|
||
|
|
private static final long l_id_tipoDaDafinire = 1L;
|
||
|
|
|
||
|
|
public ThreadImportEsprinet(ApplParmFull apFull, String fileXls, boolean sendEmail) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.fileCsvlarge = fileXls;
|
||
|
|
this.sendEmail = sendEmail;
|
||
|
|
if (!CCImport.isThreadEsprinetAttivo()) {
|
||
|
|
CCImport.threadImportEsprinet = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void run() {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
String TAG_THREAD_MSG = "IMPORT ESPRINET ";
|
||
|
|
Timer timer = new Timer();
|
||
|
|
timer.start();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ESPRINET ", "...inizio ...");
|
||
|
|
String serie = "";
|
||
|
|
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
|
||
|
|
System.out.println("##############\nIMPORT ESPRINET " + serie + "\nSTART: " + start.toString());
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
BufferedReader reader = null;
|
||
|
|
String targetDir = this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("DOCBASE").getTesto();
|
||
|
|
String fileCsv = this.fileCsvlarge.substring(this.fileCsvlarge.lastIndexOf('/') + 1);
|
||
|
|
String l_fileName = this.fileCsvlarge;
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/" + fileCsv;
|
||
|
|
if (l_fileName.endsWith(".csv")) {
|
||
|
|
rp = importGiornalieroCSV(l_fileName);
|
||
|
|
} else {
|
||
|
|
rp = importGiornalieroXls(l_fileName);
|
||
|
|
}
|
||
|
|
timer.stop();
|
||
|
|
rp.setMsg("Import concluso. DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
if (this.sendEmail)
|
||
|
|
CCImport.this.sendArticoliCambiatiByEmail(this.apFull, rp.getMsg(), 1973L);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ESPRINET ", rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, "IMPORT ESPRINET ");
|
||
|
|
CCImport.threadImportEsprinet = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgEbay() == 1L) {
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
bean.startThreadAllineaEbay(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgAmz() == 1L) {
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
bean.startThreadAllineaAmz(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importGiornalieroXls(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
boolean isNuovo = false;
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
StringBuilder scartoCodici = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
HashSet<Long> hsMarche = new HashSet<>();
|
||
|
|
HashSet<Long> hsTipi = new HashSet<>();
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Downloads/Listino-Storageaaaa2.xlsx";
|
||
|
|
XLSFileReader xfr = new XLSFileReader(l_fileName);
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ESPRINET ", ": Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 1973L);
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
Marca marca = new Marca(this.apFull);
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
xfr.nextRecord();
|
||
|
|
while (xfr.nextRecord()) {
|
||
|
|
isNuovo = false;
|
||
|
|
isPromo = false;
|
||
|
|
String l_marcaDesc = xfr.getField(5);
|
||
|
|
marca.findByDescrizioneImport(l_marcaDesc);
|
||
|
|
if (marca.getId_marca() > 0L) {
|
||
|
|
long dispoL;
|
||
|
|
double prezzo, streetprice;
|
||
|
|
if (!hsMarche.contains(Long.valueOf(marca.getId_marca()))) {
|
||
|
|
hsMarche.add(Long.valueOf(marca.getId_marca()));
|
||
|
|
System.out.println("NUOVA marca GESTITA: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
String l_articoloCodiceFornitore = xfr.getField(0).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "ES_" + l_articoloCodiceFornitore;
|
||
|
|
String l_articoloCodiceProduttore = xfr.getField(1).trim();
|
||
|
|
String l_codiceEan = xfr.getField(2).trim();
|
||
|
|
if (l_codiceEan.equals("0000000000000") || l_codiceEan.indexOf("99999999") >= 0)
|
||
|
|
l_codiceEan = "";
|
||
|
|
String l_categoriaImport = xfr.getField(7).trim();
|
||
|
|
if (!xfr.getField(7).trim().equals(xfr.getField(9).trim()))
|
||
|
|
l_categoriaImport = l_categoriaImport + " " + l_categoriaImport;
|
||
|
|
art.resetBean();
|
||
|
|
String l_nome = xfr.getField(3).trim();
|
||
|
|
l_nome = l_nome.replace("Ñ", "");
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceFornitore.equals("MZ-V7S250BW"))
|
||
|
|
System.out.println("cod prod: " + l_articoloCodiceFornitore);
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(1973L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_codiceEan.isEmpty()) {
|
||
|
|
if (l_codiceEan.length() < 13)
|
||
|
|
l_codiceEan = DBAdapter.zeroLeft(l_codiceEan, 13);
|
||
|
|
art.findByCodiceEanSerie(l_codiceEan, serie);
|
||
|
|
if (art.getId_articolo() == 0L && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.findByCodiceProduttoreMarca(l_articoloCodiceProduttore, marca.getId_marca());
|
||
|
|
}
|
||
|
|
String urlImmagine = "";
|
||
|
|
String appoggiaPrezzo = xfr.getField(15).trim();
|
||
|
|
appoggiaPrezzo = appoggiaPrezzo.replaceAll("[^0-9,]", "");
|
||
|
|
String appoggiaStreetPrice = xfr.getField(14).trim();
|
||
|
|
appoggiaStreetPrice = appoggiaStreetPrice.replaceAll("[^0-9,]", "");
|
||
|
|
String dispo = xfr.getField(10).trim();
|
||
|
|
l_descrizioneTecnica = "";
|
||
|
|
try {
|
||
|
|
prezzo = Double.valueOf(appoggiaPrezzo.replace(',', '.'));
|
||
|
|
streetprice = Double.valueOf(appoggiaStreetPrice.replace(',', '.'));
|
||
|
|
dispoL = (long)Double.parseDouble(dispo);
|
||
|
|
long dispoTotL = dispoL;
|
||
|
|
if (dispoTotL > 0L) {
|
||
|
|
salvaArticoloNuovo = true;
|
||
|
|
} else {
|
||
|
|
salvaArticoloNuovo = false;
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato: " + appoggiaPrezzo + "\n" + currentLine + "\n");
|
||
|
|
recordErrati++;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (art.getId_tipo() != 1L && !hsTipi.contains(Long.valueOf(art.getId_tipo())))
|
||
|
|
hsTipi.add(Long.valueOf(art.getId_tipo()));
|
||
|
|
if (debug);
|
||
|
|
art.aggiornaCodiciAlternativi(false);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCategoriaImport().indexOf(l_categoriaImport) < 0)
|
||
|
|
art.setCategoriaImport(art.getCategoriaImport() + art.getCategoriaImport());
|
||
|
|
if (marca.getId_marca() > 0L && art.getId_marca() == 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else if (salvaArticoloNuovo) {
|
||
|
|
double percentualeRicarico;
|
||
|
|
isNuovo = true;
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setCategoriaImport(l_categoriaImport);
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setCostoNetto(prezzo);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (prezzo <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setId_marca(0L);
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setCostoNetto(prezzo);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (prezzo <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCodiciAlternativi().length() > 50)
|
||
|
|
System.out.println(art.getCodice() + " " + art.getCodice());
|
||
|
|
if (marca.getId_marca() > 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setId_fornitoreCostoNuovo(1973L);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
DoubleOperator prezzoPubblico = new DoubleOperator(percentualeRicarico);
|
||
|
|
prezzoPubblico.setScale(2, 5);
|
||
|
|
prezzoPubblico.divide(100.0F);
|
||
|
|
prezzoPubblico.add(1);
|
||
|
|
prezzoPubblico.multiply(prezzo);
|
||
|
|
if (streetprice > 0.0D && prezzoPubblico.getResult() > streetprice)
|
||
|
|
prezzoPubblico = new DoubleOperator(streetprice);
|
||
|
|
ListinoArticolo lab = art.getListinoArticoloBase();
|
||
|
|
if (prezzoPubblico.getResult() != lab.getPrezzoIvaLA()) {
|
||
|
|
System.out.println("Articolo " + art.getCodice() + " prezzo cambiato da " + lab.getPrezzoIvaLA() + " a " +
|
||
|
|
prezzoPubblico.getResult());
|
||
|
|
lab.setPrezzoLA(prezzoPubblico.getResult());
|
||
|
|
lab.save();
|
||
|
|
}
|
||
|
|
art.setStreetPrice(streetprice);
|
||
|
|
if (art.getPrezzoArticolo(null).getPrezzoBase() > streetprice) {
|
||
|
|
ListinoArticolo listinoArticoloBase = art.getListinoArticoloBase();
|
||
|
|
System.out.println(listinoArticoloBase.getId_listinoArticolo());
|
||
|
|
listinoArticoloBase.setPrezzoLA(streetprice);
|
||
|
|
rp = listinoArticoloBase.save();
|
||
|
|
}
|
||
|
|
if (!l_descrizioneTecnica.isEmpty())
|
||
|
|
art.setDescTxtLang("descrizioneCommerciale", "it", l_descrizioneTecnica);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. Nuovo: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
artNuovoKO++;
|
||
|
|
} else {
|
||
|
|
artNuovo++;
|
||
|
|
if (urlImmagine != null && !urlImmagine.isEmpty() && urlImmagine.endsWith(".jpg"))
|
||
|
|
art.caricaImmaginaDaRemoto(urlImmagine);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L && prezzo > 0.0D) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(1973L, art.getId_articolo(), -1L);
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(1973L);
|
||
|
|
af.setCostoVecchio(af.getCostoTotale());
|
||
|
|
af.setCosto(prezzo);
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
af.setStreetPrice(streetprice);
|
||
|
|
af.setDispSede(dispoL);
|
||
|
|
af.setFlgPromo(isPromo ? 1L : 0L);
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
art.aggiornaPrezziEDispoByFornitori(streetprice, isNuovo);
|
||
|
|
if (art.getFlgModImportazione() == 2L) {
|
||
|
|
prezzoModificato++;
|
||
|
|
} else if (art.getFlgModImportazione() == 3L) {
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (art.getFlgEscludiWebArt() == 2L) {
|
||
|
|
articoloSospeso++;
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
System.out.println("marca scartata: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Large: Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE ESPRINET " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ESPRINET ", sb.toString());
|
||
|
|
}
|
||
|
|
rp = Articolo.updateArticoloNonTrovati(this.apFull, "IMPORT ESPRINET ", 1973L, hsMarche, hsTipi);
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! IMPORT ESPRINET record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ESPRINET ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import Articolo e Prezzi ESPRINET " + serie + " avvenuta correttamente. - File:" + l_fileName + " - Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
sb.append(" - Update articoli non trovati: - ");
|
||
|
|
sb.append(rp.getMsg());
|
||
|
|
sb.append(" - DEBUG ESPRINTET SCARTO CODICI: - ");
|
||
|
|
sb.append(scartoCodici.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import Articolo e Prezzi ESPRINET " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importGiornalieroCSV(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
boolean isNuovo = false;
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
long SOSPENDI_DOPO_N_GG = this.apFull.getParm("CC_SOSPENDI_DOPO_N_GG_NO_IMPORT").getNumeroLong();
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/large.csv";
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ESPRINET ", ":xxx Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 1973L);
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
Marca marca = new Marca(this.apFull);
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
reader.readLine();
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
isNuovo = false;
|
||
|
|
isPromo = false;
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, ";", '"');
|
||
|
|
if (st.countToken() >= 6) {
|
||
|
|
String l_marcaDesc = st.getToken(5);
|
||
|
|
marca.findByDescrizioneImport(l_marcaDesc);
|
||
|
|
if (marca.getId_marca() > 0L) {
|
||
|
|
long dispoL;
|
||
|
|
double prezzo, streetprice;
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(0).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "ES_" + l_articoloCodiceFornitore;
|
||
|
|
String l_articoloCodiceProduttore = st.getToken(1).trim();
|
||
|
|
String l_codiceEan = st.getToken(2).trim();
|
||
|
|
if (l_codiceEan.length() < 13)
|
||
|
|
l_codiceEan = DBAdapter.zeroLeft(l_codiceEan, 13);
|
||
|
|
if (l_codiceEan.equals("0000000000000") || l_codiceEan.indexOf("99999999") >= 0)
|
||
|
|
l_codiceEan = "";
|
||
|
|
art.resetBean();
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("CG_7DB75EA"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(1973L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_codiceEan.isEmpty())
|
||
|
|
art.findByCodiceEanSerie(l_codiceEan, serie);
|
||
|
|
if (art.getId_articolo() == 0L && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.findByCodiceProduttoreMarca(l_articoloCodiceProduttore, marca.getId_marca());
|
||
|
|
String urlImmagine = "";
|
||
|
|
if (st.countToken() > 7);
|
||
|
|
String l_nome = st.getToken(3).trim();
|
||
|
|
String appoggiaPrezzo = st.getToken(15).trim();
|
||
|
|
appoggiaPrezzo = appoggiaPrezzo.replaceAll("[^0-9,]", "");
|
||
|
|
String appoggiaStreetPrice = st.getToken(14).trim();
|
||
|
|
appoggiaStreetPrice = appoggiaStreetPrice.replaceAll("[^0-9,]", "");
|
||
|
|
String dispo = st.getToken(10).trim();
|
||
|
|
l_descrizioneTecnica = "";
|
||
|
|
try {
|
||
|
|
prezzo = Double.valueOf(appoggiaPrezzo.replace(',', '.'));
|
||
|
|
streetprice = Double.valueOf(appoggiaStreetPrice.replace(',', '.'));
|
||
|
|
dispoL = Long.parseLong(dispo);
|
||
|
|
long dispoTotL = dispoL;
|
||
|
|
if (dispoTotL > 0L) {
|
||
|
|
salvaArticoloNuovo = true;
|
||
|
|
} else {
|
||
|
|
salvaArticoloNuovo = false;
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato:" + appoggiaPrezzo + "\n" + currentLine + "\n");
|
||
|
|
recordErrati++;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (debug);
|
||
|
|
art.aggiornaCodiciAlternativi(false);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCodiciAlternativi().length() > 50)
|
||
|
|
System.out.println(art.getCodice() + " " + art.getCodice());
|
||
|
|
if (marca.getId_marca() > 0L && art.getId_marca() == 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else if (salvaArticoloNuovo) {
|
||
|
|
double percentualeRicarico;
|
||
|
|
isNuovo = true;
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setCostoNetto(prezzo);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (prezzo <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setId_marca(0L);
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setCostoNetto(prezzo);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (prezzo <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCodiciAlternativi().length() > 50)
|
||
|
|
System.out.println(art.getCodice() + " " + art.getCodice());
|
||
|
|
if (marca.getId_marca() > 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setId_fornitoreCostoNuovo(1973L);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
DoubleOperator prezzoPubblico = new DoubleOperator(percentualeRicarico);
|
||
|
|
prezzoPubblico.setScale(2, 5);
|
||
|
|
prezzoPubblico.divide(100.0F);
|
||
|
|
prezzoPubblico.add(1);
|
||
|
|
prezzoPubblico.multiply(prezzo);
|
||
|
|
if (streetprice > 0.0D && prezzoPubblico.getResult() > streetprice)
|
||
|
|
prezzoPubblico = new DoubleOperator(streetprice);
|
||
|
|
ListinoArticolo lab = art.getListinoArticoloBase();
|
||
|
|
if (prezzoPubblico.getResult() != lab.getPrezzoIvaLA()) {
|
||
|
|
System.out.println("Articolo " + art.getCodice() + " prezzo cambiato da " +
|
||
|
|
lab.getPrezzoIvaLA() + " a " + prezzoPubblico.getResult());
|
||
|
|
lab.setPrezzoLA(prezzoPubblico.getResult());
|
||
|
|
lab.save();
|
||
|
|
}
|
||
|
|
art.setStreetPrice(streetprice);
|
||
|
|
if (art.getPrezzoArticolo(null).getPrezzoBase() > streetprice) {
|
||
|
|
ListinoArticolo listinoArticoloBase = art.getListinoArticoloBase();
|
||
|
|
System.out.println(listinoArticoloBase.getId_listinoArticolo());
|
||
|
|
listinoArticoloBase.setPrezzoLA(streetprice);
|
||
|
|
rp = listinoArticoloBase.save();
|
||
|
|
}
|
||
|
|
if (!l_descrizioneTecnica.isEmpty())
|
||
|
|
art.setDescTxtLang("descrizioneCommerciale", "it", l_descrizioneTecnica);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. Nuovo: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
artNuovoKO++;
|
||
|
|
} else {
|
||
|
|
artNuovo++;
|
||
|
|
if (urlImmagine != null && !urlImmagine.isEmpty() && urlImmagine.endsWith(".jpg"))
|
||
|
|
art.caricaImmaginaDaRemoto(urlImmagine);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L && prezzo > 0.0D) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(1973L, art.getId_articolo(), -1L);
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(1973L);
|
||
|
|
af.setCostoVecchio(af.getCostoTotale());
|
||
|
|
af.setCosto(prezzo);
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
af.setStreetPrice(streetprice);
|
||
|
|
af.setDispSede(dispoL);
|
||
|
|
af.setFlgPromo(isPromo ? 1L : 0L);
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
art.aggiornaPrezziEDispoByFornitori(streetprice, isNuovo);
|
||
|
|
if (art.getFlgModImportazione() == 2L) {
|
||
|
|
prezzoModificato++;
|
||
|
|
} else if (art.getFlgModImportazione() == 3L) {
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (art.getFlgEscludiWebArt() == 2L) {
|
||
|
|
articoloSospeso++;
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
System.out.println("marca scartata: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Large: Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE ESPRINET " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ESPRINET ", sb.toString());
|
||
|
|
}
|
||
|
|
if (SOSPENDI_DOPO_N_GG > 0L)
|
||
|
|
bean.update("UPDATE ARTICOLO SET flgEscludiWebArt=2,flgEscludiWeb=2 WHERE codice LIKE '" + serie + "%' and flgModImportazione = 0 and DATEDIFF(CURDATE(), dataUltimoImport)>=" + SOSPENDI_DOPO_N_GG + ";");
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! IMPORT ESPRINET record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT ESPRINET ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import Articolo e Prezzi ESPRINET " + serie + " avvenuta correttamente. Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import Articolo e Prezzi ESPRINET " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class ThreadGoogleFtp extends Thread {
|
||
|
|
private ApplParmFull apFull;
|
||
|
|
|
||
|
|
private ArticoloCR CR;
|
||
|
|
|
||
|
|
private final String TAG_THREAD_MSG = "GOOGLE MERCHANT FTP ";
|
||
|
|
|
||
|
|
public ThreadGoogleFtp(ApplParmFull apFull, ArticoloCR CR) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.CR = CR;
|
||
|
|
if (!CCImport.isThreadGoogleMerchant()) {
|
||
|
|
CCImport.threadGoogleMerchant = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void run() {
|
||
|
|
boolean debug = false;
|
||
|
|
Timer timer = new Timer();
|
||
|
|
timer.start();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "GOOGLE MERCHANT FTP ", "...inizio ...");
|
||
|
|
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
|
||
|
|
System.out.println("##############\n GOOGLE MERCHANT FTP \nSTART: " + start.toString());
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
Articolo articolo = new Articolo(this.apFull);
|
||
|
|
rp = articolo.creaFileXmlGoogle(this.CR, true, false);
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
String temp = (String)rp.getReturnObj();
|
||
|
|
String fileDainviare = articolo.getDocBase() + articolo.getDocBase() + this.apFull.getParm("PATH_TMP").getTesto();
|
||
|
|
String fileRemoto = this.CR.getFileNameGoogle();
|
||
|
|
String user = this.apFull.getParm("GOOGLE_FTP_USER").getTesto();
|
||
|
|
String pass = this.apFull.getParm("GOOGLE_FTP_PASSWORD").getTesto();
|
||
|
|
if (!articolo.isLocalhost()) {
|
||
|
|
DBAdapter.sendFileViaSFtp("partnerupload.google.com", 19321, "[partnerupload.google.com]:19321 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUvACPnrXEiscmd7NoP7diO1w3uP9uGJ55/SDL5eviKZhy/WLTLMGRcJDWj3GPRVdAy2xVVOU4IxUIK8nxdZP5O0s5bJVzT2XRP4IXYKUrPn7AkQlnifP7M0InAMnK7S1KHvwBgWBaGfb0OBeI46a+iKBduCMD9xER6ymTVbcgNzt1o52vNGTUiQp28Q5jUBs3yvQ8Ag7d4U0qEioV95ef4AbjDwO8jV09hQGjBIsTZoMo2Tmo+FVKah2YO0+QFKe1pk5zL2nXlgF7hUxN65lIeS3PhRZzVF80Qe5vXjjuKfiJVkBdSxLoq84uXx6XCjvWci2JbTUbsavoaDO3VBy5", user, pass, fileDainviare, fileRemoto);
|
||
|
|
} else {
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "GOOGLE MERCHANT FTP ", "Invio file ftp google annullato (localhost):\n" + rp.getMsg());
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "GOOGLE MERCHANT FTP ", "Creazione file google xml fallito:\n" + rp.getMsg());
|
||
|
|
}
|
||
|
|
timer.stop();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "GOOGLE MERCHANT FTP ", "Invio concluso. DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, "GOOGLE MERCHANT FTP ");
|
||
|
|
CCImport.threadGoogleMerchant = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class ThreadImportDatamatic extends Thread {
|
||
|
|
private ApplParmFull apFull;
|
||
|
|
|
||
|
|
private final String TAG_THREAD_MSG = "CHECK MAIL DATAMATIC ";
|
||
|
|
|
||
|
|
private boolean sendEmail;
|
||
|
|
|
||
|
|
private static final long l_id_fornitore = 1971L;
|
||
|
|
|
||
|
|
private boolean DEBUG_CK_MAIL_DM = false;
|
||
|
|
|
||
|
|
private String fileCsvlarge;
|
||
|
|
|
||
|
|
private static final long l_id_tipoDaDafinire = 1L;
|
||
|
|
|
||
|
|
public ThreadImportDatamatic(ApplParmFull apFull, String fileXls, boolean sendEmail) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.fileCsvlarge = fileXls;
|
||
|
|
this.sendEmail = sendEmail;
|
||
|
|
if (!CCImport.isThreadDatamaticAttivo()) {
|
||
|
|
CCImport.threadImportDatamatic = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public ThreadImportDatamatic(ApplParmFull apFull, boolean sendMail) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.sendEmail = sendMail;
|
||
|
|
if (!CCImport.isThreadDatamaticAttivo()) {
|
||
|
|
CCImport.threadImportDatamatic = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void run() {
|
||
|
|
Timer timer = new Timer();
|
||
|
|
timer.start();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ", "...inizio ...");
|
||
|
|
boolean debug = false;
|
||
|
|
String serie = "";
|
||
|
|
System.out.println("##############\nIMPORT ALSO " + serie + "\nSTART: " + String.valueOf(timer.getTStart()));
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
if (this.fileCsvlarge != null && !this.fileCsvlarge.isEmpty()) {
|
||
|
|
BufferedReader reader = null;
|
||
|
|
String targetDir = this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("DOCBASE").getTesto();
|
||
|
|
String fileCsv = this.fileCsvlarge.substring(this.fileCsvlarge.lastIndexOf('/') + 1);
|
||
|
|
String l_fileName = this.fileCsvlarge;
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/" + fileCsv;
|
||
|
|
boolean isLarge = false, isUtenteFinale = false, isXls = false;
|
||
|
|
if (l_fileName.toLowerCase().endsWith("xls")) {
|
||
|
|
isXls = true;
|
||
|
|
} else {
|
||
|
|
try {
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
String currentLine = reader.readLine();
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, ";", '"');
|
||
|
|
if (st.countToken() == 8) {
|
||
|
|
isLarge = true;
|
||
|
|
} else if (st.countToken() == 12) {
|
||
|
|
isUtenteFinale = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setException(e);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
if (isXls)
|
||
|
|
rp = importXls(l_fileName);
|
||
|
|
if (isLarge) {
|
||
|
|
rp = importLarge(l_fileName);
|
||
|
|
} else if (isUtenteFinale) {
|
||
|
|
rp = importUtenteFinale(l_fileName);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
timer.stop();
|
||
|
|
rp.setMsg("Import concluso. DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
if (this.sendEmail)
|
||
|
|
CCImport.this.sendArticoliCambiatiByEmail(this.apFull, rp.getMsg(), 1971L);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ", rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ");
|
||
|
|
CCImport.threadImportDatamatic = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
} else {
|
||
|
|
MailAccount account = new MailAccount("mail.acxent.it", "acx-ammi", "Pinocchio9901!");
|
||
|
|
if (!this.DEBUG_CK_MAIL_DM) {
|
||
|
|
rp = fetchMessages(account, DBAdapter.getToday());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(true);
|
||
|
|
String l_file = "/Users/acolzi/Documents/webapps/cc/_tmp/AAAdatam.XLS";
|
||
|
|
l_file = "/Users/acolzi/Downloads/FLX3933324.XLS";
|
||
|
|
rp.setMsg(l_file);
|
||
|
|
}
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
String fileXLS = rp.getMsg();
|
||
|
|
importXls(fileXLS);
|
||
|
|
}
|
||
|
|
System.out.println("############FINE IMPORT DATAMATIC");
|
||
|
|
timer.stop();
|
||
|
|
rp.setMsg("Import concluso. DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
if (this.sendEmail) {
|
||
|
|
System.out.println("############ invio mail DATAMATIC");
|
||
|
|
CCImport.this.sendArticoliCambiatiByEmail(this.apFull, rp.getMsg(), 1971L);
|
||
|
|
System.out.println("############ invio mail DATAMATIC fatto?????");
|
||
|
|
}
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ", rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ");
|
||
|
|
CCImport.threadImportDatamatic = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgEbay() == 1L) {
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
bean.startThreadAllineaEbay(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgAmz() == 1L) {
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
bean.startThreadAllineaAmz(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm fetchMessages(MailAccount account, Date theDate) {
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
MailService mailService = new MailService(account.getMailServer(), account.getMailUser(), account.getMailPassword());
|
||
|
|
rp = mailService.login();
|
||
|
|
int messageCount = 0, messageSaved = 0;
|
||
|
|
if (rp.getStatus())
|
||
|
|
try {
|
||
|
|
String from = "info@ALSOTECHNOLOGYMILANO.IT";
|
||
|
|
String theSubject = "Listino Also elaborato in XLS";
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String fileNameXls = "DM_" + String.valueOf(cal.getTimeInMillis()) + ".xls";
|
||
|
|
String destFile = this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("PATH_TMP").getTesto();
|
||
|
|
Message[] messages = mailService.getMessages(theDate);
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("Mail also non trovata");
|
||
|
|
System.out.println("message id fromAddress subject");
|
||
|
|
for (int i = 0; i < messages.length; i++) {
|
||
|
|
messageCount++;
|
||
|
|
String text = "";
|
||
|
|
String messageId = "";
|
||
|
|
String subject = "";
|
||
|
|
try {
|
||
|
|
messageId = messages[i].getHeader("Message-ID")[0];
|
||
|
|
} catch (Exception e) {}
|
||
|
|
if (messageId == null || messageId.isEmpty()) {
|
||
|
|
MimeMessage cmsg = new MimeMessage(mailService.getMimeMessages(i));
|
||
|
|
messageId = cmsg.getMessageID();
|
||
|
|
}
|
||
|
|
subject = messages[i].getSubject();
|
||
|
|
Address[] fromAddress = messages[i].getFrom();
|
||
|
|
InternetAddress address = (InternetAddress)fromAddress[0];
|
||
|
|
String temp = messageId + " " + messageId + " " + String.valueOf(messages[i].getSentDate()) + " " + String.valueOf(address);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ", temp);
|
||
|
|
System.out.println(temp);
|
||
|
|
if (subject.indexOf(theSubject) >= 0) {
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ", "Trovata mail con oggetto " + theSubject);
|
||
|
|
String contentType = messages[i].getContentType();
|
||
|
|
String messageContent = "";
|
||
|
|
String attachFiles = "";
|
||
|
|
if (contentType.contains("multipart")) {
|
||
|
|
Multipart multiPart = (Multipart)messages[i].getContent();
|
||
|
|
int numberOfParts = multiPart.getCount();
|
||
|
|
for (int partCount = 0; partCount < numberOfParts; partCount++) {
|
||
|
|
MimeBodyPart part = (MimeBodyPart)multiPart.getBodyPart(partCount);
|
||
|
|
if ("attachment".equalsIgnoreCase(part.getDisposition())) {
|
||
|
|
String fileName = part.getFileName();
|
||
|
|
attachFiles = attachFiles + attachFiles + ", ";
|
||
|
|
part.saveFile(destFile);
|
||
|
|
} else {
|
||
|
|
messageContent = part.getContent().toString();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (attachFiles.length() > 1)
|
||
|
|
attachFiles = attachFiles.substring(0, attachFiles.length() - 2);
|
||
|
|
}
|
||
|
|
if (new File(destFile).exists()) {
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(destFile);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
mailService.logout();
|
||
|
|
} catch (Exception e) {
|
||
|
|
e.printStackTrace();
|
||
|
|
rp.setException(e);
|
||
|
|
rp.setStatus(false);
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importXls(String l_fileName) {
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
boolean isNuovo = false;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
HashSet<Long> hsMarche = new HashSet<>();
|
||
|
|
HashSet<Long> hsTipi = new HashSet<>();
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
String fileCsv = l_fileName + ".csv";
|
||
|
|
if (!this.DEBUG_CK_MAIL_DM) {
|
||
|
|
rp = DBAdapter.convertXlsToCsv(this.apFull, l_fileName, fileCsv);
|
||
|
|
} else {
|
||
|
|
rp.setStatus(true);
|
||
|
|
}
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
l_fileName = fileCsv;
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
if (this.DEBUG_CK_MAIL_DM)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/largeXLS.csv";
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ", "Large XLS: Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 1971L);
|
||
|
|
int colCodiceVendor = 0;
|
||
|
|
int colCodiceEan = -1;
|
||
|
|
int colCodiceFornitore = 1;
|
||
|
|
int colNome = 2;
|
||
|
|
int colPrezzo = 5;
|
||
|
|
int colPrezzoPromo = 6;
|
||
|
|
int colDispoCentrale = 3;
|
||
|
|
int colDispoCash = 4;
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
reader.readLine();
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_codiceEan = "";
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
isPromo = false;
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, ";", '"');
|
||
|
|
if (st.countToken() >= 6) {
|
||
|
|
long dispoL, dispoCashL;
|
||
|
|
double prezzo;
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(colCodiceFornitore).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "DM_" + l_articoloCodiceFornitore;
|
||
|
|
String l_articoloCodiceProduttore = st.getToken(colCodiceVendor).trim();
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
if (this.DEBUG_CK_MAIL_DM &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("DM_400AJPC"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(1971L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.findByCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
String urlImmagine = "";
|
||
|
|
if (st.countToken() > 7);
|
||
|
|
String l_nome = st.getToken(colNome).trim();
|
||
|
|
String appoggiaPrezzo = st.getToken(colPrezzo).trim();
|
||
|
|
if (!st.getToken(colPrezzoPromo).trim().equals("0,00"))
|
||
|
|
isPromo = true;
|
||
|
|
String dispo = st.getToken(colDispoCentrale).trim();
|
||
|
|
String dispoCash = st.getToken(colDispoCash).trim();
|
||
|
|
l_descrizioneTecnica = "";
|
||
|
|
try {
|
||
|
|
prezzo = Double.valueOf(appoggiaPrezzo.replace(',', '.'));
|
||
|
|
dispoL = Long.parseLong(dispo);
|
||
|
|
dispoCashL = Long.parseLong(dispoCash);
|
||
|
|
long dispoTotL = dispoL + dispoCashL;
|
||
|
|
if (dispoTotL > 0L) {
|
||
|
|
salvaArticoloNuovo = true;
|
||
|
|
} else {
|
||
|
|
salvaArticoloNuovo = false;
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato:" + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato: " + appoggiaPrezzo + "\n" + currentLine + "\n");
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (art.getId_tipo() != 1L && !hsTipi.contains(Long.valueOf(art.getId_tipo())))
|
||
|
|
hsTipi.add(Long.valueOf(art.getId_tipo()));
|
||
|
|
if (this.DEBUG_CK_MAIL_DM);
|
||
|
|
art.aggiornaCodiciAlternativi(false);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L && prezzo > 0.0D) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(1971L, art.getId_articolo(), -1L);
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(1971L);
|
||
|
|
af.setCostoVecchio(af.getCostoTotale());
|
||
|
|
af.setCosto(prezzo);
|
||
|
|
af.setStreetPrice(af.getStreetPrice());
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
af.setDispCash(dispoCashL);
|
||
|
|
af.setDispSede(dispoL);
|
||
|
|
af.setFlgPromo(isPromo ? 1L : 0L);
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
art.aggiornaPrezziEDispoByFornitori(0.0D, isNuovo);
|
||
|
|
if (art.getFlgModImportazione() == 2L) {
|
||
|
|
prezzoModificato++;
|
||
|
|
} else if (art.getFlgModImportazione() == 3L) {
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (art.getFlgEscludiWebArt() == 2L) {
|
||
|
|
articoloSospeso++;
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Large xls MAIL: Record processati: ");
|
||
|
|
if (this.DEBUG_CK_MAIL_DM)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE DATAMATIC " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ", sb.toString());
|
||
|
|
}
|
||
|
|
rp = Articolo.updateArticoloNonTrovati(this.apFull, "CHECK MAIL DATAMATIC ", 1971L, hsMarche, hsTipi);
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! CHECK MAIL DATAMATIC record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import Articolo e Prezzi DATAMATIC " + serie + " avvenuta correttamente. Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
sb.append(" - Update articoli non trovati: - ");
|
||
|
|
sb.append(rp.getMsg());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import Articolo e Prezzi DATAMATIC " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
private ResParm importLargeDatamaticFromFileXls(String fileCsvlarge, String serie) {
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
rp = importXls(fileCsvlarge);
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importLarge(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
long SOSPENDI_DOPO_N_GG = this.apFull.getParm("CC_SOSPENDI_DOPO_N_GG_NO_IMPORT").getNumeroLong();
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/large.csv";
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ", "Large: Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 1971L);
|
||
|
|
String currentLine = "";
|
||
|
|
int colCodiceVendor = 0;
|
||
|
|
int colCodiceEan = 1;
|
||
|
|
int colCodiceFornitore = 2;
|
||
|
|
int colNome = 3;
|
||
|
|
int colPrezzo = 6;
|
||
|
|
int colPrezzoPromo = 7;
|
||
|
|
int colDispoCentrale = 4;
|
||
|
|
int colDispoCash = 5;
|
||
|
|
try {
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
reader.readLine();
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
isPromo = false;
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, ";", '"');
|
||
|
|
if (st.countToken() >= 6) {
|
||
|
|
long dispoL, dispoCashL, dispoTotL;
|
||
|
|
double prezzo;
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(colCodiceFornitore).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "DM_" + l_articoloCodiceFornitore;
|
||
|
|
String l_articoloCodiceProduttore = st.getToken(colCodiceVendor).trim();
|
||
|
|
String l_codiceEan = st.getToken(colCodiceEan).trim();
|
||
|
|
if (l_codiceEan.length() < 13)
|
||
|
|
l_codiceEan = DBAdapter.zeroLeft(l_codiceEan, 13);
|
||
|
|
if (l_codiceEan.equals("0000000000000") || l_codiceEan.indexOf("99999999") >= 0)
|
||
|
|
l_codiceEan = "";
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("CG_7DB75EA"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(1971L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_codiceEan.isEmpty())
|
||
|
|
art.findByCodiceEanSerie(l_codiceEan, serie);
|
||
|
|
String urlImmagine = "";
|
||
|
|
if (st.countToken() > 7);
|
||
|
|
String l_nome = st.getToken(colNome).trim();
|
||
|
|
String appoggiaPrezzo = st.getToken(colPrezzo).trim();
|
||
|
|
if (!st.getToken(colPrezzoPromo).trim().equals("0,00"))
|
||
|
|
isPromo = true;
|
||
|
|
String dispo = st.getToken(colDispoCentrale).trim();
|
||
|
|
String dispoCash = st.getToken(colDispoCash).trim();
|
||
|
|
l_descrizioneTecnica = "";
|
||
|
|
try {
|
||
|
|
prezzo = Double.valueOf(appoggiaPrezzo.replace(',', '.'));
|
||
|
|
dispoL = Long.parseLong(dispo);
|
||
|
|
dispoCashL = Long.parseLong(dispoCash);
|
||
|
|
dispoTotL = dispoL + dispoCashL;
|
||
|
|
if (dispoTotL > 0L) {
|
||
|
|
salvaArticoloNuovo = true;
|
||
|
|
} else {
|
||
|
|
salvaArticoloNuovo = false;
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato: " + appoggiaPrezzo + "\n" + currentLine + "\n");
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (debug);
|
||
|
|
if (dispoTotL > 0L) {
|
||
|
|
if (art.getCostoNetto() != prezzo) {
|
||
|
|
art.setFlgModImportazione(2L);
|
||
|
|
prezzoModificato++;
|
||
|
|
} else {
|
||
|
|
art.setCostoNuovo(0.0D);
|
||
|
|
art.setFlgModImportazione(3L);
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
double streetprice = art.getStreetPrice();
|
||
|
|
} else {
|
||
|
|
art.setFlgModImportazione(3L);
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
art.aggiornaCodiciAlternativi(false);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L && prezzo > 0.0D) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(1971L, art.getId_articolo(), -1L);
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(1971L);
|
||
|
|
af.setCostoVecchio(af.getCostoTotale());
|
||
|
|
af.setCosto(prezzo);
|
||
|
|
af.setStreetPrice(af.getStreetPrice());
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
af.setDispCash(dispoCashL);
|
||
|
|
af.setDispSede(dispoL);
|
||
|
|
af.setFlgPromo(isPromo ? 1L : 0L);
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
double dispoF = af.getDispoFornitoriByArticolo(art.getId_articolo());
|
||
|
|
art.setQuantita(dispoF);
|
||
|
|
if (dispoF == 0.0D) {
|
||
|
|
if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
art.setFlgEscludiWebArt(2L);
|
||
|
|
articoloSospeso++;
|
||
|
|
}
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 2L && art.getId_tipo() > 0L) {
|
||
|
|
art.setFlgEscludiWebArt(0L);
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
art.superSave();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Large: Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE DATAMATIC " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ", sb.toString());
|
||
|
|
}
|
||
|
|
if (SOSPENDI_DOPO_N_GG > 0L)
|
||
|
|
bean.update("UPDATE ARTICOLO SET flgEscludiWebArt=2,flgEscludiWeb=2 WHERE codice LIKE '" + serie + "%' and flgModImportazione = 0 and DATEDIFF(CURDATE(), dataUltimoImport)>=" + SOSPENDI_DOPO_N_GG + ";");
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! CHECK MAIL DATAMATIC record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import Articolo e Prezzi DATAMATIC " + serie + " avvenuta correttamente. Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import Articolo e Prezzi DATAMATIC " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importUtenteFinale(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/utenteFinale.csv";
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ", "Utente Finale: Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 1971L);
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
reader.readLine();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
Marca marca = new Marca(this.apFull);
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, ";", '"');
|
||
|
|
if (st.countToken() >= 12) {
|
||
|
|
String l_marcaDesc = st.getToken(3);
|
||
|
|
marca.findByDescrizioneImport(l_marcaDesc);
|
||
|
|
if (marca.getId_marca() > 0L) {
|
||
|
|
double streetprice;
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(0).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "DM_" + l_articoloCodiceFornitore;
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("DM_HPW1A53A"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(1971L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
String urlImmagine = "";
|
||
|
|
if (st.countToken() > 7);
|
||
|
|
String l_nome = st.getToken(1).trim();
|
||
|
|
String appoggiaStreetPrice = st.getToken(9).trim();
|
||
|
|
try {
|
||
|
|
streetprice = Double.valueOf(appoggiaStreetPrice.replace(',', '.'));
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato: " + appoggiaStreetPrice + "\n" + currentLine + "\n");
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (debug);
|
||
|
|
if (art.getCodice().equals("0000004221"))
|
||
|
|
System.out.println(l_articoloCodiceFornitore);
|
||
|
|
if (streetprice > 0.0D && art.getStreetPrice() != streetprice) {
|
||
|
|
art.setStreetPrice(streetprice);
|
||
|
|
if (streetprice <= 0.0D || art.getPrezzoArticolo(null).getPrezzoBase() <= streetprice) {
|
||
|
|
art.setFlgModImportazione(3L);
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
art.setFlgModImportazione(3L);
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (marca.getId_marca() > 0L && art.getId_marca() == 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
if (rp.getStatus() && art.getId_articolo() > 0L) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(1971L, art.getId_articolo(), -1L);
|
||
|
|
if (streetprice != 0.0D && af.getStreetPrice() != streetprice) {
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(1971L);
|
||
|
|
af.setStreetPrice(streetprice);
|
||
|
|
rp = af.save();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else if (salvaArticoloNuovo) {
|
||
|
|
double percentualeRicarico;
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
if (marca.getId_marca() > 0L && art.getId_marca() == 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (streetprice <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
ListinoArticolo lab = art.getListinoArticoloBase();
|
||
|
|
lab.setPrezzoLA(streetprice);
|
||
|
|
lab.save();
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. Nuovo: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
artNuovoKO++;
|
||
|
|
} else {
|
||
|
|
artNuovo++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
System.out.println("marca scartata: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Utente Finale: Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE DATAMATIC " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ", sb.toString());
|
||
|
|
}
|
||
|
|
bean.update("UPDATE ARTICOLO SET flgEscludiWebArt=2,flgEscludiWeb=2 WHERE codice LIKE '" + serie + "%' and flgModImportazione = 0 and quantita <=0;");
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! CHECK MAIL DATAMATIC record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL DATAMATIC ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import Articolo e Prezzi DATAMATIC " + serie + " avvenuta correttamente. Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import Utente Finale (street price) DATAMATIC " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class ThreadImportIngramMicro extends Thread {
|
||
|
|
private static final String INGRAM_URL_FTP_LISTINO = "ftpsecure.ingrammicro.com";
|
||
|
|
|
||
|
|
private static final String INGRAM_URL_FTP_DISPO = "ftpsecure.ingrammicro.com";
|
||
|
|
|
||
|
|
private static final String INGRAM_URL_SFTP_LISTINO = "mercury.ingrammicro.com";
|
||
|
|
|
||
|
|
private static final String INGRAM_URL_SFTP_DISPO = "mercury.ingrammicro.com";
|
||
|
|
|
||
|
|
private static final String INGRAM_URL_SFTP_SIAE = "mercury.ingrammicro.com";
|
||
|
|
|
||
|
|
private static final String INGRAM_FTP_DIR_LISTINO = "/FUSION/IT/ABL630/";
|
||
|
|
|
||
|
|
private static final String INGRAM_FTP_DIR_DISPO = "/FUSION/IT/AVAIL/";
|
||
|
|
|
||
|
|
private static final String INGRAM_SFTP_DIR_LISTINO = "/";
|
||
|
|
|
||
|
|
private static final String INGRAM_SFTP_DIR_DISPO = "/AVAIL/";
|
||
|
|
|
||
|
|
private static final String INGRAM_SFTP_DIR_SIAE = "/";
|
||
|
|
|
||
|
|
private static final String INGRAM_USER = "IT630910";
|
||
|
|
|
||
|
|
private static final String INGRAM_PWD = "pAc6uT0P";
|
||
|
|
|
||
|
|
private static final String INGRAM_SFTP_PWD = "cvaTL07@0%";
|
||
|
|
|
||
|
|
private static final String INGRAM_FILE_DISPO = "TOTITHRL.ZIP";
|
||
|
|
|
||
|
|
private static final String INGRAM_FILE_LISTINO = "PRICE.ZIP";
|
||
|
|
|
||
|
|
private static final String INGRAM_FILE_SIAE = "ITSKUFEE.ZIP";
|
||
|
|
|
||
|
|
private ApplParmFull apFull;
|
||
|
|
|
||
|
|
private boolean sendEmail;
|
||
|
|
|
||
|
|
private long tipoImport;
|
||
|
|
|
||
|
|
private String TAG_THREAD_MSG = "IMPORT INGRAMMICRO ";
|
||
|
|
|
||
|
|
private static final long l_id_tipoDaDafinire = 1L;
|
||
|
|
|
||
|
|
private static final long l_id_fornitore = 1995L;
|
||
|
|
|
||
|
|
public ThreadImportIngramMicro(ApplParmFull apFull, long l_tipoImport, boolean sendEmail) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.sendEmail = sendEmail;
|
||
|
|
this.tipoImport = l_tipoImport;
|
||
|
|
if (!CCImport.isThreadIngramMicroAttivo()) {
|
||
|
|
CCImport.threadImportIngramMicro = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void run() {
|
||
|
|
String fileZip;
|
||
|
|
boolean debug = false;
|
||
|
|
Timer timer = new Timer();
|
||
|
|
timer.start();
|
||
|
|
String server = "mercury.ingrammicro.com";
|
||
|
|
String tipoImportS = " DISPO ";
|
||
|
|
String dirFtp = "/AVAIL/";
|
||
|
|
String user = "IT630910";
|
||
|
|
String pass = "cvaTL07@0%";
|
||
|
|
String serie = "";
|
||
|
|
if (this.tipoImport == 0L) {
|
||
|
|
server = "mercury.ingrammicro.com";
|
||
|
|
fileZip = "PRICE.ZIP";
|
||
|
|
dirFtp = "/";
|
||
|
|
tipoImportS = " LISTINO ";
|
||
|
|
} else if (this.tipoImport == 1L) {
|
||
|
|
server = "mercury.ingrammicro.com";
|
||
|
|
fileZip = "TOTITHRL.ZIP";
|
||
|
|
dirFtp = "/AVAIL/";
|
||
|
|
tipoImportS = " DISPO ";
|
||
|
|
} else {
|
||
|
|
server = "mercury.ingrammicro.com";
|
||
|
|
fileZip = "ITSKUFEE.ZIP";
|
||
|
|
dirFtp = "/";
|
||
|
|
tipoImportS = " SIAE ";
|
||
|
|
}
|
||
|
|
this.TAG_THREAD_MSG += this.TAG_THREAD_MSG;
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, this.TAG_THREAD_MSG, "...inizio ...");
|
||
|
|
String fileCsv = fileZip.replace(".ZIP", ".TXT");
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
|
||
|
|
System.out.println("##############\nIMPORT INGRAM " + tipoImportS + " " + serie + "\nSTART: " + start.toString());
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
HashSet<Long> hsMarche = new HashSet<>();
|
||
|
|
HashSet<Long> hsTipi = new HashSet<>();
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
String targetDir = this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("DOCBASE").getTesto();
|
||
|
|
String l_fileName = targetDir + targetDir;
|
||
|
|
String l_fileNameZip = targetDir + targetDir;
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/" + fileCsv;
|
||
|
|
if (!debug) {
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, this.TAG_THREAD_MSG, "Download nuovo file " + fileZip);
|
||
|
|
new File(l_fileName).delete();
|
||
|
|
new File(l_fileNameZip).delete();
|
||
|
|
rp = DBAdapter.getFileViaSFtp(server, 21, user, pass, dirFtp + dirFtp, l_fileNameZip);
|
||
|
|
if (rp.getStatus())
|
||
|
|
DBAdapter.unzip(l_fileNameZip, targetDir);
|
||
|
|
}
|
||
|
|
if (this.tipoImport == 0L) {
|
||
|
|
rp = importListinoCSV(l_fileName);
|
||
|
|
} else if (this.tipoImport == 1L) {
|
||
|
|
rp = importDispoCSV(l_fileName);
|
||
|
|
} else {
|
||
|
|
rp = importSiaeCSV(l_fileName);
|
||
|
|
}
|
||
|
|
timer.stop();
|
||
|
|
rp.setMsg("Import concluso. DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
if (this.sendEmail)
|
||
|
|
CCImport.this.sendArticoliCambiatiByEmail(this.apFull, rp.getMsg(), 1995L);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, this.TAG_THREAD_MSG, rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, this.TAG_THREAD_MSG);
|
||
|
|
CCImport.threadImportIngramMicro = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgEbay() == 1L)
|
||
|
|
bean.startThreadAllineaEbay(this.apFull, new ArticoloCR());
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgAmz() == 1L)
|
||
|
|
bean.startThreadAllineaAmz(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importListinoCSV(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = false;
|
||
|
|
boolean isNuovo = false;
|
||
|
|
boolean isArticoloCercatoConSku = true;
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
long SOSPENDI_DOPO_N_GG = this.apFull.getParm("CC_SOSPENDI_DOPO_N_GG_NO_IMPORT").getNumeroLong();
|
||
|
|
if (SOSPENDI_DOPO_N_GG < 6L)
|
||
|
|
SOSPENDI_DOPO_N_GG = 6L;
|
||
|
|
String CLASSE_PRODOTTO_RICONDIZIONATO = "P";
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/PRICE1.TXT";
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, this.TAG_THREAD_MSG, ": Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 1995L);
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
Marca marca = new Marca(this.apFull);
|
||
|
|
CategoriaIngrammicro categoriaIngrammicro = new CategoriaIngrammicro(this.apFull);
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
isNuovo = false;
|
||
|
|
isPromo = false;
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, ",");
|
||
|
|
if (st.countToken() >= 6) {
|
||
|
|
String l_action = st.getToken(0);
|
||
|
|
String l_marcaDesc = st.getToken(3);
|
||
|
|
if (l_marcaDesc.indexOf("-") > 0)
|
||
|
|
l_marcaDesc = l_marcaDesc.substring(0, l_marcaDesc.indexOf("-")).trim();
|
||
|
|
marca.findByDescrizioneImport(l_marcaDesc);
|
||
|
|
if (marca.getId_marca() > 0L) {
|
||
|
|
String l_classeProdotto = st.getToken(17).trim();
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(1).trim();
|
||
|
|
String l_articoloCodiceProduttore = st.getToken(7).trim();
|
||
|
|
String l_nome = st.getToken(4).trim() + " " + st.getToken(4).trim();
|
||
|
|
if (!l_classeProdotto.equals("P")) {
|
||
|
|
String l_categoriaImport;
|
||
|
|
double prezzo, streetprice;
|
||
|
|
String l_codiceCategoria = st.getToken(21).trim();
|
||
|
|
categoriaIngrammicro.findByCodice(l_codiceCategoria);
|
||
|
|
if (categoriaIngrammicro.getId_categoriaIngrammiro() > 0L) {
|
||
|
|
l_categoriaImport = categoriaIngrammicro.getDescrizione();
|
||
|
|
} else {
|
||
|
|
l_categoriaImport = "";
|
||
|
|
}
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "IM_" + l_articoloCodiceFornitore;
|
||
|
|
String l_codiceEan = st.getToken(9).trim();
|
||
|
|
if (l_codiceEan.length() < 13)
|
||
|
|
l_codiceEan = DBAdapter.zeroLeft(l_codiceEan, 13);
|
||
|
|
if (l_codiceEan.equals("0000000000000") || l_codiceEan.indexOf("99999999") >= 0)
|
||
|
|
l_codiceEan = "";
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("CG_7DB75EA"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
art.resetBean();
|
||
|
|
isArticoloCercatoConSku = false;
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(1995L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L) {
|
||
|
|
art = af.getArticolo();
|
||
|
|
isArticoloCercatoConSku = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_codiceEan.isEmpty()) {
|
||
|
|
art.findByCodiceEanSerie(l_codiceEan, serie);
|
||
|
|
if (art.getId_articolo() > 0L)
|
||
|
|
isArticoloCercatoConSku = false;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_articoloCodiceProduttore.isEmpty()) {
|
||
|
|
art.findByCodiceProduttoreMarca(l_articoloCodiceProduttore, marca.getId_marca());
|
||
|
|
if (art.getId_articolo() > 0L)
|
||
|
|
isArticoloCercatoConSku = false;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L && !isArticoloCercatoConSku) {
|
||
|
|
af.findByFornitoreArticolo(art.getId_articolo(), 1995L, 0L);
|
||
|
|
if (af.getId_articoloFornitore() > 0L &&
|
||
|
|
!af.getCodiceFornitore().equals(l_articoloCodiceFornitore))
|
||
|
|
art.resetBean();
|
||
|
|
}
|
||
|
|
String urlImmagine = "";
|
||
|
|
if (st.countToken() > 7);
|
||
|
|
String appoggiaPrezzo = st.getToken(14).trim();
|
||
|
|
String appoggiaStreetPrice = st.getToken(6).trim();
|
||
|
|
l_descrizioneTecnica = "";
|
||
|
|
try {
|
||
|
|
prezzo = Double.valueOf(appoggiaPrezzo.replace(',', '.'));
|
||
|
|
streetprice = Double.valueOf(appoggiaStreetPrice.replace(',', '.'));
|
||
|
|
if (l_action.equals("A") || l_action.equals("C")) {
|
||
|
|
salvaArticoloNuovo = true;
|
||
|
|
} else {
|
||
|
|
salvaArticoloNuovo = false;
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato:" + appoggiaPrezzo + "\n" + currentLine + "\n");
|
||
|
|
recordErrati++;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (debug);
|
||
|
|
art.aggiornaCodiciAlternativi(false);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCodiciAlternativi().length() > 50)
|
||
|
|
System.out.println(art.getCodice() + " " + art.getCodice());
|
||
|
|
if (!l_categoriaImport.isEmpty() && art.getCategoriaImport().indexOf(l_categoriaImport) < 0)
|
||
|
|
art.setCategoriaImport(art.getCategoriaImport() + art.getCategoriaImport());
|
||
|
|
if (marca.getId_marca() > 0L && art.getId_marca() == 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else if (salvaArticoloNuovo) {
|
||
|
|
double percentualeRicarico;
|
||
|
|
isNuovo = true;
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setCategoriaImport(l_categoriaImport);
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setCostoNetto(prezzo);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (prezzo <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setId_marca(0L);
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setCostoNetto(prezzo);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (prezzo <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCodiciAlternativi().length() > 50)
|
||
|
|
System.out.println(art.getCodice() + " " + art.getCodice());
|
||
|
|
if (marca.getId_marca() > 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setId_fornitoreCostoNuovo(1995L);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
DoubleOperator prezzoPubblico = new DoubleOperator(percentualeRicarico);
|
||
|
|
prezzoPubblico.setScale(2, 5);
|
||
|
|
prezzoPubblico.divide(100.0F);
|
||
|
|
prezzoPubblico.add(1);
|
||
|
|
prezzoPubblico.multiply(prezzo);
|
||
|
|
if (streetprice > 0.0D && prezzoPubblico.getResult() > streetprice)
|
||
|
|
prezzoPubblico = new DoubleOperator(streetprice);
|
||
|
|
ListinoArticolo lab = art.getListinoArticoloBase();
|
||
|
|
if (prezzoPubblico.getResult() != lab.getPrezzoIvaLA()) {
|
||
|
|
System.out.println("Articolo " + art.getCodice() + " prezzo cambiato da " +
|
||
|
|
lab.getPrezzoIvaLA() + " a " + prezzoPubblico.getResult());
|
||
|
|
lab.setPrezzoLA(prezzoPubblico.getResult());
|
||
|
|
lab.save();
|
||
|
|
}
|
||
|
|
art.setStreetPrice(streetprice);
|
||
|
|
if (art.getPrezzoArticolo(null).getPrezzoBase() > streetprice) {
|
||
|
|
ListinoArticolo listinoArticoloBase = art.getListinoArticoloBase();
|
||
|
|
System.out.println(listinoArticoloBase.getId_listinoArticolo());
|
||
|
|
listinoArticoloBase.setPrezzoLA(streetprice);
|
||
|
|
rp = listinoArticoloBase.save();
|
||
|
|
}
|
||
|
|
if (!l_descrizioneTecnica.isEmpty())
|
||
|
|
art.setDescTxtLang("descrizioneCommerciale", "it", l_descrizioneTecnica);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. Nuovo: " + l_articoloCodiceAlternativoFornitore + " - " +
|
||
|
|
art.getDescrizione() + " - " + rp.getMsg() + " - ");
|
||
|
|
artNuovoKO++;
|
||
|
|
} else {
|
||
|
|
artNuovo++;
|
||
|
|
if (urlImmagine != null && !urlImmagine.isEmpty() && urlImmagine.endsWith(".jpg"))
|
||
|
|
art.caricaImmaginaDaRemoto(urlImmagine);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L && prezzo > 0.0D) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(1995L, art.getId_articolo(), -1L);
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(1995L);
|
||
|
|
af.setCostoVecchio(af.getCostoTotale());
|
||
|
|
af.setCosto(prezzo);
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
af.setStreetPrice(streetprice);
|
||
|
|
af.setFlgPromo(isPromo ? 1L : 0L);
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
art.aggiornaPrezziEDispoByFornitori(streetprice, isNuovo);
|
||
|
|
if (art.getFlgModImportazione() == 2L) {
|
||
|
|
prezzoModificato++;
|
||
|
|
} else if (art.getFlgModImportazione() == 3L) {
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (art.getFlgEscludiWebArt() == 2L) {
|
||
|
|
articoloSospeso++;
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
System.out.println("prodotto ricondizionato escluso: codice Forn.:" + l_articoloCodiceFornitore + " codice produttore: " + l_articoloCodiceProduttore + "\n" + l_nome);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
System.out.println("marca scartata: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE INGRAMMICRO " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, this.TAG_THREAD_MSG, sb.toString());
|
||
|
|
}
|
||
|
|
if (SOSPENDI_DOPO_N_GG > 0L)
|
||
|
|
bean.update("UPDATE ARTICOLO SET flgEscludiWebArt=2,flgEscludiWeb=2 WHERE codice LIKE '" + serie + "%' and flgModImportazione = 0 and DATEDIFF(CURDATE(), dataUltimoImport)>=" + SOSPENDI_DOPO_N_GG + ";");
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! " + this.TAG_THREAD_MSG + " record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, this.TAG_THREAD_MSG, "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import Articolo e Prezzi INGRAMMICRO " + serie + " avvenuta correttamente. Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import Articolo e Prezzi INGRAMMICRO " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importDispoCSV(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = false;
|
||
|
|
boolean isNuovo = false;
|
||
|
|
boolean isArticoloCercatoConSku = true;
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
long SOSPENDI_DOPO_N_GG = this.apFull.getParm("CC_SOSPENDI_DOPO_N_GG_NO_IMPORT").getNumeroLong();
|
||
|
|
if (SOSPENDI_DOPO_N_GG < 6L)
|
||
|
|
SOSPENDI_DOPO_N_GG = 6L;
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/PRICE1.TXT";
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, this.TAG_THREAD_MSG, ": Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 1995L);
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
isNuovo = false;
|
||
|
|
isPromo = false;
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, ",", '"');
|
||
|
|
if (st.countToken() >= 4) {
|
||
|
|
long dispoL;
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(0).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "IM_" + l_articoloCodiceFornitore;
|
||
|
|
String l_articoloCodiceProduttore = st.getToken(1).trim();
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("CG_7DB75EA"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
art.resetBean();
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(1995L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
String dispo = st.getToken(2).trim();
|
||
|
|
try {
|
||
|
|
dispoL = Long.parseLong(dispo);
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato dispo errata: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato dispo errato: " + l_articoloCodiceAlternativoFornitore + " dispo rilevato:" + dispo + "\n" + currentLine + "\n");
|
||
|
|
recordErrati++;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (debug);
|
||
|
|
art.aggiornaCodiciAlternativi(false);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiciAlternativi().length() > 50)
|
||
|
|
System.out.println(art.getCodice() + " " + art.getCodice());
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(1995L, art.getId_articolo(), -1L);
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(1995L);
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
af.setDispSede(dispoL);
|
||
|
|
af.setFlgPromo(isPromo ? 1L : 0L);
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
art.aggiornaPrezziEDispoByFornitori(af.getStreetPrice(), isNuovo);
|
||
|
|
if (art.getFlgModImportazione() == 2L) {
|
||
|
|
prezzoModificato++;
|
||
|
|
} else if (art.getFlgModImportazione() == 3L) {
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (art.getFlgEscludiWebArt() == 2L) {
|
||
|
|
articoloSospeso++;
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE INGRAMMICRO " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, this.TAG_THREAD_MSG, sb.toString());
|
||
|
|
}
|
||
|
|
if (SOSPENDI_DOPO_N_GG > 0L)
|
||
|
|
bean.update("UPDATE ARTICOLO SET flgEscludiWebArt=2,flgEscludiWeb=2 WHERE codice LIKE '" + serie + "%' and flgModImportazione = 0 and DATEDIFF(CURDATE(), dataUltimoImport)>=" + SOSPENDI_DOPO_N_GG + ";");
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! " + this.TAG_THREAD_MSG + " record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, this.TAG_THREAD_MSG, "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import DISPONIBILITA' INGRAMMICRO " + serie + " avvenuta correttamente. Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import DISPONIBILITA' INGRAMMICRO " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importSiaeCSV(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
String serie = "";
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/ITSKUFEE.TXT";
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, "~");
|
||
|
|
if (st.countToken() >= 4) {
|
||
|
|
double prezzoSiae;
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(1).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "IM_" + l_articoloCodiceFornitore;
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("CG_7DB75EA"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
af.findByCodiceFornitore(1995L, l_articoloCodiceFornitore);
|
||
|
|
String appoggiaPrezzoSiae = st.getToken(3).trim();
|
||
|
|
try {
|
||
|
|
prezzoSiae = Double.valueOf(appoggiaPrezzoSiae.replace(',', '.'));
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo siae:" + appoggiaPrezzoSiae + "\n" + currentLine + "\n");
|
||
|
|
recordErrati++;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (af.getId_articoloFornitore() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (debug);
|
||
|
|
af.findByCodiceFornitore(1995L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getCostoAggiuntivo() != prezzoSiae) {
|
||
|
|
af.setCostoAggiuntivo(prezzoSiae);
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
Articolo art = af.getArticolo();
|
||
|
|
art.aggiornaPrezziEDispoByFornitori(art.getStreetPrice(), false);
|
||
|
|
if (art.getFlgModImportazione() == 2L) {
|
||
|
|
prezzoModificato++;
|
||
|
|
} else if (art.getFlgModImportazione() == 3L) {
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (art.getFlgEscludiWebArt() == 2L) {
|
||
|
|
articoloSospeso++;
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " +
|
||
|
|
af.getArticolo().getDescrizione() + " - " + rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE INGRAMMICRO " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, this.TAG_THREAD_MSG, sb.toString());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! " + this.TAG_THREAD_MSG + " record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, this.TAG_THREAD_MSG, "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import Prezzi SIAE INGRAMMICRO " + serie + " avvenuta correttamente. Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import Articolo e Prezzi INGRAMMICRO " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class ThreadImportLogicom extends Thread {
|
||
|
|
private ApplParmFull apFull;
|
||
|
|
|
||
|
|
private String fileCsvlarge;
|
||
|
|
|
||
|
|
private final String TAG_THREAD_MSG = "IMPORT LOGICOM ";
|
||
|
|
|
||
|
|
private boolean sendEmail;
|
||
|
|
|
||
|
|
private static final long l_id_fornitore = 1997L;
|
||
|
|
|
||
|
|
private static final long l_id_tipoDaDafinire = 1L;
|
||
|
|
|
||
|
|
public ThreadImportLogicom(ApplParmFull apFull, String fileXls, boolean sendEmail) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.fileCsvlarge = fileXls;
|
||
|
|
this.sendEmail = sendEmail;
|
||
|
|
if (!CCImport.isThreadLogicomAttivo()) {
|
||
|
|
CCImport.threadImportLocicom = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void run() {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
Timer timer = new Timer();
|
||
|
|
timer.start();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT LOGICOM ", "...inizio ...");
|
||
|
|
String serie = "";
|
||
|
|
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
|
||
|
|
System.out.println("##############\nIMPORT LOGICOM " + serie + "\nSTART: " + start.toString());
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
BufferedReader reader = null;
|
||
|
|
String targetDir = this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("DOCBASE").getTesto();
|
||
|
|
String fileCsv = this.fileCsvlarge.substring(this.fileCsvlarge.lastIndexOf('/') + 1);
|
||
|
|
String l_fileName = this.fileCsvlarge;
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/" + fileCsv;
|
||
|
|
rp = importGiornaliero(l_fileName);
|
||
|
|
timer.stop();
|
||
|
|
rp.setMsg("Import concluso. DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
if (this.sendEmail)
|
||
|
|
CCImport.this.sendArticoliCambiatiByEmail(this.apFull, rp.getMsg(), 1997L);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT LOGICOM ", rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, "IMPORT LOGICOM ");
|
||
|
|
CCImport.threadImportLocicom = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgEbay() == 1L) {
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
bean.startThreadAllineaEbay(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgAmz() == 1L) {
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
bean.startThreadAllineaAmz(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importGiornaliero(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
boolean isNuovo = false;
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
StringBuilder scartoCodici = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
HashSet<Long> hsMarche = new HashSet<>();
|
||
|
|
HashSet<Long> hsTipi = new HashSet<>();
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
XLSFileReader xfr = new XLSFileReader(l_fileName);
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/large.csv";
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT LOGICOM ", ": Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 1997L);
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
Marca marca = new Marca(this.apFull);
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
xfr.nextRecord();
|
||
|
|
while (xfr.nextRecord()) {
|
||
|
|
isNuovo = false;
|
||
|
|
isPromo = false;
|
||
|
|
String l_marcaDesc = xfr.getField(7);
|
||
|
|
marca.findByDescrizioneImport(l_marcaDesc);
|
||
|
|
if (marca.getId_marca() > 0L) {
|
||
|
|
long dispoL;
|
||
|
|
double prezzo, prezzoSiae, prezzoTot;
|
||
|
|
if (!hsMarche.contains(Long.valueOf(marca.getId_marca()))) {
|
||
|
|
hsMarche.add(Long.valueOf(marca.getId_marca()));
|
||
|
|
System.out.println("NUOVA marca GESTITA: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
String urlImmagine = xfr.getField(20).trim();
|
||
|
|
String l_articoloCodiceFornitore = xfr.getField(1).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "LC_" + l_articoloCodiceFornitore;
|
||
|
|
String l_articoloCodiceProduttore = xfr.getField(1).trim();
|
||
|
|
String l_codiceEan = xfr.getField(11).trim();
|
||
|
|
art.resetBean();
|
||
|
|
String l_nome = xfr.getField(6).trim();
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("LC_CC640EE"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(1997L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_codiceEan.isEmpty()) {
|
||
|
|
art.findByCodiceEanSerie(l_codiceEan, serie);
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
l_codiceEan = "0" + l_codiceEan;
|
||
|
|
art.findByCodiceEanSerie(l_codiceEan, serie);
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.findByCodiceProduttoreMarca(l_articoloCodiceProduttore, marca.getId_marca());
|
||
|
|
}
|
||
|
|
String appoggiaPrezzo = xfr.getField(5).trim();
|
||
|
|
String appoggiaPrezzoSiae = xfr.getField(9).trim();
|
||
|
|
String dispo = xfr.getField(10).trim();
|
||
|
|
l_descrizioneTecnica = "";
|
||
|
|
try {
|
||
|
|
prezzo = Double.valueOf(appoggiaPrezzo.replace(',', '.'));
|
||
|
|
prezzoSiae = Double.valueOf(appoggiaPrezzoSiae.replace(',', '.'));
|
||
|
|
if (prezzoSiae == 0.0D) {
|
||
|
|
prezzoTot = prezzo;
|
||
|
|
} else {
|
||
|
|
DoubleOperator dop = new DoubleOperator(prezzo);
|
||
|
|
dop.add(prezzoSiae);
|
||
|
|
prezzoTot = dop.getResult();
|
||
|
|
}
|
||
|
|
dispoL = (long)Double.parseDouble(dispo);
|
||
|
|
long dispoTotL = dispoL;
|
||
|
|
if (dispoTotL > 0L) {
|
||
|
|
salvaArticoloNuovo = true;
|
||
|
|
} else {
|
||
|
|
salvaArticoloNuovo = false;
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato: " + appoggiaPrezzo + "\n" + currentLine + "\n");
|
||
|
|
recordErrati++;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (art.getId_tipo() != 1L && !hsTipi.contains(Long.valueOf(art.getId_tipo())))
|
||
|
|
hsTipi.add(Long.valueOf(art.getId_tipo()));
|
||
|
|
if (debug);
|
||
|
|
art.aggiornaCodiciAlternativi(false);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (marca.getId_marca() > 0L && art.getId_marca() == 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
if (urlImmagine != null && !urlImmagine.isEmpty() && urlImmagine.endsWith(".jpg"))
|
||
|
|
if (!new File(art.getDocBase() + art.getDocBase() + art.getPathImg()).exists())
|
||
|
|
art.caricaImmaginaDaRemoto(urlImmagine);
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else if (salvaArticoloNuovo) {
|
||
|
|
double percentualeRicarico;
|
||
|
|
isNuovo = true;
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setCostoNetto(prezzoTot);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (prezzo <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCodiciAlternativi().length() > 50)
|
||
|
|
System.out.println(art.getCodice() + " " + art.getCodice());
|
||
|
|
if (marca.getId_marca() > 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setId_fornitoreCostoNuovo(1997L);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
if (!urlImmagine.isEmpty() && !art.isImgExist(1))
|
||
|
|
art.caricaImmaginaDaRemoto(urlImmagine);
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
DoubleOperator prezzoPubblico = new DoubleOperator(percentualeRicarico);
|
||
|
|
prezzoPubblico.setScale(2, 5);
|
||
|
|
prezzoPubblico.divide(100.0F);
|
||
|
|
prezzoPubblico.add(1);
|
||
|
|
prezzoPubblico.multiply(prezzoTot);
|
||
|
|
double streetprice = art.getStreetPrice();
|
||
|
|
if (streetprice > 0.0D && prezzoPubblico.getResult() > streetprice)
|
||
|
|
prezzoPubblico = new DoubleOperator(streetprice);
|
||
|
|
ListinoArticolo lab = art.getListinoArticoloBase();
|
||
|
|
if (prezzoPubblico.getResult() != lab.getPrezzoIvaLA()) {
|
||
|
|
System.out.println("Articolo " + art.getCodice() + " prezzo cambiato da " + lab.getPrezzoIvaLA() + " a " +
|
||
|
|
prezzoPubblico.getResult());
|
||
|
|
lab.setPrezzoLA(prezzoPubblico.getResult());
|
||
|
|
lab.save();
|
||
|
|
}
|
||
|
|
art.setStreetPrice(streetprice);
|
||
|
|
if (art.getPrezzoArticolo(null).getPrezzoBase() > streetprice);
|
||
|
|
if (!l_descrizioneTecnica.isEmpty())
|
||
|
|
art.setDescTxtLang("descrizioneCommerciale", "it", l_descrizioneTecnica);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. Nuovo: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
artNuovoKO++;
|
||
|
|
} else {
|
||
|
|
artNuovo++;
|
||
|
|
if (urlImmagine != null && !urlImmagine.isEmpty() && urlImmagine.endsWith(".jpg"))
|
||
|
|
art.caricaImmaginaDaRemoto(urlImmagine);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L && prezzo > 0.0D) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(1997L, art.getId_articolo(), -1L);
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(1997L);
|
||
|
|
af.setCostoVecchio(af.getCostoTotale());
|
||
|
|
af.setCosto(prezzo);
|
||
|
|
af.setCostoAggiuntivo(prezzoSiae);
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
af.setDispSede(dispoL);
|
||
|
|
af.setFlgPromo(isPromo ? 1L : 0L);
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
art.aggiornaPrezziEDispoByFornitori(art.getStreetPrice(), isNuovo);
|
||
|
|
if (art.getFlgModImportazione() == 2L) {
|
||
|
|
prezzoModificato++;
|
||
|
|
} else if (art.getFlgModImportazione() == 3L) {
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (art.getFlgEscludiWebArt() == 2L) {
|
||
|
|
articoloSospeso++;
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
System.out.println("marca scartata: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Large: Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE LOGICOM " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT LOGICOM ", sb.toString());
|
||
|
|
}
|
||
|
|
rp = Articolo.updateArticoloNonTrovati(this.apFull, "IMPORT LOGICOM ", 1997L, hsMarche, hsTipi);
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! IMPORT LOGICOM record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT LOGICOM ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import Articolo e Prezzi LOGICOM " + serie + " avvenuta correttamente. - File:" + l_fileName + " - Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
sb.append(" - Update articoli non trovati: - ");
|
||
|
|
sb.append(rp.getMsg());
|
||
|
|
sb.append(" - DEBUG LOGICOM SCARTO CODICI: - ");
|
||
|
|
sb.append(scartoCodici.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import Articolo e Prezzi LOGICOM " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class ThreadCheckMailLogicom extends Thread {
|
||
|
|
private ApplParmFull apFull;
|
||
|
|
|
||
|
|
private final String TAG_THREAD_MSG = "CHECK MAIL LOGICOM ";
|
||
|
|
|
||
|
|
private boolean sendEmail;
|
||
|
|
|
||
|
|
private static final long l_id_fornitore = 1997L;
|
||
|
|
|
||
|
|
public ThreadCheckMailLogicom(ApplParmFull apFull, boolean sendMail) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.sendEmail = sendMail;
|
||
|
|
if (!CCImport.isThreadLogicomAttivo()) {
|
||
|
|
CCImport.threadImportLocicom = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void run() {
|
||
|
|
boolean debug = false;
|
||
|
|
Timer timer = new Timer();
|
||
|
|
timer.start();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL LOGICOM ", "...inizio ...");
|
||
|
|
String serie = "";
|
||
|
|
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
|
||
|
|
System.out.println("##############\nIMPORT LOGICOM " + serie + "\nSTART: " + start.toString());
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
MailAccount account = new MailAccount("mail.acxent.it", "acx-ordini", "pippolone1000");
|
||
|
|
if (!debug) {
|
||
|
|
rp = fetchMessages(account, DBAdapter.getToday());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(true);
|
||
|
|
String l_file = "/Users/acolzi/Documents/webapps/cc/_tmp/FLX3933324.XLS";
|
||
|
|
rp.setMsg(l_file);
|
||
|
|
}
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
String fileXLS = rp.getMsg();
|
||
|
|
synchronized (this) {
|
||
|
|
CCImport.threadImportLocicom = false;
|
||
|
|
new CCImport.ThreadImportLogicom(this.apFull, fileXLS, true);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println("############FINE IMPORT LOGICOM");
|
||
|
|
timer.stop();
|
||
|
|
rp.setMsg("Import concluso. DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL LOGICOM ", rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, "CHECK MAIL LOGICOM ");
|
||
|
|
CCImport.threadImportLocicom = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm fetchMessages(MailAccount account, Date theDate) {
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
MailService mailService = new MailService(account.getMailServer(), account.getMailUser(), account.getMailPassword());
|
||
|
|
rp = mailService.login();
|
||
|
|
int messageCount = 0, messageSaved = 0;
|
||
|
|
if (rp.getStatus())
|
||
|
|
try {
|
||
|
|
String from = "Navision@Logicom-Italia.it";
|
||
|
|
String theSubject = "Logicom Partners (IT) - Pricelist";
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String fileNameXls = "LC_" + String.valueOf(cal.getTimeInMillis()) + ".xlsx";
|
||
|
|
String destFile = this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("PATH_TMP").getTesto();
|
||
|
|
Message[] messages = mailService.getMessages(theDate);
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("Mail logicom non trovata");
|
||
|
|
System.out.println("message id fromAddress subject");
|
||
|
|
for (int i = 0; i < messages.length; i++) {
|
||
|
|
messageCount++;
|
||
|
|
String text = "";
|
||
|
|
String messageId = "";
|
||
|
|
String subject = "";
|
||
|
|
try {
|
||
|
|
messageId = messages[i].getHeader("Message-ID")[0];
|
||
|
|
} catch (Exception e) {}
|
||
|
|
if (messageId == null || messageId.isEmpty()) {
|
||
|
|
MimeMessage cmsg = new MimeMessage(mailService.getMimeMessages(i));
|
||
|
|
messageId = cmsg.getMessageID();
|
||
|
|
}
|
||
|
|
subject = messages[i].getSubject();
|
||
|
|
Address[] fromAddress = messages[i].getFrom();
|
||
|
|
InternetAddress address = (InternetAddress)fromAddress[0];
|
||
|
|
String temp = messageId + " " + messageId + " " + String.valueOf(messages[i].getSentDate()) + " " + String.valueOf(address);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL LOGICOM ", temp);
|
||
|
|
System.out.println(temp);
|
||
|
|
if (subject.indexOf(theSubject) >= 0) {
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL LOGICOM ", "Trovata mail con oggetto " + theSubject);
|
||
|
|
String contentType = messages[i].getContentType();
|
||
|
|
String messageContent = "";
|
||
|
|
String attachFiles = "";
|
||
|
|
if (contentType.contains("multipart")) {
|
||
|
|
Multipart multiPart = (Multipart)messages[i].getContent();
|
||
|
|
int numberOfParts = multiPart.getCount();
|
||
|
|
for (int partCount = 0; partCount < numberOfParts; partCount++) {
|
||
|
|
MimeBodyPart part = (MimeBodyPart)multiPart.getBodyPart(partCount);
|
||
|
|
if ("attachment".equalsIgnoreCase(part.getDisposition())) {
|
||
|
|
String fileName = part.getFileName();
|
||
|
|
attachFiles = attachFiles + attachFiles + ", ";
|
||
|
|
part.saveFile(destFile);
|
||
|
|
} else {
|
||
|
|
messageContent = part.getContent().toString();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (attachFiles.length() > 1)
|
||
|
|
attachFiles = attachFiles.substring(0, attachFiles.length() - 2);
|
||
|
|
}
|
||
|
|
if (new File(destFile).exists()) {
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(destFile);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
mailService.logout();
|
||
|
|
} catch (Exception e) {
|
||
|
|
e.printStackTrace();
|
||
|
|
rp.setException(e);
|
||
|
|
rp.setStatus(false);
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class ThreadImportFlexit extends Thread {
|
||
|
|
private ApplParmFull apFull;
|
||
|
|
|
||
|
|
private String fileCsvlarge;
|
||
|
|
|
||
|
|
private final String TAG_THREAD_MSG = "IMPORT FLEXIT ";
|
||
|
|
|
||
|
|
private boolean sendEmail;
|
||
|
|
|
||
|
|
private static final long l_id_fornitore = 2001L;
|
||
|
|
|
||
|
|
private static final long l_id_tipoDaDafinire = 1L;
|
||
|
|
|
||
|
|
public ThreadImportFlexit(ApplParmFull apFull, String fileXls, boolean sendEmail) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.fileCsvlarge = fileXls;
|
||
|
|
this.sendEmail = sendEmail;
|
||
|
|
if (!CCImport.isThreadFlexitAttivo()) {
|
||
|
|
CCImport.threadImportFlexit = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void run() {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
Timer timer = new Timer();
|
||
|
|
timer.start();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT FLEXIT ", "...inizio ...");
|
||
|
|
String serie = "";
|
||
|
|
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
|
||
|
|
System.out.println("##############\nIMPORT FLEXIT " + serie + "\nSTART: " + start.toString());
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
BufferedReader reader = null;
|
||
|
|
String targetDir = this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("DOCBASE").getTesto();
|
||
|
|
String fileCsv = this.fileCsvlarge.substring(this.fileCsvlarge.lastIndexOf('/') + 1);
|
||
|
|
String l_fileName = this.fileCsvlarge;
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/" + fileCsv;
|
||
|
|
rp = importGiornaliero(l_fileName);
|
||
|
|
timer.stop();
|
||
|
|
rp.setMsg("Import concluso. DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
if (this.sendEmail)
|
||
|
|
CCImport.this.sendArticoliCambiatiByEmail(this.apFull, rp.getMsg(), 2001L);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT FLEXIT ", rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, "IMPORT FLEXIT ");
|
||
|
|
CCImport.threadImportFlexit = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgEbay() == 1L) {
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
bean.startThreadAllineaEbay(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgAmz() == 1L) {
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
bean.startThreadAllineaAmz(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importGiornaliero(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
boolean isNuovo = false;
|
||
|
|
StringBuilder err = new StringBuilder();
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
StringBuilder scartoCodici = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
HashSet<Long> hsMarche = new HashSet<>();
|
||
|
|
HashSet<Long> hsTipi = new HashSet<>();
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
XLSFileReader xfr = new XLSFileReader(l_fileName);
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
if (debug);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT FLEXIT ", ": Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 2001L);
|
||
|
|
String currentLine = "";
|
||
|
|
StatoUsato statoUsato = new StatoUsato(this.apFull);
|
||
|
|
try {
|
||
|
|
Marca marca = new Marca(this.apFull);
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String urlImmagine = "";
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
xfr.nextRecord();
|
||
|
|
while (xfr.nextRecord()) {
|
||
|
|
isNuovo = false;
|
||
|
|
isPromo = false;
|
||
|
|
String l_marcaDesc = xfr.getField(8);
|
||
|
|
marca.findByDescrizioneImport(l_marcaDesc);
|
||
|
|
if (marca.getId_marca() > 0L) {
|
||
|
|
if (!hsMarche.contains(Long.valueOf(marca.getId_marca()))) {
|
||
|
|
hsMarche.add(Long.valueOf(marca.getId_marca()));
|
||
|
|
System.out.println("NUOVA marca GESTITA: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
String l_statoUsato = xfr.getField(4).trim();
|
||
|
|
statoUsato.findBySigla(l_statoUsato);
|
||
|
|
if (statoUsato.getId_statoUsato() == 0L) {
|
||
|
|
System.out.println("ERRORE!!!! FLEXIT NON TROVATO STATO USATO " + l_statoUsato);
|
||
|
|
err.append("ERRORE!!!! FLEXIT NON TROVATO STATO USATO " + l_statoUsato);
|
||
|
|
err.append("\n");
|
||
|
|
} else {
|
||
|
|
long dispoL;
|
||
|
|
double prezzo, prezzoSiae, prezzoTot;
|
||
|
|
String l_articoloCodiceFornitore = xfr.getField(0).trim().replace(".0", "") + xfr.getField(0).trim().replace(".0", "");
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "FX_" + l_articoloCodiceFornitore;
|
||
|
|
String l_articoloCodiceProduttore = xfr.getField(1).trim();
|
||
|
|
String l_codiceEan = xfr.getField(2).trim();
|
||
|
|
if (l_codiceEan.equals("0000000000000") || l_codiceEan.indexOf("99999999") >= 0)
|
||
|
|
l_codiceEan = "";
|
||
|
|
art.resetBean();
|
||
|
|
String l_nome = xfr.getField(5).trim();
|
||
|
|
String l_nomeAgg = xfr.getField(6).trim();
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("FX_CC640EE"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(2001L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
if (af.getArticolo().getId_statoUsato() == statoUsato.getId_statoUsato() || (
|
||
|
|
statoUsato.getId_statoUsato() >= 1L && statoUsato.getId_statoUsato() <= 3L &&
|
||
|
|
af.getArticolo().getFlgUsato() == 0L)) {
|
||
|
|
art = af.getArticolo();
|
||
|
|
} else {
|
||
|
|
err.append("trovato articolo ma stato diverso flexit.... ERRORE: " + l_articoloCodiceFornitore);
|
||
|
|
err.append("\n");
|
||
|
|
System.out.println("trovato articolo ma stato diverso flexit.... ERRORE: " + l_articoloCodiceFornitore);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_codiceEan.isEmpty()) {
|
||
|
|
art.findByCodiceEanSerie(l_codiceEan, serie);
|
||
|
|
if (art.getId_articolo() == 0L)
|
||
|
|
art.findByCodiceEanSerie("0" + l_codiceEan, serie);
|
||
|
|
if (art.getId_articolo() == 0L && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.findByCodiceProduttoreMarca(l_articoloCodiceProduttore, marca.getId_marca());
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L)
|
||
|
|
if (art.getId_statoUsato() != statoUsato.getId_statoUsato() && (statoUsato.getId_statoUsato() < 1L ||
|
||
|
|
statoUsato.getId_statoUsato() > 3L || art.getFlgUsato() != 0L))
|
||
|
|
art.resetBean();
|
||
|
|
String appoggiaPrezzo = xfr.getField(7).trim();
|
||
|
|
String dispo = xfr.getField(3).trim();
|
||
|
|
if (dispo.equals("50+"))
|
||
|
|
dispo = "50";
|
||
|
|
l_descrizioneTecnica = "";
|
||
|
|
try {
|
||
|
|
prezzo = Double.valueOf(appoggiaPrezzo.replace(',', '.'));
|
||
|
|
prezzoSiae = 0.0D;
|
||
|
|
if (prezzoSiae == 0.0D) {
|
||
|
|
prezzoTot = prezzo;
|
||
|
|
} else {
|
||
|
|
DoubleOperator dop = new DoubleOperator(prezzo);
|
||
|
|
dop.add(prezzoSiae);
|
||
|
|
prezzoTot = dop.getResult();
|
||
|
|
}
|
||
|
|
dispoL = (long)Double.parseDouble(dispo);
|
||
|
|
long dispoTotL = dispoL;
|
||
|
|
if (dispoTotL > 0L) {
|
||
|
|
salvaArticoloNuovo = true;
|
||
|
|
} else {
|
||
|
|
salvaArticoloNuovo = false;
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato: " + appoggiaPrezzo + "\n" + currentLine + "\n");
|
||
|
|
recordErrati++;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (art.getId_tipo() != 1L && !hsTipi.contains(Long.valueOf(art.getId_tipo())))
|
||
|
|
hsTipi.add(Long.valueOf(art.getId_tipo()));
|
||
|
|
if (debug);
|
||
|
|
art.aggiornaCodiciAlternativi(false);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (marca.getId_marca() > 0L && art.getId_marca() == 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
if (urlImmagine != null && !urlImmagine.isEmpty() && urlImmagine.endsWith(".jpg"))
|
||
|
|
if (!new File(art.getDocBase() + art.getDocBase() + art.getPathImg()).exists())
|
||
|
|
art.caricaImmaginaDaRemoto(urlImmagine);
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else if (salvaArticoloNuovo) {
|
||
|
|
double percentualeRicarico;
|
||
|
|
isNuovo = true;
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescTxtLang("descrizioneBreve", "it", l_descrizioneTecnica);
|
||
|
|
if (statoUsato.getId_statoUsato() > 3L) {
|
||
|
|
art.setId_statoUsato(statoUsato.getId_statoUsato());
|
||
|
|
art.setFlgUsato(2L);
|
||
|
|
} else {
|
||
|
|
art.setFlgUsato(0L);
|
||
|
|
art.setId_statoUsato(statoUsato.getId_statoUsato());
|
||
|
|
}
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setCostoNetto(prezzoTot);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (prezzo <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCodiciAlternativi().length() > 50)
|
||
|
|
System.out.println(art.getCodice() + " " + art.getCodice());
|
||
|
|
if (marca.getId_marca() > 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setId_fornitoreCostoNuovo(2001L);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
if (!urlImmagine.isEmpty() && !art.isImgExist(1))
|
||
|
|
art.caricaImmaginaDaRemoto(urlImmagine);
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
DoubleOperator prezzoPubblico = new DoubleOperator(percentualeRicarico);
|
||
|
|
prezzoPubblico.setScale(2, 5);
|
||
|
|
prezzoPubblico.divide(100.0F);
|
||
|
|
prezzoPubblico.add(1);
|
||
|
|
prezzoPubblico.multiply(prezzoTot);
|
||
|
|
double streetprice = art.getStreetPrice();
|
||
|
|
if (streetprice <= 0.0D || prezzoPubblico.getResult() > streetprice);
|
||
|
|
ListinoArticolo lab = art.getListinoArticoloBase();
|
||
|
|
if (prezzoPubblico.getResult() != lab.getPrezzoIvaLA()) {
|
||
|
|
lab.setPrezzoLA(prezzoPubblico.getResult());
|
||
|
|
lab.save();
|
||
|
|
}
|
||
|
|
art.setStreetPrice(streetprice);
|
||
|
|
if (art.getPrezzoArticolo(null).getPrezzoBase() > streetprice);
|
||
|
|
if (!l_descrizioneTecnica.isEmpty())
|
||
|
|
art.setDescTxtLang("descrizioneCommerciale", "it", l_descrizioneTecnica);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. Nuovo: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
artNuovoKO++;
|
||
|
|
} else {
|
||
|
|
artNuovo++;
|
||
|
|
if (urlImmagine != null && !urlImmagine.isEmpty() && urlImmagine.endsWith(".jpg"))
|
||
|
|
art.caricaImmaginaDaRemoto(urlImmagine);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L && prezzo > 0.0D) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(2001L, art.getId_articolo(), -1L);
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(2001L);
|
||
|
|
af.setCostoVecchio(af.getCostoTotale());
|
||
|
|
af.setCosto(prezzo);
|
||
|
|
af.setCostoAggiuntivo(prezzoSiae);
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
af.setDispSede(dispoL);
|
||
|
|
af.setFlgPromo(isPromo ? 1L : 0L);
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
art.aggiornaPrezziEDispoByFornitori(art.getStreetPrice(), isNuovo);
|
||
|
|
if (art.getFlgModImportazione() == 2L) {
|
||
|
|
prezzoModificato++;
|
||
|
|
} else if (art.getFlgModImportazione() == 3L) {
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (art.getFlgEscludiWebArt() == 2L) {
|
||
|
|
articoloSospeso++;
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
System.out.println("marca scartata: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Large: Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE FLEXIT " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT FLEXIT ", sb.toString());
|
||
|
|
}
|
||
|
|
rp = Articolo.updateArticoloNonTrovati(this.apFull, "IMPORT FLEXIT ", 2001L, hsMarche, hsTipi);
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! IMPORT FLEXIT record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT FLEXIT ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import Articolo e Prezzi FLEXIT " + serie + " avvenuta correttamente. - File:" + l_fileName + " - Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
sb.append(" - Update articoli non trovati: - ");
|
||
|
|
sb.append(rp.getMsg());
|
||
|
|
sb.append(" - DEBUG FLEXIT SCARTO CODICI: - ");
|
||
|
|
sb.append(scartoCodici.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import Articolo e Prezzi FLEXIT " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class ThreadCheckMailFlexit extends Thread {
|
||
|
|
private ApplParmFull apFull;
|
||
|
|
|
||
|
|
private final String TAG_THREAD_MSG = "CHECK MAIL FLEXIT ";
|
||
|
|
|
||
|
|
private boolean sendEmail;
|
||
|
|
|
||
|
|
private static final long l_id_fornitore = 2001L;
|
||
|
|
|
||
|
|
public ThreadCheckMailFlexit(ApplParmFull apFull, boolean sendMail) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.sendEmail = sendMail;
|
||
|
|
if (!CCImport.isThreadFlexitAttivo()) {
|
||
|
|
CCImport.threadImportFlexit = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void run() {
|
||
|
|
boolean debug = false;
|
||
|
|
Timer timer = new Timer();
|
||
|
|
timer.start();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL FLEXIT ", "...inizio ...");
|
||
|
|
String serie = "";
|
||
|
|
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
|
||
|
|
System.out.println("##############\nIMPORT FLEXIT " + serie + "\nSTART: " + start.toString());
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
MailAccount account = new MailAccount("mail.acxent.it", "acx-ordini", "pippolone1000");
|
||
|
|
if (!debug) {
|
||
|
|
rp = fetchMessages(account, DBAdapter.getToday());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(true);
|
||
|
|
String l_file = "/Users/acolzi/Documents/webapps/cc/_tmp/FLX3933324.XLS";
|
||
|
|
rp.setMsg(l_file);
|
||
|
|
}
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
String fileXLS = rp.getMsg();
|
||
|
|
synchronized (this) {
|
||
|
|
CCImport.threadImportFlexit = false;
|
||
|
|
new CCImport.ThreadImportFlexit(this.apFull, fileXLS, true);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println("############FINE IMPORT FLEXIT");
|
||
|
|
timer.stop();
|
||
|
|
rp.setMsg("Import concluso. DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL FLEXIT ", rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, "CHECK MAIL FLEXIT ");
|
||
|
|
CCImport.threadImportFlexit = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm fetchMessages(MailAccount account, Date theDate) {
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
MailService mailService = new MailService(account.getMailServer(), account.getMailUser(), account.getMailPassword());
|
||
|
|
rp = mailService.login();
|
||
|
|
int messageCount = 0, messageSaved = 0;
|
||
|
|
if (rp.getStatus())
|
||
|
|
try {
|
||
|
|
String from = "Riccardo.Gilardi@flexitdistribution.com";
|
||
|
|
String theSubject = "Lista prodotti disponibili a stock";
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String fileNameXls = "FX_" + String.valueOf(cal.getTimeInMillis()) + ".xlsx";
|
||
|
|
String destFile = this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("PATH_TMP").getTesto();
|
||
|
|
Message[] messages = mailService.getMessages(theDate);
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("Mail FLEXIT non trovata");
|
||
|
|
System.out.println("message id fromAddress subject");
|
||
|
|
for (int i = 0; i < messages.length; i++) {
|
||
|
|
messageCount++;
|
||
|
|
String text = "";
|
||
|
|
String messageId = "";
|
||
|
|
String subject = "";
|
||
|
|
try {
|
||
|
|
messageId = messages[i].getHeader("Message-ID")[0];
|
||
|
|
} catch (Exception e) {}
|
||
|
|
if (messageId == null || messageId.isEmpty()) {
|
||
|
|
MimeMessage cmsg = new MimeMessage(mailService.getMimeMessages(i));
|
||
|
|
messageId = cmsg.getMessageID();
|
||
|
|
}
|
||
|
|
subject = messages[i].getSubject();
|
||
|
|
Address[] fromAddress = messages[i].getFrom();
|
||
|
|
InternetAddress address = (InternetAddress)fromAddress[0];
|
||
|
|
String temp = messageId + " " + messageId + " " + String.valueOf(messages[i].getSentDate()) + " " + String.valueOf(address);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL FLEXIT ", temp);
|
||
|
|
System.out.println(temp);
|
||
|
|
if (subject.indexOf(theSubject) >= 0) {
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "CHECK MAIL FLEXIT ", "Trovata mail con oggetto " + theSubject);
|
||
|
|
String contentType = messages[i].getContentType();
|
||
|
|
String messageContent = "";
|
||
|
|
String attachFiles = "";
|
||
|
|
if (contentType.contains("multipart")) {
|
||
|
|
Multipart multiPart = (Multipart)messages[i].getContent();
|
||
|
|
int numberOfParts = multiPart.getCount();
|
||
|
|
for (int partCount = 0; partCount < numberOfParts; partCount++) {
|
||
|
|
MimeBodyPart part = (MimeBodyPart)multiPart.getBodyPart(partCount);
|
||
|
|
if ("attachment".equalsIgnoreCase(part.getDisposition())) {
|
||
|
|
String fileName = part.getFileName();
|
||
|
|
attachFiles = attachFiles + attachFiles + ", ";
|
||
|
|
part.saveFile(destFile);
|
||
|
|
} else {
|
||
|
|
messageContent = part.getContent().toString();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (attachFiles.length() > 1)
|
||
|
|
attachFiles = attachFiles.substring(0, attachFiles.length() - 2);
|
||
|
|
}
|
||
|
|
if (new File(destFile).exists()) {
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(destFile);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
mailService.logout();
|
||
|
|
} catch (Exception e) {
|
||
|
|
e.printStackTrace();
|
||
|
|
rp.setException(e);
|
||
|
|
rp.setStatus(false);
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class ThreadTrovaprezziXml extends Thread {
|
||
|
|
private ApplParmFull apFull;
|
||
|
|
|
||
|
|
private ArticoloCR CR;
|
||
|
|
|
||
|
|
private final String TAG_THREAD_MSG = "TROVAPREZZI ";
|
||
|
|
|
||
|
|
public ThreadTrovaprezziXml(ApplParmFull apFull, ArticoloCR CR) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.CR = CR;
|
||
|
|
if (!CCImport.isThreadTrovaprezzi()) {
|
||
|
|
CCImport.threadTrovaprezzi = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void run() {
|
||
|
|
boolean debug = false;
|
||
|
|
Timer timer = new Timer();
|
||
|
|
timer.start();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "TROVAPREZZI ", "...inizio ...");
|
||
|
|
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
|
||
|
|
System.out.println("##############\n TROVAPREZZI \nSTART: " + start.toString());
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
Articolo articolo = new Articolo(this.apFull);
|
||
|
|
rp = articolo.creaFileXmlTrovaprezzi(this.CR);
|
||
|
|
timer.stop();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "TROVAPREZZI ", "File " +
|
||
|
|
this.CR.getFileNameTrovaprezzi() + " creato. DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, "TROVAPREZZI ");
|
||
|
|
CCImport.threadTrovaprezzi = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class ThreadImportBrevi extends Thread {
|
||
|
|
private ApplParmFull apFull;
|
||
|
|
|
||
|
|
private String fileXlM;
|
||
|
|
|
||
|
|
private final String TAG_THREAD_MSG = "IMPORT BREVI ";
|
||
|
|
|
||
|
|
private boolean sendEmail;
|
||
|
|
|
||
|
|
private static final long l_id_fornitore = 2111L;
|
||
|
|
|
||
|
|
private static final long l_id_tipoDaDafinire = 1L;
|
||
|
|
|
||
|
|
public ThreadImportBrevi(ApplParmFull apFull, String fileXlM, boolean sendEmail) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.fileXlM = fileXlM;
|
||
|
|
this.sendEmail = sendEmail;
|
||
|
|
if (!CCImport.isThreadEsprinetAttivo()) {
|
||
|
|
CCImport.threadImportBrevi = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void run() {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
Timer timer = new Timer();
|
||
|
|
timer.start();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BREVI ", "...inizio ...");
|
||
|
|
String serie = "";
|
||
|
|
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
|
||
|
|
System.out.println("##############\nIMPORT BREVI " + serie + "\nSTART: " + start.toString());
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
BufferedReader reader = null;
|
||
|
|
String targetDir = this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("DOCBASE").getTesto();
|
||
|
|
String l_fileName = this.fileXlM;
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/" + this.fileXlM;
|
||
|
|
rp = importGiornalieroXlm(l_fileName);
|
||
|
|
timer.stop();
|
||
|
|
rp.setMsg("Import concluso. IMPORT BREVI DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
if (this.sendEmail)
|
||
|
|
CCImport.this.sendArticoliCambiatiByEmail(this.apFull, rp.getMsg(), 2111L);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BREVI ", rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, "IMPORT BREVI ");
|
||
|
|
CCImport.threadImportBrevi = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importGiornalieroXlm(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
boolean isNuovo = false;
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
StringBuilder scartoCodici = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
HashSet<Long> hsMarche = new HashSet<>();
|
||
|
|
HashSet<Long> hsTipi = new HashSet<>();
|
||
|
|
int totArticoli = 0;
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Downloads/brvlist_17052022125006.xlm";
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BREVI ", ": Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 2111L);
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||
|
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||
|
|
Document doc = builder.parse(new File(l_fileName));
|
||
|
|
Marca marca = new Marca(this.apFull);
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
NodeList nArticoli = doc.getElementsByTagName("articolo");
|
||
|
|
totArticoli = nArticoli.getLength();
|
||
|
|
for (int nArt = 0; nArt < nArticoli.getLength(); nArt++) {
|
||
|
|
Node nArticolo = nArticoli.item(nArt);
|
||
|
|
Element eArticolo = (Element)nArticolo;
|
||
|
|
isNuovo = false;
|
||
|
|
isPromo = false;
|
||
|
|
String l_marcaDesc = eArticolo.getElementsByTagName("produttore").item(0).getTextContent();
|
||
|
|
marca.findByDescrizioneImport(l_marcaDesc);
|
||
|
|
if (marca.getId_marca() > 0L) {
|
||
|
|
String l_articoloCodiceProduttore, l_codiceEan;
|
||
|
|
long dispoL, dispoCashL;
|
||
|
|
double prezzo, streetprice, siae;
|
||
|
|
if (!hsMarche.contains(Long.valueOf(marca.getId_marca()))) {
|
||
|
|
hsMarche.add(Long.valueOf(marca.getId_marca()));
|
||
|
|
System.out.println("NUOVA marca GESTITA: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
String l_articoloCodiceFornitore = eArticolo.getElementsByTagName("codice").item(0).getTextContent();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "BR_" + l_articoloCodiceFornitore;
|
||
|
|
if (eArticolo.getElementsByTagName("codiceproduttore").item(0) == null) {
|
||
|
|
l_articoloCodiceProduttore = "";
|
||
|
|
} else {
|
||
|
|
l_articoloCodiceProduttore = eArticolo.getElementsByTagName("codiceproduttore").item(0).getTextContent();
|
||
|
|
}
|
||
|
|
if (eArticolo.getElementsByTagName("ean").item(0) == null) {
|
||
|
|
l_codiceEan = "";
|
||
|
|
} else {
|
||
|
|
l_codiceEan = eArticolo.getElementsByTagName("ean").item(0).getTextContent();
|
||
|
|
}
|
||
|
|
if (l_codiceEan.equals("0000000000000") || l_codiceEan.indexOf("99999999") >= 0)
|
||
|
|
l_codiceEan = "";
|
||
|
|
String l_categoriaImport = eArticolo.getElementsByTagName("categoria_merceologica_primaria").item(0).getTextContent();
|
||
|
|
if (!eArticolo.getElementsByTagName("categoria_merceologica_primaria").item(0).getTextContent().trim().equals(
|
||
|
|
eArticolo.getElementsByTagName("categoria_merceologica_secondaria").item(0).getTextContent().trim()))
|
||
|
|
l_categoriaImport = l_categoriaImport + " " + l_categoriaImport;
|
||
|
|
art.resetBean();
|
||
|
|
String l_nome = eArticolo.getElementsByTagName("descrizione").item(0).getTextContent();
|
||
|
|
l_nome = l_nome.replace("Ñ", "");
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceFornitore.equals("MZ-V7S250BW"))
|
||
|
|
System.out.println("cod prod: " + l_articoloCodiceFornitore);
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(2111L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_codiceEan.isEmpty()) {
|
||
|
|
if (l_codiceEan.length() < 13)
|
||
|
|
l_codiceEan = DBAdapter.zeroLeft(l_codiceEan, 13);
|
||
|
|
art.findByCodiceEanSerie(l_codiceEan, serie);
|
||
|
|
if (art.getId_articolo() == 0L && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.findByCodiceProduttoreMarca(l_articoloCodiceProduttore, marca.getId_marca());
|
||
|
|
}
|
||
|
|
String urlImmagine = "";
|
||
|
|
String appoggiaPrezzo = eArticolo.getElementsByTagName("prezzo_netto").item(0).getTextContent();
|
||
|
|
appoggiaPrezzo = appoggiaPrezzo.replaceAll("[^0-9,]", "");
|
||
|
|
appoggiaPrezzo = appoggiaPrezzo.replace(".", "");
|
||
|
|
appoggiaPrezzo = appoggiaPrezzo.replace(',', '.');
|
||
|
|
String appoggiaPercScont = eArticolo.getElementsByTagName("sconto").item(0).getTextContent();
|
||
|
|
appoggiaPercScont = appoggiaPercScont.replaceAll("[^0-9,]", "");
|
||
|
|
String appoggiaSiae = eArticolo.getElementsByTagName("siae").item(0).getTextContent();
|
||
|
|
appoggiaSiae = appoggiaSiae.replaceAll("[^0-9,]", "");
|
||
|
|
appoggiaSiae = appoggiaSiae.replace(".", "");
|
||
|
|
appoggiaSiae = appoggiaSiae.replace(',', '.');
|
||
|
|
String dispo = eArticolo.getElementsByTagName("disponibilita_sede").item(0).getTextContent();
|
||
|
|
String dispoImp = eArticolo.getElementsByTagName("impegnato_sede").item(0).getTextContent();
|
||
|
|
String dispoCash = eArticolo.getElementsByTagName("disponibilita_filiale").item(0).getTextContent();
|
||
|
|
String dispoCashImp = eArticolo.getElementsByTagName("impegnato_filiale").item(0).getTextContent();
|
||
|
|
l_descrizioneTecnica = "";
|
||
|
|
try {
|
||
|
|
prezzo = Double.valueOf(appoggiaPrezzo);
|
||
|
|
double percSconto = Double.valueOf(appoggiaPercScont);
|
||
|
|
if (percSconto > 0.0D)
|
||
|
|
isPromo = true;
|
||
|
|
siae = Double.valueOf(appoggiaSiae);
|
||
|
|
streetprice = 0.0D;
|
||
|
|
dispoL = (long)Double.parseDouble(dispo) - (long)Double.parseDouble(dispoImp);
|
||
|
|
if (dispoL < 0L)
|
||
|
|
dispoL = 0L;
|
||
|
|
dispoCashL = (long)Double.parseDouble(dispoCash) - (long)Double.parseDouble(dispoCashImp);
|
||
|
|
long dispoTotL = dispoL + dispoCashL;
|
||
|
|
if (dispoTotL > 0L) {
|
||
|
|
salvaArticoloNuovo = true;
|
||
|
|
} else {
|
||
|
|
salvaArticoloNuovo = false;
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato: " + appoggiaPrezzo + "\n" + currentLine + "\n");
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (art.getId_tipo() != 1L && !hsTipi.contains(Long.valueOf(art.getId_tipo())))
|
||
|
|
hsTipi.add(Long.valueOf(art.getId_tipo()));
|
||
|
|
if (debug);
|
||
|
|
art.aggiornaCodiciAlternativi(false);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCategoriaImport().indexOf(l_categoriaImport) < 0)
|
||
|
|
art.setCategoriaImport(art.getCategoriaImport() + art.getCategoriaImport());
|
||
|
|
if (marca.getId_marca() > 0L && art.getId_marca() == 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else if (salvaArticoloNuovo) {
|
||
|
|
double percentualeRicarico;
|
||
|
|
isNuovo = true;
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setCategoriaImport(l_categoriaImport);
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setCostoNetto(prezzo);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (prezzo <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setId_marca(0L);
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setCostoNetto(prezzo);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (prezzo <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCodiciAlternativi().length() > 50)
|
||
|
|
System.out.println(art.getCodice() + " " + art.getCodice());
|
||
|
|
if (marca.getId_marca() > 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setId_fornitoreCostoNuovo(2111L);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
DoubleOperator prezzoPubblico = new DoubleOperator(percentualeRicarico);
|
||
|
|
prezzoPubblico.setScale(2, 5);
|
||
|
|
prezzoPubblico.divide(100.0F);
|
||
|
|
prezzoPubblico.add(1);
|
||
|
|
prezzoPubblico.multiply(prezzo);
|
||
|
|
if (streetprice > 0.0D && prezzoPubblico.getResult() > streetprice)
|
||
|
|
prezzoPubblico = new DoubleOperator(streetprice);
|
||
|
|
ListinoArticolo lab = art.getListinoArticoloBase();
|
||
|
|
if (prezzoPubblico.getResult() != lab.getPrezzoIvaLA()) {
|
||
|
|
System.out.println("Articolo " + art.getCodice() + " prezzo cambiato da " + lab.getPrezzoIvaLA() + " a " +
|
||
|
|
prezzoPubblico.getResult());
|
||
|
|
lab.setPrezzoLA(prezzoPubblico.getResult());
|
||
|
|
lab.save();
|
||
|
|
}
|
||
|
|
art.setStreetPrice(streetprice);
|
||
|
|
if (art.getPrezzoArticolo(null).getPrezzoBase() > streetprice) {
|
||
|
|
ListinoArticolo listinoArticoloBase = art.getListinoArticoloBase();
|
||
|
|
System.out.println(listinoArticoloBase.getId_listinoArticolo());
|
||
|
|
listinoArticoloBase.setPrezzoLA(streetprice);
|
||
|
|
rp = listinoArticoloBase.save();
|
||
|
|
}
|
||
|
|
if (!l_descrizioneTecnica.isEmpty())
|
||
|
|
art.setDescTxtLang("descrizioneCommerciale", "it", l_descrizioneTecnica);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. Nuovo: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
artNuovoKO++;
|
||
|
|
} else {
|
||
|
|
artNuovo++;
|
||
|
|
if (urlImmagine != null && !urlImmagine.isEmpty() && urlImmagine.endsWith(".jpg"))
|
||
|
|
art.caricaImmaginaDaRemoto(urlImmagine);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L && prezzo > 0.0D) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(2111L, art.getId_articolo(), -1L);
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(2111L);
|
||
|
|
af.setCostoVecchio(af.getCostoTotale());
|
||
|
|
af.setCosto(prezzo);
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
af.setStreetPrice(streetprice);
|
||
|
|
af.setDispCash(dispoCashL);
|
||
|
|
int giornoMeseAttuale = cal.get(5);
|
||
|
|
cal.add(2, 1);
|
||
|
|
cal.set(5, 1);
|
||
|
|
cal.add(6, -1);
|
||
|
|
int giornoFineMeseAttuale = cal.get(5);
|
||
|
|
if (giornoMeseAttuale <= giornoFineMeseAttuale - 5) {
|
||
|
|
af.setDispSede(dispoL);
|
||
|
|
} else {
|
||
|
|
af.setDispSede(0L);
|
||
|
|
}
|
||
|
|
af.setCostoAggiuntivo(siae);
|
||
|
|
af.setFlgControlloCostoAggAF(1L);
|
||
|
|
af.setFlgPromo(isPromo ? 1L : 0L);
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
art.aggiornaPrezziEDispoByFornitori(streetprice, isNuovo);
|
||
|
|
if (art.getFlgModImportazione() == 2L) {
|
||
|
|
prezzoModificato++;
|
||
|
|
} else if (art.getFlgModImportazione() == 3L) {
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (art.getFlgEscludiWebArt() == 2L) {
|
||
|
|
articoloSospeso++;
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
System.out.println("marca scartata: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Large: Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE BREVI " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- tot art: ");
|
||
|
|
sb.append(totArticoli);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BREVI ", sb.toString());
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! IMPORT BREVI record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BREVI ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import Articolo e Prezzi BREVI " + serie + " avvenuta correttamente. - File:" + l_fileName + " - Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
sb.append(" - Update articoli non trovati: - ");
|
||
|
|
sb.append(rp.getMsg());
|
||
|
|
sb.append(" - DEBUG BREVI SCARTO CODICI: - ");
|
||
|
|
sb.append(scartoCodici.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import Articolo e Prezzi BREVI " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class ThreadImportRunner extends Thread {
|
||
|
|
private static final String RUNNER_FTP_URL = "runnertechstore.it";
|
||
|
|
|
||
|
|
private static final String RUNNER_FTP_USER = "C250453";
|
||
|
|
|
||
|
|
private static final String RUNNER_FTP_PWD = "rfukd8f0";
|
||
|
|
|
||
|
|
private static final String PREFISSO_CODICE_RUNNER = "RU_";
|
||
|
|
|
||
|
|
private ApplParmFull apFull;
|
||
|
|
|
||
|
|
private final String TAG_THREAD_MSG = "IMPORT RUNNER ";
|
||
|
|
|
||
|
|
private boolean sendEmail;
|
||
|
|
|
||
|
|
private long[] flgTipoImportAr;
|
||
|
|
|
||
|
|
private static final long l_id_fornitore = 2117L;
|
||
|
|
|
||
|
|
private static final long l_id_tipoDaDafinire = 1L;
|
||
|
|
|
||
|
|
private static final long TIPO_IMPORT_RUNNER_ANAGRAFICA = 0L;
|
||
|
|
|
||
|
|
private static final long TIPO_IMPORT_RUNNER_PREZZI = 1L;
|
||
|
|
|
||
|
|
private static final long TIPO_IMPORT_RUNNER_DESC_IMG = 2L;
|
||
|
|
|
||
|
|
private static final long TIPO_IMPORT_RUNNER_DISPO = 3L;
|
||
|
|
|
||
|
|
private static final long TIPO_IMPORT_RUNNER_PESO = 4L;
|
||
|
|
|
||
|
|
private String getTipoImport(long flgTipoImport) {
|
||
|
|
switch ((int)flgTipoImport) {
|
||
|
|
case 0:
|
||
|
|
return " Anagrafica";
|
||
|
|
case 2:
|
||
|
|
return " Descrizione e Immagini";
|
||
|
|
case 3:
|
||
|
|
return " Dispo";
|
||
|
|
case 1:
|
||
|
|
return " Prezzi";
|
||
|
|
case 4:
|
||
|
|
return " Peso";
|
||
|
|
}
|
||
|
|
return "??";
|
||
|
|
}
|
||
|
|
|
||
|
|
private String getTipoImportPathFtp(long flgTipoImport) {
|
||
|
|
switch ((int)flgTipoImport) {
|
||
|
|
case 0:
|
||
|
|
return "articoli.txt";
|
||
|
|
case 2:
|
||
|
|
return "descp.txt";
|
||
|
|
case 3:
|
||
|
|
return "dispo.txt";
|
||
|
|
case 1:
|
||
|
|
return "C250453/prezzi.txt";
|
||
|
|
case 4:
|
||
|
|
return "peso.txt";
|
||
|
|
}
|
||
|
|
return "??";
|
||
|
|
}
|
||
|
|
|
||
|
|
public ThreadImportRunner(ApplParmFull apFull, long[] flgTipoImportAr, boolean sendEmail) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.sendEmail = sendEmail;
|
||
|
|
this.flgTipoImportAr = flgTipoImportAr;
|
||
|
|
if (!CCImport.isThreadRunnerAttivo()) {
|
||
|
|
CCImport.threadImportRunner = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void run() {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
Timer timer = new Timer();
|
||
|
|
timer.start();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT RUNNER ", "...inizio ...");
|
||
|
|
String serverFtp = "runnertechstore.it";
|
||
|
|
String user = "C250453";
|
||
|
|
String pass = "rfukd8f0";
|
||
|
|
String serie = "";
|
||
|
|
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
|
||
|
|
System.out.println("##############\n IMPORT RUNNER " + serie + "\nSTART: " + start.toString());
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuilder sbMsg = new StringBuilder();
|
||
|
|
String targetDir = this.apFull.getParm("DOCBASE").getTesto() + this.apFull.getParm("DOCBASE").getTesto();
|
||
|
|
for (int i = 0; i < this.flgTipoImportAr.length; i++) {
|
||
|
|
String l_fileToDownload = getTipoImportPathFtp(this.flgTipoImportAr[i]);
|
||
|
|
String l_fileName = targetDir + targetDir;
|
||
|
|
l_fileName = l_fileName.replace(".txt", "_" + DBAdapter.getTimeNameForFileUpload() + ".txt");
|
||
|
|
if (!debug) {
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT RUNNER ",
|
||
|
|
getTipoImport(this.flgTipoImportAr[i]) + ": Download nuovo file " + getTipoImport(this.flgTipoImportAr[i]) + " su " + l_fileToDownload);
|
||
|
|
new File(l_fileName).delete();
|
||
|
|
rp = DBAdapter.getFileViaFtp(serverFtp, user, pass, l_fileToDownload, l_fileName);
|
||
|
|
} else {
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/" + getTipoImportPathFtp(this.flgTipoImportAr[i]);
|
||
|
|
}
|
||
|
|
if (!new File(l_fileName).exists())
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT RUNNER ",
|
||
|
|
getTipoImport(this.flgTipoImportAr[i]) + ": ERRORE!! FILE " + getTipoImport(this.flgTipoImportAr[i]) + " NON TROVATO!!!");
|
||
|
|
switch ((int)this.flgTipoImportAr[i]) {
|
||
|
|
case 0:
|
||
|
|
rp = importAnagraficaDispoCSV(l_fileName);
|
||
|
|
break;
|
||
|
|
case 2:
|
||
|
|
rp = importDecrizioniImgCSV(l_fileName);
|
||
|
|
break;
|
||
|
|
case 1:
|
||
|
|
rp = importPrezzoCSV(l_fileName);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
timer.stop();
|
||
|
|
rp.setMsg("Import concluso. IMPORT RUNNER DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
if (this.sendEmail)
|
||
|
|
CCImport.this.sendArticoliCambiatiByEmail(this.apFull, rp.getMsg(), 2117L);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT RUNNER ", rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, "IMPORT RUNNER ");
|
||
|
|
CCImport.threadImportRunner = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgEbay() == 1L) {
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
bean.startThreadAllineaEbay(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgAmz() == 1L) {
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
bean.startThreadAllineaAmz(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importAnagraficaDispoCSV(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
boolean isNuovo = false;
|
||
|
|
String TAG_EXTRA = " ANAGRAFICA E DISPO";
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
long SOSPENDI_DOPO_N_GG = this.apFull.getParm("CC_SOSPENDI_DOPO_N_GG_NO_IMPORT").getNumeroLong();
|
||
|
|
String CVS_SEPARATOR = "|";
|
||
|
|
int colArticoloCodiceAlternativoFornitore = 0;
|
||
|
|
int colArticoloCodiceProduttore = 1;
|
||
|
|
int colArticoloCodiceEAN = 2;
|
||
|
|
int colArticoloDescrizione = 3;
|
||
|
|
int colArticoloMarca = 4;
|
||
|
|
int colArticoloCodiceCategoria = 6;
|
||
|
|
int colArticoloDescCategoria = 7;
|
||
|
|
int colArticoloDispo = 8;
|
||
|
|
int colArticoloPromo = 10;
|
||
|
|
int colArticoloDataPromo = 11;
|
||
|
|
if (SOSPENDI_DOPO_N_GG < 6L)
|
||
|
|
SOSPENDI_DOPO_N_GG = 6L;
|
||
|
|
String CLASSE_PRODOTTO_RICONDIZIONATO = "XXXXX";
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Downloads/articolid-link.txt";
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT RUNNER ", " ANAGRAFICA E DISPO: Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 2117L);
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
Marca marca = new Marca(this.apFull);
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
reader.readLine();
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
isNuovo = false;
|
||
|
|
isPromo = false;
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, CVS_SEPARATOR);
|
||
|
|
if (st.countToken() >= 6) {
|
||
|
|
String l_marcaDesc = st.getToken(colArticoloMarca);
|
||
|
|
marca.findByDescrizioneImport(l_marcaDesc);
|
||
|
|
if (marca.getId_marca() > 0L) {
|
||
|
|
String l_classeProdotto = "yy";
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(colArticoloCodiceAlternativoFornitore).trim();
|
||
|
|
String l_articoloCodiceProduttore = st.getToken(colArticoloCodiceProduttore).trim();
|
||
|
|
String l_nome = st.getToken(colArticoloDescrizione).trim();
|
||
|
|
String dispo = st.getToken(colArticoloDispo);
|
||
|
|
long dispoL = Long.parseLong(dispo);
|
||
|
|
isPromo = st.getToken(colArticoloPromo).equals("1");
|
||
|
|
String finePromo = st.getToken(colArticoloDataPromo);
|
||
|
|
if (finePromo != null && !finePromo.isEmpty()) {
|
||
|
|
cal.set(1, Integer.valueOf(finePromo.substring(6, 10)).intValue());
|
||
|
|
cal.set(2, Integer.valueOf(finePromo.substring(3, 5)) - 1);
|
||
|
|
cal.set(5, Integer.valueOf(finePromo.substring(0, 2)).intValue());
|
||
|
|
cal.add(6, -1);
|
||
|
|
Date dataFinePromo = new Date(cal.getTimeInMillis());
|
||
|
|
} else {
|
||
|
|
Date dataFinePromo = null;
|
||
|
|
}
|
||
|
|
if (!l_classeProdotto.equals("XXXXX")) {
|
||
|
|
String l_codiceCategoria = st.getToken(colArticoloCodiceCategoria).trim();
|
||
|
|
String l_categoriaImport = st.getToken(colArticoloDescCategoria).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "RU_" + l_articoloCodiceFornitore;
|
||
|
|
String l_codiceEan = st.getToken(colArticoloCodiceEAN).trim();
|
||
|
|
if (l_codiceEan.length() < 13)
|
||
|
|
l_codiceEan = DBAdapter.zeroLeft(l_codiceEan, 13);
|
||
|
|
if (l_codiceEan.equals("0000000000000") || l_codiceEan.indexOf("99999999") >= 0)
|
||
|
|
l_codiceEan = "";
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("CG_7DB75EA"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
art.resetBean();
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(2117L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_codiceEan.isEmpty())
|
||
|
|
art.findByCodiceEanSerie(l_codiceEan, serie);
|
||
|
|
if (art.getId_articolo() == 0L && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.findByCodiceProduttoreMarca(l_articoloCodiceProduttore, marca.getId_marca());
|
||
|
|
String urlImmagine = "";
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (debug);
|
||
|
|
art.aggiornaCodiciAlternativi(false);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCodiciAlternativi().length() > 90)
|
||
|
|
System.out.println(art.getCodice() + " " + art.getCodice());
|
||
|
|
if (!l_categoriaImport.isEmpty() && art.getCategoriaImport().indexOf(l_categoriaImport) < 0)
|
||
|
|
art.setCategoriaImport(art.getCategoriaImport() + art.getCategoriaImport());
|
||
|
|
if (marca.getId_marca() > 0L && art.getId_marca() == 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.superSave();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else if (salvaArticoloNuovo) {
|
||
|
|
isNuovo = true;
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setCategoriaImport(l_categoriaImport);
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setId_marca(0L);
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCodiciAlternativi().length() > 90)
|
||
|
|
System.out.println(art.getCodice() + " " + art.getCodice());
|
||
|
|
if (marca.getId_marca() > 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setId_fornitoreCostoNuovo(2117L);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. Nuovo: " + l_articoloCodiceAlternativoFornitore + " - " +
|
||
|
|
art.getDescrizione() + " - " + rp.getMsg() + " - ");
|
||
|
|
artNuovoKO++;
|
||
|
|
} else {
|
||
|
|
artNuovo++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
boolean test = false;
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(2117L, art.getId_articolo(), -1L);
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(2117L);
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
if (af.getDispSede() != dispoL) {
|
||
|
|
test = true;
|
||
|
|
if (af.getId_articolo() == 146297L)
|
||
|
|
DBAdapter.printDebug("XXXXXXXXXXXXXXXXXXXXXXXXXXXX 146297 XXXXXXXXXXXXXXXX");
|
||
|
|
DBAdapter.printDebug("\nRunner - cambio dispo fornitore per articolo: " + art.getCodice() + " da " +
|
||
|
|
af.getDispSede() + " a " + dispoL + " + aggiornamento data ultimo prezzo");
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
}
|
||
|
|
af.setDispSede(dispoL);
|
||
|
|
af.setFlgPromo(isPromo ? 1L : 0L);
|
||
|
|
DBAdapter.printDebug(test, "\nRunner - articolo: " + art.getCodice() + " salvo dispo a " + dispoL + " ====" +
|
||
|
|
af.getDispSede());
|
||
|
|
rp = af.save();
|
||
|
|
DBAdapter.printDebug(test, "\nRunner - articolo: " + art.getCodice() + " SALVATO: dispo a " +
|
||
|
|
af.getDispSede() + " RP:" + rp.getMsg());
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
art.aggiornaPrezziEDispoByFornitori(0.0D, isNuovo);
|
||
|
|
if (art.getFlgModImportazione() == 2L) {
|
||
|
|
prezzoModificato++;
|
||
|
|
} else if (art.getFlgModImportazione() == 3L) {
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (art.getFlgEscludiWebArt() == 2L) {
|
||
|
|
articoloSospeso++;
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
System.out.println("prodotto ricondizionato escluso: codice Forn.:" + l_articoloCodiceFornitore + " codice produttore: " + l_articoloCodiceProduttore + "\n" + l_nome);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
System.out.println("marca scartata: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE INGRAMMICRO " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT RUNNER ", " ANAGRAFICA E DISPO" + sb.toString());
|
||
|
|
}
|
||
|
|
ArticoloCR CR = new ArticoloCR(this.apFull);
|
||
|
|
CR.setId_fornitore(2117L);
|
||
|
|
CR.setFlgModImportazione(0L);
|
||
|
|
Vectumerator<Articolo> vec = bean.findByCR(CR, 0, 0);
|
||
|
|
i = 0;
|
||
|
|
while (vec.hasMoreElements()) {
|
||
|
|
i++;
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT RUNNER ", " ANAGRAFICA E DISPO aggiornamento articoli non trovati " + i + " su " +
|
||
|
|
vec.getTotNumberOfRecords());
|
||
|
|
Articolo row = (Articolo)vec.nextElement();
|
||
|
|
if (row.getId_fornitoreCostoNuovo() == 2117L) {
|
||
|
|
row.azzeraQuantita(2L);
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
String s_sql_sqring = "UPDATE ARTICOLO_FORNITORE SET dispSede=0, dispCash=0 where id_articolo=" + row.getId_articolo() + " and id_clifor=2117";
|
||
|
|
rp = row.update(s_sql_sqring);
|
||
|
|
rp.append(row.aggiornaPrezziEDispoByFornitori(0.0D, false));
|
||
|
|
}
|
||
|
|
if (SOSPENDI_DOPO_N_GG > 0L)
|
||
|
|
bean.update("UPDATE ARTICOLO SET flgEscludiWebArt=2,flgEscludiWeb=2 WHERE codice LIKE '" + serie + "%' and flgModImportazione = 0 and DATEDIFF(CURDATE(), dataUltimoImport)>=" + SOSPENDI_DOPO_N_GG + ";");
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! IMPORT RUNNER record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT RUNNER ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import IMPORT RUNNER ANAGRAFICA E DISPO " + serie + " avvenuta correttamente. Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import IMPORT RUNNER ANAGRAFICA E DISPO " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importPrezzoCSV(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = false;
|
||
|
|
boolean isNuovo = false;
|
||
|
|
String TAG_EXTRA = " PREZZI";
|
||
|
|
isNuovo = false;
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
long SOSPENDI_DOPO_N_GG = this.apFull.getParm("CC_SOSPENDI_DOPO_N_GG_NO_IMPORT").getNumeroLong();
|
||
|
|
String CVS_SEPARATOR = "|";
|
||
|
|
int colArticoloCodiceAlternativoFornitore = 0;
|
||
|
|
int colPrezzo = 1;
|
||
|
|
if (SOSPENDI_DOPO_N_GG < 6L)
|
||
|
|
SOSPENDI_DOPO_N_GG = 6L;
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Downloads/prezzyashi.txt";
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT RUNNER ", " PREZZI: Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 2117L);
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
reader.readLine();
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
isNuovo = false;
|
||
|
|
isPromo = false;
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, CVS_SEPARATOR);
|
||
|
|
if (st.countToken() >= 2) {
|
||
|
|
double prezzo;
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(colArticoloCodiceAlternativoFornitore).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "RU_" + l_articoloCodiceFornitore;
|
||
|
|
String appoggiaPrezzo = st.getToken(colPrezzo).trim();
|
||
|
|
try {
|
||
|
|
prezzo = Double.valueOf(appoggiaPrezzo.replace(',', '.'));
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato: " + appoggiaPrezzo + "\n" + currentLine + "\n");
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
art.resetBean();
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(2117L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(2117L, art.getId_articolo(), -1L);
|
||
|
|
if (af.getCosto() != prezzo || art.getCostoNetto() == 0.0D) {
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(2117L);
|
||
|
|
af.setCostoVecchio(af.getCostoTotale());
|
||
|
|
af.setCosto(prezzo);
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
af.setStreetPrice(0.0D);
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
art.aggiornaPrezziEDispoByFornitori(0.0D, isNuovo);
|
||
|
|
if (art.getFlgModImportazione() == 2L) {
|
||
|
|
prezzoModificato++;
|
||
|
|
} else if (art.getFlgModImportazione() == 3L) {
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (art.getFlgEscludiWebArt() == 2L) {
|
||
|
|
articoloSospeso++;
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (art.getFlgEscludiWebArt() == 2L) {
|
||
|
|
articoloSospeso++;
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE IMPORT RUNNER " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. non trovati: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT RUNNER ", " PREZZI" + sb.toString());
|
||
|
|
}
|
||
|
|
if (SOSPENDI_DOPO_N_GG > 0L)
|
||
|
|
bean.update("UPDATE ARTICOLO SET flgEscludiWebArt=2,flgEscludiWeb=2 WHERE codice LIKE '" + serie + "%' and flgModImportazione = 0 and DATEDIFF(CURDATE(), dataUltimoImport)>=" + SOSPENDI_DOPO_N_GG + ";");
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! IMPORT RUNNER record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT RUNNER ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import IMPORT RUNNER PREZZI " + serie + " avvenuta correttamente. Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import IMPORT RUNNER PREZZI " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importDecrizioniImgCSV(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticolo = false;
|
||
|
|
String TAG_EXTRA = " DESCRIZIONI E IMMAGINI";
|
||
|
|
String serie = "";
|
||
|
|
String l_lang = "it";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNonSalvato = 0, artDescrizioneAggiunta = 0, artImgSalvata = 0, recordErrati = 0;
|
||
|
|
String CVS_SEPARATOR = "|";
|
||
|
|
int colArticoloCodiceAlternativoFornitore = 0;
|
||
|
|
int colLinkImg = 1;
|
||
|
|
int colDescrizione = 3;
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
if (debug)
|
||
|
|
l_fileName = "/Users/acolzi/Documents/webapps/cc/_tmp/PRICE1.TXT";
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
reader.readLine();
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
salvaArticolo = false;
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, CVS_SEPARATOR);
|
||
|
|
if (st.countToken() >= 2) {
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(colArticoloCodiceAlternativoFornitore).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "RU_" + l_articoloCodiceFornitore;
|
||
|
|
String l_descrizione = st.getToken(colDescrizione);
|
||
|
|
String l_linkImmagine = st.getToken(colLinkImg);
|
||
|
|
art.resetBean();
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(2117L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (!l_linkImmagine.isEmpty())
|
||
|
|
if (!art.isImgExist(1)) {
|
||
|
|
salvaArticolo = true;
|
||
|
|
art.caricaImmaginaDaRemoto(l_linkImmagine, 1L);
|
||
|
|
artImgSalvata++;
|
||
|
|
}
|
||
|
|
if (art.getDescrizioneCommerciale(l_lang).isEmpty() && !l_descrizione.isEmpty()) {
|
||
|
|
art.setDescTxtLang("descrizioneCommerciale", l_lang, l_descrizione);
|
||
|
|
if (art.getDescrizioneBreve(l_lang).isEmpty())
|
||
|
|
art.setDescTxtLang("descrizioneBreve", l_lang, art.getNome());
|
||
|
|
salvaArticolo = true;
|
||
|
|
artDescrizioneAggiunta++;
|
||
|
|
}
|
||
|
|
if (salvaArticolo) {
|
||
|
|
System.out.println("importDecrizioniImgCSV runner: codice: " + art.getId_articolo());
|
||
|
|
art.setFlgTipoSchedaArticoloWww(2L);
|
||
|
|
rp = art.save();
|
||
|
|
if (!rp.getStatus())
|
||
|
|
artNonSalvato++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE IMPORT RUNNER " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. desc aggiunta: ");
|
||
|
|
sb.append(artDescrizioneAggiunta);
|
||
|
|
sb.append("- art. img salvata: ");
|
||
|
|
sb.append(artImgSalvata);
|
||
|
|
sb.append("- art. non salvati: ");
|
||
|
|
sb.append(artNonSalvato);
|
||
|
|
sb.append("- art. non trovati: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT RUNNER ", " DESCRIZIONI E IMMAGINI" + sb.toString());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! IMPORT RUNNER record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT RUNNER ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import IMPORT RUNNER DESCRIZIONI E IMMAGINI " + serie + " avvenuta correttamente. Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. desc aggiunta: ");
|
||
|
|
sb.append(artDescrizioneAggiunta);
|
||
|
|
sb.append("- art. img salvata: ");
|
||
|
|
sb.append(artImgSalvata);
|
||
|
|
sb.append("- art. non salvati: ");
|
||
|
|
sb.append(artNonSalvato);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import IMPORT RUNNER DESCRIZIONI E IMMAGINI " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class ThreadImportBestIt extends Thread {
|
||
|
|
private static final String BESTIT_LOCAL_PATH = "/home/sites/f3/_listini/_bestit/";
|
||
|
|
|
||
|
|
private static final String PREFISSO_CODICE_BESTIT = "BI_";
|
||
|
|
|
||
|
|
private ApplParmFull apFull;
|
||
|
|
|
||
|
|
private final String TAG_THREAD_MSG = "IMPORT BESTIT ";
|
||
|
|
|
||
|
|
private boolean sendEmail;
|
||
|
|
|
||
|
|
private long[] flgTipoImportAr;
|
||
|
|
|
||
|
|
private static final long l_id_fornitore = 2131L;
|
||
|
|
|
||
|
|
private static final long l_id_tipoDaDafinire = 1L;
|
||
|
|
|
||
|
|
private static final long TIPO_IMPORT_BESTIT_ANAG_DISPO_PREZZI = 0L;
|
||
|
|
|
||
|
|
private static final long TIPO_IMPORT_BESTIT_DESC_IMG = 1L;
|
||
|
|
|
||
|
|
private String getTipoImport(long flgTipoImport) {
|
||
|
|
switch ((int)flgTipoImport) {
|
||
|
|
case 0:
|
||
|
|
return " Anag, Dispo, Prezzi";
|
||
|
|
case 1:
|
||
|
|
return " Descrizione e Immagini";
|
||
|
|
}
|
||
|
|
return "??";
|
||
|
|
}
|
||
|
|
|
||
|
|
public ThreadImportBestIt(ApplParmFull apFull, long[] flgTipoImportAr, boolean sendEmail) {
|
||
|
|
this.apFull = apFull;
|
||
|
|
this.sendEmail = sendEmail;
|
||
|
|
this.flgTipoImportAr = flgTipoImportAr;
|
||
|
|
if (!CCImport.isThreadEsprinetAttivo()) {
|
||
|
|
CCImport.threadImportBestit = true;
|
||
|
|
start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void run() {
|
||
|
|
String l_fileName;
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
Timer timer = new Timer();
|
||
|
|
timer.start();
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BESTIT ", "...inizio ...");
|
||
|
|
String serie = "";
|
||
|
|
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
|
||
|
|
System.out.println("##############\n IMPORT BESTIT " + serie + "\nSTART: " + start.toString());
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
String l_fileToDownload = "EsportaArticoli.txt";
|
||
|
|
StringBuilder sbMsg = new StringBuilder();
|
||
|
|
String targetDir = "/home/sites/f3/_listini/_bestit/";
|
||
|
|
if (debug) {
|
||
|
|
l_fileName = "/Users/acolzi/Downloads/" + l_fileToDownload;
|
||
|
|
} else {
|
||
|
|
l_fileName = targetDir + targetDir;
|
||
|
|
}
|
||
|
|
if (new File(l_fileName).exists()) {
|
||
|
|
for (int i = 0; i < this.flgTipoImportAr.length; i++) {
|
||
|
|
if (!debug)
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BESTIT ",
|
||
|
|
getTipoImport(this.flgTipoImportAr[i]) + ": Elaborazione nuovo file " + getTipoImport(this.flgTipoImportAr[i]) + " su " + l_fileToDownload);
|
||
|
|
if (!new File(l_fileName).exists())
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BESTIT ",
|
||
|
|
getTipoImport(this.flgTipoImportAr[i]) + ": ERRORE!! FILE " + getTipoImport(this.flgTipoImportAr[i]) + " NON TROVATO!!!");
|
||
|
|
switch ((int)this.flgTipoImportAr[i]) {
|
||
|
|
case 0:
|
||
|
|
rp = importAnagDispoPrezzoCSV(l_fileName);
|
||
|
|
break;
|
||
|
|
case 1:
|
||
|
|
rp = importDecrizioniImgCSV(l_fileName);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
rp.setMsg("ERRORE!! file " + l_fileName + " NON TROVATO");
|
||
|
|
}
|
||
|
|
timer.stop();
|
||
|
|
rp.setMsg("Import concluso. IMPORT BESTIT DURATA: " + timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||
|
|
if (this.sendEmail)
|
||
|
|
CCImport.this.sendArticoliCambiatiByEmail(this.apFull, rp.getMsg(), 2131L);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BESTIT ", rp.getMsg());
|
||
|
|
try {
|
||
|
|
sleep(10000L);
|
||
|
|
} catch (Exception e) {}
|
||
|
|
StatusMsg.deleteMsgByTag(this.apFull, "IMPORT BESTIT ");
|
||
|
|
CCImport.threadImportBestit = false;
|
||
|
|
System.out.println(rp.getMsg());
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgEbay() == 1L) {
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
bean.startThreadAllineaEbay(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
if (CCImport.this.getAttivita(this.apFull).getFlgAmz() == 1L) {
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
bean.startThreadAllineaAmz(this.apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importAnagDispoPrezzoCSV(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticoloNuovo = true;
|
||
|
|
boolean isNuovo = false;
|
||
|
|
String TAG_EXTRA = " ANAGRAFICA DISPO PREZZO";
|
||
|
|
String serie = "";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNuovo = 0, artNuovoKO = 0, artNuovoNonSalvato = 0, recordErrati = 0;
|
||
|
|
int prezzoModificato = 0, prezzoNonModificato = 0, articoloSospeso = 0, articoloVisibile = 0, articoloInOrdine = 0;
|
||
|
|
long SOSPENDI_DOPO_N_GG = this.apFull.getParm("CC_SOSPENDI_DOPO_N_GG_NO_IMPORT").getNumeroLong();
|
||
|
|
String CVS_SEPARATOR = "|";
|
||
|
|
int colArticoloCodiceAlternativoFornitore = 2;
|
||
|
|
int colArticoloCodiceProduttore = 1;
|
||
|
|
int colArticoloCodiceEAN = 11;
|
||
|
|
int colArticoloDescrizione = 3;
|
||
|
|
int colArticoloMarca = 0;
|
||
|
|
int colArticoloCodiceCategoria = 4;
|
||
|
|
int colArticoloDescCategoria = 10;
|
||
|
|
int colArticoloDispo = 6;
|
||
|
|
int colPrezzo = 5;
|
||
|
|
int colPrezzoOfferta = 9;
|
||
|
|
int colStreetprice = -1;
|
||
|
|
int colLinkFoto = 12;
|
||
|
|
int colSchedaTecnica = 13;
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BESTIT ", ": Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 2131L);
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
Marca marca = new Marca(this.apFull);
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
reader.readLine();
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
String dispoCash = "";
|
||
|
|
double streetprice = 0.0D;
|
||
|
|
isNuovo = false;
|
||
|
|
isPromo = false;
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, CVS_SEPARATOR, '"');
|
||
|
|
if (st.countToken() >= 6) {
|
||
|
|
String l_marcaDesc = st.getToken(colArticoloMarca);
|
||
|
|
marca.findByDescrizioneImport(l_marcaDesc);
|
||
|
|
if (marca.getId_marca() > 0L) {
|
||
|
|
long dispoL;
|
||
|
|
double prezzo;
|
||
|
|
String l_nome = st.getToken(colArticoloDescrizione).trim();
|
||
|
|
String urlImmagine = st.getToken(colLinkFoto);
|
||
|
|
l_descrizioneTecnica = st.getToken(colSchedaTecnica);
|
||
|
|
String l_codiceCategoria = st.getToken(colArticoloCodiceCategoria).trim();
|
||
|
|
String l_categoriaImport = l_codiceCategoria + " " + l_codiceCategoria;
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(colArticoloCodiceAlternativoFornitore).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "BI_" + l_articoloCodiceFornitore;
|
||
|
|
l_articoloCodiceAlternativoFornitore = "BI_" + l_articoloCodiceFornitore;
|
||
|
|
String l_articoloCodiceProduttore = st.getToken(colArticoloCodiceProduttore).trim();
|
||
|
|
String l_codiceEan = st.getToken(colArticoloCodiceEAN).trim();
|
||
|
|
if (l_codiceEan.length() < 13)
|
||
|
|
l_codiceEan = DBAdapter.zeroLeft(l_codiceEan, 13);
|
||
|
|
if (l_codiceEan.equals("0000000000000") || l_codiceEan.indexOf("99999999") >= 0)
|
||
|
|
l_codiceEan = "";
|
||
|
|
art.resetBean();
|
||
|
|
if (debug &&
|
||
|
|
l_articoloCodiceAlternativoFornitore.equals("CG_7DB75EA"))
|
||
|
|
System.out.println(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(2131L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_codiceEan.isEmpty())
|
||
|
|
art.findByCodiceEanSerie(l_codiceEan, serie);
|
||
|
|
if (art.getId_articolo() == 0L && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.findByCodiceProduttoreMarca(l_articoloCodiceProduttore, marca.getId_marca());
|
||
|
|
if (st.countToken() > 7);
|
||
|
|
String appoggiaPrezzo = st.getToken(colPrezzo).trim();
|
||
|
|
String appoggiaPrezzoOfferta = st.getToken(colPrezzoOfferta).trim();
|
||
|
|
String dispo = st.getToken(colArticoloDispo).trim();
|
||
|
|
try {
|
||
|
|
prezzo = Double.valueOf(appoggiaPrezzo.replace(',', '.'));
|
||
|
|
double prezzoOfferta = Double.valueOf(appoggiaPrezzoOfferta.replace(',', '.'));
|
||
|
|
dispoL = Long.parseLong(dispo);
|
||
|
|
long dispoTotL = dispoL;
|
||
|
|
if (dispoTotL > 0L) {
|
||
|
|
salvaArticoloNuovo = true;
|
||
|
|
} else {
|
||
|
|
salvaArticoloNuovo = false;
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
err.append("Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " - ");
|
||
|
|
System.out.println("err: Record scartato prezzo errato: " + l_articoloCodiceAlternativoFornitore + " prezzo rilevato:" + appoggiaPrezzo + "\n" + currentLine + "\n");
|
||
|
|
recordErrati++;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (debug);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (!l_categoriaImport.isEmpty() && art.getCategoriaImport().indexOf(l_categoriaImport) < 0)
|
||
|
|
art.setCategoriaImport(art.getCategoriaImport() + art.getCategoriaImport());
|
||
|
|
if (marca.getId_marca() > 0L && art.getId_marca() == 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. agg: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
} else {
|
||
|
|
artAggiornati++;
|
||
|
|
}
|
||
|
|
} else if (salvaArticoloNuovo) {
|
||
|
|
double percentualeRicarico;
|
||
|
|
isNuovo = true;
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setCostoNetto(prezzo);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (prezzo <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setId_iva(this.apFull.getParm("CODICE_IVA_STD_VEND").getNumeroLong());
|
||
|
|
art.setId_tipo(1L);
|
||
|
|
if (!serie.isEmpty()) {
|
||
|
|
art.setCodice(art.getCodicePrimoLiberoBySerie(serie));
|
||
|
|
System.out.println("nuovoCodice: " + art.getCodice());
|
||
|
|
}
|
||
|
|
art.setNome(l_nome);
|
||
|
|
art.setDescrizione(l_nome);
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setCategoriaImport(l_categoriaImport);
|
||
|
|
art.setFlgEscludiWebArt(1L);
|
||
|
|
art.setCostoNetto(prezzo);
|
||
|
|
art.setFlgModImportazione(1L);
|
||
|
|
if (prezzo <= (double)costoLimiteRicarico) {
|
||
|
|
percentualeRicarico = (double)ricaricoSottoLimite;
|
||
|
|
} else {
|
||
|
|
percentualeRicarico = (double)ricaricoSopraLimite;
|
||
|
|
}
|
||
|
|
art.setPercRicarico(percentualeRicarico);
|
||
|
|
art.setCodiciAlternativi(l_articoloCodiceAlternativoFornitore);
|
||
|
|
if (art.getCodiceProduttore().isEmpty() && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.setCodiceProduttore(l_articoloCodiceProduttore);
|
||
|
|
if (art.getCodiceEan().isEmpty() && !l_codiceEan.isEmpty())
|
||
|
|
art.setCodiceEan(l_codiceEan);
|
||
|
|
if (art.getCodiciAlternativi().length() > 50)
|
||
|
|
System.out.println(art.getCodice() + " " + art.getCodice());
|
||
|
|
if (marca.getId_marca() > 0L)
|
||
|
|
art.setId_marca(marca.getId_marca());
|
||
|
|
art.setId_fornitoreCostoNuovo(2131L);
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
DoubleOperator prezzoPubblico = new DoubleOperator(percentualeRicarico);
|
||
|
|
prezzoPubblico.setScale(2, 5);
|
||
|
|
prezzoPubblico.divide(100.0F);
|
||
|
|
prezzoPubblico.add(1);
|
||
|
|
prezzoPubblico.multiply(prezzo);
|
||
|
|
if (streetprice > 0.0D && prezzoPubblico.getResult() > streetprice)
|
||
|
|
prezzoPubblico = new DoubleOperator(streetprice);
|
||
|
|
ListinoArticolo lab = art.getListinoArticoloBase();
|
||
|
|
if (prezzoPubblico.getResult() != lab.getPrezzoIvaLA()) {
|
||
|
|
System.out.println("Articolo " + art.getCodice() + " prezzo cambiato da " +
|
||
|
|
lab.getPrezzoIvaLA() + " a " + prezzoPubblico.getResult());
|
||
|
|
lab.setPrezzoLA(prezzoPubblico.getResult());
|
||
|
|
lab.save();
|
||
|
|
}
|
||
|
|
art.setStreetPrice(streetprice);
|
||
|
|
if (art.getPrezzoArticolo(null).getPrezzoBase() > streetprice) {
|
||
|
|
ListinoArticolo listinoArticoloBase = art.getListinoArticoloBase();
|
||
|
|
System.out.println(listinoArticoloBase.getId_listinoArticolo());
|
||
|
|
listinoArticoloBase.setPrezzoLA(streetprice);
|
||
|
|
rp = listinoArticoloBase.save();
|
||
|
|
}
|
||
|
|
art.setCountImportNonTrovato(0L);
|
||
|
|
art.setDataUltimoImport(DBAdapter.getToday());
|
||
|
|
rp = art.save();
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
err.append("Art. Nuovo: " + l_articoloCodiceAlternativoFornitore + " - " + art.getDescrizione() + " - " +
|
||
|
|
rp.getMsg() + " - ");
|
||
|
|
artNuovoKO++;
|
||
|
|
} else {
|
||
|
|
artNuovo++;
|
||
|
|
if (urlImmagine != null && !urlImmagine.isEmpty() && urlImmagine.endsWith(".jpg"))
|
||
|
|
art.caricaImmaginaDaRemoto(urlImmagine);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artNuovoNonSalvato++;
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() > 0L && prezzo > 0.0D) {
|
||
|
|
af = new ArticoloFornitore(this.apFull);
|
||
|
|
af.findByFornitoreArticolo(2131L, art.getId_articolo(), -1L);
|
||
|
|
af.setId_articolo(art.getId_articolo());
|
||
|
|
af.setId_clifor(2131L);
|
||
|
|
af.setCostoVecchio(af.getCostoTotale());
|
||
|
|
af.setCosto(prezzo);
|
||
|
|
af.setDataUltimoPrezzo(DBAdapter.getToday());
|
||
|
|
af.setCodiceFornitore(l_articoloCodiceFornitore);
|
||
|
|
af.setStreetPrice(streetprice);
|
||
|
|
af.setDispSede(dispoL);
|
||
|
|
af.setFlgPromo(isPromo ? 1L : 0L);
|
||
|
|
rp = af.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
art.aggiornaCodiciAlternativi(false);
|
||
|
|
art.aggiornaPrezziEDispoByFornitori(streetprice, isNuovo);
|
||
|
|
if (art.getFlgModImportazione() == 2L) {
|
||
|
|
prezzoModificato++;
|
||
|
|
} else if (art.getFlgModImportazione() == 3L) {
|
||
|
|
prezzoNonModificato++;
|
||
|
|
}
|
||
|
|
if (art.getFlgEscludiWebArt() == 2L) {
|
||
|
|
articoloSospeso++;
|
||
|
|
} else if (art.getFlgEscludiWebArt() == 0L) {
|
||
|
|
articoloVisibile++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
System.out.println("marca scartata: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Large: Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE ESPRINET " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BESTIT ", sb.toString());
|
||
|
|
}
|
||
|
|
ArticoloCR CR = new ArticoloCR(this.apFull);
|
||
|
|
CR.setId_fornitore(2131L);
|
||
|
|
CR.setFlgModImportazione(0L);
|
||
|
|
Vectumerator<Articolo> vec = bean.findByCR(CR, 0, 0);
|
||
|
|
i = 0;
|
||
|
|
while (vec.hasMoreElements()) {
|
||
|
|
i++;
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BESTIT ", " ANAGRAFICA DISPO PREZZO aggiornamento articoli non trovati " + i + " su " +
|
||
|
|
vec.getTotNumberOfRecords());
|
||
|
|
Articolo row = (Articolo)vec.nextElement();
|
||
|
|
if (row.getId_fornitoreCostoNuovo() == 2131L) {
|
||
|
|
row.azzeraQuantita(2L);
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
String s_sql_sqring = "UPDATE ARTICOLO_FORNITORE SET dispSede=0, dispCash=0 where id_articolo=" + row.getId_articolo() + " and id_clifor=2131";
|
||
|
|
rp = row.update(s_sql_sqring);
|
||
|
|
rp.append(row.aggiornaPrezziEDispoByFornitori(0.0D, false));
|
||
|
|
}
|
||
|
|
if (SOSPENDI_DOPO_N_GG > 0L)
|
||
|
|
bean.update("UPDATE ARTICOLO SET flgEscludiWebArt=2,flgEscludiWeb=2 WHERE codice LIKE '" + serie + "%' and flgModImportazione = 0 and DATEDIFF(CURDATE(), dataUltimoImport)>=" + SOSPENDI_DOPO_N_GG + ";");
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! IMPORT BESTIT record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BESTIT ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import IMPORT BESTIT ANAGRAFICA DISPO PREZZO " + serie + " avvenuta correttamente. Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- art. nuovi: ");
|
||
|
|
sb.append(artNuovo);
|
||
|
|
sb.append("- art. nuovi NON SALVATI: ");
|
||
|
|
sb.append(artNuovoNonSalvato);
|
||
|
|
sb.append("- art. nuovi KO: ");
|
||
|
|
sb.append(artNuovoKO);
|
||
|
|
sb.append("- prezzi modificati: ");
|
||
|
|
sb.append(prezzoModificato);
|
||
|
|
sb.append("- prezzi NON modificati: ");
|
||
|
|
sb.append(prezzoNonModificato);
|
||
|
|
sb.append("- articoli sospesi: ");
|
||
|
|
sb.append(articoloSospeso);
|
||
|
|
sb.append("- articoli Visibili: ");
|
||
|
|
sb.append(articoloVisibile);
|
||
|
|
sb.append("- articoli in ordine: ");
|
||
|
|
sb.append(articoloInOrdine);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import IMPORT BESTIT ANAGRAFICA DISPO PREZZO " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm importDecrizioniImgCSV(String l_fileName) {
|
||
|
|
boolean debug = false;
|
||
|
|
boolean salvaArticolo = false;
|
||
|
|
boolean isNuovo = false;
|
||
|
|
String TAG_EXTRA = " ANAGRAFICA DISPO PREZZO";
|
||
|
|
String serie = "";
|
||
|
|
String l_lang = "it";
|
||
|
|
long costoLimiteRicarico = 500L;
|
||
|
|
long ricaricoSottoLimite = 6L, ricaricoSopraLimite = 7L;
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer err = new StringBuffer();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
int artAggiornati = 0, artEscluso = 0, artNonSalvato = 0, artDescrizioneAggiunta = 0, artImgSalvata = 0, recordErrati = 0;
|
||
|
|
long SOSPENDI_DOPO_N_GG = this.apFull.getParm("CC_SOSPENDI_DOPO_N_GG_NO_IMPORT").getNumeroLong();
|
||
|
|
String CVS_SEPARATOR = "|";
|
||
|
|
int colArticoloCodiceAlternativoFornitore = 2;
|
||
|
|
int colArticoloCodiceProduttore = 1;
|
||
|
|
int colArticoloCodiceEAN = 11;
|
||
|
|
int colArticoloDescrizione = 3;
|
||
|
|
int colArticoloMarca = 0;
|
||
|
|
int colArticoloCodiceCategoria = 4;
|
||
|
|
int colArticoloDescCategoria = 10;
|
||
|
|
int colArticoloDispo = 6;
|
||
|
|
int colPrezzo = 5;
|
||
|
|
int colPrezzoOfferta = 9;
|
||
|
|
int colStreetprice = -1;
|
||
|
|
int colLinkFoto = 12;
|
||
|
|
int colSchedaTecnica = 13;
|
||
|
|
BufferedReader reader = null;
|
||
|
|
Articolo bean = new Articolo(this.apFull);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BESTIT ", ": Aggiornamento stato a non trovato su tutti gli articoli con fornitore dato");
|
||
|
|
bean.updateModimportazioneByFornitore(0L, 2131L);
|
||
|
|
String currentLine = "";
|
||
|
|
try {
|
||
|
|
Marca marca = new Marca(this.apFull);
|
||
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
||
|
|
if (reader != null) {
|
||
|
|
reader.readLine();
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
String l_descrizioneTecnica = "";
|
||
|
|
boolean isPromo = false;
|
||
|
|
Articolo art = new Articolo(this.apFull);
|
||
|
|
ArticoloFornitore af = new ArticoloFornitore(this.apFull);
|
||
|
|
while ((currentLine = reader.readLine()) != null) {
|
||
|
|
isNuovo = false;
|
||
|
|
isPromo = false;
|
||
|
|
StringTokenizer st = new StringTokenizer(currentLine, CVS_SEPARATOR, '"');
|
||
|
|
if (st.countToken() >= 6) {
|
||
|
|
String l_marcaDesc = st.getToken(colArticoloMarca);
|
||
|
|
marca.findByDescrizioneImport(l_marcaDesc);
|
||
|
|
if (marca.getId_marca() > 0L) {
|
||
|
|
String l_nome = st.getToken(colArticoloDescrizione).trim();
|
||
|
|
l_descrizioneTecnica = st.getToken(colSchedaTecnica);
|
||
|
|
String l_linkImmagine = st.getToken(colLinkFoto);
|
||
|
|
String l_articoloCodiceFornitore = st.getToken(colArticoloCodiceAlternativoFornitore).trim();
|
||
|
|
String l_articoloCodiceAlternativoFornitore = "BI_" + l_articoloCodiceFornitore;
|
||
|
|
String l_articoloCodiceProduttore = st.getToken(colArticoloCodiceProduttore).trim();
|
||
|
|
String l_codiceEan = st.getToken(colArticoloCodiceEAN).trim();
|
||
|
|
if (l_codiceEan.length() < 13)
|
||
|
|
l_codiceEan = DBAdapter.zeroLeft(l_codiceEan, 13);
|
||
|
|
if (l_codiceEan.equals("0000000000000") || l_codiceEan.indexOf("99999999") >= 0)
|
||
|
|
l_codiceEan = "";
|
||
|
|
art.resetBean();
|
||
|
|
if (art.getId_articolo() == 0L) {
|
||
|
|
af.findByCodiceFornitore(2131L, l_articoloCodiceFornitore);
|
||
|
|
if (af.getId_articolo() > 0L)
|
||
|
|
art = af.getArticolo();
|
||
|
|
}
|
||
|
|
if (art.getId_articolo() == 0L && !l_codiceEan.isEmpty())
|
||
|
|
art.findByCodiceEanSerie(l_codiceEan, serie);
|
||
|
|
if (art.getId_articolo() == 0L && !l_articoloCodiceProduttore.isEmpty())
|
||
|
|
art.findByCodiceProduttoreMarca(l_articoloCodiceProduttore, marca.getId_marca());
|
||
|
|
if (st.countToken() > 7);
|
||
|
|
if (art.getId_articolo() > 0L) {
|
||
|
|
System.out.print("*");
|
||
|
|
if (!l_linkImmagine.isEmpty())
|
||
|
|
if (!art.isImgExist(1)) {
|
||
|
|
salvaArticolo = true;
|
||
|
|
l_linkImmagine = l_linkImmagine.replace("http:", "https:");
|
||
|
|
art.caricaImmaginaDaRemoto(l_linkImmagine, 1L);
|
||
|
|
artImgSalvata++;
|
||
|
|
}
|
||
|
|
if (l_descrizioneTecnica != null &&
|
||
|
|
art.getDescrizioneCommerciale(l_lang).isEmpty() && !l_descrizioneTecnica.isEmpty()) {
|
||
|
|
art.setDescTxtLang("descrizioneCommerciale", l_lang, l_descrizioneTecnica);
|
||
|
|
if (art.getDescrizioneBreve(l_lang).isEmpty())
|
||
|
|
art.setDescTxtLang("descrizioneBreve", l_lang, art.getNome());
|
||
|
|
salvaArticolo = true;
|
||
|
|
artDescrizioneAggiunta++;
|
||
|
|
}
|
||
|
|
if (salvaArticolo) {
|
||
|
|
art.setFlgTipoSchedaArticoloWww(3L);
|
||
|
|
rp = art.save();
|
||
|
|
if (!rp.getStatus())
|
||
|
|
artNonSalvato++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
artEscluso++;
|
||
|
|
System.out.println("marca scartata: " + l_marcaDesc);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
err.append("Pochi campi: " + i + " - " + currentLine);
|
||
|
|
recordErrati++;
|
||
|
|
}
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
sb = new StringBuilder(" Large: Record processati: ");
|
||
|
|
if (debug)
|
||
|
|
sb.append("ATTENZIONE!!!! DEBUG ATTIVO. FILE ESPRINET " + serie + " SICURAMENTE NON AGGIORNATO.");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. desc aggiunta: ");
|
||
|
|
sb.append(artDescrizioneAggiunta);
|
||
|
|
sb.append("- art. img salvata: ");
|
||
|
|
sb.append(artImgSalvata);
|
||
|
|
sb.append("- art. non salvati: ");
|
||
|
|
sb.append(artNonSalvato);
|
||
|
|
sb.append("- art. non trovati: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BESTIT ", sb.toString());
|
||
|
|
}
|
||
|
|
if (SOSPENDI_DOPO_N_GG > 0L)
|
||
|
|
bean.update("UPDATE ARTICOLO SET flgEscludiWebArt=2,flgEscludiWeb=2 WHERE codice LIKE '" + serie + "%' and flgModImportazione = 0 and DATEDIFF(CURDATE(), dataUltimoImport)>=" + SOSPENDI_DOPO_N_GG + ";");
|
||
|
|
}
|
||
|
|
} catch (Exception exception) {
|
||
|
|
CCImport.this.handleDebug(exception);
|
||
|
|
exception.printStackTrace();
|
||
|
|
System.out.println("ERRORE!!!! IMPORT BESTIT record: " + i + "\n" + currentLine);
|
||
|
|
StatusMsg.updateMsgByTag(this.apFull, "IMPORT BESTIT ", "ERRORE + " + exception.getMessage() + "<br>" + currentLine);
|
||
|
|
} finally {
|
||
|
|
try {
|
||
|
|
reader.close();
|
||
|
|
} catch (Exception e) {
|
||
|
|
CCImport.this.handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
System.out.println(err.toString());
|
||
|
|
if (err.length() == 0) {
|
||
|
|
sb = new StringBuilder("Import IMPORT BESTIT ANAGRAFICA DISPO PREZZO " + serie + " avvenuta correttamente. Record processati: ");
|
||
|
|
sb.append(i);
|
||
|
|
sb.append("- art. desc aggiunta: ");
|
||
|
|
sb.append(artDescrizioneAggiunta);
|
||
|
|
sb.append("- art. img salvata: ");
|
||
|
|
sb.append(artImgSalvata);
|
||
|
|
sb.append("- art. non salvati: ");
|
||
|
|
sb.append(artNonSalvato);
|
||
|
|
sb.append("- art. esclusi: ");
|
||
|
|
sb.append(artEscluso);
|
||
|
|
sb.append("- art. aggiornati: ");
|
||
|
|
sb.append(artAggiornati);
|
||
|
|
sb.append("- record errati: ");
|
||
|
|
sb.append(recordErrati);
|
||
|
|
sb.append(" - ");
|
||
|
|
sb.append(err.toString());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg(sb.toString());
|
||
|
|
} else {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("ERRORE! Import IMPORT BESTIT ANAGRAFICA DISPO PREZZO " + serie + " avvenuta con errori. Articoli processati: " + i + " - " +
|
||
|
|
err.toString());
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public static boolean isThreadCgrossAttivo() {
|
||
|
|
return threadImportCGross;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static boolean isThreadRunnerAttivo() {
|
||
|
|
return threadImportRunner;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static boolean isThreadGoogleMerchant() {
|
||
|
|
return threadGoogleMerchant;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static boolean isThreadTrovaprezzi() {
|
||
|
|
return threadTrovaprezzi;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static boolean isThreadDatamaticAttivo() {
|
||
|
|
return threadImportDatamatic;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static boolean isThreadEsprinetAttivo() {
|
||
|
|
return threadImportEsprinet;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static boolean isThreadImportBreviAttivo() {
|
||
|
|
return threadImportBrevi;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static boolean isThreadFlexitAttivo() {
|
||
|
|
return threadImportFlexit;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static boolean isThreadIngramMicroAttivo() {
|
||
|
|
return threadImportIngramMicro;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static boolean isThreadLogicomAttivo() {
|
||
|
|
return threadImportLocicom;
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm startImportCgross(ApplParmFull apFull, String fileZip, boolean sendEmail) {
|
||
|
|
boolean test = false;
|
||
|
|
if (test) {
|
||
|
|
System.out.println("startImportCgross...testtttttt");
|
||
|
|
return sendArticoliCambiatiByEmail(apFull, "test", 1970L);
|
||
|
|
}
|
||
|
|
if (!isThreadCgrossAttivo()) {
|
||
|
|
new ThreadImportComputerGross(apFull, fileZip, sendEmail);
|
||
|
|
return new ResParm(true, "Thread Import CGROSS avviato");
|
||
|
|
}
|
||
|
|
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm startImportDatamatic(ApplParmFull apFull, String fileXls, boolean sendEmail) {
|
||
|
|
if (!isThreadDatamaticAttivo()) {
|
||
|
|
new ThreadImportDatamatic(apFull, fileXls, sendEmail);
|
||
|
|
return new ResParm(true, "Thread Import DATAMATIC avviato");
|
||
|
|
}
|
||
|
|
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm startImportEsprinet(ApplParmFull apFull, String fileXls, boolean sendEmail) {
|
||
|
|
if (!isThreadEsprinetAttivo()) {
|
||
|
|
new ThreadImportEsprinet(apFull, fileXls, sendEmail);
|
||
|
|
return new ResParm(true, "Thread Import ESPRINET avviato");
|
||
|
|
}
|
||
|
|
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm sendArticoliCambiatiByEmail(ApplParmFull apFull, String msg, long l_id_fornitore) {
|
||
|
|
ResParm rp = new ResParm();
|
||
|
|
String TDAP = "<td>";
|
||
|
|
String TDAP_CENTER = "<td style=\"text-align: center\">";
|
||
|
|
String TDCH = "</td>";
|
||
|
|
String fileName = apFull.getParm("DOCBASE").getTesto() + "admin/art/_mailMessage/articoliModificati.html";
|
||
|
|
MailMessage mm = new MailMessage(apFull, fileName);
|
||
|
|
NumberFormat nf = apFull.getNf();
|
||
|
|
Articolo articolo = new Articolo(apFull);
|
||
|
|
ArticoloCR CR = new ArticoloCR();
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
mm.setDate("data", DBAdapter.getToday());
|
||
|
|
mm.setString("risultato", msg);
|
||
|
|
String oggettoMessaggio = "Import automatico ";
|
||
|
|
if (l_id_fornitore == 0L) {
|
||
|
|
mm.setString("fornitore", "Non impostato");
|
||
|
|
oggettoMessaggio = oggettoMessaggio + " fornitore non impostato";
|
||
|
|
} else {
|
||
|
|
Clifor fornitore = new Clifor(apFull);
|
||
|
|
fornitore.findByPrimaryKey(l_id_fornitore);
|
||
|
|
if (fornitore.getId_clifor() == 0L) {
|
||
|
|
mm.setString("fornitore", "Attenzione! codice fornitore " + l_id_fornitore + " NON TROVATO");
|
||
|
|
oggettoMessaggio = oggettoMessaggio + " fornitore " + oggettoMessaggio + " NON TROVATO";
|
||
|
|
} else {
|
||
|
|
mm.setString("fornitore", fornitore.getCognome());
|
||
|
|
oggettoMessaggio = oggettoMessaggio + " fornitore " + oggettoMessaggio;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
CR.setFlgModImportazione(2L);
|
||
|
|
CR.setFlgEscludiWeb(0L);
|
||
|
|
CR.setId_fornitore(l_id_fornitore);
|
||
|
|
Vectumerator<Articolo> vec = articolo.findByCR(CR, 0, 0);
|
||
|
|
while (vec.hasMoreElements()) {
|
||
|
|
Articolo row = (Articolo)vec.nextElement();
|
||
|
|
sb.append("<tr>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(row.getCodice());
|
||
|
|
sb.append("<br><a target='_blank' href='");
|
||
|
|
sb.append(row.getCCLinkAdmin());
|
||
|
|
sb.append("'>");
|
||
|
|
sb.append(row.getCodice());
|
||
|
|
sb.append("</a>");
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td style=\"text-align: center\">");
|
||
|
|
if (row.getFlgSubito() == 1L) {
|
||
|
|
sb.append("V");
|
||
|
|
} else {
|
||
|
|
sb.append(" ");
|
||
|
|
}
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td style=\"text-align: center\">");
|
||
|
|
if (row.getFlgEbay() == 1L) {
|
||
|
|
sb.append("V");
|
||
|
|
} else {
|
||
|
|
sb.append(" ");
|
||
|
|
}
|
||
|
|
if (!row.getEbayOfferId().isEmpty())
|
||
|
|
sb.append(" - " + row.getEbayOfferId());
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td style=\"text-align: center\">");
|
||
|
|
if (row.getFlgGoogle() == 1L) {
|
||
|
|
sb.append("V");
|
||
|
|
if (!row.getGoogleFeedFileName().isEmpty()) {
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(row.getGoogleFeedFileName());
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
sb.append(" ");
|
||
|
|
}
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(row.getCodiciAlternativiLink());
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(row.getCodiceEan());
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(row.getMarca().getDescrizione() + " " + row.getMarca().getDescrizione() + " - " + row.getTipo().getDescrizioneCompleta());
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getCostoPrecedente()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getCostoNetto()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getPercRicarico()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getImponibilePrecedenteIva()));
|
||
|
|
sb.append("</td>");
|
||
|
|
if (row.isPrezzoVenditaSalito()) {
|
||
|
|
sb.append("<td style='font-weight: bold;color:darkred'>+");
|
||
|
|
} else if (row.isPrezzoVenditaSceso()) {
|
||
|
|
sb.append("<td style='font-weight: bold;color:darkgreen'>-");
|
||
|
|
} else {
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append("=");
|
||
|
|
}
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getPrezzoPubblicoIva()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getStreetPriceIva()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getRicaricoEffettivoDaCostoNetto()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getQuantita()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(row.getEscludiWeb());
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("</tr>");
|
||
|
|
sb.append("\n");
|
||
|
|
}
|
||
|
|
sb.append("</table>");
|
||
|
|
mm.setString("listaArticoli", sb.toString());
|
||
|
|
CR.setFlgModImportazione(1L);
|
||
|
|
CR.setFlgEscludiWeb(-1L);
|
||
|
|
CR.setId_fornitore(l_id_fornitore);
|
||
|
|
vec = articolo.findByCR(CR, 0, 0);
|
||
|
|
sb = new StringBuilder();
|
||
|
|
while (vec.hasMoreElements()) {
|
||
|
|
Articolo row = (Articolo)vec.nextElement();
|
||
|
|
sb.append("<tr>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(row.getCodice());
|
||
|
|
sb.append("<br><a target='_blank' href='");
|
||
|
|
sb.append(row.getParm("P_WWW_ADDRESS").getTesto());
|
||
|
|
sb.append("Redir.abl?_svlt=/admin/art/Articolo.abl&_parms=@cmd:search@codice:");
|
||
|
|
sb.append(row.getCodice());
|
||
|
|
sb.append("'>");
|
||
|
|
sb.append(row.getCodice());
|
||
|
|
sb.append("</a>");
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td style=\"text-align: center\">");
|
||
|
|
if (row.getFlgSubito() == 1L) {
|
||
|
|
sb.append("V");
|
||
|
|
} else {
|
||
|
|
sb.append(" ");
|
||
|
|
}
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td style=\"text-align: center\">");
|
||
|
|
if (row.getFlgEbay() == 1L) {
|
||
|
|
sb.append("V");
|
||
|
|
} else {
|
||
|
|
sb.append(" ");
|
||
|
|
}
|
||
|
|
if (!row.getEbayOfferId().isEmpty())
|
||
|
|
sb.append(" - " + row.getEbayOfferId());
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td style=\"text-align: center\">");
|
||
|
|
if (row.getFlgGoogle() == 1L) {
|
||
|
|
sb.append("V");
|
||
|
|
if (!row.getGoogleFeedFileName().isEmpty()) {
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(row.getGoogleFeedFileName());
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
sb.append(" ");
|
||
|
|
}
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(row.getCodiciAlternativiLink());
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(row.getCodiceEan());
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(row.getMarca().getDescrizione() + " " + row.getMarca().getDescrizione() + " - " + row.getTipo().getDescrizioneCompleta() + " (" +
|
||
|
|
row.getNome().substring(0, Math.min(row.getNome().length(), 50)) + ")");
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getCostoPrecedente()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getCostoNetto()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getPercRicarico()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getImponibilePrecedenteIva()));
|
||
|
|
sb.append("</td>");
|
||
|
|
if (row.isPrezzoVenditaSalito()) {
|
||
|
|
sb.append("<td style='font-weight: bold;color:darkred'>+");
|
||
|
|
} else if (row.isPrezzoVenditaSceso()) {
|
||
|
|
sb.append("<td style='font-weight: bold;color:darkgreen'>-");
|
||
|
|
} else {
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append("=");
|
||
|
|
}
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getPrezzoPubblicoIva()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getStreetPriceIva()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getRicaricoEffettivoDaCostoNetto()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getQuantita()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(row.getEscludiWeb());
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("</tr>");
|
||
|
|
sb.append("\n");
|
||
|
|
}
|
||
|
|
sb.append("</table>");
|
||
|
|
mm.setString("listaArticoliNuovi", sb.toString());
|
||
|
|
CR.setFlgModImportazione(0L);
|
||
|
|
CR.setFlgEscludiWeb(0L);
|
||
|
|
CR.setId_fornitore(l_id_fornitore);
|
||
|
|
vec = articolo.findByCR(CR, 0, 0);
|
||
|
|
sb = new StringBuilder();
|
||
|
|
while (vec.hasMoreElements()) {
|
||
|
|
Articolo row = (Articolo)vec.nextElement();
|
||
|
|
sb.append("<tr>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(row.getCodice());
|
||
|
|
sb.append("<br><a target='_blank' href='");
|
||
|
|
sb.append(row.getCCLinkAdmin());
|
||
|
|
sb.append("'>");
|
||
|
|
sb.append(row.getCodice());
|
||
|
|
sb.append("</a>");
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td style=\"text-align: center\">");
|
||
|
|
if (row.getFlgSubito() == 1L) {
|
||
|
|
sb.append("V");
|
||
|
|
} else {
|
||
|
|
sb.append(" ");
|
||
|
|
}
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td style=\"text-align: center\">");
|
||
|
|
if (row.getFlgEbay() == 1L) {
|
||
|
|
sb.append("V");
|
||
|
|
} else {
|
||
|
|
sb.append(" ");
|
||
|
|
}
|
||
|
|
if (!row.getEbayOfferId().isEmpty())
|
||
|
|
sb.append(" - " + row.getEbayOfferId());
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td style=\"text-align: center\">");
|
||
|
|
if (row.getFlgGoogle() == 1L) {
|
||
|
|
sb.append("V");
|
||
|
|
if (!row.getGoogleFeedFileName().isEmpty()) {
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(row.getGoogleFeedFileName());
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
sb.append(" ");
|
||
|
|
}
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(row.getCodiciAlternativiLink());
|
||
|
|
sb.append(" ");
|
||
|
|
sb.append(row.getCodiceEan());
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(row.getMarca().getDescrizione() + " " + row.getMarca().getDescrizione() + " - " + row.getTipo().getDescrizioneCompleta());
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getCostoPrecedente()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getCostoNetto()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getPercRicarico()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getImponibilePrecedenteIva()));
|
||
|
|
sb.append("</td>");
|
||
|
|
if (row.isPrezzoVenditaSalito()) {
|
||
|
|
sb.append("<td style='font-weight: bold;color:darkred'>+");
|
||
|
|
} else if (row.isPrezzoVenditaSceso()) {
|
||
|
|
sb.append("<td style='font-weight: bold;color:darkgreen'>-");
|
||
|
|
} else {
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append("=");
|
||
|
|
}
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getPrezzoPubblicoIva()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getStreetPriceIva()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getRicaricoEffettivoDaCostoNetto()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(nf.format(row.getQuantita()));
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("<td>");
|
||
|
|
sb.append(row.getEscludiWeb());
|
||
|
|
sb.append(" (");
|
||
|
|
sb.append(row.getCountImportNonTrovato());
|
||
|
|
sb.append(")");
|
||
|
|
sb.append("</td>");
|
||
|
|
sb.append("</tr>");
|
||
|
|
sb.append("\n");
|
||
|
|
}
|
||
|
|
sb.append("</table>");
|
||
|
|
mm.setString("listaArticoliNonTrovati", sb.toString());
|
||
|
|
String from = apFull.getParm("FROM").getTesto();
|
||
|
|
MailProperties mp = new MailProperties();
|
||
|
|
mp.setProperty("FROM", from);
|
||
|
|
mp.setProperty("TO", from);
|
||
|
|
mp.setProperty("SUBJECT", oggettoMessaggio);
|
||
|
|
System.out.println("sendArticoliCambiatiByEmail: from: " + from + " to " + from + " oggetto: " + oggettoMessaggio);
|
||
|
|
rp = mm.sendMailMessage(mp, true);
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm crontabJob(ApplParmFull ap) {
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
StringBuffer msg = new StringBuffer("\n################# Inizio crontab Giornaliera CC (" +
|
||
|
|
DBAdapter.getNow().toString() + ")\n#################");
|
||
|
|
long t0 = System.currentTimeMillis();
|
||
|
|
rp = startImportCgross(ap, null, true);
|
||
|
|
msg.append(rp.getMsg());
|
||
|
|
msg.append("\n################# Fine crontab Giornaliera CC (" + DBAdapter.getNow().toString() + ")\n#################");
|
||
|
|
long tn = System.currentTimeMillis();
|
||
|
|
long duration = (tn - t0) / 60000L;
|
||
|
|
msg.append("Durata aggiornamento: " + duration + " minuti.\n");
|
||
|
|
rp.setMsg(msg.toString());
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm startGoogleFtp(ApplParmFull apFull, ArticoloCR CR) {
|
||
|
|
if (!isThreadGoogleMerchant()) {
|
||
|
|
new ThreadGoogleFtp(apFull, CR);
|
||
|
|
return new ResParm(true, "Thread GOOGLE FTP avviato");
|
||
|
|
}
|
||
|
|
return new ResParm(false, "ATTENZIONE!! Thread GOOGLE FTP in esecuzione!!!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm startTrovaprezziXml(ApplParmFull apFull, ArticoloCR CR) {
|
||
|
|
if (!isThreadTrovaprezzi()) {
|
||
|
|
new ThreadTrovaprezziXml(apFull, CR);
|
||
|
|
return new ResParm(true, "Thread TROVAPREZZI avviato");
|
||
|
|
}
|
||
|
|
return new ResParm(false, "ATTENZIONE!! Thread TROVAPREZZI in esecuzione!!!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm startImportLogicomMail(ApplParmFull apFull, boolean sendEmail) {
|
||
|
|
if (!isThreadLogicomAttivo()) {
|
||
|
|
new ThreadCheckMailLogicom(apFull, sendEmail);
|
||
|
|
return new ResParm(true, "Thread Import LOGICOM MAIL avviato");
|
||
|
|
}
|
||
|
|
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm startImportIngramMicro(ApplParmFull apFull, long l_tipoImport, boolean sendEmail) {
|
||
|
|
boolean test = false;
|
||
|
|
if (test) {
|
||
|
|
System.out.println("startImportIngramMigro TEST");
|
||
|
|
return sendArticoliCambiatiByEmail(apFull, "test", 1995L);
|
||
|
|
}
|
||
|
|
if (!isThreadIngramMicroAttivo()) {
|
||
|
|
new ThreadImportIngramMicro(apFull, l_tipoImport, sendEmail);
|
||
|
|
return new ResParm(true, "Thread Import INGRAMMICRO+" + l_tipoImport + " avviato");
|
||
|
|
}
|
||
|
|
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm startImportLogicom(ApplParmFull apFull, String fileXls, boolean sendEmail) {
|
||
|
|
if (!isThreadLogicomAttivo()) {
|
||
|
|
new ThreadImportLogicom(apFull, fileXls, sendEmail);
|
||
|
|
return new ResParm(true, "Thread Import LOGICOM avviato");
|
||
|
|
}
|
||
|
|
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm startImportDatamaticMail(ApplParmFull apFull, boolean sendEmail) {
|
||
|
|
if (!isThreadDatamaticAttivo()) {
|
||
|
|
new ThreadImportDatamatic(apFull, sendEmail);
|
||
|
|
return new ResParm(true, "Thread Import DATAMATIC MAIL avviato");
|
||
|
|
}
|
||
|
|
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm startImportFlexit(ApplParmFull apFull, String fileXls, boolean sendEmail) {
|
||
|
|
if (!isThreadFlexitAttivo()) {
|
||
|
|
new ThreadImportFlexit(apFull, fileXls, sendEmail);
|
||
|
|
return new ResParm(true, "Thread Import FLEXIT avviato");
|
||
|
|
}
|
||
|
|
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm startImportFlexitMail(ApplParmFull apFull, boolean sendEmail) {
|
||
|
|
if (!isThreadFlexitAttivo()) {
|
||
|
|
new ThreadCheckMailFlexit(apFull, sendEmail);
|
||
|
|
return new ResParm(true, "Thread Import FLEXIT MAIL avviato");
|
||
|
|
}
|
||
|
|
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm startImportBrevi(ApplParmFull apFull, String fileXls, boolean sendEmail) {
|
||
|
|
if (!isThreadImportBreviAttivo()) {
|
||
|
|
new ThreadImportBrevi(apFull, fileXls, sendEmail);
|
||
|
|
return new ResParm(true, "Thread Import BREVI avviato");
|
||
|
|
}
|
||
|
|
return new ResParm(false, "ATTENZIONE!! Thread IMPORT BREVI in esecuzione!!!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm startImportRunner(ApplParmFull apFull, long[] flgTipoImportA, boolean sendEmail) {
|
||
|
|
if (!isThreadRunnerAttivo()) {
|
||
|
|
new ThreadImportRunner(apFull, flgTipoImportA, sendEmail);
|
||
|
|
return new ResParm(true, "Thread Import RUNNER avviato");
|
||
|
|
}
|
||
|
|
return new ResParm(false, "ATTENZIONE!! Thread IMPORT RUNNER in esecuzione!!!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public Attivita getAttivita(ApplParmFull apFull) {
|
||
|
|
if (this.attivita == null)
|
||
|
|
this.attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
return this.attivita;
|
||
|
|
}
|
||
|
|
|
||
|
|
public final ResParm startImportBestit(ApplParmFull apFull, long[] flgTipoImportA, boolean sendEmail) {
|
||
|
|
if (!isThreadBestitAttivo()) {
|
||
|
|
new ThreadImportBestIt(apFull, flgTipoImportA, sendEmail);
|
||
|
|
return new ResParm(true, "Thread Import BESTIT avviato");
|
||
|
|
}
|
||
|
|
return new ResParm(false, "ATTENZIONE!! Thread IMPORT BESTIT in esecuzione!!!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public static boolean isThreadBestitAttivo() {
|
||
|
|
return threadImportBestit;
|
||
|
|
}
|
||
|
|
}
|