fixes bug #9201
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@76862 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
ca8c279681
commit
1fc58c594b
|
@ -1,12 +1,15 @@
|
||||||
package com.rjconsultores.ventaboletos.dao;
|
package com.rjconsultores.ventaboletos.dao;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCCF;
|
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCCF;
|
||||||
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCCFR2;
|
|
||||||
|
|
||||||
public interface MonitoramentoCCFDAO extends GenericDAO<MonitoramentoCCF, Integer> {
|
public interface MonitoramentoCCFDAO extends GenericDAO<MonitoramentoCCF, Integer> {
|
||||||
public List<MonitoramentoCCF> buscaQuebraCCF(String numserie20, Date data);
|
public List<MonitoramentoCCF> buscaQuebraCCF(final String numserie, final Date data, final Integer ccfInicial);
|
||||||
public List<MonitoramentoCCFR2> buscaRegistrosR2(Date data);
|
public List<MonitoramentoCCF> obtenerTodos();
|
||||||
|
public void setConnection(Connection con);
|
||||||
|
public Map<String, Integer> obterImpressorasComCCFInicial(Date data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,4 +7,5 @@ import com.rjconsultores.ventaboletos.entidad.MonitoramentoCRZ;
|
||||||
|
|
||||||
public interface MonitoramentoCRZDAO extends GenericDAO<MonitoramentoCRZ, Integer> {
|
public interface MonitoramentoCRZDAO extends GenericDAO<MonitoramentoCRZ, Integer> {
|
||||||
public List<MonitoramentoCRZ> buscaQuebraCRZ(Date data);
|
public List<MonitoramentoCRZ> buscaQuebraCRZ(Date data);
|
||||||
|
public List<MonitoramentoCRZ> obtenerTodos();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,19 @@
|
||||||
package com.rjconsultores.ventaboletos.dao.hibernate;
|
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.text.SimpleDateFormat;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.hibernate.Query;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.jfree.util.Log;
|
import org.hibernate.jdbc.Work;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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;
|
||||||
|
@ -17,7 +23,7 @@ import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Estado;
|
import com.rjconsultores.ventaboletos.entidad.Estado;
|
||||||
import com.rjconsultores.ventaboletos.entidad.FiscalImpressora;
|
import com.rjconsultores.ventaboletos.entidad.FiscalImpressora;
|
||||||
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCCF;
|
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCCF;
|
||||||
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCCFR2;
|
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCRZ;
|
||||||
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
|
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Usuario;
|
import com.rjconsultores.ventaboletos.entidad.Usuario;
|
||||||
import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
|
import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
|
||||||
|
@ -25,6 +31,9 @@ import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
|
||||||
@Repository("monitoramentoCCFDAO")
|
@Repository("monitoramentoCCFDAO")
|
||||||
public class MonitoramentoCCFHibernateDAO extends GenericHibernateDAO<MonitoramentoCCF, Integer>
|
public class MonitoramentoCCFHibernateDAO extends GenericHibernateDAO<MonitoramentoCCF, Integer>
|
||||||
implements MonitoramentoCCFDAO {
|
implements MonitoramentoCCFDAO {
|
||||||
|
private static Logger log = Logger.getLogger(MonitoramentoCCFHibernateDAO.class);
|
||||||
|
private Connection con;
|
||||||
|
Boolean jaexiste;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public MonitoramentoCCFHibernateDAO(
|
public MonitoramentoCCFHibernateDAO(
|
||||||
|
@ -35,99 +44,211 @@ implements MonitoramentoCCFDAO {
|
||||||
private String getSQL(){
|
private String getSQL(){
|
||||||
StringBuilder sql = new StringBuilder();
|
StringBuilder sql = new StringBuilder();
|
||||||
|
|
||||||
sql.append(" select ");
|
sql.append(" SELECT ");
|
||||||
sql.append(" fi.empresa_id as empresa, ");
|
sql.append(" fi.empresa_id as empresa, ");
|
||||||
sql.append(" r4.numserie20, ");
|
sql.append(" fi.numserie20 as numserie20, ");
|
||||||
sql.append(" fi.fiscalimpressora_id, ");
|
sql.append(" fi.fiscalimpressora_id as fiscalimpressora_id, ");
|
||||||
sql.append(" fi.estadolocal_id as estado, ");
|
sql.append(" fi.estadolocal_id as estado, ");
|
||||||
sql.append(" to_date(r4.datamov, 'YYYYMMDD') as datamov, ");
|
sql.append(" c.FECCREACION as datamov, ");
|
||||||
sql.append(" fi.puntoventa_id, ");
|
sql.append(" fi.puntoventa_id as puntoventa_id, ");
|
||||||
sql.append(" r4.usuario_id, ");
|
sql.append(" c.usuario_id as usuario_id, ");
|
||||||
sql.append(" r4.coo ");
|
sql.append(" r4.contador as ccf, ");
|
||||||
sql.append("from ");
|
sql.append(" c.caja_id as cajaId, ");
|
||||||
sql.append(" fiscal_r4 r4 ");
|
sql.append(" fi.numserie as numserie ");
|
||||||
sql.append(" left join fiscal_impressora fi on fi.NUMSERIE20 = r4.NUMSERIE20 ");
|
sql.append(" FROM ");
|
||||||
|
sql.append(" caja c ");
|
||||||
|
sql.append(" left join fiscal_r4 R4 on R4.CAJA_ID = c.CAJA_ID ");
|
||||||
|
sql.append(" inner join fiscal_impressora fi on fi.numserie = c.SERIEIMPFISCAL ");
|
||||||
sql.append(" where ");
|
sql.append(" where ");
|
||||||
sql.append(" to_date(r4.datamov, 'YYYYMMDD') = to_date(:dataIni, 'YYYY-MM-DD') ");
|
sql.append(" fi.numserie = :numserie ");
|
||||||
sql.append(" and fi.numserie20 = :numserie20 ");
|
sql.append(" and trunc(c.FECCREACION) >= :data ");
|
||||||
sql.append(" order by r4.coo ");
|
sql.append(" and c.ccf >= :ccfInicial ");
|
||||||
|
sql.append(" and fi.activo = 1 ");
|
||||||
|
sql.append(" and c.activo = 1 ");
|
||||||
|
sql.append(" and ((c.indreimpresion = 0) or (c.indreimpresion = 1 and c.indstatusboleto in ('E')) or (c.indreimpresion = 1 and c.motivocancelacion_id =(select motivocancelacion_id from motivo_cancelacion where cvesistema = 'CANCELAMENTO_ECF') and c.ccf is not null)) ");
|
||||||
|
sql.append(" and c.ccf is not null ");
|
||||||
|
sql.append(" and r4.fiscalr4_id is not null ");
|
||||||
|
sql.append(" order by c.ccf ");
|
||||||
|
|
||||||
return sql.toString();
|
return sql.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSQLR2(){
|
private String getSqlImpressorasComCCFInicial(){
|
||||||
StringBuilder sql = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(" select ");
|
||||||
sql.append(" select ");
|
sb.append(" SERIEIMPFISCAL, ");
|
||||||
sql.append(" coalesce(to_number((select r22.ccf from fiscal_r2 r22 where r22.numserie20 = r2.numserie20 and to_number(r22.crz, '999999999') = to_number(r2.crz, '999999999') -1), '999999999'), to_number(r2.ccf, '999999999')) as cooinicial, ");
|
sb.append(" max(ccf) ");
|
||||||
sql.append(" r2.ccf as coofinal, ");
|
sb.append(" from ");
|
||||||
sql.append(" fi.numserie20, ");
|
sb.append(" caja ");
|
||||||
sql.append(" fie.estado_id, ");
|
sb.append(" where ");
|
||||||
sql.append(" fi.empresa_id, ");
|
sb.append(" feccreacion <= :dataMenos2 ");
|
||||||
sql.append(" fi.puntoventa_id, ");
|
sb.append(" and SERIEIMPFISCAL in (select distinct c2.SERIEIMPFISCAL ");
|
||||||
sql.append(" fi.fiscalimpressora_id ");
|
sb.append(" from caja c2 where trunc(c2.FECCREACION) = :dataMenos1) ");
|
||||||
sql.append("from fiscal_r2 r2 ");
|
sb.append(" group by SERIEIMPFISCAL ");
|
||||||
sql.append(" left join fiscal_impressora fi on fi.NUMSERIE20 = r2.NUMSERIE20 ");
|
return sb.toString();
|
||||||
sql.append(" left join fiscal_impressora_estado fie on fie.fiscalimpressora_id = fi.fiscalimpressora_id ");
|
|
||||||
sql.append("where ");
|
|
||||||
sql.append(" r2.datamov = :datamov ");
|
|
||||||
sql.append("order by datamov; ");
|
|
||||||
|
|
||||||
return sql.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MonitoramentoCCFR2> buscaRegistrosR2(Date data){
|
@Override
|
||||||
List<MonitoramentoCCFR2> result = new ArrayList<MonitoramentoCCFR2>();
|
public Map<String, Integer> obterImpressorasComCCFInicial(Date data){
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
Map<String, Integer> impressoras = new HashMap<String, Integer>();
|
||||||
|
NamedParameterStatement stmt = null;
|
||||||
|
ResultSet rset = null;
|
||||||
try{
|
try{
|
||||||
NamedParameterStatement stmt = new NamedParameterStatement(getSession().connection(), getSQLR2());
|
final Calendar c = Calendar.getInstance();
|
||||||
stmt.setString("datamov", sdf.format(data.getTime()));
|
c.setTime(data);
|
||||||
|
c.add(Calendar.DAY_OF_MONTH, -1);
|
||||||
|
stmt = new NamedParameterStatement(con, getSqlImpressorasComCCFInicial());
|
||||||
|
stmt.setDate("dataMenos2", new java.sql.Date(c.getTime().getTime()));
|
||||||
|
stmt.setDate("dataMenos1", new java.sql.Date(data.getTime()));
|
||||||
|
|
||||||
ResultSet rset = stmt.executeQuery();
|
rset = stmt.executeQuery();
|
||||||
|
|
||||||
while (rset.next()) {
|
while (rset.next()) {
|
||||||
MonitoramentoCCFR2 m = new MonitoramentoCCFR2();
|
impressoras.put(rset.getString(1), rset.getInt(2));
|
||||||
m.cooinicio = rset.getInt(1);
|
|
||||||
m.coofim = rset.getInt(2);
|
|
||||||
m.numserie20 = rset.getString(3);
|
|
||||||
m.estadoId = rset.getInt(4);
|
|
||||||
m.empresaId = rset.getInt(5);
|
|
||||||
m.puntoventaId = rset.getInt(6);
|
|
||||||
m.fiscalImpressoraId = rset.getInt(7);
|
|
||||||
result.add(m);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
Log.error("", e);
|
log.error("", e);
|
||||||
|
} finally {
|
||||||
|
if(stmt != null) {
|
||||||
|
try { stmt.close(); } catch (SQLException e) { log.error("", e); }
|
||||||
}
|
}
|
||||||
return result;
|
if(rset != null) {
|
||||||
|
try { rset.close(); } catch (SQLException e) { log.error("", e); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return impressoras;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MonitoramentoCCF> buscaQuebraCCF(String numserie20, Date data){
|
public List<MonitoramentoCCF> buscaQuebraCCF(final String numserie, final Date data, final Integer ccfInicial){
|
||||||
List<MonitoramentoCCF> result = new ArrayList<MonitoramentoCCF>();
|
final List<MonitoramentoCCF> result = new ArrayList<MonitoramentoCCF>();
|
||||||
|
|
||||||
|
NamedParameterStatement stmt = null;
|
||||||
|
ResultSet rset = null;
|
||||||
try{
|
try{
|
||||||
NamedParameterStatement stmt = new NamedParameterStatement(getSession().connection(), getSQL());
|
stmt = new NamedParameterStatement(con, getSQL());
|
||||||
stmt.setDate("dataIni", new java.sql.Date(data.getTime()));
|
stmt.setString("numserie", numserie);
|
||||||
stmt.setString("numserie20", numserie20);
|
stmt.setDate("data", new java.sql.Date(data.getTime()));
|
||||||
|
stmt.setInt("ccfInicial", ccfInicial);
|
||||||
|
|
||||||
ResultSet rset = stmt.executeQuery();
|
rset = stmt.executeQuery();
|
||||||
|
|
||||||
while (rset.next()) {
|
while (rset.next()) {
|
||||||
|
Integer empresaId = rset.getInt("empresa");
|
||||||
|
Integer estadoId = rset.getInt("estado");
|
||||||
|
Date dataMov = rset.getDate("datamov");
|
||||||
|
FiscalImpressora fiscalImpressora = new FiscalImpressora(rset.getInt("fiscalimpressora_id"));
|
||||||
|
Empresa empresa = empresaId != null && empresaId != 0 ? new Empresa(empresaId) : null;
|
||||||
|
Estado estado = estadoId != null && estadoId != 0 ? new Estado(estadoId) : null;
|
||||||
|
PuntoVenta puntoVenta = new PuntoVenta(rset.getInt("puntoventa_id"));
|
||||||
|
Usuario usuario = new Usuario(rset.getInt("usuario_id"));
|
||||||
|
Integer ccf = rset.getInt("ccf");
|
||||||
|
Integer ccf2 = null;
|
||||||
|
|
||||||
|
if (rset.next()){
|
||||||
|
ccf2 = rset.getInt("ccf");
|
||||||
|
Date aux = dataMov;
|
||||||
|
if (ccf2 - ccf > 1){
|
||||||
|
for (int i = ccf +1; i < ccf2; i++){
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.setTime(aux);
|
||||||
|
c.add(Calendar.DATE, +1);
|
||||||
|
aux = c.getTime();
|
||||||
|
|
||||||
MonitoramentoCCF m = new MonitoramentoCCF();
|
MonitoramentoCCF m = new MonitoramentoCCF();
|
||||||
m.setDataMonitoramento(new Date());
|
m.setDataMonitoramento(new Date());
|
||||||
m.setDataOcorrencia(rset.getDate("datamov"));
|
m.setDataOcorrencia(dataMov);
|
||||||
m.setDiasAlertaAberto(new Date());
|
m.setDiasAlertaAberto(new Date());
|
||||||
m.setImpressora(new FiscalImpressora(rset.getInt("fiscalimpressora_id")));
|
m.setImpressora(fiscalImpressora);
|
||||||
m.setEmpresa(new Empresa(rset.getInt("empresa")));
|
m.setEmpresa(empresa);
|
||||||
m.setEstadoInstalacao(new Estado(rset.getInt("estado")));
|
m.setEstadoInstalacao(estado);
|
||||||
m.setPuntoventa(new PuntoVenta(rset.getInt("puntoventa")));
|
m.setPuntoventa(puntoVenta);
|
||||||
m.setSequenciaCCFQuebrada(rset.getInt("coo"));
|
m.setSequenciaCCFQuebrada(i);
|
||||||
m.setUsuario(new Usuario(rset.getInt("usuario_id")));
|
m.setUsuario(usuario);
|
||||||
|
|
||||||
result.add(m);
|
result.add(m);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
Log.error("", e);
|
log.error("", e);
|
||||||
|
} finally {
|
||||||
|
if(stmt != null) {
|
||||||
|
try { stmt.close(); } catch (SQLException e) { log.error("", e); }
|
||||||
|
}
|
||||||
|
if(rset != null) {
|
||||||
|
try { rset.close(); } catch (SQLException e) { log.error("", e); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<MonitoramentoCCF> obtenerTodos(){
|
||||||
|
StringBuilder hql = new StringBuilder();
|
||||||
|
hql.append("SELECT m FROM MonitoramentoCCF m ");
|
||||||
|
hql.append("left join m.empresa ");
|
||||||
|
hql.append("ORDER BY m.sequenciaCCFQuebrada ");
|
||||||
|
Query query = getSession().createQuery(hql.toString());
|
||||||
|
|
||||||
|
return query.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getMonitoramentoCCFSQL(){
|
||||||
|
StringBuilder sql = new StringBuilder();
|
||||||
|
|
||||||
|
sql.append(" select count(*) ");
|
||||||
|
sql.append(" from monitoramento_ccf ");
|
||||||
|
sql.append(" where SEQUENCIA_CCF_QUEBRADA = :seq and fiscalimpressora_id = :fiscalimpressoraId ");
|
||||||
|
|
||||||
|
return sql.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MonitoramentoCCF suscribir(final MonitoramentoCCF entity){
|
||||||
|
jaexiste = false;
|
||||||
|
try{
|
||||||
|
getSession().doWork(new Work() {
|
||||||
|
public void execute(Connection connection) throws SQLException
|
||||||
|
{
|
||||||
|
NamedParameterStatement stmt = null;
|
||||||
|
ResultSet rset = null;
|
||||||
|
try{
|
||||||
|
log.debug("salvando ccf " + entity.getSequenciaCCFQuebrada() + " para impressora " + entity.getImpressora().getFiscalimpressoraId());
|
||||||
|
stmt = new NamedParameterStatement(connection, getMonitoramentoCCFSQL());
|
||||||
|
stmt.setInt("seq", entity.getSequenciaCCFQuebrada());
|
||||||
|
stmt.setInt("fiscalimpressoraId", entity.getImpressora().getFiscalimpressoraId());
|
||||||
|
rset = stmt.executeQuery();
|
||||||
|
if (rset.next()){
|
||||||
|
if (rset.getInt(1) > 0){
|
||||||
|
jaexiste = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if(stmt != null) {
|
||||||
|
stmt.close();
|
||||||
|
}
|
||||||
|
if(rset != null) {
|
||||||
|
rset.close();
|
||||||
|
}
|
||||||
|
if(connection != null) {
|
||||||
|
//connection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!jaexiste) {
|
||||||
|
return super.suscribir(entity);
|
||||||
|
} else {
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
} catch (Exception e){
|
||||||
|
log.error("", e);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setConnection(Connection con) {
|
||||||
|
this.con = con;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
package com.rjconsultores.ventaboletos.dao.hibernate;
|
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.hibernate.Query;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.jfree.util.Log;
|
import org.hibernate.jdbc.Work;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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;
|
||||||
|
@ -15,6 +22,7 @@ import com.rjconsultores.ventaboletos.dao.MonitoramentoCRZDAO;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Estado;
|
import com.rjconsultores.ventaboletos.entidad.Estado;
|
||||||
import com.rjconsultores.ventaboletos.entidad.FiscalImpressora;
|
import com.rjconsultores.ventaboletos.entidad.FiscalImpressora;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCCF;
|
||||||
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCRZ;
|
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCRZ;
|
||||||
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
|
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Usuario;
|
import com.rjconsultores.ventaboletos.entidad.Usuario;
|
||||||
|
@ -23,6 +31,8 @@ import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
|
||||||
@Repository("monitoramentoCRZDAO")
|
@Repository("monitoramentoCRZDAO")
|
||||||
public class MonitoramentoCRZHibernateDAO extends GenericHibernateDAO<MonitoramentoCRZ, Integer>
|
public class MonitoramentoCRZHibernateDAO extends GenericHibernateDAO<MonitoramentoCRZ, Integer>
|
||||||
implements MonitoramentoCRZDAO {
|
implements MonitoramentoCRZDAO {
|
||||||
|
private static Logger log = Logger.getLogger(MonitoramentoCRZHibernateDAO.class);
|
||||||
|
Boolean jaexiste;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public MonitoramentoCRZHibernateDAO(
|
public MonitoramentoCRZHibernateDAO(
|
||||||
|
@ -33,54 +43,202 @@ implements MonitoramentoCRZDAO {
|
||||||
private String getSQL(){
|
private String getSQL(){
|
||||||
StringBuilder sql = new StringBuilder();
|
StringBuilder sql = new StringBuilder();
|
||||||
|
|
||||||
sql.append(" select ");
|
sql.append(" SELECT ");
|
||||||
sql.append(" r2.numserie20, ");
|
sql.append(" * ");
|
||||||
sql.append(" c.serieimpfiscal, ");
|
sql.append(" FROM ");
|
||||||
sql.append(" fi.numserie, ");
|
sql.append(" (SELECT ");
|
||||||
sql.append(" fi.fiscalimpressora_id, ");
|
sql.append(" R2.crz, ");
|
||||||
sql.append(" to_date(r2.datamov, 'YYYYMMDD') as datamov, ");
|
sql.append(" R2.numserie20 AS numserie20, ");
|
||||||
sql.append(" r2.COOINICIAL, ");
|
sql.append(" fi.numserie AS numserie, ");
|
||||||
sql.append(" r2.COOFINAL, ");
|
sql.append(" fi.fiscalimpressora_id AS fiscalimpressora_id, ");
|
||||||
sql.append(" fi.estadolocal_id as estado, ");
|
sql.append(" R2.datamov AS datamov, ");
|
||||||
sql.append(" fi.empresa_id as empresa, ");
|
sql.append(" R2.COOINICIAL AS COOINICIAL, ");
|
||||||
sql.append(" r2.puntoventa_id as puntoventa, ");
|
sql.append(" R2.COOFINAL AS COOFINAL, ");
|
||||||
sql.append(" r2.CRZ as CRZ, ");
|
sql.append(" fi.estadolocal_id AS estadolocal_id, ");
|
||||||
sql.append(" r2.usuario_id as usuario_id ");
|
sql.append(" fi.empresa_id AS empresa_id, ");
|
||||||
sql.append("from ");
|
sql.append(" R2.puntoventa_id AS puntoventa_id, ");
|
||||||
sql.append(" fiscal_r2 r2 ");
|
sql.append(" R2.USUARIO_ID AS USUARIO_ID ");
|
||||||
sql.append(" left join fiscal_impressora fi on fi.NUMSERIE20 = r2.NUMSERIE20 ");
|
sql.append(" FROM ");
|
||||||
sql.append(" left join caja c on c.serieimpfiscal = fi.numserie ");
|
sql.append(" FISCAL_R2 R2 ");
|
||||||
sql.append("where ");
|
sql.append(" inner join fiscal_impressora fi on fi.numserie20 = R2.numserie20 ");
|
||||||
sql.append(" c.serieimpfiscal is null ");
|
sql.append(" WHERE R2.NUMSERIE20 = :numserie and R2.datamov != '20000000' ");
|
||||||
sql.append(" and to_date(r2.datamov, 'YYYYMMDD') = to_date(:dataIni, 'YYYY-MM-DD') ");
|
sql.append(" ORDER BY r2.crz desc) ");
|
||||||
|
sql.append(" where rownum <= 5 ");
|
||||||
|
|
||||||
return sql.toString();
|
return sql.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MonitoramentoCRZ> buscaQuebraCRZ(Date data){
|
public List<String> buscaImpressoras(){
|
||||||
List<MonitoramentoCRZ> result = new ArrayList<MonitoramentoCRZ>();
|
final List<String> result = new ArrayList<String>();
|
||||||
try{
|
try{
|
||||||
NamedParameterStatement stmt = new NamedParameterStatement(getSession().connection(), getSQL());
|
getSession().doWork(new Work() {
|
||||||
stmt.setDate("data", new java.sql.Date(data.getTime()));
|
public void execute(Connection connection) throws SQLException
|
||||||
|
{
|
||||||
|
NamedParameterStatement stmt = null;
|
||||||
|
ResultSet rset = null;
|
||||||
|
try{
|
||||||
|
stmt = new NamedParameterStatement(connection, "select distinct numserie20 from fiscal_impressora where activo = 1");
|
||||||
|
|
||||||
ResultSet rset = stmt.executeQuery();
|
rset = stmt.executeQuery();
|
||||||
|
|
||||||
while (rset.next()) {
|
while (rset.next()) {
|
||||||
MonitoramentoCRZ m = new MonitoramentoCRZ();
|
result.add(rset.getString(1));
|
||||||
m.setDataMonitoramento(new Date());
|
|
||||||
m.setDataReducaoZFaltante(rset.getDate("datamov"));
|
|
||||||
m.setDiasAlertaAberto(new Date());
|
|
||||||
m.setEmpresa(new Empresa(rset.getInt("empresa")));
|
|
||||||
m.setEstadoInstalacao(new Estado(rset.getInt("estado")));
|
|
||||||
m.setPuntoventa(new PuntoVenta(rset.getInt("puntoventa")));
|
|
||||||
m.setSequenciaCRZQuebrada(rset.getInt("CRZ"));
|
|
||||||
m.setUltimoUsuarioECF(new Usuario(rset.getInt("usuario_id")));
|
|
||||||
m.setImpressora(new FiscalImpressora(rset.getInt("fiscalimpressora_id")));
|
|
||||||
result.add(m);
|
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
if(stmt != null) {
|
||||||
|
stmt.close();
|
||||||
|
}
|
||||||
|
if(rset != null) {
|
||||||
|
rset.close();
|
||||||
|
}
|
||||||
|
if(connection != null) {
|
||||||
|
//connection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
Log.error("", e);
|
log.error("", e);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<MonitoramentoCRZ> buscaQuebraCRZ(final Date data){
|
||||||
|
final List<MonitoramentoCRZ> result = new ArrayList<MonitoramentoCRZ>();
|
||||||
|
final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
||||||
|
try{
|
||||||
|
getSession().doWork(new Work() {
|
||||||
|
public void execute(Connection connection) throws SQLException
|
||||||
|
{
|
||||||
|
NamedParameterStatement stmt = null;
|
||||||
|
ResultSet rset = null;
|
||||||
|
try{
|
||||||
|
stmt = new NamedParameterStatement(connection, getSQL());
|
||||||
|
for (String s : buscaImpressoras()){
|
||||||
|
stmt.setString("numserie", s);
|
||||||
|
rset = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (rset.next()) {
|
||||||
|
Integer empresaId = rset.getInt("empresa_id");
|
||||||
|
Integer estadoId = rset.getInt("estadolocal_id");
|
||||||
|
PuntoVenta puntoVenta = new PuntoVenta(rset.getInt("puntoventa_id"));
|
||||||
|
Usuario usuario = new Usuario(rset.getInt("usuario_id"));
|
||||||
|
FiscalImpressora fiscalImpressora = new FiscalImpressora(rset.getInt("fiscalimpressora_id"));
|
||||||
|
Integer crz = rset.getInt("CRZ");
|
||||||
|
Date dataRegistro = sdf.parse(rset.getString("datamov"));
|
||||||
|
Integer crz2 = null;
|
||||||
|
|
||||||
|
|
||||||
|
if (rset.next()){
|
||||||
|
crz2 = rset.getInt("CRZ");
|
||||||
|
Date aux = dataRegistro;
|
||||||
|
if (crz - crz2 > 1){ // crz é maior que crz2 pois esta ordenado decrescente
|
||||||
|
for (int i = crz -1; i > crz2; i--){
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.setTime(aux);
|
||||||
|
c.add(Calendar.DATE, -1);
|
||||||
|
aux = c.getTime();
|
||||||
|
|
||||||
|
MonitoramentoCRZ m = new MonitoramentoCRZ();
|
||||||
|
m.setDataMonitoramento(new Date());
|
||||||
|
m.setDataReducaoZFaltante(aux);
|
||||||
|
m.setDiasAlertaAberto(new Date());
|
||||||
|
m.setEmpresa(empresaId != null && empresaId != 0 ? new Empresa(empresaId) : null);
|
||||||
|
m.setEstadoInstalacao(estadoId != null && estadoId != 0 ? new Estado(estadoId) : null);
|
||||||
|
m.setPuntoventa(puntoVenta);
|
||||||
|
m.setSequenciaCRZQuebrada(i);
|
||||||
|
m.setUltimoUsuarioECF(usuario);
|
||||||
|
m.setImpressora(fiscalImpressora);
|
||||||
|
result.add(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (ParseException e) {
|
||||||
|
log.error("", e);
|
||||||
|
} finally {
|
||||||
|
if(stmt != null) {
|
||||||
|
stmt.close();
|
||||||
|
}
|
||||||
|
if(rset != null) {
|
||||||
|
rset.close();
|
||||||
|
}
|
||||||
|
if(connection != null) {
|
||||||
|
//connection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e){
|
||||||
|
log.error("", e);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getMonitoramentoCRZSQL(){
|
||||||
|
StringBuilder sql = new StringBuilder();
|
||||||
|
|
||||||
|
sql.append(" select count(*) ");
|
||||||
|
sql.append(" from monitoramento_crz ");
|
||||||
|
sql.append(" where SEQUENCIA_CRZ_QUEBRADA = :seq and fiscalimpressora_id = :fiscalimpressoraId ");
|
||||||
|
|
||||||
|
return sql.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MonitoramentoCRZ suscribir(final MonitoramentoCRZ entity){
|
||||||
|
jaexiste = false;
|
||||||
|
try{
|
||||||
|
getSession().doWork(new Work() {
|
||||||
|
public void execute(Connection connection) throws SQLException
|
||||||
|
{
|
||||||
|
NamedParameterStatement stmt = null;
|
||||||
|
ResultSet rset = null;
|
||||||
|
try{
|
||||||
|
log.debug("salvando crz " + entity.getSequenciaCRZQuebrada() + " para impressora " + entity.getImpressora().getFiscalimpressoraId());
|
||||||
|
stmt = new NamedParameterStatement(connection, getMonitoramentoCRZSQL());
|
||||||
|
stmt.setInt("seq", entity.getSequenciaCRZQuebrada());
|
||||||
|
stmt.setInt("fiscalimpressoraId", entity.getImpressora().getFiscalimpressoraId());
|
||||||
|
rset = stmt.executeQuery();
|
||||||
|
if (rset.next()){
|
||||||
|
if (rset.getInt(1) > 0){
|
||||||
|
jaexiste = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if(stmt != null) {
|
||||||
|
stmt.close();
|
||||||
|
}
|
||||||
|
if(rset != null) {
|
||||||
|
rset.close();
|
||||||
|
}
|
||||||
|
if(connection != null) {
|
||||||
|
//connection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!jaexiste) {
|
||||||
|
return super.suscribir(entity);
|
||||||
|
} else {
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
} catch (Exception e){
|
||||||
|
log.error("", e);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MonitoramentoCRZ> obtenerTodos(){
|
||||||
|
StringBuilder hql = new StringBuilder();
|
||||||
|
hql.append("SELECT m FROM MonitoramentoCRZ m ");
|
||||||
|
hql.append("left join m.empresa ");
|
||||||
|
hql.append("ORDER BY m.sequenciaCRZQuebrada ");
|
||||||
|
Query query = getSession().createQuery(hql.toString());
|
||||||
|
|
||||||
|
return query.list();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
package com.rjconsultores.ventaboletos.service;
|
package com.rjconsultores.ventaboletos.service;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCCF;
|
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCCF;
|
||||||
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCCFR2;
|
|
||||||
|
|
||||||
public interface MonitoramentoCCFService extends GenericService<MonitoramentoCCF, Integer> {
|
public interface MonitoramentoCCFService extends GenericService<MonitoramentoCCF, Integer> {
|
||||||
public List<MonitoramentoCCF> buscaQuebraCCF(String numserie20, Date data);
|
public List<MonitoramentoCCF> buscaQuebraCCF(final String numserie20, final Date data, final Integer ccfInicial);
|
||||||
public List<MonitoramentoCCFR2> buscaRegistrosR2(Date data);
|
public void gravarListaCCFQuebrados(Map<String, Integer> impressoras, Date data);
|
||||||
|
public Map<String, Integer> obterImpressorasComCCFInicial(Date data);
|
||||||
|
public void openConnection();
|
||||||
|
public void closeConnection();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,35 @@
|
||||||
package com.rjconsultores.ventaboletos.service.impl;
|
package com.rjconsultores.ventaboletos.service.impl;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.jfree.util.Log;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.dao.MonitoramentoCCFDAO;
|
import com.rjconsultores.ventaboletos.dao.MonitoramentoCCFDAO;
|
||||||
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCCF;
|
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCCF;
|
||||||
import com.rjconsultores.ventaboletos.entidad.MonitoramentoCCFR2;
|
|
||||||
import com.rjconsultores.ventaboletos.service.MonitoramentoCCFService;
|
import com.rjconsultores.ventaboletos.service.MonitoramentoCCFService;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||||
|
|
||||||
@Service("monitoramentoCCFService")
|
@Service("monitoramentoCCFService")
|
||||||
public class MonitoramentoCCFServiceImpl implements MonitoramentoCCFService{
|
public class MonitoramentoCCFServiceImpl implements MonitoramentoCCFService{
|
||||||
|
private static Logger log = Logger.getLogger(MonitoramentoCCFServiceImpl.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MonitoramentoCCFDAO monitoramentoCCFDAO;
|
private MonitoramentoCCFDAO monitoramentoCCFDAO;
|
||||||
|
@Autowired
|
||||||
|
private DataSource dataSource;
|
||||||
|
private Connection con;
|
||||||
|
|
||||||
public List<MonitoramentoCCF> obtenerTodos() {
|
public List<MonitoramentoCCF> obtenerTodos() {
|
||||||
return monitoramentoCCFDAO.obtenerTodos();
|
return monitoramentoCCFDAO.obtenerTodos();
|
||||||
|
@ -27,6 +39,31 @@ public class MonitoramentoCCFServiceImpl implements MonitoramentoCCFService{
|
||||||
return monitoramentoCCFDAO.obtenerID(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
|
@Transactional
|
||||||
public MonitoramentoCCF suscribir(MonitoramentoCCF entidad) {
|
public MonitoramentoCCF suscribir(MonitoramentoCCF entidad) {
|
||||||
entidad.setUsuarioModif(UsuarioLogado.getUsuarioLogado());
|
entidad.setUsuarioModif(UsuarioLogado.getUsuarioLogado());
|
||||||
|
@ -55,12 +92,23 @@ public class MonitoramentoCCFServiceImpl implements MonitoramentoCCFService{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MonitoramentoCCF> buscaQuebraCCF(String numserie20, Date data) {
|
public List<MonitoramentoCCF> buscaQuebraCCF(final String numserie20, final Date data, final Integer ccfInicial) {
|
||||||
return monitoramentoCCFDAO.buscaQuebraCCF(numserie20, data);
|
return monitoramentoCCFDAO.buscaQuebraCCF(numserie20, data, ccfInicial);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void gravarListaCCFQuebrados(Map<String, Integer> impressoras, Date data){
|
||||||
public List<MonitoramentoCCFR2> buscaRegistrosR2(Date data){
|
try {
|
||||||
return monitoramentoCCFDAO.buscaRegistrosR2(data);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jfree.util.Log;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -32,7 +33,12 @@ public class MonitoramentoCRZServiceImpl implements MonitoramentoCRZService{
|
||||||
entidad.setFecmodif(Calendar.getInstance().getTime());
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||||
entidad.setActivo(Boolean.TRUE);
|
entidad.setActivo(Boolean.TRUE);
|
||||||
|
|
||||||
|
try{
|
||||||
return monitoramentoCRZDAO.suscribir(entidad);
|
return monitoramentoCRZDAO.suscribir(entidad);
|
||||||
|
} catch (Exception e){
|
||||||
|
Log.error("", e);
|
||||||
|
return entidad;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|
Loading…
Reference in New Issue