11package root .core .usecase .implement ;
22
3+ import java .io .File ;
34import java .io .FileInputStream ;
4- import java .io .FileNotFoundException ;
55import java .io .FileOutputStream ;
66import java .io .IOException ;
7- import java .io .InputStream ;
87import java .io .OutputStream ;
98
109import org .apache .poi .ss .usermodel .Sheet ;
2322import root .utils .CsvUtils ;
2423import root .utils .DBManageExcel ;
2524import root .utils .DateUtils ;
26- import root .utils .ExcelUtils ;
25+ import root .utils .ExcelSheet ;
2726
2827public class DBCheckUsecaseImpl implements DBCheckUsecase {
2928 private DBCheckRepository dbCheckRepository ;
@@ -38,6 +37,17 @@ public DBCheckUsecaseImpl(DBCheckRepository dbCheckRepository, ReportRepository
3837 public void printArchiveUsageCheck () {
3938 MonitoringResult <ArchiveUsage > result = dbCheckRepository .checkArchiveUsage ();
4039 System .out .println ("\t ▶ Archive Usage Check" );
40+
41+ result .getMonitoringResults ().forEach (r -> {
42+ if (r .getUsedPercent () >= 90 ) {
43+ System .out .println ("\t " + ConsoleUtils .BACKGROUND_RED + ConsoleUtils .FONT_WHITE
44+ + "▶ Archive Usage Check : Usage 90% 초과! (" + r .getArchiveName () + ")" + ConsoleUtils .RESET
45+ + "\n " );
46+ } else {
47+ System .out .println ("\t ▶ Archive Usage Check : SUCCESS\n " );
48+ }
49+ });
50+
4151 try {
4252 TextTable tt = new TextTable (
4353 new CsvTableModel (CsvUtils .toCsvString (result .getMonitoringResults (), ArchiveUsage .class )));
@@ -81,14 +91,6 @@ public void printASMDiskCheck() {
8191 public void writeExcelArchiveUsageCheck () throws Exception {
8292 MonitoringResult <ArchiveUsage > result = dbCheckRepository .checkArchiveUsage ();
8393 String dbName = dbCheckRepository .getDBName ();
84- double archiveUsage = result .getMonitoringResults ().get (0 ).getUsedPercent ();
85-
86- if (archiveUsage >= 90 ) {
87- System .out .println ("\t " + ConsoleUtils .BACKGROUND_RED + ConsoleUtils .FONT_WHITE
88- + "▶ Archive Usage Check : Usage 90% 초과!" + ConsoleUtils .RESET + "\n " );
89- } else {
90- System .out .println ("\t ▶ Archive Usage Check : SUCCESS\n " );
91- }
9294
9395 int year = Integer .parseInt (DateUtils .getToday ("yyyy" ));
9496 int month = Integer .parseInt (DateUtils .getToday ("MM" ));
@@ -104,20 +106,18 @@ public void writeExcelArchiveUsageCheck() throws Exception {
104106 rowIndex = 29 ;
105107 }
106108
107- String filePath = "C: \\ Users \\ aserv \\ Documents \\ WorkSpace_DBMonitoring_Quartz \\ DBMonitoring \\ report\\ " ;
108- String fileName = "DB관리대장_종합_" + year + "." + month ;
109+ String filePath = "./ report/ " ;
110+ String fileName = "DB관리대장_종합_" + year + "." + DateUtils . getTwoDigitDate ( month ) ;
109111 String extension = ".xlsx" ;
110- String file = filePath + fileName + extension ;
111-
112- InputStream is = null ;
113- try {
114- is = new FileInputStream (file );
115- } catch (FileNotFoundException e ) {
112+ File file = new File (filePath + fileName + extension );
113+
114+ if (!file .exists ()) {
115+ file .getParentFile ().mkdirs ();
116116 DBManageExcel .createMonthlyReportInExcel (year , month );
117- is = new FileInputStream (file );
118117 }
119-
120- Workbook workbook = ExcelUtils .getWorkbook (is , fileName + extension );
118+
119+ double archiveUsage = result .getMonitoringResults ().get (0 ).getUsedPercent ();
120+ Workbook workbook = ExcelSheet .getWorkbook (new FileInputStream (file ), fileName + extension );
121121 Sheet sheet = workbook .getSheetAt (0 );
122122 sheet .getRow (rowIndex ).getCell (colIndex ).setCellValue (archiveUsage + "%" );
123123 OutputStream os = new FileOutputStream (file );
0 commit comments