|
|
|
|
@@ -15,27 +15,33 @@
|
|
|
|
|
*/
|
|
|
|
|
package cn.ysk.cashier.service.impl.shopimpl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.ysk.cashier.exception.BadRequestException;
|
|
|
|
|
import cn.ysk.cashier.pojo.product.TbProduct;
|
|
|
|
|
import cn.ysk.cashier.pojo.shop.TbMerchantCoupon;
|
|
|
|
|
import cn.ysk.cashier.repository.product.TbProductRepository;
|
|
|
|
|
import cn.ysk.cashier.utils.ValidationUtil;
|
|
|
|
|
import cn.ysk.cashier.utils.FileUtil;
|
|
|
|
|
import cn.ysk.cashier.vo.CouponVO;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import cn.ysk.cashier.repository.shop.TbMerchantCouponRepository;
|
|
|
|
|
import cn.ysk.cashier.service.shop.TbMerchantCouponService;
|
|
|
|
|
import cn.ysk.cashier.dto.shop.TbMerchantCouponDto;
|
|
|
|
|
import cn.ysk.cashier.dto.shop.TbMerchantCouponQueryCriteria;
|
|
|
|
|
import cn.ysk.cashier.mapper.shop.TbMerchantCouponMapper;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
|
import cn.ysk.cashier.utils.PageUtil;
|
|
|
|
|
import cn.ysk.cashier.utils.QueryHelp;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
|
|
import java.time.Instant;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @website https://eladmin.vip
|
|
|
|
|
@@ -49,13 +55,30 @@ public class TbMerchantCouponServiceImpl implements TbMerchantCouponService {
|
|
|
|
|
|
|
|
|
|
private final TbMerchantCouponRepository tbMerchantCouponRepository;
|
|
|
|
|
private final TbMerchantCouponMapper tbMerchantCouponMapper;
|
|
|
|
|
private final TbProductRepository tbProductRepository;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String,Object> queryAll(TbMerchantCouponQueryCriteria criteria, Pageable pageable){
|
|
|
|
|
Page<TbMerchantCoupon> page = tbMerchantCouponRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
|
|
|
|
return PageUtil.toPage(page.map(tbMerchantCouponMapper::toDto));
|
|
|
|
|
List<CouponVO> objects = new ArrayList<>();
|
|
|
|
|
for (TbMerchantCoupon o :page.getContent()) {
|
|
|
|
|
CouponVO couponVO = new CouponVO();
|
|
|
|
|
BeanUtils.copyProperties(o,couponVO);
|
|
|
|
|
if (!o.getRelationIds().isEmpty()) {
|
|
|
|
|
List<Integer> integers = new ArrayList<>();
|
|
|
|
|
integers.add(Integer.valueOf(o.getRelationIds()));
|
|
|
|
|
List<TbProduct> byIds = tbProductRepository.findByIds(integers);
|
|
|
|
|
couponVO.setName(byIds.get(0).getName());
|
|
|
|
|
couponVO.setCoverImg(byIds.get(0).getCoverImg());
|
|
|
|
|
}
|
|
|
|
|
objects.add(couponVO);
|
|
|
|
|
}
|
|
|
|
|
HashMap<String, Object> couponvoMap = new HashMap<>();
|
|
|
|
|
couponvoMap.put("content", objects);
|
|
|
|
|
couponvoMap.put("totalElements", page.getTotalElements());
|
|
|
|
|
return couponvoMap;
|
|
|
|
|
// return PageUtil.toPage(page.map(tbMerchantCouponMapper::toDto));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<TbMerchantCouponDto> queryAll(TbMerchantCouponQueryCriteria criteria){
|
|
|
|
|
return tbMerchantCouponMapper.toDto(tbMerchantCouponRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
|
|
|
|
@@ -71,8 +94,29 @@ public class TbMerchantCouponServiceImpl implements TbMerchantCouponService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public TbMerchantCouponDto create(TbMerchantCoupon resources) {
|
|
|
|
|
return tbMerchantCouponMapper.toDto(tbMerchantCouponRepository.save(resources));
|
|
|
|
|
public TbMerchantCoupon create(TbMerchantCoupon resources) {
|
|
|
|
|
resources.setCreatedAt(Instant.now().toEpochMilli());
|
|
|
|
|
resources.setUpdatedAt(Instant.now().toEpochMilli());
|
|
|
|
|
if (resources.getEffectType() == 1){
|
|
|
|
|
if (resources.getToTime() == null && resources.getFromTime() == null){
|
|
|
|
|
throw new BadRequestException("开始时间结束时间为空");
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
resources.setToTime(null);
|
|
|
|
|
resources.setFromTime(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("product".equals(resources.getClassType())){
|
|
|
|
|
if (resources.getRelationIds() == null){
|
|
|
|
|
throw new BadRequestException("商品不能为空");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (resources.getNumber() == 0){
|
|
|
|
|
resources.setLeftNumber(0);
|
|
|
|
|
}else {
|
|
|
|
|
resources.setLeftNumber(resources.getNumber());
|
|
|
|
|
}
|
|
|
|
|
return tbMerchantCouponRepository.save(resources);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|