/** 获得站点列表 */ public static List<Site> getSiteList() { @SuppressWarnings("unchecked") List<Site> siteList = (List<Site>) CacheUtils.get(CMS_CACHE, "siteList"); if (siteList == null) { Page<Site> page = new Page<Site>(1, -1); page = siteService.find(page, new Site()); siteList = page.getList(); CacheUtils.put(CMS_CACHE, "siteList", siteList); } return siteList; }
@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); }
/** * 获得主导航列表 * * @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; }
@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); }
public static List<Dict> getDictList(String type) { @SuppressWarnings("unchecked") Map<String, List<Dict>> dictMap = (Map<String, List<Dict>>) CacheUtils.get(CACHE_DICT_MAP); if (dictMap == null) { dictMap = Maps.newHashMap(); for (Dict dict : dictDao.findAllList(new Dict())) { List<Dict> dictList = dictMap.get(dict.getType()); if (dictList != null) { dictList.add(dict); } else { dictMap.put(dict.getType(), Lists.newArrayList(dict)); } } CacheUtils.put(CACHE_DICT_MAP, dictMap); } List<Dict> dictList = dictMap.get(type); if (dictList == null) { dictList = Lists.newArrayList(); } return dictList; }
public static void putCache(String key, Object value) { CacheUtils.put(CMS_CACHE, key, value); }
/** * 写入SYS_CACHE缓存 * * @param key * @return */ public static void put(String key, Object value) { put(SYS_CACHE, key, value); }