当前位置:网站首页>Cereals mall -day13- goods on the shelves
Cereals mall -day13- goods on the shelves
2022-06-09 03:28:00 【Endless code week after week】
Release commodities
Member information
From Member management module



We started the member service configuration , Creating a few pieces of data will solve this problem
Get the brand associated with the classification


vo
@Data
public class BrandVo {
private Long brandId;
private String brandName;
}
/** * Get a list of all categories associated with the current brand */
@GetMapping("/brands/list")
public R relationBrandsList(@RequestParam(value = "catId", required = true) Long catId) {
List<BrandEntity> vos = categoryBrandRelationService.getBrandByCatId(catId);
List<BrandVo> collect = vos.stream().map(item -> {
BrandVo brandVo = new BrandVo();
brandVo.setBrandId(item.getBrandId());
brandVo.setBrandName(item.getName());
return brandVo;
}).collect(Collectors.toList());
return R.ok().put("data", collect);
}
@Override
public List<BrandEntity> getBrandByCatId(Long catId) {
List<CategoryBrandRelationEntity> catelogId = baseMapper.selectList(new QueryWrapper<CategoryBrandRelationEntity>()
.eq("catelog_id", catId));
List<BrandEntity> collect = catelogId.stream().map(item -> {
Long brandId = item.getBrandId();
BrandEntity byId = brandService.getById(brandId);
return byId;
}).collect(Collectors.toList());
return collect;
}
test
Get all groups under the category & Association attribute

@Data
public class AttrGroupWithAttrsVo {
/** * grouping id */
private Long attrGroupId;
/** * Group name */
private String attrGroupName;
/** * Sort */
private Integer sort;
/** * describe */
private String descript;
/** * Group icon */
private String icon;
/** * Classification id */
private Long catelogId;
private List<AttrEntity> attrs;
}
@GetMapping("/{catelogId}/withattr")
public R getAttrgroupWithAttrs(@PathVariable("catelogId") Long catelogId) {
// 1. Find out all attribute groups under the current classification
// 2. Find out all attributes of each attribute group
List<AttrGroupWithAttrsVo> vos = attrGroupService.getAttrGroupWithAttrsByCatelogId(catelogId);
return R.ok().put("data", vos);
}
/** * according to classification id Find out all the groups and the attributes in these groups * @param catelogId * @return */
@Override
public List<AttrGroupWithAttrsVo> getAttrGroupWithAttrsByCatelogId(Long catelogId) {
// 1. Query grouping information
List<AttrGroupEntity> attrGroupEntities = this.list(new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId));
// 2. Query all properties
List<AttrGroupWithAttrsVo> collect = attrGroupEntities.stream().map(group -> {
AttrGroupWithAttrsVo attrsVo = new AttrGroupWithAttrsVo();
BeanUtils.copyProperties(group, attrsVo);
List<AttrEntity> attrs = attrService.getRelationAttr(attrsVo.getAttrGroupId());
attrsVo.setAttrs(attrs);
return attrsVo;
}).collect(Collectors.toList());
return collect;
}
Many null pointers will be reported here , Remember to exclude

New products vo extract
according to Interface document , There is a tool website On-line JSON Verify formatting tool (Be JSON)

