package com.alatus.mall.product.service.impl;
import com.alatus.mall.product.dao.SkuInfoDao;
import com.alatus.mall.product.entity.SkuInfoEntity;
import com.alatus.mall.product.service.SkuInfoService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.alatus.common.utils.PageUtils;
import com.alatus.common.utils.Query;
@Service("pmsSkuInfoService")
public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoDao, SkuInfoEntity> implements SkuInfoService {
@Override
public PageUtils queryPage(Map<String, Object> params) {
QueryWrapper<SkuInfoEntity> queryWrapper = new QueryWrapper<>();
String key = (String) params.get("key");
if(!StringUtils.isEmpty(key) && !"0".equalsIgnoreCase(key)){
queryWrapper.and((wrapper) -> {
wrapper.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 min = (String) params.get("min");
if(!StringUtils.isEmpty(min) && !"0".equalsIgnoreCase(min)){
queryWrapper.ge("price",min);
}
String max = (String) params.get("max");
if(!StringUtils.isEmpty(max) && !"0".equalsIgnoreCase(max)){
try{
BigDecimal maxPrice = new BigDecimal(max);
if(maxPrice.compareTo(new BigDecimal("0")) == 1){
queryWrapper.le("price",max);
}
}
catch (Exception e){
e.printStackTrace();
}
}
IPage<SkuInfoEntity> page = this.page(
new Query<SkuInfoEntity>().getPage(params),
queryWrapper
);
return new PageUtils(page);
}
@Override
public void saveSkuInfo(SkuInfoEntity skuInfoEntity) {
this.baseMapper.insert(skuInfoEntity);
}
}
package com.alatus.mall.product.service.impl;
import com.alatus.mall.product.dao.SkuInfoDao;
import com.alatus.mall.product.entity.SkuInfoEntity;
import com.alatus.mall.product.service.SkuInfoService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.alatus.common.utils.PageUtils;
import com.alatus.common.utils.Query;
@Service("pmsSkuInfoService")
public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoDao, SkuInfoEntity> implements SkuInfoService {
@Override
public PageUtils queryPage(Map<String, Object> params) {
QueryWrapper<SkuInfoEntity> queryWrapper = new QueryWrapper<>();
String key = (String) params.get("key");
if(!StringUtils.isEmpty(key) && !"0".equalsIgnoreCase(key)){
queryWrapper.and((wrapper) -> {
wrapper.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 min = (String) params.get("min");
if(!StringUtils.isEmpty(min) && !"0".equalsIgnoreCase(min)){
queryWrapper.ge("price",min);
}
String max = (String) params.get("max");
if(!StringUtils.isEmpty(max) && !"0".equalsIgnoreCase(max)){
try{
BigDecimal maxPrice = new BigDecimal(max);
if(maxPrice.compareTo(new BigDecimal("0")) == 1){
queryWrapper.le("price",max);
}
}
catch (Exception e){
e.printStackTrace();
}
}
IPage<SkuInfoEntity> page = this.page(
new Query<SkuInfoEntity>().getPage(params),
queryWrapper
);
return new PageUtils(page);
}
@Override
public void saveSkuInfo(SkuInfoEntity skuInfoEntity) {
this.baseMapper.insert(skuInfoEntity);
}
}
package com.alatus.mall.product.service.impl;
import com.alatus.common.to.SkuReductionTo;
import com.alatus.common.to.SpuBoundTo;
import com.alatus.common.utils.R;
import com.alatus.mall.product.entity.*;
import com.alatus.mall.product.feign.CouponFeignService;
import com.alatus.mall.product.service.*;
import com.alatus.mall.product.vo.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.alatus.common.utils.PageUtils;
import com.alatus.common.utils.Query;
import com.alatus.mall.product.dao.SpuInfoDao;
import org.springframework.transaction.annotation.Transactional;
@Service("spuInfoService")
public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> implements SpuInfoService {
@Autowired
private SpuInfoDescService spuInfoDescService;
@Autowired
private SpuImagesService imagesService;
@Autowired
private AttrService attrService;
@Autowired
private ProductAttrValueService productAttrValueService;
@Autowired
private SkuInfoService skuInfoService;
@Autowired
private SkuImagesService skuImagesService;
@Autowired
private SkuSaleAttrValueService skuSaleAttrValueService;
@Autowired
private CouponFeignService couponFeignService;
@Override
public PageUtils queryPage(Map<String, Object> params) {
QueryWrapper<SpuInfoEntity> wrapper = new QueryWrapper<>();
// 处理 "key" 参数
String key = (String) params.get("key");
if (!StringUtils.isEmpty(key) && !"0".equalsIgnoreCase(key)) {
wrapper.and((w) -> w.eq("id", key).or().like("spu_name", key));
}
// 处理 "status" 参数
String status = (String) params.get("status");
if (!StringUtils.isEmpty(status) && !"0".equalsIgnoreCase(status)) {
wrapper.eq("publish_status", status);
}
// 处理 "brandId" 参数
String brandId = (String) params.get("brandId");
if (!StringUtils.isEmpty(brandId) && !"0".equalsIgnoreCase(brandId)) {
wrapper.eq("brand_id", brandId);
}
// 处理 "catelogId" 参数
String catelogId = (String) params.get("catelogId");
if (!StringUtils.isEmpty(catelogId) && !"0".equalsIgnoreCase(catelogId)) {
wrapper.eq("catalog_id", catelogId);
}
// 执行分页查询
IPage<SpuInfoEntity> page = this.page(
new Query<SpuInfoEntity>().getPage(params),
wrapper
);
return new PageUtils(page);
}
@Override
@Transactional
public void saveSpuInfo(SpuSaveVo spuSaveVo) {
// 保存SPU基本信息
SpuInfoEntity spuInfoEntity = new SpuInfoEntity();
BeanUtils.copyProperties(spuSaveVo,spuInfoEntity);
spuInfoEntity.setCreateTime(new Date());
spuInfoEntity.setUpdateTime(new Date());
this.saveBaseSpuInfo(spuInfoEntity);
// 保存SPU的描述图片
List<String> decript = spuSaveVo.getDecript();
SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();
spuInfoDescEntity.setSpuId(spuInfoEntity.getId());
spuInfoDescEntity.setDecript(String.join(",",decript));
spuInfoDescService.save(spuInfoDescEntity);
// 保存spu的图片集
List<String> images = spuSaveVo.getImages();
imagesService.saveImages(spuInfoEntity.getId(),images);
// 保存SPU的描述信息
List<BaseAttrs> baseAttrs = spuSaveVo.getBaseAttrs();
List<ProductAttrValueEntity> productAttrValueEntities = baseAttrs.stream().map(attr -> {
ProductAttrValueEntity productAttrValueEntity = new ProductAttrValueEntity();
productAttrValueEntity.setAttrId(attr.getAttrId());
// 获取名字并赋值
productAttrValueEntity.setAttrName(attrService.getById(attr.getAttrId()).getAttrName());
productAttrValueEntity.setAttrValue(attr.getAttrValues());
productAttrValueEntity.setQuickShow(attr.getShowDesc());
productAttrValueEntity.setSpuId(spuInfoEntity.getId());
return productAttrValueEntity;
}).collect(Collectors.toList());
productAttrValueService.saveProductAttr(productAttrValueEntities);
// 保存积分信息
Bounds bounds = spuSaveVo.getBounds();
SpuBoundTo spuBoundTo = new SpuBoundTo();
BeanUtils.copyProperties(bounds,spuBoundTo);
spuBoundTo.setSpuId(spuInfoEntity.getId());
R r = couponFeignService.saveSpuBounds(spuBoundTo);
if(r.getCode() != 0){
log.error("远程保存spu积分信息失败");
}
// 保存SPU的规格参数
// 保存当前spu对应的所有sku信息
List<Skus> skus = spuSaveVo.getSkus();
if(skus != null && skus.size() > 0){
skus.forEach(item -> {
String defaultImg = "";
for (Images image : item.getImages()) {
if(image.getDefaultImg() == 1){
defaultImg = image.getImgUrl();
}
}
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);
// sku的基本信息
skuInfoService.saveSkuInfo(skuInfoEntity);
Long skuId = skuInfoEntity.getSkuId();
List<SkuImagesEntity> collect = item.getImages().stream().map(img -> {
SkuImagesEntity skuImagesEntity = new SkuImagesEntity();
skuImagesEntity.setSkuId(skuId);
skuImagesEntity.setImgUrl(img.getImgUrl());
skuImagesEntity.setDefaultImg(img.getDefaultImg());
return skuImagesEntity;
}).filter(entity -> {
// 返回true就是有值有图片的
return !StringUtils.isEmpty(entity.getImgUrl());
}).collect(Collectors.toList());
// sku的图片信息
skuImagesService.saveBatch(collect);
// sku的销售属性信息
List<Attr> attrs = item.getAttr();
List<SkuSaleAttrValueEntity> skuSaleAttrValueEntities = attrs.stream().map(attr -> {
SkuSaleAttrValueEntity skuSaleAttrValueEntity = new SkuSaleAttrValueEntity();
BeanUtils.copyProperties(attr, skuSaleAttrValueEntity);
skuSaleAttrValueEntity.setSkuId(skuId);
return skuSaleAttrValueEntity;
}).collect(Collectors.toList());
skuSaleAttrValueService.saveBatch(skuSaleAttrValueEntities);
// sku的优惠满减信息
SkuReductionTo skuReductionTo = new SkuReductionTo();
BeanUtils.copyProperties(item,skuReductionTo);
skuReductionTo.setSkuId(skuId);
if(skuReductionTo.getFullCount() > 0 || skuReductionTo.getFullPrice().compareTo(new BigDecimal("0")) == 1){
R result = couponFeignService.saveSkuReduction(skuReductionTo);
if (result.getCode() != 0){
log.error("远程保存sku优惠信息失败");
}
}
});
}
}
@Override
public void saveBaseSpuInfo(SpuInfoEntity spuInfoEntity) {
this.baseMapper.insert(spuInfoEntity);
}
}
package com.alatus.mall.product.service.impl;
import com.alatus.common.to.SkuReductionTo;
import com.alatus.common.to.SpuBoundTo;
import com.alatus.common.utils.R;
import com.alatus.mall.product.entity.*;
import com.alatus.mall.product.feign.CouponFeignService;
import com.alatus.mall.product.service.*;
import com.alatus.mall.product.vo.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.alatus.common.utils.PageUtils;
import com.alatus.common.utils.Query;
import com.alatus.mall.product.dao.SpuInfoDao;
import org.springframework.transaction.annotation.Transactional;
@Service("spuInfoService")
public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> implements SpuInfoService {
@Autowired
private SpuInfoDescService spuInfoDescService;
@Autowired
private SpuImagesService imagesService;
@Autowired
private AttrService attrService;
@Autowired
private ProductAttrValueService productAttrValueService;
@Autowired
private SkuInfoService skuInfoService;
@Autowired
private SkuImagesService skuImagesService;
@Autowired
private SkuSaleAttrValueService skuSaleAttrValueService;
@Autowired
private CouponFeignService couponFeignService;
@Override
public PageUtils queryPage(Map<String, Object> params) {
QueryWrapper<SpuInfoEntity> wrapper = new QueryWrapper<>();
// 处理 "key" 参数
String key = (String) params.get("key");
if (!StringUtils.isEmpty(key) && !"0".equalsIgnoreCase(key)) {
wrapper.and((w) -> w.eq("id", key).or().like("spu_name", key));
}
// 处理 "status" 参数
String status = (String) params.get("status");
if (!StringUtils.isEmpty(status) && !"0".equalsIgnoreCase(status)) {
wrapper.eq("publish_status", status);
}
// 处理 "brandId" 参数
String brandId = (String) params.get("brandId");
if (!StringUtils.isEmpty(brandId) && !"0".equalsIgnoreCase(brandId)) {
wrapper.eq("brand_id", brandId);
}
// 处理 "catelogId" 参数
String catelogId = (String) params.get("catelogId");
if (!StringUtils.isEmpty(catelogId) && !"0".equalsIgnoreCase(catelogId)) {
wrapper.eq("catalog_id", catelogId);
}
// 执行分页查询
IPage<SpuInfoEntity> page = this.page(
new Query<SpuInfoEntity>().getPage(params),
wrapper
);
return new PageUtils(page);
}
@Override
@Transactional
public void saveSpuInfo(SpuSaveVo spuSaveVo) {
// 保存SPU基本信息
SpuInfoEntity spuInfoEntity = new SpuInfoEntity();
BeanUtils.copyProperties(spuSaveVo,spuInfoEntity);
spuInfoEntity.setCreateTime(new Date());
spuInfoEntity.setUpdateTime(new Date());
this.saveBaseSpuInfo(spuInfoEntity);
// 保存SPU的描述图片
List<String> decript = spuSaveVo.getDecript();
SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();
spuInfoDescEntity.setSpuId(spuInfoEntity.getId());
spuInfoDescEntity.setDecript(String.join(",",decript));
spuInfoDescService.save(spuInfoDescEntity);
// 保存spu的图片集
List<String> images = spuSaveVo.getImages();
imagesService.saveImages(spuInfoEntity.getId(),images);
// 保存SPU的描述信息
List<BaseAttrs> baseAttrs = spuSaveVo.getBaseAttrs();
List<ProductAttrValueEntity> productAttrValueEntities = baseAttrs.stream().map(attr -> {
ProductAttrValueEntity productAttrValueEntity = new ProductAttrValueEntity();
productAttrValueEntity.setAttrId(attr.getAttrId());
// 获取名字并赋值
productAttrValueEntity.setAttrName(attrService.getById(attr.getAttrId()).getAttrName());
productAttrValueEntity.setAttrValue(attr.getAttrValues());
productAttrValueEntity.setQuickShow(attr.getShowDesc());
productAttrValueEntity.setSpuId(spuInfoEntity.getId());
return productAttrValueEntity;
}).collect(Collectors.toList());
productAttrValueService.saveProductAttr(productAttrValueEntities);
// 保存积分信息
Bounds bounds = spuSaveVo.getBounds();
SpuBoundTo spuBoundTo = new SpuBoundTo();
BeanUtils.copyProperties(bounds,spuBoundTo);
spuBoundTo.setSpuId(spuInfoEntity.getId());
R r = couponFeignService.saveSpuBounds(spuBoundTo);
if(r.getCode() != 0){
log.error("远程保存spu积分信息失败");
}
// 保存SPU的规格参数
// 保存当前spu对应的所有sku信息
List<Skus> skus = spuSaveVo.getSkus();
if(skus != null && skus.size() > 0){
skus.forEach(item -> {
String defaultImg = "";
for (Images image : item.getImages()) {
if(image.getDefaultImg() == 1){
defaultImg = image.getImgUrl();
}
}
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);
// sku的基本信息
skuInfoService.saveSkuInfo(skuInfoEntity);
Long skuId = skuInfoEntity.getSkuId();
List<SkuImagesEntity> collect = item.getImages().stream().map(img -> {
SkuImagesEntity skuImagesEntity = new SkuImagesEntity();
skuImagesEntity.setSkuId(skuId);
skuImagesEntity.setImgUrl(img.getImgUrl());
skuImagesEntity.setDefaultImg(img.getDefaultImg());
return skuImagesEntity;
}).filter(entity -> {
// 返回true就是有值有图片的
return !StringUtils.isEmpty(entity.getImgUrl());
}).collect(Collectors.toList());
// sku的图片信息
skuImagesService.saveBatch(collect);
// sku的销售属性信息
List<Attr> attrs = item.getAttr();
List<SkuSaleAttrValueEntity> skuSaleAttrValueEntities = attrs.stream().map(attr -> {
SkuSaleAttrValueEntity skuSaleAttrValueEntity = new SkuSaleAttrValueEntity();
BeanUtils.copyProperties(attr, skuSaleAttrValueEntity);
skuSaleAttrValueEntity.setSkuId(skuId);
return skuSaleAttrValueEntity;
}).collect(Collectors.toList());
skuSaleAttrValueService.saveBatch(skuSaleAttrValueEntities);
// sku的优惠满减信息
SkuReductionTo skuReductionTo = new SkuReductionTo();
BeanUtils.copyProperties(item,skuReductionTo);
skuReductionTo.setSkuId(skuId);
if(skuReductionTo.getFullCount() > 0 || skuReductionTo.getFullPrice().compareTo(new BigDecimal("0")) == 1){
R result = couponFeignService.saveSkuReduction(skuReductionTo);
if (result.getCode() != 0){
log.error("远程保存sku优惠信息失败");
}
}
});
}
}
@Override
public void saveBaseSpuInfo(SpuInfoEntity spuInfoEntity) {
this.baseMapper.insert(spuInfoEntity);
}
}