996 lines
34 KiB
Java
996 lines
34 KiB
Java
package it.acxent.pg;
|
|
|
|
import it.acxent.common.CrontabInterface;
|
|
import it.acxent.common.StatusMsg;
|
|
import it.acxent.db.AddImgInterface;
|
|
import it.acxent.db.ApplParmFull;
|
|
import it.acxent.db.DBAdapter;
|
|
import it.acxent.db.ResParm;
|
|
import it.acxent.db.WcString;
|
|
import it.acxent.util.FileWr;
|
|
import it.acxent.util.SimpleDateFormat;
|
|
import it.acxent.util.StringTokenizer;
|
|
import it.acxent.util.Timer;
|
|
import it.acxent.util.UploadFile;
|
|
import it.acxent.util.Vectumerator;
|
|
import java.io.BufferedReader;
|
|
import java.io.File;
|
|
import java.io.FileReader;
|
|
import java.io.Serializable;
|
|
import java.sql.Date;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.SQLException;
|
|
import java.sql.Time;
|
|
import java.sql.Timestamp;
|
|
import java.util.Calendar;
|
|
|
|
public class Gara extends _PgAdapter implements Serializable, AddImgInterface, CrontabInterface {
|
|
private static final long serialVersionUID = 1511425418987L;
|
|
|
|
private long id_gara;
|
|
|
|
private long id_tipoGara;
|
|
|
|
private String descrizione;
|
|
|
|
private String localita;
|
|
|
|
private Date dataGaraInizio;
|
|
|
|
private Date dataGaraFine;
|
|
|
|
private String pathBase;
|
|
|
|
private String imgTmst;
|
|
|
|
private TipoGara tipoGara;
|
|
|
|
private long flgEventoInLinea;
|
|
|
|
private long nDownload;
|
|
|
|
private Date dataDownload;
|
|
|
|
private String testoColore;
|
|
|
|
private long testoSize;
|
|
|
|
private String testoO;
|
|
|
|
private String testoV;
|
|
|
|
private String testoFont;
|
|
|
|
private long codGara;
|
|
|
|
public static final long TIPO_INDEX_MANOLA = 1L;
|
|
|
|
public static final long TIPO_INDEX_NO = 0L;
|
|
|
|
private long flgTipoIndex;
|
|
|
|
class ThreadCreaPuntiFoto extends Thread {
|
|
private boolean indicizza = false;
|
|
|
|
private Gara gara;
|
|
|
|
private long id_users;
|
|
|
|
public ThreadCreaPuntiFoto(Gara gara, boolean indicizza, long id_users) {
|
|
if (!Gara.isThreadAttivo()) {
|
|
Gara.threadCreaPuntiFoto = true;
|
|
this.gara = gara;
|
|
this.indicizza = indicizza;
|
|
this.id_users = id_users;
|
|
start();
|
|
}
|
|
}
|
|
|
|
public void run() {
|
|
boolean debug = false;
|
|
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
|
|
System.out.println("##############\nCREA PUNTI FOTO\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;
|
|
ApplParmFull ap = this.gara.getApFull();
|
|
Gara.threadCreaPuntiFotoMsg = "Attenzione! Thread CREA PUNTI FOTO in esecuzione!!! Aggiornamento articoli attuali ";
|
|
String dirBase = this.gara.getPathBaseFoto() + this.gara.getPathBaseFoto();
|
|
if (new File(dirBase).exists()) {
|
|
File dir = new File(dirBase);
|
|
File[] puntiFotos = dir.listFiles();
|
|
File thePuntoFotoDir = null;
|
|
try {
|
|
for (int j = 0; j < puntiFotos.length; j++) {
|
|
thePuntoFotoDir = puntiFotos[j];
|
|
String theDir = thePuntoFotoDir.getAbsolutePath();
|
|
if (new File(theDir).isDirectory()) {
|
|
String path = theDir.substring(dirBase.length());
|
|
PuntoFoto pf = new PuntoFoto(ap);
|
|
pf.findByGaraPath(this.gara.getId_gara(), path);
|
|
if (pf.getDBState() == 0) {
|
|
Gara.threadCreaPuntiFotoMsg = "Creazione punto foto " + path;
|
|
pf.setId_gara(this.gara.getId_gara());
|
|
pf.setPathRelativoFoto(path);
|
|
pf.setDescrizionePuntoFoto(path.replace("/", ""));
|
|
rp = pf.save();
|
|
if (rp.getStatus() &&
|
|
this.indicizza) {
|
|
Gara.threadCreaPuntiFotoMsg = "Indicizzazione punto foto " + path;
|
|
pf.indexFoto(this.id_users);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Gara.threadCreaPuntiFotoMsg = "Creazione punto foto gara " + this.gara.getDescrizione() + " ok!";
|
|
sleep(8000L);
|
|
Gara.threadCreaPuntiFotoMsg = "";
|
|
} catch (Exception e) {
|
|
Gara.this.handleDebug(e);
|
|
Gara.threadCreaPuntiFotoMsg = "Errore! CREA PUNTO FOTO" + thePuntoFotoDir.getName() + "<br>" + e.getMessage();
|
|
}
|
|
} else {
|
|
Gara.threadCreaPuntiFotoMsg = "Errore! Percorso base errato: " + dirBase;
|
|
}
|
|
Timestamp stop = new Timestamp(Calendar.getInstance().getTimeInMillis());
|
|
System.out.println("STOP: " + start.toString());
|
|
SimpleDateFormat dfMS = new SimpleDateFormat("HH:mm:ss ");
|
|
System.out.println("DURATA: " + dfMS.format(new Time(stop.getTime() - start.getTime() - 3600000L)) + "Risultato import:\n" +
|
|
rp.getMsg() + "\n\nIMPORT CREA PUNTI FOTO concluso\n****************");
|
|
Gara.threadCreaPuntiFoto = false;
|
|
}
|
|
}
|
|
|
|
class ThreadInvioEOcr extends Thread {
|
|
private boolean conOcr = false;
|
|
|
|
private Gara gara;
|
|
|
|
public ThreadInvioEOcr(Gara gara, boolean conOcr) {
|
|
if (!Gara.isThreadInvioEOCrAttivo()) {
|
|
Gara.threadInvioEOcr = true;
|
|
this.gara = gara;
|
|
this.conOcr = conOcr;
|
|
start();
|
|
}
|
|
}
|
|
|
|
public void run() {
|
|
boolean debug = false;
|
|
String TAG_THREAD_MSG = "INVIO FOTO GARA";
|
|
if (this.conOcr)
|
|
TAG_THREAD_MSG = "INVIO FOTO GARA + OCR";
|
|
ResParm rp = new ResParm(true);
|
|
Timer timer = new Timer();
|
|
timer.start();
|
|
ApplParmFull ap = this.gara.getApFull();
|
|
StatusMsg.updateMsgByTag(Gara.this.getApFull(), TAG_THREAD_MSG, "Avvio thread creazione gara e invio foto.");
|
|
if (!Gara.threadInvioGaraWww) {
|
|
if (debug)
|
|
System.out.println(TAG_THREAD_MSG + " ####### AVVIO THREAD exportGaraDa3PianoAWWW ######" + TAG_THREAD_MSG);
|
|
Gara.threadInvioGaraWww = true;
|
|
new Thread() {
|
|
public void run() {
|
|
Gara.this.exportGaraDa3PianoAWWW(false);
|
|
Gara.threadInvioGaraWww = false;
|
|
}
|
|
}.start();
|
|
StatusMsg.updateMsgByTag(Gara.this.getApFull(), TAG_THREAD_MSG, "Thread export gara su WWW avviato!");
|
|
} else {
|
|
try {
|
|
StatusMsg.updateMsgByTag(Gara.this.getApFull(), TAG_THREAD_MSG, "ATTENZIONE! Thread export gara su WWW gia' in esecuzione!");
|
|
sleep(10000L);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
Vectumerator<PuntoFoto> vec = this.gara.getPuntiFoto(0, 0);
|
|
while (vec.hasMoreElements()) {
|
|
PuntoFoto pf = (PuntoFoto)vec.nextElement();
|
|
if (debug)
|
|
System.out.println(TAG_THREAD_MSG + " ####### AVVIO THREAD startOcrThread PUNTO FOTO " + TAG_THREAD_MSG + " ######" + pf.getDescrizionePuntoFoto());
|
|
rp = pf.startOcrThread();
|
|
StatusMsg.updateMsgByTag(Gara.this.getApFull(), TAG_THREAD_MSG, "Avvio thread ocr puntofoto " +
|
|
pf.getDescrizionePuntoFoto() + " " + rp.getStatus());
|
|
while (PuntoFoto.isThreadOcrAttivo(pf.getId_puntoFoto())) {
|
|
try {
|
|
sleep(10000L);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
if (debug)
|
|
System.out.println(TAG_THREAD_MSG + " ####### FINE CICLO THREAD startOcrThread PUNTO FOTO ######" + TAG_THREAD_MSG);
|
|
int attesa = 0;
|
|
while (Gara.threadInvioGaraWww || Foto.threadInvioFotoWww) {
|
|
try {
|
|
StatusMsg.updateMsgByTag(Gara.this.getApFull(), TAG_THREAD_MSG, "Attesa conclusione primo invio gara " + attesa + " sec");
|
|
if (debug)
|
|
System.out.println(TAG_THREAD_MSG + " ####### Attesa conclusione THREAD threadInvioGaraWww e threadInvioFotoWww INIZIALE ######" + TAG_THREAD_MSG);
|
|
sleep(10000L);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
attesa += 10;
|
|
}
|
|
if (debug)
|
|
System.out.println(TAG_THREAD_MSG + " ####### FINE THREAD threadInvioGaraWww INIZIALE ######" + TAG_THREAD_MSG);
|
|
StatusMsg.updateMsgByTag(Gara.this.getApFull(), TAG_THREAD_MSG, "Avvio nuovo thread invio foto con le indicizzazioni");
|
|
if (!Gara.threadInvioGaraWww) {
|
|
if (debug)
|
|
System.out.println(TAG_THREAD_MSG + " ####### NUOVO AVVIO THREAD exportGaraDa3PianoAWWW ######" + TAG_THREAD_MSG);
|
|
Gara.threadInvioGaraWww = true;
|
|
new Thread() {
|
|
public void run() {
|
|
Gara.this.exportGaraDa3PianoAWWW(false);
|
|
Gara.threadInvioGaraWww = false;
|
|
}
|
|
}.start();
|
|
StatusMsg.updateMsgByTag(Gara.this.getApFull(), TAG_THREAD_MSG, "Secondo Thread export gara su WWW avviato!");
|
|
} else {
|
|
try {
|
|
StatusMsg.updateMsgByTag(Gara.this.getApFull(), TAG_THREAD_MSG, "ATTENZIONE! Thread export gara su WWW gia' in esecuzione!");
|
|
sleep(10000L);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
if (debug)
|
|
System.out.println(TAG_THREAD_MSG + " ####### FINE DI TUTTO PROBABILE THREAD exportGaraDa3PianoAWWW IN ESECUZIONE !!!! ######" + TAG_THREAD_MSG);
|
|
timer.stop();
|
|
StatusMsg.updateMsgByTag(Gara.this.getApFull(), TAG_THREAD_MSG, "FINE: DURATA: " + timer.getDurata());
|
|
try {
|
|
sleep(15000L);
|
|
} catch (Exception e) {}
|
|
StatusMsg.deleteMsgByTag(Gara.this.getApFull(), TAG_THREAD_MSG);
|
|
Gara.threadInvioEOcr = false;
|
|
}
|
|
}
|
|
|
|
public static boolean threadInvioGaraWww = false;
|
|
|
|
public static boolean threadCreaPuntiFoto = false;
|
|
|
|
public static boolean threadInvioEOcr = false;
|
|
|
|
public static String threadCreaPuntiFotoMsg = "";
|
|
|
|
public static final int FLG_EVENTO_NON_IN_LINEA = 0;
|
|
|
|
public static final int FLG_EVENTO_STAND_BY = 1;
|
|
|
|
public static final int FLG_EVENTO_IN_LINEA = 2;
|
|
|
|
private long flgFree;
|
|
|
|
private String fileNameExport;
|
|
|
|
private boolean fileExportOk;
|
|
|
|
public Gara(ApplParmFull newApplParmFull) {
|
|
super(newApplParmFull);
|
|
}
|
|
|
|
public Gara() {}
|
|
|
|
public void setId_gara(long newId_gara) {
|
|
this.id_gara = newId_gara;
|
|
}
|
|
|
|
public void setId_tipoGara(long newId_tipoGara) {
|
|
this.id_tipoGara = newId_tipoGara;
|
|
setTipoGara(null);
|
|
}
|
|
|
|
public void setDescrizione(String newDescrizione) {
|
|
this.descrizione = newDescrizione;
|
|
}
|
|
|
|
public void setLocalita(String newLocalita) {
|
|
this.localita = newLocalita;
|
|
}
|
|
|
|
public void setDataGaraInizio(Date newDataGaraInizio) {
|
|
this.dataGaraInizio = newDataGaraInizio;
|
|
}
|
|
|
|
public void setDataGaraFine(Date newDataGaraFine) {
|
|
this.dataGaraFine = newDataGaraFine;
|
|
}
|
|
|
|
public void setPathBase(String newPathBase) {
|
|
this.pathBase = newPathBase;
|
|
}
|
|
|
|
public void setImgTmst(String newImgTmst) {
|
|
this.imgTmst = newImgTmst;
|
|
}
|
|
|
|
public long getId_gara() {
|
|
return this.id_gara;
|
|
}
|
|
|
|
public long getId_tipoGara() {
|
|
return this.id_tipoGara;
|
|
}
|
|
|
|
public String getDescrizione() {
|
|
return (this.descrizione == null) ? "" : this.descrizione.trim();
|
|
}
|
|
|
|
public String getLocalita() {
|
|
return (this.localita == null) ? "" : this.localita.trim();
|
|
}
|
|
|
|
public Date getDataGaraInizio() {
|
|
return this.dataGaraInizio;
|
|
}
|
|
|
|
public Date getDataGaraFine() {
|
|
return this.dataGaraFine;
|
|
}
|
|
|
|
public String getPathBase() {
|
|
return (this.pathBase == null) ? "" : this.pathBase.trim();
|
|
}
|
|
|
|
public String getImgTmst() {
|
|
return (this.imgTmst == null) ? "" : this.imgTmst.trim();
|
|
}
|
|
|
|
public void setTipoGara(TipoGara newTipoGara) {
|
|
this.tipoGara = newTipoGara;
|
|
}
|
|
|
|
public TipoGara getTipoGara() {
|
|
this.tipoGara = (TipoGara)getSecondaryObject(this.tipoGara, TipoGara.class, getId_tipoGara());
|
|
return this.tipoGara;
|
|
}
|
|
|
|
protected ResParm checkDeleteCascade() {
|
|
return new ResParm(true);
|
|
}
|
|
|
|
protected void deleteCascade() {}
|
|
|
|
public Vectumerator<Gara> findByCR(GaraCR CR, int pageNumber, int pageRows) {
|
|
StringBuilder s_Sql_Find = new StringBuilder("select A.* from GARA AS A");
|
|
String s_Sql_Order = " order by A.dataGaraInizio desc";
|
|
WcString wc = new WcString();
|
|
if (CR.getId_tipoGara() != 0L)
|
|
s_Sql_Find.append(" inner join TIPO_GARA AS C ON C.id_tipoGara=A.id_tipoGara");
|
|
if (!CR.getSearchTxt().trim().isEmpty()) {
|
|
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
|
StringBuffer txt = new StringBuffer("(");
|
|
while (st.hasMoreTokens()) {
|
|
String token = st.nextToken();
|
|
txt.append("(A.descrizione like '%" + token + "%' or A.localita like '%" + token + "%')");
|
|
if (st.hasMoreTokens())
|
|
txt.append(" and ");
|
|
}
|
|
txt.append(")");
|
|
wc.addWc(txt.toString());
|
|
}
|
|
if (!CR.getDescrizioneGara().trim().isEmpty()) {
|
|
StringTokenizer st = new StringTokenizer(CR.getDescrizioneGara().trim(), " ");
|
|
StringBuffer txt = new StringBuffer("(");
|
|
while (st.hasMoreTokens()) {
|
|
String token = st.nextToken();
|
|
txt.append("(A.descrizione like '%" + token + "%' or A.localita like '%" + token + "%')");
|
|
if (st.hasMoreTokens())
|
|
txt.append(" and ");
|
|
}
|
|
txt.append(")");
|
|
wc.addWc(txt.toString());
|
|
}
|
|
if (CR.getId_tipoGara() != 0L)
|
|
wc.addWc("(A.id_tipogara=" + CR.getId_tipoGara() + " or C.indici like'%:" + CR.getId_tipoGara() + ":%')");
|
|
if (CR.getDataGaraInizioDa() != null)
|
|
wc.addWc("(A.dataGaraInizio>=? )");
|
|
if (CR.getDataGaraInizioA() != null)
|
|
wc.addWc("(A.dataGaraInizio<=? )");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString());
|
|
int numData = 1;
|
|
if (CR.getDataGaraInizioDa() != null) {
|
|
stmt.setDate(numData, CR.getDataGaraInizioDa());
|
|
numData++;
|
|
}
|
|
if (CR.getDataGaraInizioA() != null) {
|
|
stmt.setDate(numData, CR.getDataGaraInizioA());
|
|
numData++;
|
|
}
|
|
return findRows(stmt, pageNumber, pageRows);
|
|
} catch (SQLException e) {
|
|
removeCPConnection();
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public ResParm addPuntoFoto(PuntoFoto ab) {
|
|
PuntoFoto bean = new PuntoFoto(getApFull());
|
|
if (ab.getId_puntoFoto() == 0L) {
|
|
ab.setDBState(0);
|
|
} else {
|
|
bean.findByPrimaryKey(ab.getId_puntoFoto());
|
|
if (bean != null) {
|
|
ab.setDBState(bean.getDBState());
|
|
} else {
|
|
ab.setDBState(0);
|
|
}
|
|
}
|
|
ab.setId_gara(getId_gara());
|
|
return ab.save();
|
|
}
|
|
|
|
public ResParm delPuntoFoto(long l_id) {
|
|
PuntoFoto bean = new PuntoFoto(getApFull());
|
|
bean.findByPrimaryKey(l_id);
|
|
return bean.delete();
|
|
}
|
|
|
|
public String getDescrizioneGaraCompleta() {
|
|
if (getId_gara() == 0L)
|
|
return "";
|
|
return getDataFormat().format(getDataGaraInizio()) + " - " + getDataFormat().format(getDataGaraInizio()) + " - " + getDataFormat().format(getDataGaraFine());
|
|
}
|
|
|
|
public String getDescrizioneGaraHtml() {
|
|
return convertStringToHtml(getDescrizione());
|
|
}
|
|
|
|
public Vectumerator getPuntiFoto(int pageNumber, int pageRows) {
|
|
return new PuntoFoto(getApFull()).findPuntiFotoByGara(getId_gara(), pageNumber, pageRows);
|
|
}
|
|
|
|
public boolean isIndexManuale() {
|
|
if (getId_gara() == 0L)
|
|
return false;
|
|
PuntoFoto pf = new PuntoFoto(getApFull());
|
|
PuntoFotoCR CR = new PuntoFotoCR(getApFull());
|
|
CR.setId_gara(getId_gara());
|
|
CR.setFlgIndexOk(2L);
|
|
Vectumerator<PuntoFoto> vec = pf.findByCR(CR, 1, 1);
|
|
if (vec.hasMoreElements())
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
public Vectumerator findWebByCR(FotoCR CR, int pageNumber, int pageRows) {
|
|
String s_Sql_Find = "select A.* from GARA AS A";
|
|
String s_Sql_Order = " order by A.flgEventoInLinea, A.dataGaraInizio desc, A.descrizione";
|
|
WcString wc = new WcString();
|
|
if (CR.getId_tipoGara() > 0L)
|
|
s_Sql_Find = s_Sql_Find + " inner join TIPO_GARA AS C ON A.id_tipoGara=C.id_tipoGara";
|
|
if (CR.getId_tipoGara() > 0L)
|
|
wc.addWc("(A.id_tipoGara=" + CR.getId_tipoGara() + " or C.indici like'%:" + CR.getId_tipoGara() + ":%')");
|
|
if (!CR.getLocalita().isEmpty())
|
|
wc.addWc("A.localita like '%" + CR.getLocalita() + "%'");
|
|
wc.addWc("A.flgEventoInLinea>0");
|
|
if (CR.getAnno() > 0L) {
|
|
wc.addWc("A.dataGaraInizio>=?");
|
|
wc.addWc("A.dataGaraInizio<=?");
|
|
}
|
|
if (CR.getFlgMese() > 0L)
|
|
wc.addWc("MONTH(A.dataGaraInizio)=" + CR.getFlgMese());
|
|
if (CR.getDataGaraInizio() != null)
|
|
wc.addWc("(A.dataGaraInizio<=? and (A.dataGaraFine>=? || A.dataGaraFine is null))");
|
|
if (CR.getDataGaraInizioDa() != null)
|
|
wc.addWc("(A.dataGaraInizio>=? or A.dataGaraFine>=?)");
|
|
if (CR.getDataGaraInizioA() != null)
|
|
wc.addWc("(A.dataGaraInizio<=? or A.dataGaraFine<=?)");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
int numData = 1;
|
|
if (CR.getAnno() > 0L) {
|
|
stmt.setDate(1, DBAdapter.getFirstOfYear((int)CR.getAnno()));
|
|
numData++;
|
|
stmt.setDate(2, DBAdapter.getLastOfYear((int)CR.getAnno()));
|
|
numData++;
|
|
}
|
|
if (CR.getDataGaraInizio() != null) {
|
|
stmt.setDate(numData, CR.getDataGaraInizio());
|
|
numData++;
|
|
stmt.setDate(numData, CR.getDataGaraInizio());
|
|
numData++;
|
|
}
|
|
if (CR.getDataGaraInizioDa() != null) {
|
|
stmt.setDate(numData, CR.getDataGaraInizioDa());
|
|
numData++;
|
|
stmt.setDate(numData, CR.getDataGaraInizioDa());
|
|
numData++;
|
|
}
|
|
if (CR.getDataGaraInizioA() != null) {
|
|
stmt.setDate(numData, CR.getDataGaraInizioA());
|
|
numData++;
|
|
stmt.setDate(numData, CR.getDataGaraInizioA());
|
|
numData++;
|
|
}
|
|
return findRows(stmt, pageNumber, pageRows);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public long getFlgEventoInLinea() {
|
|
return this.flgEventoInLinea;
|
|
}
|
|
|
|
public void setFlgEventoInLinea(long flgEventoInLinea) {
|
|
this.flgEventoInLinea = flgEventoInLinea;
|
|
}
|
|
|
|
public static final String getEventoInLinea(long l_flgEventoInLinea) {
|
|
switch ((int)l_flgEventoInLinea) {
|
|
case 0:
|
|
return "Non In Linea";
|
|
case 1:
|
|
return "Stand By";
|
|
case 2:
|
|
return "In Linea";
|
|
}
|
|
return "--";
|
|
}
|
|
|
|
public static final String getFree(long l_flgFree) {
|
|
switch ((int)l_flgFree) {
|
|
case 0:
|
|
return "No";
|
|
case 1:
|
|
return "SI";
|
|
}
|
|
return "--";
|
|
}
|
|
|
|
public String getEventoInLinea() {
|
|
return getEventoInLinea(getFlgEventoInLinea());
|
|
}
|
|
|
|
public ResParm save() {
|
|
if (!getPathBase().isEmpty() && !getPathBase().endsWith("/"))
|
|
setPathBase(getPathBase() + "/");
|
|
ResParm rp = super.save();
|
|
if (rp.getStatus() &&
|
|
getPathBase().isEmpty() && getDataGaraInizio() != null) {
|
|
Calendar cal = Calendar.getInstance();
|
|
cal.setTime(getDataGaraInizio());
|
|
int year = cal.get(1);
|
|
setPathBase("" + year + "/" + year + "/");
|
|
rp.append(super.save());
|
|
}
|
|
return rp;
|
|
}
|
|
|
|
public final ResParm startCreaPuntiFoto(Gara l_gara, boolean l_indicizza, long l_id_users) {
|
|
if (!isThreadAttivo()) {
|
|
new ThreadCreaPuntiFoto(l_gara, l_indicizza, l_id_users);
|
|
return new ResParm(true, "Thread Creazione Punti foto avviato");
|
|
}
|
|
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
|
|
}
|
|
|
|
public final ResParm startInvioEOcr(Gara l_gara, boolean l_conOcr) {
|
|
if (!isThreadInvioEOCrAttivo()) {
|
|
if (threadInvioGaraWww || Foto.threadInvioFotoWww || PuntoFoto.isThreadOcrAttivo())
|
|
return new ResParm(false, "ATTENZIONE!! Thread Invio gara/foto o OCR in esecuzione separatamente!!!");
|
|
new ThreadInvioEOcr(l_gara, l_conOcr);
|
|
return new ResParm(true, "Thread Invio e OCR avviato");
|
|
}
|
|
return new ResParm(false, "ATTENZIONE!! Thread Invio e OCR in esecuzione!!!");
|
|
}
|
|
|
|
public static boolean isThreadAttivo() {
|
|
return threadCreaPuntiFoto;
|
|
}
|
|
|
|
public static boolean isThreadInvioEOCrAttivo() {
|
|
return threadInvioEOcr;
|
|
}
|
|
|
|
public long getNDownload() {
|
|
return this.nDownload;
|
|
}
|
|
|
|
public void setNDownload(long nDownload) {
|
|
this.nDownload = nDownload;
|
|
}
|
|
|
|
public Date getDataDownload() {
|
|
return this.dataDownload;
|
|
}
|
|
|
|
public void setDataDownload(Date dataDownload) {
|
|
this.dataDownload = dataDownload;
|
|
}
|
|
|
|
public ResParm crontabJob(ApplParmFull ap) {
|
|
ResParm rp = new ResParm(true);
|
|
StringBuffer msg = new StringBuffer("\n################# Inizio crontab Giornaliera PG (" +
|
|
DBAdapter.getNow().toString() + ")\n#################");
|
|
long t0 = System.currentTimeMillis();
|
|
Gara bean = new Gara(ap);
|
|
rp = bean.aggiornaStatistiche();
|
|
msg.append(rp.getMsg());
|
|
long totFoto = new Foto(ap).getTotFoto();
|
|
msg.append(" TOTALI FOTO PRESENTI: " + ap.getNf().format(totFoto));
|
|
msg.append("\n################# Fine crontab Giornaliera PG (" + 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 ResParm aggiornaStatistiche() {
|
|
ResParm rp = new ResParm(false);
|
|
if (getApFull() != null) {
|
|
Gara bean = new Gara(getApFull());
|
|
String s_Sql_Find = "select count(*) as nDownload , B.id_gara from LOG_FOTO AS A INNER JOIN FOTO AS B ON A.id_foto=B.id_foto GROUP BY B.id_gara;";
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find);
|
|
long totDownload = 0L, totGareNonTrovate = 0L;
|
|
Vectumerator<Gara> vec = findRows(stmt);
|
|
while (vec.hasMoreElements()) {
|
|
Gara row = (Gara)vec.nextElement();
|
|
bean.findByPrimaryKey(row.getId_gara());
|
|
if (bean.getId_gara() > 0L) {
|
|
bean.setNDownload(row.getNDownload());
|
|
bean.setDataDownload(getToday());
|
|
bean.save();
|
|
totDownload += row.getNDownload();
|
|
continue;
|
|
}
|
|
totGareNonTrovate++;
|
|
}
|
|
rp.setMsg("Aggiornati " + vec.getTotNumberOfRecords() + " records. Tot. download: " + totDownload + " gare non trovate nei log: " + totGareNonTrovate);
|
|
} catch (SQLException e) {
|
|
removeCPConnection();
|
|
handleDebug(e);
|
|
rp.setStatus(false);
|
|
rp.setMsg(e);
|
|
}
|
|
} else {
|
|
rp.setMsg("ERRORE!! AP null");
|
|
}
|
|
return rp;
|
|
}
|
|
|
|
public boolean isImportFileExist() {
|
|
String theFile = getImpCsvFileName();
|
|
return isFileExist(theFile);
|
|
}
|
|
|
|
public String getImpCsvFileName() {
|
|
return getDocBase() + "csv/" + getDocBase() + ".csv";
|
|
}
|
|
|
|
public ResParm indexFotoPisa(String l_fileName, String TAG_THREAD_MSG) {
|
|
boolean debug = false;
|
|
ResParm rp = new ResParm();
|
|
int se1 = 10;
|
|
int se2 = 100;
|
|
int i = 0;
|
|
int nrighe = 0;
|
|
int fotoTrovate = 0;
|
|
int fotoNonTrovate = 0;
|
|
if (debug)
|
|
System.out.println("indexFotoPisa: start: filename; " + l_fileName);
|
|
StringBuffer errMsg = new StringBuffer();
|
|
if (getId_gara() == 0L) {
|
|
rp.setMsg("Indicizzazione foto: Bean gara non caricato");
|
|
rp.setStatus(false);
|
|
handleDebug("Indicizzazione foto: Bean gara non caricato", 2);
|
|
return rp;
|
|
}
|
|
BufferedReader reader = null;
|
|
Foto foto = new Foto(getApFull());
|
|
try {
|
|
reader = new BufferedReader(new FileReader(l_fileName));
|
|
if (reader != null) {
|
|
String currentLine = reader.readLine();
|
|
while ((currentLine = reader.readLine()) != null) {
|
|
nrighe++;
|
|
if (debug)
|
|
System.out.println("indexFotoPisa: currentline: " + currentLine);
|
|
int firstComma = currentLine.indexOf(",");
|
|
String nomeFoto = currentLine.substring(0, firstComma);
|
|
String pettorali = currentLine.substring(firstComma + 1);
|
|
if (debug)
|
|
System.out.println("indexFotoPisa: pettorali " + nomeFoto + " - " + pettorali);
|
|
foto.findByFilenameGara(nomeFoto, getId_gara());
|
|
if (foto.getDBState() == 1) {
|
|
fotoTrovate++;
|
|
pettorali = pettorali.replace("\"", "");
|
|
if (debug)
|
|
System.out.println("indexFotoPisa: pettorali con replace" + nomeFoto + " - " + pettorali);
|
|
Foto.syncAggiornaPettoraleInviato(foto, 0L, 0L, pettorali, 2L);
|
|
} else {
|
|
fotoNonTrovate++;
|
|
}
|
|
StatusMsg.updateMsgByTag(getApFull(), TAG_THREAD_MSG, "Index csv: n. riga:" + nrighe + " foto trovate:" + fotoTrovate + " NON trovate:" + fotoNonTrovate);
|
|
i++;
|
|
if (se1 <= 0 || i % se1 == 0);
|
|
if (se2 <= 0 || i % se2 == 0);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
rp.setStatus(false);
|
|
rp.appendMsg("-------------------\nECCEZIONE !!!\n");
|
|
rp.appendMsg(e.getMessage());
|
|
rp.appendMsg(" \n Numero righe importate: " + nrighe);
|
|
rp.appendMsg(" \nFoto Trovate: " + fotoTrovate + " foto Non trovate: " + fotoNonTrovate);
|
|
} finally {
|
|
if (reader != null)
|
|
try {
|
|
reader.close();
|
|
} catch (Exception e2) {
|
|
e2.printStackTrace();
|
|
}
|
|
}
|
|
if (rp.getStatus())
|
|
rp.setMsg(" Numero righe importate: " + nrighe + " \nFoto Trovate: " + fotoTrovate + " foto Non trovate: " + fotoNonTrovate);
|
|
StatusMsg.updateMsgByTag(getApFull(), TAG_THREAD_MSG, "Index csv: Numero righe importate: " + nrighe + " Foto Trovate: " + fotoTrovate + " foto Non trovate: " + fotoNonTrovate);
|
|
StatusMsg.deleteMsgByTag(getApFull(), TAG_THREAD_MSG);
|
|
return rp;
|
|
}
|
|
|
|
public String getPathImg() {
|
|
return "_img/_gara/";
|
|
}
|
|
|
|
public ResParm exportGaraDa3PianoAWWW(boolean soloFoto) {
|
|
ResParm rp = new ResParm(true);
|
|
String TAG_THREAD_MSG = "Export gara su www";
|
|
if (getId_gara() != 0L) {
|
|
try {
|
|
System.out.println("Export gara su www 2");
|
|
ApplParmFull apRemoto = getApRemoto();
|
|
Gara garaWww = new Gara(apRemoto);
|
|
garaWww.findByPrimaryKey(getCodGara());
|
|
System.out.println("Export gara su www 3");
|
|
String urlServletRicevente = getApFull().getParm("RECEIVE_FILE_SERVLET").getTesto();
|
|
if (garaWww.getId_gara() == 0L) {
|
|
System.out.println("Export gara su www 4");
|
|
StatusMsg.updateMsgByTag(getApFull(), "Export gara su www", "...creo la gara su www piano");
|
|
garaWww = (Gara)clone();
|
|
garaWww.setDBState(0);
|
|
garaWww.setId_gara(0L);
|
|
garaWww.setApFull(apRemoto);
|
|
rp = garaWww.save();
|
|
System.out.println("Export gara su www 5");
|
|
if (rp.getStatus()) {
|
|
System.out.println("Export gara su www 6");
|
|
setCodGara(garaWww.getId_gara());
|
|
rp = save();
|
|
System.out.println("Export gara su www 7 " + rp.getMsg());
|
|
System.out.println("Export gara su www 8");
|
|
}
|
|
} else {
|
|
System.out.println("Export gara su www pre9 gara esistente");
|
|
}
|
|
System.out.println("Export gara su www 9");
|
|
if (rp.getStatus()) {
|
|
System.out.println("Export gara su www 10");
|
|
StatusMsg.updateMsgByTag(getApFull(), "Export gara su www", "....trasferisco immagine gara");
|
|
if (!garaWww.getImgTmst().equals(getImgTmst())) {
|
|
garaWww.setImgTmst(getImgTmst());
|
|
garaWww.save();
|
|
}
|
|
System.out.println("Export gara su www 11");
|
|
UploadFile uf = new UploadFile();
|
|
String percorsoLocale = getDocBase() + "img/gare/";
|
|
File logoGara = new File(getImgLogoGaraFileName());
|
|
String percorsoRemoto = garaWww.getDocBase() + garaWww.getDocBase();
|
|
String fileRemoto = garaWww.getImgFileName(1);
|
|
System.out.println("Export gara su www 12");
|
|
if (logoGara.exists()) {
|
|
System.out.println("Export gara su www 13");
|
|
System.out.println("trasferisco tramite " + urlServletRicevente + " il logo gara " + getImgLogoGaraFileName() + " su " + percorsoRemoto + " " + fileRemoto);
|
|
rp = uf.transferFile(urlServletRicevente, logoGara, percorsoRemoto, fileRemoto, false);
|
|
if (!rp.getStatus()) {
|
|
StatusMsg.updateMsgByTag(getApFull(), "Export gara su www", "Attenzione!! trasferimento logo fallito! ");
|
|
System.out.println("Export gara su wwwAttenzione!! trasferimento logo fallito! " + rp.getMsg());
|
|
rp.setStatus(true);
|
|
}
|
|
}
|
|
}
|
|
if (rp.getStatus());
|
|
if (rp.getStatus()) {
|
|
System.out.println("Export gara su www 14 trasf punti foto");
|
|
Vectumerator<PuntoFoto> vecPf = getPuntiFoto(0, 0);
|
|
while (vecPf.hasMoreElements()) {
|
|
PuntoFoto row = (PuntoFoto)vecPf.nextElement();
|
|
if (row.getId_puntoFotoExport() > 0L)
|
|
continue;
|
|
StatusMsg.updateMsgByTag(getApFull(), "Export gara su www", "... trasferisco punto foto " +
|
|
row.getGara().getDescrizione() + " " + row.getDescrizione() + " ....");
|
|
PuntoFoto puntoFotoR = (PuntoFoto)row.clone();
|
|
puntoFotoR.setDBState(0);
|
|
puntoFotoR.setId_gara(garaWww.getId_gara());
|
|
puntoFotoR.setId_puntoFoto(0L);
|
|
puntoFotoR.setApFull(apRemoto);
|
|
rp = puntoFotoR.save();
|
|
if (rp.getStatus()) {
|
|
row.setId_puntoFotoExport(puntoFotoR.getId_puntoFoto());
|
|
row.save();
|
|
}
|
|
}
|
|
}
|
|
if (rp.getStatus()) {
|
|
System.out.println("Export gara su www 15 startInvioFotoDa3PianoAWwwMT");
|
|
Foto foto = new Foto(getApFull());
|
|
foto.startInvioFotoDa3PianoAWwwMT(getId_gara(), soloFoto);
|
|
}
|
|
} catch (Exception e) {
|
|
System.out.println("Export gara su www ex");
|
|
e.printStackTrace();
|
|
rp.setException(e);
|
|
}
|
|
} else {
|
|
rp.setStatus(false);
|
|
rp.setMsg("ERRORE! id gara o codice gara 3 piano non impostato. Contatta marco!!!");
|
|
}
|
|
StatusMsg.updateMsgByTag(getApFull(), "Export gara su www", "Export DB gara su 3piano concluso!");
|
|
System.out.println("OCR #######**** FINE THREAD Export gara su www ######" + String.valueOf(DBAdapter.getNow()));
|
|
StatusMsg.deleteMsgByTag(getApFull(), "Export gara su www");
|
|
return rp;
|
|
}
|
|
|
|
public String getImgLogoGaraFileName() {
|
|
String oldLogogara = getDocBase() + "img/gare/" + getDocBase() + "_logoGara.jpg";
|
|
if (new File(oldLogogara).exists())
|
|
return oldLogogara;
|
|
return getDocBase() + getDocBase() + getPathImg();
|
|
}
|
|
|
|
public String getImgLogoGaraName() {
|
|
String oldLogogara = getDocBase() + "img/gare/" + getDocBase() + "_logoGara.jpg";
|
|
if (new File(oldLogogara).exists())
|
|
return "" + getId_gara() + "_logoGara.jpg";
|
|
return getImgFileName(1);
|
|
}
|
|
|
|
public String getTestoColore() {
|
|
return (this.testoColore == null) ? "" : this.testoColore.trim();
|
|
}
|
|
|
|
public void setTestoColore(String testoColore) {
|
|
this.testoColore = testoColore;
|
|
}
|
|
|
|
public long getTestoSize() {
|
|
return this.testoSize;
|
|
}
|
|
|
|
public void setTestoSize(long testoSize) {
|
|
this.testoSize = testoSize;
|
|
}
|
|
|
|
public String getTestoO() {
|
|
return (this.testoO == null) ? "" : this.testoO.trim();
|
|
}
|
|
|
|
public void setTestoO(String testO) {
|
|
this.testoO = testO;
|
|
}
|
|
|
|
public String getTestoV() {
|
|
return (this.testoV == null) ? "" : this.testoV.trim();
|
|
}
|
|
|
|
public void setTestoV(String testoV) {
|
|
this.testoV = testoV;
|
|
}
|
|
|
|
public String getTestoFont() {
|
|
return (this.testoFont == null) ? "" : this.testoFont.trim();
|
|
}
|
|
|
|
public void setTestoFont(String testoFont) {
|
|
this.testoFont = testoFont;
|
|
}
|
|
|
|
public long getCodGara() {
|
|
return this.codGara;
|
|
}
|
|
|
|
public void setCodGara(long codGara) {
|
|
this.codGara = codGara;
|
|
}
|
|
|
|
public static final String getTipoIndex(long l_flgTipoIndex) {
|
|
switch ((int)l_flgTipoIndex) {
|
|
case 1:
|
|
return "Pettorali (manola)";
|
|
case 0:
|
|
return "NO";
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public long getFlgTipoIndex() {
|
|
return this.flgTipoIndex;
|
|
}
|
|
|
|
public void setFlgTipoIndex(long flgTipoIndex) {
|
|
this.flgTipoIndex = flgTipoIndex;
|
|
}
|
|
|
|
public String getTipoIndex() {
|
|
return getTipoIndex(getFlgTipoIndex());
|
|
}
|
|
|
|
protected void initFields() {
|
|
super.initFields();
|
|
setTestoColore("#fbfe07");
|
|
setTestoSize(56L);
|
|
setTestoFont("/home/piero/Documenti/sites/rus/admin/_V4/_font/timesbd.ttf");
|
|
}
|
|
|
|
public long getFlgFree() {
|
|
return this.flgFree;
|
|
}
|
|
|
|
public void setFlgFree(long flgFree) {
|
|
this.flgFree = flgFree;
|
|
}
|
|
|
|
public ResParm exportFileIdx(String fileName) {
|
|
int numRec = 0;
|
|
String sep = ";";
|
|
new File(fileName).delete();
|
|
FileWr outFile = new FileWr(fileName, false);
|
|
String temp2 = System.getProperty("line.separator");
|
|
if (temp2.equals("\n"));
|
|
ResParm rp = new ResParm(false, "Errore in export: " + fileName + "<br>");
|
|
try {
|
|
outFile.writeLine("filename;md5;pettorali");
|
|
FotoCR CR = new FotoCR();
|
|
CR.setId_gara(getId_gara());
|
|
CR.setFlgConPettorali(1L);
|
|
Vectumerator<Foto> vec = new Foto(getApFull()).findByCR(CR, 0, 0);
|
|
StringBuilder temp = new StringBuilder();
|
|
while (vec.hasMoreElements()) {
|
|
Foto currentFoto = (Foto)vec.nextElement();
|
|
temp.append(currentFoto.getFileName());
|
|
temp.append(";");
|
|
temp.append(currentFoto.getMd5());
|
|
temp.append(";");
|
|
temp.append(currentFoto.getPettorali());
|
|
outFile.writeLine(temp.toString());
|
|
numRec++;
|
|
temp = new StringBuilder();
|
|
}
|
|
outFile.closeFile();
|
|
rp.setStatus(true);
|
|
rp.setMsg("Generazione file export avvenuta con successo.<br> n. foto esportate: " + numRec);
|
|
} catch (Exception e) {
|
|
handleDebug(e);
|
|
rp.setException(e);
|
|
rp.setStatus(false);
|
|
}
|
|
return rp;
|
|
}
|
|
|
|
public String getFileNameExport() {
|
|
return (this.fileNameExport == null) ? "" : this.fileNameExport.trim();
|
|
}
|
|
|
|
public void setFileNameExport(String fileNameExport) {
|
|
this.fileNameExport = fileNameExport;
|
|
}
|
|
|
|
public boolean isFileExportOk() {
|
|
return this.fileExportOk;
|
|
}
|
|
|
|
public void setFileExportOk(boolean fileExportOk) {
|
|
this.fileExportOk = fileExportOk;
|
|
}
|
|
}
|