3 Commits b185df216c ... eb87034e36

Author SHA1 Message Date
  Fabio Dalle Ave eb87034e36 modifica query per griglie frontend 2 months ago
  Fabio Dalle Ave ecd9f9f806 WIP: Numero colli minimo 4 months ago
  Fabio Dalle Ave 8e583889b6 wip cleanup 4 months ago

+ 9 - 1
pom.xml

@@ -99,10 +99,18 @@
             <version>1.9.4</version>
         </dependency>
 
+<!--
         <dependency>
             <groupId>com.lowagie</groupId>
             <artifactId>itext</artifactId>
-            <version>2.0.7</version>
+            <version>2.0.8</version>
+        </dependency>
+-->
+
+        <dependency>
+            <groupId>com.github.librepdf</groupId>
+            <artifactId>openpdf</artifactId>
+            <version>2.0.3</version>
         </dependency>
 
         <dependency>

+ 2 - 139
src/main/java/commons/utility/dao/GenericDAO.java

@@ -1,33 +1,23 @@
 package commons.utility.dao;
 
-import java.beans.PropertyDescriptor;
 import java.io.BufferedReader;
 import java.io.Reader;
 import java.io.Serializable;
 
-import org.apache.commons.beanutils.PropertyUtils;
+import jakarta.transaction.Transactional;
 import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
-import org.hibernate.proxy.HibernateProxy;
-import org.hibernate.proxy.LazyInitializer;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Repository;
 
 import commons.utility.UnproxyObject;
 
-import java.lang.reflect.Array;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.ParameterizedType;
 import java.sql.Clob;
 import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
 
+@Transactional
 public class GenericDAO<T, ID extends Serializable>
         implements IDAO<T, ID> {
 
@@ -74,13 +64,6 @@ public class GenericDAO<T, ID extends Serializable>
         return entity;
     }
 
-    @SuppressWarnings("unchecked")
-    public T readNoTransaction(ID id) {
-        T entity = (T) sessionFactory.getCurrentSession().get(persistentClass,
-                id);
-        return entity;
-    }
-
     public T saveOrUpdate(T entity) throws Exception {
         boolean tx = startTransaction();
         try {
@@ -146,10 +129,6 @@ public class GenericDAO<T, ID extends Serializable>
         commit();
     }
 
-    public void flush() {
-        currentSession().flush();
-    }
-
     @SuppressWarnings("unchecked")
     public List<T> listAll() {
         return listAll(false);
@@ -202,23 +181,6 @@ public class GenericDAO<T, ID extends Serializable>
         }
     }
 
-    @SuppressWarnings("unchecked")
-    public static <T> T initializeAndUnproxy(T entity) {
-        if (entity == null) {
-            return null;
-        }
-        if (entity instanceof HibernateProxy) {
-            Hibernate.initialize(entity);
-            entity = (T) ((HibernateProxy) entity).getHibernateLazyInitializer().getImplementation();
-        }
-        return entity;
-    }
-
-    @SuppressWarnings("unchecked")
-    public T unproxy(T proxied) {
-        return deepDeproxy(proxied);
-    }
-
     public List<T> unproxy(List<T> proxied) {
         List<T> unproxied = new ArrayList<T>();
         for (T element : proxied)
@@ -226,103 +188,4 @@ public class GenericDAO<T, ID extends Serializable>
         return unproxied;
     }
 
