【调度系统】广东民航医疗快线调度系统源代码
克樊道人
2024-12-02 61ce8cc6883e5f94e6470141df3484167caf31ed
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
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
var isInitFinished=false;//是否加载完视频插件???
var swfwidth=0;//swf插件窗口宽度
var swfheight=0;
var PlateNum=0; //url中车牌号
var chnCount = 1;//通道数量
var maxChnCount = 1; //最大窗口数
var loginServer = null;
var isLoadLoginServer = false;
var jsession="";
var devIdno="";// 车辆对应设备号
var vehiIdno = ""; //车牌号
var isShowResidualSeconds=false; //是否显示视频播放剩余秒数
var radioFileLocation=1;//视频文件位置 1为终端设备,2为储存服务器 ,4为下载服务器
var closeSecond = 3*60;//自动关闭视频秒数
var stopIndex = 0;
var lang = new langZhCn();
var IsSearching=false;
var videoFileList = new Hashtable();  //视频文件列表
var host=window.location.host;
var ip_="";
var port_="6605";//平台登录验证端口号
var serverIp="";
var serverPort="";
var queryVehicleChannels = new Array();//Find the vehicle channel
var channels=null;
 
function langZhCn() {
    this.loginError = "登陆失败";
    this.jsessionError = "会话号不存在";
    this.deviceNoExist = "找不到车辆信息";
    this.errorVideoDevice = "这个设备不是视频设备";
    this.vehicleNotOperate = "没有车辆或者设备操作权限";
    this.closeTip = "秒后关闭视频";
    this.quering="正在查询…";
    this.VideoQueryPrompt="未查到相关录像结果!";
    this.query="查询";
    this.ServerQueryPrompt="相关服务器信息查询失败!";
    this.allowed="该浏览器是否设置了允许的弹出框!";
    this.NullVideoFileInfo = "无视频文件信息!";
    this.optionTips = "必须选择摄像头!";
    this.operator = "操作";
    this.begintime = "开始时间";
    this.endtime = "结束时间";
    this.duration = "持续时间";
    this.date = "日期";
    this.realtimeVideo = "实时视频";
    this.replayVideo = "历史视频";
    this.channel = "通道";
    this.download="下载";
    this.video_playback="回放";
    this.Normal="常规";
    this.Alarm="报警";
    this.Device="设备";
    this.StorageServer="储服务器";
    this.DownloadServer="下载服务器";
    this.searchEnded = "搜查完毕";
    this.errorGetVideoFile = "获取视频文件信息失败!";
    this.deviceNotOnline= "设备不在线!";
    this.segment = "分段";
    this.segemenDownloadSuccess = '保存成功';
    this.segemenDownloadFail = '下载任务已经存在';
    
    
    this.setParam = "分段下载参数设置";
    this.savaParam = "确认参数";
    this.endTimeBigStartTime = "结束时间不小于开始时间";
    this.beginInfoErro = "开始时间范围";
    this.endInfoErro = "结束时间范围";
    
    
 
    
}
 
function langEn() {
    this.loginError = "Login failed";
    this.jsessionError = "Jsession error";
    this.deviceNoExist = "Can't not find vehicles";
    this.vehicleNotOperate = "No vehicle or device operating authority";
    this.errorVideoDevice = "This device is not video device";
    this.closeTip = " seconds later close video"
    this.quering="quering...";
    this.VideoQueryPrompt="Related video results were not found!";
    this.query="query";
    this.ServerQueryPrompt="Related server information query failed!";
    this.allowed="Does this browser set the allowed pop up box!";
    this.NullVideoFileInfo = "No video file information!";
    this.optionTips = "Select one camara at least!";
    this.operator = "operator";
    this.begintime = "start";
    this.endtime = "ended";
    this.duration = "duration";
    this.date = "Date";
    this.realtimeVideo = "Realtime Video";
    this.replayVideo = "Replay Video";
    this.channel = "channel";
    this.download="Download";
    this.video_playback = "PlayBack";
    this.Normal="Normal";
    this.Alarm="Alarm";
    this.Device="Device";
    this.StorageServer="StorageServer";
    this.DownloadServer="DownloadServer";
    this.searchEnded = "Search ended";
    this.errorGetVideoFile = "Failed to obtain video file information!";
    this.deviceNotOnline= "The device isn't online!";
    this.segment = "Segment";
    this.segemenDownloadSuccess = 'Save success';
    this.segemenDownloadFail = 'Download task already exists';
    this.setParam = "Download Parameters";
    this.savaParam = "Save";
    this.endTimeBigStartTime = "End time is not less than the start time";
    this.beginInfoErro = "Start time range";
    this.endInfoErro = "End time range";
    
    
}
 
 
$(document).ready(function () {
    var host = window.location.host;
    ip_ = host.split(":")[0];
    if(!ip_|| ip_ == 'localhost') {
        ip_ = '127.0.0.1';
    }
    if (getUrlParameter("lang") == "en") {
        lang = new langEn();
    }
    
//    alert("host1:"+host1+"\n href1:"+href1+"\n pathname1:"+pathname1+"\n documentURL1:"+documentURL1+"\n search1:"+search1);
    //加载搜索栏信息
    $("#closeTip").hide();
    $("#time").val(dateCurrentDateString());//(datatime.getFullYear()+"-"+(datatime.getMonth()+1)+"-"+datatime.getDate()
    $("#time").click(function(){WdatePicker({lang:"zh",dateFmt:'yyyy-MM-dd'}); });//去HH:mm:ss
    $("#query").val(lang.query);
    $('#labelTime').text(lang.date);
    $('#current').next().text(lang.realtimeVideo);
    $('#history').next().text(lang.replayVideo);
    $('#labelChn').text(lang.channel);
    $("#query").click(function(){
        videoFileList.clear();
        getChns();
        Search();
    });
 
    //加载页面
    loadPage();
    //配置车辆信息
    $('#videoTitle').val(vehiIdno);
});
 
