jiangping
2023-09-18 69c65dda53f5fa7007130e6a7339666b5b5ef52a
server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java
@@ -130,7 +130,7 @@
    @Override
    public  Integer createPlat(GoodCreatePlatRequest param){
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(Constants.equalsInteger(user.getType(), Constants.UserType.COMPANY.getKey())){
        if(!Constants.equalsInteger(user.getType(), Constants.UserType.COMPANY.getKey())){
            //非企业用户不能操作
            throw new BusinessException(ResponseStatus.NOT_ALLOWED);
        }
@@ -143,7 +143,7 @@
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        Category category = categoryMapper.selectById(param.getCategoryId());
        if(category ==null ||Constants.equalsInteger(category.getIsdeleted(), Constants.ONE) ||Constants.equalsInteger(category.getCompanyId(), user.getCompanyId())){
        if(category ==null ||Constants.equalsInteger(category.getIsdeleted(), Constants.ONE) ||!Constants.equalsInteger(category.getCompanyId(), user.getCompanyId())){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,类别信息不正确,请刷新重试!");
        }
        if(category.getPlatCateId() == null){
@@ -160,11 +160,14 @@
                if(p.getGoodsId() == null || p.getPrice() == null){
                    throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请正确选择平台商品并配置入手价!");
                }
                if(ids == null){
                    ids = new ArrayList<>();
                }
                ids.add(p.getGoodsId());
            }
        }
        goodsList = baseGoodsMapper.selectList(new QueryWrapper<>(bp).lambda().in((ids!=null && ids.size()>0),BaseGoods::getId,ids));
        if(Constants.equalsInteger(Constants.ONE, param.getType()) || goodsList==null || ids.size()!=goodsList.size()){
        if(Constants.equalsInteger(Constants.ONE, param.getType()) &&( goodsList==null || ids.size()!=goodsList.size())){
            //  如果选择平台商品和查询结果对不上,提示错误
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请正确选择平台商品!");
        }
@@ -219,6 +222,7 @@
        goods.setStatus(Constants.ZERO);
        goods.setCreateDate(new Date());
        goods.setCreator(user.getId());
        goods.setCompanyId(user.getCompanyId());
        goods.setIsdeleted(Constants.ZERO);
        //处理拼音问题
        goods.setPinyin(PinYinUtil.getFullSpell(goods.getName()));
@@ -227,7 +231,7 @@
        goods.setCategoryId(param.getCategoryId());
        //获取入手价格
        goods.setPrice(getPriceFromParam(model,param));
        goods.setZdPrice(model.getZdPrice());g
        goods.setZdPrice(model.getZdPrice());
        goods.setRemark(model.getRemark());
        goods.setImgurl(model.getImgurl());
        goods.setBrandId(model.getBrandId());
@@ -559,8 +563,8 @@
    @Override
    public Goods findById(Integer id) {
        Goods goods = goodsMapper.selectById(id);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
                + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
        goods.setPrefixUrl(prefixUrl);
        Brand brand = brandMapper.selectById(goods.getBrandId());
        if(!Objects.isNull(brand)){
@@ -603,8 +607,8 @@
                Goods::getPrice,goods.getSPrice(),goods.getEPrice());
        queryWrapper.orderByDesc(Goods::getId);
        List<Goods> goodsList = goodsJoinMapper.selectJoinList(Goods.class,queryWrapper);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
                + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
        goodsList.forEach(i->{
            i.setPrefixUrl(prefixUrl);
            i.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",i.getId()).orderByAsc(" SORTNUM ")));
@@ -621,11 +625,16 @@
        queryWrapper.selectAll(Goods.class);
        queryWrapper.selectAs(Category::getName, Goods::getCategoryName);
        queryWrapper.selectAs(BaseGoods::getZdPrice, Goods::getBaseZdPrice);
        queryWrapper.selectAs(BaseGoods::getPrice, Goods::getBasePrice);
        queryWrapper.selectAs(Brand::getName, Goods::getBrandName);
        queryWrapper.selectAs(Category::getAttrFirst, Goods::getAttrFirst);
        queryWrapper.selectAs(Category::getAttrSecond, Goods::getAttrSecond);
        queryWrapper.selectAs(BaseCategory::getPriceRate,Goods::getBasePriceRate);
        queryWrapper.leftJoin(Category.class, Category::getId, Goods::getCategoryId);
        queryWrapper.leftJoin(Brand.class, Brand::getId, Goods::getBrandId);
        queryWrapper.leftJoin(BaseGoods.class,BaseGoods::getId,Goods::getGoodsId);
        queryWrapper.leftJoin(BaseCategory.class,BaseCategory::getId,BaseGoods::getCategoryId);
        queryWrapper.eq(Goods::getIsdeleted, Constants.ZERO);
        if (pageWrap.getModel().getId() != null) {
@@ -644,14 +653,19 @@
        if (pageWrap.getModel().getBrandId() != null) {
            queryWrapper.eq(Goods::getBrandId, pageWrap.getModel().getBrandId());
        }
        if (pageWrap.getModel().getCompanyId() != null) {
            queryWrapper.eq(Goods::getCompanyId, pageWrap.getModel().getCompanyId());
        }
        queryWrapper.orderByDesc(Goods::getId);
        IPage<Goods> goodsIPage =  goodsJoinMapper.selectJoinPage(page, Goods.class, queryWrapper);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
                + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
        goodsIPage.getRecords().forEach(i->{
            i.setPrefixUrl(prefixUrl);
            if(i.getType().equals(Constants.ONE)){
                i.setBasePrice(i.getBasePrice().multiply(i.getBasePriceRate()));
            }
        });
        return PageData.from(goodsIPage);
    }
@@ -761,54 +775,54 @@
            //查询全部属性1和属性2规格值
            List<CateAttr> allAttr = cateAttrMapper.selectList(new QueryWrapper<>(ca));
            //属性1集合
            String[] attrs = StringUtils.defaultString(m.getAttrFirstNames(),"").split("\n");
//            String[] attrs = StringUtils.defaultString(m.getAttrFirstNames(),"").split("\n");
            //属性2集合
            String[] attrs2 = StringUtils.defaultString(m.getAttrSecodNames(),"").split("\n");
//            String[] attrs2 = StringUtils.defaultString(m.getAttrSecodNames(),"").split("\n");
            //产品参数集合
            String[] params =  StringUtils.defaultString(m.getParamStr(),"").split("\n");
            if(attrs.length > 0){
                String attrids="" ,attrNames="";
                for(String s : attrs){
                    if(StringUtils.isBlank(s)){
                        continue;
                    }
                    //查询属性规格对象
                    CateAttr ta = getCateAttrByName(s,Constants.ZERO,allAttr);
                    if(ta == null){
                        throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行属性1中【"+s+"】无效,请检查输入!");
                    }
                    if(StringUtils.isNotBlank(attrids)){
                        attrids += ",";
                        attrNames += ",";
                    }
                    attrids+= ta.getId();
                    attrNames+= ta.getName();
                }
                newModel.setAttrFirstIds(attrids);
                newModel.setAttrFirstNames(attrNames);
            }
            if(attrs2.length > 0){
                String attrids="" ,attrNames="";
                for(String s : attrs2){
                    if(StringUtils.isBlank(s)){
                        continue;
                    }
                    //查询属性规格对象
                    CateAttr ta = getCateAttrByName(s,Constants.ONE,allAttr);
                    if(ta == null){
                        throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行属性1中【"+s+"】无效,请检查输入!");
                    }
                    if(StringUtils.isNotBlank(attrids)){
                        attrids += ",";
                        attrNames += ",";
                    }
                    attrids+= ta.getId();
                    attrNames+= ta.getName();
                }
                newModel.setAttrSecodIds(attrids);
                newModel.setAttrSecodNames(attrNames);
            }
//            if(attrs.length > 0){
//                String attrids="" ,attrNames="";
//                for(String s : attrs){
//                    if(StringUtils.isBlank(s)){
//                        continue;
//                    }
//                    //查询属性规格对象
//                    CateAttr ta = getCateAttrByName(s,Constants.ZERO,allAttr);
//                    if(ta == null){
//                        throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行属性1中【"+s+"】无效,请检查输入!");
//                    }
//                    if(StringUtils.isNotBlank(attrids)){
//                        attrids += ",";
//                        attrNames += ",";
//                    }
//                    attrids+= ta.getId();
//                    attrNames+= ta.getName();
//                }
//                newModel.setAttrFirstIds(attrids);
//                newModel.setAttrFirstNames(attrNames);
//            }
//            if(attrs2.length > 0){
//                String attrids="" ,attrNames="";
//                for(String s : attrs2){
//                    if(StringUtils.isBlank(s)){
//                        continue;
//                    }
//                    //查询属性规格对象
//                    CateAttr ta = getCateAttrByName(s,Constants.ONE,allAttr);
//                    if(ta == null){
//                        throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行属性1中【"+s+"】无效,请检查输入!");
//                    }
//                    if(StringUtils.isNotBlank(attrids)){
//                        attrids += ",";
//                        attrNames += ",";
//                    }
//                    attrids+= ta.getId();
//                    attrNames+= ta.getName();
//                }
//                newModel.setAttrSecodIds(attrids);
//                newModel.setAttrSecodNames(attrNames);
//
//            }
            List<String> mulFiles = null;
            String proDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROJECTS).getCode();
@@ -890,6 +904,20 @@
                    gp.setSortnum(ta.getSortnum());
                    //插入产品参数关联表
                    goodsParamMapper.insert(gp);
                    //存储 cate_param_select 查询是否已存在
                    if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>()
                            .eq("PARAM_ID",gp.getPramaId()).eq("NAME",gp.getName()))<=Constants.ZERO){
                        CateParamSelect cateParamSelect = new CateParamSelect();
                        cateParamSelect.setCreator(user.getId());
                        cateParamSelect.setCreateDate(new Date());
                        cateParamSelect.setName(gp.getVal());
                        cateParamSelect.setIsdeleted(Constants.ZERO);
                        cateParamSelect.setStatus(Constants.ZERO);
                        cateParamSelect.setParamId(gp.getPramaId());
                        cateParamSelect.setCategoryId(newModel.getCategoryId());
                        cateParamSelect.setStatus(Constants.ZERO);
                        cateParamSelectMapper.insert(cateParamSelect);
                    };
                }
            }
            if(mulFiles !=null && mulFiles.size()>0){