Example usage for org.hibernate.criterion DetachedCriteria add

List of usage examples for org.hibernate.criterion DetachedCriteria add

Introduction

In this page you can find the example usage for org.hibernate.criterion DetachedCriteria add.

Prototype

public DetachedCriteria add(Criterion criterion) 

Source Link

Document

Add a restriction

Usage

From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java

/**
 * ??// w w w  .j a v a  2s  . c  om
 * 
 * @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 va 2s .c om*/
 * 
 * @param dateStar
 *            
 * @param dateEnd
 *            ?
 * @param dateMin
 *            ??action
 * @return ???
 */
public void oprIssueTime(Date dateStar, Date dateEnd, Integer dateMin) {
    if (null == dateStar)
        throw new ServiceException("");
    if (null == dateEnd)
        throw new ServiceException("?");
    if (null == dateMin)
        throw new ServiceException("?.");
    Class<S> clazz = ReflectionUtils.getSuperClassGenricType(getClass(), 0);
    DetachedCriteria criteria = DetachedCriteria.forClass(clazz);
    criteria.add(Restrictions.ge("endedTime", dateStar));
    criteria.add(Restrictions.le("endedTime", dateEnd));
    criteria.addOrder(Order.asc("endedTime"));
    List<I> resultList = schemeDao.findByDetachedCriteria(criteria, true);
    if (resultList != null && resultList.size() > 0) {
        for (I issue : resultList) {
            issue.setStartTime(DateUtils.addMinutes(issue.getStartTime(), dateMin));
            issue.setEndedTime(DateUtils.addMinutes(issue.getEndedTime(), dateMin));
            issue.setPrizeTime(DateUtils.addMinutes(issue.getPrizeTime(), dateMin));
        }
    } else {
        if (null == dateMin)
            throw new ServiceException("?.");
    }
}

From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java

/**
 * /*from w ww.  j a v a 2  s .co  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.cai310.lottery.web.controller.lottery.keno.KenoController.java

/**
 * ?/*from  w  w  w .j  a  v a2 s.  c  o m*/
 * 
 * @return
 */
public String result() {
    try {
        Class<I> cls = kenoService.getIssueDataClass();
        DetachedCriteria criteria = DetachedCriteria.forClass(cls);
        criteria.add(Restrictions.isNotNull("results"));
        if (StringUtils.isBlank(resultDate)) {
            resultDate = DateUtil.getTodaySixStr();
        }
        criteria.add(Restrictions.gt("prizeTime", DateUtil.getTodaySixDate(resultDate)));
        criteria.add(
                Restrictions.lt("prizeTime", DateUtil.getNextdaySixDate(DateUtil.getTodaySixDate(resultDate))));
        criteria.addOrder(Order.desc("id"));
        periods = kenoService.findKenoPeriodByCriteria(criteria, null);
        resultDates = DateUtil.getSixList();
        return "result-info";
    } catch (ServiceException e) {
        addActionMessage(e.getMessage());
    } catch (Exception e) {
        addActionMessage(e.getMessage());
        logger.warn(e.getMessage(), e);
    }

    return error();
}

From source file:com.cai310.lottery.web.controller.lottery.NumberSchemeBaseController.java

protected void periodAnalyse() {
    if (null != this.period) {
        DetachedCriteria criteria = DetachedCriteria.forClass(MobileNewsData.class, "m");
        criteria.add(Restrictions.eq("m.periodId", this.period.getId()));
        criteria.add(Restrictions.eq("m.lotteryType", this.period.getLotteryType()));
        criteria.add(Restrictions.eq("m.lotteryPlayType", getLotteryPlayType()));
        criteria.add(Restrictions.eq("m.mobileInfoType", MobileInfoType.ZJJH));
        List<MobileNewsData> list = this.queryService.findByDetachedCriteria(criteria);
        for (MobileNewsData mobileNewsData : list) {
            if (null != mobileNewsData.getAnalyse()) {
                if (mobileNewsData.getAnalyse().indexOf("|") != -1) {
                    this.commonAnalyse = mobileNewsData.getAnalyse().split("\\|")[0];
                    this.analyse = mobileNewsData.getAnalyse().split("\\|")[1];
                } else {
                    this.commonAnalyse = mobileNewsData.getAnalyse();
                }/*  w ww.  j a  v  a 2s . c  om*/
            }
            if (null != mobileNewsData.getSingleAnalyse()) {
                if (mobileNewsData.getSingleAnalyse().indexOf("|") != -1) {
                    this.commonSingleAnalyse = mobileNewsData.getSingleAnalyse().split("\\|")[0];
                    this.singleAnalyse = mobileNewsData.getSingleAnalyse().split("\\|")[1];
                } else {
                    this.commonSingleAnalyse = mobileNewsData.getSingleAnalyse();
                }
            }
        }
    }
}

From source file:com.cai310.lottery.web.controller.ticket.then.KenoController.java

