package com.alatus.mall.product.web;
import com.alatus.mall.product.service.SkuInfoService;
import com.alatus.mall.product.vo.SkuItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@Controller
public class ItemController {
@Autowired
private SkuInfoService skuInfoService;
@GetMapping("/{skuId}.html")
public String skuItem(@PathVariable("skuId") Long skuId){
SkuItemVo skuItemVo = skuInfoService.item(skuId);
return "item";
}
}
package com.alatus.mall.product.web;
import com.alatus.mall.product.service.SkuInfoService;
import com.alatus.mall.product.vo.SkuItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@Controller
public class ItemController {
@Autowired
private SkuInfoService skuInfoService;
@GetMapping("/{skuId}.html")
public String skuItem(@PathVariable("skuId") Long skuId){
SkuItemVo skuItemVo = skuInfoService.item(skuId);
return "item";
}
}
package com.alatus.mall.product.service;
import com.alatus.mall.product.vo.SkuItemVo;
import com.baomidou.mybatisplus.extension.service.IService;
import com.alatus.common.utils.PageUtils;
import com.alatus.mall.product.entity.SkuInfoEntity;
import java.util.List;
import java.util.Map;
/**
* sku信息
*
* @author Alatus
* @email 1571345941@qq.com
* @date 2024-06-08 16:06:24
*/
public interface SkuInfoService extends IService<SkuInfoEntity> {
PageUtils queryPage(Map<String, Object> params);
void saveSkuInfo(SkuInfoEntity skuInfoEntity);
List<SkuInfoEntity> getSkusBySpuId(Long spuId);
SkuItemVo item(Long skuId);
}
package com.alatus.mall.product.service;
import com.alatus.mall.product.vo.SkuItemVo;
import com.baomidou.mybatisplus.extension.service.IService;
import com.alatus.common.utils.PageUtils;
import com.alatus.mall.product.entity.SkuInfoEntity;
import java.util.List;
import java.util.Map;
/**
* sku信息
*
* @author Alatus
* @email 1571345941@qq.com
* @date 2024-06-08 16:06:24
*/
public interface SkuInfoService extends IService<SkuInfoEntity> {
PageUtils queryPage(Map<String, Object> params);
void saveSkuInfo(SkuInfoEntity skuInfoEntity);
List<SkuInfoEntity> getSkusBySpuId(Long spuId);
SkuItemVo item(Long skuId);
}
package com.alatus.mall.product.vo;
import com.alatus.mall.product.entity.SkuImagesEntity;
import com.alatus.mall.product.entity.SkuInfoEntity;
import com.alatus.mall.product.entity.SpuInfoDescEntity;
import lombok.Data;
import java.util.List;
@Data
public class SkuItemVo {
// sku基本信息
private SkuInfoEntity info;
// sku图片信息
private List<SkuImagesEntity> images;
// spu销售组合信息
private List<SkuItemSaleAttrVo> saleAttr;
// spu的介绍信息
private SpuInfoDescEntity desc;
// spu规格参数信息
private List<SpuItemAttrGroupVo> groupAttrs;
@Data
public static class SkuItemSaleAttrVo{
private Long attrId;
private String attrName;
private List<String> attrValues;
}
@Data
public static class SpuItemAttrGroupVo{
private String groupName;
private List<SpuBaseAttrVo> attrs;
}
@Data
public static class SpuBaseAttrVo{
private String attrName;
private String attrValue;
}
}
package com.alatus.mall.product.vo;
import com.alatus.mall.product.entity.SkuImagesEntity;
import com.alatus.mall.product.entity.SkuInfoEntity;
import com.alatus.mall.product.entity.SpuInfoDescEntity;
import lombok.Data;
import java.util.List;
@Data
public class SkuItemVo {
// sku基本信息
private SkuInfoEntity info;
// sku图片信息
private List<SkuImagesEntity> images;
// spu销售组合信息
private List<SkuItemSaleAttrVo> saleAttr;
// spu的介绍信息
private SpuInfoDescEntity desc;
// spu规格参数信息
private List<SpuItemAttrGroupVo> groupAttrs;
@Data
public static class SkuItemSaleAttrVo{
private Long attrId;
private String attrName;
private List<String> attrValues;
}
@Data
public static class SpuItemAttrGroupVo{
private String groupName;
private List<SpuBaseAttrVo> attrs;
}
@Data
public static class SpuBaseAttrVo{
private String attrName;
private String attrValue;
}
}
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 com.alatus.mall.product.vo.SkuItemVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
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);
}
@Override
public List<SkuInfoEntity> getSkusBySpuId(Long spuId) {
return this.list(new QueryWrapper<SkuInfoEntity>().eq("spu_id",spuId));
}
@Override
public SkuItemVo item(Long skuId) {
return null;
}
}
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 com.alatus.mall.product.vo.SkuItemVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
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);
}
@Override
public List<SkuInfoEntity> getSkusBySpuId(Long spuId) {
return this.list(new QueryWrapper<SkuInfoEntity>().eq("spu_id",spuId));
}
@Override
public SkuItemVo item(Long skuId) {
return null;
}
}