From c5ab87860adf4a119d6c5d3417cfaa2f99b0ad38 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期二, 17 十二月 2024 10:27:46 +0800 Subject: [PATCH] 合并代码 --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java | 152 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 146 insertions(+), 6 deletions(-) diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java index 2e1bd89..b057bef 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java @@ -1,6 +1,8 @@ package com.ruoyi.other.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.account.api.feignClient.AppUserClient; import com.ruoyi.account.api.model.AppUser; @@ -16,19 +18,16 @@ import com.ruoyi.other.mapper.GoodsMapper; import com.ruoyi.other.mapper.GoodsShopMapper; import com.ruoyi.other.mapper.ShopMapper; -import com.ruoyi.other.service.GoodsService; -import com.ruoyi.other.service.GoodsVipService; -import com.ruoyi.other.service.VipSettingService; +import com.ruoyi.other.service.*; import com.ruoyi.other.vo.GoodsVO; import com.ruoyi.system.api.model.LoginUser; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** @@ -56,7 +55,13 @@ @Resource private GoodsShopMapper goodsShopMapper; @Resource + private GoodsShopService goodsShopService; + @Resource + private GoodsAppUserService goodsAppUserService; + @Resource private ShopMapper shopMapper; + @Resource + private GoodsAreaService goodsAreaService; @Resource private RemoteOrderGoodsClient remoteOrderGoodsClient; @@ -143,4 +148,139 @@ return goodsMapper.selectListByShopId(shopId, vipSetting.getId()); } + @Override + public IPage<Goods> getManageGoodsList(Page<Goods> page, Goods goods) { + return goodsMapper.selectManageGoodsList(page, goods); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void addGoods(Goods goods) { + goods.setSaleNum(0); + goods.setStatus(GoodsStatus.DOWN.getCode()); + goodsMapper.insert(goods); + + // 指定门店 + Integer appointStore = goods.getAppointStore(); + if (appointStore == 1){ + List<GoodsShop> goodsShopList = goods.getGoodsShopList(); + if (CollectionUtils.isEmpty(goodsShopList)){ + throw new NullPointerException("请选择指定门店"); + } + for (GoodsShop goodsShop : goodsShopList) { + goodsShop.setGoodsId(goods.getId()); + goodsShop.setId(null); + } + goodsShopService.saveBatch(goodsShopList); + } + + // 指定用户 + List<GoodsAppUser> goodsAppUserList = goods.getGoodsAppUserList(); + if (!CollectionUtils.isEmpty(goodsAppUserList)){ + for (GoodsAppUser goodsAppUser : goodsAppUserList) { + goodsAppUser.setId(null ); + goodsAppUser.setGoodsId(goods.getId()); + } + goodsAppUserService.saveBatch(goodsAppUserList); + } + + // 会员价格配置 + List<GoodsVip> goodsVipList = goods.getGoodsVipList(); + for (GoodsVip goodsVip : goodsVipList) { + goodsVip.setId(null); + goodsVip.setGoodsId(goods.getId()); + } + goodsVipService.saveBatch(goodsVipList); + + // 特殊地区售价设置 + List<GoodsArea> goodsAreaList = goods.getGoodsAreaList(); + if (!CollectionUtils.isEmpty(goodsAreaList)){ + for (GoodsArea goodsArea : goodsAreaList) { + List<GoodsArea> goodsAreaList1 = goodsArea.getGoodsAreaList(); + for (GoodsArea area : goodsAreaList1) { + area.setGoodsId(goods.getId()); + 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 + public void updateManageGoods(Goods goods) { + goodsMapper.updateById(goods); + // 指定门店 + List<GoodsShop> goodsShopList = goods.getGoodsShopList(); + goodsShopService.updateBatchById(goodsShopList); + + // 指定用户 + List<GoodsAppUser> goodsAppUserList = goods.getGoodsAppUserList(); + goodsAppUserService.updateBatchById(goodsAppUserList); + + // 会员价格配置 + List<GoodsVip> goodsVipList = goods.getGoodsVipList(); + goodsVipService.updateBatchById(goodsVipList); + + // 特殊地区售价设置 + List<GoodsArea> goodsAreaList = goods.getGoodsAreaList(); + if (!CollectionUtils.isEmpty(goodsAreaList)){ + for (GoodsArea goodsArea : goodsAreaList) { + List<GoodsArea> goodsAreaList1 = goodsArea.getGoodsAreaList(); + for (GoodsArea area : goodsAreaList1) { + area.setGoodsId(goods.getId()); + area.setProvince(goodsArea.getProvince()); + area.setCity(goodsArea.getCity()); + area.setDistricts(goodsArea.getDistricts()); + area.setProvinceCode(goodsArea.getProvinceCode()); + area.setCityCode(goodsArea.getCityCode()); + area.setDistrictsCode(goodsArea.getDistrictsCode()); + goodsAreaList1.add(area); + } + goodsAreaService.updateBatchById(goodsAreaList1); + } + } + } + + @Override + public Goods getManageGoodsDetail(Long goodsId) { + Goods goods = getById(goodsId); + // 指定门店 + List<GoodsShop> goodsShops = goodsShopService.list(new LambdaQueryWrapper<GoodsShop>() + .eq(GoodsShop::getGoodsId, goodsId)); + goods.setGoodsShopList(goodsShops); + + // 指定用户 + List<GoodsAppUser> goodsAppUserList = goodsAppUserService.list(new LambdaQueryWrapper<GoodsAppUser>() + .eq(GoodsAppUser::getGoodsId, goodsId)); + goods.setGoodsAppUserList(goodsAppUserList); + + // 会员价格 + List<GoodsVip> goodsVipList = goodsVipService.list(new LambdaQueryWrapper<GoodsVip>() + .eq(GoodsVip::getGoodsId, goodsId)); + goods.setGoodsVipList(goodsVipList); + + // 特殊地区售价设置 + List<GoodsArea> goodsAreaList = goodsAreaService.list(new LambdaQueryWrapper<GoodsArea>() + .eq(GoodsArea::getGoodsId, goodsId)); + + 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; + } } -- Gitblit v1.7.1