-    public T deepDeproxy(final Object maybeProxy) throws ClassCastException {
-        if (maybeProxy == null)
-            return null;
-        T ret = deepDeproxy(maybeProxy, new HashSet<Object>());
-        return ret;
-    }
-
-    private T deepDeproxy(final Object maybeProxy, final HashSet<Object> visited)
-            throws ClassCastException {
-        if (maybeProxy == null)
-            return null;
-        Class clazz;
-        Hibernate.initialize(maybeProxy);
-        if (maybeProxy instanceof HibernateProxy) {
-            HibernateProxy proxy = (HibernateProxy) maybeProxy;
-            LazyInitializer li = proxy.getHibernateLazyInitializer();
-            clazz = li.getImplementation().getClass();
-        } else {
-            clazz = maybeProxy.getClass();
-        }
-        T ret = (T) deepDeproxy(maybeProxy, clazz);
-        if (visited.contains(ret))
-            return ret;
-        visited.add(ret);
-        for (PropertyDescriptor property : PropertyUtils
-                .getPropertyDescriptors(ret)) {
-            try {
-                String name = property.getName();
-                if (!"owner".equals(name) && property.getWriteMethod() != null) {
-                    Object value = PropertyUtils.getProperty(ret, name);
-                    boolean needToSetProperty = false;
-                    if (value instanceof HibernateProxy) {
-                        value = deepDeproxy(value, visited);
-                        needToSetProperty = true;
-                    }
-                    if (value instanceof Object[]) {
-                        Object[] valueArray = (Object[]) value;
-                        Object[] result = (Object[]) Array.newInstance(
-                                value.getClass(), valueArray.length);
-                        for (int i = 0; i < valueArray.length; i++) {
-                            result[i] = deepDeproxy(valueArray[i], visited);
-                        }
-                        value = result;
-                        needToSetProperty = true;
-                    }
-                    if (value instanceof Set) {
-                        Set valueSet = (Set) value;
-                        Set result = new HashSet();
-                        for (Object o : valueSet) {
-                            result.add(deepDeproxy(o, visited));
-                        }
-                        value = result;
-                        needToSetProperty = true;
-                    }
-                    if (value instanceof Map) {
-                        Map valueMap = (Map) value;
-                        Map result = new HashMap();
-                        for (Object o : valueMap.keySet()) {
-                            result.put(deepDeproxy(o, visited),
-                                    deepDeproxy(valueMap.get(o), visited));
-                        }
-                        value = result;
-                        needToSetProperty = true;
-                    }
-                    if (value instanceof List) {
-                        List valueList = (List) value;
-                        List result = new ArrayList(valueList.size());
-                        for (Object o : valueList) {
-                            result.add(deepDeproxy(o, visited));
-                        }
-                        value = result;
-                        needToSetProperty = true;
-                    }
-                    if (needToSetProperty)
-                        PropertyUtils.setProperty(ret, name, value);
-                }
-            } catch (java.lang.IllegalAccessException e) {
-                e.printStackTrace();
-            } catch (InvocationTargetException e) {
-                e.printStackTrace();
-            } catch (NoSuchMethodException e) {
-                e.printStackTrace();
-            }
-        }
-        return ret;
-    }
-
-    private <T> T deepDeproxy(Object maybeProxy, Class<T> baseClass)
-            throws ClassCastException {
-        if (maybeProxy == null)
-            return null;
-        if (maybeProxy instanceof HibernateProxy) {
-            return baseClass.cast(((HibernateProxy) maybeProxy)
-                    .getHibernateLazyInitializer().getImplementation());
-        } else {
-            return baseClass.cast(maybeProxy);
-        }
-    }
-
 }

+ 2 - 1
src/main/java/it/powerage/Application.java

@@ -2,11 +2,12 @@ package it.powerage;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
 import org.springframework.context.annotation.ComponentScan;
 
