QualityRuleMaintain.jsp 28.5 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 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
<%@ page language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head> 
    <title>数据质量规则维护</title>
<style>
.table-null .table{
	margin-bottom: 0px;
}
.table-null .table > tbody > tr > td, .table-null .table > thead > tr > th{
	text-align: center;
 	width: 25%;
}
.table-null td:first-child{	
 	text-align: right;
 	width: 36%;
}
.table-null tr td:last-child .form-control,.table-null tr td:last-child table{
	width: 400px;
}

#kpiTable{
	margin: 0px;
	padding: 0px;
	height: 10px;
	width: 700px;
}
#kpiTable tr td{
	text-align: left;
	margin: 0px;
	padding: 0px;
	height: 10px;
}
</style>
</head>
  
<body>
	<div class="container">
		<ol class="breadcrumb">
			<li><a href="${ctx}/index">首页</a></li>
			<li>数据质量核查</li>
			<li class="active">数据质量规则维护</li>
		</ol>
	</div>
	<div id="main-container main-tab-container">
		<div id="content" class="container">
			<div class="section">
				<div class="tab-content">

					<div class="tab-pane fade in active" id="home">
						<div class="row">
							<div class="col-xs-12">
								<div class="table-header">数据质量规则维护</div>
								<form action="#" class="form-horizontal" id="ruleMaintainForm" method="post">
								<table id="ruleMaintainTable" class="table-null">
									<tr><td>省份(<font color="red">必填</font>):</td>
										<td>

			    							<c:forEach var="province" items="${provinceList}">
												<c:if test="${province.provinceId == '32'}">
			    							  		<input type="checkbox" name="province" class="province" id="province" onclick="return false;" value="${province.provinceId}" checked>${province.provinceName}
												</c:if>
			    							</c:forEach>
										</td>
									</tr>
									<tr><td>数据来源(<font color="red">必填</font>):</td>
										<td>
											<select class="form-control" name="dataSource" id="dataSource" >
											<c:forEach var="dataSource" items="${dataSourceList}">
												<c:if test="${dataSource.dataSourceId == '5'}">
													<option value="${dataSource.dataSourceId}" selected>${dataSource.dataSourceName}</option>
												</c:if >
											</c:forEach>
										    </select></td>
									</tr>
									<tr><td>渠道(<font color="red">必填</font>):</td>
										<td><select class="form-control" name="channel" id="channel" >
			    								<c:forEach var="channel" items="${channelList}">
													<c:if test="${channel.channelId == '7'}">
			    										<option value="${channel.channelId}" selected>${channel.channelName}</option>
													</c:if>
													<c:if test="${channel.channelId != '7'}">
														<option value="${channel.channelId}">${channel.channelName}</option>
													</c:if>
			    								</c:forEach>
										    </select></td>
									</tr>
									<tr><td>业务(<font color="red">必填</font>):</td>
										<td >
											<div class="checkbox-inline"><label><input type="checkbox" id="allBusiness" name="allBusiness" checked>全选</label></div><br/>
											<div id="businesstd">

											</div>

										</td>
									</tr>
									<tr><td>数据采集频率(<font color="red">必填</font>):</td>
										<td><select class="form-control" name="calCycle" id="calCycle" style="display: inline;">
												<option value="30MI">30分钟</option>
												<option value="01HR">1小时</option>
												<option value="01DY">1天</option>
												<option value="01MO">1月</option>
											</select>
										</td></tr>
									<tr><td>指标(<font color="red">必填</font>):</td>
										<td>
											<div class="checkbox-inline"><label><input type="checkbox" id="allKpi" name="allKpi" checked>全选</label></div><br/>
											<div id="kpitd">
												<table id="kpiTable" class="kpiTable">
													<tbody></tbody>
												</table>
											</div>

										</td>
									</tr>
									<tr><td>监控延迟时间(<font color="red">必填</font>):</td>
										<td id="monitorTime">
										<input type="text" name="frequencyValue" id="frequencyValue" style="display: inline;" />
										<select name="frequencyType" id="frequencyType">
			    									<option value="0">分钟</option>
			    									<option value="1">小时</option>
			    									<option value="2"></option>
			    									<option value="3"></option>
			    							</select></td>
									</tr>
									<tr><td>核查时间(<font color="red">必填</font>):</td>
										<td id="businessTimetd">
											<input type='text' class='form-control' id='businessTime' name='businessTime' onfocus='WdatePicker({dateFmt:"yyyy-MM-dd HH:mm:00",startDate:"%y-%M-%d 00:00:00",readOnly:false,hmsMenuCfg : {H : [ 1, 6 ], m : [ 30, 2 ], s : [ 60, 0 ]},alwaysUseStartDate:true})'/>
										</td>
									</tr>
									<tr><td>添加准确性规则:</td>
										<td><table class="table table-hover table-striped" id="displayParam">
											<thead >
											<tr><th>规则类型</th><th>范围最大值</th><th>范围最小值</th><th>重复考核粒度</th><th>重复考核开始时间</th><th>重复考核结束时间</th><th>重复是否连续</th><th>重复最大次数</th><th>数据是否累计</th><th><a href="javascript:deleteAllTr()">删除全部</a></th></tr>
											</thead>
											<tbody id="addTr"></tbody>
										</table></td></tr>
										<tr><td>准确性规则类型:</td>
											<td><select class="form-control" name="ruleType" id="ruleType" >
			    									<option value=""></option>
			    									<option value="1">范围类</option>
			    									<option  value="2">重复类</option>
			    							</select></td></tr>		
						    				<tr class="range"><td>范围最大值:</td><td><input type="text" class="form-control" name="scopeMaxValue" id="scopeMaxValue" /></td></tr>
						    				<tr class="range"><td>范围最小值:</td><td><input type="text" class="form-control" name="scopeMinValue" id="scopeMinValue" /></td></tr>
					    					<tr class="repeate"><td>重复考核粒度:</td>
												<td><select class="form-control" name='repeatedCheckGranularity' id='repeatedCheckGranularity'>
													<option value="day" selected></option>
													<option  value="mon"></option>
												</select>
												</td></tr>
			    							<tr class="repeate"><td>重复考核开始时间:</td><td><input type="text" class="form-control" id="repeatedCheckStartTime" name="repeatedCheckStartTime" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'repeatedCheckStartTime\')}'})" /></td></tr>
			    							<tr class="repeate"><td>重复考核结束时间:</td><td><input id="repeatedCheckEndTime" name="repeatedCheckEndTime" class="form-control" type="text" onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'repeatedCheckEndTime\')}'})"></td></tr>
			    							<tr class="repeate"><td>重复是否连续:</td>
												<td><select name='ifRepeatedCheckSeries' id='ifRepeatedCheckSeries' class="form-control">
													<option value="1" selected></option>
													<option  value="0"></option>
												</select>
												</td></tr>
			    							<tr class="repeate"><td>重复最大次数:</td><td><input type='text' name='repeatedCheckMaxTime' id='repeatedCheckMaxTime' class="form-control" style="display: inline;"/></td></tr>
			    							<tr class="repeate"><td>数据是否累计:</td>
												<td><select name='ifRepeatedCheckSummation' id='ifRepeatedCheckSummation' class="form-control">
													<option value="1" selected></option>
													<option  value="0"></option>
												</select>
												</td></tr>
											<tr><td></td>
												<td><button type="button" id="addParam" class="btn btn-primary">添加规则</button></td></tr>
											<tr><td></td><td><button type="button" id="ruleSubmit" class="btn btn-primary">确定</button>
															<button type="reset" class="btn btn-warning" id="ruleBack">返回</button>
											</td></tr>
	                            </table>
								</form>
								<input type="hidden" id="kpi" name="kpi" value='${kpiList}' />
								<input type="hidden" id="business" name="business" value='${businessList}' />
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	
<script type="text/javascript">
$(".range").hide();
$(".repeate").hide();
$("#addParam").hide();
$("#ruleType").change(function (){
	var selectValue = $("#ruleType").val();
	if (selectValue == ""){
		$(".range").hide();
		$(".repeate").hide();
        $("#addParam").hide();
	}
	if (selectValue == 1){
		$(".repeate").hide();
		$(".range").show();
        $("#addParam").show();
	}
	if (selectValue == 2){
		$(".range").hide();
		$(".repeate").show();
        $("#addParam").show();
	}
});

