pad点餐接口

This commit is contained in:
张松
2025-02-20 11:09:30 +08:00
parent 9207cabc2a
commit 6fffdf27b3
6 changed files with 101 additions and 24 deletions

View File

@@ -1,17 +1,9 @@
package com.czg.service.account.service.impl;
import com.czg.account.dto.pad.PadDetailAddDTO;
import com.czg.account.dto.pad.PadDetailDTO;
import com.czg.account.dto.pad.PadDetailEditDTO;
import com.czg.account.dto.pad.PadProductCategoryDTO;
import com.czg.account.entity.PadProductCategory;
import com.czg.account.entity.PadProductCategoryDetail;
import com.czg.account.entity.Product;
import com.czg.account.entity.ShopProdCategory;
import com.czg.account.service.PadProdService;
import com.czg.account.service.PadProductCategoryService;
import com.czg.account.service.ProductService;
import com.czg.account.service.ShopProdCategoryService;
import com.czg.account.dto.pad.*;
import com.czg.account.entity.*;
import com.czg.account.service.*;
import com.czg.enums.StatusEnum;
import com.czg.exception.ApiNotPrintException;
import com.czg.service.account.mapper.PadProductCategoryDetailMapper;
import com.mybatisflex.core.paginate.Page;
@@ -19,6 +11,7 @@ import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
@@ -34,6 +27,10 @@ public class PadProdServiceImpl implements PadProdService {
private ProductService productService;
@Resource
private ShopProdCategoryService shopProdCategoryService;
@Resource
private PadLayoutService padLayoutService;
@Resource
private PadProductCategoryDetailService padProductCategoryDetailService;
@Override
public Page<PadProductCategoryDTO> pageInfo(Page<PadProductCategoryDTO> objectPage, Long productCategoryId, Long shopId) {
@@ -66,12 +63,64 @@ public class PadProdServiceImpl implements PadProdService {
@Override
public Boolean add(Long shopId, PadDetailAddDTO padDetailAddDTO) {
shopProdCategoryService.getOne(new QueryWrapper().eq(ShopProdCategory::getId, padDetailAddDTO.getProductCategoryId()));
return null;
long count = shopProdCategoryService.count(new QueryWrapper().eq(ShopProdCategory::getId, padDetailAddDTO.getProductCategoryId()));
if (count == 0) {
throw new ApiNotPrintException("商品分类不存在");
}
checkInfo(shopId, padDetailAddDTO.getPadLayoutId(), padDetailAddDTO.getProductIdList());
PadProductCategory padProductCategory = new PadProductCategory().setPadLayoutId(padDetailAddDTO.getPadLayoutId()).setProductCategoryId(padDetailAddDTO.getProductCategoryId())
.setShopId(shopId);
padProductCategoryService.save(padProductCategory);
ArrayList<PadProductCategoryDetail> details = new ArrayList<>();
padDetailAddDTO.getProductIdList().forEach(item -> {
details.add(new PadProductCategoryDetail().setPadProductCategoryId(padProductCategory.getId()).setProductId(item));
});
return padProductCategoryDetailService.saveBatch(details);
}
@Override
public Boolean edit(Long shopId, PadDetailEditDTO padDetailEditDTO) {
return null;
PadProductCategory category = padProductCategoryService.getOne(new QueryWrapper().eq(PadProductCategory::getShopId, shopId).eq(PadProductCategory::getId, padDetailEditDTO.getId()));
if (category == null) {
throw new ApiNotPrintException("pad商品不存在");
}
checkInfo(shopId, padDetailEditDTO.getPadLayoutId(), padDetailEditDTO.getProductIdList());
padProductCategoryDetailService.remove(new QueryWrapper().eq(PadProductCategoryDetail::getPadProductCategoryId, padDetailEditDTO.getId()));
category.setPadLayoutId(padDetailEditDTO.getPadLayoutId());
padProductCategoryService.updateById(category);
ArrayList<PadProductCategoryDetail> details = new ArrayList<>();
padDetailEditDTO.getProductIdList().forEach(item -> {
details.add(new PadProductCategoryDetail().setPadProductCategoryId(padDetailEditDTO.getId()).setProductId(item));
});
return padProductCategoryDetailService.saveBatch(details);
}
private void checkInfo(Long shopId, Long padLayoutId, List<Long> productIdList) {
long layOutCount = padLayoutService.count(new QueryWrapper().eq(PadLayout::getId, padLayoutId).eq(PadLayout::getIsDel, 0));
if (layOutCount == 0) {
throw new ApiNotPrintException("pad布局不存在");
}
long proCount = productService.count(new QueryWrapper().eq(Product::getShopId, shopId).in(Product::getId, productIdList));
if (proCount != productIdList.size()) {
throw new ApiNotPrintException("存在错误商品id");
}
}
@Override
public Boolean del(Long shopId, PadDetailDelDTO delDTO) {
PadProductCategory category = padProductCategoryService.getOne(new QueryWrapper().eq(PadProductCategory::getShopId, shopId).eq(PadProductCategory::getId, delDTO.getId()));
if (category == null) {
throw new ApiNotPrintException("pad商品不存在");
}
padProductCategoryService.removeById(delDTO.getId());
return padProductCategoryDetailService.remove(new QueryWrapper().eq(PadProductCategoryDetail::getPadProductCategoryId, delDTO.getId()));
}
}