com.jfinal.plugin.activerecord.Page Java Examples

The following examples show how to use com.jfinal.plugin.activerecord.Page. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: _OrderController.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@AdminMenu(text = "订单管理", groupId = JPressConsts.SYSTEM_MENU_ORDER, order = 1)
public void index() {

    int todayOrderCount = orderService.queryTotayCount();
    int monthOrderCount = orderService.queryMonthCount();
    int mouthPaymentAmount = paymentService.queryMonthAmount();
    int mountOrderUserCount = orderService.queryMonthUserCount();

    setAttr("todayOrderCount", todayOrderCount);
    setAttr("monthOrderCount", monthOrderCount);
    setAttr("mouthPaymentAmount", mouthPaymentAmount);
    setAttr("mountOrderUserCount", mountOrderUserCount);

    keepPara();

    Page<UserOrder> userOrderPage = orderService.paginate(getPagePara(), 10,
            getTrimPara("productTitle"), getTrimPara("ns"));
    setAttr("page", userOrderPage);
    render("order/order_list.html");
}
 
Example #2
Source File: _PageController.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@AdminMenu(text = "页面管理", groupId = "page", order = 1)
public void index() {

    String status = getPara("status");
    String title = getPara("title");

    Page<SinglePage> page =
            StrUtil.isBlank(status)
                    ? sps._paginateWithoutTrash(getPagePara(), 10, title)
                    : sps._paginateByStatus(getPagePara(), 10, title, status);

    setAttr("page", page);

    int draftCount = sps.findCountByStatus(SinglePage.STATUS_DRAFT);
    int trashCount = sps.findCountByStatus(SinglePage.STATUS_TRASH);
    int normalCount = sps.findCountByStatus(SinglePage.STATUS_NORMAL);

    setAttr("draftCount", draftCount);
    setAttr("trashCount", trashCount);
    setAttr("normalCount", normalCount);
    setAttr("totalCount", draftCount + trashCount + normalCount);

    render("page/page_list.html");
}
 
Example #3
Source File: ArticleCommentServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Page<ArticleComment> _paginateWithoutTrash(int page, int pagesize, Long articleId, String keyword) {

    Columns columns = Columns.create("article_id", articleId)
            .ne("status", ArticleComment.STATUS_TRASH)
            .likeAppendPercent("content", keyword);

    Page<ArticleComment> p = DAO.paginateByColumns(
            page,
            pagesize,
            columns,
            "id desc");


    userService.join(p, "user_id");
    articleService.join(p, "article_id");
    return p;
}
 
Example #4
Source File: SinglePageCommentServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Page<SinglePageComment> paginateByPageIdInNormal(int page, int pagesize, long pageId) {
    Columns columns = Columns.create("page_id", pageId);
    columns.add("status", SinglePageComment.STATUS_NORMAL);


    Page<SinglePageComment> p = DAO.paginateByColumns(
            page,
            pagesize,
            columns,
            "id desc");

    join(p, "pid", "parent");
    joinParentUser(p);
    userService.join(p, "user_id");

    return p;
}
 
Example #5
Source File: SinglePageCommentServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Page<SinglePageComment> _paginateWithoutTrash(int page, int pagesize, Long articleId, String keyword) {
    Columns columns = Columns.create("article_id", articleId)
            .ne("status", SinglePageComment.STATUS_TRASH)
            .likeAppendPercent("content", keyword);

    Page<SinglePageComment> p = DAO.paginateByColumns(
            page,
            pagesize,
            columns,
            "id desc");


    userService.join(p, "user_id");
    pageService.join(p, "page_id", "page");
    return p;
}
 
Example #6
Source File: UserServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Page<User> _paginate(int page, int pagesize, Columns columns, Long memberGroupId, String tag) {

    StringBuilder sqlBuilder = new StringBuilder("from `user` u ");

    if (memberGroupId != null) {
        sqlBuilder.append(" left join member m on u.id = m.user_id ");
        columns.add("m.group_id", memberGroupId);
    }


    if (StrUtil.isNotBlank(tag)) {
        UserTag userTag = tagService.findFirstByTag(tag);
        if (userTag == null) {
            return null;
        }
        sqlBuilder.append("left join user_tag_mapping utm on u.id = utm.user_id");
        columns.add("utm.tag_id", userTag.getId());
    }

    sqlBuilder.append(SqlUtils.toWhereSql(columns));
    sqlBuilder.append(" order by u.id desc");

    return DAO.paginate(page, pagesize, "select u.*  ", sqlBuilder.toString(), columns.getValueArray());
}
 
