Просмотр исходного кода

组合商品分类查询支持多级查询

yuanliang 1 год назад
Родитель
Сommit
d2bc3c7382

+ 1 - 14
mec-application/src/main/java/com/ym/mec/teacher/controller/GoodsController.java

@@ -1,9 +1,5 @@
 package com.ym.mec.teacher.controller;
 
-import com.ym.mec.biz.dal.entity.Goods;
-import com.ym.mec.biz.dal.entity.GoodsCategory;
-import com.ym.mec.biz.dal.wrapper.GoodsWrapper;
-import com.ym.mec.biz.service.GoodsCategoryService;
 import com.ym.mec.biz.service.GoodsService;
 import com.ym.mec.common.controller.BaseController;
 import io.swagger.annotations.Api;
@@ -15,8 +11,6 @@ import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.Objects;
-
 @RequestMapping("${app-config.url.teacher:}/goods")
 @Api(tags = "商品(教材、辅件)服务")
 @RestController
@@ -24,18 +18,11 @@ public class GoodsController extends BaseController {
 
     @Autowired
     private GoodsService goodsService;
-    @Autowired
-    private GoodsCategoryService goodsCategoryService;
 
     @ApiOperation(value = "根据商品(教材、辅件)编号查询商品(教材、辅件)")
     @GetMapping("/get/{id}")
     public Object get(@ApiParam(value = "商品(教材、辅件)编号", required = true) @PathVariable("id") Integer id) {
-        GoodsWrapper.Goods goods = goodsService.getDetail(id);
-        GoodsCategory goodsCategory = goodsCategoryService.get(goods.getGoodsCategoryId());
-        if (Objects.nonNull(goodsCategory)) {
-            goods.setGoodsCategoryName(goodsCategory.getName());
-        }
-        return succeed(goods);
+        return succeed(goodsService.getDetail(id));
     }
 
 }

+ 1 - 17
mec-application/src/main/java/com/ym/mec/web/controller/GoodsController.java

@@ -3,19 +3,14 @@ package com.ym.mec.web.controller;
 import com.ym.mec.biz.dal.dao.EmployeeDao;
 import com.ym.mec.biz.dal.entity.Employee;
 import com.ym.mec.biz.dal.entity.Goods;
-import com.ym.mec.biz.dal.entity.GoodsCategory;
 import com.ym.mec.biz.dal.entity.GoodsProcurement;
 import com.ym.mec.biz.dal.enums.YesOrNoEnum;
 import com.ym.mec.biz.dal.page.GoodsQuery;
 import com.ym.mec.biz.dal.page.GoodsQueryInfo;
 import com.ym.mec.biz.dal.wrapper.GoodsWrapper;
-import com.ym.mec.biz.service.GoodsCategoryService;
 import com.ym.mec.biz.service.GoodsService;
 import com.ym.mec.biz.service.SysUserService;
 import com.ym.mec.common.controller.BaseController;
-import com.ym.mec.common.dto.BrandDto;
-import com.ym.mec.common.dto.ProductCategoryDto;
-import com.ym.mec.common.page.PageInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -30,10 +25,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.stream.Collectors;
 
 @RequestMapping("${app-config.url.web:}/goods")
 @Api(tags = "商品(教材、辅件)服务")
