|
@@ -2,7 +2,11 @@ package com.chelvc.cloud.vehicle.server.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.chelvc.cloud.vehicle.api.constant.*;
|
|
|
import com.chelvc.cloud.vehicle.api.dto.CouponDTO;
|
|
@@ -12,6 +16,8 @@ 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.dao.GoodsMapper;
|
|
|
+import com.chelvc.cloud.vehicle.server.dao.UserCouponMapper;
|
|
|
import com.chelvc.cloud.vehicle.server.entity.Coupon;
|
|
|
import com.chelvc.cloud.vehicle.server.entity.FullDiscount;
|
|
|
import com.chelvc.cloud.vehicle.server.entity.Goods;
|
|
@@ -26,11 +32,13 @@ import com.chelvc.framework.database.util.PagingUtils;
|
|
|
import lombok.NonNull;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
|
+import org.apache.poi.ss.formula.functions.T;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.function.Consumer;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -47,6 +55,8 @@ public class CouponServiceImpl extends AbstractPromotionServiceImpl<CouponMapper
|
|
|
private final CouponActivityItemService couponActivityItemService;
|
|
|
private final PromotionGoodsService promotionGoodsService;
|
|
|
private final FullDiscountService fullDiscountService;
|
|
|
+ private final GoodsMapper goodsMapper;
|
|
|
+ private final UserCouponMapper userCouponMapper;
|
|
|
|
|
|
@Override
|
|
|
public List<CouponDTO> listUserGoodsActiveCoupons(@NonNull Long userId, Collection<Long> goodsCouponIds) {
|
|
@@ -110,13 +120,23 @@ public class CouponServiceImpl extends AbstractPromotionServiceImpl<CouponMapper
|
|
|
|
|
|
@Override
|
|
|
public Pagination<CouponDTO> getCouponPaging(@NonNull CouponPagingParam param) {
|
|
|
+ Long merchantId = param.getMerchantId();
|
|
|
+ if (Objects.isNull(merchantId)) {
|
|
|
+ merchantId = PromotionUtils.PLATFORM_ID;
|
|
|
+ }
|
|
|
// 查询优惠券列表
|
|
|
- Page<Coupon> page = this.lambdaQuery()
|
|
|
- .eq(Objects.nonNull(param.getMerchantId()), Coupon::getMerchantId, param.getMerchantId())
|
|
|
- .eq(Objects.nonNull(param.getCouponType()), Coupon::getType, param.getCouponType())
|
|
|
- .eq(Objects.nonNull(param.getCouponStatus()), Coupon::getStatus, param.getCouponStatus())
|
|
|
+ LambdaQueryChainWrapper<Coupon> lambdaQueryChainWrapper = this.lambdaQuery()
|
|
|
+ .eq(Coupon::getMerchantId, merchantId)
|
|
|
.eq(Objects.nonNull(param.getCouponClaimType()), Coupon::getClaimType, param.getCouponClaimType())
|
|
|
- .or().like(!StringUtils.isEmpty(param.getKeyword()), Coupon::getName, param.getKeyword())
|
|
|
+ .eq(Objects.nonNull(param.getCouponType()), Coupon::getType, param.getCouponType())
|
|
|
+ .ge(Objects.nonNull(param.getStartTime()), Coupon::getStartTime, param.getStartTime())
|
|
|
+ .le(Objects.nonNull(param.getEndTime()), Coupon::getStartTime, param.getEndTime())
|
|
|
+ .eq(Coupon::getDeleted, false);
|
|
|
+ if (Objects.nonNull(param.getPromotionStatus())) {
|
|
|
+ lambdaQueryChainWrapper.nested(this.queryPromotionStatus(param.getPromotionStatus()));
|
|
|
+ }
|
|
|
+ Page<Coupon> page = lambdaQueryChainWrapper
|
|
|
+ .like(!StringUtils.isEmpty(param.getKeyword()), Coupon::getName, param.getKeyword())
|
|
|
.orderByDesc(Coupon::getCreateTime).page(PagingUtils.convert(param.getPaging()));
|
|
|
List<Coupon> records = page.getRecords();
|
|
|
if (CollectionUtils.isEmpty(records)) {
|
|
@@ -136,7 +156,7 @@ public class CouponServiceImpl extends AbstractPromotionServiceImpl<CouponMapper
|
|
|
@Override
|
|
|
public void batchDeleteCoupon(@NonNull List<Long> ids) {
|
|
|
// 关闭用户优惠券信息
|
|
|
-// this.userCouponService.closeUserCoupon(ids);
|
|
|
+ this.userCouponMapper.updateUserCouponStatus(ids, UserCouponStatus.CLOSED);
|
|
|
// 删除优惠券关联优惠券活动
|
|
|
this.couponActivityItemService.removeByCouponId(ids);
|
|
|
super.removePromotion(ids);
|
|
@@ -186,7 +206,7 @@ public class CouponServiceImpl extends AbstractPromotionServiceImpl<CouponMapper
|
|
|
// 关闭优惠券,删除相关会员优惠券和券活动
|
|
|
if (startTime == null && endTime == null) {
|
|
|
//关闭用户优惠券信息
|
|
|
-// this.userCouponService.closeUserCoupon(ids);
|
|
|
+ this.userCouponMapper.updateUserCouponStatus(ids, UserCouponStatus.CLOSED);
|
|
|
//删除优惠券关联优惠券活动
|
|
|
this.couponActivityItemService.removeByCouponId(ids);
|
|
|
}
|
|
@@ -312,7 +332,7 @@ public class CouponServiceImpl extends AbstractPromotionServiceImpl<CouponMapper
|
|
|
throw new ResourceUnavailableException("指定商品范围关联id不能为空");
|
|
|
}
|
|
|
for (String id : split) {
|
|
|
- Goods goods = null;
|
|
|
+ Goods goods = this.goodsMapper.selectById(id);
|
|
|
if (goods == null) {
|
|
|
throw new ResourceUnavailableException("商品不存在");
|
|
|
}
|
|
@@ -328,4 +348,23 @@ public class CouponServiceImpl extends AbstractPromotionServiceImpl<CouponMapper
|
|
|
private CouponDTO convert(Coupon coupon) {
|
|
|
return CouponCopier.INSTANCE.copying(coupon);
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ private <T> Consumer<LambdaQueryWrapper<Coupon>> queryPromotionStatus(PromotionStatus promotionStatus) {
|
|
|
+ switch (promotionStatus) {
|
|
|
+ case NEW:
|
|
|
+ return (LambdaQueryWrapper<Coupon> t) -> t.nested(i -> i.gt(Coupon::getStartTime, new Date())
|
|
|
+ .gt(Coupon::getEndTime, new Date()));
|
|
|
+ case START:
|
|
|
+ return (LambdaQueryWrapper<Coupon> t) -> t.nested(i -> i.le(Coupon::getStartTime, new Date())
|
|
|
+ .ge(Coupon::getEndTime, new Date()));
|
|
|
+ case END:
|
|
|
+ return (LambdaQueryWrapper<Coupon> t) -> t.nested(i -> i.lt(Coupon::getStartTime, new Date())
|
|
|
+ .lt(Coupon::getEndTime, new Date()));
|
|
|
+ case CLOSE:
|
|
|
+ return (LambdaQueryWrapper<Coupon> t) -> t.nested(i -> i.isNull(Coupon::getStartTime)
|
|
|
+ .isNull(Coupon::getEndTime));
|
|
|
+ default:
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|