function loadPage(){
    setPanelWidth();
    //加载报表
    loadTable();
    //载入视频插件
    initPlayer();
    //获取车牌号
    vehiIdno=decodeURIComponent(getUrlParameter("PlateNum"));
    if(!vehiIdno ) {//为空
        alert(lang.deviceNoExist);
        return;
    }
    // callcackFn();
    login();
}
 
//加载报表
function loadTable(){
    $('#videoInfoTable').flexigrid({
//        url:'TestAction_loadEmployees.action',
        dataType:'json',
        colModel:[
                    {display: lang.operator, name : 'operator', width : 100, sortable : false, align: 'center' , hide : false},
                    {display: lang.fileIndex, name : 'fileIndex', width : 40, sortable : false, align: 'center' , hide : true},
                    {display: lang.fileTime, name : 'fileTime', width : 150, sortable : false, align: 'center' , hide : true},
                    {display: lang.Type, name : 'type', width : 80, sortable : false, align: 'center' , hide : true},
                    {display: lang.spanDevice, name : 'vehiIdno', width : 100, sortable : false, align: 'center' , hide : true},
                    /*{display: lang.vehiChn, name : 'vehiChn', width : 70, sortable : false, align: 'center' , hide : true},*/
                    {display: lang.loc, name : 'loc', width : 80, sortable : false, align: 'center' , hide : true},
                    {display: lang.fileSize, name : 'fileSize', width : 80, sortable : false, align: 'center' , hide : true},
                    {display: lang.file ,name: 'file', width : 380,sortable : false, align: 'center' , hide : true},
                    {display: 'svr' ,name: 'svr',hide : true},
                    {display: 'devIdno' ,name: 'devIdno',hide : true },
                    {display: 'len' ,name: 'len',hide : true},
                    {display: 'chnMask' ,name: 'chnMask',hide : true},
//                    {display: 'beg' ,name: 'beg',hide : true},
//                    {display: 'end' ,name: 'end',hide : true},
                  {display: lang.begintime, name : 'beg', width : 100, sortable : false, align: 'center', hide: false},
                  {display: lang.endtime, name : 'end', width : 100, sortable : false, align: 'center', hide: false},
                  {display: lang.duration, name : 'duration', width : 100, sortable : false, align: 'center', hide: false},//结束-开始
                  {display: lang.channel, name: 'vehiChn', width : 63 , sortable : false, align:'center', hide:false}//摄像头=通道+1;
                  ],
                  
                usepager: false,
                  autoload: false,
                  useRp: false,
                  singleSelect: true,
                  clickRowCenter: true,
                  onDoubleClick: function(obj,event) {
                      doubleClickVideoReplay(obj,event);
                  },
                  rp: 15,
                  showTableToggleBtn: false,
                  showToggleBtn: false,
                  width: 'auto',
                  height: 'auto',
                  resizable: false,
 
    });
    
    loadReportTableWidth(fixFun);
    
    //配置
    $("#videoInfoTable").flexSetFillCellFun(function(p, row, idx, index) {
        return fillVideoFileTable(p, row, idx, index);
    });
}
 
