no message

This commit is contained in:
cb 2025-09-10 16:49:28 +08:00
parent 1a8283e441
commit 75ffa0f6ee
10 changed files with 125 additions and 13 deletions

View File

@ -504,7 +504,16 @@ public class GoodsController extends BaseController {
queryGoods.setDeptGoodsCategoryId(serviceCategoryId); queryGoods.setDeptGoodsCategoryId(serviceCategoryId);
queryGoods.setStatus(0); // 只查询上架的商品 queryGoods.setStatus(0); // 只查询上架的商品
List<Goods> goodsList = goodsService.selectGoodsList(queryGoods); List<Goods> 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去重 // 3. 提取所有店铺ID去重
Set<Long> shopIds = goodsList.stream() Set<Long> shopIds = goodsList.stream()
.filter(g -> g.getShopId() != null) .filter(g -> g.getShopId() != null)
@ -739,18 +748,13 @@ public class GoodsController extends BaseController {
// 通过商品的服务类目获取服务店铺 // 通过商品的服务类目获取服务店铺
if (goods.getDeptGoodsCategoryId() != null) { if (goods.getDeptGoodsCategoryId() != null) {
try { try {
// 1. 通过商品的类目ID获取类目信息 // 使用新的方法通过商品ID直接获取服务类目下的所有商品
DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.selectOneByGoodsCategoryId(goods.getDeptGoodsCategoryId()); List<Goods> goodsList = goodsService.selectGoodsByServiceCategory(goodsId);
if (deptGoodsCategory != null && deptGoodsCategory.getServiceCategoryId() != null) {
logger.debug("商品的服务类目ID: {}", deptGoodsCategory.getServiceCategoryId()); if (!goodsList.isEmpty()) {
logger.debug("通过商品ID[{}]找到{}个相关服务商品", goodsId, goodsList.size());
// 2. 通过服务类目ID查询所有使用该服务类目的商品 // 提取所有店铺ID去重
Goods queryGoods = new Goods();
queryGoods.setDeptGoodsCategoryId(deptGoodsCategory.getServiceCategoryId());
queryGoods.setStatus(0); // 只查询上架的商品
List<Goods> goodsList = goodsService.selectGoodsList(queryGoods);
// 3. 提取所有店铺ID去重
Set<Long> shopIds = goodsList.stream() Set<Long> shopIds = goodsList.stream()
.filter(g -> g.getShopId() != null) .filter(g -> g.getShopId() != null)
.map(Goods::getShopId) .map(Goods::getShopId)
@ -803,7 +807,7 @@ public class GoodsController extends BaseController {
}); });
} }
} else { } else {
logger.debug("商品类目信息中未配置服务类目ID"); logger.debug("未找到商品ID[{}]的相关服务商品", goodsId);
} }
} catch (Exception e) { } catch (Exception e) {
logger.warn("获取服务店铺信息失败: {}", e.getMessage()); logger.warn("获取服务店铺信息失败: {}", e.getMessage());

View File

@ -3,6 +3,7 @@ package com.ghy.web.controller.goods;
import com.ghy.common.core.controller.BaseController; import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult; import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.core.page.TableDataInfo; import com.ghy.common.core.page.TableDataInfo;
import com.ghy.goods.domain.Goods;
import com.ghy.goods.domain.GoodsStandard; import com.ghy.goods.domain.GoodsStandard;
import com.ghy.goods.service.GoodsStandardService; import com.ghy.goods.service.GoodsStandardService;
import com.ghy.order.domain.OrderTemplate; import com.ghy.order.domain.OrderTemplate;
@ -64,4 +65,14 @@ public class GoodsStandardController extends BaseController {
return toAjax(goodsStandardService.save(goodsStandardList)); return toAjax(goodsStandardService.save(goodsStandardList));
} }
/**
* 根据部门商品分类ID获取商品列表
*/
@ResponseBody
@GetMapping("/goods/by-dept-category/{deptGoodsCategoryId}")
public AjaxResult getGoodsByDeptCategoryId(@PathVariable("deptGoodsCategoryId") Long deptGoodsCategoryId) {
List<Goods> goodsList = goodsStandardService.selectGoodsByDeptGoodsCategoryId(deptGoodsCategoryId);
return AjaxResult.success(goodsList);
}
} }

View File

@ -631,6 +631,7 @@ public class OrderController extends BaseController {
Assert.notNull(deptId, "deptId is null!"); Assert.notNull(deptId, "deptId is null!");
// 生成主单 // 生成主单
orderMaster.setOrderImages(appOrderRequest.getOrderImages());
orderMaster.setServiceShopId(appOrderRequest.getServiceShopId()); orderMaster.setServiceShopId(appOrderRequest.getServiceShopId());
orderMaster.setDeptId(deptId); orderMaster.setDeptId(deptId);
orderMaster.setIsNeedBill(appOrderRequest.getIsNeedBill()); orderMaster.setIsNeedBill(appOrderRequest.getIsNeedBill());

View File

@ -71,4 +71,11 @@ public interface GoodsStandardMapper {
*/ */
List<GoodsStandard> selectByStandardNameLike(@Param("standardName") String standardName); List<GoodsStandard> selectByStandardNameLike(@Param("standardName") String standardName);
/**
* 根据部门商品分类ID查询商品规格
* @param deptGoodsCategoryId 部门商品分类ID
* @return 符合条件的商品规格列表
*/
List<GoodsStandard> selectByDeptGoodsCategoryId(@Param("deptGoodsCategoryId") Long deptGoodsCategoryId);
} }

