Search in sources :

Example 1 with Relationships

use of com.tale.model.entity.Relationships in project tale by otale.

the class MetasService method delete.

/**
 * 删除项目
 *
 * @param mid 项目id
 */
public void delete(int mid) {
    Metas metas = select().from(Metas.class).byId(mid);
    if (null == metas) {
        return;
    }
    String type = metas.getType();
    String name = metas.getName();
    Anima.deleteById(Metas.class, mid);
    List<Relationships> list = select().from(Relationships.class).where(Relationships::getMid, mid).all();
    if (null != list) {
        list.stream().map(r -> select().from(Contents.class).byId(r.getCid())).filter(Objects::nonNull).forEach(contents -> exec(type, name, contents));
    }
    Anima.delete().from(Relationships.class).where(Relationships::getMid, mid).execute();
}
Also used : Metas(com.tale.model.entity.Metas) Relationships(com.tale.model.entity.Relationships)

Example 2 with Relationships

use of com.tale.model.entity.Relationships in project tale by otale.

the class MetasService method saveOrUpdate.

private void saveOrUpdate(Integer cid, String name, String type) {
    Metas metas = select().from(Metas.class).where(Metas::getName, name).and(Metas::getType, type).one();
    int mid;
    if (null != metas) {
        mid = metas.getMid();
    } else {
        metas = new Metas();
        metas.setSlug(name);
        metas.setName(name);
        metas.setType(type);
        mid = metas.save().asInt();
    }
    if (mid != 0) {
        long count = new Relationships().where("cid", cid).and("mid", mid).count();
        if (count == 0) {
            Relationships relationships = new Relationships();
            relationships.setCid(cid);
            relationships.setMid(mid);
            relationships.save();
        }
    }
}
Also used : Metas(com.tale.model.entity.Metas) Relationships(com.tale.model.entity.Relationships)

Aggregations

Metas (com.tale.model.entity.Metas)2 Relationships (com.tale.model.entity.Relationships)2