Java Code Examples for io.jboot.db.model.Columns#add()

The following examples show how to use io.jboot.db.model.Columns#add() . 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: 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 2
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 3
Source File: ProductCommentServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Page<ProductComment> paginateByProductIdInNormal(int page, int pagesize, long productId) {
    Columns columns = Columns.create("product_id", productId);
    columns.add("status", ProductComment.STATUS_NORMAL);


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

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

    return p;
}
 
Example 4
Source File: ArticleCommentServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Page<ArticleComment> paginateByArticleIdInNormal(int page, int pagesize, long articleId) {
    Columns columns = Columns.create("article_id", articleId);
    columns.add("status", ArticleComment.STATUS_NORMAL);


    Page<ArticleComment> 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: ArticleCategoryServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<ArticleCategory> doNewOrFindByCategoryString(String[] categories) {
    if (categories == null || categories.length == 0) {
        return null;
    }

    List<ArticleCategory> articleCategories = new ArrayList<>();
    for (String category : categories) {
        Columns columns = Columns.create("type", ArticleCategory.TYPE_CATEGORY);
        columns.add(Column.create("slug", category));

        ArticleCategory articleCategory = DAO.findFirstByColumns(columns);

        if (articleCategory == null) {
            articleCategory = new ArticleCategory();
            articleCategory.setTitle(category);
            articleCategory.setSlug(category);
            articleCategory.setType(ArticleCategory.TYPE_CATEGORY);
            articleCategory.save();
        }

        articleCategories.add(articleCategory);
    }

    return articleCategories;
}
 
Example 6
Source File: _CouponController.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void useds() {

        Columns columns = Columns.create();
        columns.add("code_id", getPara("codeid"));
        columns.add("code_user_id", getPara("cuid"));
        columns.add("coupon_id", getPara("coid"));

        Page<CouponUsedRecord> page = couponUsedRecordService.paginate(getPagePara(), 10, columns);
        setAttr("page", page);
        render("finance/coupon_useds.html");
    }
 
Example 7
Source File: ProductServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Product findPreviousById(long id) {
    Columns columns = Columns.create();
    columns.add(Column.create("id", id, Column.LOGIC_LT));
    columns.add(Column.create("status", Product.STATUS_NORMAL));
    return joinUserInfo(DAO.findFirstByColumns(columns, "id desc"));
}
 
Example 8
Source File: ProductServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Product findNextById(long id) {
    Columns columns = Columns.create();
    columns.add(Column.create("id", id, Column.LOGIC_GT));
    columns.add(Column.create("status", Product.STATUS_NORMAL));
    return joinUserInfo(DAO.findFirstByColumns(columns));
}
 
Example 9
Source File: ProductServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Page<Product> _paginateByBaseColumns(int page, int pagesize, Columns baseColumns, Long categoryId, String orderBy) {

        Columns columns = baseColumns;
        columns.add("m.category_id", categoryId);

        Page<Product> dataPage = DAO.leftJoinIf("product_category_mapping",categoryId != null).as("m")
                .on("product.id = m.`product_id`")
                .paginateByColumns(page,pagesize,columns,StrUtil.obtainDefaultIfBlank(orderBy, DEFAULT_ORDER_BY));

        return joinUserInfo(dataPage);
    }
 
Example 10
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> paginateByCategoryIdInNormal(int page, int pagesize, long categoryId, String orderBy) {

    Columns columns = new Columns();
    columns.add("m.category_id", categoryId);
    columns.add("product.status", Product.STATUS_NORMAL);

    return _paginateByBaseColumns(page, pagesize, columns, categoryId, orderBy);
}
 
Example 11
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> paginateInNormal(int page, int pagesize, String orderBy) {
    orderBy = StrUtil.obtainDefaultIfBlank(orderBy, DEFAULT_ORDER_BY);
    Columns columns = new Columns();
    columns.add("status", Product.STATUS_NORMAL);
    Page<Product> dataPage = DAO.paginateByColumns(page, pagesize, columns, orderBy);
    return joinUserInfo(dataPage);
}
 
Example 12
Source File: ProductsDirective.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {

    String flag = getPara("flag", scope);
    String style = getPara("style", scope);
    Boolean hasThumbnail = getParaToBool("hasThumbnail", scope);
    String orderBy = getPara("orderBy", scope, "id desc");
    int count = getParaToInt("count", scope, 10);


    Columns columns = Columns.create("flag", flag);
    columns.add("style", style);

    columns.add("status", Product.STATUS_NORMAL);

    if (hasThumbnail != null) {
        if (hasThumbnail) {
            columns.isNotNull("thumbnail");
        } else {
            columns.isNull("thumbnail");
        }
    }

    List<Product> products = service.findListByColumns(columns, orderBy, count);

    if (products == null || products.isEmpty()) {
        return;
    }

    scope.setLocal("products", products);
    renderBody(env, scope, writer);
}
 
Example 13
Source File: ArticleServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Article findPreviousById(long id) {
    Columns columns = Columns.create();
    columns.add(Column.create("id", id, Column.LOGIC_LT));
    columns.add(Column.create("status", Article.STATUS_NORMAL));
    return joinUserInfo(DAO.findFirstByColumns(columns, "id desc"));
}
 
Example 14
Source File: ArticleServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Article findNextById(long id) {
    Columns columns = Columns.create();
    columns.add(Column.create("id", id, Column.LOGIC_GT));
    columns.add(Column.create("status", Article.STATUS_NORMAL));
    return joinUserInfo(DAO.findFirstByColumns(columns));
}
 
Example 15
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> paginateByCategoryIdInNormal(int page, int pagesize, long categoryId, String orderBy) {

    Columns columns = new Columns();
    columns.add("m.category_id", categoryId);
    columns.add("article.status", Article.STATUS_NORMAL);

    Page<Article> dataPage = DAO.leftJoin("article_category_mapping")
            .as("m").on("article.id=m.`article_id`")
            .paginateByColumns(page, pagesize, columns, StrUtil.obtainDefaultIfBlank(orderBy, DEFAULT_ORDER_BY));
    return joinUserInfo(dataPage);
}
 
Example 16
Source File: ArticleServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Page<Article> _paginateByBaseColumns(int page, int pagesize, String title, Long categoryId, Columns baseColumns) {

        Columns columns = baseColumns;
        columns.add("m.category_id", categoryId);
        columns.likeAppendPercent("article.title", title);

        Page<Article> dataPage = DAO.leftJoinIf("article_category_mapping", categoryId != null)
                .as("m")
                .on("article.id = m.article_id")
                .paginateByColumns(page, pagesize, columns, "id desc");


        return joinUserInfo(dataPage);
    }
 
Example 17
Source File: ArticlesDirective.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {

    String flag = getPara("flag", scope);
    String style = getPara("style", scope);
    Boolean hasThumbnail = getParaToBool("hasThumbnail", scope);
    String orderBy = getPara("orderBy", scope, "id desc");
    int count = getParaToInt("count", scope, 10);


    Columns columns = Columns.create();

    columns.add("flag", flag);
    columns.add("style", style);
    columns.add("status", Article.STATUS_NORMAL);

    if (hasThumbnail != null) {
        if (hasThumbnail) {
            columns.isNotNull("thumbnail");
        } else {
            columns.isNull("thumbnail");
        }
    }

    List<Article> articles = service.findListByColumns(columns, orderBy, count);

    if (articles == null || articles.isEmpty()) {
        return;
    }

    scope.setLocal("articles", articles);
    renderBody(env, scope, writer);
}
 
Example 18
Source File: UserArticlesDirective.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {

    Long userId = getParaToLong("userId", scope);
    User user = JbootControllerContext.get().getAttr("user");

    if (userId == null && user == null) {
        throw new RuntimeException("#userArticles() args is error,userId must not be null." + getLocation());
    }

    if (userId == null) {
        userId = user.getId();
    }

    String orderBy = getPara("orderBy", scope, "id desc");
    String status = getPara("status", scope, Article.STATUS_NORMAL);
    int count = getParaToInt("count", scope, 10);


    Columns columns = Columns.create("user_id", userId);
    columns.add("status", status);

    List<Article> articles = service.findListByColumns(columns, orderBy, count);

    if (articles == null || articles.isEmpty()) {
        return;
    }

    scope.setLocal("articles", articles);
    renderBody(env, scope, writer);
}
 
Example 19
Source File: ArticleCategoryServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public List<ArticleCategory> doNewOrFindByTagString(String[] tags) {
    if (tags == null || tags.length == 0) {
        return null;
    }

    boolean needClearCache = false;
    List<ArticleCategory> articleCategories = new ArrayList<>();
    for (String tag : tags) {

        if (StrUtil.isBlank(tag)) {
            continue;
        }

        //slug不能包含字符串点 " . ",否则url不能被访问
        String slug = tag.contains(".")
                ? tag.replace(".", "_")
                : tag;

        Columns columns = Columns.create("type", ArticleCategory.TYPE_TAG);
        columns.add(Column.create("slug", slug));

        ArticleCategory articleCategory = DAO.findFirstByColumns(columns);

        if (articleCategory == null) {
            articleCategory = new ArticleCategory();
            articleCategory.setTitle(tag);
            articleCategory.setSlug(slug);
            articleCategory.setType(ArticleCategory.TYPE_TAG);
            articleCategory.save();

            needClearCache = true;
        }

        articleCategories.add(articleCategory);
    }

    if (needClearCache) {
        AopCache.removeAll("articleCategory");
    }

    return articleCategories;
}
 
Example 20
Source File: ProductCategoryServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public List<ProductCategory> findOrCreateByTagString(String[] tags) {
    if (tags == null || tags.length == 0) {
        return null;
    }

    List<ProductCategory> productCategories = new ArrayList<>();

    boolean needClearCache = false;

    for (String tag : tags) {

        if (StrUtil.isBlank(tag)) {
            continue;
        }

        //slug不能包含字符串点 " . ",否则url不能被访问
        String slug = tag.contains(".")
                ? tag.replace(".", "_")
                : tag;

        Columns columns = Columns.create("type", ProductCategory.TYPE_TAG);
        columns.add(Column.create("slug", slug));

        ProductCategory productCategory = DAO.findFirstByColumns(columns);

        if (productCategory == null) {
            productCategory = new ProductCategory();
            productCategory.setTitle(tag);
            productCategory.setSlug(slug);
            productCategory.setType(ProductCategory.TYPE_TAG);
            productCategory.save();
            needClearCache = true;
        }

        productCategories.add(productCategory);
    }

    if (needClearCache) {
        AopCache.removeAll("productCategory");
    }

    return productCategories;
}