Ejemplo n.º 1
0
  /** 下载文件 */
  public void downloadFile(
      String delIds, Boolean overlay, HttpServletResponse response, HttpServletRequest request)
      throws Exception {
    ArrayList<File> files = this.loadFileByIds(delIds);

    for (File file : files) {
      FileUtil.downloadFile(file, response, request);
    }
  }
Ejemplo n.º 2
0
 /** 分页加载所有文件; */
 @SuppressWarnings("unchecked")
 public ArrayList<FileBean> loadPageFile(PageBean pageBean, HttpSession httpSession) {
   User u = (User) httpSession.getAttribute("u");
   Query q =
       sessionFactory
           .getCurrentSession()
           .createQuery("from File file where file.user.id=" + u.getId());
   q.setFirstResult(pageBean.getStart());
   q.setMaxResults(pageBean.getRows());
   ArrayList<com.ligongcloud.model.File> files = (ArrayList<com.ligongcloud.model.File>) q.list();
   ArrayList<FileBean> fileBeans = FileUtil.formatFile(files);
   return fileBeans;
 }
Ejemplo n.º 3
0
  /** 查询文件; */
  @SuppressWarnings("unchecked")
  public ArrayList<FileBean> searchFile(
      String name,
      String s_screateDate,
      String s_ecreateDate,
      PageBean pageBean,
      HttpSession httpSession)
      throws Exception {
    User u = (User) httpSession.getAttribute("u");

    StringBuffer sqlBuffer =
        new StringBuffer("from File file where file.user.id=" + u.getId() + " ");

    if (StringUtil.isNotEmpty(name)) {
      sqlBuffer.append("and file.name = '" + name + "' ");
    }

    if (StringUtil.isEmpty(s_screateDate)) {
      s_screateDate = "2010-01-01";
    }

    if (StringUtil.isEmpty(s_ecreateDate)) {
      // 如果s_ejoindate为空,设s_ejoindate为当前系统时间
      SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
      s_ecreateDate = df.format(new Date());
    }

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 小写的mm表示的是分钟
    Date begin = sdf.parse(s_screateDate);
    Date end = sdf.parse(s_ecreateDate);

    sqlBuffer.append("and file.createDate > :beginTime and file.createDate <= :endTime");
    Query q =
        sessionFactory
            .getCurrentSession()
            .createQuery(sqlBuffer.toString())
            .setTimestamp("beginTime", begin)
            .setTimestamp("endTime", end);
    q.setFirstResult(pageBean.getStart());
    q.setMaxResults(pageBean.getRows());

    ArrayList<File> files = (ArrayList<File>) q.list();
    ArrayList<FileBean> fileBeans = FileUtil.formatFile(files);
    return fileBeans;
  }
Ejemplo n.º 4
0
  /** 删除文件(一定要注意删除本地本件和删除数据库中数据的先后顺序) */
  @SuppressWarnings("unchecked")
  public int deleteFile(String delIds, HttpSession httpSession) {
    // 注意:要先找出这些文件,根据数据库中的数据进行本地文件的删除,若先删除数据库中的数据,就没有映射进行本地文件的删除了
    // 删除本地文件(即删除网盘中的文件)
    Query q =
        sessionFactory
            .getCurrentSession()
            .createQuery("from File file where file.id in (" + delIds + ")");
    ArrayList<File> files = (ArrayList<File>) q.list();
    String fileName;
    for (File file : files) {
      fileName = file.getLocation() + "a";
      FileUtil.deleteFile(fileName);
    }
    // 删除数据库中的映射
    Query queryu =
        sessionFactory
            .getCurrentSession()
            .createQuery("delete File file where file.id in (" + delIds + ")");
    queryu.executeUpdate();

    return 1;
  }