|
|
|
@ -32,10 +32,12 @@ import com.rjconsultores.ventaboletos.entidad.ClienteFidelidad;
|
|
|
|
|
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
|
|
|
|
import com.rjconsultores.ventaboletos.entidad.TarjetaFidelidad;
|
|
|
|
|
import com.rjconsultores.ventaboletos.entidad.TipoIdentificacion;
|
|
|
|
|
import com.rjconsultores.ventaboletos.entidad.TipoOcupacion;
|
|
|
|
|
import com.rjconsultores.ventaboletos.passageirofrequente.vo.ClienteExcelVo;
|
|
|
|
|
import com.rjconsultores.ventaboletos.service.ClienteService;
|
|
|
|
|
import com.rjconsultores.ventaboletos.service.ImportacaoClientesService;
|
|
|
|
|
import com.rjconsultores.ventaboletos.service.TipoIdentificacionService;
|
|
|
|
|
import com.rjconsultores.ventaboletos.service.TipoOcupacionService;
|
|
|
|
|
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
|
|
|
|
|
import com.rjconsultores.ventaboletos.utilerias.CustomEnum;
|
|
|
|
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
|
|
|
@ -43,10 +45,15 @@ import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
|
|
|
|
@Service("importacaoClientesService")
|
|
|
|
|
public class ImportacaoClientesServiceImpl implements ImportacaoClientesService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TipoOcupacionService tipoOcupacionService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TipoIdentificacionService tipoIdentificacionService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ClienteService clienteService;
|
|
|
|
|
|
|
|
|
|
private static Logger log = Logger.getLogger(ImportacaoClientesServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -165,7 +172,7 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
|
|
|
|
StringBuilder erros = new StringBuilder();
|
|
|
|
|
Integer inseridos = 0;
|
|
|
|
|
Integer atualizados = 0;
|
|
|
|
|
Integer desconsiderados =0;
|
|
|
|
|
Integer desconsiderados = 0;
|
|
|
|
|
InputStream isMExcel = media.getStreamData();
|
|
|
|
|
Sheet sheet = null;
|
|
|
|
|
|
|
|
|
@ -184,23 +191,23 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
|
|
|
|
wb = new XSSFWorkbook(isMExcel);
|
|
|
|
|
sheet = wb.getSheetAt(0);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("",e);
|
|
|
|
|
log.error("", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rows = sheet.getPhysicalNumberOfRows();
|
|
|
|
|
|
|
|
|
|
log.info(String.format("Quantidade cliente:%s",rows));
|
|
|
|
|
log.info(String.format("Quantidade cliente:%s", rows));
|
|
|
|
|
|
|
|
|
|
if (validaSheet(sheet)) {
|
|
|
|
|
usaCPFComoFidelidade = ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.USA_CPF_COMO_FIDELIDADE.getDescricao());
|
|
|
|
|
log.info(String.format("usaCPFComoFidelidade:%s",usaCPFComoFidelidade));
|
|
|
|
|
log.info(String.format("usaCPFComoFidelidade:%s", usaCPFComoFidelidade));
|
|
|
|
|
try {
|
|
|
|
|
for (index = 1; index < rows; index++) {
|
|
|
|
|
log.info(String.format("index cliente:%s",index));
|
|
|
|
|
log.info(String.format("index cliente:%s", index));
|
|
|
|
|
|
|
|
|
|
Row row = sheet.getRow(index);
|
|
|
|
|
if (row == null){
|
|
|
|
|
if (row == null) {
|
|
|
|
|
log.info("index/row empty");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -275,17 +282,17 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.info(String.format("cliente:%s cpf:%s",cliente.getNome(),cliente.getCpf()));
|
|
|
|
|
log.info(String.format("cliente:%s cpf:%s", cliente.getNome(), cliente.getCpf()));
|
|
|
|
|
|
|
|
|
|
if (validaDadosPlanilha(cliente, erros)) {
|
|
|
|
|
log.info("enviado para gravação...");
|
|
|
|
|
try{
|
|
|
|
|
Integer[] gravados = salvarClienteExcel(empresas, usaCPFComoFidelidade, cliente, tipoIdentificacionUno, tipoIdentificacionDoos);
|
|
|
|
|
try {
|
|
|
|
|
Integer[] gravados = salvarClienteExcel(empresas, usaCPFComoFidelidade, cliente, tipoIdentificacionUno, tipoIdentificacionDoos, false);
|
|
|
|
|
inseridos = gravados[0] + inseridos;
|
|
|
|
|
atualizados = gravados[1] + atualizados;
|
|
|
|
|
desconsiderados = gravados[2] + desconsiderados;
|
|
|
|
|
}catch(Throwable e){
|
|
|
|
|
log.error("Erro na gravação do registro. Favor revisar",e);
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
log.error("Erro na gravação do registro. Favor revisar", e);
|
|
|
|
|
log.info("continuando importação");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -295,7 +302,7 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
|
|
|
|
erros.append(index + 1).append(" do arquivo.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
qtdeGravados.append("Gravados ").append(inseridos + atualizados).append(" clientes de ").append(index-1).append(" importados.\n");
|
|
|
|
|
qtdeGravados.append("Gravados ").append(inseridos + atualizados).append(" clientes de ").append(index - 1).append(" importados.\n");
|
|
|
|
|
qtdeGravados.append("Desconsiderados ").append(desconsiderados).append(" clientes.\n");
|
|
|
|
|
qtdeGravados.append("Atualizados ").append(atualizados).append(" clientes.\n");
|
|
|
|
|
qtdeGravados.append("Inseridos ").append(inseridos).append(" novos clientes.");
|
|
|
|
@ -326,13 +333,20 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Integer[] salvarClienteExcel(List<Empresa> empresas, Boolean usaCPFComoFidelidade, ClienteExcelVo cliente, TipoIdentificacion tipoIdentificacionUno, TipoIdentificacion tipoIdentificacionDoos) throws ParseException {
|
|
|
|
|
private Integer[] salvarClienteExcel(List<Empresa> empresas, Boolean usaCPFComoFidelidade, ClienteExcelVo cliente,
|
|
|
|
|
TipoIdentificacion tipoIdentificacionUno, TipoIdentificacion tipoIdentificacionDoos, boolean isImportacaoPolicial) throws ParseException {
|
|
|
|
|
Integer inseridos = new Integer(0);
|
|
|
|
|
Integer atualizados = new Integer(0);
|
|
|
|
|
Integer desconsiderados = new Integer(0);
|
|
|
|
|
Integer[] gravados = { 0, 0, 0 };
|
|
|
|
|
Cliente clienteGravar = new Cliente();
|
|
|
|
|
List<Cliente> lsCliente = clienteService.buscarPorDocumento(cliente.getCpf());
|
|
|
|
|
|
|
|
|
|
String docBusca = cliente.getCpf();
|
|
|
|
|
if (isImportacaoPolicial) {
|
|
|
|
|
docBusca = cliente.getRg();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Cliente> lsCliente = clienteService.buscarPorDocumento(docBusca);
|
|
|
|
|
|
|
|
|
|
if (lsCliente != null && !lsCliente.isEmpty()) {
|
|
|
|
|
if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.IS_DESCONSIDERA_CLIENTE_NA_BASE.getDescricao())) {
|
|
|
|
@ -344,23 +358,45 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (true) {
|
|
|
|
|
criarFidelidadesTodasEmpresas(clienteGravar, empresas, cliente);
|
|
|
|
|
// }
|
|
|
|
|
clienteGravar.setFecnacimiento(StringUtils.isEmpty(cliente.getNascimento()) ? null : retornaDate(cliente.getNascimento()));
|
|
|
|
|
clienteGravar.setDesccorreo(cliente.getEmail());
|
|
|
|
|
if (usaCPFComoFidelidade == null)
|
|
|
|
|
usaCPFComoFidelidade = false;
|
|
|
|
|
|
|
|
|
|
criarFidelidadesTodasEmpresas(clienteGravar, empresas, cliente, usaCPFComoFidelidade);
|
|
|
|
|
|
|
|
|
|
clienteGravar.setNombcliente(cliente.getNome());
|
|
|
|
|
clienteGravar.setNumfax(cliente.getFax());
|
|
|
|
|
clienteGravar.setNumtelefono(cliente.getTelefone());
|
|
|
|
|
clienteGravar.setNumtelefonodos(cliente.getCelular());
|
|
|
|
|
clienteGravar.setIndsexo(cliente.getSexo());
|
|
|
|
|
clienteGravar.setNumIdentificaUno(cliente.getCpf());
|
|
|
|
|
clienteGravar.setTipoIdentificacionUno(tipoIdentificacionUno);
|
|
|
|
|
if (!StringUtils.isEmpty(cliente.getRg())) {
|
|
|
|
|
clienteGravar.setNumIdentificaDos(cliente.getRg());
|
|
|
|
|
clienteGravar.setTipoIdentificacionDos(tipoIdentificacionDoos);
|
|
|
|
|
|
|
|
|
|
if (isImportacaoPolicial) {
|
|
|
|
|
if (!StringUtils.isEmpty(cliente.getRg())) {
|
|
|
|
|
clienteGravar.setNumIdentificaUno(cliente.getRg());
|
|
|
|
|
clienteGravar.setTipoIdentificacionUno(tipoIdentificacionUno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<TipoOcupacion> ls = tipoOcupacionService.buscar("POLICIAL MILITAR", null);
|
|
|
|
|
if (ls == null || ls.isEmpty()) {
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
|
|
|
|
clienteGravar.setTipoocupacionId(ls != null && !ls.isEmpty() ? ls.get(0) : null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
clienteGravar.setFecnacimiento(StringUtils.isEmpty(cliente.getNascimento()) ? null : retornaDate(cliente.getNascimento()));
|
|
|
|
|
clienteGravar.setDesccorreo(cliente.getEmail());
|
|
|
|
|
|
|
|
|
|
clienteGravar.setNumfax(cliente.getFax());
|
|
|
|
|
clienteGravar.setNumtelefono(cliente.getTelefone());
|
|
|
|
|
clienteGravar.setNumtelefonodos(cliente.getCelular());
|
|
|
|
|
clienteGravar.setIndsexo(cliente.getSexo());
|
|
|
|
|
clienteGravar.setNumIdentificaUno(cliente.getCpf());
|
|
|
|
|
clienteGravar.setTipoIdentificacionUno(tipoIdentificacionUno);
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(cliente.getRg())) {
|
|
|
|
|
clienteGravar.setNumIdentificaDos(cliente.getRg());
|
|
|
|
|
clienteGravar.setTipoIdentificacionDos(tipoIdentificacionDoos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setDirecion(clienteGravar, cliente);
|
|
|
|
|
}
|
|
|
|
|
setDirecion(clienteGravar, cliente);
|
|
|
|
|
|
|
|
|
|
if (clienteGravar.getClienteId() == null) {
|
|
|
|
|
clienteGravar.setFecCadastro(new Date());
|
|
|
|
|
clienteService.suscribir(clienteGravar);
|
|
|
|
@ -397,7 +433,7 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void criarFidelidadesTodasEmpresas(Cliente cliente, List<Empresa> empresas, ClienteExcelVo cExce) {
|
|
|
|
|
private void criarFidelidadesTodasEmpresas(Cliente cliente, List<Empresa> empresas, ClienteExcelVo cExce, Boolean usaCPFComoFidelidade) {
|
|
|
|
|
|
|
|
|
|
Boolean achou = false;
|
|
|
|
|
List<ClienteFidelidad> fidelidades = null;
|
|
|
|
@ -405,7 +441,7 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
|
|
|
|
if (cliente.getClienteId() == null) {
|
|
|
|
|
fidelidades = new ArrayList<ClienteFidelidad>();
|
|
|
|
|
for (Empresa e : empresas) {
|
|
|
|
|
fidelidades.add(criarFidelidade(e, cExce));
|
|
|
|
|
fidelidades.add(criarFidelidade(e, cExce, usaCPFComoFidelidade));
|
|
|
|
|
}
|
|
|
|
|
cliente.setListClienteFidelidad(fidelidades);
|
|
|
|
|
|
|
|
|
@ -413,7 +449,7 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
|
|
|
|
fidelidades = cliente.getListClienteFidelidad();
|
|
|
|
|
if (fidelidades == null || fidelidades.isEmpty()) {
|
|
|
|
|
for (Empresa e : empresas) {
|
|
|
|
|
fidelidades.add(criarFidelidade(e, cExce));
|
|
|
|
|
fidelidades.add(criarFidelidade(e, cExce, usaCPFComoFidelidade));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (Empresa e : empresas) {
|
|
|
|
@ -432,7 +468,7 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!achou) {
|
|
|
|
|
fidelidades.add(criarFidelidade(e, cExce));
|
|
|
|
|
fidelidades.add(criarFidelidade(e, cExce, usaCPFComoFidelidade));
|
|
|
|
|
}
|
|
|
|
|
achou = false;
|
|
|
|
|
}
|
|
|
|
@ -441,43 +477,10 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// private List<ClienteFidelidad> criarFidelidadesTodasEmpresas(List<ClienteFidelidad> fidelidades, List<Empresa> empresas, ClienteExcelVo cExce) {
|
|
|
|
|
//
|
|
|
|
|
// List<ClienteFidelidad> result = new ArrayList<ClienteFidelidad>();
|
|
|
|
|
// Boolean achou = false;
|
|
|
|
|
// if (fidelidades==null || fidelidades.isEmpty()) {
|
|
|
|
|
// for (Empresa e : empresas) {
|
|
|
|
|
// result.add(criarFidelidade(e, cExce));
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// for (Empresa e : empresas) {
|
|
|
|
|
// for (ClienteFidelidad f : fidelidades) {
|
|
|
|
|
// if (f.getEmpresa().equals(e)) {
|
|
|
|
|
// f.setActivo(true);
|
|
|
|
|
// f.setFecmodif(new Date());
|
|
|
|
|
// TarjetaFidelidad tarjetaFidelidad = f.getTarjetaFidelidad();
|
|
|
|
|
// if(tarjetaFidelidad!=null){
|
|
|
|
|
// tarjetaFidelidad.setActivo(true);
|
|
|
|
|
// tarjetaFidelidad.setFecmodif(new Date());
|
|
|
|
|
// }
|
|
|
|
|
// result.add(f);
|
|
|
|
|
// achou = true;
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// if (!achou) {
|
|
|
|
|
// result.add(criarFidelidade(e, cExce));
|
|
|
|
|
// }
|
|
|
|
|
// achou = false;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// return result;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
private ClienteFidelidad criarFidelidade(Empresa e, ClienteExcelVo cExcel) {
|
|
|
|
|
private ClienteFidelidad criarFidelidade(Empresa e, ClienteExcelVo cExcel, Boolean usaCPFComoFidelidade) {
|
|
|
|
|
ClienteFidelidad clienteFidelidad = new ClienteFidelidad();
|
|
|
|
|
TarjetaFidelidad tarjetaFidelidad = new TarjetaFidelidad();
|
|
|
|
|
tarjetaFidelidad.setNumTarjeta(cExcel.getCpf());
|
|
|
|
|
tarjetaFidelidad.setNumTarjeta(usaCPFComoFidelidade ? cExcel.getCpf() : cExcel.getRg());
|
|
|
|
|
tarjetaFidelidad.setActivo(true);
|
|
|
|
|
tarjetaFidelidad.setFecmodif(Calendar.getInstance().getTime());
|
|
|
|
|
tarjetaFidelidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
|
|
|
@ -624,6 +627,29 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Boolean validaSheetImportacaoPolicial(Sheet sheet) {
|
|
|
|
|
|
|
|
|
|
Row row = sheet.getRow(0);
|
|
|
|
|
Iterator<Cell> cellIterator = row.cellIterator();
|
|
|
|
|
|
|
|
|
|
while (cellIterator.hasNext()) {
|
|
|
|
|
Cell cell = cellIterator.next();
|
|
|
|
|
switch (cell.getColumnIndex()) {
|
|
|
|
|
case 0:
|
|
|
|
|
if (cell.getStringCellValue().equalsIgnoreCase(Labels.getLabel("importarClientesPolicialController.HEADERCOLUMN.nome"))) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
case 1:
|
|
|
|
|
if (cell.getStringCellValue().equalsIgnoreCase(Labels.getLabel("importarClientesPolicialController.HEADERCOLUMN.rg"))) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Date retornaDate(String date) throws ParseException {
|
|
|
|
|
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
|
@ -655,4 +681,124 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String[] lerArquivoPolicialExcel(Media media, List<Empresa> empresas) {
|
|
|
|
|
|
|
|
|
|
List<TipoIdentificacion> lsTipoIdentificacion = tipoIdentificacionService.obtenerTodos();
|
|
|
|
|
TipoIdentificacion tipoIdentificacionUno = null;
|
|
|
|
|
|
|
|
|
|
for (TipoIdentificacion t : lsTipoIdentificacion) {
|
|
|
|
|
|
|
|
|
|
if (t.getDesctipo().equalsIgnoreCase("rg")) {
|
|
|
|
|
tipoIdentificacionUno = t;
|
|
|
|
|
}
|
|
|
|
|
if (tipoIdentificacionUno != null)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Integer index = 1;
|
|
|
|
|
StringBuilder qtdeGravados = new StringBuilder();
|
|
|
|
|
StringBuilder erros = new StringBuilder();
|
|
|
|
|
Integer inseridos = 0;
|
|
|
|
|
Integer atualizados = 0;
|
|
|
|
|
Integer desconsiderados = 0;
|
|
|
|
|
InputStream isMExcel = media.getStreamData();
|
|
|
|
|
Sheet sheet = null;
|
|
|
|
|
|
|
|
|
|
if (media.getFormat().equals("xls")) {
|
|
|
|
|
HSSFWorkbook wb;
|
|
|
|
|
try {
|
|
|
|
|
wb = new HSSFWorkbook(isMExcel);
|
|
|
|
|
sheet = wb.getSheetAt(0);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (media.getFormat().equals("xlsx")) {
|
|
|
|
|
XSSFWorkbook wb;
|
|
|
|
|
try {
|
|
|
|
|
wb = new XSSFWorkbook(isMExcel);
|
|
|
|
|
sheet = wb.getSheetAt(0);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rows = sheet.getPhysicalNumberOfRows();
|
|
|
|
|
|
|
|
|
|
log.info(String.format("Quantidade cliente:%s", rows));
|
|
|
|
|
|
|
|
|
|
if (validaSheetImportacaoPolicial(sheet)) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
for (index = 1; index < rows; index++) {
|
|
|
|
|
log.info(String.format("index cliente:%s", index));
|
|
|
|
|
|
|
|
|
|
Row row = sheet.getRow(index);
|
|
|
|
|
if (row == null) {
|
|
|
|
|
log.info("index/row empty");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Iterator<Cell> cellIterator = row.cellIterator();
|
|
|
|
|
ClienteExcelVo cliente = new ClienteExcelVo();
|
|
|
|
|
|
|
|
|
|
while (cellIterator.hasNext()) {
|
|
|
|
|
Cell cell = cellIterator.next();
|
|
|
|
|
switch (cell.getColumnIndex()) {
|
|
|
|
|
case 0:
|
|
|
|
|
cell.setCellType(Cell.CELL_TYPE_STRING);
|
|
|
|
|
cliente.setNome(cell.getStringCellValue());
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
cell.setCellType(Cell.CELL_TYPE_STRING);
|
|
|
|
|
cliente.setRg(cell.getStringCellValue());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.info(String.format("cliente:%s rg:%s", cliente.getNome(), cliente.getRg()));
|
|
|
|
|
|
|
|
|
|
log.info("enviado para gravação...");
|
|
|
|
|
try {
|
|
|
|
|
Integer[] gravados = salvarClienteExcel(empresas, false, cliente, tipoIdentificacionUno, null, true);
|
|
|
|
|
inseridos = gravados[0] + inseridos;
|
|
|
|
|
atualizados = gravados[1] + atualizados;
|
|
|
|
|
desconsiderados = gravados[2] + desconsiderados;
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
log.error("Erro na gravação do registro. Favor revisar", e);
|
|
|
|
|
log.info("continuando importação");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
qtdeGravados.append("Gravados ").append(inseridos + atualizados).append(" clientes de ").append(index - 1).append(" importados.\n");
|
|
|
|
|
qtdeGravados.append("Desconsiderados ").append(desconsiderados).append(" clientes.\n");
|
|
|
|
|
qtdeGravados.append("Atualizados ").append(atualizados).append(" clientes.\n");
|
|
|
|
|
qtdeGravados.append("Inseridos ").append(inseridos).append(" novos clientes.");
|
|
|
|
|
String[] resultado = { qtdeGravados.toString(), erros.toString() };
|
|
|
|
|
|
|
|
|
|
log.info("importação finalizada");
|
|
|
|
|
|
|
|
|
|
return resultado;
|
|
|
|
|
|
|
|
|
|
} catch (ArrayIndexOutOfBoundsException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
String msg = "Erro ao gravar cliente na linha " + (index + 1) + " do arquivo.";
|
|
|
|
|
erros.append(msg);
|
|
|
|
|
String[] resultado = { "Houve erro ao gravar os clientes, consulte o arquivo de erros.", erros.toString() };
|
|
|
|
|
return resultado;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
erros.append("Linha ").append(index).append(" do arquivo de clientes, erro: ").append(e.getCause().getCause()).append("\n");
|
|
|
|
|
String[] resultado = { "Houve erro ao gravar os clientes, consulte o arquivo de erros.", erros.toString() };
|
|
|
|
|
return resultado;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
erros.append("A estrutura do arquivo esta com erro ").append("\n");
|
|
|
|
|
String[] resultado = { "Houve erro ao gravar os clientes, consulte o arquivo de erros.", erros.toString() };
|
|
|
|
|
return resultado;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|