示例#1
0
 /**
  * 获取链接列表
  *
  * @param siteId 站点编号
  * @param categoryId 分类编号
  * @param number 获取数目
  * @param param 预留参数,例: key1:'value1', key2:'value2' ...
  * @return
  */
 public static List<Link> getLinkList(long siteId, long categoryId, int number, String param) {
   Page<Link> page = new Page<Link>(1, number, -1);
   Link link = new Link(new Category(categoryId, new Site(siteId)));
   if (StringUtils.isNotBlank(param)) {
     @SuppressWarnings({"unused", "rawtypes"})
     Map map = JsonMapper.getInstance().fromJson("{" + param + "}", Map.class);
   }
   link.setDelFlag(Link.DEL_FLAG_NORMAL);
   page = linkService.find(page, link, false);
   return page.getList();
 }
示例#2
0
 /** 通过编号获取内容标题 */
 public List<Object[]> findByIds(String ids) {
   List<Object[]> list = Lists.newArrayList();
   Long[] idss = (Long[]) ConvertUtils.convert(StringUtils.split(ids, ","), Long.class);
   if (idss.length > 0) {
     List<Link> l = linkDao.findByIdIn(idss);
     for (Link e : l) {
       list.add(new Object[] {e.getId(), StringUtils.abbr(e.getTitle(), 50)});
     }
   }
   return list;
 }
示例#3
0
  @Transactional(readOnly = false)
  public Page<Link> findPage(Page<Link> page, Link link, boolean isDataScopeFilter) {
    // 更新过期的权重,间隔为“6”个小时
    Date updateExpiredWeightDate = (Date) CacheUtils.get("updateExpiredWeightDateByLink");
    if (updateExpiredWeightDate == null
        || (updateExpiredWeightDate != null
            && updateExpiredWeightDate.getTime() < new Date().getTime())) {
      dao.updateExpiredWeight(link);
      CacheUtils.put("updateExpiredWeightDateByLink", DateUtils.addHours(new Date(), 6));
    }
    link.getSqlMap().put("dsf", dataScopeFilter(link.getCurrentUser(), "o", "u"));

    return super.findPage(page, link);
  }
示例#4
0
 @Transactional(readOnly = false)
 public void save(Link link) {
   // 如果没有审核权限,则将当前内容改为待审核状态
   if (!SecurityUtils.getSubject().isPermitted("cms:link:audit")) {
     link.setDelFlag(Link.DEL_FLAG_AUDIT);
   }
   // 如果栏目不需要审核,则将该内容设为发布状态
   if (link.getCategory() != null && StringUtils.isNotBlank(link.getCategory().getId())) {
     Category category = categoryDao.get(link.getCategory().getId());
     if (!Article.YES.equals(category.getIsAudit())) {
       link.setDelFlag(Article.DEL_FLAG_NORMAL);
     }
   }
   linkDao.clear();
   linkDao.save(link);
 }
示例#5
0
 @Transactional(readOnly = false)
 public Page<Link> find(Page<Link> page, Link link, boolean isDataScopeFilter) {
   // 更新过期的权重,间隔为“6”个小时
   Date updateExpiredWeightDate = (Date) CacheUtils.get("updateExpiredWeightDateByLink");
   if (updateExpiredWeightDate == null
       || (updateExpiredWeightDate != null
           && updateExpiredWeightDate.getTime() < new Date().getTime())) {
     linkDao.updateExpiredWeight();
     CacheUtils.put("updateExpiredWeightDateByLink", DateUtils.addHours(new Date(), 6));
   }
   DetachedCriteria dc = linkDao.createDetachedCriteria();
   dc.createAlias("category", "category");
   dc.createAlias("category.site", "category.site");
   if (link.getCategory() != null
       && StringUtils.isNotBlank(link.getCategory().getId())
       && !Category.isRoot(link.getCategory().getId())) {
     Category category = categoryDao.get(link.getCategory().getId());
     if (category != null) {
       dc.add(
           Restrictions.or(
               Restrictions.eq("category.id", category.getId()),
               Restrictions.like("category.parentIds", "%," + category.getId() + ",%")));
       dc.add(Restrictions.eq("category.site.id", category.getSite().getId()));
       link.setCategory(category);
     } else {
       dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId()));
     }
   } else {
     dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId()));
   }
   if (StringUtils.isNotEmpty(link.getTitle())) {
     dc.add(Restrictions.like("title", "%" + link.getTitle() + "%"));
   }
   if (link.getCreateBy() != null && StringUtils.isNotBlank(link.getCreateBy().getId())) {
     dc.add(Restrictions.eq("createBy.id", link.getCreateBy().getId()));
   }
   if (isDataScopeFilter) {
     dc.createAlias("category.office", "categoryOffice").createAlias("createBy", "createBy");
     dc.add(dataScopeFilter(UserUtils.getUser(), "categoryOffice", "createBy"));
   }
   dc.add(Restrictions.eq(Link.FIELD_DEL_FLAG, link.getDelFlag()));
   dc.addOrder(Order.desc("weight"));
   dc.addOrder(Order.desc("updateDate"));
   return linkDao.find(page, dc);
 }
示例#6
0
 @Transactional(readOnly = false)
 public void delete(Link link, Boolean isRe) {
   // dao.updateDelFlag(id, isRe!=null&&isRe?Link.DEL_FLAG_NORMAL:Link.DEL_FLAG_DELETE);
   link.setDelFlag(isRe != null && isRe ? Link.DEL_FLAG_NORMAL : Link.DEL_FLAG_DELETE);
   dao.delete(link);
 }