283 lines
11 KiB
Plaintext
Executable File
283 lines
11 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.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.dto.save.DtoSave;
|
|
import com.fp.frontend.controller.AbstractController;
|
|
import com.fp.frontend.controller.armas.parametros.CentroControlArmasController;
|
|
import com.fp.frontend.controller.armas.parametros.TarmCentroControlJurController;
|
|
import com.fp.frontend.controller.pcustomer.PersonAddressController;
|
|
import com.fp.frontend.controller.pgeneral.gene.CatalogDetailController;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.persistence.parmas.param.TarmCentroControl;
|
|
import com.fp.persistence.parmas.param.TarmCentroControlJur;
|
|
import com.fp.persistence.parmas.soli.TarmSolicitudTramite;
|
|
import com.fp.persistence.pcustomer.gene.TcustPersonAddress;
|
|
import com.fp.persistence.pgeneral.safe.TsafeUserDetail;
|
|
|
|
public class TarmSolicitudTramiteController extends AbstractController<TarmSolicitudTramite> {
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 3067036498159997318L;
|
|
|
|
private static TsafeUserDetail tsafeUserDetailUsuario = null;
|
|
|
|
private static TarmCentroControl centroControl = null;
|
|
|
|
|
|
|
|
|
|
protected TarmSolicitudTramiteController() throws Exception {
|
|
super(TarmSolicitudTramite.class);
|
|
// TODO Auto-generated constructor stub
|
|
}
|
|
|
|
@PostConstruct
|
|
private void postconstruct() {
|
|
this.init();
|
|
// Inicializa autoconsulta
|
|
super.startQuery();
|
|
super.getMfilters().clear();
|
|
}
|
|
|
|
/**
|
|
* Incializa el controlador, cuando se esta utilizando una pagina que utliza el controlador.
|
|
*/
|
|
private void init() {
|
|
try {
|
|
recperpage = 15; // Cambiar al # reg a mirar.
|
|
lrecord = new ArrayList<>();
|
|
beanalias = "TARMSOLICITUDTRAMITECONTROLLER";
|
|
this.tsafeUserDetailUsuario = (TsafeUserDetail) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("TSAFEUSERDETAIL");
|
|
this.centroControl = new TarmCentroControl();
|
|
this.create();
|
|
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
DtoQuery dto = super.getDtoQuery(true);
|
|
dto.setOrderby("t.pk desc");
|
|
Filter f=new Filter();
|
|
if(this.getMfilelds().get("tramites")!=null){
|
|
f.setSql(this.getMfilelds().get("tramites").toString());
|
|
dto.addFiltro(f);
|
|
}
|
|
|
|
SubQuery qry2 = new SubQuery("TgeneCatalogDetail", "description", "tipotramitedesc",
|
|
"i.pk.catalog = (select a.tipoautorizacion from TarmTramite a where a.pk = t.pk.ctramite) "// t.pk.csolicitud
|
|
+ " and "
|
|
+ "i.pk.catalogcode = (select a.tipoautorizacioncodigo from TarmTramite a where a.pk = t.pk.ctramite)");
|
|
dto.addSubQuery(qry2);
|
|
|
|
SubQuery qry3 = new SubQuery("TgeneCatalogDetail", "description", "categoriadesc",
|
|
"i.pk.catalog = (select a.categoria from TarmTramite a where a.pk = t.pk.ctramite) "// t.pk.csolicitud
|
|
+ " and "
|
|
+ "i.pk.catalogcode = (select a.categoriacodigo from TarmTramite a where a.pk = t.pk.ctramite)");
|
|
dto.addSubQuery(qry3);
|
|
|
|
SubQuery qry4 = new SubQuery("TgeneCatalogDetail", "description", "usodesc",
|
|
"i.pk.catalog = (select a.usoactividad from TarmTramite a where a.pk = t.pk.ctramite) "// t.pk.csolicitud
|
|
+ " and "
|
|
+ "i.pk.catalogcode = (select a.usoactividadcodigo from TarmTramite a where a.pk = t.pk.ctramite)");
|
|
dto.addSubQuery(qry4);
|
|
|
|
SubQuery qry5 = new SubQuery("TcustPersonDetail", "identification", "cedula",
|
|
"i.pk.personcode = (select a.personcode from TarmSolicitud a where a.pk = t.pk.csolicitud) and i.pk.dateto = to_date('2999-12-31', 'YYYY-MM-DD')");
|
|
dto.addSubQuery(qry5);
|
|
|
|
SubQuery qry6 = new SubQuery("TcustPersonDetail", "name", "nombre",
|
|
"i.pk.personcode = (select a.personcode from TarmSolicitud a where a.pk = t.pk.csolicitud) and i.pk.dateto = to_date('2999-12-31', 'YYYY-MM-DD')");
|
|
dto.addSubQuery(qry6);
|
|
|
|
SubQuery qry7 = new SubQuery("TcustPersonDetail", "pk.personcode", "personcode",
|
|
"i.pk.personcode = (select a.personcode from TarmSolicitud a where a.pk = t.pk.csolicitud) and i.pk.dateto = to_date('2999-12-31', 'YYYY-MM-DD')");
|
|
dto.addSubQuery(qry7);
|
|
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
mtables.put(beanalias, dto); // permite adicionar mas de una tabla.
|
|
|
|
Request request = callerhelper.getRequest();
|
|
request.setQueryTables(mtables);
|
|
|
|
Response resp = callerhelper.executeQuery(request);
|
|
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
|
|
lrecord = new ArrayList<TarmSolicitudTramite>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
lrecord = (List<TarmSolicitudTramite>) resp.get(beanalias);
|
|
if(!lrecord.isEmpty()){
|
|
record=lrecord.get(0);
|
|
}
|
|
super.postQuery(lrecord);
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
public void cambiarEstado(String estadoTramite,String estadoTramiteCodigo){
|
|
record.setEstadotramite(estadoTramite);
|
|
record.setEstadotramitecodigo(estadoTramiteCodigo);
|
|
}
|
|
|
|
@Override
|
|
public void save() {
|
|
try {
|
|
update();
|
|
|
|
DtoSave dtosave = super.getDtoSave();
|
|
dtosave.setReturnpk(true); // Para que el core devuelva el pk de los registros nuevos.
|
|
HashMap<String, DtoSave> msave = new HashMap<String, DtoSave>();
|
|
|
|
Request request = callerhelper.getRequest();
|
|
msave.put(beanalias, dtosave); // adicionar metadata de mantenimiento para cada tabla.
|
|
|
|
request.setSaveTables(msave);
|
|
Response resp = callerhelper.executeSave(request);
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
|
|
this.postCommit(resp);
|
|
MessageHelper.setMessageInfo(resp);
|
|
} else {
|
|
MessageHelper.setMessageError(resp);
|
|
}
|
|
|
|
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Obtiene el centro de control segun usurio logeado.
|
|
* @throws Exception
|
|
*
|
|
*/
|
|
private static String obtenerCentroControl() throws Exception {
|
|
|
|
tsafeUserDetailUsuario = (TsafeUserDetail) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("TSAFEUSERDETAIL");
|
|
PersonAddressController personAddressController = new PersonAddressController();
|
|
TcustPersonAddress tcustPersonAddres=personAddressController.findPrincipal(tsafeUserDetailUsuario.getPk().getPersoncode().toString());
|
|
if(tcustPersonAddres == null){
|
|
return null;
|
|
}
|
|
TarmCentroControlJur centroControlJur= TarmCentroControlJurController.findxProvincia(tcustPersonAddres.getProvincecode());
|
|
centroControl= CentroControlArmasController.findPorCodigo(centroControlJur.getCcentrocontrol());
|
|
return CatalogDetailController.findxCodigoCodcatalogo( centroControl.getNombreinstitucion(), centroControl.getNombreinstitucioncodigo()).getDescription();
|
|
}
|
|
|
|
|
|
public static TarmSolicitudTramite findPorCtramite(String ctramite) {
|
|
try {
|
|
TarmSolicitudTramiteController cc = new TarmSolicitudTramiteController();
|
|
cc.init();
|
|
cc.recperpage = 300;
|
|
cc.addFilter("pk.ctramite", ctramite);
|
|
cc.querydatabase();
|
|
if (cc.record != null) {
|
|
return cc.record;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static List<TarmSolicitudTramite> findPorCodigoTramite(String ctramite) {
|
|
try {
|
|
TarmSolicitudTramiteController cc = new TarmSolicitudTramiteController();
|
|
cc.init();
|
|
cc.recperpage = 300;
|
|
cc.addFilter("pk.ctramite", ctramite);
|
|
cc.querydatabase();
|
|
if (cc.record != null) {
|
|
return cc.lrecord;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static TarmSolicitudTramite findPorCSolicitud(String csolicitud) {
|
|
try {
|
|
if(csolicitud==null || csolicitud.isEmpty()){
|
|
return null;
|
|
}
|
|
TarmSolicitudTramiteController cc = new TarmSolicitudTramiteController();
|
|
cc.init();
|
|
cc.recperpage = 300;
|
|
cc.addFilter("pk.csolicitud", csolicitud);
|
|
cc.querydatabase();
|
|
if (cc.record != null) {
|
|
return cc.record;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
public static TarmSolicitudTramite findPorCSolicitudYCTramite(String csolicitud,String ctramite) {
|
|
try {
|
|
TarmSolicitudTramiteController cc = new TarmSolicitudTramiteController();
|
|
cc.init();
|
|
cc.recperpage = 300;
|
|
cc.addFilter("pk.csolicitud", csolicitud);
|
|
cc.addFilter("pk.ctramite", ctramite);
|
|
cc.querydatabase();
|
|
if (cc.record != null) {
|
|
return cc.record;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static List<TarmSolicitudTramite> findTramites() {
|
|
try {
|
|
TarmSolicitudTramiteController cc = new TarmSolicitudTramiteController();
|
|
cc.init();
|
|
cc.recperpage = 30000000;
|
|
obtenerCentroControl();
|
|
cc.addField("tramites", " ctramite in (select b.pk from TarmTramite b where b.tipoautorizacion = 1 and b.categoria = 14) and estadotramite in ('APB','FIN') and csolicitud in (select a.pk from TarmSolicitud a where a.ccentrocontrol = '"+centroControl.getPk()+"') and csolicitud in (select d.csolicitud from TarmDocumentoHabilitante d where d.estado = 'APR' )"
|
|
+ " AND EXISTS(SELECT ARM FROM TarmSolicitudArmas solarm, TarmArmas arm WHERE solarm.pk.csolicitud = t.pk.csolicitud AND solarm.pk.carma = arm.pk AND arm.lote is null)");
|
|
cc.querydatabase();
|
|
if (cc.record != null) {
|
|
return cc.lrecord;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
}
|