Commit d9722179 by 刘宇峰

处理mybatis集合映射问题(id列不能省略)

1 parent 1efc339a
...@@ -5,6 +5,7 @@ import lombok.Data; ...@@ -5,6 +5,7 @@ import lombok.Data;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Table; import javax.persistence.Table;
import java.util.List;
@Data @Data
@Table(name = "shopmall_goods") @Table(name = "shopmall_goods")
...@@ -210,4 +211,13 @@ public class Goods extends BaseEntity { ...@@ -210,4 +211,13 @@ public class Goods extends BaseEntity {
*/ */
private Integer height; private Integer height;
private List<GoodsSpecification> specList;
private GoodsDescDetail descDetail;
private List<GoodsAttribute> attributeList;
private List<GoodsImage> goodsImageList;
private GoodsStock goodsStock;
private GoodsSaleLimit goodsLimit;
} }
\ No newline at end of file \ No newline at end of file
...@@ -10,18 +10,20 @@ public interface GoodsConverter { ...@@ -10,18 +10,20 @@ public interface GoodsConverter {
GoodsConverter INSTANCE = Mappers.getMapper(GoodsConverter.class); GoodsConverter INSTANCE = Mappers.getMapper(GoodsConverter.class);
Goods responseToGoods(QueryGoodsDetailResponse entity); Goods toGoodsDetailResponse(QueryGoodsDetailResponse entity);
GoodsImage responseToGoodsImage(GoodsImageListItem entity); GoodsImage toGoodsImageListItem(GoodsImageListItem entity);
GoodsDescDetail responseToGoodsDescDetail(GoodsDescDetailModel entity); GoodsDescDetail toGoodsDescDetailModel(GoodsDescDetailModel entity);
GoodsAttribute responseToGoodsAttribute(GoodsAttributeListItem entity); GoodsAttribute toGoodsAttributeListItem(GoodsAttributeListItem entity);
GoodsSpecification responseToGoodsSpecification(GoodsSpecListItem entity); GoodsSpecification toGoodsSpecListItem(GoodsSpecListItem entity);
GoodsStock responseToGoodsStock(QueryGoodsStockListResponse entity); GoodsStock toGoodsStockListResponse(QueryGoodsStockListResponse entity);
GoodsSaleLimit responseToGoodsSaleLimit(QueryGoodsSaleLimitListResponse entity); GoodsSaleLimit toGoodsSaleLimitListResponse(QueryGoodsSaleLimitListResponse entity);
QueryGoodsDetailResponse toGoodsDetailResponse(Goods entity);
} }
...@@ -16,7 +16,7 @@ public interface GoodsMapper extends CommonBaseMapper<Goods> { ...@@ -16,7 +16,7 @@ public interface GoodsMapper extends CommonBaseMapper<Goods> {
List<GoodsSkuListSearchItem> queryGoodsListByCondition(QueryGoodsListByConditionRequest req); List<GoodsSkuListSearchItem> queryGoodsListByCondition(QueryGoodsListByConditionRequest req);
List<QueryGoodsDetailResponse> queryGoodsDetail(@Param("goodsSkuCodes") List<String> goodsSkuCodes); List<Goods> queryGoodsDetail(@Param("goodsSkuCodes") List<String> goodsSkuCodes);
List<QueryGoodsShelvesListResponse> queryGoodsShelvesList(@Param("goodsSkuCodes") List<String> goodsSkuCodes); List<QueryGoodsShelvesListResponse> queryGoodsShelvesList(@Param("goodsSkuCodes") List<String> goodsSkuCodes);
......
...@@ -84,7 +84,11 @@ public class GoodsService { ...@@ -84,7 +84,11 @@ public class GoodsService {
public List<QueryGoodsDetailResponse> queryGoodsDetail(List<String> goodsSkuCodes) { public List<QueryGoodsDetailResponse> queryGoodsDetail(List<String> goodsSkuCodes) {
Assert.notEmpty(goodsSkuCodes, "goodsSkuCodes can not be null."); Assert.notEmpty(goodsSkuCodes, "goodsSkuCodes can not be null.");
// cloudCraneService.queryGoodsDetail(goodsSkuCodes); // cloudCraneService.queryGoodsDetail(goodsSkuCodes);
return goodsMapper.queryGoodsDetail(goodsSkuCodes); List<Goods> goodsList = goodsMapper.queryGoodsDetail(goodsSkuCodes);
List<QueryGoodsDetailResponse> goodsDetailList = goodsList.parallelStream().map(GoodsConverter.INSTANCE::toGoodsDetailResponse).collect(Collectors.toList());
return goodsDetailList;
} }
/** /**
...@@ -242,13 +246,13 @@ public class GoodsService { ...@@ -242,13 +246,13 @@ public class GoodsService {
boolean existFlag = goodsShelvesMap.containsKey(goodsDetailResponse.getGoodsSkuCode()); boolean existFlag = goodsShelvesMap.containsKey(goodsDetailResponse.getGoodsSkuCode());
log.info("开始处理商品{},是否存在:{}", goodsDetailResponse.getGoodsSkuCode(), existFlag); log.info("开始处理商品{},是否存在:{}", goodsDetailResponse.getGoodsSkuCode(), existFlag);
Goods goods = GoodsConverter.INSTANCE.responseToGoods(goodsDetailResponse); Goods goods = GoodsConverter.INSTANCE.toGoodsDetailResponse(goodsDetailResponse);
List<GoodsImage> goodsImageList = goodsDetailResponse.getGoodsImageList().parallelStream().map(GoodsConverter.INSTANCE::responseToGoodsImage).collect(Collectors.toList()); List<GoodsImage> goodsImageList = goodsDetailResponse.getGoodsImageList().parallelStream().map(GoodsConverter.INSTANCE::toGoodsImageListItem).collect(Collectors.toList());
GoodsDescDetail goodsDescDetail = GoodsConverter.INSTANCE.responseToGoodsDescDetail(goodsDetailResponse.getDescDetail()); GoodsDescDetail goodsDescDetail = GoodsConverter.INSTANCE.toGoodsDescDetailModel(goodsDetailResponse.getDescDetail());
List<GoodsAttribute> goodsAttributeList = goodsDetailResponse.getAttributeList().parallelStream().map(GoodsConverter.INSTANCE::responseToGoodsAttribute).collect(Collectors.toList()); List<GoodsAttribute> goodsAttributeList = goodsDetailResponse.getAttributeList().parallelStream().map(GoodsConverter.INSTANCE::toGoodsAttributeListItem).collect(Collectors.toList());
List<GoodsSpecification> goodsSpecificationList = goodsDetailResponse.getSpecList().parallelStream().map(GoodsConverter.INSTANCE::responseToGoodsSpecification).collect(Collectors.toList()); List<GoodsSpecification> goodsSpecificationList = goodsDetailResponse.getSpecList().parallelStream().map(GoodsConverter.INSTANCE::toGoodsSpecListItem).collect(Collectors.toList());
GoodsStock goodsStock = GoodsConverter.INSTANCE.responseToGoodsStock(goodsDetailResponse.getGoodsStock()); GoodsStock goodsStock = GoodsConverter.INSTANCE.toGoodsStockListResponse(goodsDetailResponse.getGoodsStock());
GoodsSaleLimit goodsSaleLimit = GoodsConverter.INSTANCE.responseToGoodsSaleLimit(goodsDetailResponse.getGoodsLimit()); GoodsSaleLimit goodsSaleLimit = GoodsConverter.INSTANCE.toGoodsSaleLimitListResponse(goodsDetailResponse.getGoodsLimit());
//新增或更新商品数据 //新增或更新商品数据
goodsMapper.insertOrUpdate(goods); goodsMapper.insertOrUpdate(goods);
......
...@@ -58,37 +58,43 @@ ...@@ -58,37 +58,43 @@
gross_weight, gross_weight_unit, density, extent, width, height, del_flag, created_date, gross_weight, gross_weight_unit, density, extent, width, height, del_flag, created_date,
created_by, updated_date, updated_by created_by, updated_date, updated_by
</sql> </sql>
<sql id="Blob_Column_List"> <resultMap id="GoodsDetailMap" extends="BaseResultMap" type="cn.com.glsx.admin.modules.entity.Goods">
<!-- <association property="descDetail" javaType="cn.com.glsx.admin.modules.entity.GoodsDescDetail">
WARNING - @mbg.generated <id column="sgdd_id" javaType="LONG" property="id"/>
--> <result column="goods_sku_code" jdbcType="VARCHAR" property="goodsSkuCode"/>
goods_describe
</sql>
<resultMap id="GoodsDetailMap" extends="BaseResultMap" type="cn.com.glsx.admin.modules.model.cloudcrane.response.QueryGoodsDetailResponse">
<association property="descDetail" javaType="cn.com.glsx.admin.modules.model.cloudcrane.response.GoodsDescDetailModel">
<result column="goods_describe" jdbcType="VARCHAR" property="goodsDescribe"/> <result column="goods_describe" jdbcType="VARCHAR" property="goodsDescribe"/>
</association> </association>
<association property="goodsStock" javaType="cn.com.glsx.admin.modules.model.cloudcrane.response.QueryGoodsStockListResponse"> <association property="goodsStock" javaType="cn.com.glsx.admin.modules.entity.GoodsStock">
<result column="stock_status" jdbcType="INTEGER" property="stockStatus" /> <id column="sgsk_id" javaType="LONG" property="id"/>
<result column="stock_num" jdbcType="INTEGER" property="stockNum" /> <result column="goods_sku_code" jdbcType="VARCHAR" property="goodsSkuCode"/>
<result column="stock_status" jdbcType="INTEGER" property="stockStatus"/>
<result column="stock_num" jdbcType="INTEGER" property="stockNum"/>
</association> </association>
<association property="goodsLimit" javaType="cn.com.glsx.admin.modules.model.cloudcrane.response.QueryGoodsSaleLimitListResponse"> <association property="goodsLimit" javaType="cn.com.glsx.admin.modules.entity.GoodsSaleLimit">
<result column="sale_limit_type" jdbcType="INTEGER" property="saleLimitType" /> <id column="sgsl_id" javaType="LONG" property="id"/>
<result column="province_ids" jdbcType="VARCHAR" property="provinceIds" /> <result column="goods_sku_code" jdbcType="VARCHAR" property="goodsSkuCode"/>
<result column="city_ids" jdbcType="VARCHAR" property="cityIds" /> <result column="sale_limit_type" jdbcType="INTEGER" property="saleLimitType"/>
<result column="area_ids" jdbcType="VARCHAR" property="areaIds" /> <result column="province_ids" jdbcType="VARCHAR" property="provinceIds"/>
<result column="city_ids" jdbcType="VARCHAR" property="cityIds"/>
<result column="area_ids" jdbcType="VARCHAR" property="areaIds"/>
</association> </association>
<collection property="specList" ofType="cn.com.glsx.admin.modules.model.cloudcrane.response.GoodsSpecListItem"> <collection property="specList" ofType="cn.com.glsx.admin.modules.entity.GoodsSpecification">
<result column="spec_name" jdbcType="VARCHAR" property="specName" /> <id column="sgs_id" javaType="LONG" property="id"/>
<result column="spec_value" jdbcType="VARCHAR" property="specValue" /> <result column="goods_sku_code" jdbcType="VARCHAR" property="goodsSkuCode"/>
<result column="spec_name" jdbcType="VARCHAR" property="specName"/>
<result column="spec_value" jdbcType="VARCHAR" property="specValue"/>
</collection> </collection>
<collection property="attributeList" ofType="cn.com.glsx.admin.modules.model.cloudcrane.response.GoodsAttributeListItem"> <collection property="attributeList" ofType="cn.com.glsx.admin.modules.entity.GoodsAttribute">
<result column="attribute_code" jdbcType="VARCHAR" property="attributeCode" /> <id column="sga_id" javaType="LONG" property="id"/>
<result column="attribute_name" jdbcType="VARCHAR" property="attributeName" /> <result column="goods_sku_code" jdbcType="VARCHAR" property="goodsSkuCode"/>
<result column="attribute_value_code" jdbcType="VARCHAR" property="attributeValueCode" /> <result column="attribute_code" jdbcType="VARCHAR" property="attributeCode"/>
<result column="attribute_value_name" jdbcType="VARCHAR" property="attributeValueName" /> <result column="attribute_name" jdbcType="VARCHAR" property="attributeName"/>
<result column="attribute_value_code" jdbcType="VARCHAR" property="attributeValueCode"/>
<result column="attribute_value_name" jdbcType="VARCHAR" property="attributeValueName"/>
</collection> </collection>
<collection property="goodsImageList" ofType="cn.com.glsx.admin.modules.model.cloudcrane.response.GoodsImageListItem"> <collection property="goodsImageList" ofType="cn.com.glsx.admin.modules.entity.GoodsImage">
<id column="sgi_id" javaType="LONG" property="id"/>
<result column="goods_sku_code" jdbcType="VARCHAR" property="goodsSkuCode"/>
<result column="img_url" jdbcType="VARCHAR" property="imgUrl"/> <result column="img_url" jdbcType="VARCHAR" property="imgUrl"/>
<result column="img_main" jdbcType="INTEGER" property="imgMain"/> <result column="img_main" jdbcType="INTEGER" property="imgMain"/>
<result column="img_sort" jdbcType="INTEGER" property="imgSort"/> <result column="img_sort" jdbcType="INTEGER" property="imgSort"/>
...@@ -144,22 +150,25 @@ ...@@ -144,22 +150,25 @@
</select> </select>
<select id="queryGoodsDetail" resultMap="GoodsDetailMap"> <select id="queryGoodsDetail" resultMap="GoodsDetailMap">
select sg.goods_code,sg.goods_sku_code,sg.goods_sku_name,sg.goods_sku_title,sg.sell_price,sg.market_price, select sg.id,sg.goods_code,sg.goods_sku_code,sg.goods_sku_name,sg.goods_sku_title,sg.sell_price,sg.market_price,
sg.start_qty,sg.shelves_status,sg.tax_code,sg.tax_rate,sg.bar_code,sg.is_deleted,sg.brand_code, sg.start_qty,sg.shelves_status,sg.tax_code,sg.tax_rate,sg.bar_code,sg.is_deleted,sg.brand_code,
sg.brand_name,sg.first_category_code,sg.first_category_name,sg.second_category_code,sg.second_category_name, sg.brand_name,sg.first_category_code,sg.first_category_name,sg.second_category_code,sg.second_category_name,
sg.last_category_code,sg.last_category_name,sg.return_goods_rules,sg.goods_characteristic,sg.goods_unit, sg.last_category_code,sg.last_category_name,sg.return_goods_rules,sg.goods_characteristic,sg.goods_unit,
sg.model_number,sg.product_place,sg.have_shelf_life,sg.shelf_life,sg.fragile_goods,sg.gross_weight,sg.gross_weight_unit, sg.model_number,sg.product_place,sg.have_shelf_life,sg.shelf_life,sg.fragile_goods,sg.gross_weight,sg.gross_weight_unit,
sg.density,sg.extent,sg.width,sg.height,sgs.spec_name,sgs.spec_value,sgdd.goods_describe, sg.density,sg.extent,sg.width,sg.height,
sga.attribute_code,sga.attribute_name,sga.attribute_value_code,sga.attribute_value_name, sgdd.id sgdd_id,sgdd.goods_describe,
sgi.img_url,sgi.img_main,sgi.img_sort,sgs2.stock_status,sgs2.stock_num, sgs.id sgs_id,sgs.spec_name,sgs.spec_value,
sgsl.sale_limit_type,sgsl.province_ids,sgsl.city_ids,sgsl.area_ids sga.id sga_id,sga.attribute_code,sga.attribute_name,sga.attribute_value_code,sga.attribute_value_name,
sgi.id sgi_id,sgi.img_url,sgi.img_main,sgi.img_sort,
sgs2.id sgsk_id,sgs2.stock_status,sgs2.stock_num,
sgsl.id sgsl_id,sgsl.sale_limit_type,sgsl.province_ids,sgsl.city_ids,sgsl.area_ids
from shopmall_goods sg from shopmall_goods sg
inner join shopmall_goods_desc_detail sgdd on sg.goods_sku_code=sgdd.goods_sku_code
inner join shopmall_goods_stock sgs2 on sg.goods_sku_code=sgs2.goods_sku_code
inner join shopmall_goods_sale_limit sgsl on sg.goods_sku_code=sgsl.goods_sku_code
left join shopmall_goods_specification sgs on sg.goods_sku_code=sgs.goods_sku_code left join shopmall_goods_specification sgs on sg.goods_sku_code=sgs.goods_sku_code
left join shopmall_goods_desc_detail sgdd on sg.goods_sku_code=sgdd.goods_sku_code
left join shopmall_goods_attribute sga on sg.goods_sku_code=sga.goods_sku_code left join shopmall_goods_attribute sga on sg.goods_sku_code=sga.goods_sku_code
left join shopmall_goods_image sgi on sg.goods_sku_code=sgi.goods_sku_code left join shopmall_goods_image sgi on sg.goods_sku_code=sgi.goods_sku_code
left join shopmall_goods_stock sgs2 on sg.goods_sku_code=sgs2.goods_sku_code
left join shopmall_goods_sale_limit sgsl on sg.goods_sku_code=sgsl.goods_sku_code
where sg.del_flag = 0 where sg.del_flag = 0
and sg.goods_sku_code in and sg.goods_sku_code in
<foreach collection="goodsSkuCodes" separator="," item="item" open="(" close=")"> <foreach collection="goodsSkuCodes" separator="," item="item" open="(" close=")">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!