date 모듈 수정

This commit is contained in:
hylee 2024-07-05 18:33:02 +09:00
parent 339e233c0b
commit 7d2ce518aa
7 changed files with 77 additions and 80 deletions

View File

@ -143,47 +143,43 @@ public final class DateUtils {
* @param dateVal
* @return
*/
public static boolean dateChkAndValueChk(String searchStartDate, String searchEndDate, int dateVal) {
public static boolean dateChkAndValueChk(String searchStartDate, String searchEndDate, int months) {
boolean isValid = true;
boolean isValid = true;
// 날짜 형식 지정
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
// 날짜 검증
LocalDate startDate = null;
LocalDate endDate = null;
//날짜 검증
LocalDate startDate = null;
LocalDate endDate = null;
// 검색 시작일자와 종료일자가 있는지 체크
if (searchStartDate == null || searchStartDate.isEmpty() || searchEndDate == null || searchEndDate.isEmpty()) {
isValid = false;
}
// 검색 시작일자와 종료일자가 있는지 체크
if (searchStartDate == null || searchStartDate.isEmpty() || searchEndDate == null || searchEndDate.isEmpty()) {
isValid = false;
}
// 날짜 형식으로 변환
if (isValid) {
try {
startDate = LocalDate.parse(searchStartDate, SLUSH_FORMATTER);
endDate = LocalDate.parse(searchEndDate, SLUSH_FORMATTER);
} catch (Exception e) {
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;
}
// 시작일자가 종료일자보다 이후인지 확인
if (isValid && startDate.isAfter(endDate)) {
isValid = false;
}
// 기간이 지정한 개월 수를 넘는지 확인
if (isValid) {
long monthsBetween = ChronoUnit.MONTHS.between(startDate, endDate);
System.out.println("monthsBetween : "+ monthsBetween);
if (monthsBetween >= months) {
isValid = false;
}
}
// 기간이 365일을 넘는지 확인
if (isValid) {
long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
if (daysBetween > dateVal) {
isValid = false;
}
}
System.out.println("isValid : "+ isValid);
return isValid;
}
return isValid;
}
}

View File

@ -229,7 +229,7 @@ public class MjonMsgCustomWebController {
// 검색 데이터가 없거나
// 시작일자가 종료일자보다 이후이거나
// 기간이 365일이 넘으면 현재일부터 365일 날짜를 넣어서 검색
if(!DateUtils.dateChkAndValueChk(mjonMsgCustomVO.getSearchStartDate(),mjonMsgCustomVO.getSearchEndDate(), 365 )) {
if(!DateUtils.dateChkAndValueChk(mjonMsgCustomVO.getSearchStartDate(),mjonMsgCustomVO.getSearchEndDate(), 12 )) {
mjonMsgCustomVO.setSearchStartDate(DateUtils.getDateDaysAgo(365));
mjonMsgCustomVO.setSearchEndDate(DateUtils.getCurrentDate());

View File

@ -2108,7 +2108,11 @@ public class MjonPayController {
// mjonPayVO.setStartDate(mjonPayVO.getStartDate() == null ? DateUtil.getDateDaysAgo(365) : mjonPayVO.getStartDate());
// mjonPayVO.setEndDate(mjonPayVO.getEndDate() == null ? DateUtil.getCurrentDate() : mjonPayVO.getEndDate());
if(!DateUtils.dateChkAndValueChk(mjonPayVO.getSearchStartDate(),mjonPayVO.getSearchEndDate(), 365 )) {
System.out.println("???");
System.out.println("mjonPayVO.getStartDate() :: "+mjonPayVO.getStartDate());
System.out.println("mjonPayVO.getEndDate() :: "+mjonPayVO.getEndDate());
if(!DateUtils.dateChkAndValueChk(mjonPayVO.getStartDate(),mjonPayVO.getEndDate(), 12 )) {
System.out.println("???");
mjonPayVO.setStartDate(DateUtils.getDateDaysAgo(365));
mjonPayVO.setEndDate(DateUtils.getCurrentDate());
};
@ -2762,7 +2766,7 @@ public class MjonPayController {
// 검색 데이터가 없거나
// 시작일자가 종료일자보다 이후이거나
// 기간이 365일이 넘으면 현재일부터 365일 날짜를 넣어서 검색
if(!DateUtils.dateChkAndValueChk(mjonMsgVO.getStartDate(),mjonMsgVO.getEndDate(), 365 )) {
if(!DateUtils.dateChkAndValueChk(mjonMsgVO.getStartDate(),mjonMsgVO.getEndDate(), 12 )) {
mjonMsgVO.setStartDate(DateUtils.getDateDaysAgo(365));
mjonMsgVO.setEndDate(DateUtils.getCurrentDate());

View File

@ -129,7 +129,7 @@ function customSampleListAjax(pageNo){
//맞춤제작 내보관함 리스트
function myCustomListAjax(pageNo){
if(!fn_cmndataValueChk("startDate", "endDate", 365)){
if(!fn_cmndataValueChk("startDate", "endDate", 12)){
return;
};

View File

@ -54,7 +54,7 @@ function listLoad(subpage , searchFlag ){
function linkPage(pageNo){
if(!fn_cmndataValueChk("startDate", "endDate", 365)){
if(!fn_cmndataValueChk("startDate", "endDate", 12)){
return;
};

View File

@ -57,7 +57,7 @@ function setCalVal(val,targetObj){
// 요금사용내역 리스트
function payUserListAjax(pageNo){
if(!fn_cmndataValueChk("startDate", "endDate", 365)){
if(!fn_cmndataValueChk("startDate", "endDate", 12)){
return;
};

View File

@ -2,41 +2,38 @@ $(document).ready(function () {
});
function fn_cmndataValueChk(startId, endId, chkDay){
// 시작일자와 종료일자를 가져오기
var startDate = document.getElementById(startId).value;
var endDate = document.getElementById(endId).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;
}
// 총 기간이 chkDay일을 넘는지 확인
var diffTime = Math.abs(end - start);
var diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
if (diffDays > chkDay) {
var chkDayTxt = "";
if(chkDay == 365){
chkDayTxt = '1년';
}
alert("총 검색 기간은 "+chkDayTxt+"을 넘을 수 없습니다.");
return false;
}
return true;
}
function fn_cmndataValueChk(startId, endId, chkMonth) {
// 시작일자와 종료일자를 가져오기
var startDate = document.getElementById(startId).value;
var endDate = document.getElementById(endId).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;
}
// 종료일자를 기준으로 chkMonth 개월 전의 날짜 계산
var maxStartDate = new Date(end);
maxStartDate.setMonth(maxStartDate.getMonth() - chkMonth);
// 시작일자가 종료일자 기준 chkMonth 개월 전보다 이전인지 확인
console.log('start :: ',start);
console.log('maxStartDate :: ',maxStartDate);
if (start <= maxStartDate) {
alert("총 검색 기간은 " + chkMonth + "개월을 넘을 수 없습니다.");
return false;
}
return true;
}