Helius
2022-05-10 722f17e0fc6a1fbe709bd02bbb7c75b8da435e07
src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
@@ -49,55 +49,59 @@
    @Transactional
    public FebsResponse addMallGoods(AddMallGoodsDto addMallGoodsDto) {
        String goodsName = addMallGoodsDto.getGoodsName();
        if(StrUtil.isEmpty(goodsName)){
        if (StrUtil.isEmpty(goodsName)) {
            return new FebsResponse().fail().message("商品名称不能为空");
        }
        Integer mallGoodsByGoodsName = mallGoodsMapper.selectMallGoodsCountByGoodsName(goodsName);
        if(mallGoodsByGoodsName > 0){
        if (mallGoodsByGoodsName > 0) {
            return new FebsResponse().fail().message("商品名称不能重复");
        }
        String goodsNo = addMallGoodsDto.getGoodsNo();
        if(StrUtil.isEmpty(goodsNo)){
        if (StrUtil.isEmpty(goodsNo)) {
            return new FebsResponse().fail().message("商品编号不能为空");
        }
        Integer mallGoodsByGoodsNo = mallGoodsMapper.selectMallGoodsCountByGoodsNo(goodsNo);
        if(mallGoodsByGoodsNo > 0){
        if (mallGoodsByGoodsNo > 0) {
            return new FebsResponse().fail().message("商品编号不能重复");
        }
        Long categoryId = addMallGoodsDto.getCategoryId();
        if(ObjectUtil.isEmpty(categoryId)){
            return new FebsResponse().fail().message("商品分类不能为空");
        }
        List<AddMallGoodsSkuDto> addSkus = addMallGoodsDto.getAddMallGoodsSkuDtos();
        if(CollUtil.isEmpty(addSkus)){
            return new FebsResponse().fail().message("商品规格不能为空");
        }
        for(AddMallGoodsSkuDto addSku : addSkus){
            String skuName = addSku.getSkuName();
            if(StrUtil.isEmpty(skuName)){
                return new FebsResponse().fail().message("商品规格名称不能为空");
            }
            String skuImage = addSku.getSkuImage();
            if(StrUtil.isEmpty(skuImage)){
                return new FebsResponse().fail().message("商品规格图片不能为空");
            }
            Integer skuVolume = addSku.getSkuVolume()==null?0: addSku.getSkuVolume();
            if(skuVolume < 0){
                return new FebsResponse().fail().message("商品规格销售数量不能小于0");
            }
            Integer stock = addSku.getStock()==null?0: addSku.getStock();
            if(stock < 0){
                return new FebsResponse().fail().message("商品规格库存必须大于0");
            }
            String originalPrice = addSku.getOriginalPrice();
            if(StrUtil.isEmpty(originalPrice)){
                return new FebsResponse().fail().message("商品规格原价不能为空");
            }
            String presentPrice = addSku.getPresentPrice();
            if(StrUtil.isEmpty(presentPrice)){
                return new FebsResponse().fail().message("商品规格现价不能为空");
        // 付费商品
        if (addMallGoodsDto.getGoodsType() != 2) {
            Long categoryId = addMallGoodsDto.getCategoryId();
            if (ObjectUtil.isEmpty(categoryId)) {
                return new FebsResponse().fail().message("商品分类不能为空");
            }
            List<AddMallGoodsSkuDto> addSkus = addMallGoodsDto.getAddMallGoodsSkuDtos();
            if (CollUtil.isEmpty(addSkus)) {
                return new FebsResponse().fail().message("商品规格不能为空");
            }
            for (AddMallGoodsSkuDto addSku : addSkus) {
                String skuName = addSku.getSkuName();
                if (StrUtil.isEmpty(skuName)) {
                    return new FebsResponse().fail().message("商品规格名称不能为空");
                }
                String skuImage = addSku.getSkuImage();
                if (StrUtil.isEmpty(skuImage)) {
                    return new FebsResponse().fail().message("商品规格图片不能为空");
                }
                Integer skuVolume = addSku.getSkuVolume() == null ? 0 : addSku.getSkuVolume();
                if (skuVolume < 0) {
                    return new FebsResponse().fail().message("商品规格销售数量不能小于0");
                }
                Integer stock = addSku.getStock() == null ? 0 : addSku.getStock();
                if (stock < 0) {
                    return new FebsResponse().fail().message("商品规格库存必须大于0");
                }
                String originalPrice = addSku.getOriginalPrice();
                if (StrUtil.isEmpty(originalPrice)) {
                    return new FebsResponse().fail().message("商品规格原价不能为空");
                }
                String presentPrice = addSku.getPresentPrice();
                if (StrUtil.isEmpty(presentPrice)) {
                    return new FebsResponse().fail().message("商品规格现价不能为空");
                }
            }
        }
        //新增商品
        MallGoods mallGoods = MallGoodsConversion.INSTANCE.dtoToEntity(addMallGoodsDto);
@@ -105,11 +109,11 @@
        mallGoodsMapper.insert(mallGoods);
        String thumbs = addMallGoodsDto.getThumbs();
        if(StrUtil.isNotEmpty(thumbs)){
        if (StrUtil.isNotEmpty(thumbs)) {
            List<String> imgs = StrUtil.splitTrim(thumbs, ",");
            if(CollUtil.isNotEmpty(imgs)){
            if (CollUtil.isNotEmpty(imgs)) {
                int i = 1;
                for(String img : imgs){
                for (String img : imgs) {
                    MallGoodsImages mallGoodsImages = new MallGoodsImages();
                    mallGoodsImages.setGoodsId(mallGoods.getId());
                    mallGoodsImages.setImageUrl(img);
@@ -120,17 +124,20 @@
            }
        }
        if (addMallGoodsDto.getGoodsType() == 2) {
            return new FebsResponse().success().message("添加成功");
        }
        List<AddMallGoodsSkuDto> addMallGoodsSkuDtos = addMallGoodsDto.getAddMallGoodsSkuDtos();
        Set<String> styles = new HashSet<>();
        if(CollUtil.isNotEmpty(addMallGoodsSkuDtos)){
            for(AddMallGoodsSkuDto addStyleDto : addMallGoodsSkuDtos){
        if (CollUtil.isNotEmpty(addMallGoodsSkuDtos)) {
            for (AddMallGoodsSkuDto addStyleDto : addMallGoodsSkuDtos) {
                styles.add(addStyleDto.getStyleName());
            }
        }
        if(CollUtil.isNotEmpty(styles)){
            for(String style : styles){
        if (CollUtil.isNotEmpty(styles)) {
            for (String style : styles) {
                //新增样式
                MallGoodsStyle mallGoodsStyle = new MallGoodsStyle();
                mallGoodsStyle.setName(style);
@@ -140,15 +147,15 @@
        }
        if(CollUtil.isNotEmpty(addMallGoodsSkuDtos)){
            for(AddMallGoodsSkuDto addMallGoodsSkuDto : addMallGoodsSkuDtos){
                MallGoodsStyle mallGoodsStyleSku = mallGoodsStyleMapper.selectByStyleName(addMallGoodsSkuDto.getStyleName(),mallGoods.getId());
        if (CollUtil.isNotEmpty(addMallGoodsSkuDtos)) {
            for (AddMallGoodsSkuDto addMallGoodsSkuDto : addMallGoodsSkuDtos) {
                MallGoodsStyle mallGoodsStyleSku = mallGoodsStyleMapper.selectByStyleName(addMallGoodsSkuDto.getStyleName(), mallGoods.getId());
                //新增商品规格
                MallGoodsSku mallGoodsSku = new MallGoodsSku();
                mallGoodsSku.setSkuName(addMallGoodsSkuDto.getSkuName());
                mallGoodsSku.setSkuImage(addMallGoodsSkuDto.getSkuImage());
                mallGoodsSku.setStock(addMallGoodsSkuDto.getStock()==null?0:addMallGoodsSkuDto.getStock());
                mallGoodsSku.setSkuVolume(addMallGoodsSkuDto.getSkuVolume()==null?0:addMallGoodsSkuDto.getSkuVolume());
                mallGoodsSku.setStock(addMallGoodsSkuDto.getStock() == null ? 0 : addMallGoodsSkuDto.getStock());
                mallGoodsSku.setSkuVolume(addMallGoodsSkuDto.getSkuVolume() == null ? 0 : addMallGoodsSkuDto.getSkuVolume());
                mallGoodsSku.setOriginalPrice(new BigDecimal(addMallGoodsSkuDto.getOriginalPrice()));
                mallGoodsSku.setPresentPrice(new BigDecimal(addMallGoodsSkuDto.getPresentPrice()));
                mallGoodsSku.setStyleId(mallGoodsStyleSku.getId());
@@ -164,7 +171,7 @@
    @Override
    public FebsResponse upMallGoods(Long id) {
        MallGoods mallGoods = mallGoodsMapper.selectById(id);
        if(ObjectUtil.isEmpty(mallGoods)){
        if (ObjectUtil.isEmpty(mallGoods)) {
            return new FebsResponse().fail().message("商品不存在,请刷新当前页面");
        }
        mallGoods.setIsSale(MallGoods.ISSALE_STATUS_ENABLE);
@@ -175,7 +182,7 @@
    @Override
    public FebsResponse downMallGoods(Long id) {
        MallGoods mallGoods = mallGoodsMapper.selectById(id);
        if(ObjectUtil.isEmpty(mallGoods)){
        if (ObjectUtil.isEmpty(mallGoods)) {
            return new FebsResponse().fail().message("商品不存在,请刷新当前页面");
        }
        mallGoods.setIsSale(MallGoods.ISSALE_STATUS_DISABLED);
@@ -187,11 +194,11 @@
    @Transactional
    public FebsResponse delMallGoods(Long id) {
        MallGoods mallGoods = mallGoodsMapper.selectById(id);
        if(ObjectUtil.isEmpty(mallGoods)){
        if (ObjectUtil.isEmpty(mallGoods)) {
            return new FebsResponse().fail().message("商品不存在,请刷新当前页面");
        }
        Integer isSale = mallGoods.getIsSale();
        if(MallGoods.ISSALE_STATUS_DISABLED != isSale){
        if (MallGoods.ISSALE_STATUS_DISABLED != isSale) {
            return new FebsResponse().fail().message("请先下架该商品");
        }
@@ -215,11 +222,11 @@
    public AdminMailGoodsUpdateVo getMallGoodsUpdateInfoById(long id) {
        AdminMailGoodsUpdateVo adminMailGoodsUpdateVo = mallGoodsMapper.getMallGoodsUpdateInfoById(id);
        List<AdminMailGoodsSkuDetailVo> adminMailGoodsSkuDetailVos = mallGoodsSkuMapper.selectByGoodId(id);
        if(CollUtil.isNotEmpty(adminMailGoodsSkuDetailVos)){
        if (CollUtil.isNotEmpty(adminMailGoodsSkuDetailVos)) {
            adminMailGoodsUpdateVo.setMailGoodsSkuDetailVo(adminMailGoodsSkuDetailVos);
        }
        List<String> adminMailGoodsImagesVos = mallGoodsImagesMapper.selectByGoodId(id);
        if(CollUtil.isNotEmpty(adminMailGoodsImagesVos)){
        if (CollUtil.isNotEmpty(adminMailGoodsImagesVos)) {
            adminMailGoodsUpdateVo.setMailGoodsImagesVo(adminMailGoodsImagesVos);
        }
        return adminMailGoodsUpdateVo;
@@ -229,52 +236,52 @@
    @Transactional
    public FebsResponse updateMallGoods(MallGoodsUpdateDto mallGoodsUpdateDto) {
        String goodsName = mallGoodsUpdateDto.getGoodsName();
        if(StrUtil.isEmpty(goodsName)){
        if (StrUtil.isEmpty(goodsName)) {
            return new FebsResponse().fail().message("商品名称不能为空");
        }
        Integer mallGoodsByGoodsName = mallGoodsMapper.selectMallGoodsCountByGoodsNameAndGoodId(goodsName,mallGoodsUpdateDto.getId());
        if(mallGoodsByGoodsName > 0){
        Integer mallGoodsByGoodsName = mallGoodsMapper.selectMallGoodsCountByGoodsNameAndGoodId(goodsName, mallGoodsUpdateDto.getId());
        if (mallGoodsByGoodsName > 0) {
            return new FebsResponse().fail().message("商品名称不能重复");
        }
        String goodsNo = mallGoodsUpdateDto.getGoodsNo();
        if(StrUtil.isEmpty(goodsNo)){
        if (StrUtil.isEmpty(goodsNo)) {
            return new FebsResponse().fail().message("商品编号不能为空");
        }
        Integer mallGoodsByGoodsNo = mallGoodsMapper.selectMallGoodsCountByGoodsNoAndGoodId(goodsNo,mallGoodsUpdateDto.getId());
        if(mallGoodsByGoodsNo > 0){
        Integer mallGoodsByGoodsNo = mallGoodsMapper.selectMallGoodsCountByGoodsNoAndGoodId(goodsNo, mallGoodsUpdateDto.getId());
        if (mallGoodsByGoodsNo > 0) {
            return new FebsResponse().fail().message("商品编号不能重复");
        }
        Long categoryId = mallGoodsUpdateDto.getCategoryId();
        if(ObjectUtil.isEmpty(categoryId)){
        if (ObjectUtil.isEmpty(categoryId)) {
            return new FebsResponse().fail().message("商品分类不能为空");
        }
        List<MailGoodsSkuDto> addSkus = mallGoodsUpdateDto.getMailGoodsSkuDto();
        if(CollUtil.isEmpty(addSkus)){
        if (CollUtil.isEmpty(addSkus)) {
            return new FebsResponse().fail().message("商品规格不能为空");
        }
        for(MailGoodsSkuDto addSku : addSkus){
        for (MailGoodsSkuDto addSku : addSkus) {
            String skuName = addSku.getSkuName();
            if(StrUtil.isEmpty(skuName)){
            if (StrUtil.isEmpty(skuName)) {
                return new FebsResponse().fail().message("商品规格名称不能为空");
            }
            String skuImage = addSku.getSkuImage();
            if(StrUtil.isEmpty(skuImage)){
            if (StrUtil.isEmpty(skuImage)) {
                return new FebsResponse().fail().message("商品规格图片不能为空");
            }
            Integer skuVolume = addSku.getSkuVolume()==null?0: addSku.getSkuVolume();
            if(skuVolume < 0){
            Integer skuVolume = addSku.getSkuVolume() == null ? 0 : addSku.getSkuVolume();
            if (skuVolume < 0) {
                return new FebsResponse().fail().message("商品规格销售数量不能小于0");
            }
            Integer stock = addSku.getStock()==null?0: addSku.getStock();
            if(stock < 0){
            Integer stock = addSku.getStock() == null ? 0 : addSku.getStock();
            if (stock < 0) {
                return new FebsResponse().fail().message("商品规格库存必须大于0");
            }
            BigDecimal originalPrice = addSku.getOriginalPrice();
            if(originalPrice.compareTo(BigDecimal.ZERO) <= 0){
            if (originalPrice.compareTo(BigDecimal.ZERO) <= 0) {
                return new FebsResponse().fail().message("商品规格原价不能小于0");
            }
            BigDecimal presentPrice = addSku.getPresentPrice();
            if(presentPrice.compareTo(BigDecimal.ZERO) <= 0){
            if (presentPrice.compareTo(BigDecimal.ZERO) <= 0) {
                return new FebsResponse().fail().message("商品规格现价不能小于0");
            }
@@ -297,11 +304,11 @@
        mallGoodsImagesMapper.deleteByGoodsId(mallGoodsUpdateDto.getId());
        String thumbs = mallGoodsUpdateDto.getThumbs();
        if(StrUtil.isNotEmpty(thumbs)){
        if (StrUtil.isNotEmpty(thumbs)) {
            List<String> imgs = StrUtil.splitTrim(thumbs, ",");
            if(CollUtil.isNotEmpty(imgs)){
            if (CollUtil.isNotEmpty(imgs)) {
                int i = 1;
                for(String img : imgs){
                for (String img : imgs) {
                    MallGoodsImages mallGoodsImages = new MallGoodsImages();
                    mallGoodsImages.setGoodsId(mallGoods.getId());
                    mallGoodsImages.setImageUrl(img);
@@ -314,23 +321,23 @@
        List<MailGoodsSkuDto> mailGoodsSkuDto = mallGoodsUpdateDto.getMailGoodsSkuDto();
        Set<String> styles = new HashSet<>();
        if(CollUtil.isNotEmpty(mailGoodsSkuDto)){
            for(MailGoodsSkuDto addStyleDto : mailGoodsSkuDto){
                if(ObjectUtil.isNotEmpty(addStyleDto.getDelLog())){
        if (CollUtil.isNotEmpty(mailGoodsSkuDto)) {
            for (MailGoodsSkuDto addStyleDto : mailGoodsSkuDto) {
                if (ObjectUtil.isNotEmpty(addStyleDto.getDelLog())) {
                    mallGoodsSkuMapper.deleteById(addStyleDto.getId());
                    mallShoppingCartMapper.deleteByGoodsIdAndSkuId(addStyleDto.getId(),addStyleDto.getGoodsId());
                    mallShoppingCartMapper.deleteByGoodsIdAndSkuId(addStyleDto.getId(), addStyleDto.getGoodsId());
                }
                if(ObjectUtil.isEmpty(addStyleDto.getStyleId())){
                    MallGoodsStyle mallGoodsStyleSku = mallGoodsStyleMapper.selectByStyleName(addStyleDto.getStyleName(),mallGoods.getId());
                    if(ObjectUtil.isEmpty(mallGoodsStyleSku)){
                if (ObjectUtil.isEmpty(addStyleDto.getStyleId())) {
                    MallGoodsStyle mallGoodsStyleSku = mallGoodsStyleMapper.selectByStyleName(addStyleDto.getStyleName(), mallGoods.getId());
                    if (ObjectUtil.isEmpty(mallGoodsStyleSku)) {
                        styles.add(addStyleDto.getStyleName());
                    }
                }
            }
        }
        if(CollUtil.isNotEmpty(styles)){
            for(String style : styles){
        if (CollUtil.isNotEmpty(styles)) {
            for (String style : styles) {
                //新增样式
                MallGoodsStyle mallGoodsStyle = new MallGoodsStyle();
                mallGoodsStyle.setName(style);
@@ -339,28 +346,28 @@
            }
        }
        if(CollUtil.isNotEmpty(mailGoodsSkuDto)){
            for(MailGoodsSkuDto addMallGoodsSkuDto : mailGoodsSkuDto){
                if(StrUtil.isEmpty(addMallGoodsSkuDto.getDelLog())){
                    if(ObjectUtil.isNotEmpty(addMallGoodsSkuDto.getId())){
        if (CollUtil.isNotEmpty(mailGoodsSkuDto)) {
            for (MailGoodsSkuDto addMallGoodsSkuDto : mailGoodsSkuDto) {
                if (StrUtil.isEmpty(addMallGoodsSkuDto.getDelLog())) {
                    if (ObjectUtil.isNotEmpty(addMallGoodsSkuDto.getId())) {
                        MallGoodsSku mallGoodsSku = mallGoodsSkuMapper.selectById(addMallGoodsSkuDto.getId());
                        mallGoodsSku.setSkuName(addMallGoodsSkuDto.getSkuName());
                        mallGoodsSku.setSkuImage(addMallGoodsSkuDto.getSkuImage());
                        mallGoodsSku.setStock(addMallGoodsSkuDto.getStock()==null?0:addMallGoodsSkuDto.getStock());
                        mallGoodsSku.setSkuVolume(addMallGoodsSkuDto.getSkuVolume()==null?0:addMallGoodsSkuDto.getSkuVolume());
                        mallGoodsSku.setStock(addMallGoodsSkuDto.getStock() == null ? 0 : addMallGoodsSkuDto.getStock());
                        mallGoodsSku.setSkuVolume(addMallGoodsSkuDto.getSkuVolume() == null ? 0 : addMallGoodsSkuDto.getSkuVolume());
                        mallGoodsSku.setOriginalPrice(addMallGoodsSkuDto.getOriginalPrice());
                        mallGoodsSku.setPresentPrice(addMallGoodsSkuDto.getPresentPrice());
                        mallGoodsSku.setStyleId(addMallGoodsSkuDto.getStyleId());
                        mallGoodsSku.setGoodsId(mallGoods.getId());
                        mallGoodsSkuMapper.updateById(mallGoodsSku);
                    }else{
                    } else {
                        //新增商品规格
                        MallGoodsStyle mallGoodsStyleSku = mallGoodsStyleMapper.selectByStyleName(addMallGoodsSkuDto.getStyleName(),mallGoods.getId());
                        MallGoodsStyle mallGoodsStyleSku = mallGoodsStyleMapper.selectByStyleName(addMallGoodsSkuDto.getStyleName(), mallGoods.getId());
                        MallGoodsSku mallGoodsSku = new MallGoodsSku();
                        mallGoodsSku.setSkuName(addMallGoodsSkuDto.getSkuName());
                        mallGoodsSku.setSkuImage(addMallGoodsSkuDto.getSkuImage());
                        mallGoodsSku.setStock(addMallGoodsSkuDto.getStock()==null?0:addMallGoodsSkuDto.getStock());
                        mallGoodsSku.setSkuVolume(addMallGoodsSkuDto.getSkuVolume()==null?0:addMallGoodsSkuDto.getSkuVolume());
                        mallGoodsSku.setStock(addMallGoodsSkuDto.getStock() == null ? 0 : addMallGoodsSkuDto.getStock());
                        mallGoodsSku.setSkuVolume(addMallGoodsSkuDto.getSkuVolume() == null ? 0 : addMallGoodsSkuDto.getSkuVolume());
                        mallGoodsSku.setOriginalPrice(addMallGoodsSkuDto.getOriginalPrice());
                        mallGoodsSku.setPresentPrice(addMallGoodsSkuDto.getPresentPrice());
                        mallGoodsSku.setStyleId(mallGoodsStyleSku.getId());