/*
 * Fill in the video file list
 */
function fillVideoFileTable(p, row, idx, index) {
    var name = p.colModel[idx].name;
    var ret = "";
    if(name == 'fileIndex') {
        ret = row.id + 1;
    } else if(name == 'fileTime') {
        var fileRealDate = getFileTime(row.year, row.mon, row.day);
        var relBeg = row.beg;
        var relEnd = row.end;
        var beginDate = fileRealDate +' '+ second2ShortHourEx(row.beg);
        var endDate = fileRealDate +' '+ second2ShortHourEx(row.end);
        var timeTitle = row.beginDate + ' - ' + second2ShortHourEx(row.end);
        ret=timeTitle;
    } else if(name == 'vehiIdno') {
        ret = row.vehiIdno;
    }else if(name == 'type') {
        if(row.type=="0"){
            ret=lang.Normal;
        }else{
            ret=lang.Alarm;
        }
    }else if(name == 'vehiChn') {
        ret = row.chnName;
    }else if(name == 'loc') {
        if(row.loc == 1) {
            ret = lang.Device;
        }else if(row.loc == 2) {
            ret = lang.StorageServer;
        }else if(row.loc == 4) {
            ret = lang.DownloadServer;
        }
    } else if(name == 'fileSize') {
        ret = (row.len/1024/1024).toFixed(2) + 'MB' ;
    } else if(name == 'file') {
        ret = row.file;
    } 
    else if(name == 'operator') {
        ret = '<a class="downLoad" href="javascript:downloadVideoFile('+row['id']+');" title="'+lang.download+'"></a>';
        ret += '<a class="segDownLoad" href="javascript:doSegementDownloadServer('+row['id']+');" title="'+lang.segment+lang.download+'"></a>';
        ret += '<a class="playback" href="javascript:videoFileReplay(this,'+row['id']+');" title="'+lang.video_playback+'"></a>';
        return ret;
    }
    else if(name == 'svr'){
        ret=row.svr;
    }else if(name == 'devIdno'){
        ret=row.devIdno;
    }else if(name == 'len'){
        ret=row.len;
    }else if(name == 'chnMask'){
        ret=row.chnMask;
    }else if(name == 'end'){
        ret=second2ShortHourEx(row.end);
    }else if(name == 'beg'){
        ret=second2ShortHourEx(row.beg);
    }else if(name == 'duration'){
        ret=second2ShortHourEx(row.end-row.beg);
    }
 
    return ret;
};
 
function fixFun(){
    var width = $(window).width();
    var height = $(window).height();
    //不能少于1024
    if(width < 1024) {
        width = 1024;
    }
    
    if(getTop($('.queryGraph-render').get(0)) == 0 || getTop($("#container").get(0)) != 0) {
        height = height - getTop($('.flexigrid .bDiv').get(0)) - $('.flexigrid .pDiv').height() - 10-24;// 
    }
    if(getTop($('.queryGraph-render').get(0)) != 0) {
        height = height - getTop($('.flexigrid .bDiv').get(0)) - $('.flexigrid .pDiv').height() - 10-24;
    }
    height = height < 0 ? 0 : height;
    $('.flexigrid .bDiv').height(height);
}
 
 
 
//如果传入了用户名和密码,则继续加载信息
function login() {
    var account = getUrlParameter("account");
    var password = getUrlParameter("password");
    var param = [];
    param.push({name: 'account', value: account});
    param.push({name: 'password', value: password});
    
    doAjaxSubmit('StandardApiAction_login.action', param, function(json, action, success) {
        if(success) {
            //获取到会话号
            jsession = json.jsession;
//            //取得会话号则搜索车牌的对应设备号
            loadDeviceInfo();
            
        }else {
            alert(lang.loginError);
        }
    });    
}
 
