largedashboard.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  1. 'use strict';
  2. app.controller('watchMapCtrl', ['$rootScope', '$scope', '$http', '$state', '$modal', '$templateCache', '$compile', 'Restangular', 'api_bpm_domain', function($rootScope, $scope, $http, $state, $modal, $templateCache, $compile, Restangular, api_bpm_domain) {
  3. // var ip = document.location.protocol + "//" + document.location.hostname + ":8080";
  4. //更改响应时间
  5. function changeTime(txt) {
  6. //填充字符串
  7. txt = (txt * 1000).toFixed(0);
  8. var time = $("#responseTime");
  9. time.empty();
  10. time.html(txt + "<span style='font:normal normal normal 50px arial,sans-serif;'>ms</span>");
  11. }
  12. //更改响应率
  13. function changePercent(txt) {
  14. //填充字符串
  15. txt = (txt * 100).toFixed(2);
  16. var percent = $("#packetPercent");
  17. percent.empty();
  18. percent.html(txt + "<span style='font:normal normal normal 50px arial,sans-serif;'>%</span>");
  19. }
  20. //鼠标放上支行点,显示tip
  21. // $scope.htmlTooltip = '<div>2314132432</div>';
  22. $scope.showBankTip = function(thisObj, id) {
  23. // var bankId = $(thisObj).attr("bankId");
  24. // var url = ip + "/service/api/bpm/bpm/getWatchAreaData/" + id;
  25. // $.getJSON(url, function(data) {
  26. api_bpm_domain.getWatchAreaData(id).then(function(data) {
  27. // var data = { "handler": 1, "resolved": 2, "close": 3 };
  28. if (data) {
  29. // var name = $(thisObj).attr("name");
  30. // var left = $(thisObj).position().left;
  31. // var top = $(thisObj).position().top - 92;
  32. // $("#toaster").remove(); //移除之前的toast
  33. // var settings = {
  34. // timeout: 100000,
  35. // toaster: {
  36. // 'id': 'toaster',
  37. // 'container': 'body',
  38. // 'template': '<div></div>',
  39. // 'class': 'toaster',
  40. // 'css': {
  41. // 'position': 'absolute',
  42. // 'left': thisObj.x,
  43. // 'top': thisObj.y - 92,
  44. // 'right': '10px',
  45. // 'width': '200px',
  46. // 'zIndex': 50000
  47. // }
  48. // },
  49. // toast: {
  50. // 'template': '<div class="alert alert-%priority% alert-dismissible" role="alert">' +
  51. // '<button type="button" class="close" onclick="$(\'#toaster\').remove()" data-dismiss="alert">' +
  52. // '<span aria-hidden="true">&times;</span>' +
  53. // '<span class="sr-only">Close</span>' +
  54. // '</button>' +
  55. // '<span class="title"></span><span class="message"></span>' +
  56. // '</div>',
  57. // 'css': {},
  58. // 'cssm': {},
  59. // 'csst': { 'fontWeight': 'bold' },
  60. // 'fade': 'slow',
  61. // 'display': function($toast) {
  62. // return $toast.fadeIn(this.fade);
  63. // },
  64. // 'remove': function($toast, callback) {
  65. // return $toast.animate({
  66. // opacity: '0',
  67. // padding: '0px',
  68. // margin: '0px',
  69. // height: '0px'
  70. // }, {
  71. // duration: this.fade,
  72. // complete: callback
  73. // });
  74. // }
  75. // }
  76. // };
  77. var handler = $scope.handler = data.handler; //处理中
  78. var resolved = $scope.resolved = data.resolved; //已解决
  79. var close = $scope.close = data.close; //已关闭
  80. var priority = 'info';
  81. settings.toaster.css.left = thisObj.x;
  82. settings.toaster.css.top = thisObj.y - 92;
  83. // $.toaster({
  84. // priority: priority,
  85. // title: name,
  86. // message: '处理中:' + handler + '<br>已解决:' + resolved +
  87. // '<br/>已关闭:' + close,
  88. // settings: settings
  89. // });
  90. }
  91. });
  92. }
  93. //初始化地图上的点
  94. function initPointer() {
  95. // var data = [{ "id": 1, "area": "主院区", "x": 625, "y": 420 }, { "id": 2, "area": "东院区", "x": 650, "y": 250 }, { "id": 3, "area": "同济院区", "x": 250, "y": 350 }, { "id": 4, "area": "商学院", "x": 426, "y": 500 }]
  96. // var url = "192.168.3.19:8080/service/api/bpm/bpm/getWatchAreaPosition";
  97. // $.getJSON(url, function(data) {
  98. api_bpm_domain.getWatchAreaPosition().then(function(data) {
  99. if (data) {
  100. $scope.arr = data;
  101. $scope.imgName = "green.png";
  102. //移除支行点
  103. // $(".area").remove();
  104. // for (var i = 0; i < $scope.arr.length; i++) {
  105. // var bean = $scope.arr[i];
  106. // $scope.width = 150;
  107. // $scope.height = 22;
  108. // var imgName = "green.png";
  109. // //TODO 一个方法搞定
  110. // $(".showtip").append("<img class='area' onclick='showBankTip(this, " + bean.id + ");'" +
  111. // " src='assets/images/" + imgName + "' style='cursor:pointer;position:absolute;left:" + bean.x + "px;top:" + bean.y + "px;' " +
  112. // " name='" + bean.area + "' areaId='" + bean.id + "' width='16' height='16'/>");
  113. // }
  114. }
  115. });
  116. }
  117. //计算鼠标相对于body的坐标
  118. function mousePosition(ev) {
  119. if (ev.pageX || ev.pageY) {
  120. return {
  121. x: ev.pageX,
  122. y: ev.pageY
  123. };
  124. }
  125. return {
  126. x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
  127. y: ev.clientY + document.body.scrollTop - document.body.clientTop
  128. };
  129. }
  130. //初始化
  131. function init() {
  132. //初始化网络拓扑图数据
  133. initPointer();
  134. //点击其他地方,隐藏设备列表
  135. $("body").click(function(event) {
  136. var pos = mousePosition(event),
  137. x = pos.x,
  138. y = pos.y;
  139. var ele = $("#deviceList"),
  140. elePos = ele.position(),
  141. left = elePos.left,
  142. top = elePos.top;
  143. // alert("x = " + x + "\ny = " + y);
  144. if (x >= left && x <= (left + 500) && y >= top && y <= (top + ele.height())) { //点击了设备列表范围内
  145. return false;
  146. } else {
  147. ele.hide();
  148. }
  149. });
  150. //定时5分钟刷新一次
  151. setTimeout(init, 1000 * 60 * 5);
  152. }
  153. $(function() {
  154. var canvas = document.getElementById('supportHtml5');
  155. if (!canvas.getContext) {
  156. $("link").remove();
  157. var body = $("body");
  158. body.empty();
  159. body.append("<p>您的浏览器不支持HTML5,图表无法展示,请升级到支持HTML5的浏览器,如IE9及以上版本、最新的Chrome、Firefox等浏览器。</p>");
  160. return false;
  161. }
  162. if (!(canvas.style.backgroundSize === '')) {
  163. alert("您的浏览器不支持CSS3特性,部分功能受到影响。");
  164. return false;
  165. }
  166. var width = window.screen.width,
  167. height = window.screen.height;
  168. if (width >= 1920) {
  169. $("body").css("overflow-x", "hidden");
  170. }
  171. init(); //初始化
  172. });
  173. }]);
  174. app.controller('watchListCtrl', ['$rootScope', '$scope', '$http', '$state', '$modal', '$templateCache', '$compile', 'Restangular', 'api_bpm_domain', 'api_bpm_data', function($rootScope, $scope, $http, $state, $modal, $templateCache, $compile, Restangular, api_bpm_domain, api_bpm_data) {
  175. // var keydata = "pending";
  176. // $scope.showdivs = function(name, id, num) {
  177. // for (var i = 1; i < num + 1; i++) {
  178. // document.getElementById(name + i).style.display = "none"; //隐藏其他层
  179. // }
  180. // document.getElementById(name + id).style.display = "block"; //显示当前层
  181. // if (id == 1) {
  182. // keydata = "pending"; //待接单
  183. // } else if (id == 2) {
  184. // keydata = "reassign"; //待处理
  185. // } else if (id == 3) {
  186. // keydata = "handler"; //重新指派
  187. // }
  188. // $scope.refreshData(keydata);
  189. // }
  190. //待接单
  191. $scope.refreshData = function() {
  192. $scope.myData = [];
  193. var defaultFilterData = {
  194. "incident": {
  195. "statusId": "pending"
  196. },
  197. "idx": 0,
  198. "sum": 20
  199. };
  200. var fildata = {
  201. "incident": {
  202. "statusId": "reassign"
  203. },
  204. "idx": 0,
  205. "sum": 20
  206. };
  207. var fileData = {
  208. "incident": {
  209. "statusId": "handler"
  210. },
  211. "idx": 0,
  212. "sum": 20
  213. };
  214. api_bpm_data.fetchDataList("incident", defaultFilterData).then(function(data) {
  215. if (data.list) {
  216. var myData = Restangular.stripRestangular(data);
  217. $scope.myPending = myData.list;
  218. } else {}
  219. }, function() {});
  220. api_bpm_data.fetchDataList("incident", fildata).then(function(data) {
  221. if (data.list) {
  222. var myData = Restangular.stripRestangular(data);
  223. $scope.myReassign = myData.list;
  224. } else {}
  225. }, function() {});
  226. api_bpm_data.fetchDataList("incident", fileData).then(function(data) {
  227. if (data.list) {
  228. var myData = Restangular.stripRestangular(data);
  229. $scope.myHandler = myData.list;
  230. } else {}
  231. }, function() {});
  232. };
  233. $scope.refreshData();
  234. // //待处理
  235. // $scope.refresh = function() {
  236. // $scope.myData = [];
  237. // api_bpm_data.fetchDataList("incident", defaultFilterData).then(function(data) {
  238. // if (data.list) {
  239. // var myData = Restangular.stripRestangular(data);
  240. // var list = [];
  241. // $scope.myData = myData.list;
  242. // } else {
  243. // // Alert.swal({
  244. // // title: "系统错误",
  245. // // text: "请稍后再试!",
  246. // // type: "error"
  247. // // });
  248. // }
  249. // }, function() {});
  250. // };
  251. }]);
  252. app.controller('watchweekCtrl', ["$scope", "$rootScope", "$state", "$timeout", "$interval", "$http", "$cookieStore", "Restangular", "api_report", "api_statistic", function($scope, $rootScope, $state, $timeout, $interval, $http, $cookieStore, Restangular, api_report, api_statistic) {
  253. api_report.getLicenseKey().then(function(response) {
  254. $cookieStore.put('Auth-Token', response.token);
  255. $scope.try_async_load();
  256. });
  257. $scope.try_async_load = function() {
  258. $scope.my_data = [];
  259. api_report.list().then(function(response) {
  260. var dataList = Restangular.stripRestangular(response);
  261. getRepoRoot(dataList, '/homes/home:admin/ITSM报表');
  262. $scope.repoRoot.name = "事件报表"
  263. convertRepoObject($scope.repoRoot);
  264. $scope.my_data.push($scope.repoRoot);
  265. });
  266. };
  267. $scope.repoRoot = null;
  268. function getRepoRoot(repo, path) {
  269. angular.forEach(repo, function(value, key) {
  270. if (value.path == path) {
  271. $scope.repoRoot = value;
  272. } else {
  273. if ($scope.repoRoot == null && angular.isDefined(value.repoObjects)) {
  274. getRepoRoot(value.repoObjects, path);
  275. } else {
  276. }
  277. }
  278. });
  279. }
  280. function convertRepoObject(repo) {
  281. if (angular.isArray(repo)) {
  282. angular.forEach(repo, function(value, key) {
  283. convertRepoObject(value);
  284. })
  285. } else {
  286. if (angular.isDefined(repo.name)) {
  287. if (repo.name.indexOf(".") >= 0) {
  288. repo.label = repo.name.substr(0, repo.name.lastIndexOf("."));
  289. } else {
  290. repo.label = repo.name;
  291. }
  292. //delete repo.name;
  293. }
  294. if (angular.isDefined(repo.repoObjects)) {
  295. repo.children = [];
  296. repo.children = repo.repoObjects;
  297. delete repo.repoObjects;
  298. convertRepoObject(repo.children);
  299. }
  300. }
  301. }
  302. function parseDateParameter(parameters) {
  303. var result = undefined;
  304. if (angular.isArray(parameters)) {
  305. // angular.forEach(parmeters,function(param){
  306. // param.
  307. // })
  308. } else {
  309. result = {};
  310. for (var k in parameters) {
  311. if (k.indexOf("Date") > 0) {
  312. if (angular.isString(parameters[k])) {
  313. result[k] = moment(parameters[k], "YYYYMMDD").format("YYYY-MM-DD");
  314. //result[k] = ''+parameters[k]+'';//= moment(parameters[k], "YYYYMMDD").toDate();
  315. }
  316. }
  317. }
  318. }
  319. return result;
  320. }
  321. function ConvertDateParameter(parameters) {
  322. var result = undefined;
  323. if (angular.isArray(parameters)) {
  324. //
  325. } else {
  326. result = {};
  327. for (var k in parameters) {
  328. if (k.indexOf("Date") > 0) {
  329. if (angular.isDate(parameters[k])) {
  330. result[k] = moment(parameters[k]).format("YYYYMMDD");
  331. } else if (angular.isString(parameters[k])) {
  332. result[k] = parameters[k];
  333. }
  334. }
  335. }
  336. }
  337. return result;
  338. }
  339. var pathuser = "/homes/home:admin/ITSM报表/事件报表/处理人员统计分析.saiku";
  340. var pathstate = "/homes/home:admin/ITSM报表/事件报表/事件状态占比.saiku";
  341. var pathreason = "/homes/home:admin/ITSM报表/事件报表/事件原因.saiku";
  342. var queryUUID;
  343. function genUUID() {
  344. var uuid = 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
  345. function(c) {
  346. var r = Math.random() * 16 | 0,
  347. v = c == 'x' ? r : (r & 0x3 | 0x8);
  348. return v.toString(16);
  349. }).toUpperCase();
  350. return uuid;
  351. }
  352. queryUUID = genUUID();
  353. var workspace = {};
  354. var pathuserkey = [];
  355. var pathreasonkey = [];
  356. var pathreasonkey = [];
  357. var getreportdata = function(key, path) {
  358. $scope.isMaskuser = true;
  359. $scope.isMaskreason = true;
  360. $scope.isMaskreason = true;
  361. api_report.getMdx(path, queryUUID).then(function(response) {
  362. var mdxquery = Restangular.stripRestangular(response);
  363. workspace.query = mdxquery;
  364. $scope.shows = false;
  365. workspace.query.parameters.paramDateFrom = $scope.starttimes;
  366. workspace.query.parameters.paramDateTo = $scope.endtimes;
  367. $scope.parameters = parseDateParameter(workspace.query.parameters);
  368. weekuser(key, mdxquery);
  369. });
  370. }
  371. var weekuser = function(keys, mdxquery) {
  372. var key = [];
  373. api_report.execute(mdxquery).then(function(data) {
  374. $scope.rheaders = [];
  375. $scope.rRows = [];
  376. var reportData = Restangular.stripRestangular(data);
  377. if (reportData.cellset == null || reportData.cellset.length == 0) {
  378. $scope.shows = true;
  379. $scope.empty = "数据为空!"
  380. } else {
  381. angular.forEach(reportData.cellset, function(item, index) {
  382. if (item.length > 1 && index > 0 && item[1].value != '') {
  383. key.push([item[0].value, Number(item[1].value)]);
  384. }
  385. })
  386. }
  387. if (keys == 'pathuserkey') {
  388. $scope.isMaskuser = false;
  389. containerfun(key);
  390. } else if (keys == 'pathstatekey') {
  391. $scope.isMaskreason = false;
  392. statesfun(key);
  393. } else if (keys == 'pathreasonkey') {
  394. $scope.isMaskreason = false;
  395. reasonfun(key);
  396. }
  397. })
  398. }
  399. $scope.parameters = {};
  400. var weeks = new Date().getDay();
  401. $scope.starttimes = moment(new Date().getTime() - 86400000 * (weeks)).format('YYYYMMDD');
  402. $scope.endtimes = moment(new Date()).format('YYYYMMDD');
  403. $scope.parameters.paramDateFrom = $scope.starttimes;
  404. $scope.parameters.paramDateTo = $scope.endtimes;
  405. $scope.parameters = parseDateParameter($scope.parameters);
  406. getreportdata('pathuserkey', pathuser);
  407. getreportdata('pathstatekey', pathstate);
  408. getreportdata('pathreasonkey', pathreason);
  409. //待处理事件饼形图
  410. var containerfun = function(pathuserkey) {
  411. $(function() {
  412. $('#container').highcharts({
  413. chart: {
  414. type: 'pie',
  415. options3d: {
  416. enabled: true,
  417. alpha: 45,
  418. beta: 0
  419. }
  420. },
  421. title: {
  422. text: '待处理事件人员统计图'
  423. },
  424. tooltip: {
  425. pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
  426. },
  427. plotOptions: {
  428. pie: {
  429. allowPointSelect: true,
  430. cursor: 'pointer',
  431. depth: 35,
  432. dataLabels: {
  433. enabled: true,
  434. format: '{point.name}'
  435. }
  436. }
  437. },
  438. series: [{
  439. type: 'pie',
  440. name: '人员占比',
  441. data: pathuserkey
  442. }]
  443. });
  444. });
  445. }
  446. // Create the chart
  447. var statesfun = function(pathstatekey) {
  448. Highcharts.chart('incidentstates', {
  449. chart: {
  450. type: 'bar'
  451. },
  452. title: {
  453. text: '事件状态统计图'
  454. },
  455. subtitle: {
  456. // text: 'Source: <a href="http://en.wikipedia.org/wiki/List_of_cities_proper_by_population">Wikipedia</a>'
  457. },
  458. xAxis: {
  459. type: 'category',
  460. labels: {
  461. rotation: -45,
  462. style: {
  463. fontSize: '13px',
  464. fontFamily: 'Verdana, sans-serif'
  465. }
  466. }
  467. },
  468. yAxis: {
  469. min: 0,
  470. title: {
  471. text: ''
  472. }
  473. },
  474. legend: {
  475. enabled: false
  476. },
  477. tooltip: {
  478. pointFormat: '<b>{point.y}</b>'
  479. },
  480. series: [{
  481. name: 'Population',
  482. colorByPoint: true,
  483. data: pathstatekey,
  484. borderWidth: 0,
  485. dataLabels: {
  486. enabled: false,
  487. rotation: -90,
  488. color: '#FFFFFF',
  489. align: 'right',
  490. format: '{point.y}', // one decimal
  491. y: 10, // 10 pixels down from the top
  492. style: {
  493. fontSize: '13px',
  494. fontFamily: 'Verdana, sans-serif'
  495. }
  496. }
  497. }]
  498. });
  499. }
  500. var reasonfun = function(pathreasonkey) {
  501. $(function() {
  502. $('#incidentreason').highcharts({
  503. chart: {
  504. type: 'pie',
  505. options3d: {
  506. enabled: true,
  507. alpha: 45,
  508. beta: 0
  509. }
  510. },
  511. title: {
  512. text: '事件原因统计图'
  513. },
  514. tooltip: {
  515. pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
  516. },
  517. plotOptions: {
  518. pie: {
  519. allowPointSelect: true,
  520. cursor: 'pointer',
  521. depth: 35,
  522. dataLabels: {
  523. enabled: true,
  524. format: '{point.name}'
  525. }
  526. }
  527. },
  528. series: [{
  529. type: 'pie',
  530. name: '事件原因占比',
  531. data: pathreasonkey
  532. }],
  533. lang: {
  534. noData: "Nichts zu anzeigen" //真正显示的文本
  535. },
  536. noData: {
  537. // Custom positioning/aligning options
  538. position: { //相对于绘图区定位无数据标签的位置。 默认值:[object Object].
  539. align: 'right',
  540. verticalAlign: 'bottom'
  541. },
  542. // Custom svg attributes
  543. attr: { //无数据标签中额外的SVG属性
  544. 'stroke-width': 1,
  545. stroke: '#cccccc'
  546. },
  547. // Custom css
  548. style: { //对无数据标签的CSS样式。 默认值:[object Object].
  549. //fontWeight: 'bold',
  550. //fontSize: '15px',
  551. //color: '#202030'
  552. }
  553. }
  554. });
  555. });
  556. }
  557. }]);
  558. //月统计图
  559. app.controller('watchmonthCtrl', ["$scope", "$rootScope", "$state", "$timeout", "$interval", "$http", "$cookieStore", "Restangular", "api_report", "api_statistic", function($scope, $rootScope, $state, $timeout, $interval, $http, $cookieStore, Restangular, api_report, api_statistic) {
  560. api_report.getLicenseKey().then(function(response) {
  561. $cookieStore.put('Auth-Token', response.token);
  562. $scope.try_async_load();
  563. });
  564. $scope.try_async_load = function() {
  565. $scope.my_data = [];
  566. api_report.list().then(function(response) {
  567. var dataList = Restangular.stripRestangular(response);
  568. getRepoRoot(dataList, '/homes/home:admin/ITSM报表');
  569. $scope.repoRoot.name = "事件报表"
  570. convertRepoObject($scope.repoRoot);
  571. $scope.my_data.push($scope.repoRoot);
  572. });
  573. };
  574. var workspace = {};
  575. $scope.repoRoot = null;
  576. function getRepoRoot(repo, path) {
  577. angular.forEach(repo, function(value, key) {
  578. if (value.path == path) {
  579. $scope.repoRoot = value;
  580. } else {
  581. if ($scope.repoRoot == null && angular.isDefined(value.repoObjects)) {
  582. getRepoRoot(value.repoObjects, path);
  583. } else {
  584. }
  585. }
  586. });
  587. }
  588. function convertRepoObject(repo) {
  589. if (angular.isArray(repo)) {
  590. angular.forEach(repo, function(value, key) {
  591. convertRepoObject(value);
  592. })
  593. } else {
  594. if (angular.isDefined(repo.name)) {
  595. if (repo.name.indexOf(".") >= 0) {
  596. repo.label = repo.name.substr(0, repo.name.lastIndexOf("."));
  597. } else {
  598. repo.label = repo.name;
  599. }
  600. //delete repo.name;
  601. }
  602. if (angular.isDefined(repo.repoObjects)) {
  603. repo.children = [];
  604. repo.children = repo.repoObjects;
  605. delete repo.repoObjects;
  606. convertRepoObject(repo.children);
  607. }
  608. }
  609. }
  610. function parseDateParameter(parameters) {
  611. var result = undefined;
  612. if (angular.isArray(parameters)) {
  613. // angular.forEach(parmeters,function(param){
  614. // param.
  615. // })
  616. } else {
  617. result = {};
  618. for (var k in parameters) {
  619. if (k.indexOf("Date") > 0) {
  620. if (angular.isString(parameters[k])) {
  621. result[k] = moment(parameters[k], "YYYYMMDD").format("YYYY-MM-DD");
  622. //result[k] = ''+parameters[k]+'';//= moment(parameters[k], "YYYYMMDD").toDate();
  623. }
  624. }
  625. }
  626. }
  627. return result;
  628. }
  629. function ConvertDateParameter(parameters) {
  630. var result = undefined;
  631. if (angular.isArray(parameters)) {
  632. //
  633. } else {
  634. result = {};
  635. for (var k in parameters) {
  636. if (k.indexOf("Date") > 0) {
  637. if (angular.isDate(parameters[k])) {
  638. result[k] = moment(parameters[k]).format("YYYYMMDD");
  639. } else if (angular.isString(parameters[k])) {
  640. result[k] = parameters[k];
  641. }
  642. }
  643. }
  644. }
  645. return result;
  646. }
  647. var lastmonth = "/homes/home:admin/ITSM报表/事件报表/地点统计.saiku";
  648. var thismonth = "/homes/home:admin/ITSM报表/事件报表/地点统计.saiku";
  649. var incidentchart = "/homes/home:admin/ITSM报表/事件报表/日统计报表.saiku";
  650. var queryUUID;
  651. function genUUID() {
  652. var uuid = 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
  653. function(c) {
  654. var r = Math.random() * 16 | 0,
  655. v = c == 'x' ? r : (r & 0x3 | 0x8);
  656. return v.toString(16);
  657. }).toUpperCase();
  658. return uuid;
  659. }
  660. queryUUID = genUUID();
  661. var pathlastmonthkey = [];
  662. var paththismonthkey = [];
  663. var pathincidenttimekey = [];
  664. var lastmonthtime = {
  665. 'starttimes': moment((new Date(moment().startOf('month'))).setMonth((new Date()).getMonth() - 1)).format('YYYYMMDD'),
  666. 'endtimes': moment((new Date(moment().startOf('month'))).setMonth((new Date()).getMonth()) - 86400000).format('YYYYMMDD')
  667. };
  668. var thismonthtime = {
  669. 'starttimes': moment((new Date(moment().startOf('month'))).setMonth((new Date()).getMonth())).format('YYYYMMDD'),
  670. 'endtimes': moment(new Date()).format('YYYYMMDD')
  671. };
  672. var incidenttime = {
  673. 'starttimes': moment(new Date().getTime() - 86400000 * 14).format('YYYYMMDD'),
  674. 'endtimes': moment(new Date()).format('YYYYMMDD')
  675. };
  676. var thisday = moment(new Date().getTime() + 86400000).format('YYYYMMDD');
  677. var thisdaymine = Date.parse(thisday.substr(4, 2) + "/" + thisday.substr(6, 2) + "/" + thisday.substr(0, 4))
  678. var averages = [
  679. [thisdaymine - 86400000 * 14, 0],
  680. [thisdaymine - 86400000 * 13, 0],
  681. [thisdaymine - 86400000 * 12, 0],
  682. [thisdaymine - 86400000 * 11, 0],
  683. [thisdaymine - 86400000 * 10, 0],
  684. [thisdaymine - 86400000 * 9, 0],
  685. [thisdaymine - 86400000 * 8, 0],
  686. [thisdaymine - 86400000 * 7, 0],
  687. [thisdaymine - 86400000 * 6, 0],
  688. [thisdaymine - 86400000 * 5, 0],
  689. [thisdaymine - 86400000 * 4, 0],
  690. [thisdaymine - 86400000 * 3, 0],
  691. [thisdaymine - 86400000 * 2, 0],
  692. [thisdaymine - 86400000 * 1, 0],
  693. [thisdaymine, 0]
  694. ];
  695. var getreportdata = function(key, thistime, path) {
  696. // $scope.isMasklastmon = true;
  697. // $scope.isMaskthismon = true;
  698. // $scope.isMaskincident = true;
  699. api_report.getMdx(path, queryUUID).then(function(response) {
  700. var mdxquery = Restangular.stripRestangular(response);
  701. workspace.query = mdxquery;
  702. workspace.query.parameters.paramDateFrom = thistime.starttimes;
  703. workspace.query.parameters.paramDateTo = thistime.endtimes;
  704. $scope.parameters = parseDateParameter(workspace.query.parameters);
  705. weekuser(key, mdxquery);
  706. });
  707. }
  708. var weekuser = function(keys, mdxquery) {
  709. var key = [];
  710. api_report.execute(mdxquery).then(function(data) {
  711. $scope.rheaders = [];
  712. $scope.rRows = [];
  713. var reportData = Restangular.stripRestangular(data);
  714. if (reportData.cellset == null || reportData.cellset.length == 0) {
  715. $scope.shows = true;
  716. $scope.empty = "数据为空!"
  717. } else {
  718. // angular.forEach(reportData.cellset, function(item, index) {
  719. // if (item.length > 1 && index > 0 && item[1].value != '') {
  720. // key.push([item[0].value, Number(item[1].value)]);
  721. // }
  722. // })
  723. if (keys == 'lastmonthkey') {
  724. angular.forEach(reportData.cellset, function(item, index) {
  725. if (item.length > 1 && index > 0 && item[1].value != '') {
  726. key.push([item[0].value, Number(item[1].value)]);
  727. }
  728. })
  729. lastmonthfun(key);
  730. } else if (keys == 'thismonthkey') {
  731. angular.forEach(reportData.cellset, function(item, index) {
  732. if (item.length > 1 && index > 0 && item[1].value != '') {
  733. key.push([item[0].value, Number(item[1].value)]);
  734. }
  735. })
  736. thismonthfun(key);
  737. } else if (keys == 'incidentchartkey') {
  738. angular.forEach(reportData.cellset, function(item, i) {
  739. angular.forEach(averages, function(index, j) {
  740. // angular.forEach(averages, function(item, index) {
  741. if (item.length > 1 && i > 0 && item[1].value != '') {
  742. if (index[0] == Date.parse(item[0].value.substr(4, 2) + "/" + item[0].value.substr(6, 2) + "/" + item[0].value.substr(0, 4)) + 86400000) {
  743. index[1] = Number(item[1].value);
  744. }
  745. // key.push([Date.parse(item[0].value.substr(4, 2) + "/" + item[0].value.substr(6, 2) + "/" + item[0].value.substr(0, 4)), Number(item[1].value)]);
  746. }
  747. // })
  748. })
  749. })
  750. incidentchartfun(averages);
  751. }
  752. }
  753. })
  754. }
  755. // $scope.parameters = {};
  756. var weeks = new Date().getDay();
  757. // $scope.starttimes = moment(new Date().getTime() - 86400000 * (weeks)).format('YYYYMMDD');
  758. // $scope.endtimes = moment(new Date()).format('YYYYMMDD');
  759. // $scope.parameters.paramDateFrom = $scope.starttimes;
  760. // $scope.parameters.paramDateTo = $scope.endtimes;
  761. // $scope.parameters = parseDateParameter($scope.parameters);
  762. getreportdata('lastmonthkey', lastmonthtime, lastmonth);
  763. getreportdata('thismonthkey', thismonthtime, thismonth);
  764. getreportdata('incidentchartkey', incidenttime, incidentchart);
  765. // 上月区域多发top10
  766. var lastmonthfun = function(lastmonthkey) {
  767. // $scope.isMasklastmon = flase;
  768. Highcharts.chart('lastmonth', {
  769. chart: {
  770. type: 'bar'
  771. },
  772. title: {
  773. text: '上月区域多发top10统计图'
  774. },
  775. subtitle: {
  776. // text: 'Source: <a href="http://en.wikipedia.org/wiki/List_of_cities_proper_by_population">Wikipedia</a>'
  777. },
  778. xAxis: {
  779. type: 'category',
  780. labels: {
  781. rotation: -45,
  782. style: {
  783. fontSize: '13px',
  784. fontFamily: 'Verdana, sans-serif'
  785. }
  786. }
  787. },
  788. yAxis: {
  789. min: 0,
  790. title: {
  791. text: ''
  792. }
  793. },
  794. legend: {
  795. enabled: false
  796. },
  797. tooltip: {
  798. pointFormat: '<b>{point.y}</b>'
  799. },
  800. series: [{
  801. name: 'Population',
  802. colorByPoint: true,
  803. data: lastmonthkey,
  804. borderWidth: 0,
  805. dataLabels: {
  806. enabled: false,
  807. rotation: -90,
  808. color: '#FFFFFF',
  809. align: 'right',
  810. format: '{point.y}', // one decimal
  811. y: 10, // 10 pixels down from the top
  812. style: {
  813. fontSize: '13px',
  814. fontFamily: 'Verdana, sans-serif'
  815. }
  816. }
  817. }]
  818. });
  819. }
  820. // 本月区域多发top10
  821. var thismonthfun = function(lastmonthkey) {
  822. // $scope.isMaskthismon = false;
  823. Highcharts.chart('thismonth', {
  824. chart: {
  825. type: 'bar'
  826. },
  827. title: {
  828. text: '本月区域多发top10统计图'
  829. },
  830. subtitle: {
  831. // text: 'Source: <a href="http://en.wikipedia.org/wiki/List_of_cities_proper_by_population">Wikipedia</a>'
  832. },
  833. xAxis: {
  834. type: 'category',
  835. labels: {
  836. rotation: -45,
  837. style: {
  838. fontSize: '13px',
  839. fontFamily: 'Verdana, sans-serif'
  840. }
  841. }
  842. },
  843. yAxis: {
  844. min: 0,
  845. title: {
  846. text: ''
  847. }
  848. },
  849. legend: {
  850. enabled: false
  851. },
  852. tooltip: {
  853. pointFormat: '<b>{point.y}</b>'
  854. },
  855. series: [{
  856. name: 'Population',
  857. colorByPoint: true,
  858. data: lastmonthkey,
  859. borderWidth: 0,
  860. dataLabels: {
  861. enabled: false,
  862. rotation: -90,
  863. color: '#FFFFFF',
  864. align: 'right',
  865. format: '{point.y}', // one decimal
  866. y: 10, // 10 pixels down from the top
  867. style: {
  868. fontSize: '13px',
  869. fontFamily: 'Verdana, sans-serif'
  870. }
  871. }
  872. }]
  873. });
  874. }
  875. // 最近15天事件
  876. var incidentchartfun = function(incidentchartkey) {
  877. // $scope.isMaskincident = false;
  878. Highcharts.chart('incidentchart', {
  879. title: {
  880. text: '事件近15天趋势图'
  881. },
  882. xAxis: {
  883. type: 'datetime',
  884. labels: {
  885. align: 'left',
  886. step: 1
  887. }
  888. },
  889. yAxis: {
  890. title: {
  891. text: null
  892. }
  893. },
  894. tooltip: {
  895. crosshairs: true,
  896. shared: true,
  897. valueSuffix: '条'
  898. },
  899. legend: {},
  900. series: [{
  901. name: '生成事件',
  902. data: incidentchartkey,
  903. zIndex: 1,
  904. marker: {
  905. fillColor: 'white',
  906. lineWidth: 2,
  907. lineColor: Highcharts.getOptions().colors[0]
  908. }
  909. }]
  910. });
  911. }
  912. }]);