Browse Source

생활치료센터 오픈API 통계 완료

junekeunsong 4 years ago
parent
commit
d6e5fd8df1

+ 34 - 0
src/main/java/com/lemon/lifecenter/common/LifeCenterFunction.java

@@ -24,6 +24,7 @@ import java.util.ArrayList;
 import java.util.Base64;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -216,6 +217,39 @@ public class LifeCenterFunction {
         return dateFormat.format(date);
     }
     
+    /**
+     * 시간 더하기 빼기
+     * @author jksong
+     * @Param
+     **/
+    public static String addDate(String fromDate, String format, int addYear, int addMonth, int addDate, int addHour, int addMinute) {
+
+      SimpleDateFormat sdf = new SimpleDateFormat(format);
+      Date date = null;
+      try {
+        date = sdf.parse(fromDate);
+
+        Calendar cal = new GregorianCalendar();
+
+        cal.setTime(date);
+        cal.add(Calendar.YEAR, +addYear);
+        cal.add(Calendar.MONTH, +addMonth);
+        cal.add(Calendar.DATE, +addDate);
+        cal.add(Calendar.HOUR, +addHour);
+        cal.add(Calendar.MINUTE, +addMinute);
+//      cal.add(Calendar.SECOND, +addSecond);
+
+        SimpleDateFormat sdf2 = new SimpleDateFormat(format);
+        String toDate = sdf2.format(cal.getTime());
+
+        return toDate;
+      } catch (ParseException e) {
+        e.printStackTrace();
+      }
+
+      return "";
+    }
+    
     public static String changeJuminToBirthday(String dateStr) {
         String resDate = "";
         try {

+ 177 - 8
src/main/java/com/lemon/lifecenter/controller/ApiMonitoringController.java

@@ -121,8 +121,7 @@ public class ApiMonitoringController extends LifeCenterController {
         }
         
         if( startDate.equals( "" ) ) {
-            //기록상 최초 환자 입소일 이후부터 계산
-            startDate = "2021-02-15";
+            startDate = LifeCenterFunction.addDate(endDate, "yyyy-MM-dd", 0, 0, -15, 0, 0);
         }
         
         dto.setEndDate(endDate);
@@ -143,13 +142,183 @@ public class ApiMonitoringController extends LifeCenterController {
         return mv;
     }
     
-    @RequestMapping("/state")
-    public ModelAndView state() {
-        ModelAndView mv = setMV("api/monitor/state");
-        return mv;
+    @RequestMapping(value="/statisticsChartStateExcel", method=RequestMethod.POST)
+    public void getstatisticsChartState(
+            @RequestParam(value="downMemo", required=false, defaultValue="") String downMemo,
+            @RequestParam(value="startDate", required=false, defaultValue="") String startDate,
+            @RequestParam(value="endDate", required=false, defaultValue="") String endDate,
+            HttpServletRequest request,HttpServletResponse response) {
+        
+        String userId = LifeCenterSessionController.getSession(request, "sesId");
+        
+        //excel 다운로드 로그 남기기
+        FileDownloadDTO fileDTO = new FileDownloadDTO();
+        fileDTO.setId( userId );
+        fileDTO.setIp( LifeCenterFunction.getRemoteAddr( request ) );
+        fileDTO.setUrl( request.getRequestURI().toString() );
+        fileDTO.setMemo( downMemo );
+        fileDTO.setEtc( "" );
+        fileDownloadService.insertExcelDownloadLog( fileDTO );
+        
+        if( endDate.equals( "" ) ) {
+            endDate = LifeCenterFunction.getNow( "yyyy-MM-dd" );
+        }
+        
+        if( startDate.equals( "" ) ) {
+//            startDate = "2021-02-15";
+            startDate = LifeCenterFunction.addDate(endDate, "yyyy-MM-dd", 0, 0, -14, 0, 0);
+        }
+        
+        ApiMonitorDTO dto = new ApiMonitorDTO();
+        dto.setEndDate(endDate);
+        dto.setStartDate(startDate);
+        
+        ApiMonitorDTO stateData = monitorService.selectStatisticsState(dto);
+        List<ApiMonitorDTO> charList = monitorService.selectStatisticsChart(dto);
+        
+        getStatisticsChartStateExcel(request, response, charList, stateData);
+        
+    }
+    
+    private void getStatisticsChartStateExcel(HttpServletRequest request, HttpServletResponse response,
+            List<ApiMonitorDTO> data, ApiMonitorDTO stateData) {
+        String password = LifeCenterSessionController.getSession(request, "sesPhoneNumber");
+        password = password.toLowerCase();
+        if (!password.equals("null") && !password.equals("")) {
+            password = password.replace("-", "");
+            password = password.substring(3).trim();
+        } else {
+            password = "";
+        }
+        
+        Workbook workbook = new XSSFWorkbook();
+        Sheet sheet1 = workbook.createSheet("firstSheet");
+        DecimalFormat df = new DecimalFormat("#,###");
+        
+        // 1.셀 스타일 및 폰트 설정
+        CellStyle styleOfBoardFillFontBlackBold16 = workbook.createCellStyle();
+        // 정렬
+        styleOfBoardFillFontBlackBold16.setAlignment(CellStyle.ALIGN_CENTER); // 가운데 정렬
+        styleOfBoardFillFontBlackBold16.setVerticalAlignment(CellStyle.VERTICAL_CENTER); // 높이 가운데 정렬
+        // 배경색
+        styleOfBoardFillFontBlackBold16.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
+        styleOfBoardFillFontBlackBold16.setFillPattern(CellStyle.SOLID_FOREGROUND);
+        // 테두리 선 (우,좌,위,아래)
+        styleOfBoardFillFontBlackBold16.setBorderRight(HSSFCellStyle.BORDER_THIN);
+        styleOfBoardFillFontBlackBold16.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+        styleOfBoardFillFontBlackBold16.setBorderTop(HSSFCellStyle.BORDER_THIN);
+        styleOfBoardFillFontBlackBold16.setBorderBottom(HSSFCellStyle.BORDER_THIN);
+        // 폰트 설정
+        Font fontOfGothicBlackBold16 = workbook.createFont();
+//        fontOfGothicBlackBold16.setFontName("나눔고딕"); //글씨체
+        fontOfGothicBlackBold16.setFontHeight((short) (10 * 20)); // 사이즈
+        fontOfGothicBlackBold16.setBoldweight(Font.BOLDWEIGHT_BOLD); // 볼드 (굵게)
+        styleOfBoardFillFontBlackBold16.setFont(fontOfGothicBlackBold16);
+        
+        Row row = sheet1.createRow(0);
+        Cell cell1 = row.createCell(0);
+        Cell cell2 = row.createCell(1);
+        Cell cell3 = row.createCell(2);
+        
+        cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
+        
+        sheet1.setColumnWidth(0, 5000); // 오픈 API 병원 건수
+        sheet1.setColumnWidth(1, 5000); // 오픈 API 호출 횟수
+        sheet1.setColumnWidth(2, 5000); // 오픈 API 호출 횟수
+        
+        cell1.setCellValue("오픈 API 병원 건수");
+        cell2.setCellValue("오픈 API 호출 횟수");
+        cell3.setCellValue("오픈 API 호출 횟수");
+        
+        row = sheet1.createRow(1);
+        cell1 = row.createCell(0);
+        cell2 = row.createCell(1);
+        cell3 = row.createCell(2);
+        
+        int hospitalCount = stateData.getTotal();
+        int apiCount = stateData.getApiCount();
+        int numberOfCase = stateData.getNumberOfCase();
+        
+        cell1.setCellValue(hospitalCount);
+        cell2.setCellValue(apiCount);
+        cell3.setCellValue(numberOfCase);
+        
+        row = sheet1.createRow(3);
+        cell1 = row.createCell(0);
+        cell2 = row.createCell(1);
+        
+        cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
+        
+        sheet1.setColumnWidth(0, 5000); // 오픈 API 병원 건수
+        sheet1.setColumnWidth(1, 5000); // 오픈 API 호출 횟수
+        
+        cell1.setCellValue("날짜");
+        cell2.setCellValue("오픈 API 호출 건수");
+        
+        int i = 4;
+        for (ApiMonitorDTO dto : data) {
+            row = sheet1.createRow(i);
+            cell1 = row.createCell(0);
+            cell2 = row.createCell(1);
+            
+            String inDate = dto.getInDate();
+            int total = dto.getTotal();
+            
+            cell1.setCellValue(inDate);
+            cell2.setCellValue(total);
+            
+            i++;
+        }
+        
+        try {
+            String tempPath = "../excel-temp/testExcel.xlsx";
+            String downName = LifeCenterFunction.getNow() + " open_api_statistics_chart_state.xlsx";
+            File xlsFile = new File(tempPath);
+
+            ByteArrayOutputStream fileOut = new ByteArrayOutputStream();
+            FileOutputStream fos = new FileOutputStream(tempPath);
+            workbook.write(fileOut);
+
+            InputStream filein = new ByteArrayInputStream(fileOut.toByteArray());
+            OPCPackage opc = OPCPackage.open(filein);
+
+            POIFSFileSystem fileSystem = new POIFSFileSystem();
+
+            EncryptionInfo encryptionInfo = new EncryptionInfo(EncryptionMode.agile);
+            Encryptor encryptor = encryptionInfo.getEncryptor();
+            encryptor.confirmPassword(password);
+
+            opc.save(encryptor.getDataStream(fileSystem));
+            opc.flush();
+
+            fileSystem.writeFilesystem(fos);
+
+            fileOut.close();
+            opc.close();
+
+            filein.close();
+            fileSystem.close();
+
+            LifeCenterFileDownload.download(request, response, tempPath, downName);
+
+            xlsFile.delete();
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (InvalidFormatException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (GeneralSecurityException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
     }
     
-    @RequestMapping( value="/statisticsExcel", method=RequestMethod.POST )
+    @RequestMapping(value="/statisticsExcel", method=RequestMethod.POST)
     public void getStatisticsList(
             @RequestParam(value="downMemo", required=false, defaultValue="") String downMemo,
             HttpServletRequest request,HttpServletResponse response ) {
@@ -176,7 +345,7 @@ public class ApiMonitoringController extends LifeCenterController {
         getStatisticsListExcel(request, response, result);
     }
     
-    private void getStatisticsListExcel(HttpServletRequest request, HttpServletResponse response, List<ApiMonitorDTO> data ) {
+    private void getStatisticsListExcel(HttpServletRequest request, HttpServletResponse response, List<ApiMonitorDTO> data) {
         String password = LifeCenterSessionController.getSession(request, "sesPhoneNumber");
         password = password.toLowerCase();
         if (!password.equals("null") && !password.equals("")) {

+ 7 - 6
src/main/webapp/WEB-INF/jsp/api/monitor/chart.jsp

@@ -111,11 +111,14 @@ function getExcel(){
     
     newForm.attr( "id", "excelForm" );
     newForm.attr( "method", "post" );
-    newForm.attr( "action", "./excel" );
+    newForm.attr( "action", "./statisticsChartStateExcel" );
     newForm.attr( "target", "_blank" );
     newForm.hide();
     
     $( document.body ).append( newForm );
+    newForm.append( $("#downMemo").clone() );
+    newForm.append( $("#startDate").clone() );
+    newForm.append( $("#endDate").clone() );
     newForm.submit();
     $( "button.close" ).click();
     $( "#downMemo" ).val( "" );
@@ -123,9 +126,6 @@ function getExcel(){
     
 }
 
-
-
-
 </script>
 </head>
 <body>
@@ -172,13 +172,13 @@ function getExcel(){
                     <!-- 환지관리 START -->
                     <div class="row">
                         <div class="col-12 col-lg-6">
-                            <h1 class="h3 mb-3">생활치료센터 오픈API 통계</h1>
+                            <h1 class="h3 mb-3">생활치료센터 오픈API 통계 (차트)</h1>
                         </div>
                         <div class="col-12 col-lg-6  text-right">
                             <nav aria-label="breadcrumb">
                                 <ol class="breadcrumb">
                                     <li class="breadcrumb-item"><a href="javscript:;">Home</a></li>
-                                    <li class="breadcrumb-item active">생활치료센터 오픈API 통계</li>
+                                    <li class="breadcrumb-item active">오픈API 통계 (차트)</li>
                                 </ol>
                             </nav>
                         </div>
@@ -248,6 +248,7 @@ function getExcel(){
                                     <div class="row mb-3 border-bottom pb-3">
                                         <div class="col-6"></div>
                                         <div class="col-6 text-right">
+                                            <button class="btn btn-secondary" onclick="location.href='./list'">리스트</button>
                                             <button class="btn btn-success" data-toggle="modal" data-target="#excelDownMemo">Excel 다운로드</button>
                                         </div>
                                     </div>

+ 3 - 5
src/main/webapp/WEB-INF/jsp/api/monitor/list.jsp

@@ -102,13 +102,13 @@ function getExcel(){
                     <!-- 환지관리 START -->
                     <div class="row">
                         <div class="col-12 col-lg-6">
-                            <h1 class="h3 mb-3">생활치료센터 오픈API 통계</h1>
+                            <h1 class="h3 mb-3">생활치료센터 오픈API 통계 (목록)</h1>
                         </div>
                         <div class="col-12 col-lg-6  text-right">
                             <nav aria-label="breadcrumb">
                                 <ol class="breadcrumb">
                                     <li class="breadcrumb-item"><a href="javscript:;">Home</a></li>
-                                    <li class="breadcrumb-item active">생활치료센터 오픈API 통계</li>
+                                    <li class="breadcrumb-item active">오픈API 통계 (목록)</li>
                                 </ol>
                             </nav>
                         </div>
@@ -181,10 +181,8 @@ function getExcel(){
                                             <fmt:formatNumber value="${total}" pattern="#,###" />
                                         </div>
                                         <div class="col-6 text-right">
+                                            <button class="btn btn-info" onclick="location.href='./chart'">차트</button>
                                             <button class="btn btn-success" data-toggle="modal" data-target="#excelDownMemo">Excel 다운로드</button>
-                                            <c:if test="${role._CREATE eq 'Y'}">
-                                                <button class="btn btn-primary" onclick="location.href='./new';">생활치료센터 신규 등록</button>
-                                            </c:if>
                                         </div>
                                     </div>
                                     <div class="table-responsive">

+ 0 - 201
src/main/webapp/WEB-INF/jsp/api/monitor/state.jsp

@@ -1,201 +0,0 @@
-<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
-<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
-<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
-<%@ page language="java" contentType="text/html; charset=UTF-8"
-    pageEncoding="UTF-8"%>
-<jsp:include page="${data._INCLUDE}/header.jsp"></jsp:include>
-<script>
-var startDate = "<c:out value='${startDate}'/>";
-var endDate   = "<c:out value='${endDate}'/>";
-
-    $(function() {
-        $("input[name=\"startDate\"]").daterangepicker({
-            singleDatePicker : true,
-            showDropdowns : true,
-//             startDate : "<c:out value='${startDate}'/>",
-            locale : {
-                //format : "M/DD hh:mm A"
-                format : "YYYY-MM-DD"
-            },
-            maxDate : new Date()
-        });
-        $("input[name=\"endDate\"]").daterangepicker({
-            singleDatePicker : true,
-            showDropdowns : true,
-//             startDate : "<c:out value='${endDate}'/>",
-            locale : {
-                //format : "M/DD hh:mm A"
-                format : "YYYY-MM-DD"
-            },
-            maxDate : new Date()
-        });
-        
-        $("input[name=\"startDate\"]").val( startDate );
-        $("input[name=\"endDate\"]").val( endDate );
-    });
-
-function getExcel(){
-    if( $.trim( $( "#downMemo" ).val() ) == "" ){
-        alertBox({ txt : "사유를 입력해주세요" });
-        $( ".modal-header>.modal-title h3" ).remove();
-        return false;
-    }
-    var newForm = $( "#searchForm" ).clone();
-    
-    newForm.attr( "id", "excelForm" );
-    newForm.attr( "method", "post" );
-    newForm.attr( "action", "./excel" );
-    newForm.attr( "target", "_blank" );
-    newForm.hide();
-    
-    $( document.body ).append( newForm );
-    newForm.submit();
-    $( "button.close" ).click();
-    $( "#downMemo" ).val( "" );
-    $( "#excelForm" ).remove();
-    
-}
-</script>
-</head>
-<body>
-    <div class="modal fade" id="excelDownMemo" tabindex="-1" role="dialog" aria-hidden="true" data-memoid="">
-        <div class="modal-dialog" role="document">
-            <div class="modal-content">
-                <div class="modal-header">
-                    <h5 class="modal-title">생활치료센터 리스트 Excel 다운로드</h5>
-                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
-                            aria-hidden="true">&times;</span> </button>
-                </div>
-                <div class="modal-body m-3">
-                    <table class="table mobile-table">
-                        <colgroup>
-                            <col style="width: 20%">
-                            <col style="width: 80%">
-                        </colgroup>
-                        <tr>
-                            <th><span class="fix">*</span>다운로드 사유</th>
-                            <td>
-                                <div class="form-row">
-                                    <textarea id="downMemo" name="downMemo" class="form-control" cols="" rows="6" placeholder="" maxlength="200"></textarea>
-                                </div>
-                            </td>
-                        </tr>
-                    </table>
-                </div>
-                <div class="addMemoTools modal-footer">
-                    <button type="button" class="btn btn-outline-primary" data-dismiss="modal">취소</button>
-                    <button type="button" class="btn btn-primary" onclick="getExcel();">제출 후 다운로드</button>
-                </div>
-            </div>
-        </div>
-    </div>
-    
-    <div class="wrapper">
-        <jsp:include page="${data._INCLUDE}/sidebar.jsp"></jsp:include>
-        
-        <div class="main">
-            <jsp:include page="${data._INCLUDE}/top.jsp"></jsp:include>
-
-            <main class="content">
-                <div class="container-fluid p-0">
-                    <!-- 환지관리 START -->
-                    <div class="row">
-                        <div class="col-12 col-lg-6">
-                            <h1 class="h3 mb-3">생활치료센터 오픈API 통계</h1>
-                        </div>
-                        <div class="col-12 col-lg-6  text-right">
-                            <nav aria-label="breadcrumb">
-                                <ol class="breadcrumb">
-                                    <li class="breadcrumb-item"><a href="javscript:;">Home</a></li>
-                                    <li class="breadcrumb-item active">생활치료센터 오픈API 통계</li>
-                                </ol>
-                            </nav>
-                        </div>
-                    </div>
-                    <div class="row">
-                        <div class="col-12">
-                            <div class="card">
-                                <form action="?" method="get" id="searchForm">
-                                    <div class="card-body">
-                                        <table class="table mobile-table">
-                                            <colgroup>
-                                                <col style="width:10%">
-                                                <col style="width:40%">
-                                                <col style="width:10%">
-                                                <col style="width:40%">
-                                            </colgroup>
-                                            <tr>
-                                                <th>지역</th>
-                                                <td>
-                                                    <select class="custom-select form-control" name="locationCode">
-                                                        <option value="">전체</option>
-                                                        <c:forEach var="i" items="${locationList}">
-                                                            <option value="${i.locationCode}" <c:if test="${i.locationCode eq locationCode}"> selected="selected"</c:if>><c:out value="${i.locationName}"/></option>
-                                                        </c:forEach>
-                                                    </select>
-                                                </td>
-                                                <th>생활치료센터명</th>
-                                                <td>
-                                                    <input type="text" class="form-control" name="centerName" placeholder="생활치료센터명" value="<c:out value="${centerName}" />">
-                                                </td>
-                                            </tr>
-                                            <tr>
-                                                <th>등록일</th>
-                                                <td>
-                                                    <div class="row">
-                                                        <div class="col-lg-5 col-sm-5">
-                                                            <div class="form-group calendar-bar mb-xl-0">
-                                                                <input class="form-control" type="text" name="startDate" placeholder="검색 시작일자" autocomplete="off">
-                                                                <i class="align-middle mr-2 fas fa-fw fa-calendar-alt"></i>
-                                                            </div>
-                                                        </div>
-                                                        <div class="col-lg-2 col-sm-2 text-center">
-                                                            ~
-                                                        </div>
-                                                        <div class="col-lg-5 col-sm-5">
-                                                            <div class="form-group calendar-bar mb-xl-0">
-                                                                <input class="form-control" type="text" name="endDate" placeholder="검색 종료일자" autocomplete="off">
-                                                                <i class="align-middle mr-2 fas fa-fw fa-calendar-alt"></i>
-                                                            </div>
-                                                        </div>
-                                                    </div>
-                                                </td>
-                                                <td colspan="2">
-                                                    <button class="btn btn-primary">검색</button>
-                                                </td>
-                                            </tr>
-                                        </table>
-                                    </div>
-                                </form>
-                            </div>
-                        </div>
-                    </div>
-                    <div class="row">
-                        <div class="col-12">
-                            <div class="card">
-                                <div class="card-body">
-                                    <div class="row mb-3">
-                                        <div class="col-6">
-                                            전체 :
-                                            <fmt:formatNumber value="${total}" pattern="#,###" />
-                                        </div>
-                                        <div class="col-6 text-right">
-                                            <button class="btn btn-success" data-toggle="modal" data-target="#excelDownMemo">Excel 다운로드</button>
-                                        </div>
-                                    </div>
-                                    
-                                    
-                                    
-                                </div>
-                            </div>
-                        </div>
-                    </div>
-                    <!-- 환자관리 END -->
-                </div>
-            </main>
-
-            <jsp:include page="${data._INCLUDE}/footer.jsp"></jsp:include>
-        </div>
-    </div>
-</body>
-</html>