/* (非 Javadoc)
  * <p>Title: delFunction</p>
  * <p>Description: 删除程式</p>
  * @param id
  * @return
  */
 public boolean delFunction(Integer id) {
   String hql = " from Permission t where t.status='A' and t.pid=" + id;
   List<Permission> list = permissionPublicDao.find(hql);
   if (list.size() != 0) {
     return false;
   } else {
     Permission function = permissionPublicDao.get(Permission.class, id);
     function.setStatus(Constants.PERSISTENCE_DELETE_STATUS);
     function.setLastmod(new Date());
     function.setModifyer(Constants.getCurrendUser().getUserId());
     permissionPublicDao.deleteToUpdate(function);
     return true;
   }
 }
  /* (非 Javadoc)
   * <p>Title: persistenceFunction</p>
   * <p>Description:持久化程式 </p>
   * @param list
   * @return
   */
  public boolean persistenceFunction(List<Permission> list) {
    logger.debug("f");
    Integer userId = Constants.getCurrendUser().getUserId();
    for (Permission function : list) {
      function.setLastmod(new Date());
      function.setModifyer(userId);
      if (Constants.TREE_GRID_ADD_STATUS.equals(function.getStatus())) {
        function.setPermissionId(null);
        function.setCreated(new Date());
        function.setLastmod(new Date());
        function.setModifyer(userId);
        function.setCreater(userId);
        function.setStatus(Constants.PERSISTENCE_STATUS);
      }

      permissionPublicDao.saveOrUpdate(function);
    }
    return true;
  }
 public List<TreeModel> findAllFunctionList() {
   String hql = "from Permission t where t.status='A' and t.type='F' ";
   List<Permission> list = permissionPublicDao.find(hql);
   List<TreeModel> tempList = new ArrayList<TreeModel>();
   for (Permission function : list) {
     TreeModel treeModel = new TreeModel();
     treeModel.setId(function.getPermissionId().toString());
     treeModel.setPid(function.getPid() == null ? "" : function.getPid().toString());
     treeModel.setName(function.getName());
     treeModel.setIconCls(function.getIconCls());
     treeModel.setState(Constants.TREE_STATUS_OPEN);
     tempList.add(treeModel);
   }
   return tempList;
 }
  /* (非 Javadoc)
   * <p>Title: persistenceFunction</p>
   * <p>Description: 持久化程式弹窗模式</p>
   * @param permission
   * @return
   */
  public boolean persistenceFunction(Permission permission) {
    Integer userId = Constants.getCurrendUser().getUserId();
    if (null == permission.getPermissionId() || "".equals(permission.getPermissionId())) {
      permission.setCreated(new Date());
      permission.setLastmod(new Date());
      permission.setCreater(userId);
      permission.setModifyer(userId);
      permission.setStatus(Constants.PERSISTENCE_STATUS);
      if (Constants.IS_FUNCTION.equals(permission.getType())) {
        permission.setState(Constants.TREE_STATUS_CLOSED);
      } else {
        permission.setState(Constants.TREE_STATUS_OPEN);
      }
      permissionPublicDao.save(permission);
    } else {
      if (Constants.IS_FUNCTION.equals(permission.getType())) {
        permission.setState(Constants.TREE_STATUS_CLOSED);
      } else {
        permission.setState(Constants.TREE_STATUS_OPEN);
      }

      permission.setLastmod(new Date());
      permission.setModifyer(userId);
      permissionPublicDao.update(permission);
    }
    return true;
  }