huliguo
3 天以前 3348eda2c33469e9935ae6afcf83ea5c52cea906
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java
@@ -20,11 +20,13 @@
import com.ruoyi.other.api.domain.*;
import com.ruoyi.other.dto.AddGoodsDTO;
import com.ruoyi.other.enums.GoodsStatus;
import com.ruoyi.other.mapper.GoodsEvaluateMapper;
import com.ruoyi.other.mapper.GoodsMapper;
import com.ruoyi.other.mapper.GoodsShopMapper;
import com.ruoyi.other.mapper.ShopMapper;
import com.ruoyi.other.service.*;
import com.ruoyi.other.util.GeodesyUtil;
import com.ruoyi.other.vo.GoodsEvaluateVO;
import com.ruoyi.other.vo.GoodsVO;
import com.ruoyi.other.vo.NearbyShopVO;
import com.ruoyi.system.api.domain.SysConfig;
@@ -39,6 +41,7 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -76,6 +79,8 @@
    @Resource
    private ShopService shopService;
    @Resource
    private GoodsEvaluateMapper goodsEvaluateMapper;
    /**
     * 热门商品列表
@@ -87,9 +92,11 @@
    public PageInfo<GoodsVO> goodsList(Goods search) {
        List<Long> shopIds=null;
        if (null!=search.getLongitude()&&null!=search.getLatitude()){
            //获取最近十家店的id
            List<NearbyShopVO> nearbyShopVOS = shopService.nearbyShopList(search.getLongitude(), search.getLatitude(), new Shop());
            shopIds = nearbyShopVOS.subList(0, 10).stream().map(NearbyShopVO::getId).collect(Collectors.toList());
            int endIndex = Math.min(10, nearbyShopVOS.size());
            shopIds = nearbyShopVOS.subList(0, endIndex).stream().map(NearbyShopVO::getId).collect(Collectors.toList());
        }
        //查找满足条件的商品  分类、名称、附近十家店
        List<GoodsVO> list = this.baseMapper.goodsList(search.getGoodsCategoryId(), search.getName(),shopIds);
@@ -111,9 +118,6 @@
                goods.setEndTime(price.getEndTime());
                goods.setPurchaseLimit(price.getPurchaseLimit());
            }
            //已售数量
            Integer data = orderClient.getGoodsSaleNum(goods.getGoodsId(), 1).getData();
            goods.setSaleNum(data);
        }
        //手动排序
        if(StringUtils.isNotEmpty(search.getOrderByColumn())){
@@ -196,6 +200,7 @@
        }
        Goods goods = this.getById(goodsId);
        if(null == goods || goods.getDelFlag() == 1){
            throw new RuntimeException("商品不存在");
        }
@@ -226,12 +231,20 @@
        GoodsShop goodsShop = goodsShopMapper.selectOne(new LambdaQueryWrapper<GoodsShop>()
                .eq(GoodsShop::getGoodsId, goodsId));
        Shop shop1 = shopMapper.selectById(goodsShop.getShopId());
        ArrayList<Shop> shops = new ArrayList<>();
        shops.add(shop1);
        goodsVO.setShopList(shops);
        goodsVO.setShop(shop1);
        //已售数量
        Integer integer = orderClient.getGoodsSaleNum(goods.getId(), 1).getData();
        goodsVO.setSaleNum(integer);
        //商品评价
        GoodsEvaluate goodsEvaluate=goodsEvaluateMapper.getGoodsEvaluateOne(goods.getId());
        if (null != goodsEvaluate){
            AppUser appUserById = appUserClient.getAppUserById(goodsEvaluate.getAppUserId());
            goodsEvaluate.setAvatar(appUserById.getAvatar());
            goodsEvaluate.setUserName(appUserById.getName());
            goodsVO.setGoodsEvaluate(goodsEvaluate);
        }
        return goodsVO;
    }
@@ -241,6 +254,9 @@
    public List<GoodsVO> getGoodsListByShopId(PageInfo<GoodsVO> pageInfo, Integer shopId) {
        //查询该门店商品
        List<GoodsVO> goods = goodsMapper.selectListByShopId(pageInfo, shopId);
        if (goods == null) {
            return null;
        }
        for (GoodsVO good : goods) {
            //价格
            Price price = getPrice( good.getGoodsId());
@@ -259,42 +275,43 @@
    }
    @Override
    public IPage<Goods> getManageGoodsList(Page<Goods> page, Goods goods) {
        IPage<Goods> goodsIPage = goodsMapper.selectManageGoodsList(page, goods);
        goodsIPage.getRecords().forEach(goods1 -> {
            Integer data = orderClient.getGoodsSaleNum(goods1.getId(), 1).getData();
            goods1.setSaleNum(data);
        });
        return goodsIPage;
    public R getManageGoodsList(Integer pageNum,Integer pageSize,  Goods goods) {
        PageInfo<Goods> pageInfo = new PageInfo<>(pageNum,pageSize);
        List<Goods> list = goodsMapper.selectManageGoodsList(pageInfo, goods);
        pageInfo.setRecords(list);
        return R.ok(pageInfo);
    }
    @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 (null != appointStore && appointStore == 1){
            List<GoodsShop> goodsShopList = goods.getGoodsShopList();
            if (CollectionUtils.isEmpty(goodsShopList)){
                throw new NullPointerException("请选择指定门店");
            }
            saveGoodsShopList(goodsShopList, goods.getId());
        }*/
        //保存商品门店关系
        GoodsShop goodsShop = new GoodsShop();
        goodsShop.setGoodsId(goods.getId());
        goodsShop.setShopId(goods.getShopId());
        Shop shop = shopMapper.selectById(goods.getShopId());
        goodsShop.setShopName(shop.getName());
        goodsShop.setOwnerName(shop.getShopManager());
        goodsShop.setPhone(shop.getPhone());
        goodsShop.setAddress(shop.getAddress());
        goodsShopService.save(goodsShop);
        //判断是否参加秒杀活动
    }
    @Override
    public void updateManageGoods(Goods goods) {
       /* this.updateById(goods);
        this.updateById(goods);
        //修改个别字段
        this.update(new LambdaUpdateWrapper<Goods>().eq(Goods::getId, goods.getId()).set(Goods::getSellingPrice, goods.getSellingPrice())
                .set(Goods::getIntegral, goods.getIntegral()));
        // 指定门店
        List<GoodsShop> goodsShopList = goods.getGoodsShopList();
        saveGoodsShopList(goodsShopList, goods.getId());*/
        // 保存门店
        saveGoodsShop(goods.getShopId(),goods.getId());
    }
