115 lines
4.9 KiB
Java
115 lines
4.9 KiB
Java
import com.ablia.anag.ListinoArticolo;
|
|
import com.ablia.art.Articolo;
|
|
import com.ablia.art.ArticoloVariante;
|
|
import com.ablia.db.ApplParm;
|
|
import com.ablia.db.ApplParmFull;
|
|
import com.ablia.db.ResParm;
|
|
import com.ablia.util.DbConsole;
|
|
import com.ablia.util.StringTokenizer;
|
|
import java.io.BufferedReader;
|
|
import java.io.FileReader;
|
|
|
|
public class ImportArticoliPresta extends DbConsole {
|
|
public static void main(String[] args) {
|
|
ImportArticoliXls bean = new ImportArticoliXls();
|
|
bean.doImport();
|
|
System.exit(0);
|
|
}
|
|
|
|
public void doImport() {
|
|
int i = 0;
|
|
int se1 = 10;
|
|
int se2 = 100;
|
|
String hostname = "localhost";
|
|
String db = "ravinale";
|
|
String fileCsv = "/Users/acolzi/Documents/_ablia/work/ravinale/www/admin/_alterTable/elencoArticoliPresta.csv";
|
|
boolean importArticoli = false;
|
|
String temp = "";
|
|
temp = getCi().readLine("importArticoli(" + importArticoli + "):");
|
|
if (!temp.isEmpty())
|
|
importArticoli = temp.equals("y");
|
|
ApplParmFull ap = new ApplParmFull(new ApplParm(3, "//" + hostname + "/" + db, "root", "root", 1, 10, 300));
|
|
ap.setDebug(false);
|
|
StringBuffer msg = new StringBuffer();
|
|
try {
|
|
int numBanche = 0, numClienti = 0;
|
|
if (importArticoli) {
|
|
i = 0;
|
|
System.out.println("\nimportArticoli");
|
|
Articolo articolo = new Articolo(ap);
|
|
BufferedReader reader = new BufferedReader(new FileReader(fileCsv));
|
|
if (reader != null) {
|
|
int numbToken = 0;
|
|
int colname = 2, colNomeArticolo = 3, colid_tipo = 8, colprice = 9, colreference = 12, coldescription_short = 14;
|
|
int coldescription = 15, colmeta_title = 16, colmeta_description = 18;
|
|
StringBuffer currentArticolo = new StringBuffer();
|
|
reader.readLine();
|
|
reader.readLine();
|
|
String currentLine;
|
|
while ((currentLine = reader.readLine()) != null) {
|
|
StringTokenizer st = new StringTokenizer(currentLine, ";");
|
|
String name = st.getToken(colname);
|
|
String nomeArticolo = st.getToken(colNomeArticolo);
|
|
String nomeVariante = name.replace(nomeArticolo, "");
|
|
String id_tipo = st.getToken(colid_tipo);
|
|
String price = st.getToken(colprice);
|
|
String reference = st.getToken(colreference);
|
|
String description_short = st.getToken(coldescription_short);
|
|
String description = st.getToken(coldescription);
|
|
String meta_title = st.getToken(colmeta_title);
|
|
String meta_description = st.getToken(colmeta_description);
|
|
if (reference.isEmpty())
|
|
continue;
|
|
String codiceArticolo = reference.substring(0, 6);
|
|
String codiceVariante = reference.substring(6);
|
|
articolo = new Articolo(ap);
|
|
articolo.findArticoloByCodice(codiceArticolo);
|
|
if (articolo.getDBState() == 0) {
|
|
articolo.setCodice(codiceArticolo);
|
|
if (nomeArticolo.isEmpty()) {
|
|
articolo.setNome(name);
|
|
} else {
|
|
articolo.setNome(nomeArticolo);
|
|
}
|
|
articolo.setId_tipo(Long.valueOf(id_tipo).longValue());
|
|
articolo.setMetaTag(meta_title);
|
|
articolo.setMetaDesc(meta_description);
|
|
articolo.setId_iva(1L);
|
|
articolo.setDescTxtLang("descrizione", "it", description);
|
|
articolo.setDescTxtLang("descrizioneCommerciale", "it", description_short);
|
|
ResParm rp = articolo.save();
|
|
if (rp.getStatus()) {
|
|
ListinoArticolo listinoArticoloBase = articolo.getListinoArticoloBase();
|
|
listinoArticoloBase.setId_articolo(articolo.getId_articolo());
|
|
listinoArticoloBase.setId_listino(articolo.getListinoBase().getId_listino());
|
|
listinoArticoloBase.setPrezzoConIvaLA(Double.parseDouble(price));
|
|
rp = listinoArticoloBase.save();
|
|
}
|
|
}
|
|
ArticoloVariante av = new ArticoloVariante(ap);
|
|
av.findArticoloVarianteByCodiceVariante(reference);
|
|
if (av.getDBState() == 0) {
|
|
av.setId_articolo(articolo.getId_articolo());
|
|
av.setCodiceVariante(reference);
|
|
av.setNomeV(nomeVariante);
|
|
av.setDescTxtLang("descrizioneV", "it", description_short);
|
|
ResParm rp = av.save();
|
|
if (rp.getStatus()) {
|
|
av.setDescTxtLang("descrizione", "it", description);
|
|
av.setDescTxtLang("descrizioneCommerciale", "it", description_short);
|
|
}
|
|
}
|
|
i++;
|
|
if (se1 > 0 && i % se1 == 0)
|
|
System.out.print(".");
|
|
if (se2 > 0 && i % se2 == 0)
|
|
System.out.println(String.valueOf(i) + " / ");
|
|
}
|
|
}
|
|
System.out.println("fine ciclo \n\n\n\n\n\n\n\n\n\n\n" + msg.toString());
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|