chargingCtrl的副本.js 13 KB

1
  1. "use strict";app.controller("chartingCtrl",["$scope","$rootScope","$state","$timeout","$interval","$http","$cookieStore","moment","SweetAlert","Restangular","api_report","api_statistic",function(e,a,r,t,l,n,s,o,u,i,p,v){function h(e){var a=void 0;if(angular.isArray(e));else{a={};for(var r in e)r.indexOf("Date")>0&&angular.isString(e[r])&&(a[r]=o(e[r],"YYYYMMDD").format("YYYY-MM-DD"))}return a}function c(e){var a=void 0;if(angular.isArray(e));else{a={};for(var r in e)r.indexOf("Date")>0&&(angular.isDate(e[r])?a[r]=o(e[r]).format("YYYYMMDD"):angular.isString(e[r])&&(a[r]=e[r]))}return a}function d(){return Y=D(Y),R(x(Y.h,Y.s,Y.v))}function f(){var e="xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var a=16*Math.random()|0,r="x"==e?a:3&a|8;return r.toString(16)}).toUpperCase();return e}function g(a){p.execute(a).then(function(a){e.rheaders=[],e.rRows=[];var r=i.stripRestangular(a);e.reportData=angular.copy(r);m(r)})}function m(e){return y(e)}function y(a){var r,t,l,n,s,o,u,i,p="",v="",h=a.cellset,c=h?h:[],d=!1,f=0,g=[],m=null,y=!1,D=!1,x=!1,R=[],_=!0,q=[],M=[],k={};k[b]=a.rowTotalsLists,k[O]=a.colTotalsLists;for(var E={},A={},T=[O,b],P=0;P<T.length;P++)E[T[P]]=new Array,A[T[P]]=new Array;if(k[b])for(var P=0;P<k[b].length;P++)A[b][P]=0,E[b][P]=k[b][P][A[b][P]].width;for(var P=0,Y=0,U=c.length;Y<U;Y++){var C=Y-a.topOffset;i=1,r=1,t="",l=!1,s=!1,o=!1,D=!1;var S=!1;if(k[O])for(var P=0;P<k[O].length;P++)A[O][P]=0,E[O][P]=k[O][P][A[O][P]].width;v="<tr>",0===Y&&(v="<thead>"+v);for(var F=0,H=c[Y].length;F<H;F++){var I=F-a.leftOffset,L=h[Y][F];if("COLUMN_HEADER"===L.type&&(D=!0),"ROW_HEADER"===L.type&&h[Y][0],"COLUMN_HEADER"===L.type&&"null"===L.value&&(null==n||F<n)){v+='<th class="all_null">&nbsp;</th>';var N={thclass:"all_null",value:" / "};q.push(N)}else if("COLUMN_HEADER"===L.type){if(null==n&&(n=F),c[Y].length==F+1?s=!0:u=h[Y][F+1],s)if("null"==L.value){v+='<th class="col_null">&nbsp;</th>';var N={thclass:"all_null",value:" / "};q.push(N)}else{k[O]&&(r=k[O][Y+1][A[O][Y+1]].span),v+='<th class="col" style="text-align: center;" colspan="'+r+'" title="'+L.value+'">'+(_?'<div rel="'+Y+":"+F+'">'+L.value+"</div>":L.value)+"</th>";var N={thclass:"col",colspan:""+r,title:L.value};_?N.value={rel:Y+":"+F,value:L.value}:N.value=L.value,q.push(N)}else{var $=F>1&&Y>1&&!l&&F>n&&(h[Y-1][F+1].value!=h[Y-1][F].value||h[Y-1][F+1].properties.uniquename!=h[Y-1][F].properties.uniquename),W=r>999;if(L.value!=u.value||w(h,Y,F)||l||$||W){if("null"==L.value){v+='<th class="col_null" colspan="'+r+'">&nbsp;</th>';var N={thclass:"col_null",colspan:r,value:"&nbsp;"};q.push(N)}else{k[O]&&(r=k[O][Y+1][A[O][Y+1]].span),v+='<th class="col" style="text-align: center;" colspan="'+(0==r?1:r)+'" title="'+L.value+'">'+(_?'<div rel="'+Y+":"+F+'">'+L.value+"</div>":L.value)+"</th>";var N={thclass:"col",colspan:0==r?1:r,title:L.value};_?N.value={rel:Y+":"+F,value:L.value}:N.value=L.value,q.push(N)}r=1}else r++}h[Y][3]={},k[O]&&(v+=genTotalHeaderCells(F-a.leftOffset+1,Y+1,E[O],A[O],k[O],_))}else if("ROW_HEADER"===L.type&&"null"===L.value){v+='<th class="row_null">&nbsp;</th>';var N={thclass:"row_null",value:L.value};q.push()}else if("ROW_HEADER"===L.type){f==F?l=!0:u=h[Y][F+1],c.length==Y+1?o=!0:i=h[Y+1][F];var K=h[Y-1],N={},j=!S&&!l&&0==F&&L.value===K[F].value;S=!j;var z=j?"<div>&nbsp;</div>":'<div rel="'+Y+":"+F+'">'+L.value+"</div>";j?N.value={value:"  "}:N.value={value:L.value,rel:Y+":"+F},_||(z=j?"&nbsp;":L.value,j?N.value=" / ":N.value=L.value);var G,B="",G=j?"row_null":"row",Z=0,X=0;if(!l&&("undefined"==typeof u||"null"===u.value)){Z=1;for(var J=L.properties.dimension,Q=L.properties.level,V=(J in g?g[J].length-g[J].indexOf(Q):1),ee=F+1;Z<V&&ee<=f+1&&"null"!==h[Y][ee];ee++)Z=ee-F;F+=Z}!o&&h[Y+1][F].value==h[Y][F].value,v+='<th class="'+G+'" '+(Z>0?' colspan="'+Z+'"':"")+(X>0?' rowspan="'+X+'"':"")+B+">"+z+"</th>",N.thclass=G,Z>0&&(N.colspan=Z),M.push(N)}else if("ROW_HEADER_HEADER"===L.type){v+='<th class="row_header">'+(_?"<div>"+L.value+"</div>":L.value)+"</th>";var N={thclass:"row_header",value:L.value};if(_?N.value={value:L.value}:N.value=L.value,q.push(N),l=!0,d=!0,f=F,L.properties.hasOwnProperty("dimension")){var J=L.properties.dimension;J in g||(g[J]=[]),g[J].push(L.properties.level)}}else if("DATA_CELL"===L.type){null!=L.value&&""!=L.value||(L.value="0"),y=!0;var ae="",re=L.value,te="",le={};if(L.properties){if(L.properties.hasOwnProperty("image")){var ne=L.properties.hasOwnProperty("image_height")?" height='"+L.properties.image_height+"'":"",se=L.properties.hasOwnProperty("image_width")?" width='"+L.properties.image_width+"'":"";re="<img "+ne+" "+se+" style='padding-left: 5px' src='"+L.properties.image+"' border='0'>"}L.properties.hasOwnProperty("style")&&(ae=" style='background-color: "+L.properties.style+"' ",le.rowStyle={"background-color":L.properties.style}),L.properties.hasOwnProperty("link")&&(re="<a target='__blank' href='"+L.properties.link+"'>"+re+"</a>"),L.properties.hasOwnProperty("arrow")&&(te="<img height='10' width='10' style='padding-left: 5px' src='./images/arrow-"+L.properties.arrow+".gif' border='0'>")}else L.properties={};v+='<td class="data" '+ae+">"+(_?'<div class="datadiv" alt="'+L.properties.raw+'" rel="'+L.properties.position+'">':"")+re+te+(_?"</div>":"")+"</td>",_?le.value={alt:L.properties.raw,rel:L.properties.position,value:re}:le.value=re,M.push(le),k[O]&&(v+=genTotalDataCells(I+1,C,E[O],A[O],k,_))}}v+="</tr>",e.rheaders.push(q),q=[],M.length>1&&(P+=parseInt(M[M.length-1].value.value,10),e.rRows.push(M),M=[]);var oe="";k[b]&&C>=0&&(oe+=genTotalHeaderRowCells(C+1,E,A,k,_)),y&&m?Y<=m?(D||x||(p+="</thead><tbody>",x=!0),p+=v,oe.length>0&&(p+=oe)):(R.push(v),oe.length>0&&R.push(oe)):(D||x||(p+="</thead><tbody>",x=!0),p+=v,oe.length>0&&(p+=oe))}var ue=[],ie=[],pe=[];ue[0]={thclass:"row",value:{rel:"1:0",value:"合计"}};for(var ve=0;ve<e.rRows.length;ve++){0!=P?(e.rRows[ve].push({value:{value:String((100*parseInt(e.rRows[ve][e.rRows[ve].length-1].value.value)/P).toFixed(2))+"%"}}),e.rRows[ve].push({value:{value:String((parseFloat(e.rRows[ve][e.rRows[ve].length-1].value.value)*e.allMoney/100).toFixed(2))}})):(e.rRows[ve].push({value:{value:"0%"}}),e.rRows[ve].push({value:{value:"0"}}));for(var he=0;he<e.rRows[ve].length;he++){var ce=/^[+-]?\d*\.?\d*$/.test(e.rRows[ve][he].value.value);ce&&(angular.isUndefined(pe[he])?pe[he]=parseFloat(e.rRows[ve][he].value.value):pe[he]=pe[he]+parseFloat(e.rRows[ve][he].value.value),ue[he]={value:{value:String(pe[he])}})}}ue[2]={value:{value:"100%"}},angular.forEach(ue,function(e){e&&ie.push(e)}),e.rheaders[0].push({colspan:"1",thclass:"col",title:"事件占比",value:{rel:"0:1",value:"事件占比(%)"}}),e.rheaders[0].push({colspan:"1",thclass:"col",title:"kpi",value:{rel:"0:1",value:"KPI(元)"}}),e.rRows.push(ie);var de=35*e.rRows.length;return e.allheight=de+570,"<table>"+p+"</tbody></table>"}function w(e,a,r){for(;a-- >0;)if(e[a][r].properties.uniquename!=e[a][r+1].properties.uniquename)return!0;return!1}function D(e){return angular.isUndefined(e)?{h:0,s:.75,v:.8}:{h:e.h+51.5,s:.75,v:.8}}function x(e,a,r){var t,l,n,s,o,u,i,p;if(0==a)return r=Math.floor(255*r),{r:r,g:r,b:r};switch(e/=60,t=Math.floor(e),l=e-t,n=r*(1-a),s=r*(1-a*l),o=r*(1-a*(1-l)),t){case 0:u=r,i=o,p=n;break;case 1:u=s,i=r,p=n;break;case 2:u=n,i=r,p=o;break;case 3:u=n,i=s,p=r;break;case 4:u=o,i=n,p=r;break;default:u=r,i=n,p=s}return{r:255*u,g:255*i,b:255*p}}function R(e){var a=e.r,r=e.g,t=e.b,l=t|r<<8|a<<16;return"#"+l.toString(16)}var O="ROWS",b="COLUMNS";e.treeshow=!0,p.getLicenseKey().then(function(e){s.put("Auth-Token",e.token)});var q={};e.parameters={},e.allMoney=0,e.category={},e.reportName="计费",e.allheight=100,e.isMaskground=!1,e.starttimes=o(new Date(o().startOf("month")).setMonth((new Date).getMonth()-1)).format("YYYYMMDD"),e.endtimes=o(new Date(o().startOf("month")).setMonth((new Date).getMonth())-864e5).format("YYYYMMDD");var M="/homes/home:admin/KPI报表/KPI.saiku";A=f();var k=function(a){p.getMdx(a,A).then(function(a){var r=i.stripRestangular(a);q.query=r,e.shows=!1,q.query.parameters.paramDateFrom=e.starttimes,q.query.parameters.paramDateTo=e.endtimes,e.parameters=h(q.query.parameters),e.mdxquery(r)})};k(M),e.my_data=[];var E=/^\d+(?=\.{0,1}\d+$|$)/;e.getmoney=function(){return null==e.allMoney||!E.test(e.allMoney)||""==e.allMoney},e.shareMoney=function(a){e.allMoney=a,e.reportData=angular.copy(e.manyData),e.rRows=[],e.rheaders=[],y(e.reportData)},e.repoRoot=null,e.open=function(a){a.preventDefault(),a.stopPropagation(),e.opened=!e.opened},e.endOpen=function(a){a.preventDefault(),a.stopPropagation(),e.startOpened=!1,e.endOpened=!e.endOpened},e.startOpen=function(a){a.preventDefault(),a.stopPropagation(),e.endOpened=!1,e.startOpened=!e.startOpened},e.mdxquery=function(){e.isMaskground=!0,e.shows=!1,angular.isDefined(q.query)&&(e.rptUUID?(q.query.parameters=c(e.parameters),q.query.parameters.paramDateFrom=q.query.parameters.paramDateFrom.replace(/-/g,""),q.query.parameters.paramDateTo=q.query.parameters.paramDateTo.replace(/-/g,""),e.starttimes=q.query.parameters.paramDateFrom,e.endtimes=q.query.parameters.paramDateTo,v.query(q.query.parameters,e.rptUUID).then(function(a){e.isMaskground=!1,e.rheaders=[],e.rRows=[];var r=i.stripRestangular(a);e.reportData=angular.copy(r),e.manyData=angular.copy(r),r.cellset.length<2&&(r.cellset=null,e.shows=!0,e.empty="数据为空!");m(r)})):(e.rptUUID=void 0,q.query.parameters=c(e.parameters),angular.isDefined(e.parameters.paramDateFrom)&&angular.isDefined(e.parameters.paramDateTo)&&(q.query.parameters.paramDateFrom=q.query.parameters.paramDateFrom.replace(/-/g,""),q.query.parameters.paramDateTo=q.query.parameters.paramDateTo.replace(/-/g,""),e.starttimes=q.query.parameters.paramDateFrom,e.endtimes=q.query.parameters.paramDateTo,p.execute(q.query).then(function(a){e.isMaskground=!1,e.rheaders=[],e.rRows=[];var r=i.stripRestangular(a);e.reportData=angular.copy(r),e.manyData=angular.copy(r),null!=r.cellset&&0!=r.cellset.length||(e.shows=!0,e.empty="数据为空!");m(r);P(r)}))))},e.execute=function(){p.list(e.token).then(function(a){e.select_treedata=e.my_data=a})},e.searchOptions=function(){if(angular.isDefined(q.query)){var e=q.query.parameters;for(var a in e);}},e.activeParentGroup=!1,e.disabledParentGroup=!1,e.toggleParentGroup=function(){q.query&&(q.query.properties["saiku.olap.result.formatter"]="flattened",g(q.query))};var A,T=function(e,a,r){var t=this,l={};a&&(l.resultset=[],l.metadata=[],l.height=0,l.width=0);var n=l;if("undefined"!=typeof e&&"undefined"!=typeof e.data&&(null===e.data||null===e.data.error)&&!(null===e.data||e.data.cellset&&0===e.data.cellset.length)){var s=e.data.cellset;if(s&&s.length>0){var o,u,i,p=0,v=0,h=!1,c=function(e,a){return e+a};for(o=0,u=s.length;0===v&&o<u;o++)for(var d=0,f=s[o].length;d<f;d++){if(!h)for(;"COLUMN_HEADER"==s[o][d].type&&"null"==s[o][d].value;)o++;if(h=!0,"ROW_HEADER_HEADER"==s[o][d].type){for(;"ROW_HEADER_HEADER"==s[o][d].type;)a&&l.metadata.push({colIndex:d,colType:"String",colName:s[o][d].value}),d++;p=d-1}if("COLUMN_HEADER"==s[o][d].type){for(var g=0,m=[];g<=o;)"null"!==s[g][d].value&&m.push(s[g][d].value),g++;a&&l.metadata.push({colIndex:d,colType:"Numeric",colName:m.join(" ~ ")}),v=o+1}}var y=[];for(i=0;i<=p;i++)y.push(null);for(o=v,u=s.length;o<u;o++)if(""!==s[o][0].value){var w=[],D=[],x=null,R=null;for(i=0;i<=p;i++){if(s[o]&&"null"===s[o][i].value){n=l;for(var O=0;O<p&&"null"===s[o][O].value;O++)n=n[y[O]];O>i&&(i=O)}if(s[o]&&"null"!==s[o][i].value){if(0===i)for(var b=0;b<=p;b++)y[b]=null;"number"==typeof n&&(x[R]={},n=x[R]),R=s[o][i].value,y[i]=R,n.hasOwnProperty(R)||(n[R]={}),x=n,n=n[R]}}D=_.clone(y);for(var q=p+1,M=s[o].length;q<M;q++){var k=s[o][q],E=k.value||0,A=0!==E,T=k.properties.raw;T&&"null"!==T?E=parseFloat(T):"number"!=typeof k.value&&parseFloat(k.value.replace(/[^a-zA-Z 0-9.]+/g,""))&&(E=parseFloat(k.value.replace(/[^a-zA-Z 0-9.]+/g,"")),A=!1),E>0&&A&&(E=k.value&&k.value.indexOf("%")>=0?100*E:E),w.push(E),D.push({f:k.value,v:E})}a&&l.resultset.push(D);var P=_.reduce(w,c,0);R=null===R?"null":R,x[R]=P,n=l}return r&&(t.rawdata=e.data,t.data=l,t.hasProcessed=!0,t.data.height=t.data.resultset.length),l}}},P=function(a){var r=T({data:a}),t=window._,l=void 0;if(e.chartData=[],q.query)if("sunburst"==q.query.properties["saiku.ui.render.type"]){e.chartType="pie",l=[];var n=0,s=0;t.forIn(r,function(e,a){n+=e,s++,l.push({label:a,value:e,color:d()})}),e.chartData=l,e.chartOptions={segmentShowStroke:!0,segmentStrokeWidth:2,legendTemplate:'<ul class="tc-chart-js-legend col-md-2.5 " style="float:right;margin-top:-250px;z-index: 999;"><% for (var i=0; i<Math.min(segments.length,5); i++){%><li><span style="background-color:<%=segments[i].fillColor%>"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>',onAnimationComplete:function(){this.showTooltip(this.segments,!0)}}}else"stackedBar"==q.query.properties["saiku.ui.render.type"]};e.getRelativePosition=function(e){},e.getPointPosition=function(e){},e.exportData=function(a){!a&&A&&(a=A);var r=e.mdxpath;if(void 0!=q.query.name){var t=r.substring(r.lastIndexOf("/")+1).slice(0,-5);n({url:p.exportData("flat",a,encodeURIComponent(t)).getRequestedUrl(),method:"POST",data:q.query,headers:{Accept:"application/vnd.ms-excel","X-Auth-Token":s.get("Auth-Token")||null},responseType:"arraybuffer"}).success(function(e,a,r,l){var n=new Blob([e],{type:"application/vnd.ms-excel"}),s=URL.createObjectURL(n),o=document.createElement("a");o.href=s,o.target="_blank",o.download=t+"xls",document.body.appendChild(o),o.click()}).error(function(e,a,r,t){})}},e.rheaders=[],e.rRows=[],e.onChartClick=function(e){};var Y=void 0}]);