List of usage examples for org.hibernate.criterion DetachedCriteria setProjection
public DetachedCriteria setProjection(Projection projection)
From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java
/** * ?/*from www . j a va 2 s. c o m*/ */ @Override public void doChasePlan(long curPeriodId, Boolean iswonStop) { DetachedCriteria criteria = DetachedCriteria.forClass(ChasePlan.class); criteria.setProjection(Projections.property("id")); if (iswonStop != null) criteria.add(Restrictions.eq("wonStop", iswonStop)); criteria.add(Restrictions.eq("lotteryType", getLottery())); criteria.add(Restrictions.eq("curPeriodId", curPeriodId)); criteria.add(Restrictions.eq("state", ChaseState.RUNNING)); List<Long> list = queryService.findByDetachedCriteria(criteria); if (list != null && !list.isEmpty()) { for (Long chasePlanId : list) { this.handChasePlan(chasePlanId); } } }
From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java
/** * //from w w w .j a v a 2 s . c om * * @param periodId * @return */ @SuppressWarnings("unchecked") @Transactional(readOnly = true) public Integer calAllSchemeCount(Long periodId) { Class<S> clazz = ReflectionUtils.getSuperClassGenricType(getClass(), 1); DetachedCriteria criteria = DetachedCriteria.forClass(clazz); criteria.add(Restrictions.eq("periodId", periodId)); criteria.setProjection(Projections.rowCount()); List<Integer> resultList = schemeDao.findByDetachedCriteria(criteria); if (resultList != null && resultList.size() > 0) { return resultList.get(0); } else { return 0; } }
From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java
/** * ?//from w ww . j a v a 2s . c o m * * @param periodId * @return */ @Transactional(readOnly = true) public Integer calAllSaleCount(Long periodId) { Class<S> clazz = ReflectionUtils.getSuperClassGenricType(getClass(), 1); DetachedCriteria criteria = DetachedCriteria.forClass(clazz); criteria.add(Restrictions.eq("periodId", periodId)); criteria.add(Restrictions.eq("state", SchemeState.SUCCESS)); criteria.setProjection(Projections.sum("schemeCost")); List<Integer> resultList = schemeDao.findByDetachedCriteria(criteria); if (null != resultList && !resultList.isEmpty()) { Integer count = resultList.get(0); if (null != count) { return count.intValue(); } else { return 0; } } else { return 0; } }
From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java
/** * //from w w w .ja va 2 s .com * * @param periodId * @return */ @Transactional(readOnly = true) public Integer calAllPrizeCount(Long periodId) { Class<S> clazz = ReflectionUtils.getSuperClassGenricType(getClass(), 1); DetachedCriteria criteria = DetachedCriteria.forClass(clazz); criteria.add(Restrictions.eq("periodId", periodId)); criteria.add(Restrictions.eq("won", true)); criteria.setProjection(Projections.rowCount()); List<Integer> resultList = schemeDao.findByDetachedCriteria(criteria); if (resultList != null && resultList.size() > 0) { return resultList.get(0); } else { return 0; } }
From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java
/** * ?//from www .j a va 2 s .c o m * * @param periodId * @return */ @Transactional(readOnly = true) public Integer calSuccessSchemeCount(Long periodId) { Class<S> clazz = ReflectionUtils.getSuperClassGenricType(getClass(), 1); DetachedCriteria criteria = DetachedCriteria.forClass(clazz); criteria.add(Restrictions.eq("periodId", periodId)); criteria.add(Restrictions.eq("state", SchemeState.SUCCESS)); criteria.setProjection(Projections.rowCount()); List<Integer> resultList = schemeDao.findByDetachedCriteria(criteria); if (resultList != null && resultList.size() > 0) { return resultList.get(0); } else { return 0; } }
From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java
/** * ??/*www . j a v a 2 s .co m*/ * * @param dateNow * * @param beforeTime * ??? * @return ??? */ @Transactional(readOnly = true) public Integer getCanChaseIssueNum(Date dateNow, Integer beforeTime) { if (null == dateNow) return null; if (null == beforeTime) return null; Class<S> clazz = ReflectionUtils.getSuperClassGenricType(getClass(), 0); DetachedCriteria criteria = DetachedCriteria.forClass(clazz); criteria.add(Restrictions.not(Restrictions.eq("state", IssueState.ISSUE_SATE_FINISH))); criteria.add(Restrictions.gt("endedTime", DateUtils.addMinutes(dateNow, beforeTime))); criteria.addOrder(Order.asc("endedTime")); criteria.setProjection(Projections.rowCount()); List<Integer> resultList = schemeDao.findByDetachedCriteria(criteria, true); if (resultList != null && resultList.size() > 0) { return resultList.get(0); } else { return 0; } }
From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java
/** * // www. j a v a 2 s . c o m * * @param issueData * @throws DataException */ public void saleAnalye(I issueData) throws DataException { Class<S> clazz = ReflectionUtils.getSuperClassGenricType(getClass(), 1); DetachedCriteria criteria = DetachedCriteria.forClass(clazz); criteria.setProjection(Projections.property("id")); criteria.add(Restrictions.eq("periodId", issueData.getId())); List<Long> schemeIdList = schemeDao.findByDetachedCriteria(criteria); SaleAnalyse saleAnalyse = null; Integer playType = null; Map<String, SaleAnalyse> saleAnalyeMap = new HashMap<String, SaleAnalyse>(); S s; SdEl11to5Scheme sdEl11to5Scheme = null; SscScheme sscScheme = null; AhKuai3Scheme ahKuai3Scheme = null; XjEl11to5Scheme xjEl11to5Scheme = null; Set<Long> updateSchemeSet = Sets.newHashSet(); for (Long id : schemeIdList) { // ///keyplayType key=userId_ key=userId_0userId_1 s = getScheme(id); saleAnalyse = saleAnalyeMap.get(s.getSponsorId() + "_" + (null == playType ? "" : playType)); if (null == saleAnalyse) { saleAnalyse = new SaleAnalyse(); } updateSchemeSet.add(s.getId()); if (Lottery.SDEL11TO5.equals(s.getLotteryType())) { sdEl11to5Scheme = (SdEl11to5Scheme) s; playType = sdEl11to5Scheme.getBetType().ordinal(); } else if (Lottery.SSC.equals(s.getLotteryType())) { sscScheme = (SscScheme) s; playType = sscScheme.getBetType().ordinal(); } else if (Lottery.AHKUAI3.equals(s.getLotteryPlayType())) { ahKuai3Scheme = (AhKuai3Scheme) s; playType = ahKuai3Scheme.getBetType().ordinal(); } else if (Lottery.XJEL11TO5.equals(s.getLotteryPlayType())) { xjEl11to5Scheme = (XjEl11to5Scheme) s; playType = xjEl11to5Scheme.getBetType().ordinal(); } // // saleAnalyse.setPeriodId(issueData.getId()); saleAnalyse.setLottery(s.getLotteryType()); saleAnalyse.setPeriodNumber(issueData.getPeriodNumber()); saleAnalyse.setPlayType(playType); saleAnalyse.setUserId(s.getSponsorId()); saleAnalyse.setUserName(s.getSponsorName()); saleAnalyse.setEndedTime(issueData.getEndedTime()); saleAnalyse.setYearNum(DateUtil.getYear(issueData.getEndedTime())); saleAnalyse.setQuarterNum(DateUtil.getQuarter(issueData.getEndedTime())); saleAnalyse.setMonthNum(DateUtil.getMonth(issueData.getEndedTime())); saleAnalyse.setWeekNum(DateUtil.getWeek(issueData.getEndedTime())); saleAnalyse.setSendCurrency(Boolean.FALSE); saleAnalyse.addSchemeCount(1); saleAnalyse.addSchemeCost(s.getSchemeCost().intValue()); saleAnalyse.addSchemeWonPrize(s.getPrize()); saleAnalyse.addSubscriptionCount(1); saleAnalyse.addSubscriptionCost(new BigDecimal(s.getSchemeCost())); saleAnalyse.addSubscriptionWonPrize(s.getPrize()); if (SchemeState.SUCCESS.equals(s.getState())) { // ? saleAnalyse.addSchemeSuccessCount(1); saleAnalyse.addSchemeSuccessCost(s.getSchemeCost().intValue()); saleAnalyse.addSchemeSuccessWonPrize(s.getPrize()); saleAnalyse.addSubscriptionSuccessCount(1); saleAnalyse.addSubscriptionSuccessCost(new BigDecimal(s.getSchemeCost())); saleAnalyse.addSubscriptionSuccessWonPrize(s.getPrize()); } else if (SchemeState.CANCEL.equals(s.getState())) { // saleAnalyse.addSchemeCancelCount(1); saleAnalyse.addSchemeCancelCost(s.getSchemeCost().intValue()); saleAnalyse.addSchemeCancelWonPrize(s.getPrize()); saleAnalyse.addSubscriptionCancelCount(1); saleAnalyse.addSubscriptionCancelCost(new BigDecimal(s.getSchemeCost())); saleAnalyse.addSubscriptionCancelWonPrize(s.getPrize()); } else { // ? throw new DataException("?"); } saleAnalyeMap.put(s.getSponsorId() + "_" + (null == playType ? "" : playType), saleAnalyse); } Set<String> keySet = saleAnalyeMap.keySet(); List<SaleAnalyse> updateSaleAnalyse = Lists.newArrayList(); for (String key : keySet) { updateSaleAnalyse.add(saleAnalyeMap.get(key)); } saleAnalyseEntityManager.updateSaleAnalyse(updateSaleAnalyse, updateSchemeSet, issueData.getLotteryType()); }
From source file:com.cimmyt.model.dao.impl.AbstractDAO.java
License:Apache License
public Integer getListByFilterTotal(final T filter, final Integer id) { Integer numResults = null;/*ww w . j a v a 2 s.c om*/ numResults = this.getHibernateTemplate().execute(new HibernateCallback<Integer>() { @Override public Integer doInHibernate(Session session) throws HibernateException, SQLException { DetachedCriteria criteria = DetachedCriteria.forClass(type); buildCriteria(criteria, filter, id); criteria.setProjection(Projections.rowCount()); return (Integer) getHibernateTemplate().findByCriteria(criteria).get(0); } }); return numResults; }
From source file:com.cimmyt.model.dao.impl.AbstractDAO.java
License:Apache License
public Integer getTotalRowsByFilter(final T filter, final Integer id) { Integer resultList = this.getHibernateTemplate().execute(new HibernateCallback<Integer>() { @Override/*from ww w .j av a2 s . c o m*/ public Integer doInHibernate(Session session) throws HibernateException, SQLException { DetachedCriteria criteria = DetachedCriteria.forClass(type); buildCriteria(criteria, filter, id); criteria.setProjection(Projections.rowCount()); Object obj = getHibernateTemplate().findByCriteria(criteria).get(0); if (obj instanceof Long) return ((Long) getHibernateTemplate().findByCriteria(criteria).get(0)).intValue(); else if (obj instanceof Integer) return (Integer) getHibernateTemplate().findByCriteria(criteria).get(0); else return 0; } }); return resultList; }
From source file:com.cimmyt.model.dao.impl.AbstractDAO.java
License:Apache License
public Integer getListByFilterTotalLong(final T filter, final Integer id) { Integer numResults = null;/* w w w . j a v a 2s.co m*/ numResults = this.getHibernateTemplate().execute(new HibernateCallback<Integer>() { @Override public Integer doInHibernate(Session session) throws HibernateException, SQLException { DetachedCriteria criteria = DetachedCriteria.forClass(type); buildCriteria(criteria, filter); criteria.setProjection(Projections.rowCount()); Object obj = getHibernateTemplate().findByCriteria(criteria).get(0); if (obj instanceof Long) return ((Long) getHibernateTemplate().findByCriteria(criteria).get(0)).intValue(); else if (obj instanceof Integer) return (Integer) getHibernateTemplate().findByCriteria(criteria).get(0); else return 0; } }); return numResults; }