12
12
import org .apache .log4j .Logger ;
13
13
14
14
import com .qiniu .cdn .CdnResult ;
15
+ import com .qiniu .cdn .CdnResult .BandwidthData ;
16
+ import com .qiniu .cdn .CdnResult .FluxData ;
15
17
import com .qiniu .cdn .CdnResult .LogData ;
16
18
import com .qiniu .common .QiniuException ;
17
19
import com .qiniu .http .Response ;
25
27
import com .zhazhapan .qiniu .util .Formatter ;
26
28
import com .zhazhapan .qiniu .view .Dialogs ;
27
29
30
+ import javafx .application .Platform ;
28
31
import javafx .collections .FXCollections ;
29
32
import javafx .collections .ObservableList ;
33
+ import javafx .scene .chart .XYChart .Data ;
34
+ import javafx .scene .chart .XYChart .Series ;
30
35
31
36
/**
32
37
* @author pantao
@@ -41,6 +46,88 @@ public enum FileAction {
41
46
COPY , MOVE
42
47
}
43
48
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
+
44
131
/**
45
132
* 日志下载,cdn相关
46
133
*/
@@ -248,6 +335,8 @@ public void deleteFiles(ObservableList<FileInfo> fileInfos, String bucket) {
248
335
logger .info ("delete file '" + file + "' success" );
249
336
deleteLog += "\t success\t " ;
250
337
QiniuApplication .data .remove (seletecFileInfos .get (i ));
338
+ QiniuApplication .totalLength --;
339
+ QiniuApplication .totalSize -= Formatter .sizeToLong (seletecFileInfos .get (i ).getSize ());
251
340
if (sear ) {
252
341
currentRes .remove (seletecFileInfos .get (i ));
253
342
}
@@ -261,6 +350,7 @@ public void deleteFiles(ObservableList<FileInfo> fileInfos, String bucket) {
261
350
} catch (QiniuException e ) {
262
351
Dialogs .showException (Values .DELETE_ERROR , e );
263
352
}
353
+ MainWindowController .getInstance ().setBucketCount ();
264
354
}
265
355
}
266
356
0 commit comments