zoukankan      html  css  js  c++  java
  • 最近开发的一个文档管理系统

    最近在琢磨着开发一个文档管理系统。 打算用之前配置的ssh的基本框架来搭建,配合刚学一点皮毛的extjs。首先看一下大致的界面效果

    大致说明下程序的组织结构:

    后端:采用spring+hibernate+struts2的框架设置,这个框架是之前开发别的系统中使用的,这里继续沿用。在项目的具体的实现中其实只用了登录,注册这些基本的功能。关于框架的配置部分不再赘述。讲一点自己的心得体会。在开发过程中,我喜欢将通用的东西,写到单独的包中,以便以后可以沿用。目前简单的编写了json,session,filter,interceptor,dao(基本的dao层),xml,util等层。感觉确实在项目移植中起到了很好的简化作用。之后将举其中一例说明。

    前端:extjs框架,目前采用开发的方法大致是js+html,通常在我的html中,

    <script type="text/javascript" src="./common/main.js"></script>
            <script type="text/javascript" src="./common/uploadfile.js"></script>
            <script type="text/javascript" src="./common/highsearch.js"></script>
             
            <script type="text/javascript">
            //document.execCommand("BackgroundImageCache", false, true)
            var curpath;//全局变量
            Ext.onReady(function(){
                new Ext.clNameSpace.topBar({
                    renderTo:'topbar-div'
                });
                new Ext.clNameSpace.mainPanel({
                    renderTo:'main-div'
                });    
              
            });

      会这样编写,具体的panel继承编写,并在html中引用。调用Ext.onReady方法进行相应的呈现。 目前的缺点是,panel比较复杂,代码量比较大,重用的代码风格不是很好。 下面也会对其进行举例介绍。

    前面提到过,我将后端代码可以重用的部分抽象出来,方便代码重用,而这个可重用的类,统一放在comm的包里面。举个例子, 在进行ssh开发的时候,我们通常对dao层会进行基本的抽象。

    复制代码
    public interface IBaseDao<T> {
    
        public T getById(java.io.Serializable id);
        public List<T> getAll();
        public List<T> getByProperty(String property,Object value);
        public List<T> getByExample(T example);
        public void delete(T entity);
        public void update(T entity);
        public java.io.Serializable save(T entity);
        public T load(Class entityClass,java.io.Serializable id);
        public List<T> getAllWithCache();
        public List<T> getByPage(String hql,int beginIndex,int everyPage);
        
    }
    复制代码

    首先创建如上的泛型接口,之后创建相对应的BaseDao抽象类

    复制代码
    public abstract class BaseDao<T> extends HibernateDaoSupport implements IBaseDao<T>{
        
        public List<T> getByPage(final String hql, final int beginIndex, final int everyPage) {
            // TODO Auto-generated method stub
            return super.getHibernateTemplate().executeFind(new HibernateCallback(){
                public Object doInHibernate(Session session) throws HibernateException,SQLException{
                    Query query = session.createQuery(hql);
                    query.setFirstResult(beginIndex);
                    query.setMaxResults(everyPage);
                    return query.list();
                }
            });
            
        }
    复制代码

    具体的实现,我们不做过多介绍,这样实现的好处是,在我们具体的业务层实现的时候,可以继承这个BaseDao类,从而节省基本的增删改查的编写。提高一些效率。

    同样对于filter,比如我们的loginfilter,characterEncodingFilter等都可以抽象出来,对于不同的项目稍作修改即可满足要求。而xml更是我们常用的功能了,这部分也要抽象出来。

    上面是对自己框架的一些简单介绍,刚工作不久,里面肯定存在很多问题。

    下面这部分是我们业务核心文件的管理功能, 对于开发这样的文件管理系统,不知道各位有什么真知灼见。我这里采用最简单的方法。之前有对linux文件系统进行了解,但是因为时间有限。我只做了一小步来模拟文件系统。对于每个文件夹,我采用自己的一个单独的文件进行目录的管理,作为我的系统文件,名字是abcdeedcba.data ,在这个文件中,我们保存系统目录和文件的属性,方便以后的信息阅读和检索。而目录和文件是不同的信息,我们用两个类来实现

    复制代码
    /**
     * 目录信息
     * @author chilei 
     *
     */
    public class DirectoryInfor implements Serializable{
        
        private String dirName;
        private String dirPath;
    复制代码

    文件信息

    复制代码
    /**
     * 文件信息
     * @author chilei
     *
     */
    public class FileInfor implements Serializable{
        
        private String fileName;
        private String filePath;
        private String fileTitle;
        private String keywords;
        private String describe;
        private String filemaster;
        private int downloadtimes;
        private Date uploadtime;
        private String fileSize;
        private String fileType;
        private int version;
        private String versionDescribe;
    复制代码

    对于上传,下载这些操作,我用一个管理类来实现,这类简单的采用了synchronized来做多线性的互斥。效率不高。有待改进,

    复制代码
    */
    public class DirMgr {
    
        private static final String inforFileName = "abceddecba.data";
        private static final String rootPath = SysInfo.rootpath;
    
        /**
         * 初始化
         * 
         * @param path
         * @throws Exception
         */
        public static void dirInit(String path) throws Exception {
            DirectoryInfor result = new DirectoryInfor();
    
            File file = new File(path);
            String[] filea = path.split("\\" + File.separator);
            String tName = filea[filea.length - 1];
            // System.out.println(tName);
            File[] subFile = file.listFiles();
            List<DirectoryInfor> dirList = new ArrayList<DirectoryInfor>();
            List<FileInfor> fileList = new ArrayList<FileInfor>();
            if (subFile != null) {
                for (int i = 0; i < subFile.length; i++) {
    
                    // 目录or文件
                    if (subFile[i].isDirectory()) {
                        // System.out.println(subFile[i]);
                        String[] tmpInfor = subFile[i].toString().split(
                                "\\" + File.separator);
                        DirectoryInfor tmp = new DirectoryInfor();
                        if (tmpInfor.length > 0) {
                            String dirName = tmpInfor[tmpInfor.length - 1];
                            tmp.setDirName(dirName);
                        }
    
                        tmp.setDirPath(subFile[i].toString());
                        dirList.add(tmp);
    
                    } else {
    
                    }
                }
                result.setDirList(dirList);
                result.setDirName(tName);
                result.setDirPath(path);
            }
            // 文件流
            FileOutputStream outstream = new FileOutputStream(path + File.separator
                    + inforFileName);
            ObjectOutputStream out = new ObjectOutputStream(outstream);
            out.writeObject(result);
            out.close();
    
        }
    
        /**
         * 反序列化
         * 
         * @param path
         * @return
         * @throws Exception
         */
        public static synchronized DirectoryInfor dirDeserialize(String path)
                throws Exception {
            File abcde = new File(path + File.separator + inforFileName);
            if (!abcde.exists()) {
                dirInit(path);
            }
            FileInputStream instream = new FileInputStream(path + File.separator
                    + inforFileName);
            ObjectInputStream in = new ObjectInputStream(instream);
            DirectoryInfor result = (DirectoryInfor) in.readObject();
    
            return result;
        }
    
        /**
         * 往已有的目录中增加目录
         * 
         * @param parentPath
         * @param dirName
         * @throws Exception
         */
        public synchronized static boolean addDir(String parentPath, String dirName)
    复制代码

    没有贴完整代码,这样实现的原因,我考虑一是可以比较方便的进行扩展,二是,我们要保存一些文件关键词,下载次数等。 这些信息存放在数据库中也不见得效率特别高。主要对于每个子目录的文件个数应该也不是特别多。

    之后我考虑的一个问题是如何进行文件的检索,目前是分两种情况,已经知道目录,和未知道目录,前一种只要在该目录底下,分析abcdeedcba.data文件既可以找到我们的文件,而后一种需要从根目录来检索。这样如果我们简单的进行顺序检索,效率应当很低,知道我们应采用一种树形结构来建立相关索引。目前考虑红黑树或者B树,(这部分尚未开发,正在开发中)。

    对于文件下载,之前做项目的时候,都是直接给出<href>的链接,感觉这样不是特别好,而且经常容易出现文件直接打开的情况,还暴露自己的程序目录,增加了系统的隐患。这次采用流的方式实现的。将文件内容转换为inputStream这样的流格式。有关这部分,请参照流文件下载。 感觉这样仍然不是特别号,目前也正在考虑中。

    最后还实现了预览一部分文件的功能,用了flexpaper控件,这部分比较没有技术含量,就是文件->pdf->swf文件三种格式之间的转换。效果就是类似百度文库的那样的效果。

    OK,简单介绍了自己开发的系统,不知道各位是否有收获。 

    下一步考虑的事情: 全文检索和 利用hadoop来进行分布式开发配置,   比如多人同时在线修改同一个文件等这样的功能。

    发此文的目的就是:不知道这样的系统是否有一定的应用价值呢?是否有人愿意一起同我把这系统做做?

                                                                      迷茫困惑

                                                                            化蛹成蝶

    http://www.cnblogs.com/snail-tomorrow/archive/2012/12/13/2816729.html

  • 相关阅读:
    上百个Linux、BSD、Unix学习电子书+视频下载汇总
    测试管理杂谈之理论篇
    浅谈软件测试思维
    细节决定完美——色彩在测试工作中的应用
    图像视频测试基础
    [转]什么是三码、五码机?
    一组经典测试思想观点
    关于LCD分辨率、色素相关知识介绍
    QTP 学习视频汇总
    【诗词涂鸦】满江红 别情
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2817954.html
Copyright © 2011-2022 走看看