|
|
@@ -588,12 +588,11 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<LifeDiscountCouponVo> getUserCouponList(UserLoginInfo userLoginInfo, int page, int size, String tabType) {
|
|
|
+ public List<LifeDiscountCouponVo> getUserCouponList(UserLoginInfo userLoginInfo, int page, int size, String tabType, Integer type) {
|
|
|
List<LifeDiscountCouponVo> lifeDiscountCouponVos = new ArrayList<>();
|
|
|
IPage<LifeDiscountCouponUser> iPage = new Page<>(page, size);
|
|
|
LambdaQueryWrapper<LifeDiscountCouponUser> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(LifeDiscountCouponUser::getUserId, userLoginInfo.getUserId());
|
|
|
-
|
|
|
//比较工具对象
|
|
|
//获取七日前时间
|
|
|
Date now = new Date();
|
|
|
@@ -657,6 +656,12 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
//并且状态为待使用
|
|
|
queryWrapper.eq(LifeDiscountCouponUser::getStatus, DiscountCouponEnum.WAITING_USED.getValue());
|
|
|
}
|
|
|
+ // type:1 仅优惠券(couponId 有值),4 仅代金券(voucherId 有值),不传则都查
|
|
|
+ if (type != null && type == 1) {
|
|
|
+ queryWrapper.and(w -> w.isNotNull(LifeDiscountCouponUser::getCouponId));
|
|
|
+ } else if (type != null && type == 4) {
|
|
|
+ queryWrapper.and(w -> w.isNotNull(LifeDiscountCouponUser::getVoucherId));
|
|
|
+ }
|
|
|
queryWrapper.orderByDesc(LifeDiscountCouponUser::getCreatedTime);
|
|
|
IPage<LifeDiscountCouponUser> lifeDiscountCouponUserIPage = lifeDiscountCouponUserMapper.selectPage(iPage, queryWrapper);
|
|
|
//根据券id去查询该券的基本信息
|
|
|
@@ -667,19 +672,100 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
ZoneId zoneId = ZoneId.systemDefault();
|
|
|
LocalDate localNow1 = instant.atZone(zoneId).toLocalDate();
|
|
|
|
|
|
- //所有优惠券
|
|
|
- List<Integer> couponIdList = lifeDiscountCouponUserIPage.getRecords().stream().map(LifeDiscountCouponUser::getCouponId).collect(Collectors.toList());
|
|
|
+ List<LifeDiscountCouponUser> records = lifeDiscountCouponUserIPage.getRecords();
|
|
|
+ // type=4:仅代金券,查 life_coupon 表
|
|
|
+ if (type != null && type == 4) {
|
|
|
+ List<String> voucherIdList = records.stream().map(LifeDiscountCouponUser::getVoucherId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ if (voucherIdList.isEmpty()) {
|
|
|
+ return lifeDiscountCouponVos;
|
|
|
+ }
|
|
|
+ List<LifeCoupon> lifeCoupons = lifeCouponMapper.selectList(new LambdaQueryWrapper<LifeCoupon>().in(LifeCoupon::getId, voucherIdList));
|
|
|
+ List<String> storeIdList = lifeCoupons.stream().map(LifeCoupon::getStoreId).filter(s -> !StringUtils.isEmpty(s)).collect(Collectors.toList());
|
|
|
+ List<StoreInfo> storeInfoList = storeInfoMapper.getList(new LambdaQueryWrapper<StoreInfo>().in(!storeIdList.isEmpty(), StoreInfo::getId, storeIdList));
|
|
|
+ for (LifeDiscountCouponUser lifeDiscountCouponUser : records) {
|
|
|
+ LifeCoupon lc = lifeCoupons.stream().filter(c -> c.getId().equals(lifeDiscountCouponUser.getVoucherId())).findFirst().orElse(null);
|
|
|
+ if (lc == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ LifeDiscountCouponVo vo = mapLifeCouponToVo(lc);
|
|
|
+ vo.setUserCouponId(lifeDiscountCouponUser.getId());
|
|
|
+ vo.setVoucherId(lc.getId());
|
|
|
+ vo.setQuantityClaimed(records.size());
|
|
|
+ vo.setExpirationTime(lifeDiscountCouponUser.getExpirationTime());
|
|
|
+ vo.setReachUseTimeFlag(1);
|
|
|
+ if (lc.getStartDate() != null) {
|
|
|
+ LocalDate startLocal = lc.getStartDate().toInstant().atZone(zoneId).toLocalDate();
|
|
|
+ if (localNow1.isBefore(startLocal)) {
|
|
|
+ vo.setReachUseTimeFlag(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (lc.getEndDate() != null) {
|
|
|
+ vo.setValidDate(lc.getEndDate().toInstant().atZone(zoneId).toLocalDate());
|
|
|
+ }
|
|
|
+ StoreInfo storeInfoOne = storeInfoList.stream().filter(s -> s.getId().toString().equals(lc.getStoreId())).findFirst().orElse(null);
|
|
|
+ if (storeInfoOne != null) {
|
|
|
+ vo.setBusinessSection(storeInfoOne.getBusinessSection());
|
|
|
+ vo.setBusinessSectionName(storeInfoOne.getBusinessSectionName());
|
|
|
+ }
|
|
|
+ lifeDiscountCouponVos.add(vo);
|
|
|
+ }
|
|
|
+ return lifeDiscountCouponVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ // type=1 或 type=null:优惠券(或混合),查 life_discount_coupon
|
|
|
+ List<Integer> couponIdList = records.stream().map(LifeDiscountCouponUser::getCouponId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
List<LifeDiscountCoupon> lifeDiscountCoupons = lifeDiscountCouponMapper.selectList(new QueryWrapper<LifeDiscountCoupon>().lambda().in(!couponIdList.isEmpty(), LifeDiscountCoupon::getId, couponIdList));
|
|
|
- if (lifeDiscountCoupons.isEmpty()) {
|
|
|
+ if (type != null && type == 1 && lifeDiscountCoupons.isEmpty()) {
|
|
|
return lifeDiscountCouponVos;
|
|
|
}
|
|
|
- //优惠券的所有门店
|
|
|
- List<String> storeIdList = lifeDiscountCoupons.stream().map(LifeDiscountCoupon::getStoreId).collect(Collectors.toList());
|
|
|
+ List<String> storeIdList = lifeDiscountCoupons.isEmpty() ? new ArrayList<>() : lifeDiscountCoupons.stream().map(LifeDiscountCoupon::getStoreId).collect(Collectors.toList());
|
|
|
List<StoreInfo> storeInfoList = storeInfoMapper.getList(new LambdaQueryWrapper<StoreInfo>().in(!storeIdList.isEmpty(), StoreInfo::getId, storeIdList));
|
|
|
- if (storeInfoList.isEmpty() && lifeDiscountCouponUserIPage.getRecords().isEmpty()) {
|
|
|
+ if (type != null && type == 1 && storeInfoList.isEmpty() && records.isEmpty()) {
|
|
|
return lifeDiscountCouponVos;
|
|
|
}
|
|
|
- for (LifeDiscountCouponUser lifeDiscountCouponUser : lifeDiscountCouponUserIPage.getRecords()) {
|
|
|
+ List<LifeCoupon> lifeCouponsForMerge = new ArrayList<>();
|
|
|
+ if (type == null) {
|
|
|
+ List<String> voucherIdList = records.stream().map(LifeDiscountCouponUser::getVoucherId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ if (!voucherIdList.isEmpty()) {
|
|
|
+ lifeCouponsForMerge = lifeCouponMapper.selectList(new LambdaQueryWrapper<LifeCoupon>().in(LifeCoupon::getId, voucherIdList));
|
|
|
+ }
|
|
|
+ if (!lifeCouponsForMerge.isEmpty()) {
|
|
|
+ List<String> voucherStoreIds = lifeCouponsForMerge.stream().map(LifeCoupon::getStoreId).filter(s -> !StringUtils.isEmpty(s)).collect(Collectors.toList());
|
|
|
+ if (!voucherStoreIds.isEmpty()) {
|
|
|
+ List<StoreInfo> voucherStores = storeInfoMapper.getList(new LambdaQueryWrapper<StoreInfo>().in(StoreInfo::getId, voucherStoreIds));
|
|
|
+ storeInfoList = new ArrayList<>(storeInfoList);
|
|
|
+ storeInfoList.addAll(voucherStores);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (LifeDiscountCouponUser lifeDiscountCouponUser : records) {
|
|
|
+ if (lifeDiscountCouponUser.getVoucherId() != null && !lifeCouponsForMerge.isEmpty()) {
|
|
|
+ LifeCoupon lc = lifeCouponsForMerge.stream().filter(c -> c.getId().equals(lifeDiscountCouponUser.getVoucherId())).findFirst().orElse(null);
|
|
|
+ if (lc != null) {
|
|
|
+ LifeDiscountCouponVo vo = mapLifeCouponToVo(lc);
|
|
|
+ vo.setUserCouponId(lifeDiscountCouponUser.getId());
|
|
|
+ vo.setVoucherId(lc.getId());
|
|
|
+ vo.setQuantityClaimed(records.size());
|
|
|
+ vo.setExpirationTime(lifeDiscountCouponUser.getExpirationTime());
|
|
|
+ vo.setReachUseTimeFlag(1);
|
|
|
+ if (lc.getStartDate() != null) {
|
|
|
+ LocalDate startLocal = lc.getStartDate().toInstant().atZone(zoneId).toLocalDate();
|
|
|
+ if (localNow1.isBefore(startLocal)) {
|
|
|
+ vo.setReachUseTimeFlag(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (lc.getEndDate() != null) {
|
|
|
+ vo.setValidDate(lc.getEndDate().toInstant().atZone(zoneId).toLocalDate());
|
|
|
+ }
|
|
|
+ StoreInfo storeInfoOne = storeInfoList.stream().filter(s -> s.getId().toString().equals(lc.getStoreId())).findFirst().orElse(null);
|
|
|
+ if (storeInfoOne != null) {
|
|
|
+ vo.setBusinessSection(storeInfoOne.getBusinessSection());
|
|
|
+ vo.setBusinessSectionName(storeInfoOne.getBusinessSectionName());
|
|
|
+ }
|
|
|
+ lifeDiscountCouponVos.add(vo);
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
LifeDiscountCoupon lifeDiscountCouponOne = lifeDiscountCoupons.stream().filter(lifeDiscountCoupon -> lifeDiscountCoupon.getId().equals(lifeDiscountCouponUser.getCouponId())).findFirst().orElse(null);
|
|
|
if (lifeDiscountCouponOne == null) {
|
|
|
continue;
|
|
|
@@ -693,7 +779,7 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
lifeDiscountCouponVo.setBusinessSection(storeInfoOne.getBusinessSection());
|
|
|
lifeDiscountCouponVo.setBusinessSectionName(storeInfoOne.getBusinessSectionName());
|
|
|
}
|
|
|
- lifeDiscountCouponVo.setCouponId(lifeDiscountCouponUser.getId());
|
|
|
+ lifeDiscountCouponVo.setCouponId(lifeDiscountCouponOne.getId());
|
|
|
lifeDiscountCouponVo.setVoucherId(lifeDiscountCouponUser.getVoucherId());
|
|
|
BeanUtils.copyProperties(lifeDiscountCouponOne, lifeDiscountCouponVo);
|
|
|
lifeDiscountCouponVo.setQuantityClaimed(lifeDiscountCouponUserIPage.getRecords().size());
|
|
|
@@ -985,35 +1071,72 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String getCouponRule(String couponId, UserLoginInfo userLoginInfo) {
|
|
|
- LifeDiscountCoupon lifeDiscountCoupon = lifeDiscountCouponMapper.selectById(couponId);
|
|
|
+ public String getCouponRule(String couponId, UserLoginInfo userLoginInfo, Integer type, String voucherId) {
|
|
|
+ // type=4:仅代金券,根据 life_coupon 构建使用规则文案(代金券 id 优先用 id 参数,未传则用 couponId)
|
|
|
+ if (type != null && type == 4) {
|
|
|
+ String vid = (voucherId != null && !voucherId.isEmpty()) ? voucherId : couponId;
|
|
|
+ if (vid == null || vid.isEmpty()) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ LifeCoupon lc = lifeCouponMapper.selectById(vid);
|
|
|
+ return lc != null ? buildLifeCouponRule(lc) : "";
|
|
|
+ }
|
|
|
+ // type=1:仅优惠券,根据 life_discount_coupon 构建使用规则
|
|
|
+ if (type != null && type == 1) {
|
|
|
+ try {
|
|
|
+ Integer coupon = Integer.parseInt(couponId);
|
|
|
+ LifeDiscountCoupon lifeDiscountCoupon = lifeDiscountCouponMapper.selectById(coupon);
|
|
|
+ if (lifeDiscountCoupon == null) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ return buildDiscountCouponRule(lifeDiscountCoupon);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // type 不传:根据 life_discount_coupon 与 life_coupon 两张表分别构建使用规则文案并都返回
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ try {
|
|
|
+ Integer coup = Integer.parseInt(couponId);
|
|
|
+ LifeDiscountCoupon c = lifeDiscountCouponMapper.selectById(coup);
|
|
|
+ if (c != null) {
|
|
|
+ sb.append("【优惠券使用规则】\n").append(buildDiscountCouponRule(c));
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException ignored) {
|
|
|
+ }
|
|
|
+ String vid = (voucherId != null && !voucherId.isEmpty()) ? voucherId : couponId;
|
|
|
+ if (vid != null && !vid.isEmpty()) {
|
|
|
+ try {
|
|
|
+ LifeCoupon lc = lifeCouponMapper.selectById(vid);
|
|
|
+ if (lc != null) {
|
|
|
+ if (sb.length() > 0) {
|
|
|
+ sb.append("\n\n");
|
|
|
+ }
|
|
|
+ sb.append("【代金券使用规则】\n").append(buildLifeCouponRule(lc));
|
|
|
+ }
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 根据 life_coupon(代金券)构建使用规则文案,委托给 buildVoucherCouponRule,与 buildDiscountCouponRule 对应的一套代金券逻辑 */
|
|
|
+ private String buildLifeCouponRule(LifeCoupon lc) {
|
|
|
+ return buildVoucherCouponRule(lc);
|
|
|
+ }
|
|
|
|
|
|
+ /** 根据 life_discount_coupon 构建使用规则文案(节假日/周中禁用 + 最低消费) */
|
|
|
+ private String buildDiscountCouponRule(LifeDiscountCoupon lifeDiscountCoupon) {
|
|
|
// 获取 Calendar 实例,默认表示当前日期和时间
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
- // 将小时设置为 0
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
- // 将分钟设置为 0
|
|
|
calendar.set(Calendar.MINUTE, 0);
|
|
|
- // 将秒设置为 0
|
|
|
calendar.set(Calendar.SECOND, 0);
|
|
|
- // 将毫秒设置为 0
|
|
|
calendar.set(Calendar.MILLISECOND, 0);
|
|
|
- // 获取设置后的 Date 对象
|
|
|
- Date midnight = calendar.getTime();
|
|
|
-
|
|
|
- //判断今日是否为节该券禁用节假日
|
|
|
- //判断当日是否为节假日
|
|
|
- // 获取当前日期
|
|
|
Date currentDate = new Date();
|
|
|
- // 创建 SimpleDateFormat 对象,指定日期格式
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- // 格式化日期
|
|
|
String formattedDate = dateFormat.format(currentDate);
|
|
|
- //获取当前年份
|
|
|
- // 获取 Calendar 实例
|
|
|
- // 获取当前年份
|
|
|
int year = calendar.get(Calendar.YEAR);
|
|
|
- //获取该年份基础节假日数据
|
|
|
LambdaQueryWrapper<EssentialHolidayComparison> essentialHolidayComparisonLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
essentialHolidayComparisonLambdaQueryWrapper.eq(EssentialHolidayComparison::getParticularYear, year);
|
|
|
List<EssentialHolidayComparison> essentialHolidayComparisons = essentialHolidayComparisonMapper.selectList(essentialHolidayComparisonLambdaQueryWrapper);
|
|
|
@@ -1023,7 +1146,6 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
festivalName = essentialHolidayComparison.getFestivalName();
|
|
|
}
|
|
|
}
|
|
|
- //获取今日周几
|
|
|
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
|
|
|
String dayName = "";
|
|
|
switch (dayOfWeek) {
|
|
|
@@ -1048,10 +1170,11 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
case Calendar.SATURDAY:
|
|
|
dayName = "六";
|
|
|
break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
LifeDiscountCouponVo lifeDiscountCouponVo = new LifeDiscountCouponVo();
|
|
|
- //该券的节假日禁用规则
|
|
|
LambdaQueryWrapper<LifeDiscountCouponUnavailableRules> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
lambdaQueryWrapper.eq(LifeDiscountCouponUnavailableRules::getDiscountCouponId, lifeDiscountCoupon.getId());
|
|
|
lambdaQueryWrapper.eq(LifeDiscountCouponUnavailableRules::getUnavailableRuleType, DiscountCouponEnum.HOLIDAY_UNAVAILABLE.getValue());
|
|
|
@@ -1063,7 +1186,6 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
List<String> holidCoupnDis = lifeDiscountCouponUnavailableRules.stream().map(rule -> rule.getUnavailableRuleValue()).collect(Collectors.toList());
|
|
|
forbiddenRule += String.join(", ", holidCoupnDis);
|
|
|
for (LifeDiscountCouponUnavailableRules lifeDiscountCouponUnavailableRule : lifeDiscountCouponUnavailableRules) {
|
|
|
- //如果当日为节假日,并且该券该节假日也禁用,则该券禁用
|
|
|
if (StringUtils.isEmpty(festivalName) && festivalName.equals(lifeDiscountCouponUnavailableRule.getUnavailableRuleValue())) {
|
|
|
lifeDiscountCouponVo.setDisabledStatus(false);
|
|
|
}
|
|
|
@@ -1071,7 +1193,6 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
if (lifeDiscountCouponUnavailableRules.size() > 0) {
|
|
|
forbiddenRule += NOT_USE;
|
|
|
}
|
|
|
- //该券的周中禁用规则
|
|
|
LambdaQueryWrapper<LifeDiscountCouponUnavailableRules> lambdaQueryWeekWrapper = new LambdaQueryWrapper<>();
|
|
|
lambdaQueryWeekWrapper.eq(LifeDiscountCouponUnavailableRules::getDiscountCouponId, lifeDiscountCoupon.getId());
|
|
|
lambdaQueryWeekWrapper.eq(LifeDiscountCouponUnavailableRules::getUnavailableRuleType, DiscountCouponEnum.WEEKDAY_UNAVAILABLE.getValue());
|
|
|
@@ -1082,7 +1203,6 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
List<String> weekCoupnDis = weekLifeDiscountCouponUnavailableRules.stream().map(rule -> rule.getUnavailableRuleValue()).collect(Collectors.toList());
|
|
|
forbiddenRule += String.join(", ", weekCoupnDis);
|
|
|
for (LifeDiscountCouponUnavailableRules lifeDiscountCouponUnavailableRule : lifeDiscountCouponUnavailableRules) {
|
|
|
- //该券该周中日也禁用,则该券禁用
|
|
|
if (dayName.equals(lifeDiscountCouponUnavailableRule.getUnavailableRuleValue())) {
|
|
|
lifeDiscountCouponVo.setDisabledStatus(false);
|
|
|
}
|
|
|
@@ -1092,10 +1212,111 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
}
|
|
|
forbiddenRule += MINIMUM_SPENDING_AMOUNT + lifeDiscountCoupon.getMinimumSpendingAmount();
|
|
|
lifeDiscountCouponVo.setForbiddenRule(forbiddenRule);
|
|
|
+ return forbiddenRule;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 代金券使用规则文案(对应表 life_coupon),逻辑与 buildDiscountCouponRule 平行:查 essentialHolidayComparison、lifeDiscountCouponUnavailableRules(按 voucher_id),再拼接面值/使用规则/有效期等。
|
|
|
+ */
|
|
|
+ private String buildVoucherCouponRule(LifeCoupon lifeCoupon) {
|
|
|
+ // 与 buildDiscountCouponRule 一致:Calendar、当日日期、年份
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
+ Date currentDate = new Date();
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String formattedDate = dateFormat.format(currentDate);
|
|
|
+ int year = calendar.get(Calendar.YEAR);
|
|
|
+ // 查 essentialHolidayComparison 获取当日是否节假日
|
|
|
+ LambdaQueryWrapper<EssentialHolidayComparison> essentialHolidayComparisonLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ essentialHolidayComparisonLambdaQueryWrapper.eq(EssentialHolidayComparison::getParticularYear, String.valueOf(year));
|
|
|
+ List<EssentialHolidayComparison> essentialHolidayComparisons = essentialHolidayComparisonMapper.selectList(essentialHolidayComparisonLambdaQueryWrapper);
|
|
|
+ String festivalName = "";
|
|
|
+ for (EssentialHolidayComparison essentialHolidayComparison : essentialHolidayComparisons) {
|
|
|
+ if (essentialHolidayComparison.getFestivalDate() != null && formattedDate.equals(essentialHolidayComparison.getFestivalDate().toString())) {
|
|
|
+ festivalName = essentialHolidayComparison.getFestivalName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 当日周几
|
|
|
+ int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
|
|
|
+ String dayName = "";
|
|
|
+ switch (dayOfWeek) {
|
|
|
+ case Calendar.SUNDAY:
|
|
|
+ dayName = "日";
|
|
|
+ break;
|
|
|
+ case Calendar.MONDAY:
|
|
|
+ dayName = "一";
|
|
|
+ break;
|
|
|
+ case Calendar.TUESDAY:
|
|
|
+ dayName = "二";
|
|
|
+ break;
|
|
|
+ case Calendar.WEDNESDAY:
|
|
|
+ dayName = "三";
|
|
|
+ break;
|
|
|
+ case Calendar.THURSDAY:
|
|
|
+ dayName = "四";
|
|
|
+ break;
|
|
|
+ case Calendar.FRIDAY:
|
|
|
+ dayName = "五";
|
|
|
+ break;
|
|
|
+ case Calendar.SATURDAY:
|
|
|
+ dayName = "六";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // 代金券按 voucher_id 查 life_discount_coupon_unavailable_rules(节假日 + 周中),与优惠券按 discount_coupon_id 查对应
|
|
|
+ String voucherId = lifeCoupon.getId();
|
|
|
+ LambdaQueryWrapper<LifeDiscountCouponUnavailableRules> holidayWrapper = new LambdaQueryWrapper<>();
|
|
|
+ holidayWrapper.eq(LifeDiscountCouponUnavailableRules::getVoucherId, voucherId);
|
|
|
+ holidayWrapper.eq(LifeDiscountCouponUnavailableRules::getUnavailableRuleType, DiscountCouponEnum.HOLIDAY_UNAVAILABLE.getValue());
|
|
|
+ List<LifeDiscountCouponUnavailableRules> holidayRules = lifeDiscountCouponUnavailableRulesMapper.selectList(holidayWrapper);
|
|
|
+ String forbiddenRule = "";
|
|
|
+ if (!holidayRules.isEmpty()) {
|
|
|
+ forbiddenRule += HOLIDAY_RULE_TITLE;
|
|
|
+ forbiddenRule += holidayRules.stream().map(LifeDiscountCouponUnavailableRules::getUnavailableRuleValue).collect(Collectors.joining(", "));
|
|
|
+ forbiddenRule += NOT_USE;
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<LifeDiscountCouponUnavailableRules> weekWrapper = new LambdaQueryWrapper<>();
|
|
|
+ weekWrapper.eq(LifeDiscountCouponUnavailableRules::getVoucherId, voucherId);
|
|
|
+ weekWrapper.eq(LifeDiscountCouponUnavailableRules::getUnavailableRuleType, DiscountCouponEnum.WEEKDAY_UNAVAILABLE.getValue());
|
|
|
+ List<LifeDiscountCouponUnavailableRules> weekRules = lifeDiscountCouponUnavailableRulesMapper.selectList(weekWrapper);
|
|
|
+ if (!weekRules.isEmpty()) {
|
|
|
+ forbiddenRule += WEEK_RULE_TITLE;
|
|
|
+ forbiddenRule += weekRules.stream().map(LifeDiscountCouponUnavailableRules::getUnavailableRuleValue).collect(Collectors.joining(", "));
|
|
|
+ forbiddenRule += NOT_USE;
|
|
|
+ }
|
|
|
+ // life_coupon 表字段:面值、使用规则、使用有效期、购买须知使用时间
|
|
|
+ forbiddenRule += "面值:" + (lifeCoupon.getPrice() != null ? lifeCoupon.getPrice() : "");
|
|
|
+ if (!StringUtils.isEmpty(lifeCoupon.getUseRule())) {
|
|
|
+ forbiddenRule += "\n使用规则:" + lifeCoupon.getUseRule();
|
|
|
+ }
|
|
|
+ if (lifeCoupon.getStartDate() != null || lifeCoupon.getEndDate() != null) {
|
|
|
+ forbiddenRule += "\n使用有效期:";
|
|
|
+ if (lifeCoupon.getStartDate() != null) {
|
|
|
+ forbiddenRule += new SimpleDateFormat("yyyy-MM-dd").format(lifeCoupon.getStartDate());
|
|
|
+ }
|
|
|
+ forbiddenRule += " 至 ";
|
|
|
+ if (lifeCoupon.getEndDate() != null) {
|
|
|
+ forbiddenRule += new SimpleDateFormat("yyyy-MM-dd").format(lifeCoupon.getEndDate());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(lifeCoupon.getBuyUseStartTime()) || !StringUtils.isEmpty(lifeCoupon.getBuyUseEndTime())) {
|
|
|
+ forbiddenRule += "\n购买须知使用时间:";
|
|
|
+ if (!StringUtils.isEmpty(lifeCoupon.getBuyUseStartTime())) {
|
|
|
+ forbiddenRule += lifeCoupon.getBuyUseStartTime();
|
|
|
+ }
|
|
|
+ forbiddenRule += " 至 ";
|
|
|
+ if (!StringUtils.isEmpty(lifeCoupon.getBuyUseEndTime())) {
|
|
|
+ forbiddenRule += lifeCoupon.getBuyUseEndTime();
|
|
|
+ }
|
|
|
+ }
|
|
|
return forbiddenRule;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 获取优惠券状态
|