1
phpcjl
2024-12-16 73199a80eb7fff02dffb32b38c7a9784c217b1ed
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java
@@ -27,10 +27,7 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -164,12 +161,20 @@
        goodsMapper.insert(goods);
        // 指定门店
        List<GoodsShop> goodsShopList = goods.getGoodsShopList();
        goodsShopService.saveBatch(goodsShopList);
        Integer appointStore = goods.getAppointStore();
        if (appointStore == 1){
            List<GoodsShop> goodsShopList = goods.getGoodsShopList();
            if (CollectionUtils.isEmpty(goodsShopList)){
                throw new NullPointerException("请选择指定门店");
            }
            goodsShopService.saveBatch(goodsShopList);
        }
        // 指定用户
        List<GoodsAppUser> goodsAppUserList = goods.getGoodsAppUserList();
        goodsAppUserService.saveBatch(goodsAppUserList);
        if (!CollectionUtils.isEmpty(goodsAppUserList)){
            goodsAppUserService.saveBatch(goodsAppUserList);
        }
        // 会员价格配置
        List<GoodsVip> goodsVipList = goods.getGoodsVipList();
@@ -177,7 +182,21 @@
        // 特殊地区售价设置
        List<GoodsArea> goodsAreaList = goods.getGoodsAreaList();
        goodsAreaService.saveBatch(goodsAreaList);
        if (!CollectionUtils.isEmpty(goodsAreaList)){
            for (GoodsArea goodsArea : goodsAreaList) {
                List<GoodsArea> goodsAreaList1 = goodsArea.getGoodsAreaList();
                for (GoodsArea area : goodsAreaList1) {
                    area.setProvince(goodsArea.getProvince());
                    area.setCity(goodsArea.getCity());
                    area.setDistricts(goodsArea.getDistricts());
                    area.setProvinceCode(goodsArea.getProvinceCode());
                    area.setCityCode(goodsArea.getCityCode());
                    area.setDistrictsCode(goodsArea.getDistrictsCode());
                }
                goodsAreaService.saveBatch(goodsAreaList1);
            }
        }
    }
    @Override
@@ -197,7 +216,20 @@
        // 特殊地区售价设置
        List<GoodsArea> goodsAreaList = goods.getGoodsAreaList();
        goodsAreaService.updateBatchById(goodsAreaList);
        if (!CollectionUtils.isEmpty(goodsAreaList)){
            for (GoodsArea goodsArea : goodsAreaList) {
                List<GoodsArea> goodsAreaList1 = goodsArea.getGoodsAreaList();
                for (GoodsArea area : goodsAreaList1) {
                    area.setProvince(goodsArea.getProvince());
                    area.setCity(goodsArea.getCity());
                    area.setDistricts(goodsArea.getDistricts());
                    area.setProvinceCode(goodsArea.getProvinceCode());
                    area.setCityCode(goodsArea.getCityCode());
                    area.setDistrictsCode(goodsArea.getDistrictsCode());
                }
                goodsAreaService.updateBatchById(goodsAreaList1);
            }
        }
    }
    @Override
@@ -221,7 +253,19 @@
        // 特殊地区售价设置
        List<GoodsArea> goodsAreaList = goodsAreaService.list(new LambdaQueryWrapper<GoodsArea>()
                .eq(GoodsArea::getGoodsId, goodsId));
        goods.setGoodsAreaList(goodsAreaList);
        Map<String, List<GoodsArea>> listMap = goodsAreaList.stream()
                .collect(Collectors.groupingBy(goodsArea ->
                        goodsArea.getProvinceCode() + goodsArea.getCityCode() + goodsArea.getDistrictsCode()));
        List<GoodsArea> goodsAreaList1 = new ArrayList<>();
        listMap.forEach((s, goodsAreas) -> {
            GoodsArea goodsArea = goodsAreas.get(0);
            goodsArea.setGoodsAreaList(goodsAreas);
            goodsAreaList1.add(goodsArea);
        });
        goods.setGoodsAreaList(goodsAreaList1);
        return goods;
    }
}