//如果传入设备号,则直接判断设备号;
//如果没传入设备号,则判断传入的车牌号
//根据设备号或者车牌号获取设备信息,并判断是否有效和是否视频设备
//获取设备通道
//实时视频用
function loadDeviceInfo() {
    var param = [];
    param.push({name: 'jsession', value: jsession});
    param.push({name: 'vehiIdno', value: vehiIdno});
    this.doAjaxSubmit('StandardApiAction_getVideoDevice.action', param, function(json, action, success) {
        if(success) {
            //不是视频设备
            if(!json.isVideoDevice) {
                alert(lang.errorVideoDevice);
            }else {
                devIdno = json.devIdno;
                chnCount = json.chnCount;
                //加载通道选择框
                loadChannels();
            }
        }else {
            //没有操作权限
            if(json) {
                if(json.result == 5) {
                    alert(lang.jsessionError);
                }else if(json.result == 8) {
                    alert(lang.vehicleNotOperate);
                }else {
                    alert(lang.deviceNoExist);
                }
            }else {
                alert(lang.deviceNoExist);
            }
        }
    });
}
 
 
function loadChannels(){
    for(var i=0;i<chnCount;i++){
        if(i==5){
            $('#channels').append('<input id="channel'+(i+1)+'" type="checkbox" name="channel" value="'+i+'" checked/>'
                    +'<span id="labelChannel'+(i+1)+'" class="labelChannel">'+(i+1)+'</span></br>');
        }else{
            $('#channels').append('<input id="channel'+(i+1)+'" type="checkbox" name="channel" value="'+i+'" checked/>'
                    +'<span id="labelChannel'+(i+1)+'" class="labelChannel">'+(i+1)+'</span>');
        }
    }
}
 
//
function loadAgain(){
    setPanelWidth();
    loadReportTableWidth(fixFun);
}
 
function Search(){
    if(IsSearching==true){
        return;
    } 
    if(getChns().length<1){
        alert(lang.optionTips);
        return;
    }
    IsSearching=true;
    $("#query").val(lang.quering);
    var number=vehiIdno;   
    var id=devIdno;
    var radioFileType=2;//文件类型 2表示录像。
    var radioVideoType= -1;//录像类型 0表示常规,1表示报警,-1表示所有。
    var beginstr =$("#time").val()+" "+"00:00:00";
    var str=beginstr.split(" ");
    var begstr = beginstr.replace(/-/g,"/");
    var begdate = new Date(begstr);
    var date=str[0].split("-");
    var y = date[0].toString(); // year
    var m = date[1].toString(); // month
    var d = date[2].toString(); // day
    var endstr =$("#time").val()+" "+"23:59:59";
    endstr = endstr.split(" ");
    var beg=shortHour2Second(str[1].toString());
    var end=shortHour2Second(endstr[1].toString());
    var param = [];
     param.push({name: 'MediaType', value: 2});
     param.push({name: 'DownType', value: 2});
     param.push({name: 'jsession', value: jsession});
     if(radioFileLocation != 1) {
         param.push({name: 'DevIDNO', value: number.toString()});
     }else {
         param.push({name: 'DevIDNO', value: id.toString()});
     }
     /*param.push({name:'DevIDNO',value:devIdno});*/
     param.push({name: 'Location', value:Number(radioFileLocation)});
    
     $.ajax({
        type:'POST',
        url:'http://'+ ip_ +':' + port_+'/3/1/callback=getData',
        data:param,
        cache:false,
        dataType: 'jsonp',
        success: getData = function (data) {
            if(data.result == 0){
                serverIp=data.server.clientIp;
                serverPort=data.server.clientPort;
 
                var param2 = [];
                param2.push({name: 'DownType', value: 2});
                 param2.push({name: 'jsession', value: jsession});
                 if(radioFileLocation != 1) {
                     param2.push({name: 'DevIDNO', value: number.toString()});
                 }else {
                     param2.push({name: 'DevIDNO', value: id.toString()});
                 }
                 param2.push({name: 'LOC', value: Number(radioFileLocation)});
                 param2.push({name: 'CHN', value: -1});
                 param2.push({name: 'YEAR', value: Number(y)});
                 param2.push({name: 'MON', value: Number(m)});
                 param2.push({name: 'DAY', value: Number(d)});
                 param2.push({name: 'RECTYPE', value: Number(radioVideoType)});
                 param2.push({name: 'FILEATTR', value: Number(radioFileType)});
                 param2.push({name: 'BEG', value:beg});
                 param2.push({name: 'END', value:end});
                 $.ajax({
                    type:'POST',
                    url:'http://'+serverIp+':'+serverPort+'/3/5/callback=getData',
                    data:param2,
                    cache:false,
                    dataType: 'jsonp',
                    success: getData = function (json) {
                        $("#videoInfoTable tr").remove();
                        if(data.result == 0){
                            addVideoFileInfo(json);
                        }else{
                            alert(lang.VideoQueryPrompt);
                        }
                        IsSearching=false;
                        $("#query").val(lang.query);
                    }
                 });
            }else{
                alert(lang.ServerQueryPrompt);
                IsSearching=false;
                $("#query").val(lang.query);
            }
        }
    });    
}
 
