From 8aa85c5cc7baa645687054ef21aff759a22d32fb Mon Sep 17 00:00:00 2001 From: hylee Date: Thu, 4 Jul 2024 16:38:30 +0900 Subject: [PATCH] =?UTF-8?q?[=EC=82=AC=EC=9A=A9=EC=9E=90]=20=EB=A7=9E?= =?UTF-8?q?=EC=B6=A4=EC=A0=9C=EC=9E=91=20>=20=EB=82=B4=EB=B3=B4=EA=B4=80?= =?UTF-8?q?=ED=95=A8=20=3D=3D>=20=EA=B2=80=EC=83=89=EA=B8=B0=EA=B0=84=20?= =?UTF-8?q?=EA=B8=B0=EB=B3=B8=EA=B0=92=20=EC=A0=9C=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/itn/com/cmm/util/DateUtil.java | 72 ++++++++++++++++++- .../web/MjonMsgCustomWebController.java | 29 +++++++- .../WEB-INF/jsp/web/custom/MsgCustomView.jsp | 47 +++++++++++- .../jsp/web/custom/MsgMyCustomListAjax.jsp | 4 ++ 4 files changed, 147 insertions(+), 5 deletions(-) diff --git a/src/main/java/itn/com/cmm/util/DateUtil.java b/src/main/java/itn/com/cmm/util/DateUtil.java index 81899a46..895b5f79 100644 --- a/src/main/java/itn/com/cmm/util/DateUtil.java +++ b/src/main/java/itn/com/cmm/util/DateUtil.java @@ -6,6 +6,7 @@ import java.time.LocalDate; 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 @@ import java.util.Date; * */ public final class DateUtil { - + + // 날짜를 포맷하는 포맷터 정의 + private static final DateTimeFormatter SLUSH_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd"); /** * @methodName : getTodayYearAndMonthAndFirstDay @@ -108,5 +111,70 @@ public final class DateUtil { } - + // 현재 날짜를 기본 포맷으로 반환 + 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; + } } diff --git a/src/main/java/itn/let/mjo/msgCustom/web/MjonMsgCustomWebController.java b/src/main/java/itn/let/mjo/msgCustom/web/MjonMsgCustomWebController.java index 66032d7a..b692ceb9 100644 --- a/src/main/java/itn/let/mjo/msgCustom/web/MjonMsgCustomWebController.java +++ b/src/main/java/itn/let/mjo/msgCustom/web/MjonMsgCustomWebController.java @@ -3,6 +3,9 @@ package itn.let.mjo.msgCustom.web; 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.EgovCmmUseService; 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 @@ public class MjonMsgCustomWebController { 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 @@ public class MjonMsgCustomWebController { // 문자 종류 정보가 없으면 단문문자로 셋팅 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 resultCustomImgList = mjonMsgCustomService.selectMjonMsgMyCustomImgList(mjonMsgCustomVO); @@ -223,7 +249,8 @@ public class MjonMsgCustomWebController { 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 diff --git a/src/main/webapp/WEB-INF/jsp/web/custom/MsgCustomView.jsp b/src/main/webapp/WEB-INF/jsp/web/custom/MsgCustomView.jsp index be0ea813..48eb93fe 100644 --- a/src/main/webapp/WEB-INF/jsp/web/custom/MsgCustomView.jsp +++ b/src/main/webapp/WEB-INF/jsp/web/custom/MsgCustomView.jsp @@ -128,6 +128,11 @@ function customSampleListAjax(pageNo){ //맞춤제작 내보관함 리스트 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){ @@ -135,6 +140,44 @@ function myCustomListAjax(pageNo){ }); } +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; +} + //맞춤제작 내보관함 정렬 조회 function fnMyCustomSearchListOrd(){ @@ -430,9 +473,9 @@ function popScrCloseSetting(){
· 기간
- + ~ - +