//删除所有准确性规则
function deleteAllTr(){
    $("#addTr").empty();
}

//删除一条准确性规则
function deleteRow(elementTag){
    $(elementTag).parent().parent().remove();
}


//添加/修改准确性规则
$("#addParam").click(function(){
    var  ruleType= $("#ruleType").val();
    var scopeMaxValue = $.trim($("#scopeMaxValue").val());
    var scopeMinValue = $.trim($("#scopeMinValue").val());
    var repeatedCheckGranularity = $.trim($("#repeatedCheckGranularity").val());
    var repeatedCheckStartTime = $.trim($("#repeatedCheckStartTime").val());
    var repeatedCheckEndTime = $.trim($("#repeatedCheckEndTime").val());
    var ifRepeatedCheckSeries = $.trim($("#ifRepeatedCheckSeries").val());
    var repeatedCheckMaxTime = $.trim($("#repeatedCheckMaxTime").val());
    var ifRepeatedCheckSummation = $.trim($("#ifRepeatedCheckSummation").val());
	if(ruleType == "1" || ruleType == "2"){
        if(ruleType == "1"){
            if(scopeMaxValue==""){$.alert("范围最大值不能为空");}
            if(scopeMinValue==""){$.alert("范围最小值不能为空");}
            repeatedCheckGranularity ="无";
            repeatedCheckStartTime ="无";
            repeatedCheckEndTime ="无";
            ifRepeatedCheckSeries ="无";
            repeatedCheckMaxTime ="无";
            ifRepeatedCheckSummation ="无";
        } else if(ruleType == "2"){
            if(repeatedCheckGranularity==""){$.alert("重复考核粒度不能为空");}
            if(repeatedCheckStartTime==""){$.alert("重复考核开始时间不能为空");}
            if(repeatedCheckEndTime==""){$.alert("重复考核结束时间不能为空");}
            if(ifRepeatedCheckSeries==""){$.alert("重复是否连续不能为空");}
            if(repeatedCheckMaxTime==""){$.alert("重复最大次数不能为空");}
            if(ifRepeatedCheckSummation==""){$.alert("数据是否累计不能为空");}
            scopeMaxValue ="无";
            scopeMinValue ="无";
        }
        if($("#addTr").find("tr.orange-tr").html()==null){
            var addRow = $("<tr><td>"+ruleType+"</td><td>"+scopeMaxValue+"</td><td>"+scopeMinValue+"</td><td>"+repeatedCheckGranularity+"</td><td>"+repeatedCheckStartTime+"</td><td>"+repeatedCheckEndTime+"</td><td>"+ifRepeatedCheckSeries+"</td><td>"+repeatedCheckMaxTime+"</td><td>"+ifRepeatedCheckSummation+"</td><td><a href='javascript:;' title='' onclick='deleteRow(this)'>删除</a></td></tr>");
            $("#addTr").append(addRow);
            $("#ruleType").attr("value","");
            $("#scopeMaxValue").attr("value","");
            $("#scopeMinValue").attr("value","");
            $("#repeatedCheckGranularity").attr("value","");
            $("#repeatedCheckStartTime").attr("value","");
            $("#repeatedCheckEndTime").attr("value","");
            $("#ifRepeatedCheckSeries").attr("value","");
            $("#repeatedCheckMaxTime").attr("value","");
            $("#ifRepeatedCheckSummation").attr("value","");
        }else{
            var findTr = $("#addTr").find("tr.orange-tr");
            $(findTr).find("td").eq(0).html(ruleType);
            $(findTr).find("td").eq(1).html(scopeMaxValue);
            $(findTr).find("td").eq(2).html(scopeMinValue);
            $(findTr).find("td").eq(3).html(repeatedCheckGranularity);
            $(findTr).find("td").eq(4).html(repeatedCheckStartTime);
            $(findTr).find("td").eq(5).html(repeatedCheckEndTime);
            $(findTr).find("td").eq(6).html(ifRepeatedCheckSeries);
            $(findTr).find("td").eq(7).html(repeatedCheckMaxTime);
            $(findTr).find("td").eq(8).html(ifRepeatedCheckSummation);
            $("#addTr").find("tr").removeClass();
            $("#addParam").text("添加规则");
        }
    }
});

	//form表单提交
	$("#ruleSubmit").click(function(){
        $.dialog({
            title: "提醒",
            content:"确定新增该规则吗?",
            ok: function(){
				if($.trim($("#frequencyValue").val())==""){
					$.alert("监控延迟时间不能为空");
				}else if($("#businessTime").val()==""){
					$.alert("指标业务时间不能为空");
				}else if($("#ruleCrtTime").val()==""){
					$.alert("规则创建时间不能为空");
				}else if($("#ruleUpdateTime").val()==""){
					$.alert("规则更新时间不能为空");
				}else{
					if($.trim($("#ruleType").val())=="1" || $.trim($("#ruleType").val())=="2"){
					$.dialog({
						title: "提醒",
						content: "有准确性规则参数尚未添加,确定提交",
						ok: function(){

						$("#ruleSubmit").attr("disabled",true);
						var i = $("#addTr").find("tr").size();

						if(i==0){
						var createForm=$("#ruleMaintainForm");
							createForm.attr("action","${ctx}/AnalysisSupport/QualityRuleMaintain/saveRuleDataForm");
							createForm.submit();
							createForm.attr("action","#");
					}else{
							$("#addTr").find("tr").each(function(){
							var ruleType = $(this).find("td").eq(0).html();
							var scopeMaxValue = $(this).find("td").eq(1).html();
							var scopeMinValue = $(this).find("td").eq(2).html();
							var repeatedCheckGranularity = $(this).find("td").eq(3).html();
							var repeatedCheckStartTime = $(this).find("td").eq(4).html();
							var repeatedCheckEndTime = $(this).find("td").eq(5).html();
							var ifRepeatedCheckSeries = $(this).find("td").eq(6).html();
							var repeatedCheckMaxTime = $(this).find("td").eq(7).html();
							var ifRepeatedCheckSummation = $(this).find("td").eq(8).html();
							if(scopeMaxValue =="无"){scopeMaxValue ="";}
							if(scopeMinValue =="无"){scopeMinValue ="";}
							if(repeatedCheckGranularity =="无"){repeatedCheckGranularity ="";}
							if(repeatedCheckStartTime =="无"){repeatedCheckStartTime ="";}
							if(repeatedCheckEndTime ="无"){repeatedCheckEndTime ="";}
							if(ifRepeatedCheckSeries =="无"){ifRepeatedCheckSeries ="";}
							if(repeatedCheckMaxTime =="无"){repeatedCheckMaxTime ="";}
							if(ifRepeatedCheckSummation =="无"){ifRepeatedCheckSummation ="";}

							$.ajax({
								type : "GET",
								contentType : "application/json",
								url: "${ctx}/AnalysisSupport/QualityRuleMaintain/createAccuracyRule?ruleType="+ruleType+"&scopeMaxValue="+scopeMaxValue+"&scopeMinValue="+scopeMinValue+"&repeatedCheckGranularity="+repeatedCheckGranularity+"&repeatedCheckStartTime="+repeatedCheckStartTime+"&repeatedCheckEndTime="+repeatedCheckEndTime+"&ifRepeatedCheckSeries="+ifRepeatedCheckSeries+"&repeatedCheckMaxTime="+repeatedCheckMaxTime+"&ifRepeatedCheckSummation="+ifRepeatedCheckSummation,
								dataType : "text",
								async: false,
								beforeSend: function(data) {},
								success: function(){
									i--;
									if(i==0){
										var createForm=$("#ruleMaintainForm");
										createForm.attr("action","${ctx}/AnalysisSupport/QualityRuleMaintain/saveRuleDataForm");
										createForm.submit();
										createForm.attr("action","#");
									}
								}
							});
						});
					}
						},
						okValue: "确定",
						cancel: function(){},
						cancelValue: "取消",
					});
					}else{
						$("#ruleSubmit").attr("disabled",true);
						var i = $("#addTr").find("tr").size();

						if(i==0){
						var createForm=$("#ruleMaintainForm");
							createForm.attr("action","${ctx}/AnalysisSupport/QualityRuleMaintain/saveRuleDataForm");
							createForm.submit();
							createForm.attr("action","#");
					}else{
							$("#addTr").find("tr").each(function(){
								var ruleType = $(this).find("td").eq(0).html();
								var scopeMaxValue = $(this).find("td").eq(1).html();
								var scopeMinValue = $(this).find("td").eq(2).html();
								var repeatedCheckGranularity = $(this).find("td").eq(3).html();
								var repeatedCheckStartTime = $(this).find("td").eq(4).html();
								var repeatedCheckEndTime = $(this).find("td").eq(5).html();
								var ifRepeatedCheckSeries = $(this).find("td").eq(6).html();
								var repeatedCheckMaxTime = $(this).find("td").eq(7).html();
								var ifRepeatedCheckSummation = $(this).find("td").eq(8).html();
								if(scopeMaxValue =="无"){scopeMaxValue ="";}
								if(scopeMinValue =="无"){scopeMinValue ="";}
								if(repeatedCheckGranularity =="无"){repeatedCheckGranularity ="";}
								if(repeatedCheckStartTime =="无"){repeatedCheckStartTime ="";}
								if(repeatedCheckEndTime ="无"){repeatedCheckEndTime ="";}
								if(ifRepeatedCheckSeries =="无"){ifRepeatedCheckSeries ="";}
								if(repeatedCheckMaxTime =="无"){repeatedCheckMaxTime ="";}
								if(ifRepeatedCheckSummation =="无"){ifRepeatedCheckSummation ="";}
								$.ajax({
											type : "GET",
											contentType : "application/json",
											url: "${ctx}/AnalysisSupport/QualityRuleMaintain/createAccuracyRule?ruleType="+ruleType+"&scopeMaxValue="+scopeMaxValue+"&scopeMinValue="+scopeMinValue+"&repeatedCheckGranularity="+encodeURIComponent(repeatedCheckGranularity)+"&repeatedCheckStartTime="+encodeURIComponent(repeatedCheckStartTime)+"&repeatedCheckEndTime="+encodeURIComponent(repeatedCheckEndTime)+"&ifRepeatedCheckSeries="+ifRepeatedCheckSeries+"&repeatedCheckMaxTime="+repeatedCheckMaxTime+"&ifRepeatedCheckSummation="+ifRepeatedCheckSummation,
											dataType : "text",
											async: false,
											beforeSend: function(data) {},
											success: function(){
												i--;
												if(i==0){
													var createForm=$("#ruleMaintainForm");
													createForm.attr("action","${ctx}/AnalysisSupport/QualityRuleMaintain/saveRuleDataForm");
													createForm.submit();
													createForm.attr("action","#");
									}
								}
							});

							});
					}
				}

			}
			},
                okValue:"确定",
                    cancel: function(){},
                cancelValue:"返回",
                    lock:true
		});

});

