Browse Source

config.properties 추가

huiwon.seo 4 years ago
parent
commit
f7e301523d

+ 6 - 0
pom.xml

@@ -96,6 +96,12 @@
 	        <artifactId>json</artifactId>
 	        <version>20180813</version>
 	    </dependency>
+        
+        <dependency>
+          <groupId>org.springframework.mobile</groupId>
+          <artifactId>spring-mobile-device</artifactId>
+          <version>1.1.0.RELEASE</version>
+        </dependency>
 	</dependencies>
 
 	<build>

+ 3 - 0
src/main/java/com/lemon/lifecenter/LifeCenterApplication.java

@@ -2,6 +2,9 @@ package com.lemon.lifecenter;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
 
 @SpringBootApplication
 public class LifeCenterApplication {

+ 29 - 0
src/main/java/com/lemon/lifecenter/common/LifeCenterConfigVO.java

@@ -0,0 +1,29 @@
+package com.lemon.lifecenter.common;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.stereotype.Component;
+
+@Component
+@Configuration
+@PropertySource("classpath:config.properties")
+public class LifeCenterConfigVO {
+    public final static String AccessAdmin = "/admin";
+    public static byte[] IV = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+    
+    @Value( "${config.aesKey}" )
+    public String aesKey;
+    
+    // 페이지 그룹 갯수
+    @Value( "${config.pageGroupSize}" )
+    public int pageGroupSize;
+    
+    // 페이지당 보여줄 데이터 갯수
+    @Value( "${config.pageDataSize}" )
+    public int pageDataSize;
+    
+    // 페이지 prefix   ex) ?page
+    @Value( "${config.pagePrefix}" )
+    public String pagePrefix;
+}

+ 25 - 12
src/main/java/com/lemon/lifecenter/common/LifeCenterInterCeptor.java

@@ -5,31 +5,44 @@ import javax.servlet.http.HttpServletResponse;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mobile.device.Device;
+import org.springframework.mobile.device.DeviceUtils;
+import org.springframework.stereotype.Component;
 import org.springframework.web.servlet.ModelAndView;
 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
 
+@Component
 public class LifeCenterInterCeptor extends HandlerInterceptorAdapter {
+    @Autowired
+    private LifeCenterConfigVO config;
+    
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
-    // 컨트롤러의 메서드에 매핑된 특정 URI를 호출했을 때 컨트롤러에 접근하기 전에 실행되는 메서드입니다.
     @Override
-    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
-            throws Exception {
-        // TODO Auto-generated method stub
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
+        System.out.println("--------------------- InterCeptor Start --------------------- ");
 
-        System.out.println("Request URI : " + request.getRequestURI());
-        logger.info("info");
-        logger.debug("debug");
+        String url = request.getRequestURI().toString();
+        String port = String.valueOf(request.getLocalPort());
+        Device device = DeviceUtils.getCurrentDevice(request);
 
-        return super.preHandle(request, response, handler);
+        logger.info("IP : " + LifeCenterFunction.getRemoteAddr(request) + " URL : " + url + " Port : " + port
+                + " Device : " + device);
+        
+        return true;
     }
 
-    // 컨트롤러를 경유한 다음, 화면(View)으로 결과를 전달하기 전에 실행되는 메서드입니다.
     @Override
     public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
-            ModelAndView modelAndView) throws Exception {
-        // TODO Auto-generated method stub
-        super.postHandle(request, response, handler, modelAndView);
+            ModelAndView modelAndView) {
+        logger.info("Method Executed Time : postHandle");
     }
 
+    @Override
+    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
+            Exception ex) {
+        logger.info("Method Completed Time : afterCompletion");
+        System.out.println("--------------------- InterCeptor End ---------------------");
+    }
 }

+ 247 - 0
src/main/java/com/lemon/lifecenter/common/LifeCenterPaging.java

@@ -0,0 +1,247 @@
+package com.lemon.lifecenter.common;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class LifeCenterPaging {
+    @Autowired
+    private LifeCenterConfigVO config;
+    
+    private int pageSize; // 게시 글 수
+    private int firstPageNo; // 첫 번째 페이지 번호
+    private int prevPageNo; // 이전 페이지 번호
+    private int startPageNo; // 시작 페이지 (페이징 네비 기준)
+    private int pageNo; // 페이지 번호
+    private int endPageNo; // 끝 페이지 (페이징 네비 기준)
+    private int nextPageNo; // 다음 페이지 번호
+    private int finalPageNo; // 마지막 페이지 번호
+    private int totalCount; // 게시 글 전체 수
+    private int groupCount; // 출력되는 페이징 그룹 숫자
+    private String url;
+    private String preFix;
+    private String another;
+
+    public LifeCenterPaging() {}
+    
+    public LifeCenterPaging( int total, int page, String param ) {
+        
+        System.out.println( "3s page : " + page );
+        
+        
+        this.setPreFix( config.pagePrefix );
+        this.setPageSize( config.pageDataSize );
+        this.setGroupCount( config.pageGroupSize );
+        this.setTotalCount( total );
+        this.setPageNo( page );
+        this.setUrl( param );
+        
+        this.makePaging();
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public String getPreFix() {
+        return preFix;
+    }
+
+    public void setPreFix(String preFix) {
+        this.preFix = preFix;
+    }
+
+    public String getAnother() {
+        return another;
+    }
+
+    public void setAnother(String another) {
+        this.another = another;
+    }
+
+    /**
+     * @return the pageSize
+     */
+    public int getPageSize() {
+        return pageSize;
+    }
+
+    /**
+     * @param pageSize the pageSize to set
+     */
+    public void setPageSize(int pageSize) {
+        this.pageSize = pageSize;
+    }
+
+    /**
+     * @return the firstPageNo
+     */
+    public int getFirstPageNo() {
+        return firstPageNo;
+    }
+
+    /**
+     * @param firstPageNo the firstPageNo to set
+     */
+    public void setFirstPageNo(int firstPageNo) {
+        this.firstPageNo = firstPageNo;
+    }
+
+    /**
+     * @return the prevPageNo
+     */
+    public int getPrevPageNo() {
+        return prevPageNo;
+    }
+
+    /**
+     * @param prevPageNo the prevPageNo to set
+     */
+    public void setPrevPageNo(int prevPageNo) {
+        this.prevPageNo = prevPageNo;
+    }
+
+    /**
+     * @return the startPageNo
+     */
+    public int getStartPageNo() {
+        return startPageNo;
+    }
+
+    /**
+     * @param startPageNo the startPageNo to set
+     */
+    public void setStartPageNo(int startPageNo) {
+        this.startPageNo = startPageNo;
+    }
+
+    /**
+     * @return the pageNo
+     */
+    public int getPageNo() {
+        return pageNo;
+    }
+
+    /**
+     * @param pageNo the pageNo to set
+     */
+    public void setPageNo(int pageNo) {
+        this.pageNo = pageNo;
+    }
+
+    /**
+     * @return the endPageNo
+     */
+    public int getEndPageNo() {
+        return endPageNo;
+    }
+
+    /**
+     * @param endPageNo the endPageNo to set
+     */
+    public void setEndPageNo(int endPageNo) {
+        this.endPageNo = endPageNo;
+    }
+
+    /**
+     * @return the nextPageNo
+     */
+    public int getNextPageNo() {
+        return nextPageNo;
+    }
+
+    /**
+     * @param nextPageNo the nextPageNo to set
+     */
+    public void setNextPageNo(int nextPageNo) {
+        this.nextPageNo = nextPageNo;
+    }
+
+    /**
+     * @return the finalPageNo
+     */
+    public int getFinalPageNo() {
+        return finalPageNo;
+    }
+
+    /**
+     * @param finalPageNo the finalPageNo to set
+     */
+    public void setFinalPageNo(int finalPageNo) {
+        this.finalPageNo = finalPageNo;
+    }
+
+    /**
+     * @return the totalCount
+     */
+    public int getTotalCount() {
+        return totalCount;
+    }
+
+    /**
+     * @param totalCount the totalCount to set
+     */
+    public void setTotalCount(int totalCount) {
+        this.totalCount = totalCount;
+        this.makePaging();
+    }
+
+    public int getGroupCount() {
+        return groupCount;
+    }
+
+    public void setGroupCount(int groupCount) {
+        this.groupCount = groupCount;
+    }
+
+    /**
+     * 페이징 생성
+     */
+    private void makePaging() {
+        if (this.totalCount == 0)
+            return; // 게시 글 전체 수가 없는 경우
+        if (this.pageNo == 0)
+            this.setPageNo(1); // 기본 값 설정
+        if (this.pageSize == 0)
+            this.setPageSize(10); // 기본 값 설정
+        if (this.groupCount == 0)
+            this.setGroupCount(10);
+
+        int finalPage = (int) Math.ceil(Double.valueOf(this.totalCount) / Double.valueOf(this.pageSize)); // 마지막 페이지
+        if (this.pageNo > finalPage)
+            this.setPageNo(finalPage); // 기본 값 설정
+        if (this.pageNo < 0 || this.pageNo > finalPage)
+            this.pageNo = 1; // 현재 페이지 유효성 체크
+
+        boolean isNowFirst = pageNo == 1 ? true : false; // 시작 페이지 (전체)
+        boolean isNowFinal = pageNo == finalPage ? true : false; // 마지막 페이지 (전체)
+
+        int startPage = ((pageNo - 1) / this.groupCount) * this.groupCount + 1; // 시작 페이지 (페이징 네비 기준)
+        int endPage = startPage + this.groupCount - 1; // 끝 페이지 (페이징 네비 기준)
+
+        if (endPage > finalPage) { // [마지막 페이지 (페이징 네비 기준) > 마지막 페이지] 보다 큰 경우
+            endPage = finalPage;
+        }
+
+        this.setFirstPageNo(1); // 첫 번째 페이지 번호
+
+        if (isNowFirst) {
+            this.setPrevPageNo(1); // 이전 페이지 번호
+        } else {
+            this.setPrevPageNo(((pageNo - 1) < 1 ? 1 : (pageNo - 1))); // 이전 페이지 번호
+        }
+
+        this.setStartPageNo(startPage); // 시작 페이지 (페이징 네비 기준)
+        this.setEndPageNo(endPage); // 끝 페이지 (페이징 네비 기준)
+
+        if (isNowFinal) {
+            this.setNextPageNo(finalPage); // 다음 페이지 번호
+        } else {
+            this.setNextPageNo(((pageNo + 1) > finalPage ? finalPage : (pageNo + 1))); // 다음 페이지 번호
+        }
+
+        this.setFinalPageNo(finalPage); // 마지막 페이지 번호
+    }
+}

+ 23 - 0
src/main/java/com/lemon/lifecenter/common/WebConfigurations.java

@@ -1,5 +1,6 @@
 package com.lemon.lifecenter.common;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
@@ -7,8 +8,30 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
 @Configuration
 public class WebConfigurations implements WebMvcConfigurer {
+    @Autowired
+    LifeCenterInterCeptor lifeCenterInterCeptor;
+    
     @Override
     public void addResourceHandlers(ResourceHandlerRegistry registry) {
         registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
     }
+    
+    /*
+     * Interceptor 설정
+     * */
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+        registry.addInterceptor(lifeCenterInterCeptor).addPathPatterns("/**/*");
+    }
+    
+//    @Autowired
+//    @Qualifier(value = "httpInterceptor")
+//    private HandlerInterceptor interceptor;
+//
+//    @Override
+//    public void addInterceptors(InterceptorRegistry registry) {
+//      registry.addInterceptor(interceptor)
+//          .addPathPatterns("/")
+//          .excludePathPatterns("/user/**");
+//    }
 }

+ 17 - 4
src/main/java/com/lemon/lifecenter/controller/PatientController.java

@@ -11,18 +11,22 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.servlet.ModelAndView;
 
+import com.lemon.lifecenter.common.LifeCenterConfigVO;
 import com.lemon.lifecenter.common.LifeCenterController;
+import com.lemon.lifecenter.common.LifeCenterPaging;
 import com.lemon.lifecenter.dto.PatientDTO;
 import com.lemon.lifecenter.service.PatientService;
 
 @Controller
 @RequestMapping("/patient")
 public class PatientController extends LifeCenterController {
-
-    private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
     @Autowired
     private PatientService patientService;
+    
+    @Autowired
+    private LifeCenterConfigVO config;
+    
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
     @RequestMapping("/list")
 //    @ModelAttribute("dto") final ASiboDTO dto,
@@ -32,13 +36,18 @@ public class PatientController extends LifeCenterController {
             @RequestParam(value="inputState", required=false, defaultValue="ALL") String inputState,
             @RequestParam(value="patientName", required=false, defaultValue="") String patientName,
             @RequestParam(value="startDate", required=false, defaultValue="") String startDate,
-            @RequestParam(value="endDate", required=false, defaultValue="") String endDate) {
+            @RequestParam(value="endDate", required=false, defaultValue="") String endDate,
+            @RequestParam(value="page", required=false, defaultValue="1") int page ) {
+        
+        System.err.println( "page : " + page );
         
         PatientDTO dto = new PatientDTO();
         dto.setPatientName(patientName);
         dto.setStat(inputState);
         dto.setStartDate(startDate);
         dto.setEndDate(endDate);
+        dto.setLimit( ( Integer.valueOf( page ) - 1 ) * config.pageDataSize );
+        dto.setLimitMax( config.pageDataSize );
         
         int total = patientService.selectPatientCount(dto);
         List<PatientDTO> result = new ArrayList<PatientDTO>();
@@ -48,10 +57,14 @@ public class PatientController extends LifeCenterController {
         }
         
         ModelAndView mv = setMV("patient/list");
+        
+        String param = "patientName=" + patientName + "&inputState=" + inputState + "&startDate=" + startDate + "&endDate=" + endDate;
+        
         mv.addObject("inputState", inputState);
         mv.addObject("patientName", patientName);
         mv.addObject("total", total);
         mv.addObject("item", result);
+        
         return mv;
     }
 

+ 15 - 0
src/main/java/com/lemon/lifecenter/dto/PatientDTO.java

@@ -16,7 +16,22 @@ public class PatientDTO {
     private String stat;
     private String startDate;
     private String endDate;
+    private int limit;
+    private int limitMax;
     
+    
+    public int getLimit() {
+        return limit;
+    }
+    public void setLimit(int limit) {
+        this.limit = limit;
+    }
+    public int getLimitMax() {
+        return limitMax;
+    }
+    public void setLimitMax(int limitMax) {
+        this.limitMax = limitMax;
+    }
     public String getNum() {
         return num;
     }

+ 0 - 5
src/main/resources/application.properties

@@ -19,8 +19,3 @@ mybatis.mapper-locations=mybatis/mapper/**/*.xml
 
 logging.level.root=debug
 spring.profiles.active=local
-
-
-#ex2) 패키지별로 로깅 레벨 지정 - 다음 방법으로 상위 패키지의 디폴트 레벨을 설정하고, 하위 패키지들에 대한 각각의 로깅 레벨을 별도로 설정할 수 있다.
-#logging.level.com.god.bo.test=info 
-#logging.level.com.god.bo.test.controller=debug

+ 7 - 0
src/main/resources/config.properties

@@ -0,0 +1,7 @@
+#################################
+## LifeCenterConfigVO
+#################################
+config.aesKey        = 1q2w3e4r5t6y7u8i9o0p!@#$%^&*()
+config.pageGroupSize = 5
+config.pageDataSize  = 10
+config.pagePrefix    = page

+ 39 - 39
src/main/resources/mybatis/mapper/patient/patient.xml

@@ -2,44 +2,44 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 
 <mapper namespace="com.lemon.lifecenter.mapper.PatientMapper">
-
-  <select id="selectPatientCount" parameterType="PatientDTO" resultType="int">
-      <![CDATA[
-        SELECT count(*) AS total
-          FROM PATIENT_CARE
-         WHERE 1 = 1
-    ]]>
-    <if test='stat != "ALL"'>
-        <![CDATA[
-            AND STATE = #{stat}
-        ]]>
-    </if>
-    <if test='patientName != null and patientName != ""'>
+    <select id="selectPatientCount" parameterType="PatientDTO" resultType="int">
         <![CDATA[
-            AND PATIENT_NAME = #{patientName}
+            SELECT count(*) AS total
+              FROM PATIENT_CARE
+             WHERE 1 = 1
         ]]>
-    </if>
-    <if test='startDate != null and startDate != "" and endDate != null and endDate != ""'>
+        <if test='stat != "ALL"'>
+            <![CDATA[
+               AND STATE = #{stat}
+            ]]>
+        </if>
+        <if test='patientName != null and patientName != ""'>
+            <![CDATA[
+               AND PATIENT_NAME = #{patientName}
+            ]]>
+        </if>
+        <if test='startDate != null and startDate != "" and endDate != null and endDate != ""'>
+            <![CDATA[
+               AND DATE_FORMAT(FINAL_CLINIC_DATE, '%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
+            ]]>
+        </if>
+    </select>
+    
+    <select id="selectPatientList" parameterType="PatientDTO" resultType="PatientDTO">
         <![CDATA[
-            AND DATE_FORMAT(FINAL_CLINIC_DATE, '%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
+            SELECT ROWNUM                                                             AS num,
+                   PATIENT_NAME                                                       AS patientName,
+                   GENDER                                                             AS gender,
+                   (SELECT TRUNC((SYSDATE-TO_DATE(19 || JUMIN, 'YYYYMMDD'))/365) + 1) AS age,
+                   ward_number                                                        AS wardNumber,
+                   room_number                                                        AS roomNumber,
+                   DATE_FORMAT(FINAL_CLINIC_DATE, '%Y-%m-%d %H:%i')                   AS finamClinicDate,
+                   DATE_FORMAT(HOSPITALIZATION_DATE, '%Y-%m-%d %H:%i')                AS hospitalizationDate,
+                   DATE_FORMAT(DISISOLATION_DATE, '%Y-%m-%d %H:%i')                   AS disisolationDate,
+                   STATE                                                              AS state
+              FROM PATIENT_CARE
+             WHERE 1 = 1
         ]]>
-    </if>
-  </select>
-  <select id="selectPatientList" parameterType="PatientDTO" resultType="PatientDTO">
-    <![CDATA[
-        SELECT ROWNUM                                                             AS num,
-               PATIENT_NAME                                                       AS patientName,
-               GENDER                                                             AS gender,
-               (SELECT TRUNC((SYSDATE-TO_DATE(19 || JUMIN, 'YYYYMMDD'))/365) + 1) AS age,
-               ward_number                                                        AS wardNumber,
-               room_number                                                        AS roomNumber,
-               DATE_FORMAT(FINAL_CLINIC_DATE, '%Y-%m-%d %H:%i')                   AS finamClinicDate,
-               DATE_FORMAT(HOSPITALIZATION_DATE, '%Y-%m-%d %H:%i')                AS hospitalizationDate,
-               DATE_FORMAT(DISISOLATION_DATE, '%Y-%m-%d %H:%i')                   AS disisolationDate,
-               STATE                                                              AS state
-          FROM PATIENT_CARE
-         WHERE 1 = 1
-    ]]>
     <if test='stat != "ALL"'>
         <![CDATA[
             AND STATE = #{stat}
@@ -55,9 +55,9 @@
             AND DATE_FORMAT(FINAL_CLINIC_DATE, '%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
         ]]>
     </if>
-    <![CDATA[
-         ORDER BY HOSPITALIZATION_DATE DESC
-         LIMIT 0, 10
-    ]]>
-  </select>
+        <![CDATA[
+             ORDER BY HOSPITALIZATION_DATE DESC
+             LIMIT ${limit}, ${limitMax}
+        ]]>
+    </select>
 </mapper>

+ 21 - 0
src/main/webapp/WEB-INF/jsp/include/paging.jsp

@@ -0,0 +1,21 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+<c:if test="${param.total > 0 && param.endPageNo > 1}">
+    <div class="p_wrap">
+        <a href="?${param.url}&${param.preFix}=${param.firstPageNo}" class="p_btn" title="${param.firstPageNo}">처음</a>
+        <a href="?${param.url}&${param.preFix}=${param.prevPageNo}" class="p_btn" title="${param.prevPageNo}">이전</a>
+        <c:forEach var="i" begin="${param.startPageNo}" end="${param.endPageNo}" step="1">
+            <c:choose>
+                <c:when test="${i eq param.pageNo}">
+                  <a href="?${param.url}&${param.preFix}=${i}" class="p_btn on" title="${i}">${i}</a>
+                </c:when>
+                <c:otherwise>
+                  <a href="?${param.url}&${param.preFix}=${i}" class="p_btn" title="${i}">${i}</a>
+                </c:otherwise>
+            </c:choose>
+        </c:forEach>
+        <a href="?${param.url}&${param.preFix}=${param.nextPageNo}" class="p_btn">다음</a>
+        <a href="?${param.url}&${param.preFix}=${param.finalPageNo}" class="p_btn">마지막</a>
+    </div>
+</c:if>

+ 4 - 8
src/main/webapp/WEB-INF/jsp/patient/list.jsp

@@ -309,8 +309,7 @@
                                         </table>
                                     </div>
                                     <div class="row mt-5">
-                                         <div
-                                            class="col-12 col-lg-6 mb-2">
+                                         <div class="col-12 col-lg-6 mb-2">
                                             <!-- <select
                                                 class="custom-select form-control col-md-2"
                                                 id="inputState"
@@ -321,12 +320,9 @@
                                                 <option value="warning">퇴소</option>
                                             </select> -->
                                         </div>
-                                        <div
-                                            class="col-12 col-lg-6 mb-2">
-                                            <nav
-                                                aria-label="Page navigation">
-                                                <ul
-                                                    class="pagination pagination-mb">
+                                        <div class="col-12 col-lg-6 mb-2">
+                                            <nav aria-label="Page navigation">
+                                                <ul class="pagination pagination-mb">
                                                     <li
                                                         class="page-item"><a
                                                         class="page-link"