rk
6 小时以前 11c5ab8d97809bdeddb60b22a4fe161a67aa3b05
server/dmmall_service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java
@@ -89,6 +89,8 @@
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private ShopMapper shopMapper;
    @Autowired
    private GoodsSkuAttrJoinMapper goodsSkuAttrJoinMapper;
@@ -214,8 +216,9 @@
                    || goods.getDeductRata() == null
                    || goods.getPrice() == null
                    || goods.getSkuPrice() == null
                    || StringUtils.isBlank(goods.getImgurl())
                    || org.apache.commons.collections.CollectionUtils.isEmpty(goods.getFileList())) {
//                    || StringUtils.isBlank(goods.getImgurl())
//                    || org.apache.commons.collections.CollectionUtils.isEmpty(goods.getFileList())
            ) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), ResponseStatus.BAD_REQUEST.getMessage());
            }
@@ -710,6 +713,9 @@
    @Override
    public List<Goods> findList(Goods goods) {
        QueryWrapper<Goods> wrapper = new QueryWrapper<>(goods);
        wrapper.lambda()
            .in(goods.getIdList() != null && goods.getIdList().size()>0, Goods::getId, goods.getIdList())
            .eq( Goods::getIsdeleted, Constants.ZERO);
        return goodsMapper.selectList(wrapper);
    }
@@ -718,9 +724,7 @@
        IPage<Goods> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<Goods> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        queryWrapper.selectAll(Goods.class);
        queryWrapper.select("t1.name",Goods::getCategoryName);
        queryWrapper.select("t2.name" ,Goods::getBrandName);
        queryWrapper.select("t3.name" ,Goods::getParentName);
@@ -729,6 +733,7 @@
        queryWrapper.leftJoin(Labels.class,Labels::getId,Goods::getParentCategoryId);
        //库存量
        queryWrapper.select("(select sum(STOCK) from goods_sku where ISDELETED=0 and GOODS_ID=t.id) as stockNum ");
        queryWrapper.select("(select count(id) from shop_goods_relation s where s.ISDELETED=0 and s.GOODS_ID=t.id) as pricedShopNum ");
        //实际销量
        queryWrapper.select("(select sum(gd.GOODS_NUM) from  goodsorder_detail gd" +
                "        inner join  goods_sku gs on gs.id=gd.GOODS_SKU_ID" +
@@ -750,8 +755,8 @@
        queryWrapper.eq(pageWrap.getModel().getParentCategoryId() != null, Goods::getParentCategoryId, pageWrap.getModel().getParentCategoryId());
        queryWrapper.eq(pageWrap.getModel().getBrandId() != null, Goods::getBrandId, pageWrap.getModel().getBrandId());
        queryWrapper.eq(pageWrap.getModel().getStatus() != null, Goods::getStatus, pageWrap.getModel().getStatus());
        queryWrapper.orderByDesc(Goods::getCreateDate);
        queryWrapper.in(pageWrap.getModel().getIdList() != null && pageWrap.getModel().getIdList().size()>0, Goods::getId, pageWrap.getModel().getIdList());
        queryWrapper.orderByDesc(Goods::getId);
        IPage<Goods> result = goodsAdminJoinMapper.selectJoinPage(page, Goods.class, queryWrapper);
        initResult(result.getRecords());
        return PageData.from(result);
@@ -780,9 +785,12 @@
        if (list == null || list.size() == 0) {
            return;
        }
       long shopNum = shopMapper.selectCount(new QueryWrapper<Shop>().lambda()
                .eq(Shop::getIsdeleted,Constants.ZERO));
        String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_FILE).getCode();
        for (Goods goods : list) {
            goods.setShopNum(shopNum);
            goods.setResourcePath(path);
            //查询sku
            MPJLambdaWrapper<GoodsSku> queryWrapper = new MPJLambdaWrapper<GoodsSku>()
@@ -827,13 +835,11 @@
                .eq("g.ISDELETED",Constants.ZERO)
                .eq(!Objects.isNull(model) && Objects.nonNull(model.getCategoryId()),
                        "g.CATEGORY_ID", model.getCategoryId())
               //TODO 适用品牌  适用系列
//               .eq(!Objects.isNull(model) && Objects.nonNull(model.getApplicableBrandId()),
//                       "","")
//               .eq(!Objects.isNull(model) && Objects.nonNull(model.getSeriesBrandId()),
//                       "","")
               //适用品牌  适用系列
               .apply(!Objects.isNull(model) && Objects.nonNull(model.getApplicableBrandId()),
                       " find_in_set( '["+model.getApplicableBrandId()+"]' , g.BRAND_IDS )  ")
               .apply(!Objects.isNull(model) && Objects.nonNull(model.getSeriesBrandId()),
                       " find_in_set( '["+model.getSeriesBrandId()+"]' , g.SERIAL_IDS )  ")
                .eq("g.STATUS", Constants.ZERO)
                .like(StringUtils.isNotBlank(model.getGoodsName()),"g.NAME",model.getGoodsName());
@@ -851,59 +857,16 @@
                        wrapper.orderByDesc("g.price");
                    }
                }