$("#ruleBack").click(function(){
		location.href="${ctx}/AnalysisSupport/QualityRuleResult";
	});

function getProvinceCheckedValues() {
	var provinceArray = new Array();
	var i=0;
	$("#province:checked").each(function(){
	    provinceArray[i]=$(this).val();
	    i++;
	});
	return provinceArray;
}

function getProvinceCheckedValuesString(){
    var provinceStr="";
    var provinceArray=getProvinceCheckedValues();
    for(var i=0;i<provinceArray.length;i++){
        if(i==provinceArray.length-1){
            provinceStr+=provinceArray[i];
        }else{
            provinceStr+=provinceArray[i]+",";
        }
    }
    return provinceStr;
}

var dataSourceValue =$("#dataSource").val();
var channelValue = $("#channel").val();
var businessIds = getBusinessCheckedValues();
var calCycleValue =$("#calCycle").val();
$("#dataSource").change(function(){
	dataSourceValue = $("#dataSource").val();
	updateBusiness(dataSourceValue,channelValue);
});	
$("#channel").change(function(){
	channelValue = $("#channel").val();
	updateBusiness(dataSourceValue,channelValue);
	
});

function updateKpi(businessIds,calCycleValue){
	
	$.ajax({
		type : "GET",
		contentType : "application/json",
		url: "${ctx}/AnalysisSupport/QualityRuleMaintain/findKpiId?businessIds="+businessIds+"&calCycleValue="+calCycleValue,
		async: false,
		beforeSend: function(data) {},
		success: function(data){
		    console.log(data)
            var tbody=$('<tbody></tbody>');

            data.forEach(function(t,i){
                var tr = $('<tr></tr>');
                tr.empty();
                if(i % 3 == 0){
                    if(data.length-1-i >= 3){
                        tr.append('<td>'+"<input type='checkbox' name='kpiinput' class='kpiItem' title='"+data[i+1][2]+"' value='"+data[i+1][0]+"' checked >"+data[i+1][1]+"</input>"+'</td>'+
                            '<td>'+"<input type='checkbox' name='kpiinput' class='kpiItem' title='"+data[i+2][2]+"' value='"+data[i+2][0]+"' checked >"+data[i+2][1]+"</input>"+'</td>'+
                            '<td>'+"<input type='checkbox' name='kpiinput' class='kpiItem' title='"+data[i+3][2]+"' value='"+data[i+3][0]+"' checked >"+data[i+3][1]+"</input>"+'</td>')
                        tbody.append(tr);
					}else if((data.length-1-i) == 2){
						tr.append('<td>'+"<input type='checkbox' name='kpiinput' class='kpiItem' title='"+data[i][2]+"' value='"+data[i][0]+"' checked >"+data[i][1]+"</input>"+'</td>'+
						    '<td>'+"<input type='checkbox' name='kpiinput' class='kpiItem' title='"+data[i+1][2]+"' value='"+data[i+1][0]+"' checked >"+data[i+1][1]+"</input>"+'</td>'+
							'<td>'+"<input type='checkbox' name='kpiinput' class='kpiItem' title='"+data[i+2][2]+"' value='"+data[i+2][0]+"' checked >"+data[i+2][1]+"</input>"+'</td>')
						tbody.append(tr);
					}else if((data.length-1-i) == 1) {
						tr.append('<td>'+"<input type='checkbox' name='kpiinput' class='kpiItem' title='"+data[i][2]+"' value='"+data[i][0]+"' checked >"+data[i][1]+"</input>"+'</td>'+
						    '<td>' + "<input type='checkbox' name='kpiinput' class='kpiItem' title='" + data[i + 1][2] + "' value='" + data[i + 1][0] + "' checked >" + data[i + 1][1] + "</input>" + '</td>')
						tbody.append(tr);
					}else if((data.length-1-i) == 0) {
                        tr.append('<td>'+"<input type='checkbox' name='kpiinput' class='kpiItem' title='"+data[i][2]+"' value='"+data[i][0]+"' checked >"+data[i][1]+"</input>"+'</td>')
                        tbody.append(tr);
                    }
				}
			});
            $('#kpiTable tbody').replaceWith(tbody);
		}
	});
}

