128 lines
5.0 KiB
Plaintext
Executable File
128 lines
5.0 KiB
Plaintext
Executable File
package com.fp.armas.rules.save.webservices;
|
|
|
|
import java.sql.Timestamp;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import javax.persistence.Query;
|
|
|
|
import com.fp.dto.rules.TransactionRule;
|
|
import com.fp.dto.save.SaveRequest;
|
|
import com.fp.persistence.commondb.PersistenceHelper;
|
|
import com.fp.persistence.parmas.inte.TarmLectura;
|
|
import com.fp.persistence.parmas.inte.TarmLecturaDetalle;
|
|
import com.fp.persistence.parmas.inte.TarmLecturaDetalleKey;
|
|
import com.fp.persistence.parmas.inte.TarmTagArma;
|
|
import com.fp.sessionbeans.helper.Sequence;
|
|
|
|
/**
|
|
* Componente en donde se ingresa las lecturas que provienen del hand held
|
|
* @author dcruz
|
|
*
|
|
*/
|
|
public class IngresaLectura extends TransactionRule {
|
|
|
|
private static final long serialVersionUID = 8760785038997324400L;
|
|
|
|
private static final String QUERY_TAG_ARMA = "SELECT o FROM TarmTagArma o WHERE o.ctag=:codigotag";
|
|
|
|
/**
|
|
* Método en el cual se inserta los registros de los dispositivos leidos en la hand held
|
|
*/
|
|
@Override
|
|
public SaveRequest normalProcess(SaveRequest pRequest) throws Exception {
|
|
System.out.println("INGRESA A GUARDAR EL TAG........................"+pRequest);
|
|
String tagsleidos = (String) pRequest.get("TAGSLECTURA");
|
|
Date fechalectura = (Date) pRequest.get("FECHALECTURA");
|
|
String locacionlectura = (String) pRequest.get("LOCACIONLECTURA");
|
|
String idportal = (String) pRequest.get("IDPORTAL");
|
|
String tipooperacion = (String) pRequest.get("TIPOOPERACION");
|
|
String[] tagleidosArray=null;
|
|
if(tagsleidos.contains(",")){
|
|
tagleidosArray = tagsleidos.split(",");
|
|
}else{
|
|
tagleidosArray = tagsleidos.split("/");
|
|
}
|
|
String direccion = locacionlectura;
|
|
guardaLectura(tagleidosArray, fechalectura, direccion, idportal, tipooperacion);
|
|
return pRequest;
|
|
}
|
|
|
|
/**
|
|
* Método en el cual guardamos los datos leíidos desde el hand held
|
|
* @param tagleidos array de tag leídos del hand held
|
|
* @param fechaLectura la fecha en la que se realizó la lectura
|
|
* @param countrycode código de país
|
|
* @param provincecode código de provincia
|
|
* @param cantoncode código de cantón
|
|
* @param parroquiacode código de parroquia
|
|
* @param idportal id del portal de donde se capturó la lectura
|
|
* @param tipooperacion tipo de operació de la lectura si es hand held o si es portal
|
|
* @throws Exception
|
|
*/
|
|
private void guardaLectura(String[] tagleidos, Date fechaLectura, String direccion, String idportal, String tipooperacion) throws Exception{
|
|
TarmLectura tarmLectura = new TarmLectura();
|
|
tarmLectura.setPk(getCodigoLectura());
|
|
tarmLectura.setFecha(new Timestamp(fechaLectura.getTime()));
|
|
|
|
System.out.println("direccion ......................."+direccion);
|
|
System.out.println(direccion.contains(","));
|
|
if(direccion.contains(",")){
|
|
String[] direccionArray = direccion.split(",");
|
|
String provincecode = direccionArray[0];
|
|
tarmLectura.setProvincecode(provincecode);
|
|
}
|
|
|
|
// tarmLectura.setCountrycode(countrycode);
|
|
// tarmLectura.setProvincecode(provincecode);
|
|
// tarmLectura.setCantoncode(cantoncode);
|
|
// tarmLectura.setParroquiacode(parroquiacode);
|
|
tarmLectura.setIdportal(idportal);
|
|
tarmLectura.setTipolectura(tipooperacion);
|
|
tarmLectura.setTipolecturacode("TIPOLECTURA");
|
|
tarmLectura.setDireccion(direccion);
|
|
PersistenceHelper.getEntityManager().persist(tarmLectura);
|
|
for (String tag : tagleidos) {
|
|
// String carma = getCodigoArmadeTag(tag);
|
|
TarmLecturaDetalle tarmLecturaDetalle = new TarmLecturaDetalle(new TarmLecturaDetalleKey(tarmLectura.getPk(), tag));
|
|
// tarmLecturaDetalle.set
|
|
PersistenceHelper.getEntityManager().persist(tarmLecturaDetalle);
|
|
}
|
|
PersistenceHelper.getEntityManager().flush();
|
|
}
|
|
|
|
/**
|
|
* Retorna el codigo del arma asociada al tag desde TarmTagArma
|
|
* @param codigotag
|
|
* @return el código del arma relacionada con el tag
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
private String getCodigoArmadeTag(String codigotag) throws Exception{
|
|
//tanto el tag como el arma deben estar relacionados entre si, no se puede producir el caso en que un tag este relacionado con mas de un arma y viceversa
|
|
String codigoarma = null;
|
|
Query query = PersistenceHelper.getEntityManager().createQuery(QUERY_TAG_ARMA);
|
|
query.setParameter("codigotag", codigotag);
|
|
List<TarmTagArma> ltarmTagArmas = query.getResultList();
|
|
if(ltarmTagArmas != null && !ltarmTagArmas.isEmpty()){
|
|
codigoarma = ltarmTagArmas.iterator().next().getPk().getCarma();
|
|
}
|
|
return codigoarma;
|
|
}
|
|
|
|
@Override
|
|
public SaveRequest reverseProcess(SaveRequest pRequest) throws Exception {
|
|
return pRequest;
|
|
}
|
|
|
|
/**
|
|
* Retorna el codódigo secuencial de la pk de la tabla {@link TarmLectura}
|
|
* @return la secuencia de la tabla {@link TarmLectura}
|
|
* @throws Exception
|
|
*/
|
|
public Long getCodigoLectura() throws Exception {
|
|
Sequence sequence = new Sequence();
|
|
return sequence.getNextValue("CLECTURA").longValue();
|
|
}
|
|
|
|
}
|