- ajuste: validação de traslapa no pricing ocupação

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@32129 d1611594-4594-4d17-8e1d-87c2c4800839
master
gleimar 2013-11-20 17:34:55 +00:00
parent 7ce6de0cf9
commit 010293e6fa
5 changed files with 75 additions and 32 deletions

View File

@ -6,7 +6,6 @@ package com.rjconsultores.ventaboletos.dao;
import java.util.List; import java.util.List;
import com.rjconsultores.ventaboletos.entidad.Pricing;
import com.rjconsultores.ventaboletos.entidad.PricingOcupaAntecipa; import com.rjconsultores.ventaboletos.entidad.PricingOcupaAntecipa;
/** /**
@ -15,5 +14,6 @@ import com.rjconsultores.ventaboletos.entidad.PricingOcupaAntecipa;
*/ */
public interface PricingOcupaAntecipaDAO extends GenericDAO<PricingOcupaAntecipa, Integer> { public interface PricingOcupaAntecipaDAO extends GenericDAO<PricingOcupaAntecipa, Integer> {
public List<PricingOcupaAntecipa> podeSalvar(Pricing pricing);
public List<PricingOcupaAntecipa> buscarOcupaAntecipaPricing(Integer pricingId);
} }

View File

@ -38,10 +38,11 @@ public class PricingOcupaAntecipaHibernateDAO extends GenericHibernateDAO<Pricin
} }
@Override @Override
public List<PricingOcupaAntecipa> podeSalvar(Pricing pricing) { public List<PricingOcupaAntecipa> buscarOcupaAntecipaPricing(Integer pricingId) {
Criteria c = getSession().createCriteria(getPersistentClass()); Criteria c = getSession().createCriteria(getPersistentClass());
c.add(Restrictions.eq("activo", Pricing.ATIVO)); c.add(Restrictions.eq("activo", Pricing.ATIVO));
c.add(Restrictions.eq("pricing", pricing)); c.add(Restrictions.eq("pricing.pricingId", pricingId));
return c.list(); return c.list();
} }
} }

View File

@ -1,11 +1,13 @@
package com.rjconsultores.ventaboletos.service; package com.rjconsultores.ventaboletos.service;
import java.util.List;
import com.rjconsultores.ventaboletos.entidad.Pricing;
import com.rjconsultores.ventaboletos.entidad.PricingOcupaAntecipa; import com.rjconsultores.ventaboletos.entidad.PricingOcupaAntecipa;
import com.rjconsultores.ventaboletos.exception.BusinessException;
public interface PricingOcupaAntecipaService extends GenericService<PricingOcupaAntecipa, Integer> { public interface PricingOcupaAntecipaService {
public List<PricingOcupaAntecipa> obtenerPorPricing(Pricing pricing); public PricingOcupaAntecipa suscribir(PricingOcupaAntecipa entidad) throws BusinessException;
public PricingOcupaAntecipa actualizacion(PricingOcupaAntecipa entidad) throws BusinessException;
public void borrar(PricingOcupaAntecipa entidad);
} }

View File