@@ -304,16 +321,16 @@
    private void saveGoodsShopList(List<GoodsShop> goodsShopList, Integer goodsId) {
    private void saveGoodsShop(Integer shopId, Integer goodsId) {
        goodsShopService.remove(new LambdaQueryWrapper<GoodsShop>()
                .eq(GoodsShop::getGoodsId, goodsId));
        if (!CollectionUtils.isEmpty(goodsShopList)){
            for (GoodsShop goodsShop : goodsShopList) {
                goodsShop.setGoodsId(goodsId);
                goodsShop.setId(null);
            }
        }
        goodsShopService.saveBatch(goodsShopList);
        GoodsShop goodsShop = new GoodsShop();
        goodsShop.setGoodsId(goodsId);
        goodsShop.setShopId(shopId);
        goodsShop.setId(null);
        goodsShopService.save(goodsShop);
    }
    @Override
@@ -322,20 +339,18 @@
        if (goods == null){
            return null;
        }
        // 指定门店
        List<GoodsShop> goodsShops = goodsShopService.list(new LambdaQueryWrapper<GoodsShop>()
        // 获取指定门店
        GoodsShop goodsShop = goodsShopService.getOne(new LambdaQueryWrapper<GoodsShop>()
                .eq(GoodsShop::getGoodsId, goodsId));
        for (GoodsShop goodsShop : goodsShops) {
            Shop shop = shopMapper.selectById(goodsShop.getShopId());
            if(null != shop){
                goodsShop.setShopName(shop.getName());
                goodsShop.setOwnerName(shop.getShopManager());
                goodsShop.setPhone(shop.getPhone());
                goodsShop.setAddress(shop.getAddress());
            }
        goods.setShopId(goodsShop.getShopId());
        Shop shop = shopService.getById(goodsShop.getShopId());
        if(null != shop){
            goodsShop.setShopName(shop.getName());
            goodsShop.setPhone(shop.getPhone());
            goodsShop.setAddress(shop.getAddress());
            goodsShop.setOwnerName(shop.getShopManager());
        }
//        goods.setGoodsShopList(goodsShops);
        goods.setGoodsShop(goodsShop);
        return goods;
    }