@Data
public class SpuSaveVo {
private String spuName;
private String spuDescription;
private Long catalogId;
private Long brandId;
private BigDecimal weight;
private int publishStatus;
private List<String> decript;
private List<String> images;
private Bounds bounds;
private List<BaseAttrs> baseAttrs;
private List<Skus> skus;
}
@Data
public class Bounds {
private BigDecimal buyBounds;
private BigDecimal growBounds;
}
@Data
public class BaseAttrs {
private Long attrId;
private String attrValues;
private int showDesc;
}
@Data
public class Skus {
private List<Attr> attr;
private String skuName;
private BigDecimal price;
private String skuTitle;
private String skuSubtitle;
private List<Images> images;
private List<String> descar;
private int fullCount;
private BigDecimal discount;
private int countStatus;
private BigDecimal fullPrice;
private BigDecimal reducePrice;
private int priceStatus;
private List<MemberPrice> memberPrice;
}
@Data
public class Attr {
private Long attrId;
private String attrName;
private String attrValue;
}
@Data
public class Images {
private String imgUrl;
private int defaultImg;
}
@Data
public class MemberPrice {
private Long id;
private String name;
private BigDecimal price;
}
preservation sku essential information
@Transactional
@Override
public void saveSpuInfo(SpuSaveVo saveVo) {
//1. preservation spu essential information pms_spu_info
SpuInfoEntity spuInfoEntity = new SpuInfoEntity();
BeanUtils.copyProperties(saveVo, spuInfoEntity);
spuInfoEntity.setCreateTime(new Date());
spuInfoEntity.setUpdateTime(new Date());
baseMapper.insert(spuInfoEntity);
//2. preservation spu Description of the picture pms_spu_info_desc
List<String> decript = saveVo.getDecript();
SpuInfoDescEntity descEntity = new SpuInfoDescEntity();
descEntity.setSpuId(spuInfoEntity.getId());
descEntity.setDecript(String.join(",", decript));
descService.save(descEntity);
//3. preservation spu The photo collection of pms_spu_images
List<String> images = saveVo.getImages();
spuImagesService.saveImages(spuInfoEntity.getId(), images);
//4. preservation spu Specification parameters of pms_product_attr_value
List<BaseAttrs> baseAttrs = saveVo.getBaseAttrs();
List<ProductAttrValueEntity> collect = baseAttrs.stream().map(attr -> {
ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();
valueEntity.setAttrId(attr.getAttrId());
valueEntity.setAttrName(attrService.getById(attr.getAttrId()).getAttrName());
valueEntity.setAttrValue(attr.getAttrValues());
valueEntity.setQuickShow(attr.getShowDesc());
valueEntity.setSpuId(spuInfoEntity.getId());
return valueEntity;
}).collect(Collectors.toList());
productAttrValueService.saveBatch(collect);
//5. preservation spu Integral information gulimall_sms -> sms_spu_bounds
Bounds bounds = saveVo.getBounds();
SpuBoundTo spuBoundTo = new SpuBoundTo();
BeanUtils.copyProperties(bounds, spuBoundTo);
spuBoundTo.setSpuId(spuInfoEntity.getId());
R r = couponFeignService.saveSpuBounds(spuBoundTo);
if (r.getCode() != 0) {
log.error(" Remote storage spu Integral information failed ");
}
//5. Save the current spu Corresponding sku Information :
List<Skus> skus = saveVo.getSkus();
if (skus != null && skus.size() > 0) {
skus.forEach(item -> {
String defaultImg = "";
for (Images image : item.getImages()) {
if (image.getDefaultImg() == 1) {
defaultImg = image.getImgUrl();
}
}
// private String skuName;
// private BigDecimal price;
// private String skuTitle;
// private String skuSubtitle;
SkuInfoEntity skuInfoEntity = new SkuInfoEntity();
BeanUtils.copyProperties(item, skuInfoEntity);
skuInfoEntity.setBrandId(skuInfoEntity.getBrandId());
skuInfoEntity.setCatalogId(skuInfoEntity.getCatalogId());
skuInfoEntity.setSaleCount(0L);
skuInfoEntity.setSpuId(spuInfoEntity.getId());
skuInfoEntity.setSkuDefaultImg(defaultImg);
// 5.1)sku essential information : pms_sku_info
skuInfoService.save(skuInfoEntity);
Long skuId = skuInfoEntity.getSkuId();
List<SkuImagesEntity> imagesEntities = item.getImages().stream().map(img -> {
SkuImagesEntity skuImagesEntity = new SkuImagesEntity();
skuImagesEntity.setSkuId(skuId);
skuImagesEntity.setImgUrl(img.getImgUrl());
skuImagesEntity.setDefaultImg(img.getDefaultImg());
return skuImagesEntity;
}).filter(entity -> {
return !StringUtils.isEmpty(entity.getImgUrl());
}).collect(Collectors.toList());
// 5.2)sku Image information : pms_sku_images
// TODO No picture Path does not need to be saved
skuImagesService.saveBatch(imagesEntities);
// 5.3)sku Sales attribute information of : pms_sku_sale_attr_value
List<Attr> attr = item.getAttr();
List<SkuSaleAttrValueEntity> skuSaleAttrValueEntities = attr.stream().map(a -> {
SkuSaleAttrValueEntity skuSaleAttrValueEntity = new SkuSaleAttrValueEntity();
BeanUtils.copyProperties(a, skuSaleAttrValueEntity);
skuSaleAttrValueEntity.setSkuId(skuId);
return skuSaleAttrValueEntity;
}).collect(Collectors.toList());
skuSaleAttrValueService.saveBatch(skuSaleAttrValueEntities);
// 5.4 ) sku Discount , Full minus and other information
SkuReductionTo skuReductionTo = new SkuReductionTo();
BeanUtils.copyProperties(item, skuReductionTo);
skuReductionTo.setSkuId(skuId);
if (skuReductionTo.getFullCount() > 0 && skuReductionTo.getFullPrice().compareTo(new BigDecimal("0")) == 1) {
R r1 = couponFeignService.saveSkuReduction(skuReductionTo);
if (r1.getCode() != 0) {
log.error(" Remote storage sku Offer information failed ");
}
}
});
}
}
Call the remote interface to save information such as product discounts
@FeignClient("gulimall-coupon")
public interface CouponFeignService {
@PostMapping("/coupon/spubounds/save")
R saveSpuBounds(@RequestBody SpuBoundTo spuBoundTo);
@PostMapping("/coupon/skufullreduction/saveinfo")
R saveSkuReduction(@RequestBody SkuReductionTo skuReductionTo);
}
The second interface , Here it is common Created in to
@Data
public class SkuReductionTo {
private Long skuId;
private int fullCount;
private BigDecimal discount;
private int countStatus;
private BigDecimal fullPrice;
private BigDecimal reducePrice;
private int priceStatus;
private List<MemberPrice> memberPrice;
}
@Data
public class SpuBoundTo {
private Long spuId;
private BigDecimal buyBounds;
private BigDecimal growBounds;
}
@Data
public class MemberPrice {
private Long id;
private String name;
private BigDecimal price;
}
@PostMapping("/saveinfo")
public R saveInfo(@RequestBody SkuReductionTo skuReductionTo) {
skuFullReductionService.saveSkuReduction(skuReductionTo);
return R.ok();
}
@Override
public void saveSkuReduction(SkuReductionTo skuReductionTo) {
// 1.sms_sku_ladder
SkuLadderEntity skuLadderEntity = new SkuLadderEntity();
skuLadderEntity.setSkuId(skuReductionTo.getSkuId());
skuLadderEntity.setFullCount(skuReductionTo.getFullCount());
skuLadderEntity.setDiscount(skuReductionTo.getDiscount());
skuLadderEntity.setAddOther(skuLadderEntity.getAddOther());
if (skuReductionTo.getFullCount() > 0) {
skuLadderService.save(skuLadderEntity);
}
// 2.sms_sku_full_reduction
SkuFullReductionEntity reductionEntity = new SkuFullReductionEntity();
BeanUtils.copyProperties(skuReductionTo, reductionEntity);
if (reductionEntity.getFullPrice().compareTo(new BigDecimal("0")) == 1) {
this.save(reductionEntity);
}
// 3.sms_member_price
List<MemberPrice> memberPrice = skuReductionTo.getMemberPrice();
List<MemberPriceEntity> collect = memberPrice.stream().map(item -> {
MemberPriceEntity priceEntity = new MemberPriceEntity();
priceEntity.setSkuId(reductionEntity.getSkuId());
priceEntity.setMemberLevelId(item.getId());
priceEntity.setMemberLevelName(item.getName());
priceEntity.setMemberPrice(item.getPrice());
priceEntity.setAddOther(1);
return priceEntity;
}).filter(item -> {
return item.getMemberPrice().compareTo(new BigDecimal("0")) == 1;
}).collect(Collectors.toList());
memberPriceService.saveBatch(collect);
}
spu retrieval
Here's the story Why... Here Splicing key You need to use this method when querying criteria
Because these two conditions are put together in parentheses

