diff --git a/src/main/java/com/habday/server/classes/Calculation.java b/src/main/java/com/habday/server/classes/Calculation.java index fb9de3a..1d3ccfb 100644 --- a/src/main/java/com/habday/server/classes/Calculation.java +++ b/src/main/java/com/habday/server/classes/Calculation.java @@ -47,15 +47,18 @@ public Date calPayDate(LocalDate localDate){ Date toDate = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); Calendar calendar = Calendar.getInstance(); calendar.setTime(toDate); - calendar.add(Calendar.MINUTE, CmnConst.paymentDelayMin);//펀딩 종료 30분 후에 결제 + calendar.add(Calendar.DATE, CmnConst.paymentDelayDate);//펀딩 마감일이 생일 전날 -> 결제일은 생일날 + calendar.add(Calendar.MINUTE, CmnConst.paymentDelayMin);//펀딩 종료 다음날 30분 후에 결제 return new Date(calendar.getTimeInMillis()); } + //펀딩 인증 & (memberState 변경: 이 함수 적용 안함) public Boolean isAfterTwoWeek(FundingItem item){ - LocalDate finishedDate = item.getFinishDate(); - LocalDate afterTwoWeek = finishedDate.plusDays(CmnConst.confirmLimitDate); - - if (afterTwoWeek.compareTo(LocalDate.now()) < 0){ + LocalDate finishedDate = item.getFinishDate();//14일(생일 15일) + //LocalDate payDate = finishedDate.plusDays(CmnConst.paymentDelayDate);//15일 + LocalDate afterTwoWeek = finishedDate.plusDays(CmnConst.confirmLimitDate);//28일 + //15 16 17 18 19 20 21 22 23 24 25 26 27 28 + if (afterTwoWeek.compareTo(LocalDate.now()) < 0){//28 < 29일(오늘) log.info("isAfterTwoWeek(): 펀딩 인증 2주 지남" + finishedDate.compareTo(afterTwoWeek) + " " + afterTwoWeek + "," + finishedDate); return true; }else { @@ -64,10 +67,32 @@ public Boolean isAfterTwoWeek(FundingItem item){ } } -// public Date addDate(Date baseDate, int addedUnit, int addedTime){ -// Calendar calendar = Calendar.getInstance(); -// calendar.setTime(baseDate); -// calendar.add(addedUnit, addedTime); -// return new Date(calendar.getTimeInMillis()); -// } + public Boolean isOverFinishDate(LocalDate finishDate){ + if(LocalDate.now().compareTo(finishDate)>=0){ + log.info("isFinishDate: 오늘 >= 마감일 입니다."); + return true; + }else{ + log.info("isFinishDate: 마감일 전입니다."); + return false; + } + } + + public Boolean isBeforeFinishDate(LocalDate finishDate){ + if (finishDate.compareTo(LocalDate.now()) >= 0){ + log.info("isBeforeFinishDate: 마감일 당일 혹은 마감일 전"); + return true; + } + else { + log.info("isBeforeFinishDate: 마감일 이후"); + return false; + } + } + + public LocalDate calScheduleFinishDate(){ + return LocalDate.now().minusDays(CmnConst.paymentDelayDate); + } + + public LocalDate calMemberStateFinishDate(){ + return LocalDate.now().minusDays(CmnConst.confirmLimitDate); + } } diff --git a/src/main/java/com/habday/server/config/email/EmailService.java b/src/main/java/com/habday/server/config/email/EmailService.java index f329dba..7331b96 100644 --- a/src/main/java/com/habday/server/config/email/EmailService.java +++ b/src/main/java/com/habday/server/config/email/EmailService.java @@ -48,7 +48,7 @@ public Boolean sendEmail(EmailMessage emailMessage){ public String[] getParticipantEmail(FundingItem fundingItem){ List mailList = fundingMemberRepository.getMailList(fundingItem); - log.info("mailList: " + new Gson().toJson(mailList)); + //log.info("mailList: " + new Gson().toJson(mailList)); return mailList.toArray(new String[mailList.size()]); } } diff --git a/src/main/java/com/habday/server/constants/CmnConst.java b/src/main/java/com/habday/server/constants/CmnConst.java index 38d7064..e81fc89 100644 --- a/src/main/java/com/habday/server/constants/CmnConst.java +++ b/src/main/java/com/habday/server/constants/CmnConst.java @@ -4,6 +4,7 @@ public class CmnConst { public static String server = "http://13.124.209.40:8080/"; public static String localhost = "http://localhost:9000/"; //TODO 스케쥴 시간 등 중요한 정보 넣기 + public static int paymentDelayDate = 1;//일 단위. 펀딩 마감일이 생일 전날이면(생일 8월 30일, 마감일 8월 29일, 29 +1일 + 30분 더해서 예약) public static int paymentDelayMin = 30;//분 단위 public static int confirmLimitDate = 14; //일 단위 public static final String scheduleCron = "0 5 0 * * *"; //"0 5 0 * * *" diff --git a/src/main/java/com/habday/server/constants/code/ExceptionCode.java b/src/main/java/com/habday/server/constants/code/ExceptionCode.java index c9be3f2..3ebeb32 100644 --- a/src/main/java/com/habday/server/constants/code/ExceptionCode.java +++ b/src/main/java/com/habday/server/constants/code/ExceptionCode.java @@ -52,7 +52,8 @@ public enum ExceptionCode { FUNDING_CONFIRM_NOT_YET(INTERNAL_SERVER_ERROR, "완료되지 않은 펀딩은 인증을 진행할 수 없습니다."), FUNDING_ALREADY_CONFIRMED(INTERNAL_SERVER_ERROR, "이미 인증된 펀딩입니다."), NO_CONFIRMATION_EXIST(INTERNAL_SERVER_ERROR,"펀딩 인증이 존재하지 않습니다."), - DELETE_FUNDING_UNAVAILABLE(INTERNAL_SERVER_ERROR, "마감한 펀딩에 대해서는 펀딩 삭제가 불가합니다."), + DELETE_FUNDING_UNAVAILABLE(INTERNAL_SERVER_ERROR, "마감 당일과 마감일 이후에는 펀딩 삭제가 불가합니다."), + UPDATE_FUNDING_UNAVAILABLE(INTERNAL_SERVER_ERROR, "마감 당일 이후에 대해서는 펀딩 삭제가 불가합니다."), DELETE_PARTICIPATE_UNAVAILABLE(INTERNAL_SERVER_ERROR,"마감한 펀딩에 대해서는 참여 취소가 불가합니다."), PAYMENT_VALIDATION_FAIL(INTERNAL_SERVER_ERROR, "결제 수단이 사용자 정보와 일치하지 않습니다."), FUNDING_MEMBER_VALIDATION_FAIL(INTERNAL_SERVER_ERROR, "펀딩 참여 내역이 사용자 정보와 일치하지 않습니다."); diff --git a/src/main/java/com/habday/server/service/FundingService.java b/src/main/java/com/habday/server/service/FundingService.java index 5615c38..cc05862 100644 --- a/src/main/java/com/habday/server/service/FundingService.java +++ b/src/main/java/com/habday/server/service/FundingService.java @@ -181,7 +181,7 @@ public void confirm(MultipartFile img, ConfirmationRequest request, Long funding throw new CustomException(FUNDING_CONFIRM_NOT_NEEDED); } - if (fundingItem.getFinishDate().compareTo(LocalDate.now()) > 0){//now < finishDate + if (calculation.isBeforeFinishDate(fundingItem.getFinishDate())){//now <= finishDate log.info("confirm(): 아직 진행중인 펀딩임." + fundingItem.getFinishDate()); throw new CustomException(FUNDING_CONFIRM_NOT_YET); }//fundingItemStatus는 SUCCESS이지만 아직 진행중인 경우 @@ -224,6 +224,10 @@ public void updateFundingItem(Long fundingItemId, MultipartFile fundingItemImg, FundingItem fundingItem = fundingItemRepository.findById(fundingItemId) .orElseThrow(() -> new CustomException(NO_FUNDING_ITEM_ID)); System.out.println("updateFundingItem^^ fundingItem " + fundingItem); + + if(calculation.isOverFinishDate(fundingItem.getFinishDate())){//마감 당일에는 수정 x + throw new CustomException(UPDATE_FUNDING_UNAVAILABLE); + } //ObjectMapper mapper = new ObjectMapper(); //System.out.println("updateFundingItem^^ fundingItem" + mapper.writeValueAsString(fundingItem)); System.out.println("updateFundingItem^^ fundingItemImg" + fundingItemImg + " fundingItemName" + fundingItemName + " fundingItemDetail" + fundingItemDetail); @@ -245,7 +249,7 @@ public void deleteFundingItem(Long fundingItemId) { FundingItem fundingItem = fundingItemRepository.findById(fundingItemId) .orElseThrow(() -> new CustomException(NO_FUNDING_ITEM_ID)); - if(LocalDate.now().compareTo(fundingItem.getFinishDate())>=0){ + if(calculation.isOverFinishDate(fundingItem.getFinishDate())){//마감 당일에는 삭제 X throw new CustomException(DELETE_FUNDING_UNAVAILABLE); } fundingItemRepository.delete(fundingItem); diff --git a/src/main/java/com/habday/server/service/ScheduleService.java b/src/main/java/com/habday/server/service/ScheduleService.java index 5a0171e..45e51d6 100644 --- a/src/main/java/com/habday/server/service/ScheduleService.java +++ b/src/main/java/com/habday/server/service/ScheduleService.java @@ -30,13 +30,16 @@ @Service public class ScheduleService extends Common { private final FundingCloseService closeService; + private final Calculation calculation; @Transactional @Scheduled(cron = scheduleCron) // "0 5 0 * * *" 매일 밤 0시 5분에 실행 public void checkFundingState() { log.info("schedule 시작"); - List successFunding = fundingItemRepository.findByStatusAndFinishDate(FundingState.SUCCESS, LocalDate.now()); - List failFunding = fundingItemRepository.findByStatusAndFinishDate(FundingState.PROGRESS, LocalDate.now()); + List successFunding = fundingItemRepository.findByStatusAndFinishDate(FundingState.SUCCESS, + calculation.calScheduleFinishDate()); + List failFunding = fundingItemRepository.findByStatusAndFinishDate(FundingState.PROGRESS, + calculation.calScheduleFinishDate()); successFunding.forEach(fundingItem -> { log.info("오늘 마감 성공 fundingItem: " + fundingItem.getId()); @@ -56,11 +59,11 @@ public void checkFundingState() { * */ @Transactional @Scheduled(cron = memberStateCron)//매일 밤 12시 - public void checkMemberState(){ + public void checkMemberState(){//finishDate 13일 -> 27일 //14 15 16 17 18 19 20 21 22 23 24 25 26 27 // 28일부터 걸러야 log.info("member cron 돌아감"); List fundingItems = //now > finishDate + 14 == now - 14 > finishDate fundingItemRepository.findByIsConfirmAndStatusAndFinishDateLessThan(FundingConfirmState.FALSE, - FundingState.SUCCESS, LocalDate.now().minusDays(CmnConst.confirmLimitDate));//데이터 많아지면 검색 범위를 지정해도 되지 않을까 너무 옛날꺼는 검색하지 않는다던지 + FundingState.SUCCESS, calculation.calMemberStateFinishDate());//데이터 많아지면 검색 범위를 지정해도 되지 않을까 너무 옛날꺼는 검색하지 않는다던지 //성공한 펀딩 and 인증 기간 지남(14일 지남) and 펀딩 인증 false fundingItems.forEach((item -> {//for문의 범위를 줄여야 해!! log.info("item: " + item.getId() + " memberId: " + item.getMember().getId());