Example #7
Source File: CartController.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 购物车
 */
public void index() {
    Page<UserCart> page = cartService.paginateByUser(1, 20, getLoginedUser().getId());


    if (page != null && page.getList() != null) {
        for (UserCart userCart : page.getList()) {
            userCart.put("optionsMap", ProductManager.me().renderProductOptions(userCart));
        }
    }

    setAttr("page", page);
    setAttr("selectItemCount", cartService.querySelectedCount(getLoginedUser().getId()));

    List<UserCart> selectedUserCarts = cartService.findSelectedListByUserId(getLoginedUser().getId());
    if (selectedUserCarts != null) {
        BigDecimal totalPrice = new BigDecimal(0);
        for (UserCart cart : selectedUserCarts) {
            totalPrice = totalPrice.add(cart.getShouldPayPrice());
        }
        setAttr("selectItemTotalPrice", totalPrice);
    }


    render("cart.html");
}
 
Example #8
Source File: ArticlePageDirective.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {

    Controller controller = JbootControllerContext.get();

    int page = controller.getParaToInt(1, 1);
    int pageSize = getParaToInt("pageSize", scope, 10);
    String orderBy = getPara("orderBy", scope, "id desc");

    // 可以指定当前的分类ID
    Long categoryId = getParaToLong("categoryId", scope, 0L);
    ArticleCategory category = controller.getAttr("category");

    if (categoryId == 0 && category != null) {
        categoryId = category.getId();
    }

    Page<Article> articlePage = categoryId == 0
            ? service.paginateInNormal(page, pageSize, orderBy)
            : service.paginateByCategoryIdInNormal(page, pageSize, categoryId, orderBy);

    scope.setGlobal("articlePage", articlePage);
    renderBody(env, scope, writer);
}
 
Example #9
Source File: SysMenuController.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 菜单相关角色数据
 */
@Before(SearchSql.class)
public void queryMenuRole() {
    int pageNumber = getAttr("pageNumber");
    int pageSize = getAttr("pageSize");
    String where = getAttr(Constant.SEARCH_SQL);
    Page<SysRoleMenu> sysRoleMenuPage = SysRoleMenu.dao.pageWithRoleInfo(pageNumber, pageSize, where);
    renderDatagrid(sysRoleMenuPage);
}
 
Example #10
Source File: GoodsController.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
/**
 * 列表
 */
@ResponseBody
@Login
@PostMapping("/list")
public R info(@RequestBody GoodsListForm goodsListForm){
	List<Filter> filterList = new ArrayList<>();

	Filter filter = new Filter();
	if (goodsListForm.getCategoryId() != null &&!goodsListForm.getCategoryId().equals(-1)) {
		filter.setProperty("product_category_id");
		filter.setOperator(Filter.Operator.in);
		Filter pc = new Filter();
		pc.setProperty("tree_path");
		pc.setValue(goodsListForm.getCategoryId());
		pc.setOperator(Filter.Operator.like);
		List<ProductCategory> productCategoryList = productCategoryService.findByFilter(pc);
		List<Long> categoryIds = productCategoryList.stream().map(item -> {
			return item.getId();
		}).collect(Collectors.toList());
		filter.setValue(categoryIds);
		filterList.add(filter);
	}

	filter = new Filter();
	filter.setProperty("is_marketable");
	filter.setValue(GeneralEnum.TRUE.getCode());
	filter.setOperator(Filter.Operator.eq);
	filterList.add(filter);

	Order order = new Order();
	order.setProperty("create_date");
	order.setDirection(Order.Direction.desc);

	Page<Goods> pr = goodsService.paginate(goodsListForm.getPageNum(), goodsListForm.getPageSize(), filterList, order);

	return R.ok().put("goodsPage", pr);
}
 
Example #11
Source File: SysNoticeDetail.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 分页查询
 *
 * @param pageNumber 第几页
 * @param pageSize   每页条数
 * @param where      查询条件
 * @return 分页数据
 */
public Page<SysNoticeDetail> page(int pageNumber, int pageSize, String where) {
    String sqlSelect = " select * ";
    String sqlExceptSelect = " from sys_notice_detail  ";
    if (StringUtils.notEmpty(where)) {
        sqlExceptSelect += " where " + where;
    }
    return this.paginate(pageNumber, pageSize, sqlSelect, sqlExceptSelect);
}
 