//                for(PageWrap.SortData sortData:pageWrap.getSorts1()){
//                    if ("CREATE_DATE".equalsIgnoreCase(sortData.getProperty())){
//                        if (PageWrap.ASC.equalsIgnoreCase(sortData.getDirection())){
//                            wrapper.orderByAsc("g.CREATE_DATE");
//                        }
//                        wrapper.orderByDesc("g.CREATE_DATE");
//
//                    }
//                    if ("realSaleNum".equalsIgnoreCase(sortData.getProperty())){
//
//                        if (PageWrap.ASC.equalsIgnoreCase(sortData.getDirection())){
//                            wrapper.orderByAsc("realSaleNum");
//                        }
//                        wrapper.orderByDesc("realSaleNum");
//                    }
//                    if ("PRICE".equalsIgnoreCase(sortData.getProperty())){
//                        if (PageWrap.ASC.equalsIgnoreCase(sortData.getDirection())){
//                            wrapper.orderByAsc("g.PRICE");
//                        }
//                        wrapper.orderByDesc("g.PRICE");
//                    }
//
//                }
        IPage<GoodsInfoResponse> page = goodsMapper.goodsPage(pageWrap.toPage(),wrapper);
        IPage<GoodsInfoResponse> page =
                Objects.isNull(model.getShopId())?
                goodsMapper.goodsPage(pageWrap.toPage(),wrapper)
                :
                goodsMapper.goodsPageForShop(pageWrap.toPage(),wrapper,model.getShopId()) ;
        if (!CollectionUtils.isEmpty(page.getRecords())){
            String preFixPath = systemDictDataBiz.getPreFixPath(Constants.RESOURCE_PATH, Constants.GOODS_FILE);
            page.getRecords().forEach(s->s.setImgurl(preFixPath+s.getImgurl()));
        }
//        if (pageWrap.getModel().getType().equals(Constants.TWO)) {
//            for (GoodsInfoResponse goodsResponse : page.getRecords()) {
//                //查询商品的分类
//                goodsResponse.setCategoryLabels(labelsMapper.selectById(goodsResponse.getCategoryId()));
//                //查询商品的品牌
//                goodsResponse.setBrandLabels(labelsMapper.selectById(goodsResponse.getBrandId()));
//                //查询商品的标签信息
//                if (StringUtils.isNotBlank(goodsResponse.getLabels())) {
//                    goodsResponse.setLabelsList(labelsMapper.selectList(new QueryWrapper<Labels>()
//                            .apply(" find_in_set( id, " + goodsResponse.getLabels().split(",") + " ) ")));
//                }
//                //查询是否已订阅
//                goodsResponse.setIsSubscribe(goodsorderDetailMapper.selectCount(new QueryWrapper<GoodsorderDetail>()
//                        .eq("CREATOR", pageWrap.getModel().getMemberId())
//                        .apply(" GOODS_SKU_ID in ( SELECT g.id  FROM goods_sku g where g.GOODS_ID = " + goodsResponse.getId() + "  )  ")
//                ));
//                //sku基础信息
//                this.getSkuInfo(goodsResponse);
//            }
//        }
        return page;
    }