388 lines
11 KiB
Java
388 lines
11 KiB
Java
|
|
package it.acxent.banner;
|
||
|
|
|
||
|
|
import it.acxent.anag.Clifor;
|
||
|
|
import it.acxent.anag._AnagAdapter;
|
||
|
|
import it.acxent.db.AddImgInterface;
|
||
|
|
import it.acxent.db.ApplParmFull;
|
||
|
|
import it.acxent.db.ResParm;
|
||
|
|
import it.acxent.db.WcString;
|
||
|
|
import it.acxent.util.StringTokenizer;
|
||
|
|
import it.acxent.util.Vectumerator;
|
||
|
|
import java.io.Serializable;
|
||
|
|
import java.sql.Date;
|
||
|
|
import java.sql.PreparedStatement;
|
||
|
|
import java.util.Random;
|
||
|
|
|
||
|
|
public class Banner extends _AnagAdapter implements AddImgInterface, Serializable {
|
||
|
|
private static final long serialVersionUID = 5881146247767448667L;
|
||
|
|
|
||
|
|
private long id_banner;
|
||
|
|
|
||
|
|
private long id_tipoBanner;
|
||
|
|
|
||
|
|
private long flgAttivo;
|
||
|
|
|
||
|
|
private String descrizioneClifor;
|
||
|
|
|
||
|
|
private Date dataInizioCampagna;
|
||
|
|
|
||
|
|
private Date dataFineCampagna;
|
||
|
|
|
||
|
|
private long priorita;
|
||
|
|
|
||
|
|
private TipoBanner tipoBanner;
|
||
|
|
|
||
|
|
private Clifor clifor;
|
||
|
|
|
||
|
|
private long flgTipo;
|
||
|
|
|
||
|
|
private long impression;
|
||
|
|
|
||
|
|
private long clickThrough;
|
||
|
|
|
||
|
|
public Banner(ApplParmFull newApplParmFull) {
|
||
|
|
super(newApplParmFull);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static long TIPO_IMMAGINE = 0L;
|
||
|
|
|
||
|
|
public static long TIPO_TESTO = 1L;
|
||
|
|
|
||
|
|
private String link;
|
||
|
|
|
||
|
|
private String descrizioneBanner;
|
||
|
|
|
||
|
|
private String titolo;
|
||
|
|
|
||
|
|
private long id_clifor;
|
||
|
|
|
||
|
|
public Banner() {
|
||
|
|
initFields();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setId_banner(long newId_banner) {
|
||
|
|
this.id_banner = newId_banner;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setId_tipoBanner(long newId_tipoBanner) {
|
||
|
|
this.id_tipoBanner = newId_tipoBanner;
|
||
|
|
setTipoBanner(null);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setId_clifor(long newId_clifor) {
|
||
|
|
this.id_clifor = newId_clifor;
|
||
|
|
setClifor(null);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setLink(String newLink) {
|
||
|
|
this.link = newLink;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setDataInizioCampagna(Date newDataInizioCampagna) {
|
||
|
|
this.dataInizioCampagna = newDataInizioCampagna;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setDataFineCampagna(Date newDataFineCampagna) {
|
||
|
|
this.dataFineCampagna = newDataFineCampagna;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setPriorita(long newPeso) {
|
||
|
|
this.priorita = newPeso;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getId_banner() {
|
||
|
|
return this.id_banner;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getId_tipoBanner() {
|
||
|
|
return this.id_tipoBanner;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getId_clifor() {
|
||
|
|
return this.id_clifor;
|
||
|
|
}
|
||
|
|
|
||
|
|
public String getLink() {
|
||
|
|
if (this.link == null)
|
||
|
|
return "";
|
||
|
|
if (this.link.toLowerCase().startsWith("http://") || this.link.toLowerCase().startsWith("https://"))
|
||
|
|
return this.link.trim();
|
||
|
|
return "http://" + this.link.trim();
|
||
|
|
}
|
||
|
|
|
||
|
|
public Date getDataInizioCampagna() {
|
||
|
|
return this.dataInizioCampagna;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Date getDataFineCampagna() {
|
||
|
|
return this.dataFineCampagna;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getPriorita() {
|
||
|
|
return this.priorita;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected ResParm checkDeleteCascade() {
|
||
|
|
return new ResParm(true);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void deleteCascade() {}
|
||
|
|
|
||
|
|
public void setTipoBanner(TipoBanner newTipoBanner) {
|
||
|
|
this.tipoBanner = newTipoBanner;
|
||
|
|
}
|
||
|
|
|
||
|
|
public TipoBanner getTipoBanner() {
|
||
|
|
if (this.tipoBanner == null && getId_tipoBanner() != 0L)
|
||
|
|
try {
|
||
|
|
this.tipoBanner = new TipoBanner(getApFull());
|
||
|
|
this.tipoBanner.findByPrimaryKey(new Long(getId_tipoBanner()));
|
||
|
|
} catch (Exception e) {}
|
||
|
|
return (this.tipoBanner == null) ? new TipoBanner() : this.tipoBanner;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setClifor(Clifor newClifor) {
|
||
|
|
this.clifor = newClifor;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Clifor getClifor() {
|
||
|
|
this.clifor = (Clifor)getSecondaryObject(this.clifor, Clifor.class, getId_clifor());
|
||
|
|
return this.clifor;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getFlgAttivo() {
|
||
|
|
return this.flgAttivo;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setFlgAttivo(long flgAttivo) {
|
||
|
|
this.flgAttivo = flgAttivo;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getImpression() {
|
||
|
|
return this.impression;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setImpression(long impression) {
|
||
|
|
this.impression = impression;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getClickThrough() {
|
||
|
|
return this.clickThrough;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setClickThrough(long clickThrough) {
|
||
|
|
this.clickThrough = clickThrough;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void addBannerStats(String l_entryPoint, String l_ip, String l_flgI_CT) {}
|
||
|
|
|
||
|
|
public String getTitolo() {
|
||
|
|
return (this.titolo == null) ? "" : this.titolo.trim();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setTitolo(String titolo) {
|
||
|
|
this.titolo = titolo;
|
||
|
|
}
|
||
|
|
|
||
|
|
public String getDescrizioneBanner() {
|
||
|
|
return (this.descrizioneBanner == null) ? "" : this.descrizioneBanner.trim();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setDescrizioneBanner(String descrizioneBanner) {
|
||
|
|
this.descrizioneBanner = descrizioneBanner;
|
||
|
|
}
|
||
|
|
|
||
|
|
public String getDescrizioneClifor() {
|
||
|
|
if (getId_clifor() != 0L)
|
||
|
|
return getClifor().getDescrizioneCompleta();
|
||
|
|
return (this.descrizioneClifor == null) ? "" : this.descrizioneClifor.trim();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setDescrizioneClifor(String descrizioneClifor) {
|
||
|
|
this.descrizioneClifor = descrizioneClifor;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Vectumerator findByCR(BannerCR CR, int pageNumber, int pageRows) {
|
||
|
|
String s_Sql_Find = "select A.* from BANNER AS A";
|
||
|
|
String s_Sql_Order = " ORDER BY A.descrizioneClifor ";
|
||
|
|
WcString wc = new WcString();
|
||
|
|
if (!CR.getDescrizioneClifor().trim().isEmpty()) {
|
||
|
|
StringTokenizer st = new StringTokenizer(CR.getDescrizioneClifor().trim(), " ");
|
||
|
|
StringBuffer txt = new StringBuffer("(");
|
||
|
|
while (st.hasMoreTokens()) {
|
||
|
|
String token = st.nextToken();
|
||
|
|
txt.append("(A.descrizioneClifor like '%" + token + "%')");
|
||
|
|
if (st.hasMoreTokens())
|
||
|
|
txt.append(" and ");
|
||
|
|
}
|
||
|
|
txt.append(")");
|
||
|
|
wc.addWc(txt.toString());
|
||
|
|
}
|
||
|
|
if (CR.getFlgAttivo() == 0L) {
|
||
|
|
wc.addWc("(A.flgAttivo is null or A.flgAttivo=0 or A.dataFineVld is null)");
|
||
|
|
} else if (CR.getFlgAttivo() > 0L) {
|
||
|
|
wc.addWc("A.flgAttivo = 1");
|
||
|
|
wc.addWc("A.dataFineVld is not null");
|
||
|
|
}
|
||
|
|
if (CR.getDataFineCampagnaDa() != null)
|
||
|
|
wc.addWc("A.dataFineCampagna >= ? ");
|
||
|
|
if (CR.getDataFineCampagnaA() != null)
|
||
|
|
wc.addWc("A.dataFineCampagna <= ? ");
|
||
|
|
try {
|
||
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
|
||
|
|
int dataCount = 0;
|
||
|
|
if (CR.getDataFineCampagnaDa() != null) {
|
||
|
|
dataCount++;
|
||
|
|
stmt.setDate(dataCount, CR.getDataFineCampagnaDa());
|
||
|
|
}
|
||
|
|
if (CR.getDataFineCampagnaA() != null) {
|
||
|
|
dataCount++;
|
||
|
|
stmt.setDate(dataCount, CR.getDataFineCampagnaA());
|
||
|
|
}
|
||
|
|
return findRows(stmt, pageNumber, pageRows);
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e, 2);
|
||
|
|
return AB_EMPTY_VECTUMERATOR;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public String getPathImgBanner() {
|
||
|
|
return getParm("PATH_IMG_BANNER").getTesto();
|
||
|
|
}
|
||
|
|
|
||
|
|
protected int getStringValueCase(String l_colomnName) {
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Banner getRandomBanner(long l_id_tipoBanner) {
|
||
|
|
String s_Sql_Find = "select A.* from BANNER AS A";
|
||
|
|
String wc = "";
|
||
|
|
String wcPrior = "";
|
||
|
|
wc = buildWc(wc, "A.id_tipoBanner =" + l_id_tipoBanner);
|
||
|
|
wc = buildWc(wc, "A.dataFineVld is null");
|
||
|
|
wc = buildWc(wc, "A.flgAttivo=1");
|
||
|
|
wc = buildWc(wc, "A.dataInizioCampagna<=?");
|
||
|
|
wc = buildWc(wc, "A.dataFineCampagna>=?");
|
||
|
|
int prioritySeed = (int)(Math.random() * 10.0D);
|
||
|
|
wcPrior = " and A.priorita>" + prioritySeed;
|
||
|
|
try {
|
||
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc);
|
||
|
|
stmt.setDate(1, getToday());
|
||
|
|
stmt.setDate(2, getToday());
|
||
|
|
Vectumerator vec = findRows(stmt, 0, 0);
|
||
|
|
while (vec.getTotNumberOfRecords() == 0 && prioritySeed-- > 0) {
|
||
|
|
wcPrior = " and A.priorita>" + prioritySeed;
|
||
|
|
stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc);
|
||
|
|
stmt.setDate(1, getToday());
|
||
|
|
stmt.setDate(2, getToday());
|
||
|
|
vec = findRows(stmt, 0, 0);
|
||
|
|
}
|
||
|
|
int totBanner = vec.getTotNumberOfRecords();
|
||
|
|
if (totBanner > 0) {
|
||
|
|
int idx = (int)(Math.random() * (double)totBanner);
|
||
|
|
return (Banner)vec.elementAt(idx);
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
} catch (Exception e) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void addClickThrough(String ipAddress, String entryPoint) {
|
||
|
|
try {
|
||
|
|
if (getDBState() == 1)
|
||
|
|
synchronized (this) {
|
||
|
|
setClickThrough(getClickThrough() + 1L);
|
||
|
|
ResParm resParm = save();
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void addImpression(String ipAddress, String entryPoint) {
|
||
|
|
try {
|
||
|
|
if (getDBState() == 1)
|
||
|
|
synchronized (this) {
|
||
|
|
setImpression(getImpression() + 1L);
|
||
|
|
ResParm resParm = save();
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getFlgTipo() {
|
||
|
|
return this.flgTipo;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setFlgTipo(long flgTipo) {
|
||
|
|
this.flgTipo = flgTipo;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static String getTipo(long l_flgTipo) {
|
||
|
|
if (l_flgTipo == TIPO_IMMAGINE)
|
||
|
|
return "Immagine";
|
||
|
|
return "Testo";
|
||
|
|
}
|
||
|
|
|
||
|
|
public String getTipo() {
|
||
|
|
return getTipo(getFlgTipo());
|
||
|
|
}
|
||
|
|
|
||
|
|
public Vectumerator<Banner> findRandomBannerAttivi(long l_id_tipoBanner, long totBanner) {
|
||
|
|
String limit;
|
||
|
|
boolean debug = false;
|
||
|
|
String s_Sql_Find = "select A.* from BANNER AS A";
|
||
|
|
String s_Sql_order = " order by rand()";
|
||
|
|
WcString wc = new WcString();
|
||
|
|
String wcPrior = "";
|
||
|
|
if (totBanner == 0L) {
|
||
|
|
limit = "";
|
||
|
|
} else {
|
||
|
|
limit = " limit " + totBanner;
|
||
|
|
}
|
||
|
|
wc.addWc("A.id_tipoBanner =" + l_id_tipoBanner);
|
||
|
|
wc.addWc("A.dataFineVld is null");
|
||
|
|
wc.addWc("A.flgAttivo=1");
|
||
|
|
wc.addWc("A.dataInizioCampagna<=?");
|
||
|
|
wc.addWc("(A.dataFineCampagna is null or A.dataFineCampagna>=?)");
|
||
|
|
Random r = new Random();
|
||
|
|
int prioritySeed = Math.abs(r.nextInt()) % 11;
|
||
|
|
if (totBanner > 0L)
|
||
|
|
wcPrior = " and A.priorita>=" + prioritySeed;
|
||
|
|
try {
|
||
|
|
if (debug)
|
||
|
|
System.out.println(s_Sql_Find + s_Sql_Find + wc.toString() + wcPrior + s_Sql_order);
|
||
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + wcPrior + s_Sql_order);
|
||
|
|
stmt.setDate(1, getToday());
|
||
|
|
stmt.setDate(2, getToday());
|
||
|
|
Vectumerator<Banner> vec = findRows(stmt, 0, 0);
|
||
|
|
if (totBanner > 0L)
|
||
|
|
while ((long)vec.getTotNumberOfRecords() < totBanner && prioritySeed-- >= 0) {
|
||
|
|
wcPrior = " and A.priorita>=" + prioritySeed;
|
||
|
|
if (debug)
|
||
|
|
System.out.println("" + prioritySeed + ": " + prioritySeed + s_Sql_Find + wc.toString() + wcPrior + s_Sql_order);
|
||
|
|
stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + wcPrior + s_Sql_order);
|
||
|
|
stmt.setDate(1, getToday());
|
||
|
|
stmt.setDate(2, getToday());
|
||
|
|
vec = findRows(stmt, 0, 0);
|
||
|
|
}
|
||
|
|
return vec;
|
||
|
|
} catch (Exception e) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public boolean useDescLangTables() {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public String getLink(String lang) {
|
||
|
|
return getDescTxtLang("link", lang.isEmpty() ? "it" : lang);
|
||
|
|
}
|
||
|
|
|
||
|
|
public String getPathImg() {
|
||
|
|
return getPathImgBanner();
|
||
|
|
}
|
||
|
|
}
|