From 9d8dba1ff84484e6e3182635af537f13c809abd1 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期三, 15 一月 2025 10:43:15 +0800 Subject: [PATCH] 修改bug --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java | 67 +++++++++++++++++++++------------ 1 files changed, 43 insertions(+), 24 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 2fbcf1b..68927ec 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 @@ -165,25 +165,37 @@ }); } } - //手动处理分页 + // 手动处理分页 PageInfo<GoodsVO> pageInfo = new PageInfo<>(); pageInfo.setSize(search.getPageSize()); pageInfo.setTotal(list.size()); - Integer pageSize = search.getPageSize(); - Integer pageNum = (search.getPageCurr() - 1) * pageSize; - if(list.size() >= (pageNum + 1) * pageSize){ - list = list.subList(pageNum, pageNum + pageSize); - }else if(pageNum < list.size() && list.size() < (pageNum + 1) * pageSize){ - list = list.subList(pageNum, list.size()); - }else{ - list = new ArrayList<>(); + int pageSize = search.getPageSize(); + int pageCurr = search.getPageCurr(); + + // 计算起始索引 + int pageNum = (pageCurr - 1) * pageSize; + + // 检查 pageNum 是否合法 + if (pageNum < 0 || pageNum >= list.size()) { + // 如果 pageNum 不合法,返回空列表 + pageInfo.setRecords(new ArrayList<>()); + return pageInfo; } - return pageInfo.setRecords(list); + + // 计算结束索引 + int endIndex = Math.min(pageNum + pageSize, list.size()); + + // 获取分页数据 + List<GoodsVO> pageList = list.subList(pageNum, endIndex); + + // 设置分页结果 + pageInfo.setRecords(pageList); + return pageInfo; } @Override - public GoodsVO goodsDetail(Long goodsId, String longitude, String latitude) { + public GoodsVO goodsDetail(Long goodsId, Integer shopId, String longitude, String latitude) { if (goodsId == null || goodsId <= 0) { throw new NullPointerException("商品ID不能为空"); } @@ -216,7 +228,7 @@ BeanUtils.copyBeanProp(goodsVO, goods); goodsVO.setGoodsId(goods.getId()); goodsVO.setGoodsName(goods.getName()); - Price price = getPrice(vipId, goods.getId(), null, 1, provinceCode, cityCode, districtCode); + Price price = getPrice(vipId, goods.getId(), shopId, 1, provinceCode, cityCode, districtCode); if(null != price){ goodsVO.setPointPayment(price.getPointPayment() ? 1 : 0); goodsVO.setCashPayment(price.getCashPayment() ? 1 : 0); @@ -260,8 +272,9 @@ } Integer integer = orderClient.getGoodsSaleNum(goods.getId(), 1).getData(); goodsVO.setSaleNum(integer); - GoodsEvaluate goodsEvaluate = goodsEvaluateService.lambdaQuery().eq(GoodsEvaluate::getGoodsId, goodsId) - .orderByDesc(GoodsEvaluate::getGrade).eq(GoodsEvaluate::getStatus, 2).eq(GoodsEvaluate::getDelFlag, 0).last(" limit 0, 1").one(); + GoodsEvaluate goodsEvaluate = goodsEvaluateService.lambdaQuery().eq(GoodsEvaluate::getGoodsId, goodsId).ne(GoodsEvaluate::getComment, "") + .orderByDesc(GoodsEvaluate::getGrade).eq(GoodsEvaluate::getStatus, 2).isNotNull(GoodsEvaluate::getComment) + .eq(GoodsEvaluate::getDelFlag, 0).last(" limit 0, 1").one(); if (null != goodsEvaluate) { AppUser appUserById = appUserClient.getAppUserById(goodsEvaluate.getAppUserId()); if(null != appUserById){ @@ -307,7 +320,12 @@ @Override public IPage<Goods> getManageGoodsList(Page<Goods> page, Goods goods) { - return goodsMapper.selectManageGoodsList(page, 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; } @Override @@ -388,9 +406,10 @@ area.setProvinceCode(goodsArea.getProvinceCode()); area.setCityCode(goodsArea.getCityCode()); area.setDistrictsCode(goodsArea.getDistrictsCode()); - if(null != area.getSellingPrice() && null != area.getIntegral()){ - goodsAreaList2.add(area); - } +// if(null != area.getSellingPrice() || null != area.getIntegral()){ +// goodsAreaList2.add(area); +// } + goodsAreaList2.add(area); } goodsAreaService.saveBatch(goodsAreaList2); } @@ -566,15 +585,15 @@ if(null == bargainPriceDetail){ //没有门店特价,判断地区价格配置 LambdaQueryWrapper<GoodsArea> queryWrapper = new LambdaQueryWrapper<GoodsArea>().eq(GoodsArea::getGoodsId, goodsId).eq(GoodsArea::getVip, vip); - if(StringUtils.isNotEmpty(districtCode)){ - queryWrapper.eq(GoodsArea::getDistrictsCode, districtCode); - } - if(StringUtils.isNotEmpty(cityCode)){ - queryWrapper.eq(GoodsArea::getCityCode, cityCode); - } if(StringUtils.isNotEmpty(provinceCode)){ queryWrapper.eq(GoodsArea::getProvinceCode, provinceCode); } + if(StringUtils.isNotEmpty(cityCode)){ + queryWrapper.and(i -> i.eq(GoodsArea::getCityCode, cityCode).or().isNull(GoodsArea::getCityCode)); + } + if(StringUtils.isNotEmpty(districtCode)){ + queryWrapper.and(i -> i.eq(GoodsArea::getDistrictsCode, districtCode).or().isNull(GoodsArea::getDistrictsCode)); + } GoodsArea goodsArea = goodsAreaService.getOne(queryWrapper); if(null == goodsArea){ //没有地区价格,则使用会员价格 -- Gitblit v1.7.1