|
@@ -7,20 +7,22 @@ import cn.newfeifan.mall.framework.common.pojo.PageResult;
|
|
import cn.newfeifan.mall.framework.common.util.collection.CollectionUtils;
|
|
import cn.newfeifan.mall.framework.common.util.collection.CollectionUtils;
|
|
import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
|
|
import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
|
|
import cn.newfeifan.mall.module.product.controller.admin.category.vo.ProductCategoryListReqVO;
|
|
import cn.newfeifan.mall.module.product.controller.admin.category.vo.ProductCategoryListReqVO;
|
|
-import cn.newfeifan.mall.module.product.controller.admin.spu.vo.ProductSkuSaveReqVO;
|
|
|
|
-import cn.newfeifan.mall.module.product.controller.admin.spu.vo.ProductSpuPageReqVO;
|
|
|
|
-import cn.newfeifan.mall.module.product.controller.admin.spu.vo.ProductSpuSaveReqVO;
|
|
|
|
-import cn.newfeifan.mall.module.product.controller.admin.spu.vo.ProductSpuUpdateStatusReqVO;
|
|
|
|
|
|
+import cn.newfeifan.mall.module.product.controller.admin.spu.vo.*;
|
|
import cn.newfeifan.mall.module.product.controller.app.spu.vo.AppProductSpuPageReqVO;
|
|
import cn.newfeifan.mall.module.product.controller.app.spu.vo.AppProductSpuPageReqVO;
|
|
import cn.newfeifan.mall.module.product.dal.dataobject.category.ProductCategoryDO;
|
|
import cn.newfeifan.mall.module.product.dal.dataobject.category.ProductCategoryDO;
|
|
import cn.newfeifan.mall.module.product.dal.dataobject.spu.ProductSpuDO;
|
|
import cn.newfeifan.mall.module.product.dal.dataobject.spu.ProductSpuDO;
|
|
import cn.newfeifan.mall.module.product.dal.mysql.spu.ProductSpuMapper;
|
|
import cn.newfeifan.mall.module.product.dal.mysql.spu.ProductSpuMapper;
|
|
import cn.newfeifan.mall.module.product.enums.spu.ProductSpuStatusEnum;
|
|
import cn.newfeifan.mall.module.product.enums.spu.ProductSpuStatusEnum;
|
|
-import cn.newfeifan.mall.module.product.service.brand.ProductBrandService;
|
|
|
|
import cn.newfeifan.mall.module.product.service.category.ProductCategoryService;
|
|
import cn.newfeifan.mall.module.product.service.category.ProductCategoryService;
|
|
import cn.newfeifan.mall.module.product.service.sku.ProductSkuService;
|
|
import cn.newfeifan.mall.module.product.service.sku.ProductSkuService;
|
|
|
|
+import cn.newfeifan.mall.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
|
+import cn.newfeifan.mall.module.system.dal.mysql.user.AdminUserMapper;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.google.common.collect.Maps;
|
|
import com.google.common.collect.Maps;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -30,6 +32,7 @@ import java.util.*;
|
|
|
|
|
|
import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.newfeifan.mall.framework.common.util.collection.CollectionUtils.*;
|
|
import static cn.newfeifan.mall.framework.common.util.collection.CollectionUtils.*;
|
|
|
|
+import static cn.newfeifan.mall.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
import static cn.newfeifan.mall.module.product.dal.dataobject.category.ProductCategoryDO.CATEGORY_LEVEL;
|
|
import static cn.newfeifan.mall.module.product.dal.dataobject.category.ProductCategoryDO.CATEGORY_LEVEL;
|
|
import static cn.newfeifan.mall.module.product.enums.ErrorCodeConstants.*;
|
|
import static cn.newfeifan.mall.module.product.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
@@ -40,6 +43,7 @@ import static cn.newfeifan.mall.module.product.enums.ErrorCodeConstants.*;
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
@Validated
|
|
@Validated
|
|
|
|
+@Slf4j
|
|
public class ProductSpuServiceImpl implements ProductSpuService {
|
|
public class ProductSpuServiceImpl implements ProductSpuService {
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
@@ -49,22 +53,21 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
@Lazy // 循环依赖,避免报错
|
|
@Lazy // 循环依赖,避免报错
|
|
private ProductSkuService productSkuService;
|
|
private ProductSkuService productSkuService;
|
|
@Resource
|
|
@Resource
|
|
- private ProductBrandService brandService;
|
|
|
|
- @Resource
|
|
|
|
private ProductCategoryService categoryService;
|
|
private ProductCategoryService categoryService;
|
|
|
|
+ @Resource
|
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
|
|
+ @Resource
|
|
|
|
+ private AdminUserMapper userMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public Long createSpu(ProductSpuSaveReqVO createReqVO) {
|
|
public Long createSpu(ProductSpuSaveReqVO createReqVO) {
|
|
// 校验分类、品牌
|
|
// 校验分类、品牌
|
|
validateCategory(createReqVO.getCategoryId());
|
|
validateCategory(createReqVO.getCategoryId());
|
|
- brandService.validateProductBrand(createReqVO.getBrandId());
|
|
|
|
|
|
+// brandService.validateProductBrand(createReqVO.getBrandId());
|
|
|
|
|
|
// 根据商户ID查询对应的店铺ID
|
|
// 根据商户ID查询对应的店铺ID
|
|
- // todo 后续如果存在多店铺的情况下
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ // todo 后续如果存在多店铺的情况
|
|
|
|
|
|
|
|
|
|
// 校验 SKU
|
|
// 校验 SKU
|
|
@@ -74,6 +77,17 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
ProductSpuDO spu = BeanUtils.toBean(createReqVO, ProductSpuDO.class);
|
|
ProductSpuDO spu = BeanUtils.toBean(createReqVO, ProductSpuDO.class);
|
|
// 初始化 SPU 中 SKU 相关属性
|
|
// 初始化 SPU 中 SKU 相关属性
|
|
initSpuFromSkus(spu, skuSaveReqList);
|
|
initSpuFromSkus(spu, skuSaveReqList);
|
|
|
|
+
|
|
|
|
+ //加入商户、店铺信息
|
|
|
|
+ ShopBO shop = getShop();
|
|
|
|
+ spu.setShopId(shop.getShopId());
|
|
|
|
+ spu.setMerchantId(shop.getMerId());
|
|
|
|
+
|
|
|
|
+ for (ProductSkuSaveReqVO productSkuSaveReqVO : skuSaveReqList) {
|
|
|
|
+ productSkuSaveReqVO.setShopId(shop.getShopId());
|
|
|
|
+ productSkuSaveReqVO.setMerchantId(shop.getMerId());
|
|
|
|
+ }
|
|
|
|
+
|
|
// 插入 SPU
|
|
// 插入 SPU
|
|
productSpuMapper.insert(spu);
|
|
productSpuMapper.insert(spu);
|
|
// 插入 SKU
|
|
// 插入 SKU
|
|
@@ -82,6 +96,22 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
return spu.getId();
|
|
return spu.getId();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private ShopBO getShop() {
|
|
|
|
+ Long loginUserId = getLoginUserId();
|
|
|
|
+ String s = stringRedisTemplate.opsForValue().get("shop:" + loginUserId);
|
|
|
|
+ if (StringUtils.isEmpty(s)) {
|
|
|
|
+ AdminUserDO adminUserDO = userMapper.selectById(loginUserId);
|
|
|
|
+ ShopBO shop = new ShopBO();
|
|
|
|
+ shop.setShopId(adminUserDO.getShopId());
|
|
|
|
+ shop.setMerId(adminUserDO.getMerchantId());
|
|
|
|
+ log.info("====shop:{}",shop);
|
|
|
|
+ return shop;
|
|
|
|
+ } else {
|
|
|
|
+ log.info("====shop:{}",s);
|
|
|
|
+ return JSONObject.parseObject(s, ShopBO.class);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public void updateSpu(ProductSpuSaveReqVO updateReqVO) {
|
|
public void updateSpu(ProductSpuSaveReqVO updateReqVO) {
|
|
@@ -89,7 +119,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
validateSpuExists(updateReqVO.getId());
|
|
validateSpuExists(updateReqVO.getId());
|
|
// 校验分类、品牌
|
|
// 校验分类、品牌
|
|
validateCategory(updateReqVO.getCategoryId());
|
|
validateCategory(updateReqVO.getCategoryId());
|
|
- brandService.validateProductBrand(updateReqVO.getBrandId());
|
|
|
|
|
|
+// brandService.validateProductBrand(updateReqVO.getBrandId());
|
|
// 校验SKU
|
|
// 校验SKU
|
|
List<ProductSkuSaveReqVO> skuSaveReqList = updateReqVO.getSkus();
|
|
List<ProductSkuSaveReqVO> skuSaveReqList = updateReqVO.getSkus();
|
|
productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType());
|
|
productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType());
|
|
@@ -210,6 +240,9 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public PageResult<ProductSpuDO> getSpuPage(ProductSpuPageReqVO pageReqVO) {
|
|
public PageResult<ProductSpuDO> getSpuPage(ProductSpuPageReqVO pageReqVO) {
|
|
|
|
+ ShopBO shop = getShop();
|
|
|
|
+ pageReqVO.setShopId(shop.getShopId());
|
|
|
|
+ pageReqVO.setMerchantId(shop.getMerId());
|
|
return productSpuMapper.selectPage(pageReqVO);
|
|
return productSpuMapper.selectPage(pageReqVO);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -273,23 +306,26 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Map<Integer, Long> getTabsCount(Long merId) {
|
|
|
|
|
|
+ public Map<Integer, Long> getTabsCountByMer() {
|
|
Map<Integer, Long> counts = Maps.newLinkedHashMapWithExpectedSize(5);
|
|
Map<Integer, Long> counts = Maps.newLinkedHashMapWithExpectedSize(5);
|
|
|
|
+
|
|
|
|
+ ShopBO shop = getShop();
|
|
|
|
+
|
|
// 查询销售中的商品数量
|
|
// 查询销售中的商品数量
|
|
counts.put(ProductSpuPageReqVO.FOR_SALE,
|
|
counts.put(ProductSpuPageReqVO.FOR_SALE,
|
|
- productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.ENABLE.getStatus()));
|
|
|
|
|
|
+ productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.ENABLE.getStatus(), shop.getMerId(),shop.getShopId()));
|
|
// 查询仓库中的商品数量
|
|
// 查询仓库中的商品数量
|
|
counts.put(ProductSpuPageReqVO.IN_WAREHOUSE,
|
|
counts.put(ProductSpuPageReqVO.IN_WAREHOUSE,
|
|
- productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.DISABLE.getStatus()));
|
|
|
|
|
|
+ productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.DISABLE.getStatus(), shop.getMerId(),shop.getShopId()));
|
|
// 查询售空的商品数量
|
|
// 查询售空的商品数量
|
|
counts.put(ProductSpuPageReqVO.SOLD_OUT,
|
|
counts.put(ProductSpuPageReqVO.SOLD_OUT,
|
|
- productSpuMapper.selectCount(ProductSpuDO::getStock, 0));
|
|
|
|
|
|
+ productSpuMapper.selectCount(ProductSpuDO::getStock, 0, shop.getMerId(),shop.getShopId()));
|
|
// 查询触发警戒库存的商品数量
|
|
// 查询触发警戒库存的商品数量
|
|
counts.put(ProductSpuPageReqVO.ALERT_STOCK,
|
|
counts.put(ProductSpuPageReqVO.ALERT_STOCK,
|
|
- productSpuMapper.selectCount());
|
|
|
|
|
|
+ productSpuMapper.selectCount(shop.getMerId(),shop.getShopId()));
|
|
// 查询回收站中的商品数量
|
|
// 查询回收站中的商品数量
|
|
counts.put(ProductSpuPageReqVO.RECYCLE_BIN,
|
|
counts.put(ProductSpuPageReqVO.RECYCLE_BIN,
|
|
- productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus()));
|
|
|
|
|
|
+ productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus(), shop.getMerId(),shop.getShopId()));
|
|
return counts;
|
|
return counts;
|
|
}
|
|
}
|
|
|
|
|