diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java index 08b5bea5..e7419538 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java @@ -504,7 +504,16 @@ public class GoodsController extends BaseController { queryGoods.setDeptGoodsCategoryId(serviceCategoryId); queryGoods.setStatus(0); // 只查询上架的商品 List goodsList = goodsService.selectGoodsList(queryGoods); - + if (goodsList.size()==0){ + DeptGoodsCategory deptGoodsCategory1=deptGoodsCategoryService.selectOneByGoodsCategoryId(serviceCategoryId); + serviceCategoryId=deptGoodsCategory1.getDeptGoodsCategoryId(); + // 直接使用新方法获取商品列表 + goodsList = goodsStandardService.selectGoodsByDeptGoodsCategoryId(serviceCategoryId); + // 过滤只保留上架的商品 + goodsList = goodsList.stream() + .filter(goods -> goods.getStatus() != null && goods.getStatus() == 0) + .collect(Collectors.toList()); + } // 3. 提取所有店铺ID(去重) Set shopIds = goodsList.stream() .filter(g -> g.getShopId() != null) @@ -739,18 +748,13 @@ public class GoodsController extends BaseController { // 通过商品的服务类目获取服务店铺 if (goods.getDeptGoodsCategoryId() != null) { try { - // 1. 通过商品的类目ID获取类目信息 - DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.selectOneByGoodsCategoryId(goods.getDeptGoodsCategoryId()); - if (deptGoodsCategory != null && deptGoodsCategory.getServiceCategoryId() != null) { - logger.debug("商品的服务类目ID: {}", deptGoodsCategory.getServiceCategoryId()); + // 使用新的方法通过商品ID直接获取服务类目下的所有商品 + List goodsList = goodsService.selectGoodsByServiceCategory(goodsId); + + if (!goodsList.isEmpty()) { + logger.debug("通过商品ID[{}]找到{}个相关服务商品", goodsId, goodsList.size()); - // 2. 通过服务类目ID查询所有使用该服务类目的商品 - Goods queryGoods = new Goods(); - queryGoods.setDeptGoodsCategoryId(deptGoodsCategory.getServiceCategoryId()); - queryGoods.setStatus(0); // 只查询上架的商品 - List goodsList = goodsService.selectGoodsList(queryGoods); - - // 3. 提取所有店铺ID(去重) + // 提取所有店铺ID(去重) Set shopIds = goodsList.stream() .filter(g -> g.getShopId() != null) .map(Goods::getShopId) @@ -803,7 +807,7 @@ public class GoodsController extends BaseController { }); } } else { - logger.debug("商品类目信息中未配置服务类目ID"); + logger.debug("未找到商品ID[{}]的相关服务商品", goodsId); } } catch (Exception e) { logger.warn("获取服务店铺信息失败: {}", e.getMessage()); diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsStandardController.java b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsStandardController.java index 363a2a0b..b06d5e0c 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsStandardController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsStandardController.java @@ -3,6 +3,7 @@ package com.ghy.web.controller.goods; import com.ghy.common.core.controller.BaseController; import com.ghy.common.core.domain.AjaxResult; import com.ghy.common.core.page.TableDataInfo; +import com.ghy.goods.domain.Goods; import com.ghy.goods.domain.GoodsStandard; import com.ghy.goods.service.GoodsStandardService; import com.ghy.order.domain.OrderTemplate; @@ -64,4 +65,14 @@ public class GoodsStandardController extends BaseController { return toAjax(goodsStandardService.save(goodsStandardList)); } + /** + * 根据部门商品分类ID获取商品列表 + */ + @ResponseBody + @GetMapping("/goods/by-dept-category/{deptGoodsCategoryId}") + public AjaxResult getGoodsByDeptCategoryId(@PathVariable("deptGoodsCategoryId") Long deptGoodsCategoryId) { + List goodsList = goodsStandardService.selectGoodsByDeptGoodsCategoryId(deptGoodsCategoryId); + return AjaxResult.success(goodsList); + } + } diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java index 0218d458..521e014f 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java @@ -631,6 +631,7 @@ public class OrderController extends BaseController { Assert.notNull(deptId, "deptId is null!"); // 生成主单 + orderMaster.setOrderImages(appOrderRequest.getOrderImages()); orderMaster.setServiceShopId(appOrderRequest.getServiceShopId()); orderMaster.setDeptId(deptId); orderMaster.setIsNeedBill(appOrderRequest.getIsNeedBill()); diff --git a/ghy-goods/src/main/java/com/ghy/goods/mapper/GoodsStandardMapper.java b/ghy-goods/src/main/java/com/ghy/goods/mapper/GoodsStandardMapper.java index cd33ddfe..cac6ce45 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/mapper/GoodsStandardMapper.java +++ b/ghy-goods/src/main/java/com/ghy/goods/mapper/GoodsStandardMapper.java @@ -71,4 +71,11 @@ public interface GoodsStandardMapper { */ List selectByStandardNameLike(@Param("standardName") String standardName); + /** + * 根据部门商品分类ID查询商品规格 + * @param deptGoodsCategoryId 部门商品分类ID + * @return 符合条件的商品规格列表 + */ + List selectByDeptGoodsCategoryId(@Param("deptGoodsCategoryId") Long deptGoodsCategoryId); + } diff --git a/ghy-goods/src/main/java/com/ghy/goods/service/GoodsService.java b/ghy-goods/src/main/java/com/ghy/goods/service/GoodsService.java index f5ac37a1..f91a9b5e 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/service/GoodsService.java +++ b/ghy-goods/src/main/java/com/ghy/goods/service/GoodsService.java @@ -95,4 +95,12 @@ public interface GoodsService { int edit(Goods goods); + /** + * 通过商品ID查找其服务类目,然后通过服务类目的四级类目查询所有相关商品 + * + * @param goodsId 商品ID + * @return 相关商品列表(只包含上架商品) + */ + List selectGoodsByServiceCategory(Long goodsId); + } diff --git a/ghy-goods/src/main/java/com/ghy/goods/service/GoodsStandardService.java b/ghy-goods/src/main/java/com/ghy/goods/service/GoodsStandardService.java index bf97a3da..84a96078 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/service/GoodsStandardService.java +++ b/ghy-goods/src/main/java/com/ghy/goods/service/GoodsStandardService.java @@ -66,4 +66,11 @@ public interface GoodsStandardService { */ List selectByStandardNameLike(String standardName); + /** + * 根据部门商品分类ID获取所有商品 + * @param deptGoodsCategoryId 部门商品分类ID + * @return 商品列表 + */ + List selectGoodsByDeptGoodsCategoryId(Long deptGoodsCategoryId); + } diff --git a/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsServiceImpl.java b/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsServiceImpl.java index 09f221a3..020b73f6 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsServiceImpl.java +++ b/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsServiceImpl.java @@ -12,8 +12,12 @@ import com.ghy.goods.service.GoodsAreaService; import com.ghy.goods.service.GoodsImgsService; import com.ghy.goods.service.GoodsService; import com.ghy.goods.service.GoodsStandardService; +import com.ghy.goods.service.DeptGoodsCategoryService; +import com.ghy.goods.domain.DeptGoodsCategory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.stream.Collectors; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -40,6 +44,8 @@ public class GoodsServiceImpl implements GoodsService { private GoodsImgsService goodsImgsService; @Resource private GoodsStandardService goodsStandardService; + @Resource + private DeptGoodsCategoryService deptGoodsCategoryService; @Override @Transactional @@ -210,4 +216,40 @@ public class GoodsServiceImpl implements GoodsService { return 0; } + @Override + public List selectGoodsByServiceCategory(Long goodsId) { + // Get goods info by goodsId + Goods goods = selectById(goodsId); + if (goods == null || goods.getDeptGoodsCategoryId() == null) { + return new ArrayList<>(); + } + + // Get DeptGoodsCategory by deptGoodsCategoryId to obtain serviceCategory + DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.selectOneByGoodsCategoryId(goods.getDeptGoodsCategoryId()); + if (deptGoodsCategory == null || deptGoodsCategory.getServiceCategoryId() == null) { + return new ArrayList<>(); + } + + // Query all goods using this service category ID + Goods queryGoods = new Goods(); + queryGoods.setDeptGoodsCategoryId(deptGoodsCategory.getServiceCategoryId()); + queryGoods.setStatus(0); // Only query active goods + List goodsList = selectGoodsList(queryGoods); + + // If no goods found, try using fourth-level category query + if (goodsList.isEmpty()) { + DeptGoodsCategory serviceDeptCategory = deptGoodsCategoryService.selectOneByGoodsCategoryId(deptGoodsCategory.getServiceCategoryId()); + if (serviceDeptCategory != null) { + // Use GoodsStandardService method to get goods list + goodsList = goodsStandardService.selectGoodsByDeptGoodsCategoryId(serviceDeptCategory.getDeptGoodsCategoryId()); + // Filter to keep only active goods + goodsList = goodsList.stream() + .filter(item -> item.getStatus() != null && item.getStatus() == 0) + .collect(Collectors.toList()); + } + } + + return goodsList; + } + } diff --git a/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsStandardServiceImpl.java b/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsStandardServiceImpl.java index 5dd29051..282b9d1c 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsStandardServiceImpl.java +++ b/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsStandardServiceImpl.java @@ -1,8 +1,10 @@ package com.ghy.goods.service.impl; +import com.ghy.goods.domain.Goods; import com.ghy.goods.domain.GoodsStandard; import com.ghy.goods.mapper.GoodsStandardMapper; import com.ghy.goods.request.AppGoodsRequest; +import com.ghy.goods.service.GoodsService; import com.ghy.goods.service.GoodsStandardService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -26,6 +28,9 @@ public class GoodsStandardServiceImpl implements GoodsStandardService { @Resource private GoodsStandardMapper goodsStandardMapper; + + @Resource + private GoodsService goodsService; @Override public GoodsStandard selectById(Long goodsStandardId) { @@ -91,4 +96,19 @@ public class GoodsStandardServiceImpl implements GoodsStandardService { public List selectByStandardNameLike(String standardName) { return goodsStandardMapper.selectByStandardNameLike(standardName); } + + @Override + public List selectGoodsByDeptGoodsCategoryId(Long deptGoodsCategoryId) { + // 1. 根据deptGoodsCategoryId查询所有商品规格 + List goodsStandardList = goodsStandardMapper.selectByDeptGoodsCategoryId(deptGoodsCategoryId); + + // 2. 提取所有不重复的goodsId + Set goodsIds = goodsStandardList.stream() + .map(GoodsStandard::getGoodsId) + .collect(Collectors.toSet()); + + + // 4. 通过goodsId批量查询Goods实体 + return goodsService.selectByIds(goodsIds); + } } diff --git a/ghy-goods/src/main/resources/mapper/goods/GoodsStandardMapper.xml b/ghy-goods/src/main/resources/mapper/goods/GoodsStandardMapper.xml index ecc0fbed..872df07d 100644 --- a/ghy-goods/src/main/resources/mapper/goods/GoodsStandardMapper.xml +++ b/ghy-goods/src/main/resources/mapper/goods/GoodsStandardMapper.xml @@ -176,4 +176,14 @@ + + + diff --git a/ghy-order/src/main/java/com/ghy/order/request/AppOrderRequest.java b/ghy-order/src/main/java/com/ghy/order/request/AppOrderRequest.java index d1a5bab4..5ec658b8 100644 --- a/ghy-order/src/main/java/com/ghy/order/request/AppOrderRequest.java +++ b/ghy-order/src/main/java/com/ghy/order/request/AppOrderRequest.java @@ -47,4 +47,6 @@ public class AppOrderRequest { private Long insuranceId; private Long serviceShopId; + + private String orderImages; }