108 lines
4 KiB
Java
108 lines
4 KiB
Java
import it.acxent.art.Articolo;
|
|
import it.acxent.art.ArticoloCR;
|
|
import it.acxent.art.ArticoloUsato;
|
|
import it.acxent.db.ApplParm;
|
|
import it.acxent.db.ApplParmFull;
|
|
import it.acxent.util.DbConsole;
|
|
import it.acxent.util.Vectumerator;
|
|
import java.sql.Time;
|
|
import java.util.StringTokenizer;
|
|
|
|
public class AggiustaArticoloUsato extends DbConsole {
|
|
public static void main(String[] args) {
|
|
AggiustaArticoloUsato bean = new AggiustaArticoloUsato();
|
|
bean.doImport();
|
|
System.exit(0);
|
|
}
|
|
|
|
public void doImport() {
|
|
String db = "tf19";
|
|
int i = 0;
|
|
int se1 = 10;
|
|
int se2 = 100;
|
|
String hostname = "localhost";
|
|
String temp = getCi().readLine("Hostname (" + hostname + "):");
|
|
if (!temp.isEmpty())
|
|
hostname = temp;
|
|
temp = getCi().readLine("Database name (" + db + "):");
|
|
if (!temp.isEmpty())
|
|
db = temp;
|
|
System.out.println("Db: " + db);
|
|
ApplParmFull apTarget = new ApplParmFull(new ApplParm(3, "//" + hostname + "/" + db, "root", "root", 1, 10, 300));
|
|
apTarget.setDebug(false);
|
|
StringBuffer msg = new StringBuffer();
|
|
try {
|
|
Articolo bean = new Articolo(apTarget);
|
|
System.out.println("ciclo articoli");
|
|
ArticoloCR CR = new ArticoloCR();
|
|
CR.setFlgOrderBy(1L);
|
|
CR.setFlgUsato(99L);
|
|
CR.setFlgEscludiWeb(-1L);
|
|
long currentidAU = 0L;
|
|
Vectumerator<Articolo> vec = bean.findByCR(CR, 0, 0);
|
|
ArticoloUsato au = new ArticoloUsato(apTarget);
|
|
System.out.println("Tot Record: " + vec.getTotNumberOfRecords());
|
|
boolean daInvertire = false;
|
|
while (vec.hasMoreElements()) {
|
|
Articolo row = (Articolo)vec.nextElement();
|
|
Vectumerator<ArticoloUsato> vecAU = au.findByArticoloOrdineManuale(row.getId_articolo());
|
|
currentidAU = 0L;
|
|
daInvertire = false;
|
|
while (vecAU.hasMoreElements()) {
|
|
ArticoloUsato rowAU = (ArticoloUsato)vecAU.nextElement();
|
|
if (rowAU.getId_articoloUsato() > currentidAU) {
|
|
currentidAU = rowAU.getId_articoloUsato();
|
|
continue;
|
|
}
|
|
System.out.println("DA INVERTIRE articolo: " + row.getId_articolo() + " " + row.getCodice());
|
|
daInvertire = true;
|
|
break;
|
|
}
|
|
if (daInvertire) {
|
|
vecAU.moveFirst();
|
|
while (vecAU.hasMoreElements()) {
|
|
ArticoloUsato rowAU2 = (ArticoloUsato)vecAU.nextElement();
|
|
ArticoloUsato rowNew = new ArticoloUsato(apTarget);
|
|
rowNew.findByPrimaryKey(rowAU2.getId_articoloUsato());
|
|
rowNew.setDBState(0);
|
|
rowNew.setId_articoloUsato(0L);
|
|
rowNew.save();
|
|
rowAU2.delete();
|
|
}
|
|
}
|
|
i++;
|
|
if (se1 > 0 && i % se1 == 0)
|
|
System.out.print(".");
|
|
if (se2 > 0 && i % se2 == 0)
|
|
System.out.println("" + i + " / " + i);
|
|
}
|
|
System.out.println("fine ciclo \n" + msg.toString());
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
protected Time getTimeFromString(String theTime) {
|
|
try {
|
|
if (theTime.matches("[0-9][0-9][0-9][0-9]"))
|
|
theTime = theTime.substring(0, 2) + ":" + theTime.substring(0, 2);
|
|
if (theTime.matches("[0-9]{1,2}+:[0-9]{1,2}+")) {
|
|
StringTokenizer st = new StringTokenizer(theTime, ":");
|
|
int hour = Integer.parseInt(st.nextToken());
|
|
int min = Integer.parseInt(st.nextToken());
|
|
int sec = st.hasMoreElements() ? Integer.parseInt(st.nextToken()) : 0;
|
|
return new Time((long)((hour - 1) * 3600000 + min * 60000 + sec * 1000));
|
|
}
|
|
if (theTime.matches("[0-9]{1,2}+:[0-9]{1,2}+:[0-9]{1,2}+")) {
|
|
StringTokenizer st = new StringTokenizer(theTime, ":");
|
|
int hour = Integer.parseInt(st.nextToken());
|
|
int min = Integer.parseInt(st.nextToken());
|
|
int sec = st.hasMoreElements() ? Integer.parseInt(st.nextToken()) : 0;
|
|
return new Time((long)((hour - 1) * 3600000 + min * 60000 + sec * 1000));
|
|
}
|
|
return null;
|
|
} catch (Exception e) {
|
|
return null;
|
|
}
|
|
}
|
|
}
|