View File

@ -95,4 +95,12 @@ public interface GoodsService {
int edit(Goods goods); int edit(Goods goods);
/**
* 通过商品ID查找其服务类目然后通过服务类目的四级类目查询所有相关商品
*
* @param goodsId 商品ID
* @return 相关商品列表只包含上架商品
*/
List<Goods> selectGoodsByServiceCategory(Long goodsId);
} }

View File

@ -66,4 +66,11 @@ public interface GoodsStandardService {
*/ */
List<GoodsStandard> selectByStandardNameLike(String standardName); List<GoodsStandard> selectByStandardNameLike(String standardName);
/**
* 根据部门商品分类ID获取所有商品
* @param deptGoodsCategoryId 部门商品分类ID
* @return 商品列表
*/
List<Goods> selectGoodsByDeptGoodsCategoryId(Long deptGoodsCategoryId);
} }

View File

@ -12,8 +12,12 @@ import com.ghy.goods.service.GoodsAreaService;
import com.ghy.goods.service.GoodsImgsService; import com.ghy.goods.service.GoodsImgsService;
import com.ghy.goods.service.GoodsService; import com.ghy.goods.service.GoodsService;
import com.ghy.goods.service.GoodsStandardService; 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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.stream.Collectors;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -40,6 +44,8 @@ public class GoodsServiceImpl implements GoodsService {
private GoodsImgsService goodsImgsService; private GoodsImgsService goodsImgsService;
@Resource @Resource
private GoodsStandardService goodsStandardService; private GoodsStandardService goodsStandardService;
@Resource
private DeptGoodsCategoryService deptGoodsCategoryService;
@Override @Override
@Transactional @Transactional
@ -210,4 +216,40 @@ public class GoodsServiceImpl implements GoodsService {
return 0; return 0;
} }
@Override
public List<Goods> 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<Goods> 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;
}
} }

View File

@ -1,8 +1,10 @@
package com.ghy.goods.service.impl; package com.ghy.goods.service.impl;
import com.ghy.goods.domain.Goods;
import com.ghy.goods.domain.GoodsStandard; import com.ghy.goods.domain.GoodsStandard;
import com.ghy.goods.mapper.GoodsStandardMapper; import com.ghy.goods.mapper.GoodsStandardMapper;
import com.ghy.goods.request.AppGoodsRequest; import com.ghy.goods.request.AppGoodsRequest;
import com.ghy.goods.service.GoodsService;
import com.ghy.goods.service.GoodsStandardService; import com.ghy.goods.service.GoodsStandardService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -26,6 +28,9 @@ public class GoodsStandardServiceImpl implements GoodsStandardService {
@Resource @Resource
private GoodsStandardMapper goodsStandardMapper; private GoodsStandardMapper goodsStandardMapper;
@Resource
private GoodsService goodsService;
@Override @Override
public GoodsStandard selectById(Long goodsStandardId) { public GoodsStandard selectById(Long goodsStandardId) {
@ -91,4 +96,19 @@ public class GoodsStandardServiceImpl implements GoodsStandardService {
public List<GoodsStandard> selectByStandardNameLike(String standardName) { public List<GoodsStandard> selectByStandardNameLike(String standardName) {
return goodsStandardMapper.selectByStandardNameLike(standardName); return goodsStandardMapper.selectByStandardNameLike(standardName);
} }
@Override
public List<Goods> selectGoodsByDeptGoodsCategoryId(Long deptGoodsCategoryId) {
// 1. 根据deptGoodsCategoryId查询所有商品规格
List<GoodsStandard> goodsStandardList = goodsStandardMapper.selectByDeptGoodsCategoryId(deptGoodsCategoryId);
// 2. 提取所有不重复的goodsId
Set<Long> goodsIds = goodsStandardList.stream()
.map(GoodsStandard::getGoodsId)
.collect(Collectors.toSet());
// 4. 通过goodsId批量查询Goods实体
return goodsService.selectByIds(goodsIds);
}
} }

View File

@ -176,4 +176,14 @@
</if> </if>
</where> </where>
</select> </select>
<!-- 根据部门商品分类ID查询商品规格 -->
<select id="selectByDeptGoodsCategoryId" resultMap="GoodsStandardResult">
<include refid="selectGoodsStandard"/>
<where>
<if test="deptGoodsCategoryId != null">
AND dept_goods_category_id = #{deptGoodsCategoryId}
</if>
</where>
</select>
</mapper> </mapper>

View File

@ -47,4 +47,6 @@ public class AppOrderRequest {
private Long insuranceId; private Long insuranceId;
private Long serviceShopId; private Long serviceShopId;
private String orderImages;
} }