商品上架:构造基本数据
作者:互联网
package com.atguigu.common.to.es; import lombok.Data; import java.io.Serializable; import java.math.BigDecimal; import java.util.List; /** * <p>Title: SkuEsModel</p> * Description: * "mappings": { * "properties": { * "skuId":{ * "type": "long" * }, * "spuId":{ * "type": "keyword" * }, * "skuTitle":{ * "type": "text", * "analyzer": "ik_smart" * }, * "skuPrice":{ * "type": "keyword" * }, * "skuImg":{ * "type": "keyword", * "index": false, * "doc_values": false * }, * "saleCount":{ * "type": "long" * }, * "hasStock":{ * "type": "boolean" * }, * "hotScore":{ * "type": "long" * }, * "brandId":{ * "type": "long" * }, * "catalogId":{ * "type": "long" * }, * "brandName":{ * "type":"keyword", * "index": false, * "doc_values": false * }, * "brandImg":{ * "type": "keyword", * "index": false, * "doc_values": false * }, * "catalogName":{ * "type": "keyword", * "index": false, * "doc_values": false * }, * "attrs":{ * "type": "nested", * "properties": { * "attrId":{ * "type":"long" * }, * "attrName":{ * "type":"keyword", * "index":false, * "doc_values": false * }, * "attrValue":{ * "type":"keyword" * } * } * } * } * } * date:2020/6/8 18:52 */ @Data public class SkuEsModel implements Serializable { private Long skuId; private Long spuId; private String skuTitle; private BigDecimal skuPrice; private String skuImg; private Long saleCount; private Boolean hasStock; private Long hotScore; private Long brandId; private Long catalogId; private String brandName; private String brandImg; private String catalogName; private List<Attrs> attrs; /** * 检索属性 */ @Data public static class Attrs implements Serializable{ private Long attrId; private String attrName; private String attrValue; } }
讲道理,这个应该放到product服务和search服务中,这里放到了common服务中。
再次理清 skuspu:
===================================
/** * 不一样的属性:skuPrice、skuImg、hasStock、hotScore、 * brandName、brandImg、catalogName、attrs * * @param spuId */ @Override public void up(Long spuId) { // 1 组装数据 查出当前spuId对应的所有sku信息 List<SkuInfoEntity> skus = skuInfoService.getSkusBySpuId(spuId); // TODO 4. 查询当前 SKU的所有 可以被用来检索的规格属性===这些规格属性是按照spu来的,所以放到外面查一遍即可 // 2 封装每个sku的信息 List<SkuEsModel> uoProducts = skus.stream().map((x) -> { SkuEsModel esModel = new SkuEsModel(); //一样的属性: BeanUtils.copyProperties(x,esModel);//这个是spring的类 把当前遍历的sku拷贝到esModel中 //不一样的属性:skuPrice、skuImg、hasStock、hotScore、brandName、brandImg、catalogName、attrs //skuPrice、skuImg esModel.setSkuPrice(x.getPrice()); esModel.setSkuImg(x.getSkuDefaultImg()); // TODO 1. hasStock发送远程调用,查询是否有库存 // TODO 2. hotScore 热度评分。0,后面可以扩展 // TODO 3. brandName brandImg catalogName 查询品牌名字和分类名字,以及品牌图片 BrandEntity brandEntity = brandService.getById(esModel.getBrandId()); esModel.setBrandName(brandEntity.getName()); esModel.setBrandImg(brandEntity.getLogo()); CategoryEntity categoryEntity = categoryService.getById(esModel.getCatalogId()); esModel.setCatalogName(categoryEntity.getName()); return esModel; }).collect(Collectors.toList()); //TODO 5. 将数据发送给ES进行保存,要用search服务来做,不能直接用product服务来做。 }
内容待完成,今天先休息。22:52:51
标签:false,keyword,type,上架,private,商品,构造,esModel,Long 来源: https://www.cnblogs.com/wyw123456/p/15835391.html