@ -3,6 +3,9 @@ package com.rjconsultores.ventaboletos.service.impl;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import org.jfree.util.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
@ -10,25 +13,24 @@ import org.springframework.transaction.annotation.Transactional;
import com.rjconsultores.ventaboletos.dao.PricingOcupaAntecipaDAO; import com.rjconsultores.ventaboletos.dao.PricingOcupaAntecipaDAO;
import com.rjconsultores.ventaboletos.entidad.Pricing; import com.rjconsultores.ventaboletos.entidad.Pricing;
import com.rjconsultores.ventaboletos.entidad.PricingOcupaAntecipa; import com.rjconsultores.ventaboletos.entidad.PricingOcupaAntecipa;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.service.PricingOcupaAntecipaService; import com.rjconsultores.ventaboletos.service.PricingOcupaAntecipaService;
import com.rjconsultores.ventaboletos.utilerias.TraslaparUtil;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
@Service("pricingOcupacionService") @Service("pricingOcupacionService")
public class PricingOcupaAntecipaServiceImpl implements PricingOcupaAntecipaService { public class PricingOcupaAntecipaServiceImpl implements PricingOcupaAntecipaService {
private static final Logger log = LoggerFactory.getLogger(PricingOcupaAntecipaServiceImpl.class);
@Autowired @Autowired
private PricingOcupaAntecipaDAO pricingOcupacionDAO; private PricingOcupaAntecipaDAO pricingOcupacionDAO;
public List<PricingOcupaAntecipa> obtenerTodos() {
return pricingOcupacionDAO.obtenerTodos();
}
public PricingOcupaAntecipa obtenerID(Integer id) {
return pricingOcupacionDAO.obtenerID(id);
}
@Transactional @Transactional
public PricingOcupaAntecipa suscribir(PricingOcupaAntecipa entidad) { public PricingOcupaAntecipa suscribir(PricingOcupaAntecipa entidad) throws BusinessException {
if (traslapa(entidad)) {
throw new BusinessException("PricingOcupaAntecipaServiceImpl.msg.traslapa");
}
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
entidad.setFecmodif(Calendar.getInstance().getTime()); entidad.setFecmodif(Calendar.getInstance().getTime());
entidad.setActivo(Pricing.ATIVO); entidad.setActivo(Pricing.ATIVO);
@ -36,8 +38,11 @@ public class PricingOcupaAntecipaServiceImpl implements PricingOcupaAntecipaServ
return pricingOcupacionDAO.suscribir(entidad); return pricingOcupacionDAO.suscribir(entidad);
} }
@Transactional @Transactional(rollbackFor = BusinessException.class)
public PricingOcupaAntecipa actualizacion(PricingOcupaAntecipa entidad) { public PricingOcupaAntecipa actualizacion(PricingOcupaAntecipa entidad) throws BusinessException {
if (traslapa(entidad)) {
throw new BusinessException("PricingOcupaAntecipaServiceImpl.msg.traslapa");
}
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
entidad.setFecmodif(Calendar.getInstance().getTime()); entidad.setFecmodif(Calendar.getInstance().getTime());
entidad.setActivo(Pricing.ATIVO); entidad.setActivo(Pricing.ATIVO);
@ -54,8 +59,48 @@ public class PricingOcupaAntecipaServiceImpl implements PricingOcupaAntecipaServ
pricingOcupacionDAO.actualizacion(entidad); pricingOcupacionDAO.actualizacion(entidad);
} }
@Override private boolean traslapa(PricingOcupaAntecipa pricingOcupaAntecipa) {
public List<PricingOcupaAntecipa> obtenerPorPricing(Pricing pricing) { boolean traslapa = false;
return pricingOcupacionDAO.podeSalvar(pricing); List<PricingOcupaAntecipa> lsSalvos = pricingOcupacionDAO.buscarOcupaAntecipaPricing(pricingOcupaAntecipa.getPricing().getPricingId());
// removo o pricing que eu estou validando
lsSalvos.remove(pricingOcupaAntecipa);
Integer cantasientosmin = pricingOcupaAntecipa.getCantasientosmin();
Integer cantasientosmax = pricingOcupaAntecipa.getCantasientosmax();
boolean validaCantAsientos = ((cantasientosmin != null) && (cantasientosmax != null));
Integer cantdiasmin = pricingOcupaAntecipa.getCantdiasmin();
Integer cantdiasmax = pricingOcupaAntecipa.getCantdiasmax();
boolean validaCantDias = ((cantdiasmin != null) && (cantdiasmax != null));
for (PricingOcupaAntecipa poa : lsSalvos) {
boolean traslapaCantAsiento = false;
if (validaCantAsientos) {
if ((poa.getCantasientosmin() != null) && (poa.getCantasientosmax() != null)) {
traslapaCantAsiento = TraslaparUtil.intersectNum(poa.getCantasientosmin(), poa.getCantasientosmax(), cantasientosmin, cantasientosmax);
}
}
boolean traslapaCantDias = false;
if (validaCantDias) {
if ((poa.getCantdiasmin() != null) && (poa.getCantdiasmax() != null)) {
traslapaCantDias = TraslaparUtil.intersectNum(poa.getCantdiasmin(), poa.getCantdiasmax(), cantdiasmin, cantdiasmax);
}
}
if (traslapaCantAsiento || traslapaCantDias) {
log.info("registro que traslapa PricingOcupaAntecipa id =" + poa.getPricingocupaantecipaId());
traslapa = true;
break;
}
}
return traslapa;
} }
} }

View File

@ -54,14 +54,9 @@ public class TraslaparUtil {
return false; return false;
} }
public static boolean intersectNum(BigDecimal numStart, BigDecimal numEnd, BigDecimal numStartCompare, BigDecimal numEndCompare) { public static boolean intersectNum(BigDecimal numStart, BigDecimal numEnd, BigDecimal numStartCompare, BigDecimal numEndCompare) {
if (((numStart.compareTo(numStartCompare) >= 0) && (numEnd.compareTo(numEndCompare) <= 0)) return intersectNum(numStart.longValue(), numEnd.longValue(), numStartCompare.longValue(), numEndCompare.longValue());
|| ((numEnd.compareTo(numStartCompare) >= 0) && (numEnd.compareTo(numEndCompare) <= 0))
|| ((numStart.compareTo(numStartCompare) >= 0) && (numStart.compareTo(numEndCompare) <= 0))
|| ((numStart.compareTo(numStartCompare) <= 0) && (numEnd.compareTo(numEndCompare) >= 0))) {
return true;
} }
public static boolean intersectNum(Integer numStart, Integer numEnd, Integer numStartCompare, Integer numEndCompare) {
return false; return intersectNum(numStart.longValue(), numEnd.longValue(), numStartCompare.longValue(), numEndCompare.longValue());
} }
} }