|
@@ -1,19 +1,23 @@
|
|
|
package com.chelvc.cloud.vehicle.server.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.chelvc.cloud.vehicle.api.constant.CouponType;
|
|
|
-import com.chelvc.cloud.vehicle.api.constant.PromotionScopeType;
|
|
|
-import com.chelvc.cloud.vehicle.api.constant.PromotionType;
|
|
|
+import com.chelvc.cloud.vehicle.api.constant.*;
|
|
|
import com.chelvc.cloud.vehicle.api.dto.CouponDTO;
|
|
|
import com.chelvc.cloud.vehicle.api.param.CouponModifyParam;
|
|
|
import com.chelvc.cloud.vehicle.api.param.CouponPagingParam;
|
|
|
+import com.chelvc.cloud.vehicle.api.param.FullDiscountQueryParam;
|
|
|
+import com.chelvc.cloud.vehicle.api.param.PromotionGoodsQueryParam;
|
|
|
import com.chelvc.cloud.vehicle.server.copier.CouponCopier;
|
|
|
import com.chelvc.cloud.vehicle.server.dao.CouponMapper;
|
|
|
import com.chelvc.cloud.vehicle.server.entity.Coupon;
|
|
|
+import com.chelvc.cloud.vehicle.server.entity.FullDiscount;
|
|
|
import com.chelvc.cloud.vehicle.server.entity.Goods;
|
|
|
-import com.chelvc.cloud.vehicle.server.service.CouponService;
|
|
|
-import com.chelvc.cloud.vehicle.server.service.GoodsService;
|
|
|
+import com.chelvc.cloud.vehicle.server.entity.PromotionGoods;
|
|
|
+import com.chelvc.cloud.vehicle.server.service.*;
|
|
|
+import com.chelvc.cloud.vehicle.server.util.PromotionUtils;
|
|
|
import com.chelvc.framework.base.exception.ResourceUnavailableException;
|
|
|
import com.chelvc.framework.base.util.ResourceUtils;
|
|
|
import com.chelvc.framework.common.model.Pagination;
|
|
@@ -26,9 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -43,6 +45,10 @@ public class CouponServiceImpl extends AbstractPromotionServiceImpl<CouponMapper
|
|
|
com.chelvc.cloud.vehicle.api.service.CouponService {
|
|
|
|
|
|
private final GoodsService goodsService;
|
|
|
+ private final UserCouponService userCouponService;
|
|
|
+ private final CouponActivityItemService couponActivityItemService;
|
|
|
+ private final PromotionGoodsService promotionGoodsService;
|
|
|
+ private final FullDiscountService fullDiscountService;
|
|
|
|
|
|
@Override
|
|
|
public List<CouponDTO> listUserGoodsActiveCoupons(@NonNull Long userId, Collection<Long> goodsCouponIds) {
|
|
@@ -52,8 +58,6 @@ public class CouponServiceImpl extends AbstractPromotionServiceImpl<CouponMapper
|
|
|
@Override
|
|
|
public Long addCoupon(@NonNull CouponModifyParam param) {
|
|
|
Coupon coupon = CouponCopier.INSTANCE.copying(param);
|
|
|
- coupon.setUsedNum(0);
|
|
|
- coupon.setReceivedNum(0);
|
|
|
this.save(coupon);
|
|
|
return coupon.getId();
|
|
|
}
|
|
@@ -62,7 +66,14 @@ public class CouponServiceImpl extends AbstractPromotionServiceImpl<CouponMapper
|
|
|
public void updateCoupon(@NonNull Long id, @NonNull CouponModifyParam param) {
|
|
|
Coupon coupon = ResourceUtils.required(this.getById(id), "优惠券不存在");
|
|
|
CouponCopier.INSTANCE.copying(param, coupon);
|
|
|
+ // 检查促销状态
|
|
|
+ this.checkStatus(coupon);
|
|
|
+ // 检查促销参数
|
|
|
+ this.checkPromotion(coupon);
|
|
|
+ // 修改优惠券信息
|
|
|
this.updateById(coupon);
|
|
|
+ // 更新促销商品信息
|
|
|
+ this.updatePromotionsGoods(coupon);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -74,9 +85,31 @@ public class CouponServiceImpl extends AbstractPromotionServiceImpl<CouponMapper
|
|
|
@Override
|
|
|
public CouponDTO getCoupon(@NonNull Long id) {
|
|
|
Coupon coupon = ResourceUtils.required(this.getById(id), "优惠券不存在");
|
|
|
+ List<PromotionGoods> promotionGoods = this.promotionGoodsService
|
|
|
+ .listFindAll(PromotionGoodsQueryParam.builder().promotionId(id).build());
|
|
|
+ if (CollectionUtil.isNotEmpty(promotionGoods)) {
|
|
|
+ coupon.setPromotionGoodsList(promotionGoods);
|
|
|
+ }
|
|
|
return this.convert(coupon);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Long saveCoupon(@NonNull CouponModifyParam param) {
|
|
|
+ Coupon coupon = CouponCopier.INSTANCE.copying(param);
|
|
|
+ if (PromotionUtils.PLATFORM_ID.equals(coupon.getMerchantId())) {
|
|
|
+ coupon.setMerchantName(PromotionUtils.PLATFORM_NAME);
|
|
|
+ }
|
|
|
+ // 初始化促销信息
|
|
|
+ this.initPromotion(coupon);
|
|
|
+ // 检查促销参数
|
|
|
+ this.checkPromotion(coupon);
|
|
|
+ // 保存优惠券信息
|
|
|
+ this.save(coupon);
|
|
|
+ // 更新促销商品信息
|
|
|
+ this.updatePromotionsGoods(coupon);
|
|
|
+ return coupon.getId();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Pagination<CouponDTO> getCouponPaging(@NonNull CouponPagingParam param) {
|
|
|
// 查询优惠券列表
|
|
@@ -97,6 +130,20 @@ public class CouponServiceImpl extends AbstractPromotionServiceImpl<CouponMapper
|
|
|
return PagingUtils.convert(page, clients);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void updateCouponStatus(@NonNull CouponModifyParam param) {
|
|
|
+ this.updateStatus(param.getIds(), param.getStartTime(), param.getEndTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void batchDeleteCoupon(@NonNull List<Long> ids) {
|
|
|
+ // 关闭用户优惠券信息
|
|
|
+ this.userCouponService.closeUserCoupon(ids);
|
|
|
+ // 删除优惠券关联优惠券活动
|
|
|
+ this.couponActivityItemService.removeByCouponId(ids);
|
|
|
+ super.removePromotion(ids);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Pagination<CouponDTO> getMerchantCouponPaging(@NonNull Long merchantId, @NonNull CouponPagingParam param) {
|
|
|
// 查询优惠券列表
|
|
@@ -126,20 +173,28 @@ public class CouponServiceImpl extends AbstractPromotionServiceImpl<CouponMapper
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean updatePromotion(Coupon promotions) {
|
|
|
- return super.updatePromotion(promotions);
|
|
|
- }
|
|
|
+ public boolean updateStatus(List<Long> ids, Date startTime, Date endTime) {
|
|
|
+ List<Coupon> coupons = this.lambdaQuery()
|
|
|
+ .in(Coupon::getId, ids)
|
|
|
+ .eq(Coupon::getRangeDayType, CouponRangeDay.DYNAMICTIME).list();
|
|
|
+ if (!coupons.isEmpty()) {
|
|
|
+ LambdaUpdateWrapper<Coupon> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.in(Coupon::getId, coupons.stream().map(Coupon::getId).collect(Collectors.toList()));
|
|
|
+ updateWrapper.set(Coupon::getEffectiveDays, 0);
|
|
|
+ updateWrapper.set(Coupon::getPromotionStatus, PromotionStatus.CLOSE);
|
|
|
+ this.update(updateWrapper);
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public boolean updateStatus(List<Long> ids, Long startTime, Long endTime) {
|
|
|
+ // 关闭优惠券,删除相关会员优惠券和券活动
|
|
|
+ if (startTime == null && endTime == null) {
|
|
|
+ //关闭用户优惠券信息
|
|
|
+ this.userCouponService.closeUserCoupon(ids);
|
|
|
+ //删除优惠券关联优惠券活动
|
|
|
+ this.couponActivityItemService.removeByCouponId(ids);
|
|
|
+ }
|
|
|
return super.updateStatus(ids, startTime, endTime);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public boolean removePromotion(List<Long> ids) {
|
|
|
- return super.removePromotion(ids);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void initPromotion(Coupon coupon) {
|
|
|
coupon.setUsedNum(0);
|
|
@@ -186,23 +241,40 @@ public class CouponServiceImpl extends AbstractPromotionServiceImpl<CouponMapper
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void checkStatus(Coupon promotion) {
|
|
|
- super.checkStatus(promotion);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean updatePromotionsGoods(Coupon promotion) {
|
|
|
- return super.updatePromotionsGoods(promotion);
|
|
|
+ public void checkStatus(Coupon coupon) {
|
|
|
+ super.checkStatus(coupon);
|
|
|
+ FullDiscountQueryParam queryParam = new FullDiscountQueryParam();
|
|
|
+ queryParam.setCouponFlag(true);
|
|
|
+ queryParam.setCouponId(coupon.getId());
|
|
|
+ queryParam.setPromotionStatus(PromotionStatus.START.name());
|
|
|
+ List<FullDiscount> fullDiscounts = fullDiscountService.listFindAll(queryParam);
|
|
|
+ if (fullDiscounts != null && !fullDiscounts.isEmpty()) {
|
|
|
+ throw new ResourceUnavailableException("当前优惠券参与了促销活动【" + fullDiscounts.get(0).getPromotionName()
|
|
|
+ + "】不能进行编辑删除操作");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void updateEsGoodsIndex(Coupon promotion) {
|
|
|
- super.updateEsGoodsIndex(promotion);
|
|
|
+ public boolean updatePromotionsGoods(Coupon coupon) {
|
|
|
+ boolean result = super.updatePromotionsGoods(coupon);
|
|
|
+ if (!PromotionStatus.CLOSE.equals(coupon.getPromotionStatus()) &&
|
|
|
+ PromotionScopeType.PORTION_GOODS.equals(coupon.getScopeType())) {
|
|
|
+ this.promotionGoodsService.deletePromotionGoods(Collections.singletonList(coupon.getId()));
|
|
|
+ List<PromotionGoods> promotionGoodsList = PromotionUtils.promotionGoodsInit(coupon.getPromotionGoodsList(),
|
|
|
+ coupon, this.getPromotionType());
|
|
|
+ for (PromotionGoods promotionGoods : promotionGoodsList) {
|
|
|
+ promotionGoods.setMerchantId(coupon.getMerchantId());
|
|
|
+ promotionGoods.setMerchantName(coupon.getMerchantName());
|
|
|
+ }
|
|
|
+ //促销活动商品更新
|
|
|
+ result = this.promotionGoodsService.saveBatch(promotionGoodsList);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PromotionType getPromotionType() {
|
|
|
- return null;
|
|
|
+ return PromotionType.COUPON;
|
|
|
}
|
|
|
|
|
|
/**
|