maia/.svn/pristine/7f/7f2de1f91e5095bb1ced0dd2202...

190 lines
7.0 KiB
Plaintext
Executable File

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;
/**
* @author Andres Cevallos
* Clase Controladora para la entidad TarmArma
* Incluye metodo de consulta para la busqueda de persona y registro
*/
@SuppressWarnings("serial")
@ManagedBean
@ViewScoped
public class ArmaVentaController extends AbstractController<TarmArmas> {
//Variabgles globales
/**
*String el cual tendr un nombre de filtro
*/
private String csolicitud;
public ArmaVentaController() throws Exception {
super(TarmArmas.class);
}
/**
* Metodo invocado despues de instanciar el controlador
*/
@PostConstruct
private void postconstruct() {
this.init();
// Inicializa autoconsulta
super.startQuery();
}
/**
* Incializa variables del controlador, cuando se esta utilizando una pagina que utliza el controlador.
*/
private void init() {
try {
this.recperpage = 15; // Cambiar al # reg a mirar.
this.lrecord = new ArrayList<>();
this.record=new TarmArmas();
this.beanalias = "ARMAS";
this.filtro();
} catch (Exception e) {
MessageHelper.setMessageError(e);
}
}
/* (non-Javadoc)
* @see com.fp.frontend.controller.AbstractController#querydatabase()
*/
@SuppressWarnings("unchecked")
@Override
public void querydatabase() {
try {
//this.addFilter("estado", "REG");
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 filtrofecha=new Filter();
//filtrofecha.setSql(
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")+") and (t.peso>0 or t.cantidad>0)";
//dto.addFiltro(filtrofecha);
String sql=csolicitud;
if(csolicitud!=null){
Filter filtro = new Filter();
filtro.setSql(filtrofecha +" and "+sql);
dto.addFiltro(filtro);
}
else{
return;
}
dto.setOrderby("pk");
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
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<TarmArmas>();
MessageHelper.setMessageError(resp);
} else {
this.lrecord = (List<TarmArmas>) resp.get(this.beanalias);
if(!lrecord.isEmpty()){
record=lrecord.get(0);
}
super.postQuery(this.lrecord);
}
} catch (Throwable e) {
MessageHelper.setMessageError(e);
}
}
/**
* Metodo para armar el registro
* @param lsolicitud
* @throws Exception
*/
public void filtro() throws Exception{
TsafeUserDetail tsafeUserDetail=(TsafeUserDetail)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("TSAFEUSERDETAIL");
RegistroArmController registroArmas = new RegistroArmController();
registroArmas.init();
registroArmas.setRecperpage(3000000);
registroArmas.addFilter("personcode", tsafeUserDetail.getPk().getPersoncode().toString());
registroArmas.query();
for(TarmRegistroArmas soli : registroArmas.getLrecord()){
if(csolicitud==null){
csolicitud="(cregistro="+soli.getPk();
}
else{
csolicitud+=" or cregistro="+soli.getPk();
}
}
csolicitud+=")";
}
/* (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);
}
}