fixes bug#24679
dev: Valdir qua: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@112868 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
077965e1b7
commit
1c78b37aa0
|
@ -4,9 +4,8 @@
|
||||||
*/
|
*/
|
||||||
package com.rjconsultores.ventaboletos.dao.hibernate;
|
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.dao.TipoOcupacionDAO;
|
|
||||||
import com.rjconsultores.ventaboletos.entidad.TipoOcupacion;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
@ -14,43 +13,51 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.dao.TipoOcupacionDAO;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.TipoOcupacion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Administrador
|
* @author Administrador
|
||||||
*/
|
*/
|
||||||
@Repository("tipoOcupacionDAO")
|
@Repository("tipoOcupacionDAO")
|
||||||
public class TipoOcupacionHibernateDAO extends GenericHibernateDAO<TipoOcupacion, Integer>
|
public class TipoOcupacionHibernateDAO extends GenericHibernateDAO<TipoOcupacion, Integer>
|
||||||
implements TipoOcupacionDAO {
|
implements TipoOcupacionDAO {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public TipoOcupacionHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
public TipoOcupacionHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||||
setSessionFactory(factory);
|
setSessionFactory(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TipoOcupacion> obtenerTodos() {
|
public List<TipoOcupacion> obtenerTodos() {
|
||||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||||
|
|
||||||
return c.list();
|
return c.list();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TipoOcupacion> buscar(String desctipo, String cvetipoocupacion) {
|
public List<TipoOcupacion> buscar(String desctipo, String cvetipoocupacion) {
|
||||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||||
|
|
||||||
c.add(Restrictions.eq("desctipo", desctipo));
|
if (desctipo != null) {
|
||||||
c.add(Restrictions.eq("cvetipoocupacion", cvetipoocupacion));
|
c.add(Restrictions.eq("desctipo", desctipo));
|
||||||
|
}
|
||||||
|
|
||||||
return c.list();
|
if (cvetipoocupacion != null) {
|
||||||
}
|
c.add(Restrictions.eq("cvetipoocupacion", cvetipoocupacion));
|
||||||
|
}
|
||||||
|
|
||||||
public List<TipoOcupacion> buscarClave(String cvetipoocupacion) {
|
return c.list();
|
||||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
}
|
||||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
||||||
|
|
||||||
c.add(Restrictions.eq("cvetipoocupacion", cvetipoocupacion));
|
public List<TipoOcupacion> buscarClave(String cvetipoocupacion) {
|
||||||
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||||
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||||
|
|
||||||
return c.list();
|
c.add(Restrictions.eq("cvetipoocupacion", cvetipoocupacion));
|
||||||
}
|
|
||||||
|
return c.list();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,4 +14,7 @@ public interface ImportacaoClientesService {
|
||||||
public String[] lerArquivoExcel(Media media, List<Empresa> empresas);
|
public String[] lerArquivoExcel(Media media, List<Empresa> empresas);
|
||||||
|
|
||||||
public Integer[] salvarClientes(String[] cliente, List<Empresa> empresas) throws Exception;
|
public Integer[] salvarClientes(String[] cliente, List<Empresa> empresas) throws Exception;
|
||||||
|
|
||||||
|
public String[] lerArquivoPolicialExcel(Media media, List<Empresa> empresas);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public interface TipoOcupacionService extends GenericService<TipoOcupacion, Integer> {
|
public interface TipoOcupacionService extends GenericService<TipoOcupacion, Integer> {
|
||||||
|
|
||||||
|
public List<TipoOcupacion> buscar(String desctipo);
|
||||||
|
|
||||||
public List<TipoOcupacion> buscar(String desctipo, String cvetipoocupacion);
|
public List<TipoOcupacion> buscar(String desctipo, String cvetipoocupacion);
|
||||||
|
|
||||||
public List<TipoOcupacion> buscarClave(String cvetipoocupacion);
|
public List<TipoOcupacion> buscarClave(String cvetipoocupacion);
|
||||||
|
|
|
@ -32,10 +32,12 @@ import com.rjconsultores.ventaboletos.entidad.ClienteFidelidad;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||||
import com.rjconsultores.ventaboletos.entidad.TarjetaFidelidad;
|
import com.rjconsultores.ventaboletos.entidad.TarjetaFidelidad;
|
||||||
import com.rjconsultores.ventaboletos.entidad.TipoIdentificacion;
|
import com.rjconsultores.ventaboletos.entidad.TipoIdentificacion;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.TipoOcupacion;
|
||||||
import com.rjconsultores.ventaboletos.passageirofrequente.vo.ClienteExcelVo;
|
import com.rjconsultores.ventaboletos.passageirofrequente.vo.ClienteExcelVo;
|
||||||
import com.rjconsultores.ventaboletos.service.ClienteService;
|
import com.rjconsultores.ventaboletos.service.ClienteService;
|
||||||
import com.rjconsultores.ventaboletos.service.ImportacaoClientesService;
|
import com.rjconsultores.ventaboletos.service.ImportacaoClientesService;
|
||||||
import com.rjconsultores.ventaboletos.service.TipoIdentificacionService;
|
import com.rjconsultores.ventaboletos.service.TipoIdentificacionService;
|
||||||
|
import com.rjconsultores.ventaboletos.service.TipoOcupacionService;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
|
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.CustomEnum;
|
import com.rjconsultores.ventaboletos.utilerias.CustomEnum;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||||
|
@ -43,10 +45,15 @@ import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||||
@Service("importacaoClientesService")
|
@Service("importacaoClientesService")
|
||||||
public class ImportacaoClientesServiceImpl implements ImportacaoClientesService {
|
public class ImportacaoClientesServiceImpl implements ImportacaoClientesService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TipoOcupacionService tipoOcupacionService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
TipoIdentificacionService tipoIdentificacionService;
|
TipoIdentificacionService tipoIdentificacionService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ClienteService clienteService;
|
private ClienteService clienteService;
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(ImportacaoClientesServiceImpl.class);
|
private static Logger log = Logger.getLogger(ImportacaoClientesServiceImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -165,7 +172,7 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
||||||
StringBuilder erros = new StringBuilder();
|
StringBuilder erros = new StringBuilder();
|
||||||
Integer inseridos = 0;
|
Integer inseridos = 0;
|
||||||
Integer atualizados = 0;
|
Integer atualizados = 0;
|
||||||
Integer desconsiderados =0;
|
Integer desconsiderados = 0;
|
||||||
InputStream isMExcel = media.getStreamData();
|
InputStream isMExcel = media.getStreamData();
|
||||||
Sheet sheet = null;
|
Sheet sheet = null;
|
||||||
|
|
||||||
|
@ -184,30 +191,30 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
||||||
wb = new XSSFWorkbook(isMExcel);
|
wb = new XSSFWorkbook(isMExcel);
|
||||||
sheet = wb.getSheetAt(0);
|
sheet = wb.getSheetAt(0);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("",e);
|
log.error("", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int rows = sheet.getPhysicalNumberOfRows();
|
int rows = sheet.getPhysicalNumberOfRows();
|
||||||
|
|
||||||
log.info(String.format("Quantidade cliente:%s",rows));
|
log.info(String.format("Quantidade cliente:%s", rows));
|
||||||
|
|
||||||
if (validaSheet(sheet)) {
|
if (validaSheet(sheet)) {
|
||||||
usaCPFComoFidelidade = ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.USA_CPF_COMO_FIDELIDADE.getDescricao());
|
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 {
|
try {
|
||||||
for (index = 1; index < rows; index++) {
|
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);
|
Row row = sheet.getRow(index);
|
||||||
if (row == null){
|
if (row == null) {
|
||||||
log.info("index/row empty");
|
log.info("index/row empty");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<Cell> cellIterator = row.cellIterator();
|
Iterator<Cell> cellIterator = row.cellIterator();
|
||||||
ClienteExcelVo cliente = new ClienteExcelVo();
|
ClienteExcelVo cliente = new ClienteExcelVo();
|
||||||
|
|
||||||
while (cellIterator.hasNext()) {
|
while (cellIterator.hasNext()) {
|
||||||
Cell cell = cellIterator.next();
|
Cell cell = cellIterator.next();
|
||||||
switch (cell.getColumnIndex()) {
|
switch (cell.getColumnIndex()) {
|
||||||
|
@ -241,7 +248,7 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
||||||
cliente.setFax(cell.getStringCellValue());
|
cliente.setFax(cell.getStringCellValue());
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
|
|
||||||
String dt = null;
|
String dt = null;
|
||||||
|
|
||||||
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
|
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
|
||||||
|
@ -250,7 +257,7 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
||||||
dt = cell.getDateCellValue() != null ? new SimpleDateFormat("dd/MM/yyyy").format(cell.getDateCellValue()) : null;
|
dt = cell.getDateCellValue() != null ? new SimpleDateFormat("dd/MM/yyyy").format(cell.getDateCellValue()) : null;
|
||||||
}
|
}
|
||||||
cliente.setNascimento(dt);
|
cliente.setNascimento(dt);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
cell.setCellType(Cell.CELL_TYPE_STRING);
|
cell.setCellType(Cell.CELL_TYPE_STRING);
|
||||||
|
@ -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)) {
|
if (validaDadosPlanilha(cliente, erros)) {
|
||||||
log.info("enviado para gravação...");
|
log.info("enviado para gravação...");
|
||||||
try{
|
try {
|
||||||
Integer[] gravados = salvarClienteExcel(empresas, usaCPFComoFidelidade, cliente, tipoIdentificacionUno, tipoIdentificacionDoos);
|
Integer[] gravados = salvarClienteExcel(empresas, usaCPFComoFidelidade, cliente, tipoIdentificacionUno, tipoIdentificacionDoos, false);
|
||||||
inseridos = gravados[0] + inseridos;
|
inseridos = gravados[0] + inseridos;
|
||||||
atualizados = gravados[1] + atualizados;
|
atualizados = gravados[1] + atualizados;
|
||||||
desconsiderados = gravados[2] + desconsiderados;
|
desconsiderados = gravados[2] + desconsiderados;
|
||||||
}catch(Throwable e){
|
} catch (Throwable e) {
|
||||||
log.error("Erro na gravação do registro. Favor revisar",e);
|
log.error("Erro na gravação do registro. Favor revisar", e);
|
||||||
log.info("continuando importação");
|
log.info("continuando importação");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,14 +302,14 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
||||||
erros.append(index + 1).append(" do arquivo.");
|
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("Desconsiderados ").append(desconsiderados).append(" clientes.\n");
|
||||||
qtdeGravados.append("Atualizados ").append(atualizados).append(" clientes.\n");
|
qtdeGravados.append("Atualizados ").append(atualizados).append(" clientes.\n");
|
||||||
qtdeGravados.append("Inseridos ").append(inseridos).append(" novos clientes.");
|
qtdeGravados.append("Inseridos ").append(inseridos).append(" novos clientes.");
|
||||||
String[] resultado = { qtdeGravados.toString(), erros.toString() };
|
String[] resultado = { qtdeGravados.toString(), erros.toString() };
|
||||||
|
|
||||||
log.info("importação finalizada");
|
log.info("importação finalizada");
|
||||||
|
|
||||||
return resultado;
|
return resultado;
|
||||||
|
|
||||||
} catch (ArrayIndexOutOfBoundsException e) {
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
|
@ -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 inseridos = new Integer(0);
|
||||||
Integer atualizados = new Integer(0);
|
Integer atualizados = new Integer(0);
|
||||||
Integer desconsiderados = new Integer(0);
|
Integer desconsiderados = new Integer(0);
|
||||||
Integer[] gravados = { 0, 0, 0 };
|
Integer[] gravados = { 0, 0, 0 };
|
||||||
Cliente clienteGravar = new Cliente();
|
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 (lsCliente != null && !lsCliente.isEmpty()) {
|
||||||
if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.IS_DESCONSIDERA_CLIENTE_NA_BASE.getDescricao())) {
|
if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.IS_DESCONSIDERA_CLIENTE_NA_BASE.getDescricao())) {
|
||||||
|
@ -344,23 +358,45 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (true) {
|
if (usaCPFComoFidelidade == null)
|
||||||
criarFidelidadesTodasEmpresas(clienteGravar, empresas, cliente);
|
usaCPFComoFidelidade = false;
|
||||||
// }
|
|
||||||
clienteGravar.setFecnacimiento(StringUtils.isEmpty(cliente.getNascimento()) ? null : retornaDate(cliente.getNascimento()));
|
criarFidelidadesTodasEmpresas(clienteGravar, empresas, cliente, usaCPFComoFidelidade);
|
||||||
clienteGravar.setDesccorreo(cliente.getEmail());
|
|
||||||
clienteGravar.setNombcliente(cliente.getNome());
|
clienteGravar.setNombcliente(cliente.getNome());
|
||||||
clienteGravar.setNumfax(cliente.getFax());
|
|
||||||
clienteGravar.setNumtelefono(cliente.getTelefone());
|
if (isImportacaoPolicial) {
|
||||||
clienteGravar.setNumtelefonodos(cliente.getCelular());
|
if (!StringUtils.isEmpty(cliente.getRg())) {
|
||||||
clienteGravar.setIndsexo(cliente.getSexo());
|
clienteGravar.setNumIdentificaUno(cliente.getRg());
|
||||||
clienteGravar.setNumIdentificaUno(cliente.getCpf());
|
clienteGravar.setTipoIdentificacionUno(tipoIdentificacionUno);
|
||||||
clienteGravar.setTipoIdentificacionUno(tipoIdentificacionUno);
|
}
|
||||||
if (!StringUtils.isEmpty(cliente.getRg())) {
|
|
||||||
clienteGravar.setNumIdentificaDos(cliente.getRg());
|
List<TipoOcupacion> ls = tipoOcupacionService.buscar("POLICIAL MILITAR", null);
|
||||||
clienteGravar.setTipoIdentificacionDos(tipoIdentificacionDoos);
|
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) {
|
if (clienteGravar.getClienteId() == null) {
|
||||||
clienteGravar.setFecCadastro(new Date());
|
clienteGravar.setFecCadastro(new Date());
|
||||||
clienteService.suscribir(clienteGravar);
|
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;
|
Boolean achou = false;
|
||||||
List<ClienteFidelidad> fidelidades = null;
|
List<ClienteFidelidad> fidelidades = null;
|
||||||
|
@ -405,7 +441,7 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
||||||
if (cliente.getClienteId() == null) {
|
if (cliente.getClienteId() == null) {
|
||||||
fidelidades = new ArrayList<ClienteFidelidad>();
|
fidelidades = new ArrayList<ClienteFidelidad>();
|
||||||
for (Empresa e : empresas) {
|
for (Empresa e : empresas) {
|
||||||
fidelidades.add(criarFidelidade(e, cExce));
|
fidelidades.add(criarFidelidade(e, cExce, usaCPFComoFidelidade));
|
||||||
}
|
}
|
||||||
cliente.setListClienteFidelidad(fidelidades);
|
cliente.setListClienteFidelidad(fidelidades);
|
||||||
|
|
||||||
|
@ -413,7 +449,7 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
||||||
fidelidades = cliente.getListClienteFidelidad();
|
fidelidades = cliente.getListClienteFidelidad();
|
||||||
if (fidelidades == null || fidelidades.isEmpty()) {
|
if (fidelidades == null || fidelidades.isEmpty()) {
|
||||||
for (Empresa e : empresas) {
|
for (Empresa e : empresas) {
|
||||||
fidelidades.add(criarFidelidade(e, cExce));
|
fidelidades.add(criarFidelidade(e, cExce, usaCPFComoFidelidade));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (Empresa e : empresas) {
|
for (Empresa e : empresas) {
|
||||||
|
@ -432,7 +468,7 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!achou) {
|
if (!achou) {
|
||||||
fidelidades.add(criarFidelidade(e, cExce));
|
fidelidades.add(criarFidelidade(e, cExce, usaCPFComoFidelidade));
|
||||||
}
|
}
|
||||||
achou = false;
|
achou = false;
|
||||||
}
|
}
|
||||||
|
@ -441,43 +477,10 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private List<ClienteFidelidad> criarFidelidadesTodasEmpresas(List<ClienteFidelidad> fidelidades, List<Empresa> empresas, ClienteExcelVo cExce) {
|
private ClienteFidelidad criarFidelidade(Empresa e, ClienteExcelVo cExcel, Boolean usaCPFComoFidelidade) {
|
||||||
//
|
|
||||||
// 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) {
|
|
||||||
ClienteFidelidad clienteFidelidad = new ClienteFidelidad();
|
ClienteFidelidad clienteFidelidad = new ClienteFidelidad();
|
||||||
TarjetaFidelidad tarjetaFidelidad = new TarjetaFidelidad();
|
TarjetaFidelidad tarjetaFidelidad = new TarjetaFidelidad();
|
||||||
tarjetaFidelidad.setNumTarjeta(cExcel.getCpf());
|
tarjetaFidelidad.setNumTarjeta(usaCPFComoFidelidade ? cExcel.getCpf() : cExcel.getRg());
|
||||||
tarjetaFidelidad.setActivo(true);
|
tarjetaFidelidad.setActivo(true);
|
||||||
tarjetaFidelidad.setFecmodif(Calendar.getInstance().getTime());
|
tarjetaFidelidad.setFecmodif(Calendar.getInstance().getTime());
|
||||||
tarjetaFidelidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
tarjetaFidelidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
||||||
|
@ -624,6 +627,29 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
||||||
return true;
|
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 {
|
private Date retornaDate(String date) throws ParseException {
|
||||||
|
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
|
||||||
|
@ -655,4 +681,124 @@ public class ImportacaoClientesServiceImpl implements ImportacaoClientesService
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,49 +21,53 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
@Service("tipoOcupacionService")
|
@Service("tipoOcupacionService")
|
||||||
public class TipoOcupacionServiceImpl implements TipoOcupacionService {
|
public class TipoOcupacionServiceImpl implements TipoOcupacionService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TipoOcupacionDAO tipoOcupacionDAO;
|
private TipoOcupacionDAO tipoOcupacionDAO;
|
||||||
|
|
||||||
public List<TipoOcupacion> obtenerTodos() {
|
public List<TipoOcupacion> obtenerTodos() {
|
||||||
return tipoOcupacionDAO.obtenerTodos();
|
return tipoOcupacionDAO.obtenerTodos();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TipoOcupacion obtenerID(Integer id) {
|
public TipoOcupacion obtenerID(Integer id) {
|
||||||
return tipoOcupacionDAO.obtenerID(id);
|
return tipoOcupacionDAO.obtenerID(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public TipoOcupacion suscribir(TipoOcupacion entidad) {
|
public TipoOcupacion suscribir(TipoOcupacion entidad) {
|
||||||
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
||||||
entidad.setFecmodif(Calendar.getInstance().getTime());
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||||
entidad.setActivo(Boolean.TRUE);
|
entidad.setActivo(Boolean.TRUE);
|
||||||
|
|
||||||
return tipoOcupacionDAO.suscribir(entidad);
|
return tipoOcupacionDAO.suscribir(entidad);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public TipoOcupacion actualizacion(TipoOcupacion entidad) {
|
public TipoOcupacion actualizacion(TipoOcupacion entidad) {
|
||||||
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
||||||
entidad.setFecmodif(Calendar.getInstance().getTime());
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||||
entidad.setActivo(Boolean.TRUE);
|
entidad.setActivo(Boolean.TRUE);
|
||||||
|
|
||||||
return tipoOcupacionDAO.actualizacion(entidad);
|
return tipoOcupacionDAO.actualizacion(entidad);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void borrar(TipoOcupacion entidad) {
|
public void borrar(TipoOcupacion entidad) {
|
||||||
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
||||||
entidad.setFecmodif(Calendar.getInstance().getTime());
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||||
entidad.setActivo(Boolean.FALSE);
|
entidad.setActivo(Boolean.FALSE);
|
||||||
|
|
||||||
tipoOcupacionDAO.actualizacion(entidad);
|
tipoOcupacionDAO.actualizacion(entidad);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TipoOcupacion> buscar(String desctipo, String cvetipoocupacion) {
|
public List<TipoOcupacion> buscar(String desctipo) {
|
||||||
return tipoOcupacionDAO.buscar(desctipo, cvetipoocupacion);
|
return buscar(desctipo, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TipoOcupacion> buscarClave(String cvetipoocupacion) {
|
public List<TipoOcupacion> buscar(String desctipo, String cvetipoocupacion) {
|
||||||
return tipoOcupacionDAO.buscarClave(cvetipoocupacion);
|
return tipoOcupacionDAO.buscar(desctipo, cvetipoocupacion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<TipoOcupacion> buscarClave(String cvetipoocupacion) {
|
||||||
|
return tipoOcupacionDAO.buscarClave(cvetipoocupacion);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue