From cc134fa83edea4865b48d7afc1acda5ad70e7465 Mon Sep 17 00:00:00 2001
From: luodangjia <luodangjia>
Date: 星期一, 13 一月 2025 11:20:05 +0800
Subject: [PATCH] 12.18

---
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java |  113 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 106 insertions(+), 7 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 05f7de5..9c2c7b0 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,5 +1,6 @@
 package com.ruoyi.other.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -28,6 +29,7 @@
 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.GoodsVO;
 import com.ruoyi.system.api.model.LoginUser;
 import org.jetbrains.annotations.NotNull;
@@ -90,7 +92,6 @@
 
     @Override
     public PageInfo<GoodsVO> goodsList(Goods search) {
-        PageInfo<GoodsVO> pageInfo = new PageInfo(search.getPageCurr(), search.getPageSize());
         Integer vipId = 0;
         String provinceCode = null;
         String cityCode = null;
@@ -104,7 +105,7 @@
             cityCode = appUser.getCityCode();
             districtCode = appUser.getDistrictCode();
         }
-        List<GoodsVO> list = this.baseMapper.goodsList(pageInfo, search.getGoodsCategoryId(), search.getName(), vipId);
+        List<GoodsVO> list = this.baseMapper.goodsList(search.getGoodsCategoryId(), search.getName(), vipId);
         for (GoodsVO goods : list) {
             Price price = getPrice(vipId, goods.getGoodsId(), null, 1, provinceCode, cityCode, districtCode);
             if(null != price){
@@ -113,12 +114,74 @@
                 goods.setSellingPrice(price.getCash());
                 goods.setIntegral(price.getPoint());
             }
+            Integer data = orderClient.getGoodsSaleNum(goods.getGoodsId(), 1).getData();
+            goods.setSaleNum(data);
+        }
+
+        //手动排序
+        if(StringUtils.isNotEmpty(search.getOrderByColumn())){
+            if("selling_price".equals(search.getOrderByColumn())){
+                list.sort(new Comparator<GoodsVO>() {
+                    @Override
+                    public int compare(GoodsVO o1, GoodsVO o2) {
+                        if(null != o1.getSellingPrice() && null != o2.getSellingPrice()){
+                            return o1.getSellingPrice().compareTo(o2.getSellingPrice()) * (StringUtils.isNotEmpty(search.getIsAsc()) ? -1 : 1);
+                        }
+                        if(null == o1.getSellingPrice() && null != o2.getSellingPrice()){
+                            return BigDecimal.ZERO.compareTo(o2.getSellingPrice()) * (StringUtils.isNotEmpty(search.getIsAsc()) ? -1 : 1);
+                        }
+                        if(null != o1.getSellingPrice() && null == o2.getSellingPrice()){
+                            return o1.getSellingPrice().compareTo(BigDecimal.ZERO) * (StringUtils.isNotEmpty(search.getIsAsc()) ? -1 : 1);
+                        }
+                        return 0;
+                    }
+                });
+            }
+            if("integral".equals(search.getOrderByColumn())){
+                list.sort(new Comparator<GoodsVO>() {
+                    @Override
+                    public int compare(GoodsVO o1, GoodsVO o2) {
+                        if(null != o1.getIntegral() && null != o2.getIntegral()){
+                            return o1.getIntegral().compareTo(o2.getIntegral()) * (StringUtils.isNotEmpty(search.getIsAsc()) ? -1 : 1);
+                        }
+                        if(null == o1.getIntegral() && null != o2.getIntegral()){
+                            return Integer.valueOf(0).compareTo(o2.getIntegral()) * (StringUtils.isNotEmpty(search.getIsAsc()) ? -1 : 1);
+                        }
+                        if(null != o1.getIntegral() && null == o2.getIntegral()){
+                            return o1.getIntegral().compareTo(Integer.valueOf(0)) * (StringUtils.isNotEmpty(search.getIsAsc()) ? -1 : 1);
+                        }
+                        return 0;
+                    }
+                });
+            }
+            if("sale_num".equals(search.getOrderByColumn())){
+                list.sort(new Comparator<GoodsVO>() {
+                    @Override
+                    public int compare(GoodsVO o1, GoodsVO o2) {
+                        return o1.getSaleNum().compareTo(o2.getSaleNum()) * (StringUtils.isNotEmpty(search.getIsAsc()) ? -1 : 1);
+                    }
+                });
+            }
+        }
+        //手动处理分页
+        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<>();
         }
         return pageInfo.setRecords(list);
     }
 
     @Override