function getChns(){
    channels=new Array();
    $("input:checkbox[name='channel']:checked").each(function(){
        channels.push($(this).val());
    });
    return channels;
}
 
 
/**
 * Add video file information
 **/ 
function addVideoFileInfo(json) {
    //Adding list to search
        var files = new Array();
        if(json.files != null && json.files.length > 0) {
            //File list sort, according to the start time from small to large
            json.files.sort(function(a,b){return a.beg > b.beg ? 1 : -1});
            //Add to video file list
            var index = 0;
            for (var i = 0; i < json.files.length; i++) {
                //The vehicle does not contain this channel, then the information is removed.
                var isAdd = true;
                //Can download the task of the whole file download
                //Multiple channel files, can only be downloaded
                //ChnMask>0 according to the position to determine the number of channels CHN is also a number of channels
                if(json.files[i].chnMask > 0) {
                    json.files[i].maskChns = getMaskChnArray(json.files[i].chnMask).maskChns;
                    json.files[i].chnName = getMaskChnArray(json.files[i].chnMask).maskChnNames;
                    json.files[i].isSegment = true;//Whether can only be downloaded
                    if(json.files[i].maskChns == '') {
                        isAdd = false;
                    }
                }else {
                    //chn == 98 All channels
                    if(json.files[i].chn == 98) {
                        json.files[i].chnName = getAllChnName();
                        json.files[i].isSegment = true;
                        if(json.files[i].chnName == '') {
                            isAdd = false;
                        }
                    }else {
                        json.files[i].chnName = getChnName(json.files[i].chn);
                        if(json.files[i].chnName == '') {
                            isAdd = false;
                        }
                    }
                }
                if(isAdd) {
                    json.files[i].id = index;
                    if(json.files[i].type == 1) {
                        json.files[i].color = "#FF0000";
                    }
                    json.files[i].vehiIdno = vehiIdno;
                    //Handling files across days
                    processFileDay(json.files[i]);
                    json.files[i].isDirect = true;
                    
                    
                    for(var j=0;j<channels.length;j++){
                        if(json.files[i].chn == channels[j]){
                            videoFileList.put(index, json.files[i]);
                            files.push(json.files[i]);
                            index++;
                        }
                        
                    }
                }
            }
            if(files.length > 0) {
                //Add to video file list
                $("#videoInfoTable").flexAppendRowJson(files, false);
                $.dialog.tips(lang.searchEnded, 1);
 
            }
        }
        if(json.result == 0) {
            if(files.length <= 0) {
                $.dialog.tips(lang.NullVideoFileInfo, 2);
            }
        }else if(json.result == 23){
            $.dialog.tips(lang.deviceNotOnline, 2);//设备不在线
        }else {
            var mess = '';
            if((typeof showDialogErrorMessage) == 'function') {
                mess = showDialogErrorMessage(json.result, json.cmsserver);
            }
            if(mess != null && mess == '') {
                $.dialog.tips(lang.errorGetVideoFile, 2);
            }
        }
}
 
//Deal with file information, cross day
function processFileDay(data) {
    //File across the day before the day of the day or the day after the time
    //To judge the day before the cross, if the date is the day before
    
    var beginstr =$("#time").val()+" "+"00:00:00";
    beginstr = beginstr.replace(/-/g,"/");
    var begindate = new Date(beginstr);
    data.yearMonthDay = dateFormat2DateString(begindate);
    var day = Number(data.yearMonthDay.substring(8, 10));
    var fileDay = Number(data.day);
    var fileRealDate = getFileTime(data.year, data.mon, data.day);
    if(!dateCompareStrDateRange(data.yearMonthDay, fileRealDate, 1) || !dateCompareStrDateRange(fileRealDate, data.yearMonthDay, 1)) {
        loadTimeLine = false;
        data.relBeg = data.beg;
        data.relEnd = data.end;
        data.beginDate = fileRealDate +' '+ second2ShortHourEx(data.beg);
        data.endDate = fileRealDate +' '+ second2ShortHourEx(data.end);
        data.timeTitle = data.beginDate + ' - ' + second2ShortHourEx(data.end);
    }else {
        loadTimeLine = true;
        //The day before
        if(fileDay < day || (day == 1 && fileDay <= 31 && fileDay >=28 )) {
            data.relBeg = 0;
            data.relEnd = Number(data.end) - 86400;
            data.beginDate = fileRealDate +' '+ second2ShortHourEx(data.beg);
            data.endDate = dateFormat2DateString(dateGetNextMulDay(dateStrLongTime2Date(data.beginDate), 1)) +' '+ second2ShortHourEx(data.relEnd);
            data.timeTitle = data.beginDate + ' - ' + data.endDate;
        }else if(fileDay == day && Number(data.end) > 86400)  {
            //ay after day
            data.relBeg = data.beg;
            data.relEnd = 86399;
            data.beginDate = fileRealDate +' '+ second2ShortHourEx(data.beg);
            data.endDate = dateFormat2DateString(dateGetNextMulDay(dateStrLongTime2Date(data.beginDate), 1)) +' '+ second2ShortHourEx(Number(data.end) - 86400);
            data.timeTitle = data.beginDate + ' - ' + data.endDate;
        }else {
            data.relBeg = data.beg;
            data.relEnd = data.end;
            data.beginDate = fileRealDate +' '+ second2ShortHourEx(data.beg);
            data.endDate = fileRealDate +' '+ second2ShortHourEx(data.end);
            data.timeTitle = data.beginDate + ' - ' + second2ShortHourEx(data.end);
        }
    }
}
 