function updateBusiness(dataSource,channel){
	$.ajax({
		type : "GET",
		contentType : "application/json",
		url: "${ctx}/AnalysisSupport/QualityRuleMaintain/findBusinessId?dataSource="+dataSource+"&channel="+channel,
		async: false,
		beforeSend: function(data) {},
		success: function(data){
			var td = $("#businesstd");
			var businessIds = new Array();
			td.empty();
			data = JSON.parse(data)
			data.forEach(function(t){
				td.append("<input type='checkbox' name='businessinput' class='businessItem' value='"+t[0]+"' checked >"+t[1]+"</input>")
				businessIds+=t[0]+",";
			});
			updateKpi(businessIds,calCycleValue);
		}
	});

    $(".businessItem").click(function(){
        businessIds="";
        $("[name='businessinput']:checked").each(function (){
            businessIds += $(this).val()+",";
        });
        updateKpi(businessIds,calCycleValue);
    });

}
$("#calCycle").change(function () {
    calCycleValue=$("#calCycle").val();
    $("[name='businessinput']:checked").each(function (){
        businessIds += $(this).val()+",";
    });
    updateKpi(businessIds,calCycleValue);
	updateBusinessTime(calCycleValue);
    updateMonitorTimeTime(calCycleValue);
});

updateBusiness($("#dataSource").val(),$("#channel").val());

