/**
 * 超时定时器初始化操作
 *
 * @author Administrator
 */
public class OnExpireCreateListener implements ExecutionListener {

  private static final long serialVersionUID = 1L;
  private ProjectService projectService = SpringContextHolder.getBean(ProjectService.class);

  @Override
  public void notify(DelegateExecution execution) throws Exception {

    System.out.println(execution.getCurrentActivityName() + ":" + execution.getEventName());
    ;
    String projectID = execution.getProcessBusinessKey();

    FundProject project = projectService.get(projectID);

    // 初始化执行时间
    execution.setVariable("duration", getISO8601(project.getDuration()));
  }

  private String getISO8601(Object duration) {
    return "PT" + duration.toString() + "M";
  }
}
예제 #2
0
/**
 * 内容管理工具类
 *
 * @author ThinkGem
 * @version 2013-5-29
 */
public class CmsUtils {

  private static SiteService siteService = SpringContextHolder.getBean(SiteService.class);
  private static CategoryService categoryService =
      SpringContextHolder.getBean(CategoryService.class);
  private static ArticleService articleService = SpringContextHolder.getBean(ArticleService.class);
  private static LinkService linkService = SpringContextHolder.getBean(LinkService.class);

  private static final String CMS_CACHE = "cmsCache";

  /** 获得站点列表 */
  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;
  }

  /**
   * 获得站点信息
   *
   * @param id 站点编号
   */
  public static Site getSite(long siteId) {
    long id = 1L;
    if (siteId > 0) {
      id = siteId;
    }
    for (Site site : getSiteList()) {
      if (site.getId() == id) {
        return site;
      }
    }
    return new Site(id);
  }

  /**
   * 获得主导航列表
   *
   * @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;
  }

  /**
   * 获取栏目
   *
   * @param id 栏目编号
   * @return
   */
  public static Category getCategory(long categoryId) {
    return categoryService.get(categoryId);
  }

  /**
   * 获得栏目列表
   *
   * @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();
  }

  /**
   * 获取栏目
   *
   * @param ids 栏目编号
   * @return
   */
  public static List<Category> getCategoryListByIds(String categoryIds) {
    return categoryService.findByIds(categoryIds);
  }

  /**
   * 获取文章
   *
   * @param id 文章编号
   * @return
   */
  public static Article getArticle(long articleId) {
    return articleService.get(articleId);
  }

  /**
   * 获取文章列表
   *
   * @param siteId 站点编号
   * @param categoryId 分类编号
   * @param number 获取数目
   * @param param 预留参数,例: key1:'value1', key2:'value2' ... posid 推荐位(1:首页焦点图;2:栏目页文章推荐;) image
   *     文章图片(1:有图片的文章) orderBy 排序字符串
   * @return
   */
  public static List<Article> getArticleList(
      long siteId, long categoryId, int number, String param) {
    Page<Article> page = new Page<Article>(1, number, -1);
    Article article = new Article(new Category(categoryId, new Site(siteId)));
    if (StringUtils.isNotBlank(param)) {
      @SuppressWarnings({"rawtypes"})
      Map map = JsonMapper.getInstance().fromJson("{" + param + "}", Map.class);
      if (new Integer(1).equals(map.get("posid")) || new Integer(2).equals(map.get("posid"))) {
        article.setPosid(String.valueOf(map.get("posid")));
      }
      if (new Integer(1).equals(map.get("image"))) {
        article.setImage(Article.YES);
      }
      if (StringUtils.isNotBlank((String) map.get("orderBy"))) {
        page.setOrderBy((String) map.get("orderBy"));
      }
    }
    article.setDelFlag(Article.DEL_FLAG_NORMAL);
    page = articleService.find(page, article, false);
    return page.getList();
  }

  /**
   * 获取链接
   *
   * @param id 文章编号
   * @return
   */
  public static Link getLink(long linkId) {
    return linkService.get(linkId);
  }

  /**
   * 获取链接列表
   *
   * @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();
  }

  // ============== Cms Cache ==============

  public static Object getCache(String key) {
    return CacheUtils.get(CMS_CACHE, key);
  }

  public static void putCache(String key, Object value) {
    CacheUtils.put(CMS_CACHE, key, value);
  }

  public static void removeCache(String key) {
    CacheUtils.remove(CMS_CACHE, key);
  }
}
예제 #3
0
/**
 * 字典工具类
 *
 * @author ThinkGem
 * @version 2013-5-29
 */
public class DictUtils {

  private static DictDao dictDao = SpringContextHolder.getBean(DictDao.class);

  public static final String CACHE_DICT_MAP = "dictMap";

  public static String getDictLabel(String value, String type, String defaultValue) {
    if (StringUtils.isNotBlank(type) && StringUtils.isNotBlank(value)) {
      for (Dict dict : getDictList(type)) {
        if (type.equals(dict.getType()) && value.equals(dict.getValue())) {
          return dict.getLabel();
        }
      }
    }
    return defaultValue;
  }

  public static String getDictLabels(String values, String type, String defaultValue) {
    if (StringUtils.isNotBlank(type) && StringUtils.isNotBlank(values)) {
      List<String> valueList = Lists.newArrayList();
      for (String value : StringUtils.split(values, ",")) {
        valueList.add(getDictLabel(value, type, defaultValue));
      }
      return StringUtils.join(valueList, ",");
    }
    return defaultValue;
  }

  public static String getDictValue(String label, String type, String defaultLabel) {
    if (StringUtils.isNotBlank(type) && StringUtils.isNotBlank(label)) {
      for (Dict dict : getDictList(type)) {
        if (type.equals(dict.getType()) && label.equals(dict.getLabel())) {
          return dict.getValue();
        }
      }
    }
    return defaultLabel;
  }

  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;
  }
}
예제 #4
0
 /** 获取系统业务对象 */
 public SystemService getSystemService() {
   if (systemService == null) {
     systemService = SpringContextHolder.getBean(SystemService.class);
   }
   return systemService;
 }