110 lines
5.3 KiB
Plaintext
Executable File
110 lines
5.3 KiB
Plaintext
Executable File
package com.fp.armas.rules.query.solicitud;
|
|
|
|
import java.util.List;
|
|
|
|
import com.fp.bpm.query.QueryJsf;
|
|
import com.fp.dto.query.QueryRequest;
|
|
import com.fp.dto.rules.QueryRule;
|
|
import com.fp.persistence.commondb.PersistenceHelper;
|
|
import com.fp.persistence.commondb.exception.CommondbException;
|
|
import com.fp.persistence.parmas.fun.TarmRegistroArmas;
|
|
import com.fp.persistence.parmas.param.TarmTipoArmaExplosivo;
|
|
import com.fp.persistence.parmas.soli.TarmArmas;
|
|
import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail;
|
|
import com.fp.persistence.pgeneral.gene.TgeneCatalogDetailKey;
|
|
import com.fp.persistence.pgeneral.gene.TgeneParameters;
|
|
import com.fp.persistence.pgeneral.gene.TgeneParametersKey;
|
|
|
|
/**
|
|
* Clase que obtiene los datos completos del arma que estan asignadas a una persona o
|
|
* proveedor
|
|
* @author C.P
|
|
*
|
|
*/
|
|
public class ArmasXPersonaQuery extends QueryRule {
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
/**
|
|
* Completa datos del arma
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
public QueryRequest process(QueryRequest pRequest) throws Exception {
|
|
QueryJsf query = new QueryJsf();
|
|
query.execute(pRequest);
|
|
TgeneParametersKey key = new TgeneParametersKey();
|
|
key.setCode("COD.REGISTRADO.ESTADO");//codigo del arma en REG
|
|
key.setCompanycode(1);
|
|
TgeneParameters parametro=TgeneParameters.find(PersistenceHelper.getEntityManager(),key);
|
|
|
|
List<TarmRegistroArmas> registroarmasList = (List<TarmRegistroArmas>) pRequest.getResponse().get("TREGISTROARMAS");
|
|
String serielote="";
|
|
if(pRequest.get("serielote")!=null && pRequest.get("serielote").toString().length()>0){
|
|
serielote= " and o.lote='"+(String)pRequest.get("serielote")+"'";
|
|
}
|
|
|
|
String codigoReg=null;
|
|
for(TarmRegistroArmas registro:registroarmasList){
|
|
if(codigoReg==null){
|
|
codigoReg="o.cregistro="+registro.getPk();
|
|
}else{
|
|
codigoReg+=" or o.cregistro="+registro.getPk();
|
|
}
|
|
}
|
|
if(codigoReg!=null){
|
|
//select con los codigos del registro que tenga una persona, por la fecha maxima por registro por el explosivos, cajas, filtramos si ya esta en la tabla tardecomiso arma
|
|
//y que esten en estado reg
|
|
List<TarmArmas> armasList =PersistenceHelper.getEntityManager().createQuery("Select o from TarmArmas o where ("+codigoReg+" )"
|
|
+ " and o.estado IN ('APTA','DEV','AUTO','REG') "
|
|
+ " and o.fecharegistro=(select max(ta.fecharegistro) from TarmArmas ta where o.codigoarma=ta.codigoarma and o.cregistro=ta.cregistro)"
|
|
+ " and o.pk NOT IN (select dec.carma from TarmDecomisoArma dec where dec.estado= 'CUSTEM')"
|
|
+ serielote).getResultList();
|
|
|
|
this.managedResponse(armasList);
|
|
pRequest.getResponse().put("ARMASLIST", armasList);
|
|
}
|
|
|
|
return pRequest;
|
|
}
|
|
|
|
/**
|
|
* Agrega metadata adicional de las armas para mostrar en las consultas
|
|
* @param armasList
|
|
* @throws Exception
|
|
* @throws CommondbException
|
|
*/
|
|
private void managedResponse(List<TarmArmas> armasList) throws CommondbException, Exception{
|
|
for (TarmArmas armas : armasList) {
|
|
|
|
TarmTipoArmaExplosivo explisivo= TarmTipoArmaExplosivo.find(PersistenceHelper.getEntityManager(),armas.getCtipoarmaexplosivo());
|
|
|
|
TgeneCatalogDetail clase= TgeneCatalogDetail.find(PersistenceHelper.getEntityManager(),
|
|
new TgeneCatalogDetailKey(explisivo.getClase()!= null ? explisivo.getClase():"", explisivo.getClasecodigo() != null ? explisivo.getClasecodigo() : ""));
|
|
armas.modifiedData.put("clase", clase != null ? clase.getDescription():null);
|
|
|
|
TgeneCatalogDetail tipoArma= TgeneCatalogDetail.find(PersistenceHelper.getEntityManager(),
|
|
new TgeneCatalogDetailKey(explisivo.getTipoarmaexplosivo() != null ? explisivo.getTipoarmaexplosivo() : "", explisivo.getTipoarmaexplosivocodigo()!= null ? explisivo.getTipoarmaexplosivocodigo(): ""));
|
|
armas.modifiedData.put("tipoarmaexplosivo", tipoArma != null ? tipoArma.getDescription():null);
|
|
|
|
TgeneCatalogDetail unidadMedida= TgeneCatalogDetail.find(PersistenceHelper.getEntityManager(),
|
|
new TgeneCatalogDetailKey(explisivo.getUnidadmedidapeso() != null ? explisivo.getUnidadmedidapeso():"", explisivo.getUnidadmedidapesocodigo() != null ? explisivo.getUnidadmedidapesocodigo() : ""));
|
|
armas.modifiedData.put("unidadmedidapeso", unidadMedida != null ? unidadMedida.getDescription():null);
|
|
|
|
TgeneCatalogDetail calibre= TgeneCatalogDetail.find(PersistenceHelper.getEntityManager(),
|
|
new TgeneCatalogDetailKey(explisivo.getCalibre() != null ? explisivo.getCalibre() : "", explisivo.getCalibrecodigo() != null ? explisivo.getCalibrecodigo() : ""));
|
|
armas.modifiedData.put("calibre", calibre != null ? calibre.getDescription() : null);
|
|
|
|
TgeneCatalogDetail longitud= TgeneCatalogDetail.find(PersistenceHelper.getEntityManager(),
|
|
new TgeneCatalogDetailKey(explisivo.getLongitud() != null ? explisivo.getLongitud() : "", explisivo.getLongitudcodigo() != null ? explisivo.getLongitudcodigo() : ""));
|
|
armas.modifiedData.put("longitud", longitud != null ? longitud.getDescription() : null);
|
|
|
|
TgeneCatalogDetail marca= TgeneCatalogDetail.find(PersistenceHelper.getEntityManager(),
|
|
new TgeneCatalogDetailKey(armas.getMarca() != null ? armas.getMarca() : "", armas.getMarcacodigo() != null ? armas.getMarcacodigo() : ""));
|
|
armas.modifiedData.put("marca", marca != null ? marca.getDescription():null);
|
|
}
|
|
}
|
|
|
|
}
|