function updateBusinessTime(calCycleValue) {
    $("#businessTimetd").empty()
    if(calCycleValue == "30MI"){
        $("#businessTimetd").append("<input type='text' class='form-control' id='businessTime' name='businessTime' onfocus='WdatePicker({dateFmt:\"yyyy-MM-dd HH:mm:00\",startDate:\"%y-%M-%d 00:00:00\",alwaysUseStartDate:true,readOnly:false,hmsMenuCfg : {H : [ 1, 6 ], m : [ 30, 2 ], s : [ 60, 0 ]}})'/>");
    }else if(calCycleValue == "01HR"){
        $("#businessTimetd").append("<input type='text' class='form-control' id='businessTime' name='businessTime' onfocus='WdatePicker({dateFmt:\"yyyy-MM-dd HH:00:00\",startDate:\"%y-%M-%d 00:00:00\",alwaysUseStartDate:true,readOnly:false,hmsMenuCfg : {H : [ 1, 6 ], m : [ 60, 0 ], s : [ 60, 0 ]}})'/>");
    }else if(calCycleValue == "01DY"){
        $("#businessTimetd").append("<input type='text' class='form-control' id='businessTime' name='businessTime' onfocus='WdatePicker({dateFmt:\"yyyy-MM-dd 00:00:00\",startDate:\"%y-%M-%d 00:00:00\",alwaysUseStartDate:true,readOnly:false,hmsMenuCfg : {H : [ 24, 0 ], m : [ 60, 0 ], s : [ 60, 0 ]}})'/>");
    }else if(calCycleValue == "01MO"){
        $("#businessTimetd").append("<input type='text' class='form-control' id='businessTime' name='businessTime' onfocus='WdatePicker({dateFmt:\"yyyy-MM-01 00:00:00\",startDate:\"%y-%M-%d 00:00:00\",alwaysUseStartDate:true,readOnly:false,hmsMenuCfg : {H : [ 24, 0 ], m : [ 60, 0 ], s : [ 60, 0 ]}})' />");
    }
}