//get file time
function getFileTime(year, mon, day) {
    var retTime = "";
    retTime += Number(year)+2000;
    retTime += "-";
    if(mon < 10) {
        retTime += "0"+mon;
    }else {
        retTime += mon;
    }
    retTime += "-";
    if(day < 10) {
        retTime += "0"+day;
    }else {
        retTime += day;
    }
    return retTime;
}
 
//Gets the name of the channel, comma separated
function getMaskChnArray(chnMask) {
    var chns = [];
    var chnNames = [];
    if(queryVehicleChannels) {
        for (var i = 0; i < queryVehicleChannels.length; i++) {
            if((chnMask>>queryVehicleChannels[i].index)&1 > 0  && queryVehicleChannels[i].devType == 1) {
                
                chns.push(queryVehicleChannels[i].index);
                chnNames.push(queryVehicleChannels[i].name);
            }
        }
    }
    var data = {};
    data.maskChns = chns.toString();
    data.maskChnNames = chnNames.toString();
    return data;
}
 
//获取所有通道名,逗号分隔
function getAllChnName() {
    var chnNames = [];
    if(this.queryVehicleChannels) {
        for (var i = 0; i < this.queryVehicleChannels.length; i++) {
            if(this.queryVehicleChannels[i].devType == 1) {
                chnNames.push(this.queryVehicleChannels[i].name);
            }
        }
    }
    return chnNames.toString();
}
 
//Get the channel name
function getChnName(chn) {
    return "CH"+(++chn);
}
 
//初始化视频插件
function initPlayer() {
      //视频插件初始化参数
      var params = {
        allowFullscreen: "true",
        allowScriptAccess: "always",
        bgcolor: "#FFFFFF",
        wmode: "transparent"
        };
      //初始化flash
      swfobject.embedSWF("player.swf", "cmsv6flash", swfwidth, swfheight, "11.0.0", null, null, params, null);
      initFlash();
}
 
//设置flash窗口数量
function loadFlashWindowNum(num) {
    if (num == 1) {
        swfobject.getObjectById('cmsv6flash').setWindowNum(1);
    } else if (num == 2) {
        swfobject.getObjectById('cmsv6flash').setWindowNum(2);
    } else if (num == 3) {
        swfobject.getObjectById('cmsv6flash').setWindowNum(3);
    } else {
        swfobject.getObjectById('cmsv6flash').setWindowNum(4);
    }
}
 
//视频插件是否加载完成
function initFlash() {
    
    if (swfobject.getObjectById("cmsv6flash") == null ||
        typeof swfobject.getObjectById("cmsv6flash").setWindowNum == "undefined" ) {
        setTimeout(initFlash, 50);
    } else {
          //设置视频插件的语言
          if (getUrlParameter("lang") == "en") {
              swfobject.getObjectById('cmsv6flash').setLanguage("en.xml");
          } else {
              swfobject.getObjectById('cmsv6flash').setLanguage("cn.xml");
          }
          //先将全部窗口创建好
          swfobject.getObjectById("cmsv6flash").setWindowNum(1);
          //再配置当前的窗口数目
          loadFlashWindowNum(1);
          isInitFinished = true;
         
    }
}
 
