|
|
@@ -1,16 +1,23 @@
|
|
|
|
|
|
package com.yami.shop.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
import com.yami.shop.bean.model.CategoryProd;
|
|
|
+import com.yami.shop.bean.param.CategoryProductDTO;
|
|
|
+import com.yami.shop.common.exception.GlobalException;
|
|
|
+import com.yami.shop.common.util.PageParam;
|
|
|
import com.yami.shop.dao.CategoryProdMapper;
|
|
|
import com.yami.shop.service.CategoryProdService;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
* Created by lgh on 2018/07/13.
|
|
|
*/
|
|
|
@Service
|
|
|
@@ -19,4 +26,75 @@ public class CategoryProdServiceImpl extends ServiceImpl<CategoryProdMapper, Cat
|
|
|
@Autowired
|
|
|
private CategoryProdMapper categoryPropMapper;
|
|
|
|
|
|
+ @Override
|
|
|
+ public IPage<CategoryProd> pageByCode(CategoryProd categoryProd, PageParam<CategoryProd> page) {
|
|
|
+ return categoryPropMapper.pageByCode(page, categoryProd);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void categoryProduct(CategoryProductDTO categoryProductDTO) {
|
|
|
+ List<Long> prodIdList = categoryProductDTO.getProdIdList();
|
|
|
+ if (ObjectUtils.isEmpty(prodIdList)) {
|
|
|
+ new GlobalException("新增商品为空!请选择商品");
|
|
|
+ }
|
|
|
+ for (Long aLong : prodIdList) {
|
|
|
+
|
|
|
+ Integer integer = categoryPropMapper.selectCount(new LambdaQueryWrapper<CategoryProd>().eq(CategoryProd::getProdId, aLong)
|
|
|
+ .eq(CategoryProd::getIsDelete, 0)
|
|
|
+ .eq(CategoryProd::getShopId, categoryProductDTO.getShopId())
|
|
|
+ .eq(CategoryProd::getCode, categoryProductDTO.getCode()));
|
|
|
+
|
|
|
+ if (integer > 0) {
|
|
|
+ new GlobalException("该门店分类对应商品ID=" + aLong + " 已存在!请勿重复添加");
|
|
|
+ }
|
|
|
+ CategoryProd categoryProd = new CategoryProd();
|
|
|
+ categoryProd.setCategoryId(categoryProductDTO.getCategoryId());
|
|
|
+ categoryProd.setProdId(aLong);
|
|
|
+ categoryProd.setShopId(categoryProductDTO.getShopId());
|
|
|
+ categoryProd.setCode(categoryProductDTO.getCode());
|
|
|
+ categoryProd.setIsDelete(0);
|
|
|
+ categoryProd.setCreateTime(new Date());
|
|
|
+ categoryPropMapper.insert(categoryProd);
|
|
|
+
|
|
|
+ //查看父类绑定商品是否存在不存在添加
|
|
|
+ Integer integer1 = categoryPropMapper.selectCount(new LambdaQueryWrapper<CategoryProd>()
|
|
|
+ .eq(CategoryProd::getCode, categoryProductDTO.getParentCode())
|
|
|
+ .eq(CategoryProd::getIsDelete, 0));
|
|
|
+ if (integer1 == 0) {
|
|
|
+ CategoryProd categoryProdParent = new CategoryProd();
|
|
|
+ categoryProdParent.setCategoryId(categoryProductDTO.getCategoryId());
|
|
|
+ categoryProdParent.setProdId(aLong);
|
|
|
+ categoryProdParent.setShopId(categoryProductDTO.getShopId());
|
|
|
+ categoryProdParent.setCode(categoryProductDTO.getParentCode());
|
|
|
+ categoryProdParent.setIsDelete(0);
|
|
|
+ categoryProdParent.setCreateTime(new Date());
|
|
|
+ categoryPropMapper.insert(categoryProdParent);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void cancelCategoryProduct(CategoryProductDTO categoryProductDTO) {
|
|
|
+ List<Long> prodIdList = categoryProductDTO.getProdIdList();
|
|
|
+ if (ObjectUtils.isEmpty(prodIdList)) {
|
|
|
+ new GlobalException("取消商品为空!请选择商品");
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Long aLong : prodIdList) {
|
|
|
+
|
|
|
+ CategoryProd categoryProd = categoryPropMapper.selectOne(new LambdaQueryWrapper<CategoryProd>().eq(CategoryProd::getProdId, aLong)
|
|
|
+ .eq(CategoryProd::getIsDelete, 0)
|
|
|
+ .eq(CategoryProd::getShopId, categoryProductDTO.getShopId())
|
|
|
+ .eq(CategoryProd::getCode, categoryProductDTO.getCode()));
|
|
|
+
|
|
|
+ if (ObjectUtils.isEmpty(categoryProd)) {
|
|
|
+ new GlobalException("该门店分类对应商品ID=" + aLong + " 不存在!请勿重复取消");
|
|
|
+ }
|
|
|
+ categoryProd.setIsDelete(1);
|
|
|
+ categoryPropMapper.deleteById(categoryProd);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|