285 lines
7.1 KiB
Plaintext
Executable File
285 lines
7.1 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.funcionalidad;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.faces.application.FacesMessage;
|
|
import javax.faces.bean.ManagedBean;
|
|
import javax.faces.bean.ViewScoped;
|
|
import javax.faces.context.FacesContext;
|
|
|
|
import org.primefaces.event.SelectEvent;
|
|
import org.primefaces.event.map.MarkerDragEvent;
|
|
import org.primefaces.event.map.OverlaySelectEvent;
|
|
import org.primefaces.model.map.DefaultMapModel;
|
|
import org.primefaces.model.map.LatLng;
|
|
import org.primefaces.model.map.MapModel;
|
|
import org.primefaces.model.map.Marker;
|
|
|
|
import com.fp.dto.Request;
|
|
import com.fp.dto.Response;
|
|
import com.fp.dto.query.DtoQuery;
|
|
import com.fp.dto.query.SubQuery;
|
|
import com.fp.frontend.controller.AbstractController;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.persistence.parmas.param.TarmSitioAlmacenamiento;
|
|
import com.fp.persistence.pgeneral.gene.TgeneProvince;
|
|
|
|
/**
|
|
* Clase controladora del bean TarmSitioAlmacenamiento.
|
|
*
|
|
* @author abenalcazar
|
|
*
|
|
*/
|
|
@SuppressWarnings("serial")
|
|
@ManagedBean(name = "visualizacionSitiosAlmacenamientoController")
|
|
@ViewScoped
|
|
public class VisualizacionSitiosAlmacenamientoController extends
|
|
AbstractController<TarmSitioAlmacenamiento> {
|
|
|
|
public VisualizacionSitiosAlmacenamientoController() throws Exception {
|
|
super(TarmSitioAlmacenamiento.class);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Model para GMAP
|
|
*/
|
|
private MapModel simpleModel;
|
|
/**
|
|
* Marcador de Gmap
|
|
*/
|
|
private Marker marker;
|
|
/**
|
|
* Atributo que oculta boton Generar Mapa
|
|
*/
|
|
private boolean ocultarBtnGmap;
|
|
|
|
/**
|
|
* Incializa el controlador, cuando se esta utilizando una página que
|
|
* utiliza el controlador.
|
|
*/
|
|
private void init() {
|
|
try {
|
|
recperpage = 15; // Cambiar al # reg a mirar.
|
|
lrecord = new ArrayList<>();
|
|
beanalias = "SITIOALMACENAMIENTO";
|
|
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Post Construct
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
@PostConstruct
|
|
private void postconstruct() {
|
|
this.init();
|
|
super.startQuery();
|
|
|
|
ocultarBtnGmap = true;
|
|
}
|
|
|
|
/**
|
|
* Método para consultar registros de la base de datos
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
this.addFilter("estado", "ACT");
|
|
DtoQuery dto = super.getDtoQuery(true);
|
|
|
|
SubQuery sprovincia = new SubQuery("TgeneProvince", "description",
|
|
"desprovincia",
|
|
"i.pk.countrycode = t.countrycode and i.pk.provincecode= t.provincecode");
|
|
SubQuery scanton = new SubQuery(
|
|
"TgeneCanton",
|
|
"description",
|
|
"descanton",
|
|
"i.pk.countrycode = t.countrycode and i.pk.provincecode=t.provincecode and i.pk.cantoncode=t.cantoncode");
|
|
SubQuery sparroquia = new SubQuery(
|
|
"TgeneParroquia",
|
|
"description",
|
|
"desparroquia",
|
|
"i.pk.countrycode = t.countrycode and i.pk.provincecode=t.provincecode and i.pk.cantoncode=t.cantoncode and i.pk.parroquiacode=t.parroquiacode");
|
|
|
|
//nombre
|
|
SubQuery snombre= new SubQuery
|
|
("TcustPersonDetail", "name", "nombre", "i.pk.personcode = t.personcode and i.pk.dateto=(select max(dt.pk.dateto) from TcustPersonDetail dt where dt.pk.personcode=t.personcode)");
|
|
|
|
|
|
dto.addSubQuery(sprovincia);
|
|
dto.addSubQuery(scanton);
|
|
dto.addSubQuery(sparroquia);
|
|
|
|
dto.addSubQuery(snombre);
|
|
|
|
dto.setOrderby("t.countrycode");
|
|
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);
|
|
|
|
Response resp = this.callerhelper.executeQuery(request);
|
|
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
|
|
this.lrecord = new ArrayList<TarmSitioAlmacenamiento>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
this.lrecord = (List<TarmSitioAlmacenamiento>) resp
|
|
.get(this.beanalias);
|
|
super.postQuery(this.lrecord);
|
|
listaVacia();
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
public void listaVacia() {
|
|
if (lrecord.size() != 0) {
|
|
ocultarBtnGmap = false;
|
|
} else {
|
|
ocultarBtnGmap = true;
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Método para abrir el lov de Provincia.
|
|
*/
|
|
public void openProvinciaLov() {
|
|
Map<String, List<String>> params = new HashMap<>();
|
|
ProvinceLovController.openLov(params);
|
|
}
|
|
|
|
public void onReturnProvinceLov(SelectEvent event) throws Exception {
|
|
TgeneProvince t = (TgeneProvince) event.getObject();
|
|
super.addFilter("pk.provincecode", t.getPk().getProvincecode());
|
|
super.addField("description", t.getDescription());
|
|
this.query();
|
|
}
|
|
|
|
/**
|
|
* Método para generar Mapa y mostrar los marcadores de latitud y
|
|
* longitud dentro del mapa
|
|
*/
|
|
public void generarMapa() {
|
|
|
|
if (lrecord != null) {
|
|
LatLng coord = null;
|
|
simpleModel = new DefaultMapModel();
|
|
for (TarmSitioAlmacenamiento c : lrecord) {
|
|
try {
|
|
coord = new LatLng(c.getLatitud().doubleValue(), c
|
|
.getLongitud().doubleValue());
|
|
} catch (Exception e) {
|
|
// TODO: handle exception
|
|
}
|
|
simpleModel.addOverlay(new Marker(coord, "quito"));
|
|
}
|
|
}
|
|
}
|
|
|
|
public void limpiar()
|
|
{
|
|
lrecord = new ArrayList<>();
|
|
simpleModel = new DefaultMapModel();
|
|
this.getMfilters().remove("pk.provincecode");
|
|
this.getMfilelds().remove("description");
|
|
}
|
|
|
|
/**
|
|
* Lanza el evento simpleModel
|
|
*
|
|
* @param event
|
|
*/
|
|
public void onMarkerDrag(MarkerDragEvent event) {
|
|
// since marker's state is already kept in draggableModel you do not
|
|
// necessarily
|
|
}
|
|
|
|
/**
|
|
* Selecciona un marcador dentro de gmap
|
|
*
|
|
* @param event
|
|
*/
|
|
public void onMarkerSelect(OverlaySelectEvent event) {
|
|
marker = (Marker) event.getOverlay();
|
|
|
|
addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO,
|
|
"Marker Selected", marker.getTitle()));
|
|
}
|
|
|
|
public void addMessage(FacesMessage message) {
|
|
FacesContext.getCurrentInstance().addMessage(null, message);
|
|
}
|
|
|
|
/**
|
|
* Incrementa el numero del documento
|
|
* @param arma
|
|
* @return
|
|
*/
|
|
public int incrementarRowkey(TarmSitioAlmacenamiento sitio){
|
|
int n=0;
|
|
|
|
for (int i = 0; i < this.lrecord.size(); i++) {
|
|
if(sitio.getPk()==this.lrecord.get(i).getPk()){
|
|
n=i+1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return n;
|
|
}
|
|
|
|
// **
|
|
// **ACCESORES Y MUTADORES
|
|
// **
|
|
public final MapModel getSimpleModel() {
|
|
return simpleModel;
|
|
}
|
|
|
|
public final void setSimpleModel(MapModel simpleModel) {
|
|
this.simpleModel = simpleModel;
|
|
}
|
|
|
|
public final Marker getMarker() {
|
|
return marker;
|
|
}
|
|
|
|
public final void setMarker(Marker marker) {
|
|
this.marker = marker;
|
|
}
|
|
|
|
/**
|
|
* Entrega V/F
|
|
*
|
|
* @return ocultarBtnGmap
|
|
*/
|
|
public boolean isOcultarBtnGmap() {
|
|
return ocultarBtnGmap;
|
|
}
|
|
|
|
/**
|
|
* Fija V/F
|
|
*
|
|
* @param ocultarBtnGmap
|
|
*/
|
|
public void setOcultarBtnGmap(boolean ocultarBtnGmap) {
|
|
this.ocultarBtnGmap = ocultarBtnGmap;
|
|
}
|
|
|
|
}
|