123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- 'use strict';
- 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) {
- var ROWS = "ROWS";
- var COLUMNS = "COLUMNS";
- $scope.treeshow = true;
- $scope.searchstate = "";
- $scope.headers = "请选择事件树形列表!";
- var workspace = {};
- $scope.parameters = {};
- $scope.starttimes = {};
- $scope.endtimes = {};
- $scope.category = {};
- $scope.reportName = "报表";
- $scope.allheight = 100;
- $scope.isMaskground = false;
- $scope.yeardata = "year";
- $scope.quikly = [{ name: '自定义', value: 0 }, { name: '近3年', value: 1 }, { name: '近5年', value: 2 }, { name: '近10年', value: 3 }, { name: '近20年', value: 4 }];
- function startdata() {
- $scope.searchkeys = { 'area': {}, 'quikly': { name: '近5年', value: 2 } };
- $scope.starttimes = moment((new Date()).setFullYear((new Date()).getFullYear() - 4)).format("YYYY-MM-DD");
- $scope.endtimes = moment(new Date().getTime() - 86400000).format('YYYYMMDD');
- $scope.parameters.paramDateFrom = moment($scope.starttimes, "YYYYMMDD").format("YYYY-MM-DD");
- $scope.parameters.paramDateTo = moment($scope.endtimes, "YYYYMMDD").format("YYYY-MM-DD");
- }
- startdata();
- $scope.changeForm = function(paramDateFrom) {
- $scope.searchkeys.quikly = { name: '自定义', value: 0 };
- $scope.starttimes = moment(paramDateFrom).format('YYYY-MM--DD');
- }
- $scope.changeTo = function(paramDateTo) {
- $scope.searchkeys.quikly = { name: '自定义', value: 0 };
- $scope.endtimes = moment(paramDateTo).format('YYYY-MM-DD');
- }
- $scope.open = function($event) {
- $event.preventDefault();
- $event.stopPropagation();
- $scope.opened = !$scope.opened;
- };
- $scope.endOpen = function($event) {
- $event.preventDefault();
- $event.stopPropagation();
- $scope.startOpened = false;
- $scope.endOpened = !$scope.endOpened;
- };
- $scope.startOpen = function($event) {
- $event.preventDefault();
- $event.stopPropagation();
- $scope.endOpened = false;
- $scope.startOpened = !$scope.startOpened;
- };
- function ConvertDateParameter(parameters) {
- var result = undefined;
- if (angular.isArray(parameters)) {
- //
- } else {
- result = {};
- for (var k in parameters) {
- if (k.indexOf("Date") > 0) {
- if (angular.isDate(parameters[k])) {
- result[k] = moment(parameters[k]).format("YYYY-MM-DD");
- } else if (angular.isString(parameters[k])) {
- result[k] = parameters[k];
- }
- }
- }
- }
- return result;
- }
- // 重置
- $scope.restData = function() {
- startdata();
- if($rootScope.user.duty){
- $scope.searchkeys.branch = {id: $rootScope.user.duty.branch, hosName: $rootScope.user.duty.branchName};
- $scope.getOwnDuty($rootScope.user.duty.branch, true);
- $scope.getAreas($scope.searchkeys.branch.id);
- }else if($rootScope.user.branch){
- $scope.searchkeys.branch = $rootScope.user.branch;
- $scope.getOwnDuty($rootScope.user.branch.id, true);
- $scope.getAreas($scope.searchkeys.branch.id);
- $scope.mdxquery($scope.searchkeys);
- }
- }
- $scope.mdxquery = function(key) {
- var changedate = ConvertDateParameter($scope.parameters)
- var fildata = { "start": moment(changedate.paramDateFrom).format("YYYY"), "end": moment(changedate.paramDateTo).format("YYYY"), "areaId": key.area ? key.area.id : undefined }
- getdata(fildata)
- }
- $scope.onChangetime = function(key) {
- if (key.value == 1) {
- $scope.starttimes = moment((new Date(moment().startOf('year'))).setFullYear((new Date()).getFullYear() - 2)).format('YYYY-MM-DD');
- $scope.endtimes = moment().format('YYYY-MM-DD');;
- $scope.parameters.paramDateFrom = $scope.starttimes;
- $scope.parameters.paramDateTo = $scope.endtimes;
- } else if (key.value == 2) {
- $scope.starttimes = moment((new Date(moment().startOf('year'))).setFullYear((new Date()).getFullYear() - 4)).format('YYYY-MM-DD');
- $scope.endtimes = moment().format('YYYY-MM-DD');;
- $scope.parameters.paramDateFrom = $scope.starttimes;
- $scope.parameters.paramDateTo = $scope.endtimes;
- } else if (key.value == 3) {
- $scope.starttimes = moment((new Date(moment().startOf('year'))).setFullYear((new Date()).getFullYear() - 9)).format('YYYY-MM-DD');
- $scope.endtimes = moment().format('YYYY-MM-DD');;
- $scope.parameters.paramDateFrom = $scope.starttimes;
- $scope.parameters.paramDateTo = $scope.endtimes;
- } else if (key.value == 4) {
- $scope.starttimes = moment((new Date(moment().startOf('year'))).setFullYear((new Date()).getFullYear() - 19)).format('YYYY-MM-DD');
- $scope.endtimes = moment().format('YYYY-MM-DD');;
- $scope.parameters.paramDateFrom = $scope.starttimes;
- $scope.parameters.paramDateTo = $scope.endtimes;
- }
- }
- $scope.execute = function() {
- api_report.list($scope.token).then(function(response) {
- $scope.select_treedata = $scope.my_data = response;
- });
- }
- $scope.searchOptions = function() {
- if (angular.isDefined(workspace.query)) {
- var queryParameters = workspace.query.parameters;
- for (var parm in queryParameters) {
- if (parm == 'Week') {
- } else {
- }
- }
- }
- }
- // 切换院区
- $scope.changeBranch = function(){
- console.log($scope.searchkeys.branch);
- $scope.dutys = [];
- $scope.searchkeys.duty = null;
- $scope.searchkeys.branch && $scope.getOwnDuty($scope.searchkeys.branch.id);
- $scope.outarea = [];
- $scope.searchkeys.area = null;
- $scope.searchkeys.branch && $scope.getAreas($scope.searchkeys.branch.id);
- }
- // 切换责任科室
- $scope.changeDuty = function(){
- console.log($scope.searchkeys.duty);
- }
- // 获取院区
- $scope.branchs = [];
- $scope.getOwnBranch = function(){
- api_category
- .getOwnBranch({})
- .then(function (response) {
- if (response) {
- if ((response.status = 200)) {
- $scope.branchs = response.data;
- if($rootScope.user.duty){
- $scope.searchkeys.branch = {id: $rootScope.user.duty.branch, hosName: $rootScope.user.duty.branchName};
- $scope.getOwnDuty($rootScope.user.duty.branch, true);
- $scope.getAreas($scope.searchkeys.branch.id);
- }else if($rootScope.user.branch){
- $scope.searchkeys.branch = $rootScope.user.branch;
- $scope.getOwnDuty($rootScope.user.branch.id, true);
- $scope.getAreas($scope.searchkeys.branch.id);
- $scope.mdxquery($scope.searchkeys);
- }
- }
- }
- });
- }
- $scope.getOwnBranch();
- // 获取责任科室
- $scope.dutys = [];
- $scope.getOwnDuty = function(branchId, isFirst = false){
- api_category
- .getOwnDuty({branchId: branchId})
- .then(function (response) {
- if (response) {
- if ((response.status = 200)) {
- $scope.dutys = response.data;
- if(isFirst && $rootScope.user.duty){
- $scope.searchkeys.duty = $rootScope.user.duty;
- $scope.mdxquery($scope.searchkeys);
- }
- }
- }
- });
- }
- //获取区域
- $scope.outarea = [];
- $scope.getAreas = function(branchId){
- api_user_data.fetchDataList('area', { "idx": 0, "sum": 1000, area: {branch: branchId} }).then(function(response) {
- if (response) {
- if (response.status = 200) {
- $scope.outarea = response.list;
- }
- }
- })
- }
- // $scope.getAreas();
- //数据
- var titledata = [];
- var datas = [
- []
- ];
- var serieslist = [];
- var colorlist = ['#005395', '#49a9ee', '#ffcd62', '#87c966', '#1ea58f'];
- var datetime = [];
- $scope.headerslist = [];
- $scope.listsum = [];
- $scope.rRows = [];
- //事件数量统计分析
- var domanalysis = document.getElementById("analysis");
- var myChartanalysis = echarts.init(domanalysis);
- var app = {};
- var optionanalysis = null;
- app.title = '事件数量统计分析';
- var XData = [];
- var yData = [];
- myChartanalysis.showLoading({
- text: '数据加载中...',
- color: '#c23531',
- textColor: '#fff',
- maskColor: 'rgba(255,255,255,0)',
- zlevel: 0
- });
- myChartanalysis.hideLoading();
- app.title = '堆叠条形图';
- optionanalysis = {
- tooltip: {
- trigger: 'axis',
- axisPointer: { // 坐标轴指示器,坐标轴触发有效
- type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
- },
- formatter: function(datas) {
- var allsum = 0;
- angular.forEach(datas, function(item) {
- allsum += item.data;
- })
- var res = '';
- for (var i = 0; i < datas.length; i++) {
- res += "<div>" + datas[i].marker + " " + datas[i].seriesName + ' 总数:' +
- datas[i].data + ' 占比:' + (allsum > 0 ? datas[i].data * 100 / allsum : 0).toFixed(2) + '%' + '</div>'
- }
- return "<div style='display:grid;grid-template-rows: auto auto auto;grid-template-columns: auto auto auto;'>" + res + "</div>"
- },
- confine: true
- },
- legend: {
- icon: "circle",
- bottom: '0%',
- data: titledata
- },
- grid: {
- left: '5%',
- right: '4%',
- bottom: '20%',
- top: '5%',
- containLabel: false
- },
- xAxis: {
- // axisTick: {
- // show: false
- // },
- splitLine: {
- show: false,
- },
- axisLine: {
- lineStyle: {
- color: '#ddd'
- }
- },
- splitArea: {
- show: false
- },
- axisLabel: {
- textStyle: {
- color: '#787878',
- fontSize: 12,
- }
- },
- type: 'value'
- },
- yAxis: {
- axisTick: {
- show: false
- },
- axisLabel: {
- show: true,
- textStyle: {
- color: '#6d6d6d',
- fontSize: 12,
- }
- },
- axisLine: {
- show: true,
- lineStyle: {
- color: '#ddd'
- }
- },
- splitArea: {
- show: false
- },
- type: 'category',
- data: datetime
- },
- series: serieslist
- }
- function getdata(time) {
- time.dutyId = $scope.searchkeys.duty ? $scope.searchkeys.duty.id : undefined;
- time.branchId = $scope.searchkeys.branch ? $scope.searchkeys.branch.id : undefined;
- api_hkreport.incidentreport(time, 'incident_trend_hk').then(function(data) {
- handledata(data);
- })
- }
- // getdata({ "start": moment($scope.parameters.paramDateFrom, "YYYY-MM-DD").format("YYYY"), "end": moment($scope.parameters.paramDateTo, "YYYY-MM-DD").format("YYYY") })
- function handledata(data) {
- serieslist = [];
- datetime = [];
- $scope.listsum = [];
- titledata = [];
- $scope.headerslist = data.quantityStatisticsTitle;
- $scope.rRows = data.quantityStatisticsList;
- angular.forEach($scope.rRows, function(item, index) {
- $scope.listsum[index] = { 'allzzl': '', 'sum': '', 'date': '', 'all': [] };
- var i = (Object.values($scope.rRows[0]).length - 3) / 2;
- if(i){
- for (var j = 0; j < i; j++) {
- $scope.listsum[index].all[j] = { 'category': $scope.rRows[index]['category' + j], 'zzl': $scope.rRows[index]['zzl' + j] };
- $scope.listsum[index].allzzl = $scope.rRows[index].allzzl == '-' ? $scope.rRows[index].allzzl : Number($scope.rRows[index].allzzl);
- $scope.listsum[index].sum = $scope.rRows[index].sum;
- $scope.listsum[index].date = $scope.rRows[index].date;
- $scope.rRows[index].allzzl = $scope.rRows[index].allzzl == '-' ? $scope.rRows[index].allzzl : Number($scope.rRows[index].allzzl);
- $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]) };
- }
- }else{
- for (var j = 0; j < Object.values($scope.rRows[0]).length; j++) {
- $scope.listsum[index].allzzl = $scope.rRows[index].allzzl == '-' ? $scope.rRows[index].allzzl : Number($scope.rRows[index].allzzl);
- $scope.listsum[index].sum = $scope.rRows[index].sum;
- $scope.listsum[index].date = $scope.rRows[index].date;
- }
- }
- })
- angular.forEach(data.quantityStatistics, function(item, index) {
- titledata.push(item.category);
- datas[index] = [];
- angular.forEach(item.data, function(itemtwo, indextwo) {
- datas[index][indextwo] = itemtwo.sum;
- })
- serieslist[index] = {
- name: item.category,
- type: 'bar',
- stack: '总量',
- "itemStyle": {
- "normal": {
- "barBorderRadius": 0,
- "color": colorlist[index],
- "label": {
- "show": false,
- "textStyle": {
- "color": "#87c966"
- },
- "position": "insideRight",
- formatter: function(p) {
- return p.value > 0 ? (p.value) : '';
- }
- }
- }
- },
- barWidth: 18,
- data: datas[index]
- }
- })
- angular.forEach(data.quantityStatisticsList, function(item, index) {
- datetime[index] = item.date;
- })
- optionanalysis.series = serieslist;
- optionanalysis.yAxis.data = datetime;
- optionanalysis.legend.data = titledata;
- myChartanalysis.setOption(optionanalysis, true);
- myChartanalysis.hideLoading();
- }
- }]);
|