798 lines
28 KiB
Plaintext
Executable File
798 lines
28 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.parametros;
|
|
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.io.PrintWriter;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.faces.bean.ManagedBean;
|
|
import javax.faces.bean.ManagedProperty;
|
|
import javax.faces.bean.ViewScoped;
|
|
import javax.faces.context.FacesContext;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.primefaces.event.FileUploadEvent;
|
|
import org.primefaces.model.UploadedFile;
|
|
|
|
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.save.DtoSave;
|
|
import com.fp.frontend.controller.AbstractController;
|
|
import com.fp.frontend.controller.armas.funcionalidad.RegistroArmController;
|
|
import com.fp.frontend.controller.armas.solicitud.DecomisoArmaController;
|
|
import com.fp.frontend.controller.armas.solicitud.DecomisoController;
|
|
import com.fp.frontend.controller.pcustomer.PersonDetailController;
|
|
import com.fp.frontend.controller.pgeneral.gene.CantonController;
|
|
import com.fp.frontend.controller.pgeneral.gene.CatalogDetailController;
|
|
import com.fp.frontend.controller.pgeneral.gene.ParametersController;
|
|
import com.fp.frontend.controller.pgeneral.gene.ProvinceController;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.persistence.parmas.fun.TarmRegistroArmas;
|
|
import com.fp.persistence.parmas.param.TarmCentroControl;
|
|
import com.fp.persistence.parmas.param.TarmTipoArmaExplosivo;
|
|
import com.fp.persistence.parmas.soli.TarmArmas;
|
|
import com.fp.persistence.parmas.soli.TarmDecomiso;
|
|
import com.fp.persistence.pcustomer.gene.TcustPersonDetail;
|
|
import com.fp.persistence.pgeneral.gene.TgeneCanton;
|
|
import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail;
|
|
import com.fp.persistence.pgeneral.gene.TgeneParameters;
|
|
import com.fp.persistence.pgeneral.gene.TgeneProvince;
|
|
import com.fp.persistence.pgeneral.safe.TsafeUserDetail;
|
|
|
|
@SuppressWarnings("serial")
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class ImporteArmasController extends AbstractController<TarmArmas> {
|
|
|
|
/* CATALOGOS */
|
|
/* TIPO ARMA EXPLOSIVO */
|
|
private List<TgeneCatalogDetail> listLongitudes;
|
|
private List<TgeneCatalogDetail> listCalibres;
|
|
private List<TgeneCatalogDetail> listClases;
|
|
private List<TgeneCatalogDetail> listTipoArmaExplosivos;
|
|
/* ADICONAL */
|
|
private List<TgeneCatalogDetail> listMarcas;
|
|
private List<TgeneCatalogDetail> listTipoFabricacion;
|
|
|
|
/**
|
|
* Variable para a;adir las armas que se van a Guardar
|
|
*/
|
|
private List<TarmArmas> listArmas;
|
|
/**
|
|
* registro del Arma Due;o de las armas
|
|
*/
|
|
private TarmRegistroArmas registroArma;
|
|
/**
|
|
* Cabecera del decomiso
|
|
*/
|
|
private TarmDecomiso tarmDecomiso;
|
|
/**
|
|
* Variable para listar los errores al cargar el excel
|
|
*/
|
|
private List<String> listaErrores;
|
|
/**
|
|
* Mensaje de error
|
|
*/
|
|
private String mensajeError;
|
|
/**
|
|
* numero de armas procesadas
|
|
*/
|
|
private Integer numArmasProcesadas;
|
|
/**
|
|
* numero de armas con error
|
|
*/
|
|
private Integer numArmasError;
|
|
/**
|
|
* numero de armas con error
|
|
*/
|
|
private Integer numCorrectas;
|
|
/**
|
|
* Centro de control Policoa Judicia 2/PN07
|
|
*/
|
|
private TarmCentroControl centroControl;
|
|
|
|
/**
|
|
* Detalle del usuario
|
|
*/
|
|
private TcustPersonDetail usuario;
|
|
|
|
/**
|
|
* Nombre del centro de control logeado
|
|
*/
|
|
private String centroControlNombreLogeado;
|
|
/**
|
|
* Numero de registro
|
|
*/
|
|
private String numeroRecibo;
|
|
|
|
/*Constante centro control*/
|
|
private String nombreInstitucion;
|
|
private String institucion;
|
|
/*Cedula del propietario*/
|
|
private String cedulaPropietario;
|
|
/*motivo incautacion*/
|
|
private String motivocatalogo;
|
|
/*cantidad de armas*/
|
|
private Integer cantidad=1;
|
|
|
|
@ManagedProperty(value = "#{registroArmController}")
|
|
private RegistroArmController registroArmasController;
|
|
|
|
/**
|
|
* Controlador que maneja el decomiso TarmDecomiso
|
|
*/
|
|
@ManagedProperty(value = "#{decomisoController}")
|
|
private DecomisoController decomisoController;
|
|
|
|
/**
|
|
* Controlador que maneja TarmDecomisoArma
|
|
*/
|
|
@ManagedProperty(value = "#{decomisoArmaController}")
|
|
private DecomisoArmaController decomisoArmaController;
|
|
|
|
public ImporteArmasController() 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 = "ARMASIMPORTE";
|
|
listArmas = new ArrayList<TarmArmas>();
|
|
registroArma = new TarmRegistroArmas();
|
|
cargaParametros();
|
|
cargaCatalogos();
|
|
cargaRegistroArma();
|
|
cargaUsuarioLogeado();
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
public void cargaParametros(){
|
|
nombreInstitucion=codigos("CODIGO.NOM.INSTIT.IMPORTE");//"PJ01"
|
|
institucion=codigos("CODIGO.INSTITUCION.IMPORTE");//2
|
|
/*Cedula del propietario*/
|
|
cedulaPropietario=codigos("CEDULA.PROPIETARIO.IMPORTE");//"999999999";
|
|
/*motivo incautacion*/
|
|
motivocatalogo=codigos("MOTIVO.IMPORTE");//"9";
|
|
}
|
|
|
|
/**
|
|
* Método para obtener los codigos
|
|
*/
|
|
private String codigos(String parametro){
|
|
TgeneParameters tgeneParameters= ParametersController.find(parametro, "1");
|
|
return tgeneParameters.getTextvalue();
|
|
}
|
|
|
|
public void cargaCatalogos() {
|
|
/* TIPOARMAEXPLOSIVO */
|
|
listLongitudes = CatalogDetailController.find("LONGITUD");
|
|
listCalibres = CatalogDetailController.find("CALIBRE");
|
|
listClases = CatalogDetailController.find("CLASE");
|
|
listTipoArmaExplosivos = CatalogDetailController.find("TIPOARMAEXPLOSIVO");
|
|
/* CATALOGO AD */
|
|
listMarcas = CatalogDetailController.find("MARCA");
|
|
listTipoFabricacion = CatalogDetailController.find("TIPOFABRICACION");
|
|
//listColor = CatalogDetailController.find("COLOR");
|
|
}
|
|
|
|
public void cargaUsuarioLogeado(){
|
|
TsafeUserDetail tsafeUserDetail=(TsafeUserDetail)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("TSAFEUSERDETAIL");
|
|
usuario=PersonDetailController.find(tsafeUserDetail.getPk().getPersoncode().toString());
|
|
centroControlNombreLogeado = tsafeUserDetail.getModifiedData().get("centrocontrol").toString();
|
|
}
|
|
|
|
public void cargaRegistroArma() {
|
|
TcustPersonDetail tcustPersonDetail = PersonDetailController.findByIdentification(cedulaPropietario);
|
|
registroArma.setPersoncode(tcustPersonDetail.getPk().getPersoncode());
|
|
registroArma.setFcreacion(new java.sql.Date(new Date().getTime()));
|
|
registroArma.setTiporegistro("INCA");
|
|
registroArma.setTiporegistrocodigo("TIPOREGISTRO");
|
|
registroArma.setPaisorigen("");
|
|
registroArma.setIsnew(true);
|
|
|
|
List<TarmCentroControl>listCentroControls= CentroControlArmasController.findxOrganismoUnidad(institucion,nombreInstitucion);
|
|
if(listCentroControls!=null && listCentroControls.size()==1){
|
|
centroControl=listCentroControls.get(0);
|
|
}else{
|
|
centroControl=null;
|
|
mensajeError="NO TIENE REGISTRADO UN CENTRO DE CONTROL O TIENE REGISTRADO MAS DE UNO CON EL MISMO NOMBRE DE INSTITUCI\u00d3N Y NOMBRE INSTITUCI\u00d3N";
|
|
}
|
|
}
|
|
|
|
/*
|
|
* (non-Javadoc)
|
|
*
|
|
* @see com.fp.frontend.controller.AbstractController#querydatabase()
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
public void querydatabase() {
|
|
try {
|
|
|
|
DtoQuery dto = super.getDtoQuery(true);
|
|
Filter filtrofecha = new Filter();
|
|
filtrofecha
|
|
.setSql("t.fecharegistro=(select max(ta.fecharegistro) from TarmArmas ta where t.codigoarma=ta.codigoarma and t.cregistro=ta.cregistro) and t.estado !='DEST' and t.estado !='CDP'");
|
|
dto.addFiltro(filtrofecha);
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
public void save() {
|
|
try {
|
|
if(centroControl==null){
|
|
MessageHelper.setMessageError("NO TIENE CENTRO DE CONTROL REVISE EL CENTRO DE CONTROL");
|
|
return;
|
|
}
|
|
if(listArmas==null || listArmas.size()==0 || listArmas.isEmpty()){
|
|
MessageHelper.setMessageError("NO EXISTEN ARMAS CARGADAS ");
|
|
return;
|
|
}
|
|
HashMap<String, DtoSave> msave = new HashMap<String, DtoSave>();
|
|
Request request = this.callerhelper.getRequest();
|
|
// regstroArma
|
|
registroArmasController.clearAll();
|
|
registroArmasController.setRecord(registroArma);
|
|
registroArmasController.update();
|
|
DtoSave dtosaveregistroarma = registroArmasController.getDtoSave(true);
|
|
dtosaveregistroarma.setPosition(1);
|
|
msave.put(registroArmasController.getBeanalias(),dtosaveregistroarma);
|
|
|
|
// cargar Armas
|
|
this.clearAll();
|
|
cargarArmas();
|
|
DtoSave dtosave = super.getDtoSave(true);
|
|
dtosave.setPosition(2);
|
|
msave.put(this.beanalias, dtosave);
|
|
|
|
//carga tarmdecomiso
|
|
decomisoController.clearAll();
|
|
tarmDecomiso= new TarmDecomiso();
|
|
tarmDecomiso.setIsnew(true);
|
|
tarmDecomiso.setTipoprocesocode("TIPOREGISTRO");
|
|
tarmDecomiso.setTipoproceso("INCA");
|
|
tarmDecomiso.setCcentrocontrol(centroControl.getPk());
|
|
tarmDecomiso.setNumerorecibo(numeroRecibo);//numero de oficio
|
|
tarmDecomiso.setFecharegistro(new java.sql.Date(new Date().getTime()));
|
|
//tarmDecomiso.setOrganismocontrol(centroControlNombreLogeado);
|
|
tarmDecomiso.setOrganismocontrol(centroControl.getModifiedData().get("desinstitucion").toString());
|
|
tarmDecomiso.setPersoncoderegistra(usuario.getPk().getPersoncode());
|
|
|
|
//tarmDecomiso.setNumerotransaccion(pNumerotransaccion);
|
|
decomisoController.setRecord(tarmDecomiso);
|
|
decomisoController.update();
|
|
DtoSave dtoDecomiso = decomisoController.getDtoSave(true);
|
|
dtoDecomiso.setPosition(3);
|
|
msave.put("IMPORTEDECOMISO",dtoDecomiso);
|
|
|
|
//Tarmdecomisoarma
|
|
decomisoArmaController.clearAll();
|
|
DtoSave dtoDecomisoArma = decomisoArmaController.getDtoSave(true);
|
|
dtoDecomisoArma.setPosition(4);
|
|
msave.put(decomisoArmaController.getBeanalias(),dtoDecomisoArma);
|
|
|
|
request.setSaveTables(msave);
|
|
//request.getModifiedData().put("REGISTRO", this.registroArma);
|
|
|
|
Response resp = this.callerhelper.executeSave(request);
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
|
|
this.postCommit(resp);
|
|
mensajeError=null;
|
|
MessageHelper.setMessageInfo(resp);
|
|
listArmas.clear();
|
|
} else {
|
|
MessageHelper.setMessageError(resp);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void postCommit(Response response) throws Exception {
|
|
super.postCommitGeneric(response, beanalias);
|
|
}
|
|
|
|
public void cargarArmas() throws Exception {
|
|
for (TarmArmas item : listArmas) {
|
|
item.setEstadoDecomiso(numeroRecibo);
|
|
this.record = item;
|
|
record.setIsnew(true);
|
|
super.update();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Metodo que carga y valida el contenido de un archivo excel con
|
|
* información de armas
|
|
*
|
|
* @param event
|
|
*/
|
|
public void cargarArchivo(FileUploadEvent event) {
|
|
listArmas = new ArrayList<TarmArmas>();
|
|
listaErrores = new ArrayList<String>();
|
|
int cont = 0;
|
|
Map<String,String>mapaSerie=new HashMap<String,String>();
|
|
try {
|
|
UploadedFile selectedFile = event.getFile();
|
|
InputStream archivo = selectedFile.getInputstream();
|
|
XSSFWorkbook libro = new XSSFWorkbook(archivo);
|
|
XSSFSheet hoja = libro.getSheetAt(0);
|
|
// Iterando sobre las filas
|
|
Iterator<Row> rowIterator = hoja.iterator();
|
|
// Cargando el contenido de las celdas a una lista de objetos
|
|
while (rowIterator.hasNext()) {
|
|
Row row = rowIterator.next();
|
|
if(cont!=0){
|
|
System.out.println("NUMERO REGISTROS........."+cont);
|
|
Cell orden = row.getCell(0);
|
|
Cell longuitud = row.getCell(14);
|
|
Cell calibre = row.getCell(5);
|
|
Cell clase = row.getCell(1);//material
|
|
Cell tipoArmaExplosivo = row.getCell(2);// modelo: REVOLVER CARTUCHERA CARTUCHERANO CARABINA SUB-AMETRALLADORA*revisar
|
|
Cell marca = row.getCell(3);
|
|
Cell tipoFabricacion = row.getCell(7);
|
|
Cell serie = row.getCell(4);
|
|
Cell fechaRecepcion = row.getCell(9);
|
|
Cell motivo = row.getCell(10);
|
|
Cell descripcionProvincia= row.getCell(12);
|
|
Cell descripcionCanton= row.getCell(13);
|
|
Cell observaciones= row.getCell(15);
|
|
if (!this.celdaVacia(orden)
|
|
&& !this.celdaVacia(longuitud)
|
|
&& !this.celdaVacia(calibre)
|
|
&& !this.celdaVacia(clase)
|
|
&& !this.celdaVacia(tipoArmaExplosivo)
|
|
&& !this.celdaVacia(marca)
|
|
&& !this.celdaVacia(tipoFabricacion)
|
|
&& !this.celdaVacia(serie)
|
|
&& !this.celdaVacia(fechaRecepcion)
|
|
&& !this.celdaVacia(motivo)
|
|
&& !this.celdaVacia(descripcionProvincia)
|
|
&& !this.celdaVacia(descripcionCanton)
|
|
&& !this.celdaVacia(observaciones)) {
|
|
TarmArmas arma = armarlistaArmasExcel(longuitud,calibre,clase,tipoArmaExplosivo,marca,tipoFabricacion, cont, serie,descripcionProvincia,descripcionCanton);
|
|
if (arma != null) {
|
|
arma.getModifiedData().put("motivo", motivo.toString().trim());
|
|
arma.getModifiedData().put("observaciondecomiso", observaciones.toString().trim());
|
|
arma.getModifiedData().put("cantidad",cantidad);
|
|
arma.getModifiedData().put("motivocatalogocode","MOTIVODECOMISO");
|
|
arma.getModifiedData().put("motivocatalogo",motivocatalogo);//entrega voluntaria
|
|
//dd/MM/yyyy
|
|
try {
|
|
//validar si la serie es repetida
|
|
String serieAux=null;
|
|
if(mapaSerie==null || mapaSerie.size()==0){
|
|
serieAux=serie.toString().trim();
|
|
mapaSerie.put(serieAux,serieAux);
|
|
}else{
|
|
serieAux=mapaSerie.get(serie.toString());
|
|
if(serieAux==null || serieAux.isEmpty()){
|
|
serieAux=serie.toString().trim();
|
|
mapaSerie.put(serieAux,serieAux);
|
|
}else{
|
|
serieAux=null;
|
|
listaErrores.add("SERIE DUPLICADA" + serie.toString()+ " DEL REGISTRO: "+cont);
|
|
}
|
|
}
|
|
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy"); //formatter.parse("7-OCT-016");
|
|
Date date = formatter.parse(fechaRecepcion.toString().trim());
|
|
Calendar cal= Calendar.getInstance();
|
|
cal.setTime(date);
|
|
String anio=cal.get(Calendar.YEAR)+"";
|
|
if(anio!=null && anio.trim().length()==4 && cal.get(Calendar.YEAR)>1900){
|
|
arma.getModifiedData().put("fechaRecepcion",date);
|
|
arma.getModifiedData().put("fechaDecomiso",date);
|
|
//ANIADE EL ARMA
|
|
if(serieAux!=null && !serieAux.isEmpty()){
|
|
listArmas.add(arma);
|
|
}
|
|
}else{
|
|
listaErrores.add("PROBLEMA CON LA FECHA DE RECEPCI\u00d3N " + fechaRecepcion.toString()+ ", EL A\u00d1O: "+anio+" NO CORRESPONDE AL FORMATO, EL FORMATO ES dd-MMM-yyyy EJ:(04-OCT-2017), DEL REGISTRO: "+cont);
|
|
}
|
|
} catch (Exception e) {
|
|
listaErrores.add("PROBLEMA CON LA FECHA DE RECEPCI\u00d3N " + fechaRecepcion.toString()+ ", EL FORMATO ES dd-MMM-yyyy EJ:(04-OCT-2017), DEL REGISTRO: "+cont);
|
|
}
|
|
}
|
|
} else {
|
|
listaErrores.add("EL REGISTRO TIENE CAMPOS EN BLANCO, REGISTRO: " + cont);
|
|
}
|
|
cont++;
|
|
}else{
|
|
cont++;
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
} finally {
|
|
numArmasProcesadas=cont-1;
|
|
if (!listaErrores.isEmpty()) {
|
|
MessageHelper.setMessageError("ERRORES ENCONTRADOS DENTRO DEL ARCHIVO EXCEL: ");
|
|
mensajeError="ERROR EN LA CARGA DE ARMAS";
|
|
// for (String itemError : listaErrores) {
|
|
// mensajeError=mensajeError+" <BR/> "+itemError;
|
|
// }
|
|
numCorrectas=listArmas.size();
|
|
listArmas.clear();
|
|
}else{
|
|
numCorrectas=listArmas.size();
|
|
}
|
|
numArmasError =listaErrores.size();
|
|
}
|
|
}
|
|
|
|
private TarmArmas armarlistaArmasExcel(Cell longuitud, Cell calibre,Cell clase, Cell tipoArmaExplosivo, Cell marca,
|
|
Cell tipoFabricacion, int cont, Cell serie,Cell descripcionProvincia,Cell descripcionCanton) {
|
|
TarmArmas armaRegistro = null;
|
|
TarmTipoArmaExplosivo tarmTipoArmaExplosivo = null;
|
|
String longuitudCodigo = validarCatalogo(listLongitudes, longuitud.toString().trim());
|
|
if(longuitudCodigo==null || longuitudCodigo.isEmpty()){
|
|
listaErrores.add("LA DESCRIPCI\u00d3N DE LA LONGUITUD: "+longuitud.toString()+" NO EXISTE EN EL CAT\u00c1LOGO, DEL REGISTRO: "+ cont);
|
|
}
|
|
String calibreCodigo = validarCatalogo(listCalibres, calibre.toString().trim());
|
|
if(calibreCodigo==null || calibreCodigo.isEmpty()){
|
|
listaErrores.add("LA DESCRIPCI\u00d3N DEL CALIBRE: "+calibre.toString()+" NO EXISTE EN EL CAT\u00c1LOGO, DEL REGISTRO: "+ cont);
|
|
}
|
|
String claseCodigo = validarCatalogo(listClases, clase.toString().trim());
|
|
if(claseCodigo==null || claseCodigo.isEmpty()){
|
|
listaErrores.add("LA DESCRIPCI\u00d3N DE LA CLASE: "+clase.toString()+" NO EXISTE EN EL CAT\u00c1LOGO, DEL REGISTRO: "+ cont);
|
|
}
|
|
String tipoArmaExplosivoCodigo = validarCatalogo(listTipoArmaExplosivos, tipoArmaExplosivo.toString().trim());
|
|
if(tipoArmaExplosivoCodigo==null || tipoArmaExplosivoCodigo.isEmpty()){
|
|
listaErrores.add("LA DESCRIPCI\u00d3N DEL TIPO ARMA EXPLOSIVO: "+tipoArmaExplosivo.toString()+" NO EXISTE EN EL CAT\u00c1LOGO, DEL REGISTRO: "+ cont);
|
|
}
|
|
String unidadMedidaPesoCodigo = "UNIDAD";
|
|
|
|
String marcaCodigo = validarCatalogo(listMarcas, marca.toString().trim());// MARCA
|
|
if (marcaCodigo == null) {
|
|
listaErrores.add("LA MARCA DEL ARMA: "+marca.toString()+" NO EXISTE EN EL CAT\u00c1LOGO, DEL REGISTRO: "+ cont);
|
|
}
|
|
String tipoFabricacionCodigo = validarCatalogo(listTipoFabricacion, tipoFabricacion.toString().trim());// TIPOFABRICACION
|
|
if (tipoFabricacionCodigo == null) {
|
|
listaErrores.add("EL TIPO DE FABRICACI\u00d3N: "+tipoFabricacion.toString()+" NO EXISTE EN EL CAT\u00c1LOGO, DEL REGISTRO: "+ cont);
|
|
}
|
|
/*Ubicacion Provincia canton*/
|
|
TgeneProvince province=null;
|
|
TgeneCanton canton=null;
|
|
List<TgeneProvince>listProvincias=ProvinceController.findxDescripcion("EC", null, descripcionProvincia.toString().trim());
|
|
if(listProvincias!=null ){
|
|
if(listProvincias.size()==1){
|
|
province=listProvincias.get(0);
|
|
List<TgeneCanton> listCantons= CantonController.find("EC", province.getPk().getProvincecode());
|
|
if(listCantons!=null && listCantons.size()!=0){
|
|
for (TgeneCanton item : listCantons) {
|
|
if(item.getDescription().trim().equals(descripcionCanton.toString().trim())){
|
|
canton=item;
|
|
}
|
|
}
|
|
if(canton==null){
|
|
listaErrores.add(" NO EXISTEN CANTONES ASOCIADOS CON LA PROVINCIA: "+descripcionProvincia.toString()+", DEL REGISTRO: "+ cont);
|
|
}
|
|
}else{
|
|
listaErrores.add(" NO EXISTEN CANTONES ASOCIADOS CON LA PROVINCIA: "+descripcionProvincia.toString()+", DEL REGISTRO: "+ cont);
|
|
}
|
|
}else{
|
|
listaErrores.add(" EXISTE MAS DE UNA PROVINCIA: "+descripcionProvincia.toString()+" CON ESTA DESCRIPCI\u00d3N, DEL REGISTRO: "+ cont);
|
|
}
|
|
}else{
|
|
listaErrores.add(" NO EXISTE LA PROVINCIA: "+descripcionProvincia.toString()+" EN EL CAT\u00c1LOGO, DEL REGISTRO: "+ cont);
|
|
}
|
|
|
|
if (marcaCodigo == null || tipoFabricacionCodigo == null || province==null || canton==null) {
|
|
return null;
|
|
}
|
|
/*System.out.println("longuitudCodigo.."+longuitudCodigo);
|
|
System.out.println("calibreCodigo.."+calibreCodigo);
|
|
System.out.println("claseCodigo.."+claseCodigo);
|
|
System.out.println("tipoArmaExplosivoCodigo.."+tipoArmaExplosivoCodigo);
|
|
System.out.println("unidadMedidaPesoCodigo.."+unidadMedidaPesoCodigo);
|
|
*/
|
|
if (longuitudCodigo != null && calibreCodigo != null && claseCodigo != null && tipoArmaExplosivoCodigo != null) {
|
|
tarmTipoArmaExplosivo = ImporteTipoArmaExplosivoController.findpk(longuitudCodigo, calibreCodigo, claseCodigo,tipoArmaExplosivoCodigo, unidadMedidaPesoCodigo);
|
|
if (tarmTipoArmaExplosivo != null) {
|
|
armaRegistro = new TarmArmas();
|
|
armaRegistro.setMarca(marcaCodigo);
|
|
armaRegistro.setMarcacodigo("MARCA");
|
|
armaRegistro.setTipofabricacion(tipoFabricacionCodigo);
|
|
armaRegistro.setTipofabricacioncodigo("TIPOFABRICACION");
|
|
//armaRegistro.setColor(colorCodigo);
|
|
armaRegistro.setColorcodigo("COLOR");
|
|
armaRegistro.setUnidadmedidacantidad("UNIDAD");
|
|
armaRegistro.setUnidadmedidacantidadcodigo("UNIDADMEDIDA");
|
|
armaRegistro.setEstado("INC");
|
|
armaRegistro.setEstadocodigo("ESTADOARMA");
|
|
armaRegistro.setCountrycode("EC");
|
|
armaRegistro.setProvincecode(province.getPk().getProvincecode());
|
|
armaRegistro.setCantoncode(canton.getPk().getCantoncode());
|
|
//armaRegistro.setParroquiacode("");
|
|
// armaRegistro.setCregistro();
|
|
armaRegistro.setCitycode("");
|
|
armaRegistro.setLote(serie.toString().trim());
|
|
armaRegistro.setCantidad(cantidad);
|
|
// armaRegistro.setSeriecanon();
|
|
// armaRegistro.setDireccion();
|
|
armaRegistro.setFecharegistro(new java.sql.Date(new Date().getTime()));
|
|
armaRegistro.setCtipoarmaexplosivo(tarmTipoArmaExplosivo.getPk());
|
|
armaRegistro.setEstadoDecomiso("INC");
|
|
} else {
|
|
listaErrores.add("LA COMBINACION DEL ARMA NO EXISTE EN EL REGISTRO: " + cont+ " ");
|
|
}
|
|
}
|
|
// else {
|
|
// listaErrores.add("EL REGISTRO " + cont + " LA COMBINACION DEL ARMA NO EXISTE");
|
|
// }
|
|
return armaRegistro;
|
|
}
|
|
|
|
public String validarCatalogo(List<TgeneCatalogDetail> listCatalogo,String descripcion) {
|
|
String codigo = null;
|
|
for (TgeneCatalogDetail item : listCatalogo) {
|
|
if (item.getDescription().equals(descripcion)) {
|
|
codigo = item.getPk().getCatalog();
|
|
break;
|
|
}
|
|
}
|
|
return codigo;
|
|
}
|
|
|
|
/**
|
|
* Metodo que indica cuando una celda esta vacia
|
|
* @param celda
|
|
* @return
|
|
*/
|
|
private Boolean celdaVacia(Cell celda) {
|
|
Boolean vacia = false;
|
|
if (celda == null || celda.getCellType() == Cell.CELL_TYPE_BLANK||
|
|
(celda.getCellType() == Cell.CELL_TYPE_STRING && celda.getStringCellValue().isEmpty())) {
|
|
vacia = true;
|
|
}
|
|
return vacia;
|
|
}
|
|
|
|
@SuppressWarnings("finally")
|
|
private File generarArchivoError(Long key) {
|
|
if (listaErrores.isEmpty()) {
|
|
return null;
|
|
}
|
|
PrintWriter escribir = null;
|
|
File archivo = null;
|
|
try {
|
|
archivo = File.createTempFile("errorlog" + key, ".txt");
|
|
escribir = new PrintWriter(archivo);
|
|
for (String err : listaErrores) {
|
|
escribir.print(err + "\r\n");
|
|
}
|
|
limpiar();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
} finally {
|
|
escribir.flush();
|
|
escribir.close();
|
|
return archivo;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Llama a la construccion del metodo para recargar
|
|
*/
|
|
public void descargarArchivo() {
|
|
if(listaErrores!=null && listaErrores.size()>0){
|
|
Long key = new Date().getTime();
|
|
File archivoTemporal = generarArchivoError(key);
|
|
if (archivoTemporal == null)
|
|
return;
|
|
try {
|
|
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
|
|
response.addHeader("Content-disposition","attachment; filename=errorlog" + key + ".txt");
|
|
OutputStream out = response.getOutputStream();
|
|
InputStream inputStream = new FileInputStream(archivoTemporal.getAbsolutePath());
|
|
int read = 0;
|
|
byte[] bytes = new byte[1024];
|
|
|
|
while ((read = inputStream.read(bytes)) != -1) {
|
|
out.write(bytes, 0, read);
|
|
}
|
|
|
|
inputStream.close();
|
|
out.flush();
|
|
FacesContext.getCurrentInstance().responseComplete();
|
|
} catch (Exception e) {
|
|
}
|
|
}else{
|
|
MessageHelper.setMessageError("NO TIENE ERRORES");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Limpia las los valores en las listas
|
|
*/
|
|
public void limpiar() {
|
|
try {
|
|
create();
|
|
while (lrecord.iterator().hasNext()) {
|
|
record = lrecord.get(0);
|
|
remove();
|
|
}
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
public String getCodigoCiudad() {
|
|
return codigoCiudad;
|
|
}
|
|
|
|
public void setCodigoCiudad(String codigoCiudad) {
|
|
this.codigoCiudad = codigoCiudad;
|
|
}
|
|
|
|
String codigoCiudad;
|
|
|
|
public void codigoCiudad() {
|
|
}
|
|
|
|
public void addPersoncodeFilter(String personcode) {
|
|
super.addFilter("pk.personcode", personcode);
|
|
}
|
|
|
|
public List<String> getListaErrores() {
|
|
return listaErrores;
|
|
}
|
|
|
|
public void setListaErrores(List<String> listaErrores) {
|
|
this.listaErrores = listaErrores;
|
|
}
|
|
|
|
public RegistroArmController getRegistroArmasController() {
|
|
return registroArmasController;
|
|
}
|
|
|
|
public void setRegistroArmasController(
|
|
RegistroArmController registroArmasController) {
|
|
this.registroArmasController = registroArmasController;
|
|
}
|
|
|
|
public String getMensajeError() {
|
|
return mensajeError;
|
|
}
|
|
|
|
public void setMensajeError(String mensajeError) {
|
|
this.mensajeError = mensajeError;
|
|
}
|
|
|
|
public Integer getNumArmasProcesadas() {
|
|
return numArmasProcesadas;
|
|
}
|
|
|
|
public void setNumArmasProcesadas(Integer numArmasProcesadas) {
|
|
this.numArmasProcesadas = numArmasProcesadas;
|
|
}
|
|
|
|
public Integer getNumArmasError() {
|
|
return numArmasError;
|
|
}
|
|
|
|
public void setNumArmasError(Integer numArmasError) {
|
|
this.numArmasError = numArmasError;
|
|
}
|
|
|
|
public String getNumeroRecibo() {
|
|
return numeroRecibo;
|
|
}
|
|
|
|
public void setNumeroRecibo(String numeroRecibo) {
|
|
this.numeroRecibo = numeroRecibo;
|
|
}
|
|
|
|
public TarmCentroControl getCentroControl() {
|
|
return centroControl;
|
|
}
|
|
|
|
public void setCentroControl(TarmCentroControl centroControl) {
|
|
this.centroControl = centroControl;
|
|
}
|
|
|
|
public String getCentroControlNombreLogeado() {
|
|
return centroControlNombreLogeado;
|
|
}
|
|
|
|
public void setCentroControlNombreLogeado(String centroControlNombreLogeado) {
|
|
this.centroControlNombreLogeado = centroControlNombreLogeado;
|
|
}
|
|
|
|
public DecomisoController getDecomisoController() {
|
|
return decomisoController;
|
|
}
|
|
|
|
public void setDecomisoController(DecomisoController decomisoController) {
|
|
this.decomisoController = decomisoController;
|
|
}
|
|
|
|
public DecomisoArmaController getDecomisoArmaController() {
|
|
return decomisoArmaController;
|
|
}
|
|
|
|
public void setDecomisoArmaController(
|
|
DecomisoArmaController decomisoArmaController) {
|
|
this.decomisoArmaController = decomisoArmaController;
|
|
}
|
|
|
|
public Integer getNumCorrectas() {
|
|
return numCorrectas;
|
|
}
|
|
|
|
public void setNumCorrectas(Integer numCorrectas) {
|
|
this.numCorrectas = numCorrectas;
|
|
}
|
|
|
|
public TarmDecomiso getTarmDecomiso() {
|
|
return tarmDecomiso;
|
|
}
|
|
|
|
public void setTarmDecomiso(TarmDecomiso tarmDecomiso) {
|
|
this.tarmDecomiso = tarmDecomiso;
|
|
}
|
|
|
|
}
|