mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-22 12:48:59 +08:00
feat: 新增优惠券关联指定商品分类
This commit is contained in:
parent
293bd6c81d
commit
0bd0d107c1
@ -1,16 +1,21 @@
|
||||
package com.youlai.mall.sms.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.youlai.mall.sms.converter.SmsCouponConverter;
|
||||
import com.youlai.mall.sms.mapper.SmsCouponMapper;
|
||||
import com.youlai.mall.sms.pojo.entity.SmsCoupon;
|
||||
import com.youlai.mall.sms.pojo.entity.SmsCouponSpuCategory;
|
||||
import com.youlai.mall.sms.pojo.form.CouponForm;
|
||||
import com.youlai.mall.sms.pojo.query.CouponPageQuery;
|
||||
import com.youlai.mall.sms.pojo.vo.CouponPageVO;
|
||||
import com.youlai.mall.sms.service.SmsCouponService;
|
||||
import com.youlai.mall.sms.service.SmsCouponSpuCategoryService;
|
||||
import com.youlai.mall.sms.service.SmsCouponSpuService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -26,11 +31,14 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon>
|
||||
implements SmsCouponService {
|
||||
public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon> implements SmsCouponService {
|
||||
|
||||
private final SmsCouponConverter smsCouponConverter;
|
||||
|
||||
private final SmsCouponSpuCategoryService smsCouponSpuCategoryService;
|
||||
|
||||
private final SmsCouponSpuService smsCouponSpuService;
|
||||
|
||||
/**
|
||||
* 优惠券分页列表
|
||||
*
|
||||
@ -72,6 +80,29 @@ public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon
|
||||
public boolean saveCoupon(CouponForm couponForm) {
|
||||
SmsCoupon smsCoupon = smsCouponConverter.form2Entity(couponForm);
|
||||
boolean result = this.save(smsCoupon);
|
||||
|
||||
if (result) {
|
||||
|
||||
Long couponId = smsCoupon.getId();
|
||||
List<Long> spuCategoryIds = couponForm.getSpuCategoryIds();
|
||||
|
||||
Integer applicationScope = couponForm.getApplicationScope();
|
||||
|
||||
|
||||
if (CollectionUtil.isNotEmpty(spuCategoryIds)) {
|
||||
List<SmsCouponSpuCategory> smsCouponSpuCategories = spuCategoryIds.stream().map(spuCategoryId -> {
|
||||
SmsCouponSpuCategory smsCouponSpuCategory = new SmsCouponSpuCategory();
|
||||
smsCouponSpuCategory.setCouponId(couponId);
|
||||
smsCouponSpuCategory.setCouponId(spuCategoryId);
|
||||
return smsCouponSpuCategory;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -86,6 +117,11 @@ public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon
|
||||
public boolean updateCoupon(Long couponId, CouponForm couponForm) {
|
||||
SmsCoupon entity = smsCouponConverter.form2Entity(couponForm);
|
||||
boolean result = this.updateById(entity);
|
||||
|
||||
if (result) {
|
||||
List<SmsCouponSpuCategory> list = smsCouponSpuCategoryService.list(new LambdaQueryWrapper<SmsCouponSpuCategory>().eq(SmsCouponSpuCategory::getCouponId, couponId));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -99,13 +135,12 @@ public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon
|
||||
public boolean deleteCoupons(String idsStr) {
|
||||
Assert.isTrue(StrUtil.isNotBlank(idsStr), "删除的优惠券数据为空");
|
||||
// 逻辑删除
|
||||
List<Long> ids = Arrays.asList(idsStr.split(",")).stream()
|
||||
.map(idStr -> Long.parseLong(idStr)).collect(Collectors.toList());
|
||||
List<Long> ids = Arrays.asList(idsStr.split(",")).stream().map(idStr -> Long.parseLong(idStr)).collect(Collectors.toList());
|
||||
boolean result = this.removeByIds(ids);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user