151 lines
6.4 KiB
Plaintext
Executable File
151 lines
6.4 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.solicitud;
|
|
|
|
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 com.fp.dto.Request;
|
|
import com.fp.dto.Response;
|
|
import com.fp.dto.query.DtoQuery;
|
|
import com.fp.dto.query.SubQuery;
|
|
import com.fp.dto.save.DtoSave;
|
|
import com.fp.frontend.controller.AbstractController;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.persistence.parmas.soli.TarmSolicitudAgenciaSucursal;
|
|
|
|
/**
|
|
* Controlador que maneja {@link TarmSolicitudAgenciaSucursal}
|
|
* @author dcruz
|
|
*
|
|
*/
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class SolicitudAgenciaSucursalController extends
|
|
AbstractController<TarmSolicitudAgenciaSucursal> {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
public SolicitudAgenciaSucursalController() throws Exception {
|
|
super(TarmSolicitudAgenciaSucursal.class);
|
|
}
|
|
|
|
@PostConstruct
|
|
public void postConstruct() {
|
|
this.init();
|
|
// this.querydatabase();
|
|
}
|
|
|
|
private void init(){
|
|
this.lrecord = new ArrayList<>();
|
|
this.beanalias = "SOLICITUDAGENCIA";
|
|
this.recperpage = 15;
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
DtoQuery dto = this.getDtoQuery();
|
|
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
mtables.put(beanalias, dto);//se puede aniadir mas tablas
|
|
Request request = callerhelper.getRequest();
|
|
request.setQueryTables(mtables);
|
|
Response response = callerhelper.executeQuery(request);
|
|
if(response.getResponseCode().compareTo(Response.RESPONSE_OK) != 0){
|
|
this.lrecord = new ArrayList<>();
|
|
MessageHelper.setMessageError(response);
|
|
} else{
|
|
this.lrecord = (List<TarmSolicitudAgenciaSucursal>) response.get(beanalias);
|
|
this.postQuery(lrecord);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
private DtoQuery getDtoQuery() throws Exception {
|
|
DtoQuery dto = super.getDtoQuery(Boolean.TRUE);
|
|
SubQuery subQueryNombre = new SubQuery("TarmAgenciaSucursal","nombre","nombre"," i.pk=t.pk.cagencia");
|
|
dto.addSubQuery(subQueryNombre);
|
|
|
|
SubQuery subQueryResponsable = new SubQuery("TarmAgenciaSucursal","responsable","responsable"," i.pk=t.pk.cagencia");
|
|
dto.addSubQuery(subQueryResponsable);
|
|
|
|
SubQuery subQueryTipo = new SubQuery("TgeneCatalogDetail", "description", "ntipo", "i.pk.catalog = (select o.tipo from TarmAgenciaSucursal o where o.pk=t.pk.cagencia)"
|
|
+ " and i.pk.catalogcode=(select o.tipocodigo from TarmAgenciaSucursal o where o.pk=t.pk.cagencia)");
|
|
dto.addSubQuery(subQueryTipo);
|
|
SubQuery subQueryEstado = new SubQuery("TgeneCatalogDetail", "description", "nestado", "i.pk.catalog = (select o.estado from TarmAgenciaSucursal o where o.pk=t.pk.cagencia) "
|
|
+ " and i.pk.catalogcode=(select o.estadocodigo from TarmAgenciaSucursal o where o.pk=t.pk.cagencia)");
|
|
dto.addSubQuery(subQueryEstado);
|
|
SubQuery subQueryProvincia = new SubQuery("TgeneProvince", "description", "nprovincia", "i.pk.provincecode=(select o.provincecode from TarmAgenciaSucursal o where o.pk=t.pk.cagencia)"
|
|
+ " and i.pk.countrycode= (select o.countrycode from TarmAgenciaSucursal o where o.pk=t.pk.cagencia)");
|
|
dto.addSubQuery(subQueryProvincia);
|
|
SubQuery subQueryCanton = new SubQuery("TgeneCanton", "description", "ncanton", "i.pk.countrycode= (select o.countrycode from TarmAgenciaSucursal o where o.pk=t.pk.cagencia)"
|
|
+ " and i.pk.provincecode=(select o.provincecode from TarmAgenciaSucursal o where o.pk=t.pk.cagencia)"
|
|
+ " and i.pk.cantoncode= (select o.cantoncode from TarmAgenciaSucursal o where o.pk=t.pk.cagencia)");
|
|
dto.addSubQuery(subQueryCanton);
|
|
SubQuery subQueryParroquia = new SubQuery("TgeneParroquia","description","nparroquia","i.pk.countrycode= (select o.countrycode from TarmAgenciaSucursal o where o.pk=t.pk.cagencia) "
|
|
+ " and i.pk.provincecode=(select o.provincecode from TarmAgenciaSucursal o where o.pk=t.pk.cagencia) "
|
|
+ " and i.pk.cantoncode= (select o.cantoncode from TarmAgenciaSucursal o where o.pk=t.pk.cagencia) "
|
|
+ " and i.pk.parroquiacode=(select o.parroquiacode from TarmAgenciaSucursal o where o.pk=t.pk.cagencia)");
|
|
dto.addSubQuery(subQueryParroquia);
|
|
SubQuery subQueryCiudad = new SubQuery("TgeneCity","description","nciudad","i.pk.countrycode= (select o.countrycode from TarmAgenciaSucursal o where o.pk=t.pk.cagencia) "
|
|
+ " and i.pk.provincecode=(select o.provincecode from TarmAgenciaSucursal o where o.pk=t.pk.cagencia)"
|
|
+ " and i.pk.cantoncode=(select o.cantoncode from TarmAgenciaSucursal o where o.pk=t.pk.cagencia)"
|
|
+ " and i.pk.citycode=(select o.citycode from TarmAgenciaSucursal o where o.pk=t.pk.cagencia)");
|
|
dto.addSubQuery(subQueryCiudad);
|
|
return dto;
|
|
}
|
|
|
|
|
|
@Override
|
|
public void save() {
|
|
try {
|
|
DtoSave dto = super.getDtoSave();
|
|
if(!dto.pendingProcess()){
|
|
return;
|
|
}
|
|
HashMap<String, DtoSave> msaves = new HashMap<String, DtoSave>();
|
|
msaves.put(beanalias, dto);
|
|
Request request = callerhelper.getRequest();
|
|
request.setSaveTables(msaves);
|
|
Response response = callerhelper.executeSave(request);
|
|
if(response.getResponseCode().compareTo(Response.RESPONSE_OK) == 0){
|
|
this.postCommit(response);
|
|
MessageHelper.setMessageInfo(response);
|
|
} else{
|
|
MessageHelper.setMessageError(response);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* M\u00e9todo para encontrar por solicitud
|
|
* @param solicitudCode
|
|
* @return List<TarmSolicitudAgenciaSucursal>
|
|
*/
|
|
public static List<TarmSolicitudAgenciaSucursal> findPorSolicitud(String solicitudCode) {
|
|
try {
|
|
SolicitudAgenciaSucursalController cc = new SolicitudAgenciaSucursalController();
|
|
cc.init();
|
|
cc.recperpage = 300;
|
|
cc.addFilter("pk.csolicitud", solicitudCode);
|
|
cc.querydatabase();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
}
|