realTimeCtrl.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. 'use strict';
  2. app.controller('realTimeCtrl', ["$scope", "$rootScope", "$state", "$timeout", "$interval", "$http", "$cookieStore", "SweetAlert", "Restangular", "api_report", "api_statistic", "moment", "api_event_form", "api_user_data", "api_bpm", "api_category", "$modal", "i18nService","api_newreport", function ($scope, $rootScope, $state, $timeout, $interval, $http, $cookieStore, SweetAlert, Restangular, api_report, api_statistic, moment, api_event_form, api_user_data, api_bpm, api_category, $modal, i18nService,api_newreport) {
  3. //默认无选中,选择日期
  4. $scope.searchstate = 'none';
  5. // 默认故障分布
  6. $scope.categoryActive = '一级故障分类';
  7. // 默认超时单
  8. $scope.timeoutType = '接单超时';
  9. // 默认超时单-小时数
  10. $scope.timeoutNum = 2;
  11. //日期显示格式
  12. $scope.datepickerPopuptime = 'yyyy-MM-dd';
  13. //按日
  14. $scope.dateItemClick = function () {
  15. $scope.dateItem = 'day';
  16. $scope.datepickerPopuptime = 'yyyy-MM-dd';//日期格式化
  17. $scope.day(0);//今日
  18. };
  19. // 切换院区
  20. $scope.own = {};
  21. $scope.changeBranch = function(){
  22. console.log($scope.own.branch);
  23. $scope.dutys = [];
  24. $scope.own.duty = null;
  25. $scope.own.branch && $scope.getOwnDuty($scope.own.branch.id);
  26. }
  27. // 获取院区
  28. $scope.branchs = [];
  29. $scope.getOwnBranch = function(){
  30. api_category
  31. .getOwnBranch({})
  32. .then(function (response) {
  33. if (response) {
  34. if ((response.status = 200)) {
  35. $scope.branchs = response.data;
  36. if($rootScope.user.duty){
  37. $scope.own.branch = {id: $rootScope.user.duty.branch, hosName: $rootScope.user.duty.branchName};
  38. $scope.getOwnDuty($rootScope.user.duty.branch, true);
  39. }else if($rootScope.user.branch){
  40. $scope.own.branch = $rootScope.user.branch;
  41. $scope.getOwnDuty($rootScope.user.branch.id, true);
  42. $scope.init();
  43. }
  44. }
  45. }
  46. });
  47. }
  48. $scope.getOwnBranch();
  49. // 获取责任科室
  50. $scope.dutys = [];
  51. $scope.getOwnDuty = function(branchId, isFirst = false, isReload = false){
  52. api_category
  53. .getOwnDuty({branchId: branchId})
  54. .then(function (response) {
  55. if (response) {
  56. if ((response.status = 200)) {
  57. $scope.dutys = response.data;
  58. if(isFirst && $rootScope.user.duty){
  59. $scope.own.duty = $rootScope.user.duty;
  60. $scope.init();
  61. }
  62. if(isReload){
  63. if($rootScope.user.duty){
  64. $scope.own.duty = $rootScope.user.duty;
  65. }
  66. $scope.mdxquery();
  67. }
  68. }
  69. }
  70. });
  71. }
  72. //切换开始/结束日期
  73. $scope.timesChange = function (str) {
  74. //切换结束日期的时候为年底或月底,方便传参
  75. switch (str) {
  76. case 'month':
  77. $scope.endtimesModel = moment($scope.endtimesModel).endOf('month').toDate();
  78. break;
  79. case 'year':
  80. $scope.endtimesModel = moment($scope.endtimesModel).endOf('year').toDate();
  81. break;
  82. }
  83. $scope.datepickerUpdate(str);
  84. };
  85. //配置项更新
  86. $scope.datepickerUpdate = function (str) {
  87. //开始的datepickerOptions
  88. $scope.datepickerOptionsStart = {
  89. maxDate: moment($scope.endtimesModel).format('YYYY/MM/DD'),
  90. minMode: str,
  91. datepickerMode: str
  92. };
  93. //结束的datepickerOptions
  94. $scope.datepickerOptionsEnd = {
  95. minDate: moment($scope.starttimesModel).format('YYYY/MM/DD'),
  96. maxDate: moment().format('YYYY/MM/DD'),
  97. minMode: str,
  98. datepickerMode: str
  99. };
  100. };
  101. //日期选择
  102. //本周,上周
  103. $scope.week = function (num) {
  104. if(num === 0){
  105. // 本周
  106. $scope.searchstate = "week" + num;
  107. $scope.starttimesModel = moment().startOf('week').add(1, 'days').toDate();
  108. $scope.endtimesModel = moment().endOf('week').add(1, 'days').toDate();
  109. }else{
  110. num = num > 1 ? num : 1;
  111. $scope.searchstate = "week" + num;
  112. $scope.starttimesModel = moment().week( moment().week() - num).startOf('week').add(1, 'days').toDate();
  113. $scope.endtimesModel = moment().week( moment().week() - num).endOf('week').add(1, 'days').toDate();
  114. }
  115. $scope.datepickerUpdate('day');
  116. }
  117. //本月,上月
  118. $scope.month = function (num) {
  119. if(num === 0){
  120. // 本月
  121. $scope.searchstate = "month" + num;
  122. $scope.starttimesModel = moment().startOf('month').toDate();
  123. $scope.endtimesModel = moment().endOf('month').toDate();
  124. }else{
  125. num = num > 1 ? num : 1;
  126. $scope.searchstate = "month" + num;
  127. $scope.starttimesModel = moment().month( moment().month() - num).startOf('month').toDate();
  128. $scope.endtimesModel = moment().month( moment().month() - num).endOf('month').toDate();
  129. }
  130. $scope.datepickerUpdate('month');
  131. }
  132. //本日,上一日
  133. $scope.day = function (num) {
  134. if(num === 0){
  135. // 本日
  136. $scope.searchstate = "day" + num;
  137. $scope.starttimesModel = moment().startOf('day').toDate();
  138. $scope.endtimesModel = moment().endOf('day').toDate();
  139. }else{
  140. num = num > 1 ? num : 1;
  141. $scope.searchstate = "day" + num;
  142. $scope.starttimesModel = moment().day( moment().day() - num).startOf('day').toDate();
  143. $scope.endtimesModel = moment().day( moment().day() - num).endOf('day').toDate();
  144. }
  145. $scope.datepickerUpdate('day');
  146. }
  147. //选择上一周,上个月,去年等等快捷方式
  148. $scope.chooseDate = function (date) {
  149. switch (date) {
  150. case 'day0'://本日
  151. $scope.day(0);
  152. break;
  153. case 'day1'://上一日
  154. $scope.day(1);
  155. break;
  156. case 'week0'://本周
  157. $scope.week(0);
  158. break;
  159. case 'week1'://上周
  160. $scope.week(1);
  161. break;
  162. case 'month0'://本月
  163. $scope.month(0);
  164. break;
  165. case 'month1'://上月
  166. $scope.month(1);
  167. break;
  168. }
  169. };
  170. /**
  171. *日历
  172. */
  173. //打开开始日期选择框
  174. $scope.startOpen = function ($event) {
  175. console.log(1)
  176. $event.preventDefault();
  177. $event.stopPropagation();
  178. $scope.endOpened = false;
  179. $scope.startOpened = !$scope.startOpened;
  180. };
  181. //打开结束日期选择框
  182. $scope.endOpen = function ($event) {
  183. $event.preventDefault();
  184. $event.stopPropagation();
  185. $scope.startOpened = false;
  186. $scope.endOpened = !$scope.endOpened;
  187. };
  188. //重置
  189. $scope.reload = function () {
  190. $scope.dateItemClick('day');
  191. if($rootScope.user.duty){
  192. $scope.own.branch = {id: $rootScope.user.duty.branch, hosName: $rootScope.user.duty.branchName};
  193. $scope.getOwnDuty($rootScope.user.duty.branch, false, true);
  194. }else if($rootScope.user.branch){
  195. $scope.own.branch = $rootScope.user.branch;
  196. $scope.getOwnDuty($rootScope.user.branch.id, false, true);
  197. }
  198. };
  199. //loading
  200. $scope.isArrays = function (arr) {
  201. return Array.isArray(arr);
  202. };
  203. //图表 逾期统计环形图
  204. function barechart6(datas) {
  205. datas = {
  206. "pieChart": [
  207. {
  208. "name": "逾期接单数",
  209. "value": datas.resolvedOnTime || 0
  210. },
  211. {
  212. "name": "逾期处理数",
  213. "value": datas.resolvedOverTime || 0
  214. },
  215. ],
  216. }
  217. var dom = document.getElementById("XYSJ");
  218. var option = null;
  219. var myChart = echarts.init(dom);
  220. var data = datas.pieChart;
  221. option = {
  222. color: ["#1978F2", "#33CC85"],
  223. title: {
  224. textAlign: "center",
  225. textStyle: {
  226. color: "#333",
  227. fontSize: 16,
  228. // align: 'center',
  229. },
  230. subtextStyle: {
  231. fontSize: 14,
  232. color: ["#005395"],
  233. fontWeight: "bolder",
  234. },
  235. x: "34.5%",
  236. y: "50%",
  237. },
  238. tooltip: {
  239. trigger: "item",
  240. formatter: function (a) {
  241. return a["data"]["name"] + ":" + a["data"]["value"];
  242. },
  243. position: ["50%", "30%"],
  244. },
  245. grid: {
  246. bottom: 150,
  247. left: 100,
  248. right: "10%",
  249. },
  250. legend: {
  251. orient: "vertical",
  252. top: "middle",
  253. right: "5%",
  254. textStyle: {
  255. color: "#333",
  256. fontSize: 12,
  257. },
  258. itemWidth: 8,
  259. itemHeight: 8,
  260. icon: "roundRect",
  261. data: data,
  262. },
  263. series: [
  264. // 主要展示层的
  265. {
  266. radius: ["50%", "65%"],
  267. center: ["35%", "60%"],
  268. type: "pie",
  269. label: {
  270. normal: {
  271. show: true,
  272. formatter: "{c}",
  273. textStyle: {
  274. fontSize: 14,
  275. },
  276. position: "outside",
  277. },
  278. emphasis: {
  279. show: true,
  280. },
  281. },
  282. labelLine: {
  283. normal: {
  284. show: true,
  285. length: 5,
  286. length2: 25,
  287. },
  288. emphasis: {
  289. show: true,
  290. },
  291. },
  292. name: "",
  293. data: data,
  294. },
  295. ],
  296. };
  297. if (option && typeof option === "object") {
  298. myChart.setOption(option, true);
  299. myChart.hideLoading();
  300. }
  301. }
  302. //图表 故障现象趋势图
  303. function barechart11(datas) {
  304. datas = {
  305. "data": [
  306. datas.map(v => v.count),
  307. ],
  308. "dates": datas.map(v => v.hour + '时'),
  309. "title": [
  310. "建单数",
  311. ],
  312. }
  313. console.log(datas);
  314. if (datas) {
  315. var dom = document.getElementById("deck_24build");
  316. var myChart = echarts.init(dom);
  317. var option = null;
  318. var serie = [];
  319. for (var i = 0; i < datas.data.length; i++) {
  320. var Series = {
  321. name: datas.title[i],
  322. type: "line",
  323. itemStyle: {
  324. normal: {
  325. // color: '#49A9EE'
  326. },
  327. },
  328. lineStyle: {
  329. normal: {
  330. // color: '#49A9EE'
  331. },
  332. },
  333. data: datas.data[i],
  334. };
  335. serie.push(Series);
  336. }
  337. console.log(serie);
  338. myChart.showLoading({
  339. text: "数据加载中...",
  340. color: "#c23531",
  341. textColor: "#fff",
  342. maskColor: "rgba(255,255,255,0)",
  343. zlevel: 0,
  344. });
  345. myChart.hideLoading();
  346. option = {
  347. tooltip: {
  348. trigger: "axis",
  349. axisPointer: {
  350. // 坐标轴指示器,坐标轴触发有效
  351. // type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  352. lineStyle: {
  353. color: "#49A9EE",
  354. type: "dotted",
  355. },
  356. },
  357. },
  358. // legend: {
  359. // data: datas.title,
  360. // align: "left",
  361. // // itemWidth:10,
  362. // // itemHeight:10,
  363. // bottom: 0,
  364. // },
  365. grid: {
  366. left: "2%",
  367. right: "2%",
  368. bottom: "5%",
  369. top: "20%",
  370. containLabel: true,
  371. },
  372. xAxis: [
  373. {
  374. type: "category",
  375. // axisTick: {
  376. // alignWithLabel: true
  377. // },
  378. axisLabel: {
  379. textStyle: {
  380. color: "#7B7B7B",
  381. // fontSize: '14',
  382. },
  383. },
  384. axisLine: {
  385. show: true,
  386. lineStyle: {
  387. color: "#7B7B7B",
  388. // type: 'dotted'
  389. },
  390. },
  391. // data: ['10-12', '10-12', '10-12', '10-12', '10-12', '10-12', '10-12', '10-12', '10-12']
  392. data: datas.dates,
  393. },
  394. ],
  395. yAxis: [
  396. {
  397. type: "value",
  398. scale: true,
  399. name: "建单数",
  400. min: 0,
  401. minInterval: 1,
  402. boundaryGap: [0.2, 0.2],
  403. // axisLabel: {
  404. // formatter: '{value}'
  405. // }
  406. axisLabel: {
  407. textStyle: {
  408. color: "#7B7B7B",
  409. // fontSize: '14',
  410. },
  411. },
  412. axisLine: {
  413. show: true,
  414. lineStyle: {
  415. color: "#7B7B7B",
  416. // type: 'dotted'
  417. },
  418. },
  419. },
  420. ],
  421. series: serie,
  422. // [{
  423. // name: '分类1',
  424. // type: 'line',
  425. // itemStyle: {
  426. // normal: {
  427. // color: '#49A9EE'
  428. // }
  429. // },
  430. // lineStyle: {
  431. // normal: {
  432. // color: '#49A9EE'
  433. // }
  434. // },
  435. // data: [10, 20, 5, 43, 12, 34, 12, 56, 67]
  436. // }, {
  437. // name: '分类2',
  438. // type: 'line',
  439. // itemStyle: {
  440. // normal: {
  441. // color: '#87C966'
  442. // }
  443. // },
  444. // lineStyle: {
  445. // normal: {
  446. // color: '#87C966'
  447. // }
  448. // },
  449. // data: [12, 10, 15, 23, 19, 24, 18, 26, 57]
  450. // }]
  451. };
  452. if (option && typeof option === "object") {
  453. myChart.setOption(option, true);
  454. myChart.hideLoading();
  455. }
  456. }
  457. // console.log(echarts)
  458. }
  459. // 查询人员统计
  460. $scope.incidentCount = null;
  461. $scope.userCount = null;
  462. $scope.overtimeCount = null;
  463. $scope.getPersonnelStatistics = function(type){
  464. if(type === 'overtimeCount'){
  465. $scope[type] = null;
  466. }else{
  467. $scope.incidentCount = null;
  468. $scope.userCount = null;
  469. $scope.overtimeCount = null;
  470. }
  471. api_newreport.fetchDataListIndex('indexCount2', {
  472. "dutyId": $scope.own.duty ? $scope.own.duty.id : undefined,
  473. "branchId": $scope.own.duty ? undefined: ($scope.own.branch ? $scope.own.branch.id : undefined),
  474. "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD HH:mm:ss'),
  475. "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD HH:mm:ss'),
  476. "receveOver": $scope.timeoutType == '接单超时' ? 1 : undefined,
  477. "receveOverHour": $scope.timeoutNum,
  478. }).then(function (res) {
  479. if (res.status == 200) {
  480. $scope.incidentCount = res.incidentCount ? res.incidentCount[0] : {};
  481. $scope.userCount = res.userCount || [];
  482. $scope.overtimeCount = res.overtimeCount ? res.overtimeCount.map(v => ({...v,logTime: v.logTime ? moment(v.logTime).format('MM月DD日前完成') : ''})) : [];
  483. barechart6(res.overdueCount[0]);
  484. barechart11(res.incidentHourCount);
  485. }
  486. })
  487. }
  488. // 查询故障分布
  489. $scope.typedataList = null;
  490. $scope.getTypedataList = function(){
  491. $scope.typedataList = null;
  492. $scope.typedataList = null;
  493. let hierarchy;
  494. if($scope.categoryActive === '一级故障分类'){
  495. hierarchy = 1;
  496. }else if($scope.categoryActive === '二级故障分类'){
  497. hierarchy = 2;
  498. }else if($scope.categoryActive === '三级故障分类'){
  499. hierarchy = 3;
  500. }
  501. api_event_form.fetchSjlxList({
  502. "dutyId": $scope.own.duty ? $scope.own.duty.id : undefined,
  503. "branchId": $scope.own.duty ? undefined: ($scope.own.branch ? $scope.own.branch.id : undefined),
  504. "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'),
  505. "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'),
  506. "hierarchy": hierarchy,
  507. "sortData": "sum",
  508. "sortType": "desc",
  509. "resolve":'resolve',
  510. }).then(function (res) {
  511. if (res.stats == 200) {
  512. $scope.typedataList = res.typedataList || [];
  513. }
  514. })
  515. }
  516. // 超时单
  517. $scope.timeoutTypeHandler = function(type){
  518. typeof type === 'string' && ($scope.timeoutType = type);
  519. typeof type === 'number' && ($scope.timeoutNum = type);
  520. $scope.getPersonnelStatistics('overtimeCount');
  521. }
  522. // 超时单
  523. $scope.categoryActiveHandler = function(type){
  524. $scope.categoryActive = type;
  525. $scope.getTypedataList();
  526. }
  527. // 搜索
  528. $scope.mdxquery = function(type){
  529. $scope.getPersonnelStatistics(type);
  530. $scope.getTypedataList();
  531. }
  532. //初始化
  533. $scope.init = function(){
  534. $scope.dateItemClick('day');
  535. $scope.mdxquery();
  536. }
  537. }])