realTimeCtrl.js 18 KB

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