package com.fp.frontend.controller.armas.funcionalidad; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import javax.annotation.PostConstruct; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; import javax.faces.context.FacesContext; import com.fp.dto.Request; import com.fp.dto.Response; import com.fp.dto.query.DtoQuery; import com.fp.dto.query.Filter; import com.fp.dto.query.SubQuery; import com.fp.frontend.controller.AbstractController; import com.fp.frontend.helper.MessageHelper; import com.fp.frontend.utility.MsgControlArmas; import com.fp.persistence.parmas.fun.TarmRegistroArmas; import com.fp.persistence.parmas.soli.TarmArmas; import com.fp.persistence.pgeneral.safe.TsafeUserDetail; @SuppressWarnings("serial") @ManagedBean @ViewScoped public class ConsultaArmasVentaController extends AbstractController { public ConsultaArmasVentaController() throws Exception { super(TarmArmas.class); } @PostConstruct private void postconstruct() { this.init(); super.startQuery(); } private void init() { try { this.recperpage = 15; this.lrecord = new ArrayList<>(); this.record=new TarmArmas(); this.beanalias = "CONSULTAARMASVENTA"; } catch (Exception e) { MessageHelper.setMessageError(e); } } /* (non-Javadoc) * @see com.fp.frontend.controller.AbstractController#querydatabase() */ @SuppressWarnings("unchecked") @Override public void querydatabase() { try { DtoQuery dto = super.getDtoQuery(true); SubQuery subqueryMarca= new SubQuery("TgeneCatalogDetail","description","marca","i.pk.catalog=t.marca and i.pk.catalogcode=t.marcacodigo"); dto.addSubQuery(subqueryMarca); SubQuery subqueryColor= new SubQuery("TgeneCatalogDetail","description","color","i.pk.catalog=t.color and i.pk.catalogcode=t.colorcodigo"); dto.addSubQuery(subqueryColor); SubQuery subqueryEstado= new SubQuery("TgeneCatalogDetail","description","estado","i.pk.catalog=t.estado and i.pk.catalogcode=t.estadocodigo"); dto.addSubQuery(subqueryEstado); SubQuery subqueryClase= new SubQuery("TarmTipoArmaExplosivo","clase","cclase","i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryClase); SubQuery subqueryClaseCodigo= new SubQuery("TarmTipoArmaExplosivo","clasecodigo","cclasecodigo","i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryClaseCodigo); SubQuery subqueryLongitud= new SubQuery("TarmTipoArmaExplosivo","longitud","clongitud","i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryLongitud); SubQuery subqueryLongitudCodigo= new SubQuery("TarmTipoArmaExplosivo","longitudcodigo","clongitudcodigo","i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryLongitudCodigo); SubQuery subqueryCalibre= new SubQuery("TarmTipoArmaExplosivo","calibre","ccalibre","i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryCalibre); SubQuery subqueryCalibreCodigo= new SubQuery("TarmTipoArmaExplosivo","calibrecodigo","ccalibrecodigo","i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryCalibreCodigo); SubQuery subqueryTipoArma= new SubQuery("TarmTipoArmaExplosivo","tipoarmaexplosivo","ctipoarmaexplosivo","i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryTipoArma); SubQuery subqueryTipoArmaCodigo= new SubQuery("TarmTipoArmaExplosivo","tipoarmaexplosivocodigo","ctipoarmaexplosivocodigo","i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryTipoArmaCodigo); SubQuery subqueryUnidad= new SubQuery("TarmTipoArmaExplosivo","unidadmedidapeso","cunidadmedidapeso","i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryUnidad); SubQuery subqueryUnidadCodigo= new SubQuery("TarmTipoArmaExplosivo","unidadmedidapesocodigo","cunidadmedidapesocodigo","i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryUnidadCodigo); Filter filtro=new Filter(); String filtrofecha= "t.fecharegistro=(select max(ta.fecharegistro) from TarmArmas ta where t.codigoarma=ta.codigoarma and t.cregistro=ta.cregistro) " + " and t.estado in("+MsgControlArmas.getProperty("codigo_estado_arma_busqueda_venta")+")"; filtro.setSql(filtrofecha); dto.addFiltro(filtro); dto.setOrderby("pk"); HashMap mtables = new HashMap(); mtables.put(this.beanalias, dto); // permite adicionar mas de una tabla. Request request = this.callerhelper.getRequest(); request.setQueryTables(mtables); // request.put("queryalias", "ARMASCOMPLETE"); Response resp = this.callerhelper.executeQuery(request); if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) { this.lrecord = new ArrayList(); MessageHelper.setMessageError(resp); } else { this.lrecord = (List) resp.get(this.beanalias); super.postQuery(this.lrecord); } } catch (Throwable e) { MessageHelper.setMessageError(e); } } /* (non-Javadoc) * @see com.fp.frontend.controller.AbstractController#save() */ @Override public void save(){ } @Override public void postCommit(Response response) throws Exception { super.postCommitGeneric(response, beanalias); } }