MigrationSystemCheckOperation.jsp 8.85 KB
<%@ page language="java" contentType="text/html; charset=UTF-8" %><%@ page import="weaver.general.Util,weaver.general.GCONST" %><%@ page import="java.util.*" %><%@ page import="java.io.*" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.upgradetool.dbupgrade.upgrade.DBUpgrade" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.upgradetool.dbupgrade.upgrade.PropUtil" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="org.apache.xmlbeans.impl.regex.Match" %>
<%@ page import="weaver.hrm.UserManager" %>
<%@ page import="weaver.upgradetool.dbupgrade.logger.DBUpgradeLogger" %>
<%@ page import="weaver.templetecheck.*" %>
<%@ page import="org.dom4j.Document" %>
<%@ include file="/system/upgradetoe9/MigrationOperation.jsp"%>
<%
    String operation=Util.null2String(request.getParameter("operation"));//获取执行的动作
    RecordSet rs=new RecordSet();
    if("initfile".equalsIgnoreCase(operation)){//初始化文件
        String path=Util.null2String(request.getParameter("path"));//获得路径名或则是表名\
        try{
            String type="";
            rs.executeQuery("select type from DBUpgradeInitConfig where path=?",path);
            if(rs.next()){
                 type=rs.getString("type");
            }
            if("properties".equalsIgnoreCase(type)){//初始化properties文件
                File file=new File(GCONST.getRootPath()+path);
                if(!file.exists()){
                    JSONObject json=new JSONObject();
                    json.put("status","0");
                    response.getWriter().print(json);
                }else{
                    PropUtil propUtil=PropUtil.getInstance(GCONST.getRootPath()+path.replace("\\","/"));
                    rs.executeQuery("select property,value from DBUpgradeInitConfig where path='"+path+"'");
                    while(rs.next()){
                        String propertyname=Util.null2String(rs.getString("property"));
                        String propertyvalue=Util.null2String(rs.getString("value"));
                        propUtil.put(propertyname,propertyvalue);
                    }
                    propUtil.store();
                }
                JSONObject json=new JSONObject();
                json.put("status","1");
                response.getWriter().print(json);
                return;
            }else if("db".equalsIgnoreCase(type)){//初始化数据库的操作
                RecordSet rs1=new RecordSet();
                rs.executeQuery("select * from DBUpgradeInitConfig where path=?",path);
                while(rs.next()){
                    String propertyname=Util.null2String(rs.getString("property"));
                    String propertyvalue=Util.null2String(rs.getString("value"));
                    rs1.executeQuery("update "+path+" set "+propertyname+"= "+propertyvalue);
                }
                JSONObject json=new JSONObject();
                json.put("status","1");
                response.getWriter().print(json);
                return;
            }

        }catch(Exception e){
            DBUpgradeLogger.write2File("初始化文件错误"+e);
        }
        return;
    }else if("checkfile".equalsIgnoreCase(operation)){//检查模板
        User user=new UserManager().getUserByUserIdAndLoginType(1,"1");
        user.setLanguage(7);
        Map<String,String> params=new HashMap<String,String>();
        params.put("description","");
        params.put("name","检测流程模板");
        params.put("content","");
        params.put("ishtml","0");
        params.put("tabtype","checkhtml");
        params.put("type","1");
        MatchUtil checkUtil=new MatchUtil();
        List<Map<String,String>> list=checkUtil.getMatchResult(user,params,request,response);
        JSONObject json=new JSONObject();
        json.put("status","1");//成功的状态
        json.put("counts",list.size());
        response.getWriter().print(json.toString());
        return;
    }else if("checkconfig".equalsIgnoreCase(operation)){
        //检查文件规范
        StringBuffer checkfileresult=new StringBuffer();
        StringBuffer exitfileresutl=new StringBuffer();
        String migrationtablespath=GCONST.getRootPath() + "system" + File.separatorChar + "upgradetoe9" + File.separatorChar +"resource" + File.separatorChar + "migration.properties";
        PropUtil tableprop=PropUtil.getInstance(migrationtablespath);
        String tablestr=Util.null2String(tableprop.getValues("checkxmlfilepath"));//获得需要检测的xml文件的路径
        if(tablestr.length()>0){
           String[] xmlpaths=tablestr.split(",");
           for (int i=0;i<xmlpaths.length;i++){
             String filepath=xmlpaths[i];
             String filename=filepath.substring(filepath.lastIndexOf("/")+1);
//               DBUpgradeLogger.write2File("检测xml文件名:"+filename);
               FileUtil fileUtil = new FileUtil();
               String isxml = "0";//0  是xml 1;文件不存在  2:xml格式有问题
               try {
//                   DBUpgradeLogger.write2File("检测xml路径:"+GCONST.getRootPath()+filepath);
                   File file = new File(fileUtil.getPath(GCONST.getRootPath()+filepath));
                   if(file.exists()) {
                       ReadXml readxml = new ReadXml();
                       Document doc = readxml.read(file.getPath());
                       if(doc == null) {
//                           DBUpgradeLogger.write2File("检测xml文件名:"+filename+"文件文件格式出现问题");
//                           checkfileresult.append(","+filename+"文件格式不规范");
                           checkfileresult.append(","+filename);
//                           if(checkfileresult.length()>0){
//
//                           }else{
//                               checkfileresult.append(filename);
//                           }
                       }
                   } else {
                      DBUpgradeLogger.write2File("检测xml文件名:"+filename+"文件不存在");
                         exitfileresutl.append(","+filename);//文件不存在的时候
//                       checkfileresult.append(","+filename+"文件不存在");
                   }
               } catch(Exception e) {
//                   checkfileresult.append(","+filename+"文件格式不规范");
                   checkfileresult.append(","+filename);
//                   if(checkfileresult.length()>0){
//                       checkfileresult.append(","+filename);
//                   }else{
//                       checkfileresult.append(filename);
//                   }
                   DBUpgradeLogger.write2File("xml文件规范检测出现错误"+e);
               }
           }
        }

        //检测文件,获得数量
        CheckConfigFile checkConfigFile = new CheckConfigFile();
        ConfigOperation configOperation=new ConfigOperation();

        String ids=Util.null2String(request.getParameter("ids"));
        User user=new UserManager().getUserByUserIdAndLoginType(1,"1");
        user.setLanguage(7);


        Map<String,String> params=new HashMap<String,String>();
        params.put("ids",ids);
        params.put("filetype","0");
        params.put("status","2");
        params.put("filename","");
        params.put("attrname","");
        params.put("attrvalue","");

        int checkcount=0;
        List<Map<String, String>> configlist=configOperation.getConfigFileList(user,params,request,response);
//        DBUpgradeLogger.write2File(configlist.toString());
        for(int i=0 ;i<configlist.size();i++){
            Map<String, String> map = configlist.get(i);
            String isconfiged=Util.null2String(map.get("isconfiged"));
//            DBUpgradeLogger.write2File(isconfiged);
            if(isconfiged.equalsIgnoreCase("否")){
              checkcount++;
            }
        }

//        List<Map<String, String>> list=checkConfigFile.getMatchResult(user,params,request,response);
        JSONObject json=new JSONObject();
        json.put("status","1");//成功的状态
//        json.put("counts",list.size());
        json.put("counts",checkcount);
        String backresulttext="";
        if(checkfileresult.length()>0){
//            backresulttext=checkfileresult.toString();
            backresulttext+=checkfileresult.toString()+"文件格式不规范";
        }
        if(exitfileresutl.length()>0){
            backresulttext=backresulttext+exitfileresutl+"文件不存在";
        }
        DBUpgradeLogger.write2File("检测xml文件名:"+backresulttext);
        json.put("result",backresulttext);
        response.getWriter().print(json.toString());
        return;
    }else if("removesession".equalsIgnoreCase(operation)){
        //session.removeAttribute("weaver_user@bean");
        JSONObject json=new JSONObject();
        json.put("status","1");//成功的状态
        response.getWriter().print(json.toString());
        return;
    }

%>