liurunyu
9 天以前 0bd3125739c0d8bded4f7bd405fd99f1723df964
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/util/PrivilegeListener.java
@@ -1,13 +1,10 @@
package com.dy.pmsBase.util;
import com.dy.common.util.ConfigXml;
import com.dy.common.util.MD5;
import com.dy.common.util.NumUtil;
import com.dy.common.webListener.ConfigListener;
import com.dy.pmsGlobal.daoBa.BaPrivilegeMapper;
import com.dy.pmsGlobal.daoBa.BaPrivilegeMapper;
import com.dy.pmsGlobal.pojoBa.BaPrivilege;
import com.dy.pmsGlobal.pojoBa.BaUser;
import org.jdom2.Document;
import org.jdom2.Element;
import org.springframework.beans.factory.annotation.Autowired;
@@ -51,6 +48,7 @@
            if(!this.existPrivileges()){
                this.init(event);
            }
            //this.init(event);
        }
    }
@@ -65,7 +63,7 @@
            Document doc = configXml.createDom(configFileURL) ;
            this.doInit(configXml, doc);
        } catch (Exception e) {
            System.out.println("系统启动时,初始化配置出错 !");
            System.out.println("系统启动时,初始化权限配置出错 !");
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
@@ -80,16 +78,39 @@
                        String num = ele.getAttributeValue("num") ;
                        String name = ele.getAttributeValue("name") ;
                        String type = ele.getAttributeValue("type") ;
                        this.savePrivilege(num, name, type);
                        String typeName = ele.getAttributeValue("typeName") ;
                        this.savePrivilege(num, name, type,typeName);
                    }
                }
            }
        }
    }
    /*
    private void doInit(ConfigXml configXml, Document doc) throws Exception{
        if(configXml != null && doc != null){
            Element prs = configXml.getElement(doc, "config.privileges") ;
            if(prs != null){
                List<Element> list = prs.getChildren() ;
                if(list != null){
                    Long totalInDb = this.countTotalPrivileges() ;
                    if(list.size() != totalInDb){
                        this.deleteAllPrivilegesInDb();
                        for(Element ele : list){
                            String num = ele.getAttributeValue("num") ;
                            String name = ele.getAttributeValue("name") ;
                            String type = ele.getAttributeValue("type") ;
                            String typeName = ele.getAttributeValue("typeName") ;
                            this.savePrivilege(num, name, type,typeName);
                        }
                    }
                }
            }
        }
    }
    *
    /**
     * 数据库中是否存在行政区划数据
     * 数据库中是否存在相关数据
     * @return 存在否
     */
    private boolean existPrivileges(){
@@ -97,14 +118,29 @@
        return (total != null && total > 0) ;
    }
    /**
     * 数据库中是否存在相关数据
     * @return 存在否
     */
    private Long countTotalPrivileges(){
        return this.privilegeDao.selectCount() ;
    }
    /**
     * 数据库中是否存在相关数据
     * @return 存在否
     */
    private void deleteAllPrivilegesInDb(){
        this.privilegeDao.deleteAll() ;
    }
    /**
     * 保存权限
     * @param name 编码
     * @param name 名称
     * @param type 类型
     */
    private void savePrivilege(String num, String name, String type) throws Exception{
    private void savePrivilege(String num, String name, String type,String typeName) throws Exception{
        if((num != null && !num.trim().equals("")) &&
                (name != null && !name.trim().equals("")) &&
                (type != null && !type.trim().equals(""))){
@@ -113,6 +149,7 @@
                po.num = Integer.parseInt(num) ;
                po.name = name ;
                po.type = Integer.parseInt(type) ;
                po.typeName = typeName ;
                this.privilegeDao.insertSelective(po) ;
            }
        }