-@SpringBootApplication
+@SpringBootApplication(exclude = HibernateJpaAutoConfiguration.class)
 @ComponentScan(basePackages = {
     "commons",
     "powerage",

+ 1 - 3
src/main/java/powerage/controller/LoginController.java

@@ -53,10 +53,8 @@ public class LoginController extends BaseController {
 		setRequest(request);
 		setResponse(response);
 
-		utenteDao.startTransaction();
 		Utente utente = utenteDao.login(loginBean.getUsername(), loginBean.getPassword());
-		utenteDao.commit();
-		
+
 		if (utente == null)
 			return "redirect:login.do";
 		else

+ 1 - 1
src/main/java/powerage/controller/PrintController.java

@@ -13,7 +13,7 @@ import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
-import com.lowagie.text.pdf.codec.Base64.OutputStream;
+// import com.lowagie.text.pdf.codec.Base64.OutputStream;
 
 import powerage.dao.OrdineDAO;
 import powerage.entities.Ordine;

+ 0 - 1
src/main/java/powerage/dao/AgenteDAO.java

@@ -11,7 +11,6 @@ import org.hibernate.query.Query;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Repository;
 
-
 import powerage.entities.Agente;
 import commons.utility.dao.GenericDAO;
 import commons.utility.dao.IDAO;

+ 0 - 1
src/main/java/powerage/dao/OrdineDAO.java

@@ -6,7 +6,6 @@ import commons.utility.MutableHolder;
 
 import jakarta.persistence.EntityManager;
 import jakarta.persistence.TypedQuery;
-import jakarta.transaction.Transactional;
 import lombok.RequiredArgsConstructor;
 import org.hibernate.query.Query;
 

+ 3 - 2
src/main/java/powerage/dao/UtenteDAO.java

@@ -2,8 +2,6 @@ package powerage.dao;
 
 import java.util.List;
 
-import org.hibernate.SessionFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Repository;
 
 import powerage.entities.Utente;
@@ -31,10 +29,13 @@ public class UtenteDAO
 	}
 
 	public Utente login(String login, String password) {
+		boolean tx = startTransaction();
 		List<Utente> utenti = currentSession()
 			.createQuery("from Utente u where u.login = :login", Utente.class)
 			.setParameter("login", login)
 			.list();
+		if (tx)
+			commit();
 		if (utenti.size()>0){
 			String pwdUtente = utenti.get(0).getPassword();
 			if (pwdUtente==null)

+ 1 - 1
src/main/java/powerage/entities/ListinoArticolo.java

@@ -14,7 +14,7 @@ import commons.common.CalendarJSonSerializer;
 @Table(name="Listini_articolo")
 public class ListinoArticolo {
 	@Id
-	@GeneratedValue
+	@GeneratedValue( strategy = GenerationType.IDENTITY)
 	@Column(name="idListinoArticoli")
 	private Long idListinoArticoli;
 	

+ 6 - 1
src/main/java/powerage/exporters/impl/OrdiniExporter.java

@@ -106,7 +106,12 @@ public class OrdiniExporter extends BaseExporter<Ordine> {
 		linea += StringUtility.fillString(" ", 5, ' ');  //abi
 		linea += StringUtility.fillString(" ", 12, ' ');  //conto
 		
-		linea += StringUtility.fillString(ordine.getNoteOrdine().substring(0, Math.min(ordine.getNoteOrdine().length(), 180)), 180, ' ');
+		linea += StringUtility.fillString(
+			(ordine.getNoteOrdine() != null
+				? ordine.getNoteOrdine().substring(0, Math.min(ordine.getNoteOrdine().length(), 180))
+				: " "
+			), 180, ' ');
+
 		linea += StringUtility.fillString(" ", 3, ' ');  //porto
 		linea += StringUtility.fillString(ordine.getCliente().getUbicazione(), 3, ' ');  //spedizioniere
 		linea += StringUtility.fillString("", 3, ' ');  //tipologia ordine

+ 18 - 4
src/main/java/powerage/importers/impl/ArticoliImporter.java

@@ -38,7 +38,7 @@ public class ArticoliImporter extends BaseImporter implements IBaseImporter {
 		Articolo articolo;
 		Tabella classifica1 = null, classifica2 = null, classifica3 = null, classifica4 = null;
 		String codArticolo, descrizione, unitaMisura, categoria, codGruppo, codInventario, codIVA, codStatistico;
-		float prezzoBase, pezziConfezione, pesoUnitario;
+		Float prezzoBase, pezziConfezione, pesoUnitario, numColliMinimo;
 		boolean changed;
 		
 		codArticolo = getNextField(15);
@@ -68,11 +68,23 @@ public class ArticoliImporter extends BaseImporter implements IBaseImporter {
 		pezziConfezione = Float.parseFloat(getNextField(13)) / 10000;  // 4 decimali
 		setCurrentIndex(292);
 		prezzoBase = Float.parseFloat(getNextField(17)) / 1000000;  // 6 decimali
-		
+
+		// il numero di colli minumo è a colonna 2553 lungo 6
+		setCurrentIndex(2552);
+		String sNumColliMinimo = getNextField(6);
+		numColliMinimo = null;
+		// controlla che sNumColliMinimo esista e sia numerico
+		if (sNumColliMinimo != null && sNumColliMinimo.matches("\\d+")) {
+			numColliMinimo = Float.parseFloat(sNumColliMinimo);
+		} else {
+			sNumColliMinimo = null;
+		}
+
+
 		// Cerca l'articolo
 		articolo = articoloDAO.getByCode(codArticolo);
 		Tabella tblIva = tabellaDAO.getByCode(TipoTabella.IVA, codIVA);
-		
+
 		// cerca l'iva
 		
 		if (articolo==null) {
@@ -89,7 +101,8 @@ public class ArticoliImporter extends BaseImporter implements IBaseImporter {
 					((tblIva!=null) && (articolo.getIva()==null)) ||
 					(tblIva!=null&&(tblIva.getIdTabella().compareTo(articolo.getIva().getIdTabella())!=0))||
 					(articolo.getCategoria().compareTo(categoria)!=0) ||
-					(articolo.getGruppo().compareTo(codGruppo)!=0) 
+					(articolo.getGruppo().compareTo(codGruppo)!=0)  ||
+					(numColliMinimo != articolo.getNumColliMinimo())
 					;
 		}
 
@@ -102,6 +115,7 @@ public class ArticoliImporter extends BaseImporter implements IBaseImporter {
 			articolo.setPeso(pesoUnitario);
 			articolo.setGruppo(codGruppo);
 			articolo.setCategoria(categoria);
+			articolo.setNumColliMinimo(numColliMinimo);
 			if (tblIva!=null)
 				articolo.setIva(tblIva);
 			else

+ 15 - 6
src/main/java/powerage/importers/impl/BaseImporter.java

@@ -23,6 +23,7 @@ public abstract class BaseImporter implements IBaseImporter {
 	private int currentIndex = 0;
 	protected Calendar dataModifica;
 	protected boolean changed;
+	boolean tx = false;
 	private PowerAgeDAO dao;
 	private boolean useTransactions = true;
 	private int lineNumber;
@@ -144,16 +145,24 @@ public abstract class BaseImporter implements IBaseImporter {
 	public abstract void processLine();
 	
 	public void startTransaction() {
-		if (useTransactions)
-			sessionFactory.getCurrentSession().beginTransaction();
+		if (useTransactions) {
+			tx = dao.startTransaction();
+		}
+
 	}
 	public void commit() {
-		if (useTransactions)
-			sessionFactory.getCurrentSession().getTransaction().commit();
+		if (useTransactions && tx) {
+			dao.commit();
+//			sessionFactory.getCurrentSession().getTransaction().commit();
+		}
 	}
 	public void rollback() {
-		if (useTransactions)
-			sessionFactory.getCurrentSession().getTransaction().rollback();
+		if (useTransactions && tx)  {
+			dao.rollback();
+			tx = false;
+			// sessionFactory.getCurrentSession().getTransaction().rollback();
+		}
+
 	}
 	
 	

+ 25 - 7
src/main/java/powerage/importers/impl/ClientiImporter.java

@@ -2,6 +2,8 @@
 
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.hibernate.HibernateException;
 import org.springframework.stereotype.Repository;
@@ -48,6 +50,10 @@ public class ClientiImporter extends BaseImporter implements IBaseImporter {
 	private int attivo;
 	Cliente cliente;
 
+	Map<String, Agente> agenti =  new HashMap<>();
+	Map<String, Listino> listini =  new HashMap<>();
+	Map<String, Pagamento> pagamenti =  new HashMap<>();
+
 //	public ClientiImporter() {
 //		super(false);
 //	}
@@ -80,15 +86,27 @@ public class ClientiImporter extends BaseImporter implements IBaseImporter {
 //		if (cliente==null && partitaIVA!=null && !partitaIVA.isEmpty())
 //			cliente = clienteDAO.getByPartitaIVA(partitaIVA);
 //		if (cliente==null && codiceFiscale!=null && !codiceFiscale.isEmpty())
-//			cliente = clienteDAO.getByCodiceFiscale(codiceFiscale);   \
-		
-		
-		agente = agenteDAO.getByCode(codAgente);
+//			cliente = clienteDAO.getByCodiceFiscale(codiceFiscale);
+
+		if (!agenti.containsKey(codAgente)) {
+			agente = agenteDAO.getByCode(codAgente);
+			agenti.put(codAgente, agente);
+		}
+		agente = agenti.get(codAgente);
+
 		if (agente == null) {
 			
-		} else { 
-			listino = listinoDAO.getByCode(codListino);
-			pagamento = pagamentoDAO.getByCode(codPagamento);			
+		} else {
+			if (!listini.containsKey(codListino)) {
+				listini.put(codListino, listinoDAO.getByCode(codListino));
+			}
+			listino = listini.get(codListino);
+
+			if (!pagamenti.containsKey(codPagamento)) {
+				pagamenti.put(codPagamento, pagamentoDAO.getByCode(codPagamento));
+			}
+
+			pagamento = pagamenti.get(codPagamento);
 			
 				if (cliente == null) {
 					cliente = new Cliente();

+ 28 - 4
src/main/java/powerage/importers/impl/ListinoArticoloImporter.java

@@ -2,6 +2,8 @@ package powerage.importers.impl;
 
 import java.util.Calendar;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Repository;
@@ -33,6 +35,11 @@ public class ListinoArticoloImporter extends BaseImporter implements IBaseImport
 	private Articolo articolo;
 	private Listino listino;
 	private Sconto sconto;
+
+	// cache
+	Map<String, Articolo> articoli = new HashMap<>();
+	Map<String, Listino> listini = new HashMap<>();
+	Map<String, Sconto> sconti = new HashMap<>();
 	
 	public ListinoArticoloImporter() {
 		super();
@@ -74,11 +81,28 @@ public class ListinoArticoloImporter extends BaseImporter implements IBaseImport
 		sPrezzo = getNextField(10) + getNextField(6);
 		prezzo = Double.parseDouble(sPrezzo) / 1000000;
 		codSconto = getNextField(3);
-		
-		listino = listinoDAO.getByCode(codListino);
-		articolo = articoloDAO.getByCode(codArticolo);
+
+		if (listini.get(codListino)==null) {
+			listini.put(codListino, listinoDAO.getByCode(codListino));
+		}
+
+		listino = listini.get(codListino); // listinoDAO.getByCode(codListino);
+
+		if (articoli.get(codArticolo)==null) {
+			articoli.put(codArticolo, articoloDAO.getByCode(codArticolo));
+		}
+		articolo = articoli.get(codArticolo);
+
+		//articolo = articoloDAO.getByCode(codArticolo);
+		if (sconti.get(codSconto)==null) {
+			sconti.put(codSconto, scontoDAO.getByCode(codSconto));
+		}
+		sconto = sconti.get(codSconto);
+		// sconto = scontoDAO.getByCode(codSconto);\
+
+
 		listinoArticolo = lisArtDAO.getListinoArticolo(codListino, codArticolo, dataInizio);
-		sconto = scontoDAO.getByCode(codSconto);
+
 		
 		// Controlla che il listino e l'articolo esistano
 		if (listino==null) {

+ 1 - 1
src/main/java/powerage/stampe/StampaOrdine.java

@@ -16,7 +16,7 @@ import com.lowagie.text.pdf.PdfImportedPage;
 import com.lowagie.text.pdf.PdfReader;
 import com.lowagie.text.pdf.PdfStamper;
 import com.lowagie.text.pdf.PdfWriter;
-import com.lowagie.text.pdf.codec.Base64.OutputStream;
+// import com.lowagie.text.pdf.codec.Base64.OutputStream;
 
 import powerage.entities.Ordine;
 import powerage.entities.RigaOrdine;