@@ -43,8 +34,6 @@ public class GoodsController extends BaseController {
     @Autowired
     private GoodsService goodsService;
     @Autowired
-    private GoodsCategoryService goodsCategoryService;
-    @Autowired
     private SysUserService sysUserService;
     @Autowired
     private EmployeeDao employeeDao;
@@ -100,12 +89,7 @@ public class GoodsController extends BaseController {
     @ApiOperation(value = "根据商品(教材、辅件)编号查询商品(教材、辅件)")
     @GetMapping("/get/{id}")
     public Object get(@ApiParam(value = "商品(教材、辅件)编号", required = true) @PathVariable("id") Integer id){
-        GoodsWrapper.Goods goods = goodsService.getDetail(id);
-        GoodsCategory goodsCategory = goodsCategoryService.get(goods.getGoodsCategoryId());
-        if(Objects.nonNull(goodsCategory)){
-            goods.setGoodsCategoryName(goodsCategory.getName());
-        }
-        return succeed(goods);
+        return succeed(goodsService.getDetail(id));
     }
 
     @ApiOperation(value = "分页查询商品(教材、辅件)列表")

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/page/GoodsQueryInfo.java

@@ -57,6 +57,8 @@ public class GoodsQueryInfo extends QueryInfo {
 
     private Integer subjectId;
 
+    private String goodsCategoryIds;
+
     public Integer getNoOrganSearch() {
         return noOrganSearch;
     }
@@ -184,4 +186,12 @@ public class GoodsQueryInfo extends QueryInfo {
     public void setBrandId(String brandId) {
         this.brandId = brandId;
     }
+
+    public String getGoodsCategoryIds() {
+        return goodsCategoryIds;
+    }
+
+    public void setGoodsCategoryIds(String goodsCategoryIds) {
+        this.goodsCategoryIds = goodsCategoryIds;
+    }
 }

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java

@@ -69,6 +69,8 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      */
     List<Goods> findTypeGoods(String type, Integer tenantId);
 
+    PageInfo<Goods> queryPage(GoodsQueryInfo queryInfo);
+
     /**
      * @describe 商品导入
      * @apiNote 时光荏苒,认真工作的时间总是过得很快,而我、享受这一刻!

+ 16 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -47,7 +47,6 @@ import com.ym.mec.common.entity.GoodsSubStockModel;
 import com.ym.mec.common.entity.UploadReturnBean;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
-import com.ym.mec.common.page.QueryInfo;
 import com.ym.mec.common.service.IdGeneratorService;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.common.tenant.TenantContextHolder;
@@ -129,9 +128,13 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 		if (CollectionUtils.isEmpty(rows)) {
 			throw new BizException("没有查询到商品信息");
 		}
+		List<ProductCategoryDto> productCategoryDtos = treeToList(queryGoodsCategoryList());
+		Map<Long, String> IdNamemap = productCategoryDtos.stream().collect(Collectors.toMap(ProductCategoryDto::getId, ProductCategoryDto::getName));
+
 		List<Organization> all = organizationDao.findAll(params);
 		Map<Integer, String> organizationMap = all.stream().collect(Collectors.toMap(Organization::getId, Organization::getName));
 		for (Goods goods : rows) {
+			goods.setGoodsCategoryName(IdNamemap.getOrDefault(Long.valueOf(goods.getGoodsCategoryId()),""));
 			if(StringUtils.isNotEmpty(goods.getStudentShowOrganId())){
 				String[] split = goods.getStudentShowOrganId().split(",");
 				StringBuffer sb = new StringBuffer();
@@ -381,7 +384,18 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 	}
 
 	@Override
-	public PageInfo<Goods> queryPage(QueryInfo queryInfo) {
+	public PageInfo<Goods> queryPage(GoodsQueryInfo queryInfo) {
+		Integer goodsCategoryId = queryInfo.getGoodsCategoryId();
+		if (goodsCategoryId != null) {
+			Map<Long, ProductCategoryDto> idCategoryMap = mallFeignService.listWithChildren().stream().collect(Collectors.toMap(ProductCategoryDto::getId, Function.identity()));
+			if (idCategoryMap.containsKey(Long.valueOf(goodsCategoryId))) {
+				ProductCategoryDto productCategoryDto = idCategoryMap.get(Long.valueOf(goodsCategoryId));
+				List<String> categoryIdList = productCategoryDto.getChildren().stream().map(ProductCategoryDto::getId).map(String::valueOf).distinct().collect(Collectors.toList());
+				categoryIdList.add(goodsCategoryId.toString());
+				queryInfo.setGoodsCategoryIds(String.join(",", categoryIdList));
+				queryInfo.setGoodsCategoryId(null);
+			}
+		}
 		PageInfo<Goods> page = super.queryPage(queryInfo);
 
 		List<Goods> rows = page.getRows();

+ 12 - 9
mec-biz/src/main/resources/config/mybatis/GoodsMapper.xml

@@ -328,6 +328,9 @@
             <if test="goodsCategoryId != null">
                 AND g.goods_category_id_ = #{goodsCategoryId}
             </if>
+            <if test="goodsCategoryIds != null">
+                AND find_in_set(g.goods_category_id_,#{goodsCategoryIds})
+            </if>
             <if test="type != null">
                 AND g.type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
             </if>
@@ -518,14 +521,14 @@
     </select>
 
     <select id="getGoodsInfo" resultMap="Goods">
-        SELECT g.*,gc.name_ goods_category_name_ FROM goods g
-                                                          LEFT JOIN goods_category gc on g.goods_category_id_ = gc.id_
+        SELECT g.* FROM goods g
+<!----><!--                                                          LEFT JOIN goods_category gc on g.goods_category_id_ = gc.id_-->
         WHERE g.id_=#{id}
     </select>
 
     <select id="getGoodiesAndCate" resultMap="Goods">
-        SELECT g.*,gc.name_ goods_category_name_ FROM goods g
-        LEFT JOIN goods_category gc on g.goods_category_id_ = gc.id_
+        SELECT g.* FROM goods g
+<!--        LEFT JOIN goods_category gc on g.goods_category_id_ = gc.id_-->
         WHERE g.id_ IN
         <foreach collection="goodsIds" item="goodsId" open="(" close=")" separator=",">
             #{goodsId}
@@ -542,7 +545,7 @@
         SELECT g.id_,g.brand_,g.specification_,g.brief_ param_,g.market_price_,g.discount_price_,g.group_purchase_price_ sale_price_,
         (g.discount_price_-g.group_purchase_price_) depreciation_price_
         FROM subject_goods_mapper sgm
-        LEFT JOIN goods_category gc ON gc.id_=sgm.goods_category_id_
+<!--        LEFT JOIN goods_category gc ON gc.id_=sgm.goods_category_id_-->
         LEFT JOIN goods g ON sgm.goods_category_id_ = g.goods_category_id_
         <include refid="replacementQuerySql"/>
         <include refid="global.limit"/>
@@ -551,7 +554,7 @@
     <select id="getReplacementInstrumentCount" resultType="int">
         SELECT COUNT(*)
         FROM subject_goods_mapper sgm
-        LEFT JOIN goods_category gc ON gc.id_=sgm.goods_category_id_
+<!--        LEFT JOIN goods_category gc ON gc.id_=sgm.goods_category_id_-->
         LEFT JOIN goods g ON sgm.goods_category_id_ = g.goods_category_id_
         <include refid="replacementQuerySql"/>
         <include refid="global.limit"/>
@@ -560,10 +563,10 @@
         select SUM(organ_cost_price_) from goods where FIND_IN_SET(id_,#{complementGoodsIdList});
     </select>
     <select id="exportGoods" resultMap="Goods">
-        SELECT g.*,gc.name_ goods_category_name_,
+        SELECT g.*,
         GROUP_CONCAT(gs.name_) child_name_,GROUP_CONCAT(gs.sn_) child_sn_,
         GROUP_CONCAT(gs.id_) child_id_,GROUP_CONCAT(gs.organ_cost_price_) child_organ_cost_price_ FROM goods g
-        LEFT JOIN goods_category gc ON g.goods_category_id_ = gc.id_
+<!--        LEFT JOIN goods_category gc ON g.goods_category_id_ = gc.id_-->
         left join goods gs ON FIND_IN_SET(gs.id_,g.complement_goods_id_list_)
         <include refid="queryGoodsPageSql"/>
         GROUP BY g.id_
@@ -574,7 +577,7 @@
         <where>
             g.status_ != 0
             AND g.type_ = 'INSTRUMENT'
-            AND gc.del_flag_ = 0 and g.tenant_id_ = #{tenantId}
+<!--            AND gc.del_flag_ = 0 and g.tenant_id_ = #{tenantId}-->
             <if test="organId != null">
                 AND FIND_IN_SET(#{organId},g.replacement_show_organ_id_)
             </if>