public String resultList() {
    Map map = Maps.newHashMap();// w  ww  .  j a  va2 s .co  m
    JsonConfig jsonConfig = new JsonConfig();
    StringBuffer sb = new StringBuffer();
    try {
        // check();
        checkTicket();
        Lottery lotteryType = null;
        if (StringUtils.isNotBlank(wLotteryId)) {
            try {
                lotteryType = Lottery.values()[Integer.valueOf(wLotteryId.trim())];
            } catch (Exception e) {
                throw new WebDataException("12-?");
            }
            if (null == lotteryType) {
                throw new WebDataException("12-?");
            }
        }
        // if (StringUtils.isBlank(start)){
        // throw new WebDataException("9-");
        // }
        // try{
        // Integer.valueOf(start);
        // } catch (Exception e) {
        // throw new WebDataException("9-");
        // }
        // if (StringUtils.isBlank(count)){
        // throw new WebDataException("10-?");
        // }
        // try{
        // Integer.valueOf(count);
        // } catch (Exception e) {
        // throw new WebDataException("10-?");
        // }
        Class<I> cls = this.kenoService.getIssueDataClass();
        DetachedCriteria criteria = DetachedCriteria.forClass(cls);
        criteria.add(Restrictions.gt("state", IssueState.ISSUE_SATE_RESULT));
        if (!"".equals(periodNumber)) {
            criteria.add(Restrictions.eq("periodNumber", periodNumber));
        }
        criteria.add(Restrictions.isNotNull("results"));
        criteria.addOrder(Order.desc("id"));
        List<I> list = null;
        if ("".equals(periodNumber)) {
            list = queryService.findByDetachedCriteria(criteria, 0, 1);
        } else {
            list = queryService.findByDetachedCriteria(criteria);
        }
        List<PeriodDataDTO> resultList = Lists.newArrayList();
        if (null != list && !list.isEmpty()) {
            for (I kenoPeriod : list) {
                if (null != kenoPeriod) {
                    PeriodDataDTO periodDataDTO = new PeriodDataDTO();
                    periodDataDTO.setLotteryType(kenoPeriod.getLotteryType());
                    periodDataDTO.setPeriodId(kenoPeriod.getId());
                    periodDataDTO.setPeriodNumber(kenoPeriod.getPeriodNumber());
                    periodDataDTO.setPeriodTitle(kenoPeriod.getLotteryType().getTitle());
                    periodDataDTO
                            .setPrizeTime(DateUtil.dateToStr(kenoPeriod.getPrizeTime(), "yyyy-MM-dd HH:mm:ss"));
                    periodDataDTO.setResult(kenoPeriod.getResults());
                    resultList.add(periodDataDTO);
                }
            }
        }
        map.put("processId", "0");

        map.put("resultList", resultList);
    } catch (WebDataException e) {
        String processId = "7";
        if (null != e.getMessage() && e.getMessage().indexOf("-") != -1) {
            String temp = e.getMessage().split("-")[0];
            try {
                processId = "" + Integer.valueOf(temp);
            } catch (Exception ex) {
            } // /
            Struts2Utils.setAttribute("errorMsg", e.getMessage());
        } else {
            Struts2Utils.setAttribute("errorMsg", "");
        }
        map.put("processId", processId);

        map.put("errorMsg", e.getMessage());
    } catch (ServiceException e) {
        logger.warn(e.getMessage(), e);
        String processId = "7";
        if (null != e.getMessage() && e.getMessage().indexOf("-") != -1) {
            String temp = e.getMessage().split("-")[0];
            try {
                processId = "" + Integer.valueOf(temp);
            } catch (Exception ex) {
            } // /
            Struts2Utils.setAttribute("errorMsg", e.getMessage());
        } else {
            Struts2Utils.setAttribute("errorMsg", "");
        }
        map.put("processId", processId);

        map.put("errorMsg", e.getMessage());
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        String processId = "7";
        if (null != e.getMessage() && e.getMessage().indexOf("-") != -1) {
            String temp = e.getMessage().split("-")[0];
            try {
                processId = "" + Integer.valueOf(temp);
            } catch (Exception ex) {
            } // /
            Struts2Utils.setAttribute("errorMsg", e.getMessage());
        } else {
            Struts2Utils.setAttribute("errorMsg", "");
        }
        map.put("processId", processId);

        map.put("errorMsg", e.getMessage());
    }
    renderJson(map, jsonConfig);
    return null;
}

From source file:com.callcenter.controller.command.Find.java

License:Apache License

public void addSearchFilter(DetachedCriteria criteria) {
    if (type == Find.Type.ALL)
        return;/*ww  w .ja  va  2 s. c om*/
    if (type == Find.Type.INCOMING) {
        criteria.add(Restrictions.eq(Constants.CallRecord.OUTGOING_PROPERTY_NAME, false));
        return;
    }
    criteria.add(Restrictions.eq(Constants.CallRecord.OUTGOING_PROPERTY_NAME, true));
}

From source file:com.callcenter.controller.command.From.java

License:Apache License

public void addSearchFilter(DetachedCriteria criteria) {
    if (type == Type.START)
        return;// ww  w . j a va 2  s .c o  m
    if (type == Type.DATE_AND_TIME) {
        criteria.add(Restrictions.ge(Constants.CallRecord.CALL_TIME_PROPERTY_NAME, dateAndTime));
        return;
    }
    if (type == Type.LAST) {
        quantum.addSearchFilter(criteria);
        return;
    }
}

From source file:com.callcenter.controller.command.Quantum.java

License:Apache License

public void addSearchFilter(DetachedCriteria criteria) {
    final Calendar calendar = Calendar.getInstance();
    calendar.add(type.getField(), value * type.getMultiplicationFactor());
    criteria.add(Restrictions.ge(Constants.CallRecord.CALL_TIME_PROPERTY_NAME, calendar));
}

From source file:com.callcenter.controller.command.Till.java

License:Apache License

public void addSearchFilter(DetachedCriteria criteria) {
    Calendar tillDate = Calendar.getInstance();
    if (type == Type.DATE_AND_TIME) {
        tillDate = dateAndTime;//from ww w.j a  v  a  2s  . co  m
    }
    criteria.add(Restrictions.le(Constants.CallRecord.CALL_TIME_PROPERTY_NAME, tillDate));
}