//获取URL参数信息
function getUrlParameter(name){
    if(location.search==''){
        return '';
    }
    
    var o={};
    var search=location.search.replace(/\?/,'');//只替换第一个问号,如果参数中带有问号,当作普通文本
    var s=search.split('&');
    for(var i=0;i<s.length;i++){
        o[s[i].split('=')[0]]=s[i].split('=')[1];
    }
    return o[name]==undefined?'':o[name];
}
 
 
//视频播放
//双击后播放当前行视频
function doubleClickVideoReplay(obj,event){
    var rowId = $.trim($(obj).attr('data-id'));
    QueryServer(rowId,'replay');
}
 
//Breakpoint download video file
function downloadVideoFile(id) {
    if(id != null) {
        if(!confirm(lang.allowed)){
            return;
        }
        //Search and download the video file server information, after the successful download video file information
        QueryServer(id,'down');
    }
}    
 
//Replay
function videoFileReplay(obj, id) {
        QueryServer(id,'replay');
}
 
 
//Query related server information
function QueryServer(id,type) {
    //从报表获取数据
    var fileInfo = videoFileList.get(Number(id));
    var FILESVR=fileInfo.svr;
    var FILELOC=fileInfo.loc;
    var param = [];
    param.push({name: 'MediaType', value: 2});
    param.push({name: 'DownType', value: 3});
    param.push({name: 'jsession', value: jsession});
    param.push({name: 'DevIDNO', value: vehiIdno});
 
//    param.push({name:'DevIDNO',value:devIdno}); 
    param.push({name: 'Location', value:Number(radioFileLocation)});
    param.push({name:'FileSvrID',value:Number(FILESVR)});
    $.ajax({
        type:'POST',
        url:'http://'+ ip_ +':' + port_+'/3/1/callback=getData',
        data:param,
        cache:false,
        dataType: 'jsonp',
        success: getData = function (data) {
            if(data.result == 0){
                if(type=='down'){
                    doDownloadVideoFileInfo( devIdno, id, data.server);
                }
                else if(type=='replay'){
                    doReplayVehicleServer(id,devIdno,FILELOC,FILESVR,data.server);
                }
            }else{
                alert(lang.ServerQueryPrompt);
            }
        }
    });    
}
 
//Download video file information
function doDownloadVideoFileInfo(Idno,id, dwServer) {
    var devIdno = Idno;
    var len = $("#row"+id+" .len div").text();
    var file = $("#row"+id+" .file div").text();
    var url = "http://" + dwServer.clientIp +':'+ dwServer.clientPort + "/3/5?DownType=3";
    url += "&DevIDNO="+ devIdno;
    url += "&FLENGTH="+ len;
    url += "&FOFFSET=0";
    url += "&MTYPE=1";
    url += "&FPATH="+ file;
    var paths = file.split('/');
    if (paths.length == 1) {
        paths = file.split('\\');
    }
    url += "&SAVENAME="+ encodeURI(paths[paths.length - 1]);
    window.open(url, "_blank");
}
 
//Access to video file playback server information
function doReplayVehicleServer(id,Idno,loc,svr,dwServer){
    var beg=videoFileList.get(Number(id)).beg;
    var end=videoFileList.get(Number(id)).end;
    
    console.log(videoFileList.get(Number(id)));
    
    var DValue=0;
    var chnStr=$("#row"+id+" .vehiChn div").text();
    var chn=chnStr.substring(2,chnStr.length)-1;
    var filename =$("#row"+id+" .file div").text();
    var lastindex=filename.lastIndexOf('/');
    var title=filename.substring(lastindex+1,filename.length);
    //Real time database access
    var url='http://'+dwServer.clientIp +':'+ dwServer.clientPort+'/3/5?DownType=5&DevIDNO='+Idno+'&FILELOC='+loc+'&FILESVR='+svr+'&FILECHN='+chn+'&FILEBEG='+beg+'&FILEEND='+end+'&PLAYIFRM=0&PLAYFILE='+filename+'&PLAYBEG=0&PLAYEND='+DValue+'&PLAYCHN=0';
    startPlayback(url,title);
}
 
 
var  beginDateTime = null;
var  endDateTime = null;
 
