Example #1
0
 /**
  * 获得栏目列表
  *
  * @param siteId 站点编号
  * @param parentId 分类父编号
  * @param number 获取数目
  * @param param 预留参数,例: key1:'value1', key2:'value2' ...
  */
 public static List<Category> getCategoryList(
     long siteId, long parentId, int number, String param) {
   Page<Category> page = new Page<Category>(1, number, -1);
   Category category = new Category();
   category.setSite(new Site(siteId));
   category.setParent(new Category(parentId));
   if (StringUtils.isNotBlank(param)) {
     @SuppressWarnings({"unused", "rawtypes"})
     Map map = JsonMapper.getInstance().fromJson("{" + param + "}", Map.class);
   }
   page = categoryService.find(page, category);
   return page.getList();
 }
Example #2
0
 /**
  * 获得主导航列表
  *
  * @param siteId 站点编号
  */
 public static List<Category> getMainNavList(long siteId) {
   @SuppressWarnings("unchecked")
   List<Category> mainNavList =
       (List<Category>) CacheUtils.get(CMS_CACHE, "mainNavList_" + siteId);
   if (mainNavList == null) {
     Category category = new Category();
     category.setSite(new Site(siteId));
     category.setParent(new Category(1L));
     category.setInMenu(Category.SHOW);
     Page<Category> page = new Page<Category>(1, -1);
     page = categoryService.find(page, category);
     mainNavList = page.getList();
     CacheUtils.put(CMS_CACHE, "mainNavList_" + siteId, mainNavList);
   }
   return mainNavList;
 }
Example #3
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);
 }
Example #4
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);
 }