@Override
public PageUtils queryPageByCondition(Map<String, Object> params) {
QueryWrapper<SpuInfoEntity> queryWrapper = new QueryWrapper<>();
/** * status: * key: * brandId: 1 * catelogId: 225 */
String key = (String) params.get("key");
if (!StringUtils.isEmpty(key)) {
queryWrapper.and(w -> {
w.eq("id", key).or().like("spu_name", key);
});
}
// status=1 and (id=1 or spu_name like xxx)
String status = (String) params.get("status");
if (!StringUtils.isEmpty(status)) {
queryWrapper.eq("publish_status", status);
}
String brandId = (String) params.get("brandId");
if (!StringUtils.isEmpty(brandId) && "0".equalsIgnoreCase(brandId)) {
queryWrapper.eq("brand_id", brandId);
}
String catelogId = (String) params.get("catelogId");
if (!StringUtils.isEmpty(catelogId) && "0".equalsIgnoreCase(catelogId)) {
queryWrapper.eq("catalog_id", catelogId);
}
IPage<SpuInfoEntity> page = this.page(
new Query<SpuInfoEntity>().getPage(params),
queryWrapper
);
return new PageUtils(page);
}
sku retrieval
Notice here BigDecimal To deal with
@Override
public PageUtils queryPageByCondition(Map<String, Object> params) {
QueryWrapper<SkuInfoEntity> queryWrapper = new QueryWrapper<>();
String key = (String) params.get("key");
if (!StringUtils.isEmpty(key)) {
queryWrapper.and(w -> {
w.eq("sku_id", key).or().like("sku_name", key);
});
}
String catelogId = (String) params.get("catelogId");
if (!StringUtils.isEmpty(catelogId) && "0".equalsIgnoreCase(catelogId)) {
queryWrapper.eq("catalog_id", catelogId);
}
String brandId = (String) params.get("brandId");
if (!StringUtils.isEmpty(brandId) && "0".equalsIgnoreCase(brandId)) {
queryWrapper.eq("brand_id", brandId);
}
String max = (String) params.get("max");
if (!StringUtils.isEmpty(max)) {
try {
BigDecimal bigDecimal = new BigDecimal(max);
if (bigDecimal.compareTo(new BigDecimal("0")) == 1) {
queryWrapper.le("price", max);
}
} catch (Exception e) {
}
}
String min = (String) params.get("min");
if (!StringUtils.isEmpty(min)) {
queryWrapper.ge("price", min);
}
IPage<SkuInfoEntity> page = this.page(
new Query<SkuInfoEntity>().getPage(params),
queryWrapper
);
return new PageUtils(page);
}
边栏推荐
- postgresql判断数据库的主从关系
- Some thoughts on callback
- Alook browser cookie acquisition tutorial
- MySQL 开源许可研究
- Is it safe to open a stock account online? What is the stock account opening process?
- Structure of the actual combat battalion | module 3
- Boringssl compilation and testing
- Cw2015 alarm function
- Customized development of blind box app system
- 2022年短期理财产品排行榜
猜你喜欢