Example #12
Source File: SysSetting.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 分页查询
 *
 * @param pageNumber 第几页
 * @param pageSize   每页条数
 * @param where      查询条件
 * @return 分页数据
 */
public Page<SysSetting> page(int pageNumber, int pageSize, String where) {
    String sqlSelect = " select * ";
    String sqlExceptSelect = " from sys_setting  ";
    if (StringUtils.notEmpty(where)) {
        sqlExceptSelect += " where " + where;
    }
    return this.paginate(pageNumber, pageSize, sqlSelect, sqlExceptSelect);
}
 
Example #13
Source File: SysNoticeType.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 分页查询
 *
 * @param pageNumber 第几页
 * @param pageSize   每页条数
 * @param where      查询条件
 * @return 分页数据
 */
public Page<SysNoticeType> page(int pageNumber, int pageSize, String where) {
    String sqlSelect = " select * ";
    String sqlExceptSelect = " from sys_notice_type  ";
    if (StringUtils.notEmpty(where)) {
        sqlExceptSelect += " where " + where;
    }
    return this.paginate(pageNumber, pageSize, sqlSelect, sqlExceptSelect);
}
 
Example #14
Source File: GoodsServiceImpl.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
@Override
public PageUtils queryPage(Map<String, Object> params) {
    String searchKey = (String)params.get("searchKey");
    Query<Goods> query = new Query<Goods>(params);
    List<Filter> filters = new ArrayList<>();
    if (!StringUtils.isBlank(searchKey)) {
        Filter filter = new Filter();
        filter.setProperty("name");
        filter.setValue(searchKey);
        filter.setOperator(Filter.Operator.like);
        filters.add(filter);

        filter = new Filter();
        filter.setProperty("caption");
        filter.setValue(searchKey);
        filter.setOperator(Filter.Operator.like);
        filter.setWhereOpt(Filter.WhereOpt.or);
        filters.add(filter);

        filter = new Filter();
        filter.setProperty("sn");
        filter.setValue(searchKey);
        filter.setOperator(Filter.Operator.like);
        filter.setWhereOpt(Filter.WhereOpt.or);
        filters.add(filter);
    }

    Order order = new Order();
    order.setProperty("create_date");
    order.setDirection(Order.Direction.desc);
    Page<Goods> pr = this.paginate(query.getCurrPage(), query.getLimit(), filters, order);

    return new PageUtils(pr);
}
 
Example #15
Source File: ElasticSearcher.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Page<Product> search(String keyword, int pageNum, int pageSize) {

    BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
    boolQueryBuilder.should(new MatchQueryBuilder("title", keyword));
    boolQueryBuilder.should(new MatchQueryBuilder("content", keyword));


    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    sourceBuilder.from(pageNum * pageSize - pageSize);
    sourceBuilder.size(pageSize);
    sourceBuilder.query(boolQueryBuilder);

    SearchRequest searchRequest = new SearchRequest();
    searchRequest.source(sourceBuilder);
    searchRequest.indices(index);
    searchRequest.types(type);

    try {
        SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
        if (response == null || response.getHits() == null || response.getHits().getTotalHits().value <= 0) {
            return null;
        }

        int total = (int) response.getHits().getTotalHits().value;

        List<Product> products = new ArrayList<>();
        response.getHits().forEach(hit -> {
            Product product = new Product();
            product.put(hit.getSourceAsMap());
            products.add(product);
        });

        return new Page<>(products, pageNum, pageSize, total / pageSize, total);

    } catch (Exception e) {
        LOG.error(e.toString(), e);
    }
    return null;
}
 
Example #16
Source File: ProductServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@Cacheable(name = "products")
public Page<Product> searchIndb(String queryString, int pageNum, int pageSize) {
    Columns columns = Columns.create("status", Product.STATUS_NORMAL)
            .likeAppendPercent("title", queryString);
    return joinUserInfo(paginateByColumns(pageNum, pageSize, columns, "order_number desc,id desc"));
}
 
Example #17
Source File: SinglePageServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Page<SinglePage> _paginateByStatus(int page, int pagesize, String title, String status) {

    Columns columns = Columns.create("status", status);
    if (StrUtil.isNotBlank(title)) {
        columns.like("title", "%" + title + "%");
    }

    return DAO.paginateByColumns(page,
            pagesize,
            columns,
            "id desc");
}
 
