|
@@ -7,10 +7,7 @@ import cn.newfeifan.mall.framework.common.pojo.PageResult;
|
|
|
import cn.newfeifan.mall.framework.common.util.collection.CollectionUtils;
|
|
|
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.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.dal.dataobject.category.ProductCategoryDO;
|
|
|
import cn.newfeifan.mall.module.product.dal.dataobject.spu.ProductSpuDO;
|
|
@@ -19,8 +16,14 @@ 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.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 lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -30,6 +33,7 @@ import java.util.*;
|
|
|
|
|
|
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.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.enums.ErrorCodeConstants.*;
|
|
|
|
|
@@ -40,6 +44,7 @@ import static cn.newfeifan.mall.module.product.enums.ErrorCodeConstants.*;
|
|
|
*/
|
|
|
@Service
|
|
|
@Validated
|
|
|
+@Slf4j
|
|
|
public class ProductSpuServiceImpl implements ProductSpuService {
|
|
|
|
|
|
@Resource
|
|
@@ -53,6 +58,13 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
|
@Resource
|
|
|
private ProductCategoryService categoryService;
|
|
|
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AdminUserMapper userMapper;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Long createSpu(ProductSpuSaveReqVO createReqVO) {
|
|
@@ -275,24 +287,43 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
|
@Override
|
|
|
public Map<Integer, Long> getTabsCount(Long merId) {
|
|
|
Map<Integer, Long> counts = Maps.newLinkedHashMapWithExpectedSize(5);
|
|
|
+
|
|
|
+ ShopBO shop = getShop();
|
|
|
+
|
|
|
// 查询销售中的商品数量
|
|
|
counts.put(ProductSpuPageReqVO.FOR_SALE,
|
|
|
- productSpuMapper.selectCountByMerId(merId,ProductSpuDO::getStatus, ProductSpuStatusEnum.ENABLE.getStatus()));
|
|
|
+ productSpuMapper.selectCountByMerId(shop.getShopId(),shop.getMerId(),ProductSpuDO::getStatus, ProductSpuStatusEnum.ENABLE.getStatus()));
|
|
|
// 查询仓库中的商品数量
|
|
|
counts.put(ProductSpuPageReqVO.IN_WAREHOUSE,
|
|
|
- productSpuMapper.selectCountByMerId(merId,ProductSpuDO::getStatus, ProductSpuStatusEnum.DISABLE.getStatus()));
|
|
|
+ productSpuMapper.selectCountByMerId(shop.getShopId(),shop.getMerId(),ProductSpuDO::getStatus, ProductSpuStatusEnum.DISABLE.getStatus()));
|
|
|
// 查询售空的商品数量
|
|
|
counts.put(ProductSpuPageReqVO.SOLD_OUT,
|
|
|
- productSpuMapper.selectCountByMerId(merId,ProductSpuDO::getStock, 0));
|
|
|
+ productSpuMapper.selectCountByMerId(shop.getShopId(),shop.getMerId(),ProductSpuDO::getStock, 0));
|
|
|
// 查询触发警戒库存的商品数量
|
|
|
counts.put(ProductSpuPageReqVO.ALERT_STOCK,
|
|
|
- productSpuMapper.selectCountByMerId(merId));
|
|
|
+ productSpuMapper.selectCountByMerId(shop.getShopId(),shop.getMerId()));
|
|
|
// 查询回收站中的商品数量
|
|
|
counts.put(ProductSpuPageReqVO.RECYCLE_BIN,
|
|
|
- productSpuMapper.selectCountByMerId(merId,ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus()));
|
|
|
+ productSpuMapper.selectCountByMerId(shop.getShopId(),shop.getMerId(),ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus()));
|
|
|
return counts;
|
|
|
}
|
|
|
|
|
|
+ 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
|
|
|
public Long getSpuCountByCategoryId(Long categoryId) {
|