1212import org .apache .log4j .Logger ;
1313
1414import com .qiniu .cdn .CdnResult ;
15+ import com .qiniu .cdn .CdnResult .BandwidthData ;
16+ import com .qiniu .cdn .CdnResult .FluxData ;
1517import com .qiniu .cdn .CdnResult .LogData ;
1618import com .qiniu .common .QiniuException ;
1719import com .qiniu .http .Response ;
2527import com .zhazhapan .qiniu .util .Formatter ;
2628import com .zhazhapan .qiniu .view .Dialogs ;
2729
30+ import javafx .application .Platform ;
2831import javafx .collections .FXCollections ;
2932import javafx .collections .ObservableList ;
33+ import javafx .scene .chart .XYChart .Data ;
34+ import javafx .scene .chart .XYChart .Series ;
3035
3136/**
3237 * @author pantao
@@ -41,6 +46,88 @@ public enum FileAction {
4146 COPY , MOVE
4247 }
4348
49+ /**
50+ * 获取空间带宽统计
51+ *
52+ * @return
53+ */
54+ public Series <String , Long > getBucketBandwidth (String [] domains , String fromDate , String toDate ) {
55+ CdnResult .BandwidthResult bandwidthResult = null ;
56+ try {
57+ bandwidthResult = QiniuApplication .cdnManager .getBandwidthData (domains , fromDate , toDate , "day" );
58+ } catch (QiniuException e ) {
59+ logger .error ("get bucket bandwidth error, message: " + e .getMessage ());
60+ Platform .runLater (() -> Dialogs .showException (Values .BUCKET_BAND_ERROR , e ));
61+ }
62+ Series <String , Long > bandSer = new Series <String , Long >();
63+ bandSer .setName (Values .BUCKET_BANDWIDTH_COUNT );
64+ // 获取带宽统计
65+ if (Checker .isNotNull (bandwidthResult ) && Checker .isNotEmpty (bandwidthResult .data )) {
66+ for (Map .Entry <String , BandwidthData > bandwidth : bandwidthResult .data .entrySet ()) {
67+ String [] times = bandwidthResult .time ;
68+ BandwidthData bandwidthData = bandwidth .getValue ();
69+ int i = 0 ;
70+ for (String time : times ) {
71+ long size = 0 ;
72+ if (Checker .isNotNull (bandwidthData )) {
73+ if (Checker .isNotNull (bandwidthData .china )) {
74+ size += bandwidthData .china [i ];
75+ }
76+ if (Checker .isNotNull (bandwidthData .oversea )) {
77+ size += bandwidthData .oversea [i ];
78+ }
79+ }
80+ bandSer .getData ().add (new Data <String , Long >(time .substring (5 , 10 ), size / Values .KB ));
81+ i ++;
82+ }
83+ }
84+ } else {
85+ logger .info ("bandwidth is empty of this domain" );
86+ }
87+ return bandSer ;
88+ }
89+
90+ /**
91+ * 获取空间的流量统计
92+ *
93+ * @return
94+ */
95+ public Series <String , Long > getBucketFlux (String [] domains , String fromDate , String toDate ) {
96+ CdnResult .FluxResult fluxResult = null ;
97+ try {
98+ fluxResult = QiniuApplication .cdnManager .getFluxData (domains , fromDate , toDate , "day" );
99+ } catch (QiniuException e ) {
100+ logger .error ("get bucket flux error, message: " + e .getMessage ());
101+ Platform .runLater (() -> Dialogs .showException (Values .BUCKET_FLUX_ERROR , e ));
102+ }
103+ Series <String , Long > fluxSer = new Series <String , Long >();
104+ fluxSer .setName (Values .BUCKET_FLUX_COUNT );
105+ // 获取流量统计
106+ if (Checker .isNotNull (fluxResult ) && Checker .isNotEmpty (fluxResult .data )) {
107+ for (Map .Entry <String , FluxData > flux : fluxResult .data .entrySet ()) {
108+ String [] times = fluxResult .time ;
109+ FluxData fluxData = flux .getValue ();
110+ int i = 0 ;
111+ for (String time : times ) {
112+ long size = 0 ;
113+ if (Checker .isNotNull (fluxData )) {
114+ if (Checker .isNotNull (fluxData .china )) {
115+ size += fluxData .china [i ];
116+ }
117+ if (Checker .isNotNull (fluxData .oversea )) {
118+ size += fluxData .oversea [i ];
119+ }
120+ }
121+ fluxSer .getData ().add (new Data <String , Long >(time .substring (5 , 10 ), size / Values .KB ));
122+ i ++;
123+ }
124+ }
125+ } else {
126+ logger .info ("flux is empty of this domain" );
127+ }
128+ return fluxSer ;
129+ }
130+
44131 /**
45132 * 日志下载,cdn相关
46133 */
@@ -248,6 +335,8 @@ public void deleteFiles(ObservableList<FileInfo> fileInfos, String bucket) {
248335 logger .info ("delete file '" + file + "' success" );
249336 deleteLog += "\t success\t " ;
250337 QiniuApplication .data .remove (seletecFileInfos .get (i ));
338+ QiniuApplication .totalLength --;
339+ QiniuApplication .totalSize -= Formatter .sizeToLong (seletecFileInfos .get (i ).getSize ());
251340 if (sear ) {
252341 currentRes .remove (seletecFileInfos .get (i ));
253342 }
@@ -261,6 +350,7 @@ public void deleteFiles(ObservableList<FileInfo> fileInfos, String bucket) {
261350 } catch (QiniuException e ) {
262351 Dialogs .showException (Values .DELETE_ERROR , e );
263352 }
353+ MainWindowController .getInstance ().setBucketCount ();
264354 }
265355 }
266356
0 commit comments