function doSegementDownloadServer(id){
    beginDateTime =  videoFileList.get(Number(id)).beginDate;
    endDateTime = videoFileList.get(Number(id)).endDate;
    $.dialog({id:'selectTime', title: lang.setParam,content: 'url:selectTime.html?id='+id,
            width:'450px',height:'200px', min:false, max:false, lock:true});
}
 
 
function downloadTask(id){
    
    $.dialog({id:'selectTime'}).close();
    var beg = videoFileList.get(Number(id)).beginDate;//文件日期
    var end = videoFileList.get(Number(id)).endDate;//
    var type = videoFileList.get(Number(id)).type;//类型 1报警 0正常
    //从videoFileList获取数据
    var Fph = videoFileList.get(Number(id)).file;
    var Len = videoFileList.get(Number(id)).len;
    var Chn = videoFileList.get(Number(id)).chn;
    var param = [];
    param.push({name: 'jsession', value: jsession});
    param.push({name: 'did', value: devIdno});
    param.push({name: 'fbtm', value: beginDateTime});
    param.push({name: 'fetm', value: endDateTime});
    param.push({name: 'sbtm', value: beg});
    param.push({name: 'setm', value:end});
    param.push({name: 'lab', value:'downloadExample'});
    param.push({name: 'fph', value: Fph});//录像文件路径  35
    param.push({name: 'vtp', value: type});//设备回传 1 报警类型 0 正常
    param.push({name: 'len', value: Len});//文件大小  35
    param.push({name: 'chn', value: Chn});
    param.push({name: 'dtp', value:2});
    
    /*http://localhost:8080/StandardApiAction_addDownloadTask.action?
    jsession=cf6b70a3-c82b-4392-8ab6-bbddce336222
    &did=500000  //设备号  *
    &fbtm=2015-12-25 00:00:00  //文件开始时间  3135
    &fetm=2015-12-30 23:59:59  //文件结束时间 3135
    &sbtm=2015-12-25 00:00:00  //源文件开始时间
    &setm=2015-12-30 23:59:59  //源文件结束时间
    &lab=downloadExample //录像文件标签
    &fph=/mnt/hgfs/record/H20121123-112931P3A1P0.avi  //录像文件路径  35
    &vtp=1  //录像类型0表示常规,1表示报警。  0
    &len=5000  //文件大小  35
    &chn=1  //录像通道  35
    &dtp=1  //下载方式1表示全文件下载,2表示分段下载。  2*/ 
    $.ajax({
        type:'POST',
        url:'http://'+host+'/StandardApiAction_addDownloadTask.action',
        data:param,
        cache:false,
        dataType: 'jsonp',
        success: getData = function (data) {
            if(data.result == 0){
                $.dialog.tips(lang.segemenDownloadSuccess, 1);
            }else{
                alert(lang.segemenDownloadFail);
            }
        }
    });    
    
 
}
 
 
 
 
//提交ajax
function doAjaxSubmit(action, params, callback) {
    $.ajax({
        type: 'POST',
        url: action,
        data: params,
        cache:false,/*禁用浏览器缓存*/
        dataType: 'json',
        success: function (json) {
            if(json.result == 0){
                callback.call(this, json, action, true);
            } else {
                callback.call(this, json, action, false);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            try {
                if (p.onError) p.onError(XMLHttpRequest, textStatus, errorThrown);
            } catch (e) {}
            callback.call(this, null, action, false);
        }
    });
}
 
 
function setPanelWidth(){
//    var _width = document.body.clientWidth;
//    var _height = document.body.clientHeight;
    
    var _width =min($(window).innerWidth(),document.body.clientWidth,document.documentElement.clientWidth);
    var _height =min($(window).innerHeight(),document.body.clientHeight,document.documentElement.clientHeight) - 39;
    $("#videoInfo").width(520);
    $("#selection").width(520);
    if(_width < 980){
        $('body').width(980);
        swfwidth=980-$("#videoInfo").width()-35;
    }else{
        var w=_width-10;
        $('body').width(_width-10);
        swfwidth=_width-10-$("#videoInfo").width()-35;
    }
//    swfwidth=_width-$("#videoInfo").width()-35;
    swfheight=_height-39;
    $("#cmsv6flash").width(swfwidth);
    $("#cmsv6flash").height(swfheight);
    $("#videoInfo").height(swfheight);
}
function min(a,b,c){
    var i=a;
    if(a>b){
        i=b;
    }else if(i>c){
        i=c
    }
    return c;
}
/**
 * Start remote playback
 **/
function startPlayback(url,title) {
    if (!isInitFinished){
      return;
    } else {
        
        setWindowTitle(title);
        //Window index
        var index = 0;
        //Stop before playback
        swfobject.getObjectById('cmsv6flash').stopVideo(index);
        //Start playback
          swfobject.getObjectById("cmsv6flash").startVod(index, url);
          
    }
}
/**
    *Set window title
    **/
function setWindowTitle(title) {
      if (!isInitFinished){
          return;
      } else {
          //窗口下标
          var index = 0;
          swfobject.getObjectById("cmsv6flash").setVideoInfo(index, title);
      }
}