114 lines
3.5 KiB
Java
114 lines
3.5 KiB
Java
package com.rjconsultores.ventaboletos.service.impl;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.SQLException;
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map.Entry;
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
import org.apache.log4j.Logger;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import com.rjconsultores.ventaboletos.dao.MonitoramentoCCFDAO;
|
|
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCCF;
|
|
import com.rjconsultores.ventaboletos.service.MonitoramentoCCFService;
|
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
|
|
|
@Service("monitoramentoCCFService")
|
|
public class MonitoramentoCCFServiceImpl implements MonitoramentoCCFService{
|
|
private static Logger log = Logger.getLogger(MonitoramentoCCFServiceImpl.class);
|
|
|
|
@Autowired
|
|
private MonitoramentoCCFDAO monitoramentoCCFDAO;
|
|
@Autowired
|
|
private DataSource dataSource;
|
|
private Connection con;
|
|
|
|
public List<MonitoramentoCCF> obtenerTodos() {
|
|
return monitoramentoCCFDAO.obtenerTodos();
|
|
}
|
|
|
|
public MonitoramentoCCF obtenerID(Integer id) {
|
|
return monitoramentoCCFDAO.obtenerID(id);
|
|
}
|
|
|
|
@Override
|
|
public void openConnection(){
|
|
try {
|
|
con = dataSource.getConnection();
|
|
monitoramentoCCFDAO.setConnection(con);
|
|
log.debug("Abrindo conexão...");
|
|
} catch (SQLException e) {
|
|
log.error("", e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void closeConnection(){
|
|
try {
|
|
this.con.close();
|
|
log.debug("Conexão fechada!");
|
|
} catch (SQLException e) {
|
|
log.error("", e);
|
|
} finally {
|
|
if (con != null){
|
|
try { con.close(); } catch (SQLException e) { log.error("", e); }
|
|
}
|
|
}
|
|
}
|
|
|
|
@Transactional
|
|
public MonitoramentoCCF suscribir(MonitoramentoCCF entidad) {
|
|
entidad.setUsuarioModif(UsuarioLogado.getUsuarioLogado());
|
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
|
entidad.setActivo(Boolean.TRUE);
|
|
|
|
return monitoramentoCCFDAO.suscribir(entidad);
|
|
}
|
|
|
|
@Transactional
|
|
public MonitoramentoCCF actualizacion(MonitoramentoCCF entidad) {
|
|
entidad.setUsuarioModif(UsuarioLogado.getUsuarioLogado());
|
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
|
entidad.setActivo(Boolean.TRUE);
|
|
|
|
return monitoramentoCCFDAO.actualizacion(entidad);
|
|
}
|
|
|
|
@Transactional
|
|
public void borrar(MonitoramentoCCF entidad) {
|
|
entidad.setUsuarioModif(UsuarioLogado.getUsuarioLogado());
|
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
|
entidad.setActivo(Boolean.FALSE);
|
|
|
|
monitoramentoCCFDAO.actualizacion(entidad);
|
|
}
|
|
|
|
@Override
|
|
public List<MonitoramentoCCF> buscaQuebraCCF(final String numserie20, final Date data, final Integer ccfInicial) {
|
|
return monitoramentoCCFDAO.buscaQuebraCCF(numserie20, data, ccfInicial);
|
|
}
|
|
|
|
public void gravarListaCCFQuebrados(Map<String, Integer> impressoras, Date data){
|
|
try {
|
|
for (Entry<String, Integer> imp : impressoras.entrySet()){
|
|
for (MonitoramentoCCF m : buscaQuebraCCF(imp.getKey(), data, imp.getValue())){
|
|
monitoramentoCCFDAO.suscribir(m);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
log.error("", e);
|
|
}
|
|
}
|
|
|
|
public Map<String, Integer> obterImpressorasComCCFInicial(Date data){
|
|
return monitoramentoCCFDAO.obterImpressorasComCCFInicial(data);
|
|
}
|
|
}
|