fixes bug#14354
dev:julio qua: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@93640 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
4d050fd238
commit
ee88c1f2e9
|
@ -4,6 +4,7 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
@ -31,6 +32,7 @@ import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
import org.apache.poi.ss.usermodel.Font;
|
import org.apache.poi.ss.usermodel.Font;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.jdbc.datasource.DataSourceUtils;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.zkoss.util.resource.Labels;
|
import org.zkoss.util.resource.Labels;
|
||||||
import org.zkoss.zhtml.Filedownload;
|
import org.zkoss.zhtml.Filedownload;
|
||||||
|
@ -123,16 +125,16 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardComp
|
||||||
String horInicio = horInicial.getValue() != null ? hf.format(horInicial.getValue()) : "";
|
String horInicio = horInicial.getValue() != null ? hf.format(horInicial.getValue()) : "";
|
||||||
String horFim = horFinal.getValue() != null ? hf.format(horFinal.getValue()) : "";
|
String horFim = horFinal.getValue() != null ? hf.format(horFinal.getValue()) : "";
|
||||||
|
|
||||||
|
Connection connection = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
connection = getConnectionRead();
|
||||||
|
|
||||||
String sql = getSql(empresa, ruta != null ? ruta.getRutaId().toString() : null,
|
String sql = getSql(empresa, ruta != null ? ruta.getRutaId().toString() : null,
|
||||||
orgao != null ? orgao.getOrgaoConcedenteId().toString() : null,
|
orgao != null ? orgao.getOrgaoConcedenteId().toString() : null,
|
||||||
origem != null ? origem.getParadaId().toString() : null, horInicio, horFim);
|
origem != null ? origem.getParadaId().toString() : null, horInicio, horFim);
|
||||||
|
|
||||||
ResultSet rset = null;
|
NamedParameterStatement stmt = new NamedParameterStatement(connection, sql);
|
||||||
try{
|
|
||||||
|
|
||||||
NamedParameterStatement stmt = new NamedParameterStatement(dataSourceRead.getConnection(), sql);
|
|
||||||
|
|
||||||
stmt.setString(FILED_FEC_INICIO, fecInicio);
|
stmt.setString(FILED_FEC_INICIO, fecInicio);
|
||||||
stmt.setString(FIELD_FEC_FINAL, fecFinal);
|
stmt.setString(FIELD_FEC_FINAL, fecFinal);
|
||||||
|
@ -140,7 +142,7 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardComp
|
||||||
stmt.setInt(FIELD_EMPRESA_ID, empresa.getEmpresaId());
|
stmt.setInt(FIELD_EMPRESA_ID, empresa.getEmpresaId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ruta != null && !ruta.equals("-1")) {
|
if (ruta != null && !"-1".equals(ruta.getRutaId().toString())) {
|
||||||
stmt.setInt(FIELD_RUTA_ID, ruta.getRutaId());
|
stmt.setInt(FIELD_RUTA_ID, ruta.getRutaId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,19 +158,34 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardComp
|
||||||
stmt.setString(FIELD_HOR_INICIO, horInicio);
|
stmt.setString(FIELD_HOR_INICIO, horInicio);
|
||||||
stmt.setString(FIELD_HOR_FINAL, horFim);
|
stmt.setString(FIELD_HOR_FINAL, horFim);
|
||||||
}
|
}
|
||||||
rset = stmt.executeQuery();
|
|
||||||
|
|
||||||
Map<String, Map<String, List<RelatorioEmbarqueLocalidadeBean>>> datas = ResultSetToList(rset);
|
ResultSet rset = stmt.executeQuery();
|
||||||
|
|
||||||
|
Map<String, Map<String, List<RelatorioEmbarqueLocalidadeBean>>> datas = resultSetToList(rset);
|
||||||
exportaExcel(datas);
|
exportaExcel(datas);
|
||||||
|
|
||||||
|
rset.close();
|
||||||
|
stmt.close();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("", e);
|
log.error("", e);
|
||||||
} finally {
|
} finally {
|
||||||
if(rset != null && !rset.isClosed()) {
|
try {
|
||||||
rset.close();
|
if (connection != null && !connection.isClosed()) {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("error fechar conexão", e);
|
||||||
|
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Connection getConnectionRead() {
|
||||||
|
return DataSourceUtils.getConnection(dataSourceRead);
|
||||||
|
}
|
||||||
|
|
||||||
private void exportaExcel(Map<String, Map<String, List<RelatorioEmbarqueLocalidadeBean>>> datas) {
|
private void exportaExcel(Map<String, Map<String, List<RelatorioEmbarqueLocalidadeBean>>> datas) {
|
||||||
try {
|
try {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
|
@ -251,7 +268,6 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardComp
|
||||||
cellTotalValue.setCellValue(totalGeral);
|
cellTotalValue.setCellValue(totalGeral);
|
||||||
cellTotalValue.setCellStyle(style);
|
cellTotalValue.setCellStyle(style);
|
||||||
|
|
||||||
|
|
||||||
linha = NUM_LINHA_INICIO;
|
linha = NUM_LINHA_INICIO;
|
||||||
|
|
||||||
for (int i = 0; i <= total; i++) {
|
for (int i = 0; i <= total; i++) {
|
||||||
|
@ -266,28 +282,31 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardComp
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String nomeArquivo =
|
String nomeArquivo = UsuarioLogado.getUsuarioLogado().getNombusuario()
|
||||||
UsuarioLogado.getUsuarioLogado().getNombusuario()
|
|
||||||
+ "_" + Calendar.getInstance().getTime().getTime()
|
+ "_" + Calendar.getInstance().getTime().getTime()
|
||||||
+ "_" + "EmbarqueLocalidade";
|
+ "_" + "EmbarqueLocalidade";
|
||||||
|
|
||||||
File fNomeArquivo = File.createTempFile(nomeArquivo, ".tmp");
|
File fNomeArquivo = File.createTempFile(nomeArquivo, ".tmp");
|
||||||
|
|
||||||
FileOutputStream stream = new FileOutputStream(fNomeArquivo);
|
FileOutputStream stream = new FileOutputStream(fNomeArquivo);
|
||||||
stream.flush();
|
|
||||||
wb.write(stream);
|
wb.write(stream);
|
||||||
stream.close();
|
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
is = new FileInputStream(fNomeArquivo);
|
is = new FileInputStream(fNomeArquivo);
|
||||||
Filedownload.save(is, "application/xls", "EmbarqueLocalidade.xls");
|
Filedownload.save(is, "application/xls", "EmbarqueLocalidade.xls");
|
||||||
|
|
||||||
fNomeArquivo.delete();
|
fNomeArquivo.delete();
|
||||||
|
stream.flush();
|
||||||
|
stream.close();
|
||||||
|
//is.close();
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}finally {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void geraCabecalhoTitulo(HSSFSheet sheet1, HSSFWorkbook wb) {
|
private void geraCabecalhoTitulo(HSSFSheet sheet1, HSSFWorkbook wb) {
|
||||||
HSSFRow titulo = sheet1.createRow(NUM_LINHA_TITULO);
|
HSSFRow titulo = sheet1.createRow(NUM_LINHA_TITULO);
|
||||||
|
@ -327,7 +346,6 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardComp
|
||||||
|
|
||||||
geraCabecalhoPeriodo(sheet1);
|
geraCabecalhoPeriodo(sheet1);
|
||||||
|
|
||||||
|
|
||||||
sheet1.addMergedRegion(new CellRangeAddress(
|
sheet1.addMergedRegion(new CellRangeAddress(
|
||||||
NUM_LINHA_DATA_EMPRESA, // first row (0-based)
|
NUM_LINHA_DATA_EMPRESA, // first row (0-based)
|
||||||
NUM_LINHA_DATA_EMPRESA, // last row (0-based)
|
NUM_LINHA_DATA_EMPRESA, // last row (0-based)
|
||||||
|
@ -354,8 +372,6 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardComp
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HSSFRow r1 = sheet1.createRow(NUM_LINHA_DATA_EMPRESA + 1);
|
HSSFRow r1 = sheet1.createRow(NUM_LINHA_DATA_EMPRESA + 1);
|
||||||
List<RelatorioEmbarqueLocalidadeBean> lsAux = new ArrayList<RelatorioEmbarqueLocalidadeBean>();
|
List<RelatorioEmbarqueLocalidadeBean> lsAux = new ArrayList<RelatorioEmbarqueLocalidadeBean>();
|
||||||
|
|
||||||
|
@ -390,7 +406,6 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardComp
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
r1.createCell(i++).setCellValue("TOTAL");
|
r1.createCell(i++).setCellValue("TOTAL");
|
||||||
r1.setRowStyle(styleHorario);
|
r1.setRowStyle(styleHorario);
|
||||||
total = i;
|
total = i;
|
||||||
|
@ -402,11 +417,12 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardComp
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doAfterCompose(Component comp) throws Exception {
|
public void doAfterCompose(Component comp) throws Exception {
|
||||||
|
super.doAfterCompose(comp);
|
||||||
|
|
||||||
lsEmpresas = empresaService.obtenerTodos();
|
lsEmpresas = empresaService.obtenerTodos();
|
||||||
lsOrgaosConcedentes = orgaoConcedenteService.obtenerTodos();
|
lsOrgaosConcedentes = orgaoConcedenteService.obtenerTodos();
|
||||||
lsOrigens = paradaService.obtenerTodos();
|
lsOrigens = paradaService.obtenerTodos();
|
||||||
lsRutas = rutaService.obtenerTodos();
|
// lsRutas = rutaService.obtenerTodos();
|
||||||
super.doAfterCompose(comp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onChange$cmbOrgaoConcedente(Event ev) throws Exception {
|
public void onChange$cmbOrgaoConcedente(Event ev) throws Exception {
|
||||||
|
@ -461,7 +477,7 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardComp
|
||||||
return sql.toString();
|
return sql.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String, Map<String, List<RelatorioEmbarqueLocalidadeBean>>> ResultSetToList(ResultSet rset) throws SQLException {
|
protected Map<String, Map<String, List<RelatorioEmbarqueLocalidadeBean>>> resultSetToList(ResultSet rset) throws SQLException {
|
||||||
|
|
||||||
Map<String, Map<String, List<RelatorioEmbarqueLocalidadeBean>>> datas = new LinkedHashMap<String, Map<String, List<RelatorioEmbarqueLocalidadeBean>>>();
|
Map<String, Map<String, List<RelatorioEmbarqueLocalidadeBean>>> datas = new LinkedHashMap<String, Map<String, List<RelatorioEmbarqueLocalidadeBean>>>();
|
||||||
ls = new ArrayList<RelatorioEmbarqueLocalidadeBean>();
|
ls = new ArrayList<RelatorioEmbarqueLocalidadeBean>();
|
||||||
|
@ -472,14 +488,16 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardComp
|
||||||
bean.setLinha(rset.getString(2));
|
bean.setLinha(rset.getString(2));
|
||||||
bean.setClasse(rset.getString(3));
|
bean.setClasse(rset.getString(3));
|
||||||
bean.setEmbarques(rset.getLong(4));
|
bean.setEmbarques(rset.getLong(4));
|
||||||
ls.add(bean);;
|
ls.add(bean);
|
||||||
}
|
}
|
||||||
|
|
||||||
return datas;
|
return datas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checarLinhasDuplicadas() {
|
public void checarLinhasDuplicadas() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Datebox getDatInicial() {
|
public Datebox getDatInicial() {
|
||||||
return datInicial;
|
return datInicial;
|
||||||
}
|
}
|
||||||
|
@ -577,4 +595,3 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardComp
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue