이호영 이호영 2024-07-04
[사용자] 맞춤제작 > 내보관함 ==> 검색기간 기본값 제공
@8aa85c5cc7baa645687054ef21aff759a22d32fb
src/main/java/itn/com/cmm/util/DateUtil.java
--- src/main/java/itn/com/cmm/util/DateUtil.java
+++ src/main/java/itn/com/cmm/util/DateUtil.java
@@ -6,6 +6,7 @@
 import java.time.LocalDateTime;
 import java.time.Month;
 import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
 import java.util.Date;
 
 /**
@@ -23,7 +24,9 @@
  * 
  */
 public final class DateUtil {
-	
+
+    // 날짜를 포맷하는 포맷터 정의
+    private static final DateTimeFormatter SLUSH_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd");
 
     /** 
      * @methodName	: getTodayYearAndMonthAndFirstDay 
@@ -108,5 +111,70 @@
     }
 
     
-    
+    // 현재 날짜를 기본 포맷으로 반환
+    public static String getCurrentDate() {
+        return getCurrentDate(SLUSH_FORMATTER);
+    }
+
+    // 현재 날짜를 지정된 포맷으로 반환
+    public static String getCurrentDate(DateTimeFormatter formatter) {
+        LocalDate today = LocalDate.now();
+        return today.format(formatter);
+    }
+
+    // 현재 날짜에서 특정 일수 전 날짜를 기본 포맷으로 반환
+    public static String getDateDaysAgo(int days) {
+        return getDateDaysAgo(days, SLUSH_FORMATTER);
+    }
+
+    // 현재 날짜에서 특정 일수 전 날짜를 지정된 포맷으로 반환
+    public static String getDateDaysAgo(int days, DateTimeFormatter formatter) {
+        LocalDate today = LocalDate.now();
+        LocalDate daysAgo = today.minusDays(days);
+        return daysAgo.format(formatter);
+    }
+
+	
+	public static boolean dateChk365AndValueChk(String searchStartDate, String searchEndDate) {
+		
+
+		boolean isValid = true;
+
+		// 날짜 형식 지정
+		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
+
+		//날짜 검증
+		LocalDate startDate = null;
+		LocalDate endDate = null;
+
+		// 검색 시작일자와 종료일자가 있는지 체크
+		if (searchStartDate == null || searchStartDate.isEmpty() || searchEndDate == null || searchEndDate.isEmpty()) {
+			isValid = false;
+		}
+
+		// 날짜 형식으로 변환
+		if (isValid) {
+			try {
+				startDate = LocalDate.parse(searchStartDate, formatter);
+				endDate = LocalDate.parse(searchEndDate, formatter);
+			} catch (Exception e) {
+				isValid = false;
+			}
+		}
+
+		// 시작일자가 종료일자보다 이후인지 확인
+		if (isValid && startDate.isAfter(endDate)) {
+			isValid = false;
+		}
+
+		// 총 기간이 365일을 넘는지 확인
+		if (isValid) {
+			long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
+			if (daysBetween > 365) {
+				isValid = false;
+			}
+		}
+		
+		return isValid;
+	}
 }
src/main/java/itn/let/mjo/msgCustom/web/MjonMsgCustomWebController.java
--- src/main/java/itn/let/mjo/msgCustom/web/MjonMsgCustomWebController.java
+++ src/main/java/itn/let/mjo/msgCustom/web/MjonMsgCustomWebController.java
@@ -3,6 +3,9 @@
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -32,6 +35,7 @@
 import itn.com.cmm.service.EgovFileMngService;
 import itn.com.cmm.service.EgovFileMngUtil;
 import itn.com.cmm.service.FileVO;
+import itn.com.cmm.util.DateUtil;
 import itn.com.utl.fcc.service.EgovStringUtil;
 import itn.let.lett.service.HashConfVO;
 import itn.let.lett.service.LetterService;
@@ -136,6 +140,15 @@
     	model.addAttribute("customEditPrice", customEditPrice);
     	model.addAttribute("customEdit3Price", customEdit3Price);
     	model.addAttribute("customTextPrice", customTextPrice);
+    	
+    	
+    	// 내 보관함 - 기본 날짜 검색 셋팅
+    	// 오늘 날짜에서 365일 날짜 가져와서 
+    	// 검색날짜에 입력
+    	model.addAttribute("myStartDate", DateUtil.getDateDaysAgo(365));
+    	model.addAttribute("myEndDate", DateUtil.getCurrentDate());
+    	
+    	
 		
 		return "/web/custom/MsgCustomView";
 	}
@@ -212,6 +225,19 @@
 		// 문자 종류 정보가 없으면 단문문자로 셋팅
 		mjonMsgCustomVO.setLetterType("C");
 		
+		
+		// 검색 데이터가 없거나
+		// 시작일자가 종료일자보다 이후이거나
+		// 총 기간이 365일이 넘으면 현재일부터 365일 전 날짜를 넣어서 검색
+		if(!DateUtil.dateChk365AndValueChk(mjonMsgCustomVO.getSearchStartDate(),mjonMsgCustomVO.getSearchEndDate() )) {
+
+			mjonMsgCustomVO.setSearchStartDate(DateUtil.getDateDaysAgo(365));
+			mjonMsgCustomVO.setSearchEndDate(DateUtil.getCurrentDate());
+			
+		};
+		
+
+		
 		// 내 보관함 이미지 목록 조회
 		mjonMsgCustomVO.setUserId(userId);
 		List<MjonMsgCustomVO> resultCustomImgList = mjonMsgCustomService.selectMjonMsgMyCustomImgList(mjonMsgCustomVO);
@@ -223,7 +249,8 @@
 		
 		return "/web/custom/MsgMyCustomListAjax";
 	}
-	
+
+
 	/** 사용자 맞춤제작 내보관함 삭제 - LETTNFILEDETAIL 테이블 FILE_DELETE_YN 컬럼 업데이트*/
 	@RequestMapping(value= {"/web/mjon/custom/deleteMsgMyCustomAjax.do"})
 	public ModelAndView deleteMsgMyCustomAjax(@RequestParam("chk") String[] chk, @ModelAttribute("searchVO") MjonMsgCustomVO mjonMsgCustomVO
src/main/webapp/WEB-INF/jsp/web/custom/MsgCustomView.jsp
--- src/main/webapp/WEB-INF/jsp/web/custom/MsgCustomView.jsp
+++ src/main/webapp/WEB-INF/jsp/web/custom/MsgCustomView.jsp
@@ -128,11 +128,54 @@
 
 //맞춤제작 내보관함 리스트 
 function myCustomListAjax(pageNo){
+	
+	if(!fn_dataValueChk()){
+		return;
+	};
+	
 	document.myCustomForm.pageIndex.value = pageNo;
 	var sendData= $(document.myCustomForm).serializeArray();
 	$("#myCustomLoad").load("/web/mjon/custom/selectMsgMyCustomListAjax.do", sendData ,function(response, status, xhr){
 		photoLayerView();
 	});
+}
+
+function fn_dataValueChk(){
+    // 시작일자와 종료일자를 가져오기
+    var startDate = document.getElementById("startDate").value;
+    var endDate = document.getElementById("endDate").value;
+    
+    // 날짜가 입력되었는지 확인
+    if (!startDate || !endDate) {
+        alert("검색 시작일자와 종료일자를 입력해주세요.");
+        return false;
+    }
+    
+    // 날짜 형식으로 변환
+    var start = new Date(startDate);
+    var end = new Date(endDate);
+    
+    // 날짜 유효성 체크
+    if (isNaN(start.getTime()) || isNaN(end.getTime())) {
+        alert("유효한 날짜 형식을 입력해주세요.");
+        return false;
+    }
+    
+    // 시작일자가 종료일자보다 이후인지 확인
+    if (start > end) {
+        alert("검색 시작일자는 종료일자보다 이전이어야 합니다.");
+        return false;
+    }
+    
+    // 총 기간이 365일을 넘는지 확인
+    var diffTime = Math.abs(end - start);
+    var diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); 
+    if (diffDays > 365) {
+        alert("총 검색 기간은 1년을 넘을 수 없습니다.");
+        return false;
+    }
+    
+    return true;
 }
 
 //맞춤제작 내보관함 정렬 조회
@@ -430,9 +473,9 @@
 						<div class="btn_left">
 							<span>· 기간</span>
 							<div class="calendar_wrap">
-								<input type="text" class="startDate inp calendar" title="검색 시작일" id="startDate" name="searchStartDate" value="" data-datecontrol="true">
+								<input type="text" class="startDate inp calendar" title="검색 시작일" id="startDate" name="searchStartDate" value="${myStartDate}" data-datecontrol="true">
 								<span class="dateEtc">~</span>
-								<input type="text" class="endDate inp calendar" title="검색 종료일" id="endDate" name="searchEndDate" value="" data-datecontrol="true">
+								<input type="text" class="endDate inp calendar" title="검색 종료일" id="endDate" name="searchEndDate" value="${myEndDate}" data-datecontrol="true">
 							</div>
 							<div class="search">
 <!-- 								<label for="searchWord" class="label"></label> -->
src/main/webapp/WEB-INF/jsp/web/custom/MsgMyCustomListAjax.jsp
--- src/main/webapp/WEB-INF/jsp/web/custom/MsgMyCustomListAjax.jsp
+++ src/main/webapp/WEB-INF/jsp/web/custom/MsgMyCustomListAjax.jsp
@@ -7,6 +7,10 @@
 <head>
 <script type="text/javascript">
 $(document).ready(function (){
+	
+	$('#startDate').val('${mjonMsgCustomVO.searchStartDate}');
+	$('#endDate').val('${mjonMsgCustomVO.searchEndDate}');
+	
 	var checkYn = true;
 	$("#allCheck").click(function(){
 		if(checkYn){
Add a comment
List