228 lines
6.7 KiB
Java
228 lines
6.7 KiB
Java
package it.acxent.art;
|
|
|
|
import it.acxent.anag.Nazione;
|
|
import it.acxent.db.ApplParmFull;
|
|
import it.acxent.db.DBAdapter;
|
|
import it.acxent.db.ResParm;
|
|
import it.acxent.db.WcString;
|
|
import it.acxent.util.DoubleOperator;
|
|
import it.acxent.util.StringTokenizer;
|
|
import it.acxent.util.Vectumerator;
|
|
import java.io.Serializable;
|
|
import java.sql.Date;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.SQLException;
|
|
|
|
public class AmzFeaturedPrice extends DBAdapter implements Serializable {
|
|
private static final long serialVersionUID = 1681244662207L;
|
|
|
|
private long id_amzFeaturedPrice;
|
|
|
|
private long id_articolo;
|
|
|
|
private String lang;
|
|
|
|
private double featuredOEPriceAmz;
|
|
|
|
private double competingFOPriceAmz;
|
|
|
|
private double currentFOPriceAmz;
|
|
|
|
private double currentPriceAmz;
|
|
|
|
private Date dataPriceAmz;
|
|
|
|
private long flgPrezzoCompetitivoAmz;
|
|
|
|
private long flgPrezzoCompetitivo;
|
|
|
|
private Articolo articolo;
|
|
|
|
public AmzFeaturedPrice(ApplParmFull newApplParmFull) {
|
|
super(newApplParmFull);
|
|
}
|
|
|
|
public AmzFeaturedPrice() {}
|
|
|
|
public void setId_amzFeaturedPrice(long newId_amzFeaturedPrice) {
|
|
this.id_amzFeaturedPrice = newId_amzFeaturedPrice;
|
|
}
|
|
|
|
public void setId_articolo(long newId_articolo) {
|
|
this.id_articolo = newId_articolo;
|
|
setArticolo(null);
|
|
}
|
|
|
|
public void setLang(String newLang) {
|
|
this.lang = newLang;
|
|
}
|
|
|
|
public void setFeaturedOEPriceAmz(double newFeaturedOEPriceAmz) {
|
|
this.featuredOEPriceAmz = newFeaturedOEPriceAmz;
|
|
}
|
|
|
|
public void setCompetingFOPriceAmz(double newCompetingFOPriceAmz) {
|
|
this.competingFOPriceAmz = newCompetingFOPriceAmz;
|
|
}
|
|
|
|
public void setCurrentFOPriceAmz(double newCurrentFOPriceAmz) {
|
|
this.currentFOPriceAmz = newCurrentFOPriceAmz;
|
|
}
|
|
|
|
public void setCurrentPriceAmz(double newCurrentPriceAmz) {
|
|
this.currentPriceAmz = newCurrentPriceAmz;
|
|
}
|
|
|
|
public long getId_amzFeaturedPrice() {
|
|
return this.id_amzFeaturedPrice;
|
|
}
|
|
|
|
public long getId_articolo() {
|
|
return this.id_articolo;
|
|
}
|
|
|
|
public String getLang() {
|
|
return (this.lang == null) ? "" : this.lang.trim();
|
|
}
|
|
|
|
public double getFeaturedOEPriceAmz() {
|
|
return this.featuredOEPriceAmz;
|
|
}
|
|
|
|
public double getCompetingFOPriceAmz() {
|
|
return this.competingFOPriceAmz;
|
|
}
|
|
|
|
public double getCurrentFOPriceAmz() {
|
|
return this.currentFOPriceAmz;
|
|
}
|
|
|
|
public double getCurrentPriceAmz() {
|
|
return this.currentPriceAmz;
|
|
}
|
|
|
|
public void setArticolo(Articolo newArticolo) {
|
|
this.articolo = newArticolo;
|
|
}
|
|
|
|
public Articolo getArticolo() {
|
|
this.articolo = (Articolo)getSecondaryObject(this.articolo, Articolo.class, getId_articolo());
|
|
return this.articolo;
|
|
}
|
|
|
|
protected ResParm checkDeleteCascade() {
|
|
return new ResParm(true);
|
|
}
|
|
|
|
protected void deleteCascade() {}
|
|
|
|
public Vectumerator<AmzFeaturedPrice> findByCR(AmzFeaturedPriceCR CR, int pageNumber, int pageRows) {
|
|
String s_Sql_Find = "select A.* from AMZ_FEATURED_PRICE AS A";
|
|
String s_Sql_Order = "";
|
|
WcString wc = new WcString();
|
|
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.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
|
if (st.hasMoreTokens())
|
|
txt.append(" and ");
|
|
}
|
|
txt.append(")");
|
|
wc.addWc(txt.toString());
|
|
}
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
return findRows(stmt, pageNumber, pageRows);
|
|
} catch (SQLException e) {
|
|
removeCPConnection();
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public void findByArticoloLang(Articolo articolo, String lang) {
|
|
String s_Sql_Find = "select A.* from AMZ_FEATURED_PRICE AS A";
|
|
String s_Sql_Order = "";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.id_articolo=" + articolo.getId_articolo());
|
|
wc.addWc("A.lang='" + lang + "'");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
findFirstRecord(stmt);
|
|
} catch (SQLException e) {
|
|
removeCPConnection();
|
|
handleDebug(e);
|
|
}
|
|
}
|
|
|
|
public boolean isMyPriceBetter(double thePrice) {
|
|
Double betterPrice = Double.MAX_VALUE;
|
|
if (getFeaturedOEPriceAmz() > 0.0D)
|
|
betterPrice = getFeaturedOEPriceAmz();
|
|
if (getCompetingFOPriceAmz() > 0.0D)
|
|
betterPrice = Math.min(betterPrice.doubleValue(), getCompetingFOPriceAmz());
|
|
if (getCurrentFOPriceAmz() > 0.0D)
|
|
betterPrice = Math.min(betterPrice.doubleValue(), getCurrentFOPriceAmz());
|
|
if (betterPrice == Double.MAX_VALUE)
|
|
return false;
|
|
if (thePrice <= betterPrice)
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
public boolean isMyPriceBetter() {
|
|
return isMyPriceBetter(getCurrentPriceAmz());
|
|
}
|
|
|
|
public boolean isCompetitivo() {
|
|
return (getFlgPrezzoCompetitivo() == 1L);
|
|
}
|
|
|
|
public boolean isCompetitivoAmz() {
|
|
return (getFlgPrezzoCompetitivoAmz() == 1L);
|
|
}
|
|
|
|
public Date getDataPriceAmz() {
|
|
return this.dataPriceAmz;
|
|
}
|
|
|
|
public void setDataPriceAmz(Date dataPriceAmz) {
|
|
this.dataPriceAmz = dataPriceAmz;
|
|
}
|
|
|
|
public long getFlgPrezzoCompetitivoAmz() {
|
|
return this.flgPrezzoCompetitivoAmz;
|
|
}
|
|
|
|
public void setFlgPrezzoCompetitivoAmz(long flgPrezzoCompetitivoAmz) {
|
|
this.flgPrezzoCompetitivoAmz = flgPrezzoCompetitivoAmz;
|
|
}
|
|
|
|
public long getFlgPrezzoCompetitivo() {
|
|
return this.flgPrezzoCompetitivo;
|
|
}
|
|
|
|
public void setFlgPrezzoCompetitivo(long flgPrezzoCompetitivo) {
|
|
this.flgPrezzoCompetitivo = flgPrezzoCompetitivo;
|
|
}
|
|
|
|
protected void prepareSave(PreparedStatement ps) throws SQLException {
|
|
setCurrentPriceAmz(getArticolo().getPrezzoArticoloAmazonSpedIva(getLang(), true, 1L));
|
|
setFlgPrezzoCompetitivoAmz(isMyPriceBetter(getCurrentPriceAmz()) ? 1L : 0L);
|
|
DoubleOperator prezzoPubblico = new DoubleOperator(getArticolo().getPrezzoPubblicoIva());
|
|
prezzoPubblico.setScale(2, 5);
|
|
Nazione nazione = new Nazione(getApFull());
|
|
String l_lang = getCurrentLang();
|
|
if (l_lang.isEmpty())
|
|
l_lang = "it";
|
|
nazione.findByCodice(l_lang);
|
|
prezzoPubblico.add(getArticolo().getDeliveryCost(nazione.getId_nazione()));
|
|
System.out.println("AMZFP Articolo:" + getArticolo().getCodiceEan() + " " + getCurrentPriceAmz() + " " +
|
|
getArticolo().getPrezzoArticoloAmazonSpedIva(getLang(), true, 1L) + " \n" + prezzoPubblico.getResult());
|
|
System.out.println("AMZFP comp cpmpamz:" + isCompetitivoAmz() + " " + isCompetitivoAmz());
|
|
setFlgPrezzoCompetitivo(isMyPriceBetter(prezzoPubblico.getResult()) ? 1L : 0L);
|
|
super.prepareSave(ps);
|
|
}
|
|
}
|