Example #18
Source File: LuceneSearcher.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static Page<Article> newPage(int pageNum, int pageSize, int totalRow, List<Article> articles) {
    int totalPages;
    if ((totalRow % pageSize) == 0) {
        totalPages = totalRow / pageSize;
    } else {
        totalPages = totalRow / pageSize + 1;
    }

    return new Page<>(articles,
            pageNum, pageSize, totalPages, totalRow);
}
 
Example #19
Source File: LuceneSearcher.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Page<Product> search(String keyword, int pageNum, int pageSize) {
    IndexReader indexReader = null;
    try {
        //Bug fix ,查询关键字使用一下 QueryParser.escape(keyword),例如:keyword=I/O,否则buildQuery时会出现异常
        keyword = QueryParser.escape(keyword);
        indexReader = DirectoryReader.open(directory);
        IndexSearcher indexSearcher = new IndexSearcher(indexReader);
        Query query = buildQuery(keyword);

        ScoreDoc lastScoreDoc = getLastScoreDoc(pageNum, pageSize, query, indexSearcher);
        TopDocs topDocs = indexSearcher.searchAfter(lastScoreDoc, query, pageSize);

        SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<font class=\"" + HIGH_LIGHT_CLASS + "\">", "</font>");
        Highlighter highlighter = new Highlighter(formatter, new QueryScorer(query));
        highlighter.setTextFragmenter(new SimpleFragmenter(100));

        List<Product> products = toProductList(indexSearcher, topDocs, highlighter, keyword);
        int totalRow = getTotalRow(indexSearcher, query);
        return newPage(pageNum, pageSize, totalRow, products);
    } catch (Exception e) {
        LOG.error(e.toString(), e);
    } finally {
        CommonsUtils.quietlyClose(indexReader);
    }
    return null;
}
 
Example #20
Source File: FormLeave.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 分页查询
 *
 * @param pageNumber 第几页
 * @param pageSize   每页条数
 * @param where      查询条件
 * @return 分页数据
 */
public Page<FormLeave> page(int pageNumber, int pageSize, String where) {
    String sqlSelect = " select * ";
    String sqlExceptSelect = " from form_leave  ";
    if (StringUtils.notEmpty(where)) {
        sqlExceptSelect += " where " + where;
    }
    sqlExceptSelect += "order by createTime desc";
    return this.paginate(pageNumber, pageSize, sqlSelect, sqlExceptSelect);
}
 
Example #21
Source File: ArticleServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@Cacheable(name = "articles")
public Page<Article> searchIndb(String queryString, int pageNum, int pageSize) {
    Columns columns = Columns.create("status", Article.STATUS_NORMAL)
            .likeAppendPercent("title", queryString);
    return joinUserInfo(paginateByColumns(pageNum, pageSize, columns, "order_number desc,id desc"));
}
 
Example #22
Source File: ArticleCommentServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Page<ArticleComment> paginate(int page, int pageSize) {
    Page p = super.paginate(page, pageSize);
    articleService.join(p, "article_id");
    userService.join(p, "user_id");
    return p;
}
 
Example #23
Source File: ExSingleTableController.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 列表数据
 */
@Before(SearchSql.class)
public void query() {
    int pageNumber = getAttr("pageNumber");
    int pageSize = getAttr("pageSize");
    String where = getAttr(Constant.SEARCH_SQL);
    Page<ExSingleTable> exSingleTablePage = ExSingleTable.dao.page(pageNumber, pageSize, where);
    renderDatagrid(exSingleTablePage);
}
 
Example #24
Source File: JsonUtils.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * Page<Page<? extends Model>转为Page<Map<String, Object>>,驼峰命名
 *
 * @param models
 * @return
 */
public static Page<Map<String, Object>> modelsToCamelCaseMaps(Page<? extends Model> models) {
    List<? extends Model> modelList = models.getList();
    List<Map<String, Object>> maps = new ArrayList<>();
    for (Model model : modelList) {
        maps.add(modelToCamelCaseMap(model));
    }
    return new Page<>(maps, models.getPageNumber(), models.getPageSize(), models.getTotalPage(),
            models.getTotalRow());
}
 
Example #25
Source File: SysDict.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 分页查询
 *
 * @param pageNumber 第几页
 * @param pageSize   每页条数
 * @param where      查询条件
 * @return 分页数据
 */
public Page<SysDict> page(int pageNumber, int pageSize, String where) {
    String sqlSelect = " select * ";
    String sqlExceptSelect = " from sys_dict  ";
    if (StringUtils.notEmpty(where)) {
        sqlExceptSelect += " where " + where;
    }
    sqlExceptSelect += " order by sortNum asc ";
    return this.paginate(pageNumber, pageSize, sqlSelect, sqlExceptSelect);
}
 
