Pu Zhibing
2025-06-16 49c5117caef44d1e817d2ef701529dfaf1443467
ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/goods/GoodsServiceImpl.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.bean.BeanUtils;
@@ -33,6 +34,7 @@
import com.ruoyi.system.api.domain.poji.shop.Shop;
import com.ruoyi.system.api.domain.vo.MerGoodsPriceListVo;
import com.ruoyi.system.api.domain.vo.MgtSelectGoodsPageVo;
import com.ruoyi.system.api.domain.vo.ShopRelUserVo;
import com.ruoyi.system.api.service.RemoteConfigService;
import com.ruoyi.system.api.service.RemoteShopService;
import org.springframework.stereotype.Service;
@@ -68,20 +70,20 @@
    @Resource
    private RemoteConfigService remoteConfigService;
    @Resource
    private GoodsTotalService goodsTotalService;
    @Resource
    private ActivityService activityService;
    @Resource
    private ActivityRecordService activityRecordService;
    @Resource
    private RemoteShopService remoteShopService;
    /**
     * @param page shopId
     * @return List<AppSimpleGoodsVo>
@@ -197,8 +199,8 @@
                appGoodsInfoVo.setServiceNum(shopGoods.getServiceNum());
            }
        }
        GoodsTotal goodsTotal = goodsTotalService.getById(goods.getGoodsId());
        appGoodsInfoVo.setSalesNum(goodsTotal.getBuyNumCount());
        //活动商品判断
@@ -282,7 +284,7 @@
        return merGoodsPageVoList;
    }
    /**
     * 修改商户商品
     *
@@ -298,7 +300,7 @@
                throw new ServiceException("经销商开启了统一价格管理");
            }
        }
        Goods goods = this.getById(merShopGoodsEditDto.getGoodsId());
        if (merShopGoodsEditDto.getSalePrice().compareTo(goods.getMininumPrice()) < 0) {
            throw new ServiceException(AppErrorConstant.SALESPRICE_MIN + goods.getMininumPrice().toString() + "元");
@@ -699,4 +701,66 @@
        List<String> goodsNameList = goodsMapper.listGoodsNameByGoodsClass(classId);
        return goodsNameList;
    }
    @Override
    public List<PageShopMgtGoodsVO> pageShopMgtGoods(Page<PageShopMgtGoodsVO> page,PageShopMgtGoodsDTO pageShopMgtGoodsDTO) {
        //1.查找门店
        Shop shop = remoteShopService.getShop(pageShopMgtGoodsDTO.getShopId()).getData();
        if (null == shop || shop.getDelFlag() != 0) {
            return Collections.emptyList();
        }
        List<Shop> shops = new ArrayList<>();
        //2.判断门店是否经销商
        if (shop.getShopType()==1){
            //经销商 获取下级-加盟商ids
            shops = remoteShopService.getFranchiseeIdsBYDealerId(shop.getShopId());
        }
        //将该门店加入
        shops.add(shop);
        List<Long> shopIds = shops.stream().map(Shop::getShopId).collect(Collectors.toList());
        //查询信息
        pageShopMgtGoodsDTO.setShopIds(shopIds);
        //3.根据shopId查询商品信息
        List<PageShopMgtGoodsVO> list= goodsMapper.pageShopMgtGoods(page,pageShopMgtGoodsDTO);
        if (list != null && !list.isEmpty()) {
            //4.商品分类
            // 获取所有商品分类的ID
            List<Long> goodsClassIds = list.stream()
                    .map(PageShopMgtGoodsVO::getGoodsClass)
                    .map(Long::valueOf)
                    .collect(Collectors.toList());
            // 通过远程服务获取商品分类
            Map<Long, SysClassification> sysClassificationMap = remoteConfigService.getSysClassificationList(goodsClassIds).getData();
            // 遍历所有商品
            list.forEach(mgtGoodsPageVo -> {
                // 获取商品分类
                SysClassification sysClassification = sysClassificationMap.get(Long.valueOf(mgtGoodsPageVo.getGoodsClass()));
                // 如果商品分类不为空,则设置商品分类名称
                if (sysClassification != null) {
                    mgtGoodsPageVo.setGoodsClass(sysClassification.getClassName());
                }
            });
            Map<Long, Shop> shopMap = shops.stream()
                    .collect(Collectors.toMap(
                            Shop::getShopId,            // 键映射函数
                            shop1 -> shop1        // 值映射函数
                    ));
            //5.门店信息
            list.forEach(mgtGoodsPageVo -> {
                // 获取门店信息
                Shop shopInfo = shopMap.get(Long.valueOf(mgtGoodsPageVo.getShopId()));
                // 如果门店信息不为空,则设置门店信息
                if (shopInfo != null) {
                    mgtGoodsPageVo.setShopName(shopInfo.getShopName());
                    mgtGoodsPageVo.setModifyPricePermission(shop.getModifyPricePermission());
                }
            });
        }
        return list;
    }
}