$("#frequencyValue").val("30");
function updateMonitorTimeTime(calCycleValue) {
	if(calCycleValue == "30MI"){
		$("#frequencyValue").val("30");
        $("#frequencyType").val(0);
	}else if(calCycleValue == "01HR"){
		$("#frequencyValue").val("1");
        $("#frequencyType").val(1);
	}else if(calCycleValue == "01DY"){
		$("#frequencyValue").val("1");
        $("#frequencyType").val(2);
	}else if(calCycleValue == "01MO"){
		$("#frequencyValue").val("1");
        $("#frequencyType").val(3);
	}
}

function getBusinessCheckedValues(){
    var businessArray = new Array();
    var i=0;
    $("[name='businessinput']:checked").each(function(){
        businessArray[i]=$(this).val();
        i++;
    });
    return businessArray;
}

function getBusinessCheckedValuesString(){
    var businessStr="";
    var businessArray=getBusinessCheckedValues();
    for(var i=0;i<businessArray.length;i++){
        if(i==businessArray.length-1){
            businessStr+=businessArray[i];
        }else{
            businessStr+=businessArray[i]+",";
        }
    }
    return businessStr;
}

function getKpiCheckedValues(){
    var kpiArray = new Array();
    var i=0;
    $("[name='kpiinput']:checked").each(function(){
        kpiArray[i]=$(this).val();
        i++;
    });
    return kpiArray;
}

