|
@@ -0,0 +1,438 @@
|
|
|
|
|
+package shop.alien.storeplatform.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
|
|
|
+import com.aliyun.tea.utils.StringUtils;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
|
+import org.springframework.beans.BeansException;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import shop.alien.entity.store.*;
|
|
|
|
|
+import shop.alien.entity.store.dto.LifeDiscountCouponDto;
|
|
|
|
|
+import shop.alien.entity.store.vo.LifeDiscountCouponVo;
|
|
|
|
|
+import shop.alien.mapper.*;
|
|
|
|
|
+import shop.alien.storeplatform.service.LifeDiscountCouponPlatformService;
|
|
|
|
|
+import shop.alien.storeplatform.service.LifeDiscountCouponQuantumRulesPlatformService;
|
|
|
|
|
+import shop.alien.util.common.constant.DiscountCouponEnum;
|
|
|
|
|
+
|
|
|
|
|
+import java.time.Instant;
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.ZoneId;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 优惠券表 服务实现类
|
|
|
|
|
+ * </p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author ssk
|
|
|
|
|
+ * @since 2025-02-07
|
|
|
|
|
+ */
|
|
|
|
|
+@Service
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+public class LifeDiscountCouponPlatformServiceImpl extends ServiceImpl<LifeDiscountCouponMapper, LifeDiscountCoupon> implements LifeDiscountCouponPlatformService {
|
|
|
|
|
+
|
|
|
|
|
+ private final LifeDiscountCouponMapper lifeDiscountCouponMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final LifeDiscountCouponUnavailableRulesMapper lifeDiscountCouponUnavailableRulesMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final LifeDiscountCouponQuantumRulesMapper lifeDiscountCouponQuantumRulesMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final LifeDiscountCouponQuantumRulesPlatformService lifeDiscountCouponQuantumRulesService;
|
|
|
|
|
+
|
|
|
|
|
+ private final LifeDiscountCouponUserMapper lifeDiscountCouponUserMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean addDiscountCoupon(LifeDiscountCouponDto lifeDiscountCouponDto) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ //发布优惠券表信息
|
|
|
|
|
+ LifeDiscountCoupon lifeDiscountCoupon = new LifeDiscountCoupon();
|
|
|
|
|
+ BeanUtils.copyProperties(lifeDiscountCouponDto, lifeDiscountCoupon);
|
|
|
|
|
+ // 根据开始领取时间判断可领取状态
|
|
|
|
|
+ // 判断是否在领取时间内
|
|
|
|
|
+
|
|
|
|
|
+ Date now = new Date();
|
|
|
|
|
+ Instant instant = now.toInstant();
|
|
|
|
|
+ ZoneId zoneId = ZoneId.systemDefault();
|
|
|
|
|
+ LocalDate localNow = instant.atZone(zoneId).toLocalDate();
|
|
|
|
|
+ if (lifeDiscountCouponDto.getCouponStatus() == 1 && !StringUtils.isEmpty(lifeDiscountCoupon.getBeginGetDate()) || !StringUtils.isEmpty(lifeDiscountCoupon.getEndGetDate())) {
|
|
|
|
|
+ int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
|
|
|
|
|
+ int endResult = localNow.compareTo(lifeDiscountCoupon.getEndGetDate());
|
|
|
|
|
+ if ((lifeDiscountCouponDto.getCouponStatus() != null && lifeDiscountCouponDto.getCouponStatus() == 0) || (startResult < 0 || endResult > 0)) {
|
|
|
|
|
+ lifeDiscountCoupon.setGetStatus(0);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ lifeDiscountCoupon.setGetStatus(1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 设置有效期
|
|
|
|
|
+ String specifiedDay = lifeDiscountCoupon.getSpecifiedDay();
|
|
|
|
|
+ if (!StringUtils.isEmpty(specifiedDay)) {
|
|
|
|
|
+ int sDay = Integer.parseInt(specifiedDay);
|
|
|
|
|
+ if (sDay > 0 && lifeDiscountCouponDto.getEndGetDate() != null) {
|
|
|
|
|
+ Date endGetDate = Date.from(lifeDiscountCouponDto.getEndGetDate().atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
|
|
+ Date validDate = addDaysToDateJava8(endGetDate, sDay);
|
|
|
|
|
+ LocalDate validDateLocalDate = validDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
|
+ lifeDiscountCoupon.setValidDate(validDateLocalDate);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ lifeDiscountCouponMapper.insert(lifeDiscountCoupon);
|
|
|
|
|
+ //发布优惠券规则信息
|
|
|
|
|
+ //周中规则保存
|
|
|
|
|
+ LifeDiscountCouponUnavailableRules lifeDiscountCouponUnavailableRules = new LifeDiscountCouponUnavailableRules();
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setDiscountCouponId(lifeDiscountCoupon.getId());
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setUnavailableRuleType(DiscountCouponEnum.WEEKDAY_UNAVAILABLE.getValue());
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(lifeDiscountCouponDto.getWeeklyDisabledList())) {
|
|
|
|
|
+ lifeDiscountCouponDto.getWeeklyDisabledList().forEach(weeklyDisabled -> {
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(weeklyDisabled);
|
|
|
|
|
+ lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //节假日规则保存
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setUnavailableRuleType(DiscountCouponEnum.HOLIDAY_UNAVAILABLE.getValue());
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(lifeDiscountCouponDto.getHolidayDisabledList())) {
|
|
|
|
|
+ lifeDiscountCouponDto.getHolidayDisabledList().forEach(holidayDisabled -> {
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(holidayDisabled);
|
|
|
|
|
+ lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //领取规则
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setUnavailableRuleType(DiscountCouponEnum.CLAIM_RULE.getValue());
|
|
|
|
|
+ String claimRule = lifeDiscountCouponDto.getClaimRule();
|
|
|
|
|
+ //领取规则为自定义时,获取自定义数量
|
|
|
|
|
+ if (claimRule != null && claimRule.equals(DiscountCouponEnum.CUSTOMIZE.getValue())) {
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setCustomizeValue(lifeDiscountCouponDto.getClaimRuleCustomizeValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(lifeDiscountCouponDto.getClaimRule());
|
|
|
|
|
+ lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
|
|
|
|
|
+
|
|
|
|
|
+ //指定时间段可用规则
|
|
|
|
|
+ List<LifeDiscountCouponQuantumRules> availableTimeQuantumList = lifeDiscountCouponDto.getAvailableTimeQuantum();
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(availableTimeQuantumList)) {
|
|
|
|
|
+ availableTimeQuantumList.forEach(availableTimeQuantum -> {
|
|
|
|
|
+ availableTimeQuantum.setDiscountCouponId(lifeDiscountCoupon.getId());
|
|
|
|
|
+ });
|
|
|
|
|
+ lifeDiscountCouponQuantumRulesService.saveBatch(availableTimeQuantumList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //自定义时间段不可用规则
|
|
|
|
|
+ List<LifeDiscountCouponQuantumRules> customizeUnavailableTimeQuantumList = lifeDiscountCouponDto.getCustomizeUnavailableTimeQuantum();
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(customizeUnavailableTimeQuantumList)) {
|
|
|
|
|
+ customizeUnavailableTimeQuantumList.forEach(customizeUnavailableTimeQuantum -> {
|
|
|
|
|
+ customizeUnavailableTimeQuantum.setDiscountCouponId(lifeDiscountCoupon.getId());
|
|
|
|
|
+ });
|
|
|
|
|
+ lifeDiscountCouponQuantumRulesService.saveBatch(customizeUnavailableTimeQuantumList);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (BeansException e) {
|
|
|
|
|
+ log.error("LifeDiscountCouponServiceImpl.receiveCoupon ERROR Msg=" + e.getMessage());
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean editDiscountCoupon(LifeDiscountCouponDto lifeDiscountCouponDto) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ //发布优惠券表信息
|
|
|
|
|
+ LifeDiscountCoupon lifeDiscountCoupon = new LifeDiscountCoupon();
|
|
|
|
|
+ lifeDiscountCoupon.setId(Integer.parseInt(lifeDiscountCouponDto.getCouponId()));
|
|
|
|
|
+ BeanUtils.copyProperties(lifeDiscountCouponDto, lifeDiscountCoupon);
|
|
|
|
|
+
|
|
|
|
|
+ // 根据开始领取时间判断可领取状态
|
|
|
|
|
+ // 判断是否在领取时间内
|
|
|
|
|
+ Date now = new Date();
|
|
|
|
|
+ Instant instant = now.toInstant();
|
|
|
|
|
+ ZoneId zoneId = ZoneId.systemDefault();
|
|
|
|
|
+ LocalDate localNow = instant.atZone(zoneId).toLocalDate();
|
|
|
|
|
+ if (lifeDiscountCouponDto.getCouponStatus() == 1 && !StringUtils.isEmpty(lifeDiscountCoupon.getBeginGetDate()) || !StringUtils.isEmpty(lifeDiscountCoupon.getEndGetDate())) {
|
|
|
|
|
+ int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
|
|
|
|
|
+ int endResult = localNow.compareTo(lifeDiscountCoupon.getEndGetDate());
|
|
|
|
|
+ if ((lifeDiscountCouponDto.getCouponStatus() != null && lifeDiscountCouponDto.getCouponStatus() == 0) || (startResult < 0 || endResult > 0)) {
|
|
|
|
|
+ lifeDiscountCoupon.setGetStatus(0);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ lifeDiscountCoupon.setGetStatus(1);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (lifeDiscountCouponDto.getCouponStatus() == 0) {
|
|
|
|
|
+ lifeDiscountCoupon.setGetStatus(0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 设置有效期
|
|
|
|
|
+ String specifiedDay = lifeDiscountCouponDto.getSpecifiedDay();
|
|
|
|
|
+ if (!StringUtils.isEmpty(specifiedDay)) {
|
|
|
|
|
+ int sDay = Integer.parseInt(specifiedDay);
|
|
|
|
|
+ if (sDay > 0 && lifeDiscountCouponDto.getEndGetDate() != null) {
|
|
|
|
|
+ Date endGetDate = Date.from(lifeDiscountCouponDto.getEndGetDate().atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
|
|
+ Date validDate = addDaysToDateJava8(endGetDate, sDay);
|
|
|
|
|
+ LocalDate validDateLocalDate = validDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
|
+ lifeDiscountCoupon.setValidDate(validDateLocalDate);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ lifeDiscountCouponMapper.updateById(lifeDiscountCoupon);
|
|
|
|
|
+ //发布优惠券规则信息
|
|
|
|
|
+ //先删除之前所有规则
|
|
|
|
|
+ LambdaQueryWrapper<LifeDiscountCouponUnavailableRules> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq(LifeDiscountCouponUnavailableRules::getDiscountCouponId, lifeDiscountCoupon.getId());
|
|
|
|
|
+ lifeDiscountCouponUnavailableRulesMapper.delete(queryWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ //周中规则保存
|
|
|
|
|
+ LifeDiscountCouponUnavailableRules lifeDiscountCouponUnavailableRules = new LifeDiscountCouponUnavailableRules();
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setDiscountCouponId(lifeDiscountCoupon.getId());
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setUnavailableRuleType(DiscountCouponEnum.WEEKDAY_UNAVAILABLE.getValue());
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(lifeDiscountCouponDto.getWeeklyDisabledList())) {
|
|
|
|
|
+ lifeDiscountCouponDto.getWeeklyDisabledList().forEach(weeklyDisabled -> {
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(weeklyDisabled);
|
|
|
|
|
+ lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //节假日规则保存
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setUnavailableRuleType(DiscountCouponEnum.HOLIDAY_UNAVAILABLE.getValue());
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(lifeDiscountCouponDto.getHolidayDisabledList())) {
|
|
|
|
|
+ lifeDiscountCouponDto.getHolidayDisabledList().forEach(holidayDisabled -> {
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(holidayDisabled);
|
|
|
|
|
+ lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //领取规则
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setUnavailableRuleType(DiscountCouponEnum.CLAIM_RULE.getValue());
|
|
|
|
|
+ lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(lifeDiscountCouponDto.getClaimRule());
|
|
|
|
|
+ lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
|
|
|
|
|
+
|
|
|
|
|
+ // 删除优惠券时间段规则信息
|
|
|
|
|
+ LambdaQueryWrapper<LifeDiscountCouponQuantumRules> lifeDiscountCouponQuantumRulesLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ lifeDiscountCouponQuantumRulesLambdaQueryWrapper.eq(LifeDiscountCouponQuantumRules::getDiscountCouponId, lifeDiscountCoupon.getId());
|
|
|
|
|
+ lifeDiscountCouponQuantumRulesMapper.delete(lifeDiscountCouponQuantumRulesLambdaQueryWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ // 保存指定时间段可用规则
|
|
|
|
|
+ List<LifeDiscountCouponQuantumRules> availableTimeQuantumList = lifeDiscountCouponDto.getAvailableTimeQuantum();
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(availableTimeQuantumList)) {
|
|
|
|
|
+ availableTimeQuantumList.forEach(availableTimeQuantum -> {
|
|
|
|
|
+ availableTimeQuantum.setDiscountCouponId(lifeDiscountCoupon.getId());
|
|
|
|
|
+ });
|
|
|
|
|
+ lifeDiscountCouponQuantumRulesService.saveBatch(availableTimeQuantumList);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 保存自定义时间段不可用规则
|
|
|
|
|
+ List<LifeDiscountCouponQuantumRules> customizeUnavailableTimeQuantumList = lifeDiscountCouponDto.getCustomizeUnavailableTimeQuantum();
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(customizeUnavailableTimeQuantumList)) {
|
|
|
|
|
+ customizeUnavailableTimeQuantumList.forEach(customizeUnavailableTimeQuantum -> {
|
|
|
|
|
+ customizeUnavailableTimeQuantum.setDiscountCouponId(lifeDiscountCoupon.getId());
|
|
|
|
|
+ });
|
|
|
|
|
+ lifeDiscountCouponQuantumRulesService.saveBatch(customizeUnavailableTimeQuantumList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (BeansException e) {
|
|
|
|
|
+ log.error("LifeDiscountCouponServiceImpl.editDiscountCoupon ERROR Msg=" + e.getMessage());
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean deleteDiscountCoupon(Integer id) {
|
|
|
|
|
+ //删除优惠券表信息
|
|
|
|
|
+ lifeDiscountCouponMapper.deleteById(id);
|
|
|
|
|
+ //删除优惠券规则信息
|
|
|
|
|
+ lifeDiscountCouponUnavailableRulesMapper.delete(new LambdaQueryWrapper<LifeDiscountCouponUnavailableRules>().eq(LifeDiscountCouponUnavailableRules::getDiscountCouponId, id));
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean updateCouponSingleQty(Integer id, Integer singleQty) {
|
|
|
|
|
+ return lifeDiscountCouponMapper.updateCouponById(id, singleQty) > 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean cutDiscountCouponStatus(String counponId) {
|
|
|
|
|
+ LifeDiscountCoupon lifeDiscountCoupon = lifeDiscountCouponMapper.selectById(counponId);
|
|
|
|
|
+ if (lifeDiscountCoupon.getGetStatus() == Integer.parseInt(DiscountCouponEnum.NO_GET.getValue())) {
|
|
|
|
|
+ Date now = new Date();
|
|
|
|
|
+ Instant instant = now.toInstant();
|
|
|
|
|
+ ZoneId zoneId = ZoneId.systemDefault();
|
|
|
|
|
+ LocalDate localNow = instant.atZone(zoneId).toLocalDate();
|
|
|
|
|
+ lifeDiscountCoupon.setBeginGetDate(localNow);
|
|
|
|
|
+ }
|
|
|
|
|
+ lifeDiscountCoupon.setGetStatus(lifeDiscountCoupon.getGetStatus() == Integer.parseInt(DiscountCouponEnum.NO_GET.getValue()) ? Integer.parseInt(DiscountCouponEnum.CAN_GET.getValue()) : Integer.parseInt(DiscountCouponEnum.NO_GET.getValue()));
|
|
|
|
|
+ lifeDiscountCouponMapper.updateById(lifeDiscountCoupon);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public LifeDiscountCouponVo getCounponDetailById(String counponId, UserLoginInfo userLoginInfo) {
|
|
|
|
|
+ LifeDiscountCoupon lifeDiscountCoupon = lifeDiscountCouponMapper.selectById(counponId);
|
|
|
|
|
+ LifeDiscountCouponVo lifeDiscountCouponVo = new LifeDiscountCouponVo();
|
|
|
|
|
+ lifeDiscountCouponVo.setCouponId(Integer.parseInt(counponId));
|
|
|
|
|
+ BeanUtils.copyProperties(lifeDiscountCoupon, lifeDiscountCouponVo);
|
|
|
|
|
+ //查规则信息
|
|
|
|
|
+ LambdaQueryWrapper<LifeDiscountCouponUnavailableRules> rulesLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ rulesLambdaQueryWrapper.eq(LifeDiscountCouponUnavailableRules::getDiscountCouponId, counponId);
|
|
|
|
|
+ List<LifeDiscountCouponUnavailableRules> lifeDiscountCouponUnavailableRules = lifeDiscountCouponUnavailableRulesMapper.selectList(rulesLambdaQueryWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ List<String> weeklyDisabledList = new ArrayList<>();
|
|
|
|
|
+ List<String> holidayDisabledList = new ArrayList<>();
|
|
|
|
|
+ String claimRule = "";
|
|
|
|
|
+ for (LifeDiscountCouponUnavailableRules rule : lifeDiscountCouponUnavailableRules) {
|
|
|
|
|
+ if (rule.getUnavailableRuleType().equals(DiscountCouponEnum.WEEKDAY_UNAVAILABLE.getValue())) {
|
|
|
|
|
+ weeklyDisabledList.add(rule.getUnavailableRuleValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (rule.getUnavailableRuleType().equals(DiscountCouponEnum.HOLIDAY_UNAVAILABLE.getValue())) {
|
|
|
|
|
+ holidayDisabledList.add(rule.getUnavailableRuleValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (rule.getUnavailableRuleType().equals(DiscountCouponEnum.CLAIM_RULE.getValue())) {
|
|
|
|
|
+ claimRule = rule.getUnavailableRuleValue();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ lifeDiscountCouponVo.setWeeklyDisabledList(weeklyDisabledList);
|
|
|
|
|
+ lifeDiscountCouponVo.setHolidayDisabledList(holidayDisabledList);
|
|
|
|
|
+ lifeDiscountCouponVo.setClaimRule(claimRule);
|
|
|
|
|
+
|
|
|
|
|
+ // 查询时间段规则信息
|
|
|
|
|
+ LambdaQueryWrapper<LifeDiscountCouponQuantumRules> quantumRulesLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ quantumRulesLambdaQueryWrapper.eq(LifeDiscountCouponQuantumRules::getDiscountCouponId, counponId);
|
|
|
|
|
+ List<LifeDiscountCouponQuantumRules> lifeDiscountCouponQuantumRulesList = lifeDiscountCouponQuantumRulesMapper.selectList(quantumRulesLambdaQueryWrapper);
|
|
|
|
|
+ List<LifeDiscountCouponQuantumRules> availableTimeQuantumList = new ArrayList<>();
|
|
|
|
|
+ List<LifeDiscountCouponQuantumRules> customizeUnavailableTimeQuantumList = new ArrayList<>();
|
|
|
|
|
+ for (LifeDiscountCouponQuantumRules lifeDiscountCouponQuantumRules : lifeDiscountCouponQuantumRulesList) {
|
|
|
|
|
+ if (lifeDiscountCouponQuantumRules.getTimeQuantumType().equals(DiscountCouponEnum.AVAILABLE_TIME_QUANTUM.getValue())) {
|
|
|
|
|
+ availableTimeQuantumList.add(lifeDiscountCouponQuantumRules);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (lifeDiscountCouponQuantumRules.getTimeQuantumType().equals(DiscountCouponEnum.UNAVAILABLE_TIME_QUANTUM.getValue())) {
|
|
|
|
|
+ customizeUnavailableTimeQuantumList.add(lifeDiscountCouponQuantumRules);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ lifeDiscountCouponVo.setAvailableTimeQuantum(availableTimeQuantumList);
|
|
|
|
|
+ lifeDiscountCouponVo.setCustomizeUnavailableTimeQuantum(customizeUnavailableTimeQuantumList);
|
|
|
|
|
+ return lifeDiscountCouponVo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static Date addDaysToDateJava8(Date date, int days) {
|
|
|
|
|
+ // 将Date转换为Instant
|
|
|
|
|
+ Instant instant = date.toInstant();
|
|
|
|
|
+
|
|
|
|
|
+ // 转换为LocalDate并加天数
|
|
|
|
|
+ LocalDate localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
|
+ LocalDate newLocalDate = localDate.plusDays(days);
|
|
|
|
|
+
|
|
|
|
|
+ // 转换回Date
|
|
|
|
|
+ return Date.from(newLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获取纯日期
|
|
|
|
|
+ public static Date getPureDate(Date date) {
|
|
|
|
|
+ Instant instant = date.toInstant();
|
|
|
|
|
+ LocalDate localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
|
+ LocalDateTime localDateTime = localDate.atStartOfDay(); // 时间为 00:00
|
|
|
|
|
+ return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public IPage<LifeDiscountCouponVo> getStoreAllCouponList(String storeId, UserLoginInfo userLoginInfo, int page, int size, String couponName, Integer couponsFromType, Integer couponStatus) {
|
|
|
|
|
+
|
|
|
|
|
+ IPage<LifeDiscountCoupon> iPage = new Page<>(page, size);
|
|
|
|
|
+ List<LifeDiscountCouponVo> lifeDiscountCouponVos = new ArrayList<>();
|
|
|
|
|
+ LambdaQueryWrapper<LifeDiscountCoupon> lifeDiscountCouponLambdaQueryWrapper = new LambdaQueryWrapper<LifeDiscountCoupon>();
|
|
|
|
|
+
|
|
|
|
|
+ //如果couponName不为空,则模糊查询
|
|
|
|
|
+ if (!StringUtils.isEmpty(couponName)) {
|
|
|
|
|
+ lifeDiscountCouponLambdaQueryWrapper.like(LifeDiscountCoupon::getName, couponName);
|
|
|
|
|
+ }
|
|
|
|
|
+ //获取当日日期
|
|
|
|
|
+ Date now = new Date();
|
|
|
|
|
+ //如果根据类型查询
|
|
|
|
|
+ if (!StringUtils.isEmpty(couponStatus) && couponStatus.equals(1)) {//进行中
|
|
|
|
|
+ //开始时间小于当前时间
|
|
|
|
|
+ lifeDiscountCouponLambdaQueryWrapper.le(LifeDiscountCoupon::getBeginGetDate, getPureDate(now));
|
|
|
|
|
+ //结束时间大于当前时间
|
|
|
|
|
+ lifeDiscountCouponLambdaQueryWrapper.ge(LifeDiscountCoupon::getEndGetDate, getPureDate(now));
|
|
|
|
|
+ lifeDiscountCouponLambdaQueryWrapper.gt(LifeDiscountCoupon::getSingleQty, 0);
|
|
|
|
|
+
|
|
|
|
|
+ //不要已暂停关闭领取的
|
|
|
|
|
+ lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getGetStatus, 1);
|
|
|
|
|
+ lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getCouponStatus, 1);
|
|
|
|
|
+ } else if (!StringUtils.isEmpty(couponStatus) && couponStatus.equals(2)) {//已结束
|
|
|
|
|
+ //结束时间小于当前时间
|
|
|
|
|
+ lifeDiscountCouponLambdaQueryWrapper.lt(LifeDiscountCoupon::getEndGetDate, getPureDate(now));
|
|
|
|
|
+
|
|
|
|
|
+ //不要已暂停关闭领取的
|
|
|
|
|
+ lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getGetStatus, 1);
|
|
|
|
|
+ lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getCouponStatus, 1);
|
|
|
|
|
+ } else if (!StringUtils.isEmpty(couponStatus) && couponStatus.equals(3)) {
|
|
|
|
|
+ lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getCouponStatus, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getStoreId, storeId);
|
|
|
|
|
+ lifeDiscountCouponLambdaQueryWrapper.orderByDesc(LifeDiscountCoupon::getCreatedTime);
|
|
|
|
|
+ //根据店铺id查询该店铺的优惠券,状态是开启领取的券
|
|
|
|
|
+ IPage<LifeDiscountCoupon> lifeDiscountCouponIPage = lifeDiscountCouponMapper.selectPage(iPage, lifeDiscountCouponLambdaQueryWrapper);
|
|
|
|
|
+ for (LifeDiscountCoupon lifeDiscountCoupon : lifeDiscountCouponIPage.getRecords()) {
|
|
|
|
|
+ LifeDiscountCouponVo lifeDiscountCouponVo = new LifeDiscountCouponVo();
|
|
|
|
|
+ lifeDiscountCouponVo.setCouponId(lifeDiscountCoupon.getId());
|
|
|
|
|
+ //处理一下该优惠券的状态 状态(0:进行中,1:已结束,2:未开始,3:已暂停)
|
|
|
|
|
+ // 将 Date 转换为 LocalDate
|
|
|
|
|
+ Instant instant = now.toInstant();
|
|
|
|
|
+ ZoneId zoneId = ZoneId.systemDefault();
|
|
|
|
|
+ LocalDate localNow = instant.atZone(zoneId).toLocalDate();
|
|
|
|
|
+ if (!StringUtils.isEmpty(lifeDiscountCoupon.getBeginGetDate()) && !StringUtils.isEmpty(lifeDiscountCoupon.getEndGetDate())) {
|
|
|
|
|
+ int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
|
|
|
|
|
+ int endResult = localNow.compareTo(lifeDiscountCoupon.getEndGetDate());
|
|
|
|
|
+ if (lifeDiscountCoupon.getCouponStatus() == 0) {
|
|
|
|
|
+ //如果为草稿则状态为未开始
|
|
|
|
|
+ lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.DRAFT.getValue()));
|
|
|
|
|
+ } else if (lifeDiscountCoupon.getSingleQty() == null || lifeDiscountCoupon.getSingleQty() == 0) {//无库存则已售罄 //如果当前时间小于开始时间
|
|
|
|
|
+ lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_SOLD_OUT.getValue()));
|
|
|
|
|
+ } else if (startResult < 0) {
|
|
|
|
|
+ lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()));
|
|
|
|
|
+ } else if (lifeDiscountCoupon.getGetStatus() == null || lifeDiscountCoupon.getGetStatus().toString().equals(DiscountCouponEnum.NO_GET.getValue())) {
|
|
|
|
|
+ lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.SUSPEND_GET.getValue()));
|
|
|
|
|
+ } else if (endResult > 0) {
|
|
|
|
|
+ lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.FINISHED.getValue()));
|
|
|
|
|
+ } else if (startResult >= 0 && endResult <= 0) {
|
|
|
|
|
+ lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue()));
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (lifeDiscountCoupon.getCouponStatus() == 0) {
|
|
|
|
|
+ //如果为草稿则状态为未开始
|
|
|
|
|
+ lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.DRAFT.getValue()));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 开始结束时间为空,数据异常跳过
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 查询三个规则
|
|
|
|
|
+ List<LifeDiscountCouponUnavailableRules> discountCouponId = lifeDiscountCouponUnavailableRulesMapper.selectList(new QueryWrapper<LifeDiscountCouponUnavailableRules>().eq("discount_coupon_id", lifeDiscountCoupon.getId()));
|
|
|
|
|
+ Map<String, List<LifeDiscountCouponUnavailableRules>> collect = discountCouponId.stream().collect(Collectors.groupingBy(x -> x.getUnavailableRuleType()));
|
|
|
|
|
+ if (collect.containsKey(DiscountCouponEnum.WEEKDAY_UNAVAILABLE.getValue())) {
|
|
|
|
|
+ lifeDiscountCouponVo.setWeeklyDisabledList(collect.get(DiscountCouponEnum.WEEKDAY_UNAVAILABLE.getValue()).stream().map(x -> x.getUnavailableRuleValue()).collect(Collectors.toList()));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (collect.containsKey(DiscountCouponEnum.HOLIDAY_UNAVAILABLE.getValue())) {
|
|
|
|
|
+ lifeDiscountCouponVo.setHolidayDisabledList(collect.get(DiscountCouponEnum.HOLIDAY_UNAVAILABLE.getValue()).stream().map(x -> x.getUnavailableRuleValue()).collect(Collectors.toList()));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (collect.containsKey(DiscountCouponEnum.CLAIM_RULE.getValue())) {
|
|
|
|
|
+ lifeDiscountCouponVo.setClaimRule(collect.get(DiscountCouponEnum.CLAIM_RULE.getValue()).get(0).getUnavailableRuleValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ BeanUtils.copyProperties(lifeDiscountCoupon, lifeDiscountCouponVo);
|
|
|
|
|
+
|
|
|
|
|
+ //查询已领取多少券
|
|
|
|
|
+ LambdaQueryWrapper<LifeDiscountCouponUser> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq(LifeDiscountCouponUser::getCouponId, lifeDiscountCoupon.getId());
|
|
|
|
|
+ queryWrapper.eq(LifeDiscountCouponUser::getDeleteFlag, 0);
|
|
|
|
|
+ queryWrapper.in(LifeDiscountCouponUser::getStatus, 0, 1);
|
|
|
|
|
+ List<LifeDiscountCouponUser> lifeDiscountCouponUsers = lifeDiscountCouponUserMapper.selectList(queryWrapper);
|
|
|
|
|
+ lifeDiscountCouponVo.setQuantityClaimed(lifeDiscountCouponUsers.size());
|
|
|
|
|
+
|
|
|
|
|
+ lifeDiscountCouponVos.add(lifeDiscountCouponVo);
|
|
|
|
|
+ }
|
|
|
|
|
+ IPage<LifeDiscountCouponVo> lifeDiscountCouponVoIPage = new Page<>();
|
|
|
|
|
+ BeanUtils.copyProperties(lifeDiscountCouponIPage, lifeDiscountCouponVoIPage);
|
|
|
|
|
+ lifeDiscountCouponVoIPage.setRecords(lifeDiscountCouponVos);
|
|
|
|
|
+ return lifeDiscountCouponVoIPage;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|