并发操作之——ReentrantReadWriteLock

免费的视频格式转换器

分布式 | dble 读写分离场景下为什么普通的读 sql 发送到了 master 实例上

Do you know websocket?

Ccf-csp 202203-3 computing resource scheduler 80 points

Ccf-csp 202203-1 uninitialized warning

外网访问局域网方法和VM安装的虚拟机如何在局域网内互相访问

New Presto data source support, new symbol map, and release of dataease open source data visual analysis platform v1.11.0

技术分享 | 调整 max-write-buffer-size 优化 pika 性能10倍的案例

关于JS console.log() 是同步 or 异步引发的问题
随机推荐
85. (leaflet house) leaflet military plotting - line arrow drawing
6.18 approaching, Ott becomes a new marketing battlefield
并发操作之——BlockingQueue
Practical combat of Youku terminal side bullet screen piercing technology: pixelai mobile terminal real-time portrait segmentation
[machinetranslation] a training of multilingual machinetranslation model
Redis6 learning notes - Chapter 1 - Introduction and environment construction of redis
Word+ regular expression = = quickly batch add caption (nanny level text)
Free video format converter
Development of DAPP system for digital currency holding interest bearing pledge financial management
Which securities firm should be selected for stock account opening? Is it safe to open an account
视频边缘计算网关EasyNVR硬件以服务方式启动一直报错,如何排查及解决?
Now VB6.0 has been connected to SQL, but when using the query function, you can't query with any conditions. The situation on the Internet is not consistent with mine. How can you implement it?
STM32 flash erase crash
Concurrent operation BlockingQueue
oracle 连接PLSQL
Linux MySQL installation tutorial (Graphic tutorial)
What does the seven layer network structure do?
分布式 | dble 读写分离场景下为什么普通的读 sql 发送到了 master 实例上
What does this SQL question mean
Common Android program functions clear cache