-    public GoodsVO goodsDetail(Long goodsId) {
+    public GoodsVO goodsDetail(Long goodsId, String longitude, String latitude) {
         if (goodsId == null || goodsId <= 0) {
             throw new NullPointerException("商品ID不能为空");
         }
@@ -138,11 +201,20 @@
         }
 
         Goods goods = this.getById(goodsId);
+        if(null == goods || goods.getDelFlag() == 1){
+            throw new RuntimeException("商品不存在");
+        }
+        if(goods.getStatus() == 1){
+            throw new RuntimeException("商品已被下架");
+        }
+        if(!goods.getCommodityAuthority().contains("-1") && !goods.getCommodityAuthority().contains(vipId.toString())){
+            throw new RuntimeException("权限不足");
+        }
         GoodsVO goodsVO = new GoodsVO();
         BeanUtils.copyBeanProp(goodsVO, goods);
         goodsVO.setGoodsId(goods.getId());
         goodsVO.setGoodsName(goods.getName());
-        Price price = getPrice(vipId, goods.getId(), 1, null, provinceCode, cityCode, districtCode);
+        Price price = getPrice(vipId, goods.getId(), null, 1, provinceCode, cityCode, districtCode);
         if(null != price){
             goodsVO.setPointPayment(price.getPointPayment() ? 1 : 0);
             goodsVO.setCashPayment(price.getCashPayment() ? 1 : 0);
@@ -168,6 +240,20 @@
         }else{
             List<Shop> shopList = shopMapper.selectList(new LambdaQueryWrapper<Shop>()
                     .in(Shop::getDelFlag, 0));
+            goodsVO.setShopList(shopList);
+        }
+        if(StringUtils.isNotEmpty(longitude) && StringUtils.isNotEmpty(latitude)){
+            List<Shop> shopList = goodsVO.getShopList();
+            for (Shop shop : shopList) {
+                Double wgs84 = GeodesyUtil.getDistance(longitude + "," + latitude, shop.getLongitude() + "," + shop.getLatitude()).get("WGS84");
+                shop.setDistance(wgs84);
+            }
+            shopList.sort(new Comparator<Shop>() {
+                @Override
+                public int compare(Shop o1, Shop o2) {
+                    return o1.getDistance().compareTo(o2.getDistance());
+                }
+            });
             goodsVO.setShopList(shopList);
         }
         Integer integer = orderClient.getGoodsSaleNum(goods.getId(), 1).getData();
@@ -200,6 +286,8 @@
                 good.setSellingPrice(price.getCash());
                 good.setIntegral(price.getPoint());
             }
+            Integer data = orderClient.getGoodsSaleNum(good.getId(), 1).getData();
+            good.setSaleNum(data);
         }
         return goods;
     }
@@ -246,7 +334,10 @@
 
     @Override
     public void updateManageGoods(Goods goods) {
-        goodsMapper.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());
@@ -264,12 +355,17 @@
         saveGoodsAreaList(goodsAreaList, goods.getId());
     }
 
+
+
+
+
     private void saveGoodsAreaList(List<GoodsArea> goodsAreaList, Integer id) {
         goodsAreaService.remove(new LambdaQueryWrapper<GoodsArea>()
                 .eq(GoodsArea::getGoodsId, id));
         if (!CollectionUtils.isEmpty(goodsAreaList)){
             for (GoodsArea goodsArea : goodsAreaList) {
                 List<GoodsArea> goodsAreaList1 = goodsArea.getGoodsAreaList();
+                List<GoodsArea> goodsAreaList2 = new ArrayList<>();
                 for (GoodsArea area : goodsAreaList1) {
                     area.setId(null);
                     area.setGoodsId(id);
@@ -279,8 +375,11 @@
                     area.setProvinceCode(goodsArea.getProvinceCode());
                     area.setCityCode(goodsArea.getCityCode());
                     area.setDistrictsCode(goodsArea.getDistrictsCode());
+                    if(null != area.getSellingPrice() && null != area.getIntegral()){
+                        goodsAreaList2.add(area);
+                    }
                 }
-                goodsAreaService.saveBatch(goodsAreaList1);
+                goodsAreaService.saveBatch(goodsAreaList2);
             }
         }
     }
@@ -300,7 +399,7 @@
                 .eq(GoodsAppUser::getGoodsId, id));
         if (!CollectionUtils.isEmpty(goodsAppUserList)){
             for (GoodsAppUser goodsAppUser : goodsAppUserList) {
-                goodsAppUser.setId(null );
+                goodsAppUser.setId(null);
                 goodsAppUser.setGoodsId(id);
             }
         }

--
Gitblit v1.7.1