Example #26
Source File: BusinessFormInfoController.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 列表数据
 */
@Clear(PermissionInterceptor.class)
@Before(SearchSql.class)
public void query() {
    int pageNumber = getAttr("pageNumber");
    int pageSize = getAttr("pageSize");
    String where = getAttr(Constant.SEARCH_SQL);

    // 组织机构查询条件
    String orgId = getPara("extra_orgId");
    if (StringUtils.notEmpty(orgId)) {
        Boolean cascadeOrg = getParaToBoolean("extra_cascadeOrg", false);
        String whereSeg;
        if (cascadeOrg) {
            String sonIds = TreeTableUtils.getSonTreeIds(orgId, "sys_org", "id", "pid");
            if (StringUtils.notEmpty(sonIds)) {
                sonIds = sonIds.replaceAll(",", "','");
            } else {
                sonIds = "unknow";  // 查不到的
            }
            whereSeg = " categoryId in ('" + sonIds + "')";
        } else {
            whereSeg = " categoryId ='" + orgId + "' ";
        }

        if (StringUtils.isEmpty(where)) {
            where += whereSeg;
        } else {
            where += (" and " + whereSeg);
        }
    }

    Page<BusinessFormInfo> businessFormInfoPage = BusinessFormInfo.dao.page(pageNumber, pageSize, where);
    renderDatagrid(businessFormInfoPage);
}
 
Example #27
Source File: ArticleApiController.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 通过 分类ID 分页读取文章列表
 */
public void paginate() {
    Long categoryId = getParaToLong("categoryId");
    String orderBy = getPara("orderBy");
    int pageNumber = getParaToInt("pageNumber", 1);

    Page<Article> page = categoryId == null
            ? articleService.paginateInNormal(pageNumber, 10, orderBy)
            : articleService.paginateByCategoryIdInNormal(pageNumber, 10, categoryId, orderBy);

    renderJson(Ret.ok().set("page", page));
}
 
Example #28
Source File: _ProductTagController.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@AdminMenu(text = "标签", groupId = "product", order = 3)
public void index() {
    Page<ProductCategory> page = productCategoryService.paginateByType(getPagePara(), 10, ProductCategory.TYPE_TAG);
    setAttr("page", page);

    int id = getParaToInt(0, 0);
    if (id > 0) {
        setAttr("category", productCategoryService.findById(id));
        setAttr("isDisplayInMenu", menuService.findFirstByRelatives("article_category", id) != null);
    }

    initStylesAttr("prolist_");
    render("product/product_tag_list.html");
}
 
Example #29
Source File: ElasticSearcher.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Page<Article> search(String keyword, int pageNum, int pageSize) {

    BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
    boolQueryBuilder.should(new MatchQueryBuilder("title", keyword));
    boolQueryBuilder.should(new MatchQueryBuilder("content", keyword));


    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    sourceBuilder.from(pageNum * pageSize - pageSize);
    sourceBuilder.size(pageSize);
    sourceBuilder.query(boolQueryBuilder);

    SearchRequest searchRequest = new SearchRequest();
    searchRequest.source(sourceBuilder);
    searchRequest.indices(index);
    searchRequest.types(type);

    try {
        SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
        if (response ==null || response.getHits() == null || response.getHits().getTotalHits().value <= 0){
            return null;
        }

        int total = (int) response.getHits().getTotalHits().value;

        List<Article> articles = new ArrayList<>();
        response.getHits().forEach(hit -> {
            Article article = new Article();
            article.put(hit.getSourceAsMap());
            articles.add(article);
        });

        return new Page<>(articles, pageNum, pageSize, total / pageSize, total);

    } catch (Exception e) {
        LOG.error(e.toString(), e);
    }
    return null;
}
 
Example #30
Source File: SysDictGroup.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 分页查询
 *
 * @param pageNumber 第几页
 * @param pageSize   每页条数
 * @param where      查询条件
 * @return 分页数据
 */
public Page<SysDictGroup> page(int pageNumber, int pageSize, String where) {
    String sqlSelect = " select * ";
    String sqlExceptSelect = " from sys_dict_group  ";
    if (StringUtils.notEmpty(where)) {
        sqlExceptSelect += " where " + where;
    }
    return this.paginate(pageNumber, pageSize, sqlSelect, sqlExceptSelect);
}