Explorar o código

优化 查询产品规格

java110 %!s(int64=5) %!d(string=hai) anos
pai
achega
19b1b74bf7

+ 32 - 13
java110-bean/src/main/java/com/java110/dto/product/ProductSpecDetailDto.java

@@ -1,6 +1,7 @@
 package com.java110.dto.product;
 
 import com.java110.dto.PageDto;
+
 import java.io.Serializable;
 import java.util.Date;
 
@@ -15,10 +16,11 @@ import java.util.Date;
 public class ProductSpecDetailDto extends PageDto implements Serializable {
 
     private String specId;
-private String detailName;
-private String detailValue;
-private String detailId;
-private String storeId;
+    private String[] specIds;
+    private String detailName;
+    private String detailValue;
+    private String detailId;
+    private String storeId;
 
 
     private Date createTime;
@@ -29,31 +31,40 @@ private String storeId;
     public String getSpecId() {
         return specId;
     }
-public void setSpecId(String specId) {
+
+    public void setSpecId(String specId) {
         this.specId = specId;
     }
-public String getDetailName() {
+
+    public String getDetailName() {
         return detailName;
     }
-public void setDetailName(String detailName) {
+
+    public void setDetailName(String detailName) {
         this.detailName = detailName;
     }
-public String getDetailValue() {
+
+    public String getDetailValue() {
         return detailValue;
     }
-public void setDetailValue(String detailValue) {
+
+    public void setDetailValue(String detailValue) {
         this.detailValue = detailValue;
     }
-public String getDetailId() {
+
+    public String getDetailId() {
         return detailId;
     }
-public void setDetailId(String detailId) {
+
+    public void setDetailId(String detailId) {
         this.detailId = detailId;
     }
-public String getStoreId() {
+
+    public String getStoreId() {
         return storeId;
     }
-public void setStoreId(String storeId) {
+
+    public void setStoreId(String storeId) {
         this.storeId = storeId;
     }
 
@@ -73,4 +84,12 @@ public void setStoreId(String storeId) {
     public void setStatusCd(String statusCd) {
         this.statusCd = statusCd;
     }
+
+    public String[] getSpecIds() {
+        return specIds;
+    }
+
+    public void setSpecIds(String[] specIds) {
+        this.specIds = specIds;
+    }
 }

+ 24 - 7
java110-bean/src/main/java/com/java110/dto/product/ProductSpecDto.java

@@ -1,8 +1,10 @@
 package com.java110.dto.product;
 
 import com.java110.dto.PageDto;
+
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
 /**
  * @ClassName FloorDto
@@ -15,31 +17,38 @@ import java.util.Date;
 public class ProductSpecDto extends PageDto implements Serializable {
 
     private String specId;
-private String specName;
-private String storeId;
+    private String specName;
+    private String storeId;
 
 
     private Date createTime;
 
     private String statusCd = "0";
 
+    private List<ProductSpecDetailDto> productSpecDetails;
+
 
     public String getSpecId() {
         return specId;
     }
-public void setSpecId(String specId) {
+
+    public void setSpecId(String specId) {
         this.specId = specId;
     }
-public String getSpecName() {
+
+    public String getSpecName() {
         return specName;
     }
-public void setSpecName(String specName) {
+
+    public void setSpecName(String specName) {
         this.specName = specName;
     }
-public String getStoreId() {
+
+    public String getStoreId() {
         return storeId;
     }
-public void setStoreId(String storeId) {
+
+    public void setStoreId(String storeId) {
         this.storeId = storeId;
     }
 
@@ -59,4 +68,12 @@ public void setStoreId(String storeId) {
     public void setStatusCd(String statusCd) {
         this.statusCd = statusCd;
     }
+
+    public List<ProductSpecDetailDto> getProductSpecDetails() {
+        return productSpecDetails;
+    }
+
+    public void setProductSpecDetails(List<ProductSpecDetailDto> productSpecDetails) {
+        this.productSpecDetails = productSpecDetails;
+    }
 }

+ 79 - 77
java110-db/src/main/resources/mapper/goods/ProductSpecDetailServiceDaoImplMapper.xml

@@ -5,102 +5,104 @@
 <mapper namespace="productSpecDetailServiceDaoImpl">
 
 
-
-
-
     <!-- 保存产品规格明细信息 add by wuxw 2018-07-03 -->
     <insert id="saveProductSpecDetailInfo" parameterType="Map">
         insert into product_spec_detail(
-spec_id,detail_name,detail_value,detail_id,store_id
-) values (
-#{specId},#{detailName},#{detailValue},#{detailId},#{storeId}
-)
+        spec_id,detail_name,detail_value,detail_id,store_id
+        ) values (
+        #{specId},#{detailName},#{detailValue},#{detailId},#{storeId}
+        )
     </insert>
 
 
-
     <!-- 查询产品规格明细信息 add by wuxw 2018-07-03 -->
     <select id="getProductSpecDetailInfo" parameterType="Map" resultType="Map">
-        select  t.spec_id,t.spec_id specId,t.detail_name,t.detail_name detailName,t.detail_value,t.detail_value detailValue,t.detail_id,t.detail_id detailId,t.status_cd,t.status_cd statusCd,t.store_id,t.store_id storeId 
-from product_spec_detail t 
-where 1 =1 
-<if test="specId !=null and specId != ''">
-   and t.spec_id= #{specId}
-</if> 
-<if test="detailName !=null and detailName != ''">
-   and t.detail_name= #{detailName}
-</if> 
-<if test="detailValue !=null and detailValue != ''">
-   and t.detail_value= #{detailValue}
-</if> 
-<if test="detailId !=null and detailId != ''">
-   and t.detail_id= #{detailId}
-</if> 
-<if test="statusCd !=null and statusCd != ''">
-   and t.status_cd= #{statusCd}
-</if> 
-<if test="storeId !=null and storeId != ''">
-   and t.store_id= #{storeId}
-</if> 
-order by t.create_time desc
-<if test="page != -1 and page != null ">
-   limit #{page}, #{row}
-</if> 
+        select t.spec_id,t.spec_id specId,t.detail_name,t.detail_name detailName,t.detail_value,t.detail_value
+        detailValue,t.detail_id,t.detail_id detailId,t.status_cd,t.status_cd statusCd,t.store_id,t.store_id storeId
+        from product_spec_detail t
+        where 1 =1
+        <if test="specId !=null and specId != ''">
+            and t.spec_id= #{specId}
+        </if>
+        <if test="specIds != null">
+            and t.spec_id in
+            <foreach collection="specIds" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        <if test="detailName !=null and detailName != ''">
+            and t.detail_name= #{detailName}
+        </if>
+        <if test="detailValue !=null and detailValue != ''">
+            and t.detail_value= #{detailValue}
+        </if>
+        <if test="detailId !=null and detailId != ''">
+            and t.detail_id= #{detailId}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="storeId !=null and storeId != ''">
+            and t.store_id= #{storeId}
+        </if>
+        order by t.create_time desc
+        <if test="page != -1 and page != null ">
+            limit #{page}, #{row}
+        </if>
 
     </select>
 
 
-
-
     <!-- 修改产品规格明细信息 add by wuxw 2018-07-03 -->
     <update id="updateProductSpecDetailInfo" parameterType="Map">
-        update  product_spec_detail t set t.status_cd = #{statusCd}
-<if test="newBId != null and newBId != ''">
-,t.b_id = #{newBId}
-</if> 
-<if test="specId !=null and specId != ''">
-, t.spec_id= #{specId}
-</if> 
-<if test="detailName !=null and detailName != ''">
-, t.detail_name= #{detailName}
-</if> 
-<if test="detailValue !=null and detailValue != ''">
-, t.detail_value= #{detailValue}
-</if> 
-<if test="storeId !=null and storeId != ''">
-, t.store_id= #{storeId}
-</if> 
- where 1=1 <if test="detailId !=null and detailId != ''">
-and t.detail_id= #{detailId}
-</if> 
+        update product_spec_detail t set t.status_cd = #{statusCd}
+        <if test="newBId != null and newBId != ''">
+            ,t.b_id = #{newBId}
+        </if>
+        <if test="specId !=null and specId != ''">
+            , t.spec_id= #{specId}
+        </if>
+        <if test="detailName !=null and detailName != ''">
+            , t.detail_name= #{detailName}
+        </if>
+        <if test="detailValue !=null and detailValue != ''">
+            , t.detail_value= #{detailValue}
+        </if>
+        <if test="storeId !=null and storeId != ''">
+            , t.store_id= #{storeId}
+        </if>
+        where 1=1
+        <if test="detailId !=null and detailId != ''">
+            and t.detail_id= #{detailId}
+        </if>
 
     </update>
 
     <!-- 查询产品规格明细数量 add by wuxw 2018-07-03 -->
-     <select id="queryProductSpecDetailsCount" parameterType="Map" resultType="Map">
-        select  count(1) count 
-from product_spec_detail t 
-where 1 =1 
-<if test="specId !=null and specId != ''">
-   and t.spec_id= #{specId}
-</if> 
-<if test="detailName !=null and detailName != ''">
-   and t.detail_name= #{detailName}
-</if> 
-<if test="detailValue !=null and detailValue != ''">
-   and t.detail_value= #{detailValue}
-</if> 
-<if test="detailId !=null and detailId != ''">
-   and t.detail_id= #{detailId}
-</if> 
-<if test="statusCd !=null and statusCd != ''">
-   and t.status_cd= #{statusCd}
-</if> 
-<if test="storeId !=null and storeId != ''">
-   and t.store_id= #{storeId}
-</if> 
+    <select id="queryProductSpecDetailsCount" parameterType="Map" resultType="Map">
+        select count(1) count
+        from product_spec_detail t
+        where 1 =1
+        <if test="specId !=null and specId != ''">
+            and t.spec_id= #{specId}
+        </if>
+        <if test="detailName !=null and detailName != ''">
+            and t.detail_name= #{detailName}
+        </if>
+        <if test="detailValue !=null and detailValue != ''">
+            and t.detail_value= #{detailValue}
+        </if>
+        <if test="detailId !=null and detailId != ''">
+            and t.detail_id= #{detailId}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="storeId !=null and storeId != ''">
+            and t.store_id= #{storeId}
+        </if>
 
 
-     </select>
+    </select>
 
 </mapper>

+ 32 - 1
service-goods/src/main/java/com/java110/goods/bmo/productSpec/impl/GetProductSpecBMOImpl.java

@@ -1,7 +1,9 @@
 package com.java110.goods.bmo.productSpec.impl;
 
+import com.java110.dto.product.ProductSpecDetailDto;
 import com.java110.dto.product.ProductSpecDto;
 import com.java110.goods.bmo.productSpec.IGetProductSpecBMO;
+import com.java110.intf.goods.IProductSpecDetailInnerServiceSMO;
 import com.java110.intf.goods.IProductSpecInnerServiceSMO;
 import com.java110.vo.ResultVo;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -18,18 +20,21 @@ public class GetProductSpecBMOImpl implements IGetProductSpecBMO {
     @Autowired
     private IProductSpecInnerServiceSMO productSpecInnerServiceSMOImpl;
 
+    @Autowired
+    private IProductSpecDetailInnerServiceSMO productSpecDetailInnerServiceSMOImpl;
+
     /**
      * @param productSpecDto
      * @return 订单服务能够接受的报文
      */
     public ResponseEntity<String> get(ProductSpecDto productSpecDto) {
 
-
         int count = productSpecInnerServiceSMOImpl.queryProductSpecsCount(productSpecDto);
 
         List<ProductSpecDto> productSpecDtos = null;
         if (count > 0) {
             productSpecDtos = productSpecInnerServiceSMOImpl.queryProductSpecs(productSpecDto);
+            freshSpecDetail(productSpecDtos);
         } else {
             productSpecDtos = new ArrayList<>();
         }
@@ -41,4 +46,30 @@ public class GetProductSpecBMOImpl implements IGetProductSpecBMO {
         return responseEntity;
     }
 
+    private void freshSpecDetail(List<ProductSpecDto> productSpecDtos) {
+
+        if (productSpecDtos == null || productSpecDtos.size() < 1) {
+            return;
+        }
+        List<String> specIds = new ArrayList<>();
+        for (ProductSpecDto productSpecDto : productSpecDtos) {
+            specIds.add(productSpecDto.getSpecId());
+        }
+
+        ProductSpecDetailDto productSpecDetailDto = new ProductSpecDetailDto();
+        productSpecDetailDto.setSpecIds(specIds.toArray(new String[specIds.size()]));
+        productSpecDetailDto.setStoreId(productSpecDtos.get(0).getStoreId());
+        List<ProductSpecDetailDto> productSpecDetailDtos = productSpecDetailInnerServiceSMOImpl.queryProductSpecDetails(productSpecDetailDto);
+        List<ProductSpecDetailDto> tmpProductSpecDetailDtos = null;
+        for (ProductSpecDto productSpecDto : productSpecDtos) {
+            tmpProductSpecDetailDtos = new ArrayList<>();
+            for (ProductSpecDetailDto tmpProductSpecDetailDto : productSpecDetailDtos) {
+                if (productSpecDto.getSpecId().equals(tmpProductSpecDetailDto.getSpecId())) {
+                    tmpProductSpecDetailDtos.add(tmpProductSpecDetailDto);
+                }
+            }
+            productSpecDto.setProductSpecDetails(tmpProductSpecDetailDtos);
+        }
+    }
+
 }

+ 2 - 1
service-goods/src/main/java/com/java110/goods/smo/impl/ProductSpecDetailInnerServiceSMOImpl.java

@@ -62,7 +62,8 @@ public class ProductSpecDetailInnerServiceSMOImpl extends BaseServiceSMO impleme
             productSpecDetailDto.setPage((page - 1) * productSpecDetailDto.getRow());
         }
 
-        List<ProductSpecDetailDto> productSpecDetails = BeanConvertUtil.covertBeanList(productSpecDetailServiceDaoImpl.getProductSpecDetailInfo(BeanConvertUtil.beanCovertMap(productSpecDetailDto)), ProductSpecDetailDto.class);
+        List<ProductSpecDetailDto> productSpecDetails
+                = BeanConvertUtil.covertBeanList(productSpecDetailServiceDaoImpl.getProductSpecDetailInfo(BeanConvertUtil.beanCovertMap(productSpecDetailDto)), ProductSpecDetailDto.class);
 
         return productSpecDetails;
     }