From 67793a651b075eaf8edd7a33c55e9c651e7ce566 Mon Sep 17 00:00:00 2001 From: Vinjor Date: Wed, 25 Sep 2024 14:22:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E9=93=B6=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cardCoupon/entity/CardCoupon.java | 2 + .../userGroup/entity/UserDiscount.java | 4 ++ .../service/impl/PayCenterServiceImpl.java | 69 +++++++++++++++++-- .../java/com/fuint/pay/util/CheckUtil.java | 37 +++++++--- 4 files changed, 98 insertions(+), 14 deletions(-) diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/entity/CardCoupon.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/entity/CardCoupon.java index 2ed474f5b..7f9d3bea2 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/entity/CardCoupon.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/entity/CardCoupon.java @@ -84,6 +84,8 @@ public class CardCoupon extends Model { private Integer limitTotalDay; //限制多少天内可使用几次的 次字段 private Integer limitTotalNum; + //策略选择 适用或者不适用 0适用 1不适用 + private String availableOrUn; //适用类型1每周2每月 private String availableType; //周一周二周三 1 2 3 4 5 6 7逗号隔开 diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/entity/UserDiscount.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/entity/UserDiscount.java index fbc16d88d..848740118 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/entity/UserDiscount.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/entity/UserDiscount.java @@ -76,6 +76,10 @@ public class UserDiscount extends BaseEntity implements Serializable { * 适用时间段类型:0每周、1每月 */ private String suitTimeSlotType; + /** + * 策略选择 适用或者不适用 0适用 1不适用 + */ + private String availableOrUn; /** * 适用时间段:周/月 */ diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/service/impl/PayCenterServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/service/impl/PayCenterServiceImpl.java index 31ceb1076..8740166f6 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/service/impl/PayCenterServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/service/impl/PayCenterServiceImpl.java @@ -153,7 +153,7 @@ public class PayCenterServiceImpl implements PayCenterService { //适用当前加油金额或加油升数的 .filter(rule -> checkUtil.checkConsume(rule,oilAmount,oilLiter)) //适用当前时间段的 - .filter(rule -> checkUtil.checkTime(rule.getTimeSlots(),rule.getDayStartTime(),rule.getDayEndTime(),nowDate)) + .filter(rule -> checkUtil.checkTime(rule.getTimeType(),rule.getTimeSlots(),rule.getDayStartTime(),rule.getDayEndTime(),nowDate)) //适用当前油号的 .filter(rule-> checkUtil.checkOil(rule.getOilList(),oilId)) //适用当前支付方式的 @@ -217,7 +217,7 @@ public class PayCenterServiceImpl implements PayCenterService { //适用当前会员标签的 .filter(rule->checkUtil.checkLabelId(rule.getBabelIds(),labelIdList)) //适用当前时间段的 - .filter(rule -> checkUtil.checkTime(rule.getTimeSlots(),checkUtil.getTimeFromDate(rule.getTimeApplyStart()),checkUtil.getTimeFromDate(rule.getTimeApplyEnd()),nowDate)) + .filter(rule -> checkUtil.checkTime(rule.getTimeType(),rule.getTimeSlots(),checkUtil.getTimeFromDate(rule.getTimeApplyStart()),checkUtil.getTimeFromDate(rule.getTimeApplyEnd()),nowDate)) //适用当前油号的 .filter(rule-> checkUtil.checkOilLijian(rule.getApplyOilType(),rule.getApplyOil(),oilId)) //适用当前支付方式的 @@ -271,8 +271,8 @@ public class PayCenterServiceImpl implements PayCenterService { .filter(rule->rule.getGradeId().equals(gradeId)) //节假日要求是否满足 .filter(rule->checkUtil.checkTimeJiejiari(rule.getHolidayIsUse(),nowDate)) - //适用当前时间段的 - .filter(rule -> checkUtil.checkTime(rule.getSuitDate(),checkUtil.getTimeFromDate(rule.getSuitTimeSlotFront()),checkUtil.getTimeFromDate(rule.getSuitDateAfter()),nowDate)) + //当前时间在 适用时间段内 或者 当前时间不在 不适用时间段内的 + .filter(rule ->this.checkTimeZhekouPrex(rule,nowDate)) //是否满足最低消费金额 .filter(rule-> rule.getConsumeAmount() <=oilAmount) //适用当前支付方式的 @@ -305,6 +305,33 @@ public class PayCenterServiceImpl implements PayCenterService { return rtnList; } + /** + * 营销折扣活动适用时间判断前置处理方法 + * @author vinjor-M + * @date 13:57 2024/9/25 + * @param rule 规则对象 + * @param nowDate 当前时间 + * @return java.lang.Boolean + **/ + private Boolean checkTimeZhekouPrex(UserDiscount rule,Date nowDate){ + String startTimeStr; + String endTimeStr; + if("0".equals(rule.getAvailableOrUn())){ + //适用时间 + startTimeStr = checkUtil.getTimeFromDate(rule.getSuitTimeSlotFront()); + endTimeStr = checkUtil.getTimeFromDate(rule.getSuitTimeSlotAfter()); + return checkUtil.checkTime(rule.getSuitTimeSlotType(),rule.getSuitDate(),startTimeStr,endTimeStr,nowDate); + }else if("1".equals(rule.getAvailableOrUn())){ + //不适用时间 + startTimeStr = checkUtil.getTimeFromDate(rule.getNoUseTimeFront()); + endTimeStr = checkUtil.getTimeFromDate(rule.getNoUseTimeAfter()); + return checkUtil.checkTimeReverse(rule.getNoUseTimeType(),rule.getNoUseDate(),startTimeStr,endTimeStr,nowDate); + }else { + //超出预设值范围,不可用 + return false; + } + } + /** * 收银台获取可用优惠券 * @@ -335,7 +362,41 @@ public class PayCenterServiceImpl implements PayCenterService { /*1.先查满足条件的所有生效中的优惠券*/ List couponVOList = cardCouponUserService.selectAllList(storeId, userId, nowDate); /*2.进行初步过滤,这里只过滤优惠券硬性的限制*/ + List filteredList = couponVOList.stream() + //当前时间在 适用时间段内 或者 当前时间不在 不适用时间段内的 + .filter(rule -> this.checkTimeCouponPrex(rule,nowDate)).collect(Collectors.toList()); +// //是否满足最低消费金额 +// .filter(rule-> rule.getConsumeAmount() <=oilAmount) +// //适用当前支付方式的 +// .filter(rule-> rule.getUsePaymentWay().contains(payWay)) List rtnList = new ArrayList<>(); return rtnList; } + + /** + * 优惠券适用时间判断前置处理方法 + * @author vinjor-M + * @date 13:57 2024/9/25 + * @param rule 规则对象 + * @param nowDate 当前时间 + * @return java.lang.Boolean + **/ + private Boolean checkTimeCouponPrex(CardCouponVO rule,Date nowDate){ + String startTimeStr; + String endTimeStr; + if("0".equals(rule.getAvailableOrUn())){ + //适用时间 + startTimeStr = checkUtil.getTimeFromDate(rule.getAvailablePeriodStart()); + endTimeStr = checkUtil.getTimeFromDate(rule.getAvailablePeriodEnd()); + return checkUtil.checkTime(rule.getAvailableType(),"1".equals(rule.getAvailableType())?rule.getAvailableWeek():rule.getAvailableDay(),startTimeStr,endTimeStr,nowDate); + }else if("1".equals(rule.getAvailableOrUn())){ + //不适用时间 + startTimeStr = checkUtil.getTimeFromDate(rule.getUnAvailablePeriodStart()); + endTimeStr = checkUtil.getTimeFromDate(rule.getUnAvailablePeriodEnd()); + return checkUtil.checkTimeReverse(rule.getUnAvailableType(),"1".equals(rule.getUnAvailableType())?rule.getUnAvailableWeek():rule.getUnAvailableDay(),startTimeStr,endTimeStr,nowDate); + }else { + //超出预设值范围,不可用 + return false; + } + } } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/util/CheckUtil.java b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/util/CheckUtil.java index fcdbb929e..6a3735d12 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/util/CheckUtil.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/util/CheckUtil.java @@ -16,6 +16,7 @@ import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.text.DecimalFormat; import java.time.LocalDate; +import java.time.LocalTime; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -78,15 +79,16 @@ public class CheckUtil { * 判断结算时间是否符合活动设置的适用时间 * @author vinjor-M * @date 11:41 2024/9/21 - * @param timeSlots 适用时间 - * @param startTime 某天适用的开始时间 - * @param endTime 某天适用的结束时间 + * @param type 适用时间类型 (1每周 |2每月) + * @param timeSlots 适用时间(如果是按周,则存周一、周二、...周六、周日|如果是按月,则存1,2,3,4,...,31) + * @param startTime 某天适用的开始时间(13:40) + * @param endTime 某天适用的结束时间(13:40) * @param nowDate 结算时间 * @return java.lang.Boolean **/ - public Boolean checkTime(String timeSlots,String startTime,String endTime, Date nowDate){ + public Boolean checkTime(String type,String timeSlots,String startTime,String endTime, Date nowDate){ String timeSlotsStr = timeSlots; - if(timeSlots.contains("周")){ + if("1".equals(type)){ //周几汉字转数字 timeSlotsStr = changeWeekNumber(timeSlots); } @@ -98,7 +100,7 @@ public class CheckUtil { return checkDayTime(nowDate,startTime,endTime); }else{ //设置了时间段,需要判断时间段是否符合 - if(timeSlots.contains("周")){ + if("1".equals(type)){ //活动设置的适用时间类型是每周 //结算时间是周几,特殊情况(0是周日,需要转换为7 方便判断) int nowWeek = DateUtil.dayOfWeek(nowDate)-1; @@ -129,15 +131,16 @@ public class CheckUtil { * 判断结算时间是否符合活动设置的【不适用时间】!!!!注意,判断是否处在不适用的时间范围内 * @author vinjor-M * @date 11:41 2024/9/21 - * @param timeSlots 适用时间 + * @param type 适用时间类型 (1每周 |2每月) + * @param timeSlots 不适用时间 * @param startTime 某天适用的开始时间 * @param endTime 某天适用的结束时间 * @param nowDate 结算时间 * @return java.lang.Boolean **/ - public Boolean checkTimeReverse(String timeSlots,String startTime,String endTime, Date nowDate){ + public Boolean checkTimeReverse(String type,String timeSlots,String startTime,String endTime, Date nowDate){ String timeSlotsStr = timeSlots; - if(timeSlots.contains("周")){ + if("1".equals(type)){ //周几汉字转数字 timeSlotsStr = changeWeekNumber(timeSlots); } @@ -149,7 +152,7 @@ public class CheckUtil { return checkDayTimeReverse(nowDate,startTime,endTime); }else{ //设置了时间段,需要判断时间段是否符合 - if(timeSlots.contains("周")){ + if("1".equals(type)){ //活动设置的适用时间类型是每周 //结算时间是周几,特殊情况(0是周日,需要转换为7 方便判断) int nowWeek = DateUtil.dayOfWeek(nowDate)-1; @@ -410,6 +413,20 @@ public class CheckUtil { } return rtn; } + /** + * 从一个日期里面获取时间,00:00格式 + * @author vinjor-M + * @date 19:12 2024/9/21 + * @param localTime 时间 00:00:00 + * @return java.lang.String + **/ + public String getTimeFromDate(LocalTime localTime){ + String rtn = ""; + if(null!=localTime){ + rtn = localTime.toString().substring(0,5); + } + return rtn; + } /** * 获取最符合条件的优惠规则--立减营销