|
@@ -1,10 +1,28 @@
|
|
|
package com.qs.mp.admin.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.qs.mp.admin.domain.CouponPkg;
|
|
|
+import com.qs.mp.admin.domain.CouponPkgItem;
|
|
|
+import com.qs.mp.admin.domain.param.CouponPkgItemParam;
|
|
|
+import com.qs.mp.admin.domain.param.CouponPkgParam;
|
|
|
+import com.qs.mp.admin.domain.vo.CouponPkgItemVO;
|
|
|
+import com.qs.mp.admin.domain.vo.CouponPkgVO;
|
|
|
import com.qs.mp.admin.mapper.CouponPkgMapper;
|
|
|
+import com.qs.mp.admin.service.ICouponPkgItemService;
|
|
|
import com.qs.mp.admin.service.ICouponPkgService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qs.mp.common.enums.CouponPkgStatusEnum;
|
|
|
+import com.qs.mp.common.exception.ServiceException;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -17,4 +35,104 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class CouponPkgServiceImpl extends ServiceImpl<CouponPkgMapper, CouponPkg> implements ICouponPkgService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ICouponPkgItemService couponPkgItemService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean delete(Long id) {
|
|
|
+
|
|
|
+ // 删除券包明细
|
|
|
+ couponPkgItemService.remove(new LambdaQueryWrapper<CouponPkgItem>().eq(CouponPkgItem::getCouponPkgId, id));
|
|
|
+
|
|
|
+ // 删除券包
|
|
|
+ this.removeById(id);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CouponPkgVO detail(Long id) {
|
|
|
+ CouponPkgVO couponPkgVO = new CouponPkgVO();
|
|
|
+
|
|
|
+ // 封装券包信息
|
|
|
+ CouponPkg couponPkg = this.getById(id);
|
|
|
+ if (Objects.isNull(couponPkg)) {
|
|
|
+ throw new ServiceException("券包不存在");
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(couponPkg, couponPkgVO);
|
|
|
+
|
|
|
+ // 封装券包明细信息
|
|
|
+ List<CouponPkgItemVO> list = couponPkgItemService.listDetailByCouponPkgId(id);
|
|
|
+ couponPkgVO.setCouponPkgItemVOList(list);
|
|
|
+
|
|
|
+ return couponPkgVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean updateCouponPkg(CouponPkgParam couponPkgParam) {
|
|
|
+
|
|
|
+ if (Objects.isNull(couponPkgParam.getId()) || couponPkgParam.getId() == 0) {
|
|
|
+ throw new ServiceException("券包ID不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!CouponPkgStatusEnum.PUT_INIT.getValue().equals(couponPkgParam.getStatus())) {
|
|
|
+ throw new ServiceException("券包只有待上架才可编辑");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<CouponPkgItemParam> couponPkgItemList = couponPkgParam.getCouponPkgItemList();
|
|
|
+ if (CollectionUtils.isEmpty(couponPkgItemList)) {
|
|
|
+ throw new ServiceException("券包明细不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 清除券包明细
|
|
|
+ couponPkgItemService.remove(new LambdaQueryWrapper<CouponPkgItem>()
|
|
|
+ .eq(CouponPkgItem::getCouponPkgId, couponPkgParam.getId()));
|
|
|
+
|
|
|
+ // 更新券包
|
|
|
+ CouponPkg couponPkg = new CouponPkg();
|
|
|
+ BeanUtils.copyProperties(couponPkgParam, couponPkg);
|
|
|
+ this.updateById(couponPkg);
|
|
|
+
|
|
|
+ // 创建券包明细
|
|
|
+ List<CouponPkgItem> params = new ArrayList<>();
|
|
|
+ for (CouponPkgItemParam couponPkgItemParam : couponPkgItemList) {
|
|
|
+ CouponPkgItem param = new CouponPkgItem();
|
|
|
+ param.setCouponPkgId(couponPkg.getId());
|
|
|
+ param.setCouponId(couponPkgItemParam.getCouponId());
|
|
|
+ param.setCouponNum(couponPkgItemParam.getCouponNum());
|
|
|
+ params.add(param);
|
|
|
+ }
|
|
|
+ couponPkgItemService.saveBatch(params);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean create(CouponPkgParam couponPkgParam) {
|
|
|
+
|
|
|
+ List<CouponPkgItemParam> couponPkgItemList = couponPkgParam.getCouponPkgItemList();
|
|
|
+ if (CollectionUtils.isEmpty(couponPkgItemList)) {
|
|
|
+ throw new ServiceException("券包明细不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ CouponPkg couponPkg = new CouponPkg();
|
|
|
+ BeanUtils.copyProperties(couponPkgParam, couponPkg);
|
|
|
+ this.save(couponPkg);
|
|
|
+
|
|
|
+ List<CouponPkgItem> params = new ArrayList<>();
|
|
|
+ for (CouponPkgItemParam couponPkgItemParam : couponPkgItemList) {
|
|
|
+ CouponPkgItem param = new CouponPkgItem();
|
|
|
+ param.setCouponPkgId(couponPkg.getId());
|
|
|
+ param.setCouponId(couponPkgItemParam.getCouponId());
|
|
|
+ param.setCouponNum(couponPkgItemParam.getCouponNum());
|
|
|
+ params.add(param);
|
|
|
+ }
|
|
|
+ couponPkgItemService.saveBatch(params);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|