analysis.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. 'use strict';
  2. app.controller('reportanalysisCtrl', ["$scope", "$rootScope", "$state", "$timeout", "$interval", "$http", "$cookieStore", "moment", "SweetAlert", "Restangular", "api_hkreport", "api_user_data", "api_category", function($scope, $rootScope, $state, $timeout, $interval, $http, $cookieStore, moment, SweetAlert, Restangular, api_hkreport, api_user_data,api_category) {
  3. var ROWS = "ROWS";
  4. var COLUMNS = "COLUMNS";
  5. $scope.treeshow = true;
  6. $scope.searchstate = "";
  7. $scope.headers = "请选择事件树形列表!";
  8. var workspace = {};
  9. $scope.parameters = {};
  10. $scope.starttimes = {};
  11. $scope.endtimes = {};
  12. $scope.category = {};
  13. $scope.reportName = "报表";
  14. $scope.allheight = 100;
  15. $scope.isMaskground = false;
  16. $scope.yeardata = "year";
  17. $scope.quikly = [{ name: '自定义', value: 0 }, { name: '近3年', value: 1 }, { name: '近5年', value: 2 }, { name: '近10年', value: 3 }, { name: '近20年', value: 4 }];
  18. function startdata() {
  19. $scope.searchkeys = { 'area': {}, 'quikly': { name: '近5年', value: 2 } };
  20. $scope.starttimes = moment((new Date()).setFullYear((new Date()).getFullYear() - 4)).format("YYYY-MM-DD");
  21. $scope.endtimes = moment(new Date().getTime() - 86400000).format('YYYYMMDD');
  22. $scope.parameters.paramDateFrom = moment($scope.starttimes, "YYYYMMDD").format("YYYY-MM-DD");
  23. $scope.parameters.paramDateTo = moment($scope.endtimes, "YYYYMMDD").format("YYYY-MM-DD");
  24. }
  25. startdata();
  26. $scope.changeForm = function(paramDateFrom) {
  27. $scope.searchkeys.quikly = { name: '自定义', value: 0 };
  28. $scope.starttimes = moment(paramDateFrom).format('YYYY-MM--DD');
  29. }
  30. $scope.changeTo = function(paramDateTo) {
  31. $scope.searchkeys.quikly = { name: '自定义', value: 0 };
  32. $scope.endtimes = moment(paramDateTo).format('YYYY-MM-DD');
  33. }
  34. $scope.open = function($event) {
  35. $event.preventDefault();
  36. $event.stopPropagation();
  37. $scope.opened = !$scope.opened;
  38. };
  39. $scope.endOpen = function($event) {
  40. $event.preventDefault();
  41. $event.stopPropagation();
  42. $scope.startOpened = false;
  43. $scope.endOpened = !$scope.endOpened;
  44. };
  45. $scope.startOpen = function($event) {
  46. $event.preventDefault();
  47. $event.stopPropagation();
  48. $scope.endOpened = false;
  49. $scope.startOpened = !$scope.startOpened;
  50. };
  51. function ConvertDateParameter(parameters) {
  52. var result = undefined;
  53. if (angular.isArray(parameters)) {
  54. //
  55. } else {
  56. result = {};
  57. for (var k in parameters) {
  58. if (k.indexOf("Date") > 0) {
  59. if (angular.isDate(parameters[k])) {
  60. result[k] = moment(parameters[k]).format("YYYY-MM-DD");
  61. } else if (angular.isString(parameters[k])) {
  62. result[k] = parameters[k];
  63. }
  64. }
  65. }
  66. }
  67. return result;
  68. }
  69. // 重置
  70. $scope.restData = function() {
  71. startdata();
  72. if($rootScope.user.duty){
  73. $scope.searchkeys.branch = {id: $rootScope.user.duty.branch, hosName: $rootScope.user.duty.branchName};
  74. $scope.getOwnDuty($rootScope.user.duty.branch, true);
  75. $scope.getAreas($scope.searchkeys.branch.id);
  76. }else if($rootScope.user.branch){
  77. $scope.searchkeys.branch = $rootScope.user.branch;
  78. $scope.getOwnDuty($rootScope.user.branch.id, true);
  79. $scope.getAreas($scope.searchkeys.branch.id);
  80. $scope.mdxquery($scope.searchkeys);
  81. }
  82. }
  83. $scope.mdxquery = function(key) {
  84. var changedate = ConvertDateParameter($scope.parameters)
  85. var fildata = { "start": moment(changedate.paramDateFrom).format("YYYY"), "end": moment(changedate.paramDateTo).format("YYYY"), "areaId": key.area ? key.area.id : undefined }
  86. getdata(fildata)
  87. }
  88. $scope.onChangetime = function(key) {
  89. if (key.value == 1) {
  90. $scope.starttimes = moment((new Date(moment().startOf('year'))).setFullYear((new Date()).getFullYear() - 2)).format('YYYY-MM-DD');
  91. $scope.endtimes = moment().format('YYYY-MM-DD');;
  92. $scope.parameters.paramDateFrom = $scope.starttimes;
  93. $scope.parameters.paramDateTo = $scope.endtimes;
  94. } else if (key.value == 2) {
  95. $scope.starttimes = moment((new Date(moment().startOf('year'))).setFullYear((new Date()).getFullYear() - 4)).format('YYYY-MM-DD');
  96. $scope.endtimes = moment().format('YYYY-MM-DD');;
  97. $scope.parameters.paramDateFrom = $scope.starttimes;
  98. $scope.parameters.paramDateTo = $scope.endtimes;
  99. } else if (key.value == 3) {
  100. $scope.starttimes = moment((new Date(moment().startOf('year'))).setFullYear((new Date()).getFullYear() - 9)).format('YYYY-MM-DD');
  101. $scope.endtimes = moment().format('YYYY-MM-DD');;
  102. $scope.parameters.paramDateFrom = $scope.starttimes;
  103. $scope.parameters.paramDateTo = $scope.endtimes;
  104. } else if (key.value == 4) {
  105. $scope.starttimes = moment((new Date(moment().startOf('year'))).setFullYear((new Date()).getFullYear() - 19)).format('YYYY-MM-DD');
  106. $scope.endtimes = moment().format('YYYY-MM-DD');;
  107. $scope.parameters.paramDateFrom = $scope.starttimes;
  108. $scope.parameters.paramDateTo = $scope.endtimes;
  109. }
  110. }
  111. $scope.execute = function() {
  112. api_report.list($scope.token).then(function(response) {
  113. $scope.select_treedata = $scope.my_data = response;
  114. });
  115. }
  116. $scope.searchOptions = function() {
  117. if (angular.isDefined(workspace.query)) {
  118. var queryParameters = workspace.query.parameters;
  119. for (var parm in queryParameters) {
  120. if (parm == 'Week') {
  121. } else {
  122. }
  123. }
  124. }
  125. }
  126. // 切换院区
  127. $scope.changeBranch = function(){
  128. console.log($scope.searchkeys.branch);
  129. $scope.dutys = [];
  130. $scope.searchkeys.duty = null;
  131. $scope.searchkeys.branch && $scope.getOwnDuty($scope.searchkeys.branch.id);
  132. $scope.outarea = [];
  133. $scope.searchkeys.area = null;
  134. $scope.searchkeys.branch && $scope.getAreas($scope.searchkeys.branch.id);
  135. }
  136. // 切换责任科室
  137. $scope.changeDuty = function(){
  138. console.log($scope.searchkeys.duty);
  139. }
  140. // 获取院区
  141. $scope.branchs = [];
  142. $scope.getOwnBranch = function(){
  143. api_category
  144. .getOwnBranch({})
  145. .then(function (response) {
  146. if (response) {
  147. if ((response.status = 200)) {
  148. $scope.branchs = response.data;
  149. if($rootScope.user.duty){
  150. $scope.searchkeys.branch = {id: $rootScope.user.duty.branch, hosName: $rootScope.user.duty.branchName};
  151. $scope.getOwnDuty($rootScope.user.duty.branch, true);
  152. $scope.getAreas($scope.searchkeys.branch.id);
  153. }else if($rootScope.user.branch){
  154. $scope.searchkeys.branch = $rootScope.user.branch;
  155. $scope.getOwnDuty($rootScope.user.branch.id, true);
  156. $scope.getAreas($scope.searchkeys.branch.id);
  157. $scope.mdxquery($scope.searchkeys);
  158. }
  159. }
  160. }
  161. });
  162. }
  163. $scope.getOwnBranch();
  164. // 获取责任科室
  165. $scope.dutys = [];
  166. $scope.getOwnDuty = function(branchId, isFirst = false){
  167. api_category
  168. .getOwnDuty({branchId: branchId})
  169. .then(function (response) {
  170. if (response) {
  171. if ((response.status = 200)) {
  172. $scope.dutys = response.data;
  173. if(isFirst && $rootScope.user.duty){
  174. $scope.searchkeys.duty = $rootScope.user.duty;
  175. $scope.mdxquery($scope.searchkeys);
  176. }
  177. }
  178. }
  179. });
  180. }
  181. //获取区域
  182. $scope.outarea = [];
  183. $scope.getAreas = function(branchId){
  184. api_user_data.fetchDataList('area', { "idx": 0, "sum": 1000, area: {branch: branchId} }).then(function(response) {
  185. if (response) {
  186. if (response.status = 200) {
  187. $scope.outarea = response.list;
  188. }
  189. }
  190. })
  191. }
  192. // $scope.getAreas();
  193. //数据
  194. var titledata = [];
  195. var datas = [
  196. []
  197. ];
  198. var serieslist = [];
  199. var colorlist = ['#005395', '#49a9ee', '#ffcd62', '#87c966', '#1ea58f'];
  200. var datetime = [];
  201. $scope.headerslist = [];
  202. $scope.listsum = [];
  203. $scope.rRows = [];
  204. //事件数量统计分析
  205. var domanalysis = document.getElementById("analysis");
  206. var myChartanalysis = echarts.init(domanalysis);
  207. var app = {};
  208. var optionanalysis = null;
  209. app.title = '事件数量统计分析';
  210. var XData = [];
  211. var yData = [];
  212. myChartanalysis.showLoading({  
  213. text: '数据加载中...',
  214. color: '#c23531',
  215. textColor: '#fff',
  216. maskColor: 'rgba(255,255,255,0)',
  217. zlevel: 0
  218. });
  219. myChartanalysis.hideLoading();
  220. app.title = '堆叠条形图';
  221. optionanalysis = {
  222. tooltip: {
  223. trigger: 'axis',
  224. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  225. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  226. },
  227. formatter: function(datas) {
  228. var allsum = 0;
  229. angular.forEach(datas, function(item) {
  230. allsum += item.data;
  231. })
  232. var res = '';
  233. for (var i = 0; i < datas.length; i++) {
  234. res += "<div>" + datas[i].marker + " " + datas[i].seriesName + ' 总数:' +
  235. datas[i].data + ' 占比:' + (allsum > 0 ? datas[i].data * 100 / allsum : 0).toFixed(2) + '%' + '</div>'
  236. }
  237. return "<div style='display:grid;grid-template-rows: auto auto auto;grid-template-columns: auto auto auto;'>" + res + "</div>"
  238. },
  239. confine: true
  240. },
  241. legend: {
  242. icon: "circle",
  243. bottom: '0%',
  244. data: titledata
  245. },
  246. grid: {
  247. left: '5%',
  248. right: '4%',
  249. bottom: '20%',
  250. top: '5%',
  251. containLabel: false
  252. },
  253. xAxis: {
  254. // axisTick: {
  255. // show: false
  256. // },
  257. splitLine: {
  258. show: false,
  259. },
  260. axisLine: {
  261. lineStyle: {
  262. color: '#ddd'
  263. }
  264. },
  265. splitArea: {
  266. show: false
  267. },
  268. axisLabel: {
  269. textStyle: {
  270. color: '#787878',
  271. fontSize: 12,
  272. }
  273. },
  274. type: 'value'
  275. },
  276. yAxis: {
  277. axisTick: {
  278. show: false
  279. },
  280. axisLabel: {
  281. show: true,
  282. textStyle: {
  283. color: '#6d6d6d',
  284. fontSize: 12,
  285. }
  286. },
  287. axisLine: {
  288. show: true,
  289. lineStyle: {
  290. color: '#ddd'
  291. }
  292. },
  293. splitArea: {
  294. show: false
  295. },
  296. type: 'category',
  297. data: datetime
  298. },
  299. series: serieslist
  300. }
  301. function getdata(time) {
  302. time.dutyId = $scope.searchkeys.duty ? $scope.searchkeys.duty.id : undefined;
  303. time.branchId = $scope.searchkeys.branch ? $scope.searchkeys.branch.id : undefined;
  304. api_hkreport.incidentreport(time, 'incident_trend_hk').then(function(data) {
  305. handledata(data);
  306. })
  307. }
  308. // getdata({ "start": moment($scope.parameters.paramDateFrom, "YYYY-MM-DD").format("YYYY"), "end": moment($scope.parameters.paramDateTo, "YYYY-MM-DD").format("YYYY") })
  309. function handledata(data) {
  310. serieslist = [];
  311. datetime = [];
  312. $scope.listsum = [];
  313. titledata = [];
  314. $scope.headerslist = data.quantityStatisticsTitle;
  315. $scope.rRows = data.quantityStatisticsList;
  316. angular.forEach($scope.rRows, function(item, index) {
  317. $scope.listsum[index] = { 'allzzl': '', 'sum': '', 'date': '', 'all': [] };
  318. var i = (Object.values($scope.rRows[0]).length - 3) / 2;
  319. if(i){
  320. for (var j = 0; j < i; j++) {
  321. $scope.listsum[index].all[j] = { 'category': $scope.rRows[index]['category' + j], 'zzl': $scope.rRows[index]['zzl' + j] };
  322. $scope.listsum[index].allzzl = $scope.rRows[index].allzzl == '-' ? $scope.rRows[index].allzzl : Number($scope.rRows[index].allzzl);
  323. $scope.listsum[index].sum = $scope.rRows[index].sum;
  324. $scope.listsum[index].date = $scope.rRows[index].date;
  325. $scope.rRows[index].allzzl = $scope.rRows[index].allzzl == '-' ? $scope.rRows[index].allzzl : Number($scope.rRows[index].allzzl);
  326. $scope.rRows[index]['zzl' + j] = { 'category': $scope.rRows[index]['category' + j], 'zzl': $scope.rRows[index]['zzl' + j] == '-' ? $scope.rRows[index]['zzl' + j] : Number($scope.rRows[index]['zzl' + j]) };
  327. }
  328. }else{
  329. for (var j = 0; j < Object.values($scope.rRows[0]).length; j++) {
  330. $scope.listsum[index].allzzl = $scope.rRows[index].allzzl == '-' ? $scope.rRows[index].allzzl : Number($scope.rRows[index].allzzl);
  331. $scope.listsum[index].sum = $scope.rRows[index].sum;
  332. $scope.listsum[index].date = $scope.rRows[index].date;
  333. }
  334. }
  335. })
  336. angular.forEach(data.quantityStatistics, function(item, index) {
  337. titledata.push(item.category);
  338. datas[index] = [];
  339. angular.forEach(item.data, function(itemtwo, indextwo) {
  340. datas[index][indextwo] = itemtwo.sum;
  341. })
  342. serieslist[index] = {
  343. name: item.category,
  344. type: 'bar',
  345. stack: '总量',
  346. "itemStyle": {
  347. "normal": {
  348. "barBorderRadius": 0,
  349. "color": colorlist[index],
  350. "label": {
  351. "show": false,
  352. "textStyle": {
  353. "color": "#87c966"
  354. },
  355. "position": "insideRight",
  356. formatter: function(p) {
  357. return p.value > 0 ? (p.value) : '';
  358. }
  359. }
  360. }
  361. },
  362. barWidth: 18,
  363. data: datas[index]
  364. }
  365. })
  366. angular.forEach(data.quantityStatisticsList, function(item, index) {
  367. datetime[index] = item.date;
  368. })
  369. optionanalysis.series = serieslist;
  370. optionanalysis.yAxis.data = datetime;
  371. optionanalysis.legend.data = titledata;
  372. myChartanalysis.setOption(optionanalysis, true);
  373. myChartanalysis.hideLoading();
  374. }
  375. }]);