Search in sources :

Example 1 with Metas

use of com.tale.model.Metas in project tale by otale.

the class LinksController method saveLink.

@Route(value = "save", method = HttpMethod.POST)
@JSON
public RestResponse saveLink(@QueryParam String title, @QueryParam String url, @QueryParam String logo, @QueryParam Integer mid, @QueryParam(value = "sort", defaultValue = "0") int sort) {
    try {
        Metas metas = new Metas();
        metas.setName(title);
        metas.setSlug(url);
        metas.setDescription(logo);
        metas.setSort(sort);
        metas.setType(Types.LINK);
        if (null != mid) {
            metas.setMid(mid);
            metasService.update(metas);
        } else {
            metasService.saveMeta(metas);
        }
        siteService.cleanCache(Types.C_STATISTICS);
    } catch (Exception e) {
        String msg = "友链保存失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
    return RestResponse.ok();
}
Also used : Metas(com.tale.model.Metas) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Example 2 with Metas

use of com.tale.model.Metas in project tale by otale.

the class MetasServiceImpl method delete.

@Override
public void delete(int mid) {
    Metas metas = activeRecord.byId(Metas.class, mid);
    if (null != metas) {
        String type = metas.getType();
        String name = metas.getName();
        activeRecord.delete(Metas.class, mid);
        List<Relationships> rlist = activeRecord.list(new Take(Relationships.class).eq("mid", mid));
        if (null != rlist) {
            for (Relationships r : rlist) {
                Contents contents = activeRecord.byId(Contents.class, r.getCid());
                if (null != contents) {
                    boolean isUpdate = false;
                    Contents temp = new Contents();
                    temp.setCid(r.getCid());
                    if (type.equals(Types.CATEGORY)) {
                        temp.setCategories(reMeta(name, contents.getCategories()));
                        isUpdate = true;
                    }
                    if (type.equals(Types.TAG)) {
                        temp.setTags(reMeta(name, contents.getTags()));
                        isUpdate = true;
                    }
                    if (isUpdate) {
                        activeRecord.update(temp);
                    }
                }
            }
        }
        activeRecord.delete(new Take(Relationships.class).eq("mid", mid));
    }
}
Also used : Take(com.blade.jdbc.core.Take) Metas(com.tale.model.Metas) Relationships(com.tale.model.Relationships) Contents(com.tale.model.Contents)

Example 3 with Metas

use of com.tale.model.Metas 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 4 with Metas

use of com.tale.model.Metas 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 5 with Metas

use of com.tale.model.Metas in project tale by otale.

the class ArticleController method editArticle.

/**
     * 文章编辑页面
     * @param cid
     * @param request
     * @return
     */
@Route(value = "/:cid", method = HttpMethod.GET)
public String editArticle(@PathParam String cid, Request request) {
    Contents contents = contentsService.getContents(cid);
    request.attribute("contents", contents);
    List<Metas> categories = metasService.getMetas(Types.CATEGORY);
    request.attribute("categories", categories);
    request.attribute("active", "article");
    request.attribute(Types.ATTACH_URL, Commons.site_option(Types.ATTACH_URL, Commons.site_url()));
    return "admin/article_edit";
}
Also used : Metas(com.tale.model.Metas) Contents(com.tale.model.Contents)

Aggregations

Metas (com.tale.model.Metas)5 Take (com.blade.jdbc.core.Take)3 TipException (com.tale.exception.TipException)2 Contents (com.tale.model.Contents)2 Relationships (com.tale.model.Relationships)2 JSON (com.blade.mvc.annotation.JSON)1 Route (com.blade.mvc.annotation.Route)1