package it.acxent.pg; import it.acxent.bank.paypal.PayPalReq; import it.acxent.bank.poste.PeReq; import it.acxent.bank.sella.SellaReq; import it.acxent.common.CrontabInterface; import it.acxent.common.Parm; import it.acxent.db.ApplParmFull; import it.acxent.db.DBAdapter; import it.acxent.db.ResParm; import it.acxent.db.WcString; import it.acxent.mail.MailMessage; import it.acxent.util.StringTokenizer; import it.acxent.util.Timer; import it.acxent.util.Vectumerator; import java.sql.Date; import java.sql.PreparedStatement; import java.text.NumberFormat; import java.util.Calendar; import java.util.concurrent.ConcurrentHashMap; public class Users extends it.acxent.anag.Users implements CrontabInterface { private Date dataScadenza; private Date dataVisual; private long nFotoVisual; private long nFotoVisualOggi; private long nFotoMax; private long flgVisCompatta; private long flgMailFotoScadenza; private long flgMiniature; private long flgMailFotoMax; private static final long TTL_MILLIS = 10000L; private static final ConcurrentHashMap rinnovoMailSent = new ConcurrentHashMap<>(); private static final ConcurrentHashMap scadABreveMailSent = new ConcurrentHashMap<>(); private static final ConcurrentHashMap couponOmaggioMailSent = new ConcurrentHashMap<>(); public Users(ApplParmFull newApplParmFull) { super(newApplParmFull); } public Users() {} protected ResParm checkDeleteCascade() { return new ResParm(true); } protected void deleteCascade() {} public synchronized void incrementaFotoVisual() { if (getDBState() == 1) { setNFotoVisual(getNFotoVisual() + 1L); if (getDataVisual() == null || getDateDiff(getDataVisual(), getToday()) != 0L) { setNFotoVisualOggi(0L); setDataVisual(getToday()); } setNFotoVisualOggi(getNFotoVisualOggi() + 1L); save(); } } public Date getDataScadenza() { return this.dataScadenza; } public void setDataScadenza(Date dataScadenza) { this.dataScadenza = dataScadenza; } public long getNFotoMax() { return this.nFotoMax; } public void setNFotoMax(long fotoMax) { this.nFotoMax = fotoMax; } public long getNFotoVisual() { return this.nFotoVisual; } public void setNFotoVisual(long fotoVisual) { this.nFotoVisual = fotoVisual; } public boolean isCodFiscDuplicated(String l_codFisc) { String s_Sql_Find = "select * from " + getTableBeanName() + " AS A "; String s_Sql_Order = ""; String wc = ""; wc = buildWc(wc, "A.codFisc='" + l_codFisc + "'"); try { PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc); DBAdapter bean = (DBAdapter)getFirstRecord(stmt); if (bean != null && bean.getDBState() == 1) return true; return false; } catch (Exception e) { handleDebug(e); return true; } } public Vectumerator findByCR(UsersCR CR, int pageNumber, int pageRows) { String s_Sql_Find = "select A.* from USERS AS A"; WcString wc = new WcString(); wc.addWc("dataFineVld is null"); wc = managePolicyFind(CR, wc); if (!CR.isCode1()) wc.addWc("A.id_users <>1"); if (!CR.getFlgValido().isEmpty()) wc.addWc("A.flgValido='" + CR.getFlgValido() + "'"); if (!CR.getSearchTxt().trim().isEmpty()) { String temp = CR.getSearchTxt().trim().replace("*", "%"); StringTokenizer st = new StringTokenizer(temp, " "); StringBuffer txt = new StringBuffer("("); int countToken = 0; while (st.hasMoreTokens()) { String token = prepareSqlString(st.nextToken()); countToken++; if (countToken > 1) token = "%" + token; txt.append("(A.nome like'%" + token + "%' or A.cognome like'%" + token + "%' or A.eMail like'%" + token + "%' or A.codFisc like'%" + token + "%' or A.login like'%" + token + "%')"); if (st.hasMoreTokens()) txt.append(" and "); } txt.append(")"); wc.addWc(txt.toString()); } if (!CR.getEMail().isEmpty()) wc.addWc("A.eMail like'%" + CR.getEMail() + "%'"); if (CR.getFlgMiniature() == 0L) { wc.addWc("(A.flgMiniature is null or A.flgMiniature=0)"); } else if (CR.getFlgMiniature() == 1L) { wc.addWc("A.flgMiniature=1"); } if (CR.getFlgScaduto() == 0L) { wc.addWc("A.dataScadenza>=?"); wc.addWc("A.nFotoMax>=A.nFotoVisual"); } else if (CR.getFlgScaduto() == 1L) { wc.addWc("(A.dataScadenza 0L) { wc.addWc("A.flgMl =" + CR.getFlgMl()); } try { PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find); int dataCount = 0; if (CR.getFlgScaduto() >= 0L) { dataCount++; stmt.setDate(dataCount, getToday()); } return findRows(stmt, pageNumber, pageRows); } catch (Exception e) { handleDebug(e); return AB_EMPTY_VECTUMERATOR; } } public ResParm azzeraFotoPrelevate() { String s_Sql = "delete from LOG where id_users=" + getId_users(); return delete(s_Sql); } public Date getDataVisual() { return this.dataVisual; } public void setDataVisual(Date dataVisual) { this.dataVisual = dataVisual; } public long getNFotoVisualOggi() { if (getDataVisual() == null || getDateDiff(getDataVisual(), getToday()) != 0L) return 0L; return this.nFotoVisualOggi; } public void setNFotoVisualOggi(long fotoVisualOggi) { this.nFotoVisualOggi = fotoVisualOggi; } public ResParm sendUserDataMailMessageCrypt(String l_password) { ResParm rp = new ResParm(true); try { if (getDBState() == 1) { NumberFormat nf = getNf(); String userMailMessage = getUserMailMessage("it"); if (!getControlCode().isEmpty()) userMailMessage = userMailMessage.substring(0, userMailMessage.length() - 5) + "CC" + userMailMessage.substring(0, userMailMessage.length() - 5); MailMessage mf = new MailMessage(getApFull(), userMailMessage); mf.setQuestionMark(false); if (!getControlCode().isEmpty()) mf.setString("controlCode", getControlCode()); mf.setString("data", getDataFormat().format(new java.util.Date())); mf.setString("login", getLogin()); if (l_password.isEmpty()) { mf.setString("pwd", "******"); } else { mf.setString("pwd", l_password); } mf.setString("nome", getNome()); mf.setString("cognome", getCognome()); mf.setString("citta", getCitta()); mf.setString("telefono", getTelefono()); mf.setString("eMail", getEMail()); mf.setString("indirizzo", getIndirizzo()); mf.setString("numeroCivico", getNumeroCivico()); mf.setString("codFisc", getCodFisc()); mf.setString("gruppoSportivo", getContatto()); mf.setString("motivo", getNota()); rp = mf.sendMailMessageSystem(getEMail(), mf.getMailSubject() + " Dati Registrazione ", true); } else { rp.setStatus(false); rp.setMsg("Email non in archivio!"); } } catch (Exception e) { handleDebug(e); rp.setStatus(false); rp.setMsg(e.getMessage()); } return rp; } public ResParm sendRinnovoMailMessage(long nFoto, int anni) { ResParm rp = new ResParm(true); try { if (getDBState() == 1) { String annifoto; String key = "mail-rinnovo-" + getId_users(); long now = System.currentTimeMillis(); Long lastSent = rinnovoMailSent.get(key); if (lastSent != null && now - lastSent < 10000L) return new ResParm(true); synchronized (rinnovoMailSent) { lastSent = rinnovoMailSent.get(key); if (lastSent != null && now - lastSent < 10000L) return new ResParm(true); rinnovoMailSent.put(key, Long.valueOf(now)); } String rinnovoMailMsg = getDocBase() + getDocBase(); MailMessage mf = new MailMessage(getApFull(), rinnovoMailMsg); mf.setQuestionMark(false); mf.setString("data", getDataFormat().format(new java.util.Date())); mf.setString("nome", getNome()); mf.setString("cognome", getCognome()); if (anni == 1) { annifoto = "" + anni + " anno e " + anni + " foto"; } else { annifoto = "" + anni + " anni e " + anni + " foto"; } mf.setString("annifoto", annifoto); rp = mf.sendMailMessageSystem(getEMail(), "Regalami un Sorriso - Rinnovo " + annifoto, true); } else { rp.setStatus(false); rp.setMsg("Email non in archivio!"); } } catch (Exception e) { handleDebug(e); rp.setStatus(false); rp.setMsg("ERRORE INVIO MAIL: " + e.getMessage()); } return rp; } protected String getUserMailMessage() { return getParm("MAIL_REG").getTesto(); } protected String getNoMorePicNumberMailMessage() { return getDocBase() + getDocBase(); } public boolean isUseControCodeAccess() { return true; } public long getFlgMailFotoMax() { return this.flgMailFotoMax; } public void setFlgMailFotoMax(long flgMailFotoMax) { this.flgMailFotoMax = flgMailFotoMax; } public ResParm sendNoMorePictureMessageScad() { ResParm rp = new ResParm(true); if (getFlgMailFotoScadenza() == 0L) try { if (getDBState() == 1) { boolean lockOk = trySetFlgMailFotoScadenzaToYesIfNo(); if (!lockOk) return rp; String userMailMessage = getNoMorePicScadMailMessage(); if (!getControlCode().isEmpty()) userMailMessage = userMailMessage.substring(0, userMailMessage.length() - 5) + "CC" + userMailMessage.substring(0, userMailMessage.length() - 5); MailMessage mf = new MailMessage(getApFull(), userMailMessage); mf.setQuestionMark(false); mf.setString("data", getDataFormat().format(new java.util.Date())); mf.setString("nome", getNome()); mf.setString("cognome", getCognome()); rp = mf.sendMailMessageSystem(getEMail(), mf.getMailSubject() + " Account Scaduto ", true); } else { rp.setStatus(false); rp.setMsg("Email non in archivio"); } } catch (Exception e) { handleDebug(e); rp.setStatus(false); rp.setMsg(e.getMessage()); } return rp; } public long getFlgMailFotoScadenza() { return this.flgMailFotoScadenza; } public void setFlgMailFotoScadenza(long flgMailFotoScadenza) { this.flgMailFotoScadenza = flgMailFotoScadenza; } protected String getNoMorePicScadMailMessage() { return getDocBase() + getDocBase(); } public long getFlgMiniature() { return this.flgMiniature; } public void setFlgMiniature(long flgMiniature) { this.flgMiniature = flgMiniature; } public void initApplicationParms(ApplParmFull ap) { if (ap != null) { super.initApplicationParms(ap); PeReq.initApplicationParms(ap); SellaReq.initApplicationParms(ap); PayPalReq.initApplicationParms(ap); String l_tipoParm = ""; Parm bean = new Parm(ap); l_tipoParm = "GIACOMELLI"; bean.findByCodice("PATHFOTO"); bean.setFlgAdmin(1L); bean.setTipoParm(l_tipoParm); bean.setCodice("PATHFOTO"); bean.setDescrizione("PATHFOTO"); bean.setFlgTipo(0L); if (bean.getTesto().isEmpty()) bean.setTesto("/home/sites/regalamiunsorriso/RUS/"); bean.setNota("Percorso ASSOLUTO dove risiedono tutte le foto sorgenti.
Produzione: /home/sites/regalamiunsorriso/RUS/
Test: /Users/acolzi/Documents/webapps/rus/mypics2/RUS/"); bean.save(); bean.findByCodice("PATHFOTO_RIDOTTE"); bean.setFlgAdmin(1L); bean.setTipoParm(l_tipoParm); bean.setCodice("PATHFOTO_RIDOTTE"); bean.setDescrizione("PATHFOTO_RIDOTTE"); bean.setFlgTipo(0L); if (bean.getTesto().isEmpty()) bean.setTesto("/mnt/foto/catalog/"); bean.setNota("Percorso ASSOLUTO dove risiedono tutte le foto RIDOTTE.
Produzione RUS MINT CASA E UFFICIO: /mnt/foto/catalog/
"); bean.save(); bean.findByCodice("MAX_CONCURRENT_THREAD"); bean.setFlgAdmin(0L); bean.setTipoParm(l_tipoParm); bean.setCodice("MAX_CONCURRENT_THREAD"); bean.setDescrizione("MAX_CONCURRENT_THREAD"); bean.setFlgTipo(1L); if (bean.getNumero() <= 1.0D) bean.setNumero(10.0D); bean.setNota("Numero thread concorrenti utilizzato per la riduzione foto
In locale 10 sembra il valore ottimale"); bean.save(); bean.findByCodice("MAX_CONCURRENT_UPLOAD_THREAD"); bean.setFlgAdmin(0L); bean.setTipoParm(l_tipoParm); bean.setCodice("MAX_CONCURRENT_UPLOAD_THREAD"); bean.setDescrizione("MAX_CONCURRENT_UPLOAD_THREAD"); bean.setFlgTipo(1L); if (bean.getNumero() <= 1.0D) bean.setNumero(10.0D); bean.setNota("Numero thread concorrenti utilizzato per L'UPLOAD via http o ftp"); bean.save(); bean.findByCodice("MAIL_MSG_RINNOVO"); bean.setFlgAdmin(1L); bean.setTipoParm(l_tipoParm); bean.setCodice("MAIL_MSG_RINNOVO"); bean.setDescrizione("MAIL_MSG_RINNOVO"); bean.setFlgTipo(0L); if (bean.getTesto().isEmpty()) bean.setTesto("mailMessage/rinnovoMsg.html"); bean.setNota("Percorso RELATIVO messaggio rinnovo"); bean.save(); bean.findByCodice("MAIL_MSG_COUPON_OMAGGIO"); bean.setFlgAdmin(1L); bean.setTipoParm(l_tipoParm); bean.setCodice("MAIL_MSG_COUPON_OMAGGIO"); bean.setDescrizione("MAIL_MSG_COUPON_OMAGGIO"); bean.setFlgTipo(0L); if (bean.getTesto().isEmpty()) bean.setTesto("mailMessage/couponOmaggioMsg.html"); bean.setNota("Percorso RELATIVO messaggio COUPON OMAGGIO"); bean.save(); bean.findByCodice("OCR_COMANDO_SHELL_PRODUZIONE"); bean.setFlgAdmin(1L); bean.setTipoParm(l_tipoParm); bean.setCodice("OCR_COMANDO_SHELL_PRODUZIONE"); bean.setDescrizione("OCR_COMANDO_SHELL_PRODUZIONE"); bean.setFlgTipo(0L); if (bean.getTesto().isEmpty()) bean.setTesto("/home/piero/Documenti/sites/bin/indicizzaR.sh"); bean.setNota("/home/piero/Documenti/sites/bin/indicizzaR.sh
/home/sites/bin/indicizzaR.sh"); bean.save(); bean.findByCodice("OCR_COMANDO_SHELL_TEST"); bean.setFlgAdmin(1L); bean.setTipoParm(l_tipoParm); bean.setCodice("OCR_COMANDO_SHELL_TEST"); bean.setDescrizione("OCR_COMANDO_SHELL_TEST"); bean.setFlgTipo(0L); if (bean.getTesto().isEmpty()) bean.setTesto("/Users/acolzi/Documents/_ablia/work/PG/bin/test.sh"); bean.setNota("/Users/acolzi/Documents/_ablia/work/PG/bin/test.sh
/Users/acolzi/Documents/_ablia/work/PG/bin/test.sh"); bean.save(); bean.findByCodice("OCR_LINEE_FILE_PRODUZIONE"); bean.setFlgAdmin(1L); bean.setTipoParm(l_tipoParm); bean.setCodice("OCR_LINEE_FILE_PRODUZIONE"); bean.setDescrizione("OCR_LINEE_FILE_PRODUZIONE"); bean.setFlgTipo(0L); if (bean.getTesto().isEmpty()) bean.setTesto("/home/piero/Documenti/sites/bin/tmp/"); bean.setNota("/home/piero/Documenti/sites/bin/tmp/
/home/sites/bin/tmp/"); bean.save(); bean.findByCodice("OCR_LINEE_FILE_TEST"); bean.setFlgAdmin(1L); bean.setTipoParm(l_tipoParm); bean.setCodice("OCR_LINEE_FILE_TEST"); bean.setDescrizione("OCR_LINEE_FILE_TEST"); bean.setFlgTipo(0L); if (bean.getTesto().isEmpty()) bean.setTesto("/Users/acolzi/Documents/_ablia/work/PG/bin/tmp/"); bean.setNota("/Users/acolzi/Documents/_ablia/work/PG/bin/tmp/
/Users/acolzi/Documents/_ablia/work/PG/bin/tmp/"); bean.save(); bean.findByCodice("NUM_GG_PRIMA_DELLA_SCADENZA_RINNOVO"); bean.setFlgAdmin(1L); bean.setTipoParm(l_tipoParm); bean.setCodice("NUM_GG_PRIMA_DELLA_SCADENZA_RINNOVO"); bean.setDescrizione("NUM_GG_PRIMA_DELLA_SCADENZA_RINNOVO"); bean.setFlgTipo(1L); bean.setNota("Numero di giorni prima da cui รจ possibile rinnovare l'abbonamento"); bean.save(); bean.findByCodice("MAIL_MSG_STA_PER_SCADERE"); bean.setFlgAdmin(1L); bean.setTipoParm(l_tipoParm); bean.setCodice("MAIL_MSG_STA_PER_SCADERE"); bean.setDescrizione("MAIL_MSG_STA_PER_SCADERE"); bean.setFlgTipo(0L); if (bean.getTesto().isEmpty()) bean.setTesto("mailMessage/perscadereMsg.html"); bean.setNota("Percorso RELATIVO messaggio sta per scadere"); bean.save(); } } public boolean isScaduto() { return isScaduto(true); } public boolean isFotoMaxRaggiunto() { if (getId_users() == 0L) return true; if (getNFotoMax() > 0L && getNFotoVisual() >= getNFotoMax()) { sendNoMorePictureMessageNumber(); return true; } return false; } public boolean puoScaricareFoto() { return (!isFotoMaxRaggiunto() && !isScaduto()); } public long getGgAScadenza() { if (getId_users() == 0L) return -1L; return DBAdapter.getDateDiff(DBAdapter.getToday(), getDataScadenza()); } public static final synchronized void addLogFoto(Users user, Foto row, ApplParmFull ap) { LogFoto log = new LogFoto(ap); log.setIpAddress(ap.getReqIpAddress()); log.setDataLog(DBAdapter.getToday()); log.setId_foto(row.getId_foto()); log.setId_users(user.getId_users()); ResParm rp = log.save(); if (row.getPuntoFoto().getGara().getFlgFree() == 0L) user.incrementaFotoVisual(); Foto.addImpression(row, ap); } public static final synchronized void addLogFoto(Users user, String fileName, ApplParmFull ap) { LogFoto log = new LogFoto(ap); log.setIpAddress(ap.getReqIpAddress()); log.setDataLog(DBAdapter.getToday()); if (fileName.indexOf("mypics2") > 0) { log.setDescrizione(fileName.substring(fileName.indexOf("mypics2"))); } else if (fileName.indexOf("mypics") > 0) { log.setDescrizione(fileName.substring(fileName.indexOf("mypics"))); } else { log.setDescrizione(fileName); } log.setId_users(user.getId_users()); ResParm rp = log.save(); user.incrementaFotoVisual(); Foto.addImpression(fileName, ap); } public long getFlgVisCompatta() { return this.flgVisCompatta; } public void setFlgVisCompatta(long flgVisCompatta) { this.flgVisCompatta = flgVisCompatta; } public void aggiornaVisCompatta(long l_flgVisCompatta) { if (getId_users() > 0L) { setFlgVisCompatta(l_flgVisCompatta); save(); } } public ResParm rinnovaAnno(long n_foto, int l_numAnni) { System.out.println("rinnova anno foto:" + n_foto + " anni:" + l_numAnni + ": cliente: " + getCognomeNome()); if (n_foto == 0L) n_foto = 1000L; if (getId_users() == 0L) return new ResParm(false, "ERRORE! Tentativo di rinnovare utente nullo."); if (isDaRinnovare(false) || getNFotoMax() == 1L) { Calendar cal = Calendar.getInstance(); if (getDateDiff(getToday(), getDataScadenza()) > 0L) cal.setTime(getDataScadenza()); cal.add(1, l_numAnni); setDataScadenza(new Date(cal.getTimeInMillis())); setFlgMailFotoMax(0L); setFlgMailFotoScadenza(0L); setFlgMiniature(0L); setNFotoVisual(0L); setNFotoMax(n_foto); ResParm rp = save(); if (rp.getStatus()) rp.setMsg("Utente " + getCognomeNome() + " rinnovato fino al " + getDataFormat().format(getDataScadenza()) + " per " + getNFotoMax() + " foto
"); return rp; } return new ResParm(false, "Attenzione! Tentativo di rinnovare utente non ancora scaduto."); } public boolean isScaduto(boolean inviaMail) { if (getId_users() == 0L) return true; if (getDataScadenza() != null && DBAdapter.getDateDiff(DBAdapter.getToday(), getDataScadenza()) <= 0L) { if (inviaMail) sendNoMorePictureMessageScad(); return true; } return false; } public boolean isDaRinnovare() { return isDaRinnovare(true); } public boolean isDaRinnovare(boolean inviaMail) { long ggPrimaScadenza = getParm("NUM_GG_PRIMA_DELLA_SCADENZA_RINNOVO").getNumeroLong(); return (isScaduto(inviaMail) || DBAdapter.getDateDiff(DBAdapter.getToday(), getDataScadenza()) < ggPrimaScadenza || isFotoMaxRaggiunto() || getFlgMiniature() == 1L); } public boolean isScadutoPerSito(boolean inviaMail) { return (isScaduto(inviaMail) || isFotoMaxRaggiunto() || getFlgMiniature() == 1L); } public boolean isScadutoPerSito() { return isScadutoPerSito(true); } public boolean isDatiPaypalOk() { if (getCognomeNome().isEmpty() || getIndirizzo().isEmpty() || getCap().isEmpty() || getProvincia().isEmpty()) return false; return true; } public ResParm sendNoMorePictureMessageNumber() { ResParm rp = new ResParm(true); if (getFlgMailFotoMax() == 0L) try { if (getDBState() == 1) { boolean lockOk = trySetFlgMailFotoMaxToYesIfNo(); if (!lockOk) return rp; String userMailMessage = getNoMorePicNumberMailMessage(); if (!getControlCode().isEmpty()) userMailMessage = userMailMessage.substring(0, userMailMessage.length() - 5) + "CC" + userMailMessage.substring(0, userMailMessage.length() - 5); MailMessage mf = new MailMessage(getApFull(), userMailMessage); mf.setQuestionMark(false); mf.setString("data", getDataFormat().format(new java.util.Date())); mf.setString("nome", getNome()); mf.setString("cognome", getCognome()); rp = mf.sendMailMessageSystem(getEMail(), mf.getMailSubject() + " Max num. foto raggiunto ", true); } else { rp.setStatus(false); rp.setMsg("Email non in archivio"); } } catch (Exception e) { handleDebug(e); rp.setStatus(false); rp.setMsg(e.getMessage()); } return rp; } private boolean trySetFlgMailFotoMaxToYesIfNo() { String s_sql_string = "UPDATE USERS SET flgMailFotoMax = 1"; WcString wc = new WcString(); wc.addWc("id_users=" + getId_users()); wc.addWc("(flgMailFotoMax = 0 or flgMailFotoMax is null)"); ResParm rp = update(s_sql_string + s_sql_string); if (rp.getStatus()) { if (rp.getErrorCode() < 0L) return false; return true; } return false; } private boolean trySetFlgMailFotoScadenzaToYesIfNo() { String s_sql_string = "UPDATE USERS SET flgMailFotoScadenza = 1"; WcString wc = new WcString(); wc.addWc("id_users=" + getId_users()); wc.addWc("(flgMailFotoScadenza = 0 or flgMailFotoScadenza is null)"); ResParm rp = update(s_sql_string + s_sql_string); if (rp.getStatus()) { if (rp.getErrorCode() < 0L) return false; return true; } return false; } public ResParm sendCouponOmaggioMailMessage() { ResParm rp = new ResParm(true); try { if (getDBState() == 1) { String key = "mail-coupon-" + getId_users(); long now = System.currentTimeMillis(); Long lastSent = couponOmaggioMailSent.get(key); if (lastSent != null && now - lastSent < 10000L) return new ResParm(true); synchronized (couponOmaggioMailSent) { lastSent = couponOmaggioMailSent.get(key); if (lastSent != null && now - lastSent < 10000L) return new ResParm(true); couponOmaggioMailSent.put(key, Long.valueOf(now)); } String rinnovoMailMsg = getDocBase() + getDocBase(); MailMessage mf = new MailMessage(getApFull(), rinnovoMailMsg); mf.setQuestionMark(false); mf.setString("data", getDataFormat().format(new java.util.Date())); mf.setString("nome", getNome()); mf.setString("cognome", getCognome()); rp = mf.sendMailMessageSystem(getEMail(), mf.getMailSubject() + " Coupon Omaggio ", true); } else { rp.setStatus(false); rp.setMsg("Email non in archivio!"); } } catch (Exception e) { handleDebug(e); rp.setStatus(false); rp.setMsg(e.getMessage()); } return rp; } public ResParm sendScadeABreveMailMessage() { ResParm rp = new ResParm(true); try { if (getDBState() == 1) { String key = "mail-scadenza-" + getId_users(); long now = System.currentTimeMillis(); Long lastSent = scadABreveMailSent.get(key); if (lastSent != null && now - lastSent < 10000L) return new ResParm(true); synchronized (scadABreveMailSent) { lastSent = scadABreveMailSent.get(key); if (lastSent != null && now - lastSent < 10000L) return new ResParm(true); scadABreveMailSent.put(key, Long.valueOf(now)); } String rinnovoMailMsg = getDocBase() + getDocBase(); MailMessage mf = new MailMessage(getApFull(), rinnovoMailMsg); mf.setQuestionMark(false); mf.setString("data", getDataFormat().format(new java.util.Date())); mf.setString("nome", getNome()); mf.setString("cognome", getCognome()); long ggScadenza = DBAdapter.getDateDiff(DBAdapter.getToday(), getDataScadenza()); mf.setLong("gg", ggScadenza); rp = mf.sendMailMessageSystem(getEMail(), "Regalami un Sorriso - Rinnovo tra " + ggScadenza + " giorni", true); } else { rp.setStatus(false); rp.setMsg("Email non in archivio!"); } } catch (Exception e) { handleDebug(e); rp.setStatus(false); rp.setMsg("ERRORE INVIO MAIL: " + e.getMessage()); } return rp; } public Vectumerator findInScadenza(int ggPrimaDellaScadenza) { String s_Sql_Find = "select A.* from USERS AS A"; WcString wc = new WcString(); wc.addWc("dataFineVld is null"); wc.addWc("A.flgValido='S'"); wc.addWc("A.dataScadenza=?"); try { PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find); int dataCount = 0; Calendar cal = Calendar.getInstance(); cal.add(6, ggPrimaDellaScadenza); dataCount++; stmt.setDate(dataCount, new Date(cal.getTimeInMillis())); return findRows(stmt); } catch (Exception e) { handleDebug(e); return AB_EMPTY_VECTUMERATOR; } } public ResParm crontabJob(ApplParmFull ap) { ResParm rp = new ResParm(true); Timer timer = new Timer(); timer.start(); System.out.println("RUS User crontab start..."); StringBuffer msg = new StringBuffer("\n################# Inizio RUS User crontab (" + DBAdapter.getNow().toString() + ")\n#################"); Users user = new Users(ap); int ggPrimaDellaScadenza = ap.getParm("NUM_GG_PRIMA_DELLA_SCADENZA_RINNOVO").getNumeroInt(); Vectumerator vec = user.findInScadenza(ggPrimaDellaScadenza); while (vec.hasMoreElements()) { Users row = (Users)vec.nextElement(); System.out.println(row.getCognomeNome() + " " + row.getCognomeNome() + " " + row.getEMail()); rp = row.sendScadeABreveMailMessage(); msg.append(rp.getMsg()); msg.append("\n"); } msg.append(rp.getMsg()); msg.append("\n################# Fine RUS User crontab (" + DBAdapter.getNow().toString() + ")\n#################"); timer.stop(); msg.append("Durata aggiornamento: " + timer.getDurataHourMin() + "\n"); rp.setMsg(msg.toString()); System.out.println(msg.toString()); return rp; } }