leonardo 2015-06-17 18:16:02 +00:00
parent be59404e19
commit 3c3b24ae77
4 changed files with 153 additions and 4 deletions

View File

@ -4,6 +4,14 @@
*/ */
package com.rjconsultores.ventaboletos.web.gui.controladores.catalogos; package com.rjconsultores.ventaboletos.web.gui.controladores.catalogos;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Connection; import java.sql.Connection;
@ -14,7 +22,10 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.activation.MimetypesFileTypeMap;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
@ -42,6 +53,7 @@ import org.zkoss.zul.Combobox;
import org.zkoss.zul.Comboitem; import org.zkoss.zul.Comboitem;
import org.zkoss.zul.Datebox; import org.zkoss.zul.Datebox;
import org.zkoss.zul.Doublebox; import org.zkoss.zul.Doublebox;
import org.zkoss.zul.Filedownload;
import org.zkoss.zul.Image; import org.zkoss.zul.Image;
import org.zkoss.zul.Intbox; import org.zkoss.zul.Intbox;
import org.zkoss.zul.Messagebox; import org.zkoss.zul.Messagebox;
@ -213,6 +225,7 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer {
private List<Empresa> lsEmpresaComissao; private List<Empresa> lsEmpresaComissao;
private List<PtovtaEstoque> lsEstoque; private List<PtovtaEstoque> lsEstoque;
private List<PtovtaComissao> lsPtovtaComissao; private List<PtovtaComissao> lsPtovtaComissao;
private List<String> lsLogFiles;
private Radio radDatosTarjetaSi; private Radio radDatosTarjetaSi;
private Radio radDatosTarjetaNo; private Radio radDatosTarjetaNo;
private Radio radAprobacionAutorizado; private Radio radAprobacionAutorizado;
@ -257,8 +270,10 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer {
private Combobox cmbEmpresas; private Combobox cmbEmpresas;
private Combobox cmbCategorias; private Combobox cmbCategorias;
private Combobox cmbEmpresaFechamentoParamptovta; private Combobox cmbEmpresaFechamentoParamptovta;
private Combobox cmbLogFiles;
private Button btnSalvarFormaPago; private Button btnSalvarFormaPago;
private Button btnApagar; private Button btnApagar;
private Button btnShowLog;
private Doublebox txtCargosExtras; private Doublebox txtCargosExtras;
private MyTextbox txtNome; private MyTextbox txtNome;
private MyTextbox txtNumFax; private MyTextbox txtNumFax;
@ -318,11 +333,15 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer {
private Textbox logResult; private Textbox logResult;
private boolean integracionTotvs; private boolean integracionTotvs;
private String logFileSelected;
public static final int INTERVALO_FECHAMENTO_SEMANAL = 7; public static final int INTERVALO_FECHAMENTO_SEMANAL = 7;
public static final int INTERVALO_FECHAMENTO_DECENDIAL = 10; public static final int INTERVALO_FECHAMENTO_DECENDIAL = 10;
public static final int INTERVALO_FECHAMENTO_QUINZENAL = 15; public static final int INTERVALO_FECHAMENTO_QUINZENAL = 15;
public static final int INTERVALO_FECHAMENTO_MENSAL = 30; public static final int INTERVALO_FECHAMENTO_MENSAL = 30;
private static final int TAMANHO_BUFFER = 4096; // 4kb
@Autowired @Autowired
private DataSource dataSource; private DataSource dataSource;
@ -342,6 +361,17 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer {
; ;
} }
private List<String> getLogFiles(){
List<String> files = new ArrayList<String>();
File logDir = new File(System.getProperty("jboss.server.log.dir"));
for (String str : logDir.list()){
if (str.contains("ws") && !str.contains("zip")){
files.add(str);
}
}
return files;
}
@Override @Override
public void doAfterCompose(Component comp) throws Exception { public void doAfterCompose(Component comp) throws Exception {
@ -358,7 +388,8 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer {
lsFormaPago = formaPagoService.obtenerTodos(); lsFormaPago = formaPagoService.obtenerTodos();
lsTipoPuntoVenta = tipoPuntoVentaService.obtenerTodosExceto(TipoPuntoVenta.TODOS); lsTipoPuntoVenta = tipoPuntoVentaService.obtenerTodosExceto(TipoPuntoVenta.TODOS);
lsUsuarioBancario = usuarioBancarioService.obtenerTodos(); lsUsuarioBancario = usuarioBancarioService.obtenerTodos();
lsLogFiles = getLogFiles();
popularCombobox(cmbTipoConta, cmbPessoa, cmbForm, cmbLote, cmbPosicao, cmbReceita, cmbEmpresas, cmbCategorias); popularCombobox(cmbTipoConta, cmbPessoa, cmbForm, cmbLote, cmbPosicao, cmbReceita, cmbEmpresas, cmbCategorias);
ptovtaEmpresasBloqueadasList.setItemRenderer(new RenderEmpresaBloquear()); ptovtaEmpresasBloqueadasList.setItemRenderer(new RenderEmpresaBloquear());
@ -665,6 +696,45 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer {
txtNome.focus(); txtNome.focus();
} }
public void onClick$btnDownload(Event event) {
String fileName = System.getProperty("jboss.server.log.dir") + "\\" + cmbLogFiles.getSelectedItem().getValue().toString();
String fileZip = System.getProperty("jboss.server.log.dir") + "\\" + cmbLogFiles.getSelectedItem().getValue().toString().replace("log", "zip");
FileInputStream inputStream;
try {
excluirArquivosZip();
compactarArquivo(fileZip, fileName);
File file = new File(fileZip);
if (file.exists()) {
inputStream = new FileInputStream(file);
Filedownload.save(inputStream, new MimetypesFileTypeMap().getContentType(file), file.getName());
}
file.delete();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private String readFile(String fileName) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(fileName));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append("\n");
line = br.readLine();
}
return sb.toString();
} finally {
br.close();
}
}
@Transactional @Transactional
public boolean validaFuncionTipoBoletoBloqueado() { public boolean validaFuncionTipoBoletoBloqueado() {
List<String> listClavesPermisos = new ArrayList<String>(); List<String> listClavesPermisos = new ArrayList<String>();
@ -2349,6 +2419,15 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer {
this.txtRazonSocial = txtRazonSocial; this.txtRazonSocial = txtRazonSocial;
} }
public String getLogFileSelected() {
return logFileSelected;
}
public void setLogFileSelected(String logFileSelected) {
this.logFileSelected = logFileSelected;
}
public void onChange$cmbPuntoVentaPadre(Event ev) throws InterruptedException { public void onChange$cmbPuntoVentaPadre(Event ev) throws InterruptedException {
if (puntoVenta.getPuntoventaId() != null) { if (puntoVenta.getPuntoventaId() != null) {
List<PuntoVenta> lsPuntosSubordinados = puntoVentaService.buscarPuntoVentaSubordinados(puntoVenta); List<PuntoVenta> lsPuntosSubordinados = puntoVentaService.buscarPuntoVentaSubordinados(puntoVenta);
@ -2544,4 +2623,57 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer {
public void setIntegracionTotvs(boolean integracionTotvs) { public void setIntegracionTotvs(boolean integracionTotvs) {
this.integracionTotvs = integracionTotvs; this.integracionTotvs = integracionTotvs;
} }
public List<String> getLsLogFiles() {
return lsLogFiles;
}
public void setLsLogFiles(List<String> lsLogFiles) {
this.lsLogFiles = lsLogFiles;
}
public Button getBtnShowLog() {
return btnShowLog;
}
public void setBtnShowLog(Button btnShowLog) {
this.btnShowLog = btnShowLog;
}
public static void compactarArquivo(String arqSaida,String arqEntrada) throws IOException{
int cont;
byte[] dados = new byte[TAMANHO_BUFFER];
BufferedInputStream origem = null;
FileInputStream streamDeEntrada = null;
FileOutputStream destino = null;
ZipOutputStream saida = null;
ZipEntry entry = null;
try {
destino = new FileOutputStream(new File(arqSaida));
saida = new ZipOutputStream(new BufferedOutputStream(destino));
File file = new File(arqEntrada);
streamDeEntrada = new FileInputStream(file);
origem = new BufferedInputStream(streamDeEntrada, TAMANHO_BUFFER);
entry = new ZipEntry(file.getName());
saida.putNextEntry(entry);
while((cont = origem.read(dados, 0, TAMANHO_BUFFER)) != -1) {
saida.write(dados, 0, cont);
}
origem.close();
saida.close();
} catch(IOException e) {
throw new IOException(e.getMessage());
}
}
private void excluirArquivosZip(){
File pasta = new File(System.getProperty("jboss.server.log.dir"));
File[] arquivos = pasta.listFiles();
for(File arquivo : arquivos) {
if(arquivo.getName().endsWith("zip")) {
arquivo.delete();
}
}
}
} }

View File

@ -906,6 +906,8 @@ editarPuntoVentaController.lbCheckCredito.value=CC
editarPuntoVentaController.lbCheckDebito.value=CD editarPuntoVentaController.lbCheckDebito.value=CD
editarPuntoVentaController.lbCheckTF.value=TF editarPuntoVentaController.lbCheckTF.value=TF
editarPuntoVentaController.lbCheckBoletos.value=BOL editarPuntoVentaController.lbCheckBoletos.value=BOL
editarPuntoVentaController.lbFileLog.value=Arquivos Log
editarPuntoVentaController.btnDownload.tooltiptext=Download
# Fechamento Conta Corrente Agencia # Fechamento Conta Corrente Agencia
editarPuntoVentaController.puntoventa.label = Agencia editarPuntoVentaController.puntoventa.label = Agencia

View File

@ -943,6 +943,8 @@ editarPuntoVentaController.lbCheckCredito.value=CC
editarPuntoVentaController.lbCheckDebito.value=CD editarPuntoVentaController.lbCheckDebito.value=CD
editarPuntoVentaController.lbCheckTF.value=TF editarPuntoVentaController.lbCheckTF.value=TF
editarPuntoVentaController.lbCheckBoletos.value=BOL editarPuntoVentaController.lbCheckBoletos.value=BOL
editarPuntoVentaController.lbFileLog.value=Arquivos Log
editarPuntoVentaController.btnDownload.tooltiptext=Download
# Fechamento Conta Corrente Agencia # Fechamento Conta Corrente Agencia
editarPuntoVentaController.puntoventa.label = Agencia editarPuntoVentaController.puntoventa.label = Agencia

View File

@ -1336,7 +1336,7 @@
<!-- INTEGRACAO --> <!-- INTEGRACAO -->
<tabpanel height="400px"> <tabpanel height="100%">
<grid fixedLayout="true"> <grid fixedLayout="true">
<columns> <columns>
<column width="30%" /> <column width="30%" />
@ -1393,8 +1393,21 @@
height="20" image="/gui/img/icon-active.gif" width="35px" height="20" image="/gui/img/icon-active.gif" width="35px"
tooltiptext="${c:l('busquedaEmpresaController.btnIntegracao.tooltiptext')}" /> tooltiptext="${c:l('busquedaEmpresaController.btnIntegracao.tooltiptext')}" />
</hbox> </hbox>
<hbox spacing="5px" style="padding:1px" align="right" visible="false">
<label
value="${c:l('editarPuntoVentaController.lbFileLog.value')}" />
<combobox
id="cmbLogFiles"
mold="rounded" buttonVisible="true"
model="@{winEditarPuntoVenta$composer.lsLogFiles}" />
<button id="btnDownload"
height="20"
label="${c:l('editarPuntoVentaController.btnDownload.tooltiptext')}"
tooltiptext="${c:l('editarPuntoVentaController.btnDownload.tooltiptext')}" />
</hbox>
</toolbar> </toolbar>
<textbox width="100%" rows="20" id="logResult"/>
<textbox width="100%" rows="18" id="logResult"/>
</tabpanel> </tabpanel>
</tabpanels> </tabpanels>
</tabbox> </tabbox>