TempleteSyncTools.jsp 20.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="/systeminfo/init_wev8.jsp" %>
<%@ page import="weaver.hrm.*" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="java.util.Properties" %>
<%@ page import="weaver.templetecheck.filecheck.TempleteSyncToolsPropBean" %>
<%@ page import="com.weaver.function.ConfigInfo" %>
<html>
<head>
        <%
// 增加参数判断缓存
response.setHeader("cache-control", "no-cache");
response.setHeader("pragma", "no-cache");
response.setHeader("expires", "Mon 1 Jan 1990 00:00:00 GMT");
%>

        <%
            int userid = user.getUID();
            if(userid!=1) {
                response.sendRedirect("/notice/noright.jsp");
                return;
            }
 %>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <title>模板同步迁移</title>
        <link rel="stylesheet" href="/wui/theme/ecology8/jquery/js/zDialog_e8_wev8.css" type="text/css" />
        <script language="javascript" src="/wui/theme/ecology8/jquery/js/zDialog_wev8.js"></script>
        <script language="javascript" src="/wui/theme/ecology8/jquery/js/zDrag_wev8.js"></script>
        <LINK href="/css/Weaver_wev8.css" type=text/css rel=STYLESHEET>
        <SCRIPT language="javascript" src="/js/weaver_wev8.js"></script>
        <script language="javascript">
            /*jQuery(document).ready(function(){
                wuiform.init();
            });*/
        </script>
        <style type="text/css">
            *{
                font-family:"微软雅黑"!important;
                color: #3f3f3f;
            }
            TABLE {
                FONT-SIZE: 9pt;
                FONT-FAMILY: Verdana;
                width: 100%;
            }
            BODY {
                FONT-SIZE: 9pt;
                MARGIN: 0px;
                FONT-FAMILY: Verdana;
                LIST-STYLE-TYPE: circle;
            }
            table input{
                border: 1px solid #ccc!important;
                border-radius: 3px;/* !*css3属性IE不支持*!*/
                padding: 6px 0px 5px 10px;
            }
            #dbform{
                width: 100%;
                height:auto;
                vertical-align:center;
                font-weight: bold;
            }
            .btn-primary{
                height: 35px;
                text-decoration:none;
                background:#337AB7;
                color:#f2f2f2;
                padding: 5px 20px 5px 20px;
                font-size:16px;
                font-family: 微软雅黑,宋体,Arial,Helvetica,Verdana,sans-serif;
                /*font-weight:bold;*/
                border-radius:5px;
                -webkit-transition:all linear 0.10s;
                -moz-transition:all linear 0.10s;
                transition:all linear 0.10s;
            }
            .btn-disabled {
                height: 35px;
                text-decoration: none;
                background: #959595;
                color: black;
                padding: 5px 20px 5px 20px;
                font-size: 16px;
                font-family: 微软雅黑, 宋体, Arial, Helvetica, Verdana, sans-serif;
                /*font-weight:bold;*/
                border-radius: 5px;

                -webkit-transition: all linear 0.10s;
                -moz-transition: all linear 0.10s;
                transition: all linear 0.10s;

            }
            .btn-primary:hover{ background:#286090;}
            #messagediv {border-radius:10px;border:1px solid;margin-top:1%;padding:1%;background-color:#FFFFCC }
        </style>

        <script language="javascript" type="text/javascript">
            jQuery(document).ready(function(){
                changeTestConnButton('disable');
                initDetailProcess();
            });
        </script>
    </head>
        <%
        RecordSet rs = new RecordSet();
        TempleteSyncToolsPropBean propBean = TempleteSyncToolsPropBean.getInstance();
        Properties prop = propBean.getProperties();
        String dbserver = Util.null2String(prop.getProperty("dbserver"));
        String dbport = Util.null2String(prop.getProperty("dbport"));
        String dbname = Util.null2String(prop.getProperty("dbname"));
        String username = Util.null2String(prop.getProperty("username"));
        String dbtype = Util.null2String(prop.getProperty("dbtype"));
        if("".equals(dbtype)){
            dbtype=rs.getDBType().toLowerCase();
        }
        if("".equals(dbport)){
            if(dbtype.equals("sqlserver")){
                dbport="1433";
            }else if(dbtype.equals("oracle")){
                dbport="1521";
            }
        }

%>
<body>
<iframe name="downiframe" id="downiframe" src="" style="display:none" ></iframe>
    <form name="weaver" method="post" enctype="multipart/form-data" target="_self" action="">
        <table style="padding: 0px;margin: 0px;width: 100%;height:70%;">
            <colgroup>
                <col width="40%">
                <col width="60%">
            </colgroup>
            <tbody>
            <tr>
                <td >
                    <div >
                            <table id="dbform" cellspacing="10px" cellpadding="5px">
                                <colgroup>
                                    <col width="30%">
                                    <col width="70%">
                                </colgroup>
                                <tbody>
                                <th class=Separator>
                                <td style="height: 10px" ><h1>源数据库参数设置</h1></td>
                                </th>
                                <tr>
                                    <td >验证码:   </td>
                                    <td><input id="verifycode"  type="password" name="verifycode" value="" maxlength=16 size=40></td>
                                </tr>
                                <tr>
                                    <td>数据库类型:</td>
                                    <td>
                                        <select id="dbtype" name="dbtype" onchange="changeDBType()">
                                            <option value="1" <% if(dbtype.toLowerCase().equals("sqlserver")) {%>selected<%}%>>SqlServer</option>
                                            <option value="2" <% if(dbtype.toLowerCase().equals("oracle")) {%>selected<%}%>>Oracle</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>数据库服务器IP:</td>
                                    <td><input type="text" id="dbserver" name="dbserver" maxlength="40" value="<%=dbserver%>"  size="40"></td>
                                </tr>
                                <tr>
                                    <td>数据库端口号:</td>
                                    <td><input type="text" id="dbport"  name="dbport" maxlength="40" size="40" value="<%=dbport%>"></td>
                                </tr>
                                <tr>
                                    <td>数据库名称:</td>
                                    <td><input type="text" id="dbname"  name="dbname" maxlength="40" size="40" value="<%=dbname%>"></td>
                                </tr>
                                <tr>
                                    <td>用户名:</td>
                                    <td><input type="text" id="username" name="username" maxlength="40" size="40" value="<%=username%>"></td>
                                </tr>
                                <tr>
                                    <td>密码:</td>
                                    <td><input type="password" id="password" name="password" maxlength="40" size="40" value=""></td>
                                </tr>
                                <tr>
                                    <td>操作:</td>
                                    <td><input type="button"  id="testConn" class="btn-primary"  value="测试数据库连接" onclick="testConnection()" />
                                        <span id="submittips"  style=" font-weight:bold;font-size:larger;color:red;margin-left: 10px"></span>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                    </div>
                </td>

                <td  style="border:0px solid #f8f8f8;" >
                    <div style="width:100%;height:100%;">
                        <div id="consolediv" style="width:100%;height:80%;float:left;margin:0 auto;">
                            <div style="margin-top:1%;">
                                <span style="width: 100%;height:30px;">
                                    <span style="height:26px;background-color:#1A57A0;color:white;display:inline-block;font-size:18px;width:100%;border-top-left-radius:8px;border-top-right-radius:8px;">&nbsp;&nbsp;实时同步日志
                                        <button type="button" style="float:right;height:20px;margin:3px 10px auto auto"  id="syncBtn" onclick="startSync()" name="开始迁移" >开始同步</button></span>
                                </span>
                                <textarea id="logarea1" style="padding:10px;width: 100%;height: 100%;min-height:400px;background-color: white;color: black;display:block;box-sizing:border-box"></textarea>
                            </div>
                        </div>
                    </div>

                </td>
            </tr>
            <TR>
                <TD colspan="2">
                    <div id="messagediv" style="margin-bottom: 5px;">
                            <span style="color:red">
                                <b>操作步骤:</b><br>
                                1.输入源数据库参数信息,点击“测试数据库连接”按钮,查看是否可以正常连接<br>
                                2.提示“连接成功”后,点击“开始同步”按钮即可<br>
                                <br>
                                <b>说明及注意事项:</b><br>
                                1.该功能是将源数据库表数据同步到当前数据库中,同步内容可在\templetecheck\filecheck\templeteSync.xml文件中配置<br>
                                2.同步过程中如果更新失败或出现异常,会记录在日志信息中,同步动作不会中断<br>
                                3.同步过程涉及的日志可在\log\templetesync\日期.log文件中查看,同时会在右侧窗口中动态显示<br>
                                4.特别注意:该工具只用做检测内容相关数据的迁移,如开发的js代码,html代码等,并不会迁移模板所有属性内容<br>
                            </span>
                        <br><b>版本信息</b><br>
                        V<%=ConfigInfo.getToolVersion() %>
                    </div>
                </TD>
            </TR>
            </tbody>
        </table>
    </form>
</body>
</html>

<script type="text/javascript">
    var source_status=0;//数据库信息是否填写正确的状态
    var isSyncing=0;
    var logintervaltime  = 1000;
    var detailProcessInterval;
    var firstGetLog="1";
    var atuoScrollLog = true;
    var syncStatus=0;


    //获取当前同步状态
    function initDetailProcess(){
        $.ajax({
            dataType:'json',
            type:'post',
            url:'TempleteSyncToolsOperation.jsp',
            data:{
                "method":"getCurrentSyncStatus",
            },
            success:function(data){
                var status = data.status;
                if(status=='success'){
                    syncStatus = data.syncStatus;
                    if(syncStatus==1){
                        changeTestConnButton('disable');
                        loadingLog();
                        $("#syncBtn").attr("disabled", true);
                        isSyncing=1;
                        clearIntarvals();
                        initIntervals();
                    } else if(syncStatus==2){
                        loadingLog();
                        resetSyncStatus();
                        changeTestConnButton('enable');
                        source_status=0;
                        isSyncing=0;
                        $("#syncBtn").attr("disabled", false);
                        loadingLog();
                        clearIntarvals();
                    }else{
                        changeTestConnButton('enable');
                        $("#syncBtn").attr("disabled", false);
                        isSyncing=0;
                        loadingLog();
                        clearIntarvals()
                    }
                }
            },
            error:function () {
            }
        });
    }

    //初始化定时器
    function initIntervals() {
        var intervaltime  = 3000;
        detailProcessInterval = setInterval('initDetailProcess()',intervaltime);
    }
    //清空定时器
    function clearIntarvals() {
        clearInterval(detailProcessInterval);
    }

    function loadingLog() {
        $.ajax({
            dataType:'json',
            type:'post',
            url:'TempleteSyncToolsOperation.jsp',
            data:{
                "method":"getLog",
                "firstGetLog": firstGetLog
            },
            success:function(data){
                var loginfo = data.loginfo;
                if(firstGetLog=='1'){
                    firstGetLog = "0";
                    loginfo="";
                }

                if(loginfo.trim()!=''){
                    appendDetailLog("" + loginfo)
                    scrollLog();
                }
                //setTimeout('loadingLog()', logintervaltime);
            },
            error:function (XMLHttpRequest, textStatus) {
                if(textStatus=='parsererror'){
                    firstGetLog = "0";
                    var loginfo = "====error:loadingLog获取实时日志出现错误,服务未停情况下,不影响程序往下执行";
                    if(loginfo.trim()!=''){
                        appendDetailLog("" + loginfo)
                        scrollLog();
                    }
                }else{
                    clearIntarvals();
                }
            }
        });
    }

    //向文本框中添加日志
    function appendDetailLog(str){
        if(str.length==0){
            return;
        }
        var old = document.getElementById("logarea1").value.trim();
        if(old.length>50000){
            old = old.substring(old.length-40000);
        }

        document.getElementById("logarea1").value=old +"\n"+str;
        scrollLog();
    }


    //滚动日志
    function scrollLog() {
        if(atuoScrollLog){
            var obj = document.getElementById("logarea1");
            obj.scrollTop = obj.scrollHeight;
        }
    }

    //清空定时器
    function clearIntarvals() {
        clearInterval(detailProcessInterval);
    }

    function resetSyncStatus() {
        $.ajax({
            dataType:'json',
            type:'post',
            url:'TempleteSyncToolsOperation.jsp',
            data:{
                "method":"resetSyncStatus",
            },
            success:function(data){
            },
            error:function () {
            }
        });
    }

    //开始同步
    function startSync(){
        if(isSyncing==0){
            isSyncing=1;
        }else {
            top.Dialog.alert("正在迁移中,请稍等...")
            return;
        }
        if(source_status==0){
            top.Dialog.alert("请测试源数据库连接");
            isSyncing=0;
            return;
        }else {
            isSyncing=1;
            //$("#submittips").show();
            appendDetailLog("正在准备同步...")
            initIntervals();
            $.ajax({
                sync: true,
                dataType: 'json',
                type: 'post',
                url: 'TempleteSyncToolsOperation.jsp?method=startSync',
                // timeout : 5000,
                data: { },
                success: function (data) {
                    isSyncing=0;
                    return;
                },
                error: function () {
                    isSyncing=0;
                    alert("数据同步失败");
                    resetSyncStatus();
                    clearIntarvals();
                    changeTestConnButton('enable');
                    $("#syncBtn").attr("disabled", false);
                    window.location.reload();
                }
            });
            return;
        };

    }
    function testConnection() {
        var dbtype = $("#dbtype").val();
        if (dbtype == '1') {
            dbtype = 'sqlserver'
        } else if (dbtype == '2') {
            dbtype = 'oracle'
        }
        var verifycode = $("#verifycode").val();
        var dbserver = $("#dbserver").val();
        var dbname = $("#dbname").val();
        var dbport = $("#dbport").val();
        var username = $("#username").val();
        var password = $("#password").val();
        var checkResult = checkform(verifycode, dbtype, dbserver, dbname, dbport, username, password);
        if (checkResult != '') {
            checkResult="源数据库"+checkResult;
            top.Dialog.alert(checkResult);
            return;
        }
        changeTestConnButton('disable')
        $("#submittips").html("正在测试连接,请稍后...");
        $.ajax({
            sync: false,
            dataType: 'json',
            type: 'post',
            url: 'TempleteSyncToolsOperation.jsp?method=testConnection',
            // timeout : 5000,
            data: {
                'verifycode':verifycode,
                'dbtype': dbtype,
                'dbserver': dbserver,
                'dbname': dbname,
                'dbport': dbport,
                'username': username,
                'password': password,
            },
            success: function (data) {
                var status = data.status;
                var message = data.message;
                if('success'==status){
                    source_status=1;
                    changeTestConnButton('disable')
                }else{
                    source_status=0;
                    changeTestConnButton('enable')
                }
                $("#submittips").html("");
                top.Dialog.alert(message);
            },
            error: function () {
                $("#submittips").html("");
                top.Dialog.alert("测试数据库连接发生错误,请检查后台日志")
            }
        });
    };

    function changeDBType() {
        var dbtype = $("#dbtype").val();
        if (dbtype == 1) {
            $('input[id^=dbport]').val('1433');
        } else if (dbtype == 2) {
            $('input[id^=dbport]').val('1521');
        }
    };

    function checkform(verifycode,dbtype, dbserver, dbname, dbport, username, password) {
        var message = '';
        if(verifycode==""){
            message="验证码不能为空!"
            return message;
        }
        if (dbtype == "") {
            message = "数据库类型不能为空!"
            return message;
        }
        if (dbserver == "") {
            message = "数据库服务器IP不能为空!"
            return message;
        } else {
            var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
            if (!reg.test(dbserver)) {
                return "数据库服务器IP不合法!";
            }
        }
        if (dbname == "") {
            message = "数据库名称不能为空!"
            return message;
        }
        if (dbport == "") {
            message = "数据库端口号不能为空!"
            return message;
        }
        if (username == "") {
            message = "用户名不能为空!"
            return message;
        }
        if (password == "") {
            message = "密码不能为空!"
            return message;
        }
        return message;
    }

    $("input").click(function(){
        if(isSyncing==1){
            return;
        }
        var tag=this.id.substr(-1,1);
        if(tag=='s'){
            status=0;
        }else if(tag=='t'){
            target_status=0;
        }
        changeTestConnButton('enable')
    });

    function changeTestConnButton(status){
        if('disable'==status){
            $("#testConn").attr('disabled', true);
            $("#testConn").removeClass("btn-success");
            $("#testConn").addClass("btn-disabled");

        }else if('enable'==status){
            $("#testConn").attr('disabled', false);
            $("#testConn").removeClass("btn-disabled");
            $("#testConn").addClass("btn-success");
        }

    }
</script>