doum
3 天以前 f4e09a3f13bbf63b166c3a149497a93a9fd43bc5
server/dmmall_service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java
@@ -156,7 +156,7 @@
        goodsSku.setGoodsId(goods.getId());
        goodsSku.setName(goods.getName());
        goodsSku.setPrice(goods.getSkuPrice());
        goodsSku.setShowPrice(goods.getPrice());
        goodsSku.setShowPrice(goods.getShowPrice());
        goodsSku.setStock(goods.getStockNum());
        goodsSku.setIntegralRate(goods.getDeductRata());
        goodsSku.setUnitName(goods.getUnitName());
@@ -211,6 +211,7 @@
                    || goods.getBrandList() == null
                    || goods.getBrandList().size() == 0
                    || goods.getWeight() == null
                    || goods.getDeductRata() == null
                    || goods.getPrice() == null
                    || goods.getSkuPrice() == null
                    || StringUtils.isBlank(goods.getImgurl())
@@ -218,6 +219,10 @@
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), ResponseStatus.BAD_REQUEST.getMessage());
            }
            if(goods.getDeductRata().compareTo(new BigDecimal(0.1)) <Constants.ZERO ||
                    goods.getDeductRata().compareTo(new BigDecimal(100)) >Constants.ZERO){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,积分可抵扣金额比例请设置[0.1,100]之间~");
            }
            //查询分类
            Labels cate = labelsMapper.selectById(goods.getCategoryId());
            if(cate == null || Constants.equalsInteger(cate.getIsdeleted(),Constants.ONE)
@@ -225,7 +230,7 @@
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,分类信息不存在");
            }
            if(goods.getBrandId()!=null){
                Labels brand = labelsMapper.selectById(goods.getCategoryId());
                Labels brand = labelsMapper.selectById(goods.getBrandId());
                if(brand == null || Constants.equalsInteger(brand.getIsdeleted(),Constants.ONE)
                        ||! Constants.equalsInteger(brand.getType(),Constants.LabelsType.GOODSBRAND.getKey())){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,品牌信息不存在");
@@ -234,7 +239,7 @@
            List<Integer> bIds = new ArrayList<>();
            for(Labels b : goods.getBrandList()){
                bIds.add(b.getId());
                if(b.getChildIdList() == null || b.getChildIdList().size() ==0){
                if(b.getChildIdList() != null && b.getChildIdList().size() >=0){
                    bIds.addAll(b.getChildIdList());
                }
            }
@@ -251,9 +256,9 @@
                     throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请选择正确的适用品牌");
                 }
                 idsBrand.add("["+b.getId()+"]");
                if(b.getChildIdList() == null || b.getChildIdList().size() ==0){
                if(b.getChildIdList()!= null && b.getChildIdList().size() >=0){
                   for(Integer c :b.getChildIdList()){
                       Labels cb = findLabelFromListByid(allBrands,b.getId(),Constants.LabelsType.SERIES_BRAND.getKey(),b.getId());
                       Labels cb = findLabelFromListByid(allBrands,c,Constants.LabelsType.SERIES_BRAND.getKey(),b.getId());
                       if(cb == null){
                           throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,品牌【"+tb.getName() +"】下所属系列不正确");
                       }
@@ -265,7 +270,6 @@
            if(idsSerial.size()>0){
                goods.setSerialIds(String.join(",",idsSerial));
            }
    }
    private Labels findLabelFromListByid(List<Labels> allBrands, Integer id, int type,Integer parentId) {
@@ -274,13 +278,13 @@
        }
        for(Labels labels:allBrands){
            if(!Constants.equalsInteger(id,labels.getId())){
                return null;
               continue;
            }
            if(!Constants.equalsInteger(type,labels.getType())){
                return null;
              continue;
            }
            if(parentId !=null && !Constants.equalsInteger(parentId,labels.getParentId())){
                return null;
               continue;
            }
            return labels;
        }
@@ -364,11 +368,11 @@
        skuMapper.update(null,new UpdateWrapper<Sku>().lambda()
                .set(Sku::getIsdeleted,Constants.ONE)
                .eq(Sku::getIsdeleted,Constants.ZERO)
                .eq(Sku::getGoodsId,goods.getSkuId()));
                .eq(Sku::getGoodsId,goods.getId()));
        goodsSkuMapper.update(null,new UpdateWrapper<GoodsSku>().lambda()
                .set(GoodsSku::getIsdeleted,Constants.ONE)
                .eq(GoodsSku::getIsdeleted,Constants.ZERO)
                .eq(GoodsSku::getGoodsId,goods.getSkuId()));
                .eq(GoodsSku::getGoodsId,goods.getId()));
        dealDefaultGoodsSku(goods);//新建sku信息
        dealBatchMultiFiles(goods, goods.getFileList(), user,true);
    }
@@ -526,7 +530,8 @@
    @Override
    public Goods findById(Integer id) {
        MPJLambdaWrapper<Goods> queryWrapper = new MPJLambdaWrapper<>();
        String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() + systemDictDataBiz.queryByCode(Constants.OSS, Constants.ACTIVITY_FILE).getCode();
        String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_FILE).getCode();
        queryWrapper.eq(Goods::getId,id);
        queryWrapper.selectAll(Goods.class);
@@ -554,6 +559,7 @@
            //默认sku信息
            GoodsSku goodsSku = goodsSkuList.get(0);
            goods.setSkuPrice(goodsSku.getPrice());
            goods.setShowPrice(goodsSku.getShowPrice());
            goods.setWeight(goodsSku.getWeight());
            goods.setStockNum(goodsSku.getStock());
            goods.setUnitName(goodsSku.getUnitName());
@@ -592,6 +598,7 @@
                    }
                }
            }
            goods.setBrandList(brandList);
        }
    }
