Search in sources :

Example 6 with Take

use of com.blade.jdbc.core.Take in project tale by otale.

the class CommentsServiceImpl method getComments.

@Override
public Paginator<Comment> getComments(Integer cid, int page, int limit) {
    if (null != cid) {
        Take take = new Take(Comments.class);
        take.eq("cid", cid).eq("parent", 0);
        take.page(page, limit, "coid desc");
        Paginator<Comments> cp = activeRecord.page(take);
        Paginator<Comment> commentPaginator = new Paginator<>(cp.getTotal(), page, limit);
        if (null != cp.getList()) {
            List<Comments> parents = cp.getList();
            List<Comment> comments = new ArrayList<>(parents.size());
            parents.forEach(parent -> {
                Comment comment = new Comment(parent);
                List<Comments> children = new ArrayList<>();
                getChildren(children, comment.getCoid());
                comment.setChildren(children);
                if (CollectionKit.isNotEmpty(children)) {
                    comment.setLevels(1);
                }
                comments.add(comment);
            });
            commentPaginator.setList(comments);
        }
        return commentPaginator;
    }
    return null;
}
Also used : Take(com.blade.jdbc.core.Take) Comment(com.tale.dto.Comment) Comments(com.tale.model.Comments) ArrayList(java.util.ArrayList) Paginator(com.blade.jdbc.model.Paginator)

Example 7 with Take

use of com.blade.jdbc.core.Take in project tale by otale.

the class ContentsServiceImpl method publish.

@Override
public Integer publish(Contents contents) {
    if (null == contents)
        throw new TipException("文章对象为空");
    if (StringKit.isBlank(contents.getTitle()))
        throw new TipException("文章标题不能为空");
    if (contents.getTitle().length() > TaleConst.MAX_TITLE_COUNT) {
        throw new TipException("文章标题最多可以输入" + TaleConst.MAX_TITLE_COUNT + "个字符");
    }
    if (StringKit.isBlank(contents.getContent()))
        throw new TipException("文章内容不能为空");
    // 最多可以输入5w个字
    if (contents.getContent().length() > TaleConst.MAX_TEXT_COUNT)
        throw new TipException("文章内容最多可以输入" + TaleConst.MAX_TEXT_COUNT + "个字符");
    if (null == contents.getAuthor_id())
        throw new TipException("请登录后发布文章");
    if (StringKit.isNotBlank(contents.getSlug())) {
        if (contents.getSlug().length() < 5) {
            throw new TipException("路径太短了");
        }
        if (!TaleUtils.isPath(contents.getSlug()))
            throw new TipException("您输入的路径不合法");
        int count = activeRecord.count(new Take(Contents.class).eq("type", contents.getType()).eq("slug", contents.getSlug()));
        if (count > 0)
            throw new TipException("该路径已经存在,请重新输入");
    }
    contents.setContent(EmojiParser.parseToAliases(contents.getContent()));
    int time = DateKit.getCurrentUnixTime();
    contents.setCreated(time);
    contents.setModified(time);
    String tags = contents.getTags();
    String categories = contents.getCategories();
    Integer cid = activeRecord.insert(contents);
    metasService.saveMetas(cid, tags, Types.TAG);
    metasService.saveMetas(cid, categories, Types.CATEGORY);
    return cid;
}
Also used : Take(com.blade.jdbc.core.Take) Contents(com.tale.model.Contents) TipException(com.tale.exception.TipException)

Example 8 with Take

use of com.blade.jdbc.core.Take in project tale by otale.

the class MetasServiceImpl method saveMeta.

@Override
public void saveMeta(String type, String name, Integer mid) {
    if (StringKit.isNotBlank(type) && StringKit.isNotBlank(name)) {
        Metas metas = activeRecord.one(new Take(Metas.class).eq("type", type).eq("name", name));
        if (null != metas) {
            throw new TipException("已经存在该项");
        } else {
            if (null != mid) {
                metas = new Metas();
                metas.setMid(mid);
                metas.setName(name);
                activeRecord.update(metas);
            } else {
                metas = new Metas();
                metas.setType(type);
                metas.setName(name);
                activeRecord.insert(metas);
            }
        }
    }
}
Also used : Take(com.blade.jdbc.core.Take) Metas(com.tale.model.Metas) TipException(com.tale.exception.TipException)

Example 9 with Take

use of com.blade.jdbc.core.Take in project tale by otale.

the class MetasServiceImpl method saveOrUpdate.

private void saveOrUpdate(Integer cid, String name, String type) {
    Metas metas = activeRecord.one(new Take(Metas.class).eq("name", name).eq("type", type));
    int mid = 0;
    if (null != metas) {
        //            Metas temp = new Metas();
        //            temp.setMid(metas.getMid());
        //            activeRecord.update(temp);
        mid = metas.getMid();
    } else {
        metas = new Metas();
        metas.setSlug(name);
        metas.setName(name);
        metas.setType(type);
        mid = activeRecord.insert(metas);
    }
    if (mid != 0) {
        int count = activeRecord.count(new Take(Relationships.class).eq("cid", cid).eq("mid", mid));
        if (count == 0) {
            Relationships relationships = new Relationships();
            relationships.setCid(cid);
            relationships.setMid(mid);
            activeRecord.insert(relationships);
        }
    }
}
Also used : Take(com.blade.jdbc.core.Take) Metas(com.tale.model.Metas) Relationships(com.tale.model.Relationships)

Example 10 with Take

use of com.blade.jdbc.core.Take in project tale by otale.

the class SiteServiceImpl method getStatistics.

@Override
public Statistics getStatistics() {
    Statistics statistics = mapCache.get(Types.C_STATISTICS);
    if (null != statistics) {
        return statistics;
    }
    statistics = new Statistics();
    int articles = activeRecord.count(new Take(Contents.class).eq("type", Types.ARTICLE).eq("status", Types.PUBLISH));
    int pages = activeRecord.count(new Take(Contents.class).eq("type", Types.PAGE).eq("status", Types.PUBLISH));
    int comments = activeRecord.count(new Take(Comments.class));
    int attachs = activeRecord.count(new Take(Attach.class));
    int links = activeRecord.count(new Take(Metas.class).eq("type", Types.LINK));
    int tags = activeRecord.count(new Take(Metas.class).eq("type", Types.TAG));
    int categories = activeRecord.count(new Take(Metas.class).eq("type", Types.CATEGORY));
    statistics.setArticles(articles);
    statistics.setPages(pages);
    statistics.setComments(comments);
    statistics.setAttachs(attachs);
    statistics.setLinks(links);
    statistics.setTags(tags);
    statistics.setCategories(categories);
    mapCache.set(Types.C_STATISTICS, statistics);
    return statistics;
}
Also used : Take(com.blade.jdbc.core.Take)

Aggregations

Take (com.blade.jdbc.core.Take)15 Contents (com.tale.model.Contents)7 TipException (com.tale.exception.TipException)4 Comments (com.tale.model.Comments)3 Metas (com.tale.model.Metas)3 Relationships (com.tale.model.Relationships)2 Users (com.tale.model.Users)2 Paginator (com.blade.jdbc.model.Paginator)1 Route (com.blade.mvc.annotation.Route)1 Comment (com.tale.dto.Comment)1 Options (com.tale.model.Options)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1