function getKpiCheckedValuesString(){
    var kpiStr="";
    var kpiArray=getKpiCheckedValues();
    for(var i=0;i<kpiArray.length;i++){
        if(i==kpiArray.length-1){
            kpiStr+=kpiArray[i];
        }else{
            kpiStr+=kpiArray[i]+",";
        }
    }
    return kpiStr;
}

var provinceValue = getProvinceCheckedValuesString();
var businessValue = getBusinessCheckedValuesString();
var kpiValue = getKpiCheckedValuesString();

//省份全选
$("#allProvince").click(function(){
    if($("#allProvince").attr("checked") == "checked"){//全选
        $(".province").attr("checked","checked");
    }else{//不全选
        $(".province").attr("checked",false);
    }
});
//业务全选
$("#allBusiness").click(function(){
    if($("#allBusiness").attr("checked") == "checked"){//全选
        $(".businessItem").attr("checked","checked");
    }else{//不全选
        $(".businessItem").attr("checked",false);
    }
    businessIds="";
    $("[name='businessinput']:checked").each(function (){
        businessIds += $(this).val()+",";
    });
    console.log(businessIds);
    updateKpi(businessIds,calCycleValue);
});
$(".businessItem").click(function(){
    var clickFlag=true;//是否全部选中
    $(".businessItem").each(function(){
        if($(this).attr("checked") == null||$(this).attr("checked") == false){	clickFlag=false;	}
    });
    $("#allBusiness").attr("checked",clickFlag);
});
//指标全选
$("#allKpi").click(function(){
    if($("#allKpi").attr("checked") == "checked"){//全选
        $(".kpiItem").attr("checked","checked");
    }else{//不全选
        $(".kpiItem").attr("checked",false);
    }
});
$(".kpiItem").click(function(){
    var cFlag=true;//是否全部选中
    $(".kpiItem").each(function(){
        if($(this).attr("checked") == null||$(this).attr("checked") == false){	cFlag=false;	}
    });
    $("#allKpi").attr("checked",cFlag);
});

</script>

</body>
</html>