desenvolvimento (fixes bug 6232)
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@43503 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
6968d4fb25
commit
71625abfb8
|
@ -0,0 +1,388 @@
|
|||
package com.rjconsultores.ventaboletos.web.gui.controladores.sendaAmigo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
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.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.event.UploadEvent;
|
||||
import org.zkoss.zul.Checkbox;
|
||||
import org.zkoss.zul.Label;
|
||||
|
||||
import com.rjconsultores.ventaboletos.entidad.Ciudad;
|
||||
import com.rjconsultores.ventaboletos.entidad.Colonia;
|
||||
import com.rjconsultores.ventaboletos.entidad.Estado;
|
||||
import com.rjconsultores.ventaboletos.entidad.InstiFinanceira;
|
||||
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
|
||||
import com.rjconsultores.ventaboletos.exception.IntegracionException;
|
||||
import com.rjconsultores.ventaboletos.exception.ValidacionCampoException;
|
||||
import com.rjconsultores.ventaboletos.service.CiudadService;
|
||||
import com.rjconsultores.ventaboletos.service.ColoniaService;
|
||||
import com.rjconsultores.ventaboletos.service.EstadoService;
|
||||
import com.rjconsultores.ventaboletos.service.InstiFinanceiraService;
|
||||
import com.rjconsultores.ventaboletos.service.PuntoVentaService;
|
||||
import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;
|
||||
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
|
||||
|
||||
@Controller("importarPlanilhaController")
|
||||
@Scope("prototype")
|
||||
public class ImportarPlanilhaController extends MyGenericForwardComposer {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Autowired
|
||||
private PuntoVentaService puntoVentaService;
|
||||
@Autowired
|
||||
private ColoniaService coloniaService;
|
||||
@Autowired
|
||||
private CiudadService ciudadService;
|
||||
@Autowired
|
||||
private EstadoService estadoService;
|
||||
@Autowired
|
||||
private InstiFinanceiraService instiFinanceiraService;
|
||||
private Checkbox chkCabecalho;
|
||||
private Checkbox chkTotvs;
|
||||
private Label progressLabel;
|
||||
|
||||
private static Logger log = Logger.getLogger(ImportarPlanilhaController.class);
|
||||
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
|
||||
}
|
||||
|
||||
public synchronized void onUpload(UploadEvent event) throws IOException, InterruptedException {
|
||||
|
||||
String nomeArquivo = event.getMedia().getName();
|
||||
|
||||
progressLabel.setValue("");
|
||||
|
||||
try {
|
||||
|
||||
InputStream fis = event.getMedia().getStreamData();
|
||||
|
||||
XSSFWorkbook book = new XSSFWorkbook(fis);
|
||||
XSSFSheet sheet = book.getSheetAt(0);
|
||||
|
||||
log.info(nomeArquivo);
|
||||
|
||||
Iterator<Row> itr = sheet.iterator();
|
||||
|
||||
List<InstiFinanceira> listInstiFinanceira = instiFinanceiraService.obtenerTodos();
|
||||
|
||||
while (itr.hasNext()) {
|
||||
|
||||
Row row = itr.next();
|
||||
Integer qtAtual = row.getRowNum();
|
||||
Integer qtTotal = row.getSheet().getPhysicalNumberOfRows()-1;
|
||||
log.info("Row Nº.: " + qtAtual + " de " + qtTotal);
|
||||
|
||||
if (chkCabecalho.isChecked()) {
|
||||
if (row.getRowNum() == 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<Cell> cellIterator = row.cellIterator();
|
||||
while (cellIterator.hasNext()) {
|
||||
|
||||
String codigo = row.getCell(0).getStringCellValue();
|
||||
|
||||
List<PuntoVenta> listpv = puntoVentaService.buscaPuntoVenta(codigo);
|
||||
|
||||
String razonSocial = row.getCell(1) != null ? removeCaracter(row.getCell(1).getStringCellValue()) : "";
|
||||
String nombPuntoVenta = row.getCell(2) != null ? removeCaracter(row.getCell(2).getStringCellValue()) : "";
|
||||
String endereco = row.getCell(3) != null ? removeCaracter(row.getCell(3).getStringCellValue()) : "";
|
||||
String comple = row.getCell(4) != null ? removeCaracter(row.getCell(4).getStringCellValue()) : "";
|
||||
String bairro = row.getCell(5) != null ? removeCaracter(row.getCell(5).getStringCellValue()) : "";
|
||||
String estado = row.getCell(6) != null ? removeCaracter(row.getCell(6).getStringCellValue()) : "";
|
||||
String cep = row.getCell(7) != null ? removeCaracter(row.getCell(7).getStringCellValue()) : "";
|
||||
String codMun = row.getCell(8) != null ? removeCaracter(row.getCell(8).getStringCellValue()) : "";
|
||||
String ddd = row.getCell(9) != null ? removeCaracter(row.getCell(9).getStringCellValue()) : "";
|
||||
String telefone = row.getCell(10) != null ? removeCaracter(row.getCell(10).getStringCellValue()) : "";
|
||||
String fax = row.getCell(11) != null ? removeCaracter(row.getCell(11).getStringCellValue()) : "";
|
||||
String cgc = row.getCell(12) != null ? removeCaracter(row.getCell(12).getStringCellValue()) : "";
|
||||
String inscricao = row.getCell(13) != null ? removeCaracter(row.getCell(13).getStringCellValue()) : "";
|
||||
String isento = row.getCell(14) != null ? removeCaracter(row.getCell(14).getStringCellValue()) : "";
|
||||
String email = row.getCell(15) != null ? removeCaracter(row.getCell(15).getStringCellValue()) : "";
|
||||
String obs = row.getCell(16) != null ? removeCaracter(row.getCell(16).getStringCellValue()) : "";
|
||||
String banco = row.getCell(17) != null ? removeCaracter(row.getCell(17).getStringCellValue()) : "";
|
||||
String tipoConta = row.getCell(18) != null ? removeCaracter(row.getCell(18).getStringCellValue()) : "";
|
||||
String pessoa = row.getCell(19) != null ? removeCaracter(row.getCell(19).getStringCellValue()) : "";
|
||||
String agencia = row.getCell(20) != null ? removeCaracter(row.getCell(20).getStringCellValue()) : "";
|
||||
String digitoAgencia = row.getCell(21) != null ? removeCaracter(row.getCell(21).getStringCellValue()) : "";
|
||||
String conta = row.getCell(22) != null ? removeCaracter(row.getCell(22).getStringCellValue()) : "";
|
||||
String digitoConta = row.getCell(23) != null ? removeCaracter(row.getCell(23).getStringCellValue()) : "";
|
||||
|
||||
for (PuntoVenta pv : listpv) {
|
||||
|
||||
if(chkTotvs.isChecked()){
|
||||
atualizarEntidade(pv);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(razonSocial)) {
|
||||
log.info(razonSocial);
|
||||
if(razonSocial.length() >= 40){
|
||||
pv.setRazonSocial(razonSocial.substring(0, 40));
|
||||
}else{
|
||||
pv.setRazonSocial(razonSocial);
|
||||
}
|
||||
|
||||
}
|
||||
if (StringUtils.isNotBlank(nombPuntoVenta)) {
|
||||
pv.setNombpuntoventa(nombPuntoVenta);
|
||||
log.info(nombPuntoVenta);
|
||||
}
|
||||
if (StringUtils.isNotBlank(endereco)) {
|
||||
String direcion = endereco.isEmpty() ? "" : removeCaracter(endereco.substring(0, endereco.indexOf("Nº")).trim() );
|
||||
if(StringUtils.isNotBlank(removeCaracter(direcion.trim()))){
|
||||
pv.setDireccioncalle(direcion);
|
||||
log.info(direcion);
|
||||
}else{
|
||||
pv.setDireccioncalle("");
|
||||
log.info(direcion);
|
||||
}
|
||||
|
||||
}
|
||||
if (StringUtils.isNotBlank(endereco)) {
|
||||
String numero = endereco.isEmpty() ? "" : removeCaracter(endereco.substring(endereco.indexOf("Nº") +2, endereco.length()).trim());
|
||||
if(StringUtils.isNotBlank(removeCaracter(numero.trim()))){
|
||||
pv.setDireccionnumero(numero);
|
||||
log.info(numero);
|
||||
}else{
|
||||
pv.setDireccionnumero("");
|
||||
log.info(numero);
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(comple)) {
|
||||
pv.setCompl(comple);
|
||||
log.info(comple);
|
||||
}
|
||||
if (StringUtils.isNotBlank(bairro)) {
|
||||
if (StringUtils.isNotBlank(codMun) && StringUtils.isNotBlank(estado)) {
|
||||
List<Estado> estadoBean = estadoService.buscarCveEstado(estado);
|
||||
if(!estadoBean.isEmpty()){
|
||||
List<Ciudad> listCiudad = ciudadService.buscaCodMun(Integer.valueOf(codMun), estadoBean.get(0));
|
||||
if(!listCiudad.isEmpty()){
|
||||
List<Colonia> listColonia = coloniaService.buscarPorCodMun(listCiudad.get(0), bairro);
|
||||
if(listColonia.isEmpty()){
|
||||
Colonia colonia = new Colonia();
|
||||
colonia.setDesccolonia(bairro);
|
||||
colonia.setCodpostal("0");
|
||||
colonia.setCiudad(listCiudad.get(0));
|
||||
colonia.setFecmodif(new Date());
|
||||
colonia.setUsuarioId(99);
|
||||
colonia.setActivo(Boolean.TRUE);
|
||||
coloniaService.suscribir(colonia);
|
||||
pv.setColonia(colonia);
|
||||
log.info(colonia.getDesccolonia());
|
||||
}else{
|
||||
pv.setColonia(listColonia.get(0));
|
||||
log.info(listColonia.get(0).getDesccolonia());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (StringUtils.isNotBlank(estado)) {
|
||||
//
|
||||
}
|
||||
if ((StringUtils.isNotBlank(cep)) && Long.valueOf(cep) != 0) {
|
||||
pv.setCodpostal(Long.valueOf(cep));
|
||||
log.info(cep);
|
||||
}
|
||||
if (StringUtils.isNotBlank(codMun)) {
|
||||
//
|
||||
}
|
||||
if (StringUtils.isNotBlank(ddd) && StringUtils.isNotBlank(telefone)) {
|
||||
if(telefone.length() >= 8 ){
|
||||
String tel = "(0" + ddd + ")";
|
||||
telefone = telefone.substring(0, 4) + "-" + telefone.substring(4, telefone.length()) ;
|
||||
tel = tel + telefone;
|
||||
pv.setNumtelefonouno(tel);
|
||||
log.info(tel);
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(fax)) {
|
||||
if(fax.length() >= 8 ){
|
||||
String faxTemp = "(0" + ddd + ")";
|
||||
fax = fax.substring(0, 4) + "-" + fax.substring(4, fax.length()) ;
|
||||
faxTemp = faxTemp + fax;
|
||||
pv.setNumfax(faxTemp);
|
||||
log.info(faxTemp);
|
||||
}
|
||||
|
||||
}
|
||||
if ((StringUtils.isNotBlank(cgc)) && Long.valueOf(cgc) != 0) {
|
||||
pv.setNumDoCPuntoVenta(cgc);
|
||||
log.info(cgc);
|
||||
|
||||
}
|
||||
if (StringUtils.isNotBlank(inscricao)) {
|
||||
//
|
||||
}
|
||||
if (StringUtils.isNotBlank(isento)) {
|
||||
//
|
||||
}
|
||||
if (StringUtils.isNotBlank(email)) {
|
||||
pv.setDescCorreo(email);
|
||||
log.info(email);
|
||||
|
||||
}
|
||||
if (StringUtils.isNotBlank(obs)) {
|
||||
//
|
||||
}
|
||||
if (StringUtils.isNotBlank(banco)) {
|
||||
for (InstiFinanceira insti : listInstiFinanceira) {
|
||||
if((insti.getCodigo() != null ) && insti.getCodigo().equalsIgnoreCase(banco)){
|
||||
pv.getAgenciaId().setInstiFinanceiraId(insti);
|
||||
log.info(insti.getNome());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (StringUtils.isNotBlank(tipoConta)) {
|
||||
if (tipoConta.equalsIgnoreCase("CORRENTE")) {
|
||||
pv.getAgenciaId().setTipo("C/C");
|
||||
} else if (tipoConta.equalsIgnoreCase("POUPANCA")) {
|
||||
pv.getAgenciaId().setTipo("P");
|
||||
}
|
||||
log.info(tipoConta);
|
||||
|
||||
}
|
||||
if (StringUtils.isNotBlank(pessoa)) {
|
||||
//
|
||||
}
|
||||
if (StringUtils.isNotBlank(agencia) && StringUtils.isNotBlank(digitoAgencia)) {
|
||||
pv.getAgenciaId().setNumagencia(agencia + "-" + digitoAgencia );
|
||||
log.info(agencia + "-" + digitoAgencia );
|
||||
}
|
||||
if (StringUtils.isNotBlank(conta)) {
|
||||
pv.getAgenciaId().setNumconta(conta);
|
||||
log.info(conta);
|
||||
}
|
||||
if (StringUtils.isNotBlank(digitoConta)) {
|
||||
if(digitoConta.length() > 1){
|
||||
pv.getAgenciaId().setDigito(digitoConta.trim().substring(0, 1));
|
||||
}else{
|
||||
pv.getAgenciaId().setDigito(digitoConta.trim());
|
||||
}
|
||||
log.info(digitoConta.trim());
|
||||
}
|
||||
|
||||
atualizarEntidade(pv);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
log.info("");
|
||||
}
|
||||
|
||||
progressLabel.setValue("Planilha " + nomeArquivo + " processada com sucesso.");
|
||||
|
||||
log.info("FIM");
|
||||
|
||||
} catch (Exception ie) {
|
||||
progressLabel.setValue("Erro ao processar planilha " + nomeArquivo + ".");
|
||||
log.error("", ie);
|
||||
}
|
||||
}
|
||||
|
||||
private String removeCaracter(String car) {
|
||||
if (car.equalsIgnoreCase("NULL") || car.equalsIgnoreCase("S/N")) {
|
||||
car = "";
|
||||
}
|
||||
return car;
|
||||
|
||||
}
|
||||
|
||||
private void atualizarEntidade(PuntoVenta pv) throws IntegracionException, ValidacionCampoException{
|
||||
puntoVentaService.actualizacion(pv);
|
||||
}
|
||||
|
||||
private void setContext() {
|
||||
ApplicationContext appContext = AppContext.getApplicationContext();
|
||||
|
||||
BeanFactory factory = (BeanFactory) appContext;
|
||||
puntoVentaService = (PuntoVentaService) factory.getBean("puntoVentaService");
|
||||
coloniaService = (ColoniaService) factory.getBean("coloniaService");
|
||||
instiFinanceiraService = (InstiFinanceiraService) factory.getBean("ptovtaBancoService");
|
||||
ciudadService = (CiudadService) factory.getBean("ciudadService");
|
||||
estadoService = (EstadoService) factory.getBean("estadoService");
|
||||
}
|
||||
|
||||
public PuntoVentaService getPuntoVentaService() {
|
||||
return puntoVentaService;
|
||||
}
|
||||
|
||||
public void setPuntoVentaService(PuntoVentaService puntoVentaService) {
|
||||
this.puntoVentaService = puntoVentaService;
|
||||
}
|
||||
|
||||
public ColoniaService getColoniaService() {
|
||||
return coloniaService;
|
||||
}
|
||||
|
||||
public void setColoniaService(ColoniaService coloniaService) {
|
||||
this.coloniaService = coloniaService;
|
||||
}
|
||||
|
||||
public CiudadService getCiudadService() {
|
||||
return ciudadService;
|
||||
}
|
||||
|
||||
public void setCiudadService(CiudadService ciudadService) {
|
||||
this.ciudadService = ciudadService;
|
||||
}
|
||||
|
||||
public EstadoService getEstadoService() {
|
||||
return estadoService;
|
||||
}
|
||||
|
||||
public void setEstadoService(EstadoService estadoService) {
|
||||
this.estadoService = estadoService;
|
||||
}
|
||||
|
||||
public InstiFinanceiraService getInstiFinanceiraService() {
|
||||
return instiFinanceiraService;
|
||||
}
|
||||
|
||||
public void setInstiFinanceiraService(InstiFinanceiraService instiFinanceiraService) {
|
||||
this.instiFinanceiraService = instiFinanceiraService;
|
||||
}
|
||||
|
||||
public Checkbox getChkCabecalho() {
|
||||
return chkCabecalho;
|
||||
}
|
||||
|
||||
public void setChkCabecalho(Checkbox chkCabecalho) {
|
||||
this.chkCabecalho = chkCabecalho;
|
||||
}
|
||||
|
||||
public Checkbox getChkTotvs() {
|
||||
return chkTotvs;
|
||||
}
|
||||
|
||||
public void setChkTotvs(Checkbox chkTotvs) {
|
||||
this.chkTotvs = chkTotvs;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.rjconsultores.ventaboletos.web.utilerias.menu.item.pasajerofrecuente;
|
||||
|
||||
import com.rjconsultores.ventaboletos.web.utilerias.PantallaUtileria;
|
||||
import com.rjconsultores.ventaboletos.web.utilerias.menu.DefaultItemMenuSistema;
|
||||
|
||||
public class ItemMenuImportarPlanilha extends DefaultItemMenuSistema {
|
||||
|
||||
public ItemMenuImportarPlanilha() {
|
||||
super("Importar Planilha");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaveMenu() {
|
||||
return "COM.RJCONSULTORES.ADMINISTRACION.GUI.CONFIGURACIONECCOMERCIALES.MENU.IMPORTARCLIENTES";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ejecutar() {
|
||||
PantallaUtileria.openWindow("/gui/configuraciones_comerciales/importarPlanilha.zul",
|
||||
"Importar Planilha", getArgs() ,desktop);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?page contentType="text/html;charset=UTF-8"?>
|
||||
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
|
||||
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="winImportarPlanilha"?>
|
||||
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
|
||||
|
||||
<zk xmlns="http://www.zkoss.org/2005/zul">
|
||||
<window id="winImportarPlanilha"
|
||||
title="Importar Planilha"
|
||||
apply="${importarPlanilhaController}" contentStyle="overflow:auto"
|
||||
height="130px" width="450px" border="normal">
|
||||
|
||||
<toolbar width="405px">
|
||||
<button id="btnCerrar"
|
||||
onClick="winImportarPlanilha.detach()" image="/gui/img/exit.png"
|
||||
width="35px" />
|
||||
</toolbar>
|
||||
<button label="Importar Planilha" upload="true"
|
||||
onUpload="winImportarPlanilha$composer.onUpload(event)">
|
||||
</button>
|
||||
<label id="progressLabel" value=""></label>
|
||||
<separator />
|
||||
<checkbox id="chkCabecalho" checked="true" label="Tem cabeçalho" />
|
||||
<checkbox id="chkTotvs" label="Somente Enviar Totvs" />
|
||||
</window>
|
||||
</zk>
|
Loading…
Reference in New Issue