2222import javafx .fxml .FXML ;
2323import javafx .fxml .FXMLLoader ;
2424import javafx .scene .control .Alert .AlertType ;
25+ import javafx .scene .control .Button ;
2526import javafx .scene .control .DatePicker ;
2627import javafx .scene .control .Label ;
2728import javafx .scene .control .Pagination ;
3132import javafx .scene .control .cell .PropertyValueFactory ;
3233import javafx .scene .layout .AnchorPane ;
3334import javafx .scene .layout .BorderPane ;
35+ import javafx .scene .layout .HBox ;
3436import javafx .util .Callback ;
3537import root .core .domain .MonitoringResult ;
3638import root .core .domain .enums .UsageUIType ;
3941import root .core .repository .implement .ReportFileRepo ;
4042import root .core .usecase .constracts .ReportUsecase ;
4143import root .core .usecase .implement .ReportUsecaseImpl ;
44+ import root .javafx .CustomView .PrequencyButton ;
4245import root .javafx .CustomView .UsageUI .UsageUI ;
4346import root .javafx .CustomView .UsageUI .UsageUIFactory ;
4447import root .utils .AlertUtils ;
@@ -71,11 +74,24 @@ public class MonitoringAPController<T extends MonitoringResult> extends BorderPa
7174
7275 @ FXML
7376 Pagination pagination ;
77+
78+ @ FXML
79+ HBox prequencyHBox ;
80+
81+ @ FXML
82+ Button prequencyTimeDivBtn ;
7483
7584 private Class <T > clazz ;
7685
7786 // Map<Alias, Map<MonitoringDateTime, MonitoringResults>>
7887 private Map <String , Map <String , List <T >>> tableDataMap = new HashMap <>();
88+
89+ private static Map <Integer , Long > countByTime = new HashMap <>();
90+ static {
91+ for (int i = 0 ; i < 24 ; i ++) {
92+ countByTime .put (i , 0L );
93+ }
94+ }
7995
8096 public MonitoringAPController (Class <T > clazz ) {
8197 this .reportUsecase = new ReportUsecaseImpl (ReportFileRepo .getInstance ());
@@ -108,8 +124,13 @@ public MonitoringAPController(Class<T> clazz) {
108124 String selected = aliasComboBox .getSelectionModel ().getSelectedItem ();
109125 syncTableData (selected , newValue .intValue ());
110126 });
111-
127+
128+ // Set prequency div initial value
129+ String amOrPm = Integer .valueOf (DateUtils .getToday ("HH" )) < 12 ? "AM" : "PM" ;
130+ prequencyTimeDivBtn .setText (amOrPm );
131+
112132 } catch (IOException e ) {
133+ e .printStackTrace ();
113134 }
114135 }
115136
@@ -183,12 +204,15 @@ public void syncTableData(String id, int index) {
183204 Collections .sort (times );
184205
185206 ObservableList <T > tableData = null ;
186- if (times .size () > index ) {
207+ if (times .size () > index ) {
187208 tableData = FXCollections .observableList (data .get (times .get (index )));
188209 }
189210
190211 monitoringResultTV .setItems (tableData );
191212 monitoringResultTV .refresh ();
213+
214+ // Sync monitoring prequency UI
215+ syncPrequency (prequencyTimeDivBtn .getText ());
192216 }
193217
194218 /**
@@ -288,7 +312,7 @@ public void run(ActionEvent e) {
288312 AlertUtils .showAlert (AlertType .INFORMATION , "조회결과 없음" , "해당일자의 모니터링 기록이 없습니다." );
289313 return ;
290314 }
291-
315+
292316 // Add and Sync data
293317 addTableDataSet (selected , allDataList );
294318 syncTableData (selected , 0 );
@@ -307,6 +331,18 @@ private Map<String, List<T>> inquiryMonitoringHistory() {
307331 return reportUsecase .getMonitoringReportDataByTime (this .clazz , selected , selectedUnit , selectedRoundUnit ,
308332 inquiryDate );
309333 }
334+
335+ private Map <Integer , Long > inquiryMonitoringHistoryCountByTime () {
336+ // Get selected inquiry condition
337+ String inquiryDate = this .inquiryDatePicker .getValue ().format (DateTimeFormatter .ofPattern ("yyyyMMdd" ));
338+ String selected = aliasComboBox .getSelectionModel ().getSelectedItem ();
339+ FileSize selectedUnit = unitComboBox .getSelectionModel ().getSelectedItem ();
340+ int selectedRoundUnit = roundComboBox .getSelectionModel ().getSelectedItem ();
341+
342+ // Acquire data on inquiry date
343+ return reportUsecase .getMonitoringReportCountByTime (this .clazz , selected , selectedUnit , selectedRoundUnit ,
344+ inquiryDate );
345+ }
310346
311347 /**
312348 * 현재 선택된 조회조건으로 재검색한다.
@@ -325,6 +361,36 @@ public void refresh(ActionEvent e) {
325361 public void excelDownload (ActionEvent e ) {
326362
327363 }
364+
365+ /**
366+ * 모니터링 기록 빈도를 나타내는 UI바의 AM/PM 구분을 변경한다.
367+ *
368+ * @param e
369+ */
370+ public void prequencyTimeDivToggle (ActionEvent e ) {
371+ String text = prequencyTimeDivBtn .getText ();
372+ prequencyTimeDivBtn .setText (text .equals ("AM" ) ? "PM" : "AM" );
373+ syncPrequency (prequencyTimeDivBtn .getText ());
374+ }
375+
376+ /**
377+ * 모니터링 기록 빈도 데이터와 UI의 Sync를 맞춘다.
378+ *
379+ * @param timeDiv
380+ */
381+ private void syncPrequency (String timeDiv ) {
382+ countByTime .putAll (inquiryMonitoringHistoryCountByTime ());
383+
384+ prequencyHBox .getChildren ().clear ();
385+ List <Integer > keys = new ArrayList <>(countByTime .keySet ());
386+ Collections .sort (keys );
387+
388+ int startIdx = timeDiv .equals ("AM" ) ? 0 : 12 ;
389+ int endIdx = timeDiv .equals ("AM" ) ? 12 : 24 ;
390+ for (int i = startIdx ; i < endIdx ; i ++) {
391+ prequencyHBox .getChildren ().add (new PrequencyButton (countByTime .get (i )));
392+ }
393+ }
328394
329395 /*==========================================================================================*/
330396
0 commit comments