trafficflowreport.jsp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <%@ page import="org.apache.commons.lang3.StringUtils" %>
  2. <%@ page import="java.sql.Timestamp" %>
  3. <%--
  4. Created by IntelliJ IDEA.
  5. User: SamRichard
  6. Date: 2017/1/12 0012
  7. Time: 13:29
  8. To change this template use File | Settings | File Templates.
  9. --%>
  10. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  11. <%
  12. String path = request.getContextPath();
  13. String basePath = request.getScheme() + "://"
  14. + request.getServerName() + ":" + request.getServerPort()
  15. + path + "/";
  16. Integer fullscreen = 0;
  17. String strFullscreen = (String) request.getParameter("fullscreen");
  18. if (StringUtils.isNotBlank(strFullscreen)){
  19. fullscreen = Integer.parseInt(strFullscreen);
  20. }
  21. String[] strTaskName = request.getParameterValues("taskname");
  22. String strStartTime = (String)request.getParameter("starttime");
  23. String strEndTime = (String)request.getParameter("endtime");
  24. Integer charttype = null;
  25. String strType = (String)request.getParameter("type");
  26. if (StringUtils.isNotBlank(strType)){
  27. charttype = Integer.parseInt(strType);
  28. }
  29. if (charttype == null && StringUtils.isNotBlank(strStartTime) && StringUtils.isNotBlank(strEndTime)){
  30. try {
  31. Timestamp a = Timestamp.valueOf(strStartTime);
  32. Timestamp b = Timestamp.valueOf(strEndTime);
  33. Long iDif = (b.getTime() - a.getTime()) / 1000;
  34. System.out.println(a.toString() + ":" + b.toString() + ":" + iDif.toString());
  35. if (iDif <= 0){
  36. } else if (iDif <= 2 * 3600){
  37. charttype = 0;
  38. } else if (iDif <= 2 * 86400){
  39. charttype = 1;
  40. } else if (iDif <= 60 * 86400){
  41. charttype = 2;
  42. } else {
  43. charttype = 3;
  44. }
  45. } catch (Exception e){
  46. e.printStackTrace();
  47. }
  48. }
  49. if (charttype == null){
  50. charttype = 0;
  51. }
  52. %>
  53. <!DOCTYPE html>
  54. <html lang="zh-cn">
  55. <head>
  56. <meta charset="utf-8">
  57. <meta http-equiv="x-ua-compatible" content="IE=edge">
  58. <meta name="viewport" content="width=device-width, initial-scale=1">
  59. <title>车流量报表</title>
  60. <link rel="stylesheet" href="css/bootstrap.min.css">
  61. <link rel="stylesheet" href="css/select2.min.css">
  62. <link rel="stylesheet" href="css/select2-bootstrap.css">
  63. <link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
  64. <link href="css/sweetalert2.min.css" rel="stylesheet">
  65. <link rel="icon" href="../favicon.ico">
  66. </head>
  67. <body>
  68. <div id="pagebody" class="container-fluid">
  69. <br>
  70. <form class="row form-inline" id="t2">
  71. <fieldset>
  72. <div class="col-md-1 form-group" style="padding-right: 5px;">
  73. <label class="sr-only" for="js-data-ajax-subinfo">分中心</label>
  74. <select id="js-data-ajax-subinfo" class="form-control" style="width:100%"></select>
  75. </div>
  76. <div class="col-md-3 form-group" style="padding-right: 5px;">
  77. <label class="sr-only" for="js-data-ajax-taskinfo">通道名称:</label>
  78. <select id="js-data-ajax-taskinfo" class="form-control" style="width: 100%;height: 34px;" multiple="multiple"></select>
  79. </div>
  80. <div class="col-md-1 form-group" style="padding-right: 5px;">
  81. <label for="timequickselect" class="sr-only">选择时间</label>
  82. <select class="form-control" id="timequickselect" style="width: 100%;height: 34px;">
  83. <option value="1">最近一小时</option>
  84. <option value="2">&nbsp;&nbsp;今&nbsp;&nbsp;天&nbsp;&nbsp;</option>
  85. <option value="3">&nbsp;&nbsp;本&nbsp;&nbsp;周&nbsp;&nbsp;</option>
  86. <option value="4">&nbsp;&nbsp;本&nbsp;&nbsp;月&nbsp;&nbsp;</option>
  87. <option value="5">&nbsp;&nbsp;本&nbsp;&nbsp;年&nbsp;&nbsp;</option>
  88. <option value="6">&nbsp;&nbsp;自定义&nbsp;&nbsp;</option>
  89. </select>
  90. </div>
  91. <div class="col-md-3 form-group">
  92. <label for="dtp_input1" class="control-label">始于:</label>
  93. <div class="input-group date form_datetime" data-date="2016/09/16 00:00:00+0800" data-date-format="yyyy-mm-dd hh:ii:00" data-link-field="dtp_input1" id="starttime">
  94. <input class="form-control" size="16" type="text" value="" readonly>
  95. <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
  96. <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
  97. </div>
  98. <input type="hidden" id="dtp_input1" value="" /><br/>
  99. </div>
  100. <div class="col-md-3 form-group">
  101. <label for="dtp_input2" class="control-label">终于:</label>
  102. <div class="input-group date form_datetime" data-date="22016-09-16T05:25:07+08:00" data-date-format="yyyy-mm-dd hh:ii:00" data-link-field="dtp_input2" id="endtime">
  103. <input class="form-control" size="16" type="text" value="" readonly>
  104. <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
  105. <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
  106. </div>
  107. <input type="hidden" id="dtp_input2" value="" /><br/>
  108. </div>
  109. <div class="col-md-1 form-group">
  110. <button id="getinfo" type="button" class="btn btn-primary btn-block">查看</button>
  111. </div>
  112. </fieldset>
  113. </form>
  114. <br>
  115. <div id="info" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
  116. </div>
  117. <script src="js/jquery-3.1.1.min.js"></script>
  118. <script src="js/bootstrap.min.js"></script>
  119. <script src="js/highcharts.src.js"></script>
  120. <script src="js/exporting.js"></script>
  121. <script src="js/dark-unica.js"></script>
  122. <script src="js/select2.min.js"></script>
  123. <script src="js/select2-zh-CN.js"></script>
  124. <script src="js/bootstrap-datetimepicker.min.js" charset="UTF-8"></script>
  125. <script src="js/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
  126. <script src="js/sweetalert2.min.js"></script>
  127. <script src="js/es6-promise.auto.min.js"></script>
  128. <script>
  129. //设置宽高
  130. if (<%=fullscreen%>){
  131. $("#pagebody").removeClass("container-fluid");
  132. $("br").remove();
  133. $("#t2").remove();
  134. $("#info").height(document.documentElement.clientHeight);
  135. $("#info").width(document.documentElement.clientWidth);
  136. } else {
  137. var hchartsheight = document.documentElement.clientHeight - $("br").height() * 2 - $("fieldset")[0].clientHeight - 14 * 2;
  138. if (hchartsheight > 100){
  139. $("#info").height(hchartsheight);
  140. }
  141. }
  142. //设置中文
  143. Highcharts.setOptions({
  144. lang:{
  145. contextButtonTitle:"图表导出菜单",
  146. decimalPoint:".",
  147. downloadJPEG:"下载JPEG图片",
  148. downloadPDF:"下载PDF文件",
  149. downloadPNG:"下载PNG文件",
  150. downloadSVG:"下载SVG文件",
  151. drillUpText:"返回 {series.name}",
  152. loading:"加载中",
  153. months:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],
  154. noData:"没有数据",
  155. numericSymbols: [ "千" , "兆" , "G" , "T" , "P" , "E"],
  156. printChart:"打印图表",
  157. resetZoom:"恢复缩放",
  158. resetZoomTitle:"恢复图表",
  159. //shortMonths: [ "Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec"],
  160. shortMonths: [ "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "11" , "12"],
  161. thousandsSep:",",
  162. weekdays: ["星期一", "星期二", "星期三", "星期三", "星期四", "星期五", "星期六","星期天"]
  163. },
  164. global : {
  165. useUTC : false
  166. }
  167. });
  168. //图表属性
  169. var options = {
  170. chart: {
  171. renderTo:"info",
  172. type: 'spline'
  173. },
  174. title: {
  175. text: '车流量曲线'
  176. },
  177. subtitle: {
  178. text: '类型:日曲线'
  179. },
  180. xAxis:[{
  181. type : 'datetime',
  182. title : {
  183. text : "时间"
  184. },
  185. // dateTimeLabelFormats: {
  186. // millisecond:"%M:%S.%L",
  187. //second:"%H:%M:%S",
  188. //minute:"%d %H:%M",
  189. //hour:", %m-%d %H",
  190. //day:"%Y-%m-%d,%A",
  191. //week:"%A",
  192. //month:"%Y-%M",
  193. //year:"%Y"
  194. // },
  195. labels : {
  196. enabled : true,
  197. //step : 2,
  198. formatter : function(){
  199. var date = new Date(this.value);
  200. switch (type){
  201. case 0:
  202. //分
  203. return date.getHours() + ":" + date.getMinutes();
  204. case 1:
  205. //时
  206. return date.getHours() + ":00";
  207. case 2:
  208. //天
  209. return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
  210. case 3:
  211. //月
  212. return date.getFullYear() + "-" + (date.getMonth() + 1);
  213. default:
  214. return this.value;
  215. }
  216. }
  217. },
  218. crosshair: true
  219. }],
  220. yAxis: {
  221. title: {
  222. text: '车流量'
  223. }
  224. },
  225. /*
  226. plotOptions: {
  227. line: {
  228. dataLabels: {
  229. enabled: true
  230. },
  231. enableMouseTracking: false
  232. }
  233. },
  234. */
  235. tooltip: {
  236. crosshairs: [true, true],
  237. shared: true,
  238. formatter : function(){
  239. this;
  240. },
  241. },
  242. credits:{
  243. enabled:true, // 版权信息
  244. text:"杭州慧景科技股份有限公司",
  245. href:"http://www.hzhjkj.com/"
  246. },
  247. series: []
  248. };
  249. var refreshtimer;
  250. var taskname = new Array();
  251. <% if (strTaskName != null) {
  252. for (int i = 0; i < strTaskName.length; i++){ %>
  253. taskname[<%=i%>] = "<%=strTaskName[i]%>";
  254. <%}}%>
  255. var starttime = '<%=strStartTime%>';
  256. var endtime = '<%=strEndTime%>';
  257. var type = <%=charttype%>;
  258. var $subinfo = $("#js-data-ajax-subinfo");
  259. var $taskinfo = $("#js-data-ajax-taskinfo");
  260. var $timequick = $("#timequickselect");
  261. var $startime = $("#starttime");
  262. var $endtime = $("#endtime");
  263. var subinfo;
  264. var taskinfo;
  265. //修改输出
  266. //if (!Date.prototype.toISOString) {
  267. (function() {
  268. function pad(number) {
  269. if (number < 10) {
  270. return '0' + number;
  271. }
  272. return number;
  273. }
  274. Date.prototype.toISOString = function() {
  275. return this.getFullYear() +
  276. '-' + pad(this.getMonth() + 1) +
  277. '-' + pad(this.getDate()) +
  278. ' ' + pad(this.getHours()) +
  279. ':' + pad(this.getMinutes()) +
  280. ':' + pad(this.getSeconds())
  281. ;
  282. };
  283. }());
  284. //}
  285. //初始函数
  286. $(function () {
  287. if (<%=StringUtils.isNotBlank(strStartTime) && StringUtils.isNotBlank(strEndTime)%>){
  288. var a = new Date(Date.parse('<%=strStartTime%>'.replace(/-/g, "/")));
  289. var b = new Date(Date.parse('<%=strEndTime%>'.replace(/-/g, "/")));
  290. $startime.datetimepicker('update', a);
  291. $endtime.datetimepicker('update', b);
  292. setType(a, b);
  293. $("#timequickselect").val(6).trigger("change");
  294. } else {
  295. var date = new Date();
  296. date.setSeconds(0);
  297. date.setMilliseconds(0);
  298. date.setMinutes(date.getMinutes() + 10);
  299. var date2 = new Date(date);
  300. date2.setHours(date.getHours() - 2);
  301. $startime.datetimepicker('update', date2);
  302. $endtime.datetimepicker('update', date);
  303. type = 0;
  304. starttime = date2.toISOString();
  305. endtime = date.toISOString();
  306. }
  307. queryData();
  308. $.get("getsubinfo.cpp", "", function (data) {
  309. subinfo = $subinfo.select2({
  310. language: "zh-CN",
  311. minimumResultsForSearch: Infinity,
  312. placeholder: "选择分中心",
  313. data : data
  314. });
  315. if (data.length > 0){
  316. $.get("gettaskinfo.cpp", { subno : data[0].id }, function (data2) {
  317. taskinfo = $taskinfo.select2({
  318. language: "zh-CN",
  319. placeholder: "选择通道",
  320. maximumSelectionLength: 10,
  321. allowClear: true,
  322. disabled : false,
  323. data : data2
  324. })
  325. })
  326. } else {
  327. taskinfo = $taskinfo.select2({
  328. language: "zh-CN",
  329. placeholder: "选择通道",
  330. maximumSelectionLength: 10,
  331. allowClear: true,
  332. disabled : true,
  333. data : null
  334. });
  335. }
  336. $timequick.select2({
  337. language: "zh-CN",
  338. minimumResultsForSearch: Infinity,
  339. placeholder: "选择时间",
  340. });
  341. });
  342. })
  343. var chart;
  344. //请求数据
  345. function queryData() {
  346. if (taskname.length === 0)
  347. return ;
  348. var urladdr = "getrtinfo.cpp?starttime=" + encodeURI(starttime) + "&endtime=" + encodeURI(endtime) + "&type=" + type + "&fullscreen=" + <%=fullscreen%> + "&timestamp=" + new Date().getTime();;
  349. for (var i = 0 ; i < taskname.length; i++)
  350. {
  351. urladdr += "&taskname=" + encodeURI(taskname[i]);
  352. }
  353. $.ajax({
  354. url : urladdr,
  355. type : "get",
  356. dataType : "json",
  357. success : function (data) {
  358. if (data.series.length === 0) {
  359. clearTimeout(refreshtimer);
  360. swal({
  361. type: 'success',
  362. title: '无数据',
  363. timer: 3000
  364. }).then(
  365. function () {},
  366. // handling the promise rejection
  367. function (dismiss) {
  368. if (dismiss === 'timer') {
  369. console.log('I was closed by the timer')
  370. }
  371. }
  372. )
  373. return ;
  374. }
  375. options.series = data.series;
  376. if (type == 0){
  377. options.subtitle.text = "分曲线";
  378. options.yAxis.title.text = "车辆数(辆/分)";
  379. } else if (type == 1){
  380. options.subtitle.text = "时曲线";
  381. options.yAxis.title.text = "车辆数(辆/时)";
  382. } else if (type == 2){
  383. options.subtitle.text = "日曲线";
  384. options.yAxis.title.text = "车辆数(辆/日)";
  385. } else if (type == 3){
  386. options.subtitle.text = "月曲线";
  387. options.yAxis.title.text = "车辆数(辆/月)";
  388. } else {
  389. alert(type);
  390. }
  391. if (chart) {
  392. chart = null;
  393. }
  394. chart = new Highcharts.chart(options);
  395. }
  396. })
  397. //定时刷新
  398. var now = new Date();
  399. var date = new Date(Date.parse(starttime.replace(/-/g, "/")));
  400. var date2 = new Date(Date.parse(endtime.replace(/-/g, "/")));
  401. if (now >= date && now <= date2)
  402. {
  403. date.setMinutes(date.getMinutes() + 1);
  404. date2.setMinutes(date2.getMinutes() + 1);
  405. starttime = date.toISOString();
  406. endtime = date2.toISOString();
  407. refreshtimer = setTimeout("queryData()", 60000);
  408. }
  409. }
  410. $subinfo.on("select2:select", function (e) {
  411. inittaskinfo();
  412. $.get("gettaskinfo.cpp", { subno : e.params.data.id }, function (data) {
  413. taskinfo = $taskinfo.select2({
  414. language: "zh-CN",
  415. placeholder: "选择通道",
  416. maximumSelectionLength: 10,
  417. allowClear: true,
  418. disabled : false,
  419. data : data
  420. })
  421. })
  422. });
  423. function inittaskinfo() {
  424. //$taskinfo.select2("val", "");
  425. //$taskinfo.val(null).trigger("change");
  426. $taskinfo.select2({
  427. disabled : true,
  428. placeholder: "选择通道",
  429. data : null
  430. });
  431. }
  432. $timequick.on("select2:select", function (e) {
  433. console.log("SELECT " + e.params.data.id );
  434. var date = new Date();
  435. date.setSeconds(0);
  436. date.setMilliseconds(0);
  437. switch (e.params.data.id){
  438. case "1":
  439. var date2 = new Date(date);
  440. date2.setHours(date.getHours() - 1)
  441. $startime.datetimepicker('update', date2);
  442. $endtime.datetimepicker('update', date);
  443. type = 0;
  444. break;
  445. case "2":
  446. var date2 = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 1);
  447. $startime.datetimepicker('update', date2);
  448. $endtime.datetimepicker('update', date);
  449. type = 1;
  450. break;
  451. case "3":
  452. var dateofweek = date.getDay();
  453. if (dateofweek == 0) { dateofweek = 7 };
  454. var date2 = new Date(date.getFullYear(), date.getMonth(), date.getDate() - dateofweek + 1);
  455. $startime.datetimepicker('update', date2);
  456. $endtime.datetimepicker('update', date);
  457. type = 2;
  458. break;
  459. case "4":
  460. var date2 = new Date(date.getFullYear(), date.getMonth(), 1, 0, 0, 0);
  461. $startime.datetimepicker('update', date2);
  462. $endtime.datetimepicker('update', date);
  463. type = 2;
  464. break;
  465. case "5":
  466. var date2 = new Date(date.getFullYear(), 0, 1, 0, 0, 0);
  467. $startime.datetimepicker('update', date2);
  468. $endtime.datetimepicker('update', date);
  469. type = 3;
  470. break;
  471. default:
  472. }
  473. });
  474. function newIEDate(dateStr) {
  475. // dateStr的格式:xxxx-xx-xx xx:xx:xx
  476. do {
  477. var date1 = dateStr.split(" ");
  478. if (date1.length != 2){
  479. break;
  480. }
  481. var date2 = date1[0].split("-");
  482. if (date2.length != 3){
  483. break;
  484. }
  485. var date3 = date1[1].split(":");
  486. if (date3.length != 3){
  487. break;
  488. }
  489. return new Date(date2[0], date2[1], date2[2], date3[0], date3[1], date3[2]);
  490. } while(0);
  491. return new Date();
  492. }
  493. $("#getinfo").click(function () {
  494. taskname = $taskinfo.select2("val");
  495. starttime = $("#dtp_input1").val();
  496. endtime = $("#dtp_input2").val();
  497. setType(new Date(Date.parse(starttime.replace(/-/g, "/"))), new Date(Date.parse(endtime.replace(/-/g, "/"))));
  498. queryData();
  499. })
  500. function setType(a, b) {
  501. var dif = (b.getTime() - a.getTime()) / 1000;
  502. if (dif <= 0){
  503. return;
  504. } else if (dif <= 2 * 3600){
  505. type = 0;
  506. } else if (dif <= 2 * 86400){
  507. type = 1;
  508. } else if (dif <= 60 * 86400){
  509. type = 2;
  510. } else {
  511. type = 3;
  512. }
  513. }
  514. </script>
  515. </body>
  516. </html>