Commit 58284cd7 by Tuomas Riihimäki

Merge branch 'placecount-fix' into 'master'

Placecount fix

Ny laskee oikein paikkamäärät.

Muutettu logiikka niin, että hakee kartasta vapaat paikat, ja vähentää tästä käyttämättömien placeslottien määrän.

See merge request !144
2 parents 739bbb2b 4f4df5f6
......@@ -260,7 +260,7 @@ public class PlaceBean implements PlaceBeanLocal {
logger.warn("Reserving place {} with placeslot {}", place, slot);
slot.setPlace(place);
slot.setUsed(new Date());
} else {
} else if(!permbean.hasPermission(MapPermission.MANAGE_OTHERS)) { // we still can reserve places to other people
logger.warn("Not enough slots to reserve place {}", place);
// Not enough slots to reserve place
return false;
......
......@@ -215,10 +215,12 @@ public class ProductBean implements ProductBeanLocal {
if (!prod.getProductFlags().contains(ProductFlag.PREPAID_CREDIT))
{
if (prod.getPlaces() != null && !prod.getPlaces().isEmpty()) {
int totalcount = prod.getPlaces().size();
Long boughtSlots = slotfacade.totalSlotcount(prod);
int freeCount = totalcount - boughtSlots.intValue();
logger.info("Prodlimit totcnt {}, bought {}, free {}, prod {}", totalcount, boughtSlots, freeCount, prod);
Long selectableCount = placeFacade.countSelectable(prod);
Long unusedSlots = slotfacade.findUnusedSlotsCount(prod);
int freeCount = selectableCount.intValue() - unusedSlots.intValue();
logger.info("Prodlimit selectable {}, unused {}, free {}, prod {}", selectableCount, unusedSlots, freeCount, prod);
ret.put(prod.getId(), BigDecimal.valueOf(freeCount));
}
}
......
......@@ -158,6 +158,22 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
return getEm().createQuery(cq).getResultList();
}
public Long countSelectable(Product product) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Place> root = cq.from(Place.class);
cq.select(cb.count(root));
cq.where(
cb.equal(root.get(Place_.product), product),
cb.isNull(root.get(Place_.releaseTime)),
cb.isNull(root.get(Place_.group)),
cb.isFalse(root.get(Place_.disabled))
);
return super.getSingleNullableResult(getEm().createQuery(cq));
}
public Long findCountForProduct(Product product) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
......@@ -171,6 +187,10 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
return super.getSingleNullableResult(getEm().createQuery(cq));
}
public Long countAvailable(EventMap map) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
......
......@@ -92,6 +92,27 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
return slot;
}
public Long findUnusedSlotsCount(Product prod) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> q = cb.createQuery(Long.class);
Root<PlaceSlot> root = q.from(PlaceSlot.class);
q.select(cb.count(root));
Path<Bill> bill = root.get(PlaceSlot_.bill);
Path<Calendar> billexp = bill.get(Bill_.expires);
q.where(cb.equal(root.get(PlaceSlot_.product), prod),
cb.or(cb.isNull(billexp),
cb.greaterThan(billexp, Calendar.getInstance())
),
cb.isNull(root.get(PlaceSlot_.place))
);
Long count = super.getSingleNullableResult(getEm().createQuery(q));
return count;
}
public Long totalSlotcount(Product prod) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> q = cb.createQuery(Long.class);
......
......@@ -178,6 +178,8 @@ public class PlaceView extends GenericCDIView {
place = p;
}
}
} else {
super.addFaceMessage("Cannot reserve place for user");
}
} catch (BortalCatchableException e) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!