码迷,mamicode.com
首页 > 其他好文 > 详细

liferay 高级查询 (1)

时间:2014-07-26 03:28:17      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:liferay   高级   查询   

pointExchangeLocalServiceImpl.java 加入的代码

 /**

     * 积分管理中的查询方法

     * 

     * @param searchTerms

     * @param companyId

     * @param groupId

     * @param start

     * @param end

     * @return

     * @throws SystemException

     */




    //查询PointExchange表中所有记录

    @SuppressWarnings("unchecked")

    public List<PointExchange> findPointExchanges(PointSearchTerms searchTerms, long companyId, int start, int end) throws SystemException {

        DynamicQuery dynamicQuery = getPointExchangeDynamicQuery(searchTerms, companyId);

        return dynamicQuery(dynamicQuery, start, end);

    }


    /**

     * 积分管理中查询用户总数

     * 

     * @param searchTerms

     * @param companyId

     * @param groupId

     * @return

     * @throws SystemException

     */

    public int countPointExchange(PointSearchTerms searchTerms, long companyId) throws SystemException {

        DynamicQuery dynamicQuery = getPointExchangeDynamicQuery(searchTerms, companyId);

        return ((Long) dynamicQueryCount(dynamicQuery)).intValue();

    }


    private DynamicQuery getPointExchangeDynamicQuery(PointSearchTerms searchTerms, long companyId) {

        DynamicQuery dynamicQuery = pointExchangePersistence.createDynamicQuery();

        dynamicQuery.add(PropertyFactoryUtil.forName("companyId").eq(companyId));


        if (searchTerms.isAdvancedSearch()) {  //判断是否是高级查询

            //高级查询中的条件(按什么查询)

            String realNameLike = searchTerms.getRealNameLike();  

            Date submitDate = searchTerms.getSubmitDate();

            int confirmState = searchTerms.getConfirmState();

            Junction junction = null;

            //and运算

            if (searchTerms.isAndOperator()) {

                junction = RestrictionsFactoryUtil.conjunction();//连接运算,逻辑与

            } else {

                junction = RestrictionsFactoryUtil.disjunction();//逻辑或运算

            }

            if (Validator.isNotNull(realNameLike)) {

                String realNameLikeSql = DAOUtil.getLike(realNameLike); 

                junction.add(PropertyFactoryUtil.forName("realName").like(realNameLikeSql));//模糊查询

            }

            if (Validator.isNotNull(submitDate)) {

                Calendar cal = Calendar.getInstance();

                cal.setTime(submitDate);

                cal.add(Calendar.DATE, 1);

                Junction dateJunction = RestrictionsFactoryUtil.conjunction();

               //大于等于运算符ge,lt小于运算符,eq等于运算符

                dateJunction.add(PropertyFactoryUtil.forName("submitDate").ge(submitDate));

                dateJunction.add(PropertyFactoryUtil.forName("submitDate").lt(cal.getTime()));

                junction.add(dateJunction);

            }

            if (confirmState != -1) {

                junction.add(PropertyFactoryUtil.forName("confirmState").eq(confirmState));

            }

            dynamicQuery.add(junction);

        } else {

            String keywords = searchTerms.getKeywords(); //关键词搜索

            String realNameLike = keywords;

            if (Validator.isNotNull(realNameLike)) {

                String realNameLikeSql = DAOUtil.getLike(realNameLike);

                dynamicQuery.add(PropertyFactoryUtil.forName("realName").like(realNameLikeSql));

            }

        }


        return dynamicQuery;

    }


本文出自 “hexun.com” 博客,请务必保留此出处http://551735.blog.51cto.com/541735/1529969

liferay 高级查询 (1),布布扣,bubuko.com

liferay 高级查询 (1)

标签:liferay   高级   查询   

原文地址:http://551735.blog.51cto.com/541735/1529969

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!