@@ -721,7 +728,7 @@
        queryWrapper.leftJoin(Labels.class,Labels::getId,Goods::getBrandId);
        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 sum(STOCK) from goods_sku where ISDELETED=0 and GOODS_ID=t.id) as stockNum ");
        //实际销量
        queryWrapper.select("(select sum(gd.GOODS_NUM) from  goodsorder_detail gd" +
                "        inner join  goods_sku gs on gs.id=gd.GOODS_SKU_ID" +
@@ -773,7 +780,8 @@
        if (list == null || list.size() == 0) {
            return;
        }
        String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_FILE).getCode();
        String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_FILE).getCode();
        for (Goods goods : list) {
            goods.setResourcePath(path);
            //查询sku
@@ -788,9 +796,11 @@
                //默认sku信息
                goods.setSkuPrice(goodsSku.getPrice());
                goods.setWeight(goodsSku.getWeight());
                goods.setShowPrice(goodsSku.getShowPrice());
                goods.setStockNum(goodsSku.getStock());
                goods.setUnitName(goodsSku.getUnitName());
            }
//            initGoodsApplyBrandAndSerial(goods);
        }
    }
@@ -811,45 +821,66 @@
     */
    @Override
    public IPage<GoodsInfoResponse> getGoodsPage(PageWrap<GoodsRequest> pageWrap) {
       GoodsRequest model = pageWrap.getModel();
       QueryWrapper<GoodsRequest> wrapper = new QueryWrapper<GoodsRequest>()
                .eq("g.ISDELETED",Constants.ZERO)
                .eq("g.PARENT_CATEGORY_ID",pageWrap.getModel().getParentCategoryId())
                .eq(!Objects.isNull(pageWrap.getModel()) && Objects.nonNull(pageWrap.getModel().getCategoryId()),
                        "g.CATEGORY_ID", pageWrap.getModel().getCategoryId())
                .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()),
//                       "","")
                .eq("g.STATUS", Constants.ZERO)
                .like(StringUtils.isNotBlank(pageWrap.getModel().getGoodsName()),"g.NAME",pageWrap.getModel().getGoodsName());
//                .eq(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getType()), "g.TYPE", pageWrap.getModel().getType());
                .like(StringUtils.isNotBlank(model.getGoodsName()),"g.NAME",model.getGoodsName());
                for(PageWrap.SortData sortData:pageWrap.getSorts1()){
                    if ("CREATE_DATE".equalsIgnoreCase(sortData.getProperty())){
                        if (PageWrap.ASC.equalsIgnoreCase(sortData.getDirection())){
                            wrapper.orderByAsc("g.CREATE_DATE");
                        }
                if(Objects.nonNull(model.getSortInfo())){
                    //排序方式:0=综合排序;1=销量由低到高 ;2=价格由低到高;3=销量由高到低;4=价格由高到低
                    if(Constants.equalsInteger(model.getSortInfo(),Constants.ZERO)){
                        wrapper.orderByDesc("g.CREATE_DATE");
                    }
                    if ("realSaleNum".equalsIgnoreCase(sortData.getProperty())){
                        if (PageWrap.ASC.equalsIgnoreCase(sortData.getDirection())){
                            wrapper.orderByAsc("realSaleNum");
                        }
                    }else if(Constants.equalsInteger(model.getSortInfo(),Constants.ONE)){
                        wrapper.orderByAsc("realSaleNum");
                    }else if(Constants.equalsInteger(model.getSortInfo(),Constants.TWO)){
                        wrapper.orderByAsc("g.price");
                    }else if(Constants.equalsInteger(model.getSortInfo(),Constants.THREE)){
                        wrapper.orderByDesc("realSaleNum");
                    }else if(Constants.equalsInteger(model.getSortInfo(),Constants.FOUR)){
                        wrapper.orderByDesc("g.price");
                    }
                    if ("PRICE".equalsIgnoreCase(sortData.getProperty())){
                        if (PageWrap.ASC.equalsIgnoreCase(sortData.getDirection())){
                            wrapper.orderByAsc("g.PRICE");
                        }
                        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);
        if (!CollectionUtils.isEmpty(page.getRecords())){
            String preFixPath = systemDictDataBiz.getPreFixPath(Constants.RESOURCE_PATH, Constants.GOODS_FILE);
            page.getRecords().forEach(s->s.setImgurl(preFixPath+s.getImgurl()));
        }
@@ -888,6 +919,7 @@
        String fullUrl = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+
                systemDictDataBiz.queryByCode(Constants.OSS,Constants.GOODS_FILE).getCode();
        Integer sumStock = Constants.ZERO;
        for (GoodsSkuResponse goodsSkuResponse:goodsSkuResponseList) {
            if(StringUtils.isBlank(goodsSkuResponse.getImgurl())){
                goodsSkuResponse.setImgurl(fullUrl + goodsSkuResponse.getGoodsImgUrl());
@@ -920,8 +952,11 @@
                indexData.append("," + ( skuAttr.getSortnum()-1));
            }
            goodsSkuResponse.setIndexData(indexData.toString().substring(1));
            sumStock = sumStock + goodsSkuResponse.getStock();
        }
        //真实销量 = realSaleNum  - saleNum;
        //真实库存= sumStock - (realSaleNum  - saleNum)
        goodsResponse.setStock(sumStock - goodsResponse.getRealSaleNum() + goodsResponse.getSaleNum());
        goodsResponse.setGoodsSkuResponseList(goodsSkuResponseList);
        //Sku基础信息
        List<SkuResponse> skuResponseList = skuMapper.getSkuResponseList(goodsResponse.getId());
@@ -943,7 +978,7 @@
                systemDictDataBiz.queryByCode(Constants.OSS,Constants.GOODS_FILE).getCode();
        GoodsInfoResponse goodsResponse = goodsMapper.getGoodsInfo(goodsId);
        if(Objects.isNull(goodsResponse)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前专区关联商品已删除");
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        goodsResponse.setImgurl(fullUrl + goodsResponse.getImgurl());
        //查询商品的分类
@@ -960,6 +995,7 @@
                                                                                            Constants.GOODS_FILE);
        List<MultiFileDTO> multiFileDTOS = objAllFileUrl.get(Constants.MultiFile.PLATFORM_GOOD_ROTATION.getKey());
        goodsResponse.setGoodBannerMultiFiles(multiFileDTOS);
        return goodsResponse;
    }