diff --git a/src/main/java/com/hxtec/polaris/controller/CategoryController.java b/src/main/java/com/hxtec/polaris/controller/CategoryController.java index 2ad649ea1285dfc1dd0630b2117c0e4e526e289e..764f80a489bea752f6c1d831d32641d4d97b42ac 100644 --- a/src/main/java/com/hxtec/polaris/controller/CategoryController.java +++ b/src/main/java/com/hxtec/polaris/controller/CategoryController.java @@ -1,5 +1,6 @@ package com.hxtec.polaris.controller; +import com.hxtec.polaris.entity.ShopCategory; import com.hxtec.polaris.service.CategoryService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; diff --git a/src/main/java/com/hxtec/polaris/controller/ProductController.java b/src/main/java/com/hxtec/polaris/controller/ProductController.java index 909c095576bcd26e8ef9faa5811feffd6610e5c5..baac317a287829a88eb0614394a5c76bfddd9307 100644 --- a/src/main/java/com/hxtec/polaris/controller/ProductController.java +++ b/src/main/java/com/hxtec/polaris/controller/ProductController.java @@ -37,11 +37,14 @@ import java.util.Map; @Api(value = "/product", tags = "商品详情") public class ProductController { - @Autowired - private ProductService skuService; + private final ProductService skuService; - @Autowired - private StockService shopStockService; + private final StockService shopStockService; + + public ProductController(ProductService skuService, StockService shopStockService) { + this.skuService = skuService; + this.shopStockService = shopStockService; + } /** diff --git a/src/main/java/com/hxtec/polaris/controller/ProductManageController.java b/src/main/java/com/hxtec/polaris/controller/ProductManageController.java new file mode 100644 index 0000000000000000000000000000000000000000..49d806aa6e315bf7fa2b2219e6f246ae3d335cff --- /dev/null +++ b/src/main/java/com/hxtec/polaris/controller/ProductManageController.java @@ -0,0 +1,125 @@ +package com.hxtec.polaris.controller; + +import com.hxtec.polaris.commons.MapperUtils; +import com.hxtec.polaris.commons.api.vo.Result; +import com.hxtec.polaris.entity.*; +import com.hxtec.polaris.service.CategoryService; +import com.hxtec.polaris.service.ProductBaseService; +import com.hxtec.polaris.service.ProductService; +import com.hxtec.polaris.service.StockService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + * @author Caps.Xia + */ +@RestController +@RequestMapping("product") +@CrossOrigin +@Api(value = "/product", tags = "商品详情") +public class ProductManageController { + + private final ProductService skuService; + private final CategoryService categoryService; + + private final ProductBaseService spuService; + + public ProductManageController(ProductService skuService, CategoryService categoryService, ProductBaseService spuService) { + this.skuService = skuService; + this.categoryService = categoryService; + this.spuService = spuService; + } + + + @ApiOperation(value="保存商品信息", notes="商保存商品信息") + @PostMapping("saveSkuInfo") + public Result saveSkuInfo(@RequestBody ShopProductVariant skuInfo){ + // 处理默认图片 + String skuDefaultImg = skuInfo.getImage(); + if(StringUtils.isBlank(skuDefaultImg)){ + skuInfo.setImage(skuInfo.getSkuImageList().get(0).getImgUrl()); + } + skuService.saveSkuInfo(skuInfo); + return Result.ok("success"); + } + + @GetMapping("spuSaleAttrList") + @ResponseBody + public List spuSaleAttrList(Integer spuId){ + + List pmsProductSaleAttrs = spuService.spuSaleAttrList(spuId); + return pmsProductSaleAttrs; + } + + @RequestMapping("saveSpuInfo") + @ResponseBody + public String saveSpuInfo(@RequestBody ShopProductBase pmsProductInfo){ + + spuService.saveSpuInfo(pmsProductInfo); + + return "success"; + } + + @RequestMapping("spuList") + @ResponseBody + public List spuList(String catalogId){ + + List pmsProductInfos = spuService.spuList(catalogId); + + return pmsProductInfos; + } + + + /** + * 根据二级分类获取三级分类 + * @param catalog2Id + * @return + */ + @ApiOperation("根据二级分类获取三级分类") + @GetMapping("catalog2Id") + @ResponseBody + public List getCatalog3(String catalog2Id){ + + List catalog3s = categoryService.getCatalog3(catalog2Id); + return catalog3s; + } + + + /** + * 根据一级分类获取二级分类 + * @param catalog1Id + * @return + */ + @ApiOperation("根据一级分类获取二级分类") + @GetMapping("getCatalog2") + @ResponseBody + public List getCatalog2(String catalog1Id){ + + List catalog2s = categoryService.getCatalog2(catalog1Id); + return catalog2s; + } + + /** + * 获取一级分类 + * @return + */ + @ApiOperation("获取一级分类") + @GetMapping("getCatalog1") + @ResponseBody + public List getCatalog1(){ + + List catalog1s = categoryService.getCatalog1(); + return catalog1s; + } + +} diff --git a/src/main/java/com/hxtec/polaris/entity/ShopProductBase.java b/src/main/java/com/hxtec/polaris/entity/ShopProductBase.java index c4e44b196ab5600ec649711bc5a0b6e4a4369983..54e6024a702111e34630aa2554ad2601343445c1 100644 --- a/src/main/java/com/hxtec/polaris/entity/ShopProductBase.java +++ b/src/main/java/com/hxtec/polaris/entity/ShopProductBase.java @@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import java.io.Serializable; import java.util.Date; +import java.util.List; import javax.persistence.*; import lombok.Data; @@ -87,5 +88,8 @@ public class ShopProductBase implements Serializable { @ApiModelProperty(value = "备用字段3") private String comment3; + @Transient + private List spuSaleAttrList; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/src/main/java/com/hxtec/polaris/service/CategoryService.java b/src/main/java/com/hxtec/polaris/service/CategoryService.java index d766e5fbb2bb4100c47e9b0765d7caf4f1332c6d..02f86008696280cdd706ae9e4c95b4217470c517 100644 --- a/src/main/java/com/hxtec/polaris/service/CategoryService.java +++ b/src/main/java/com/hxtec/polaris/service/CategoryService.java @@ -1,4 +1,6 @@ package com.hxtec.polaris.service; +import com.hxtec.polaris.entity.ShopCategory; + import javax.servlet.http.HttpServletRequest; import java.util.List; /** * @Author yonyong @@ -50,4 +52,24 @@ public interface CategoryService { * @return */ Object selectTree(String condition); + + /** + * 根据二级目录获取三级目录 + * @param catalog2Id + * @return + */ + List getCatalog3(String catalog2Id); + + /** + * 根据一级目录获取二级目录 + * @param catalog1Id + * @return + */ + List getCatalog2(String catalog1Id); + + /** + * 获取一级目录 + * @return + */ + List getCatalog1(); } diff --git a/src/main/java/com/hxtec/polaris/service/ProductBaseService.java b/src/main/java/com/hxtec/polaris/service/ProductBaseService.java new file mode 100644 index 0000000000000000000000000000000000000000..c395cbeb165354727cebe6df752b2adb5c9a777e --- /dev/null +++ b/src/main/java/com/hxtec/polaris/service/ProductBaseService.java @@ -0,0 +1,29 @@ +package com.hxtec.polaris.service; + +import com.hxtec.polaris.entity.ShopProductBase; +import com.hxtec.polaris.entity.ShopProductSaleAttr; + +import java.util.List; + +public interface ProductBaseService { + + /** + * 根据spuId获取销售属性信息 + * @param spuId + * @return + */ + List spuSaleAttrList(Integer spuId); + + /** + * 保存spu信息 + * @param pmsProductInfo + */ + void saveSpuInfo(ShopProductBase pmsProductInfo); + + /** + * 显示分类列表下的spu + * @param catalogId + * @return + */ + List spuList(String catalogId); +} diff --git a/src/main/java/com/hxtec/polaris/service/impl/CategoryServiceImpl.java b/src/main/java/com/hxtec/polaris/service/impl/CategoryServiceImpl.java index 381ec6020ff36d43d73c16c4a9a31c02dba5009f..c1ac7d19e59f53a0b623d37483353d7fa5436e73 100644 --- a/src/main/java/com/hxtec/polaris/service/impl/CategoryServiceImpl.java +++ b/src/main/java/com/hxtec/polaris/service/impl/CategoryServiceImpl.java @@ -14,6 +14,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import tk.mybatis.mapper.entity.Example; import javax.annotation.Resource; import javax.servlet.ServletContext; @@ -171,6 +172,30 @@ public class CategoryServiceImpl implements CategoryService { return Result.ok(mapList); } + @Override + public List getCatalog3(String catalog2Id) { + Example example=new Example(ShopCategory.class); + example.createCriteria().andEqualTo("parentId",catalog2Id) + .andEqualTo("isDelete","N"); + return shopCategoryMapper.selectByExample(example); + } + + @Override + public List getCatalog2(String catalog1Id) { + Example example=new Example(ShopCategory.class); + example.createCriteria().andEqualTo("parentId",catalog1Id) + .andEqualTo("isDelete","N"); + return shopCategoryMapper.selectByExample(example); + } + + @Override + public List getCatalog1() { + Example example=new Example(ShopCategory.class); + example.createCriteria().andIsNull("parentId") + .andEqualTo("isDelete","N"); + return shopCategoryMapper.selectByExample(example); + } + /** * ShopCategory实例赋值 * @param pid diff --git a/src/main/java/com/hxtec/polaris/service/impl/OrderServiceImpl.java b/src/main/java/com/hxtec/polaris/service/impl/OrderServiceImpl.java index e44142a5f41510955e62ade058c1fd179930620d..0bf3b4096074b582fabba2ad6f69a96ed48610a0 100644 --- a/src/main/java/com/hxtec/polaris/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/hxtec/polaris/service/impl/OrderServiceImpl.java @@ -71,8 +71,6 @@ public class OrderServiceImpl implements OrderService{ @Resource private ShopCartItemMapper cartItemMapper; - @Autowired - private ShopProductVariantMapper productVariantMapper; @Override public Object getOrder(Integer state, Integer pageNow, Integer rows) { diff --git a/src/main/java/com/hxtec/polaris/service/impl/ProductBaseServiceImpl.java b/src/main/java/com/hxtec/polaris/service/impl/ProductBaseServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..2426058b06e512a8bcf07b5090bdfb1c46a76f7a --- /dev/null +++ b/src/main/java/com/hxtec/polaris/service/impl/ProductBaseServiceImpl.java @@ -0,0 +1,73 @@ +package com.hxtec.polaris.service.impl; + +import com.hxtec.polaris.entity.ShopProductBase; +import com.hxtec.polaris.entity.ShopProductSaleAttr; +import com.hxtec.polaris.entity.ShopProductSaleAttrValue; +import com.hxtec.polaris.entity.ShopProductVariant; +import com.hxtec.polaris.mapper.ShopProductBaseMapper; +import com.hxtec.polaris.mapper.ShopProductSaleAttrMapper; +import com.hxtec.polaris.mapper.ShopProductSaleAttrValueMapper; +import com.hxtec.polaris.service.ProductBaseService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import tk.mybatis.mapper.entity.Example; + +import java.util.List; + +@Service +public class ProductBaseServiceImpl implements ProductBaseService { + private final ShopProductBaseMapper spuMapper; + + private final ShopProductSaleAttrMapper productSaleAttrMapper; + + private final ShopProductSaleAttrValueMapper productSaleAttrValueMapper; + + public ProductBaseServiceImpl(ShopProductBaseMapper spuMapper, ShopProductSaleAttrMapper productSaleAttrMapper, ShopProductSaleAttrValueMapper productSaleAttrValueMapper) { + this.spuMapper = spuMapper; + this.productSaleAttrMapper = productSaleAttrMapper; + this.productSaleAttrValueMapper = productSaleAttrValueMapper; + } + + + @Override + public List spuSaleAttrList(Integer spuId) { + Example example=new Example(ShopProductSaleAttr.class); + example.createCriteria().andEqualTo("productId",spuId); + List shopProductSaleAttrs = productSaleAttrMapper.selectByExample(example); + shopProductSaleAttrs.forEach(saleAttr->{ + ShopProductSaleAttrValue saleAttrValue=new ShopProductSaleAttrValue(); + saleAttrValue.setSaleAttrId(saleAttr.getId()); + saleAttrValue.setProductId(spuId); + List saleAttrValues = productSaleAttrValueMapper.select(saleAttrValue); + saleAttr.setSpuSaleAttrValueList(saleAttrValues); + }); + return shopProductSaleAttrs; + } + + @Override + public void saveSpuInfo(ShopProductBase pmsProductInfo) { + spuMapper.insertSelective(pmsProductInfo); + Integer productId = pmsProductInfo.getSpu(); + // 保存销售属性信息 + List spuSaleAttrList = pmsProductInfo.getSpuSaleAttrList(); + for (ShopProductSaleAttr pmsProductSaleAttr : spuSaleAttrList) { + pmsProductSaleAttr.setProductId(productId); + productSaleAttrMapper.insertSelective(pmsProductSaleAttr); + + // 保存销售属性值 + List spuSaleAttrValueList = pmsProductSaleAttr.getSpuSaleAttrValueList(); + for (ShopProductSaleAttrValue pmsProductSaleAttrValue : spuSaleAttrValueList) { + pmsProductSaleAttrValue.setProductId(productId); + productSaleAttrValueMapper.insertSelective(pmsProductSaleAttrValue); + } + } + + } + + @Override + public List spuList(String catalogId) { + Example example=new Example(ShopProductVariant.class); + example.createCriteria().andEqualTo("categoryId",catalogId); + return spuMapper.selectByExample(example); + } +} diff --git a/src/main/java/com/hxtec/polaris/service/impl/ProductServiceImpl.java b/src/main/java/com/hxtec/polaris/service/impl/ProductServiceImpl.java index 5fee52541e7efe2a3214d876da407ce1239c2dc1..0361460e89326d9ffb1f482aaa98fac2badc668e 100644 --- a/src/main/java/com/hxtec/polaris/service/impl/ProductServiceImpl.java +++ b/src/main/java/com/hxtec/polaris/service/impl/ProductServiceImpl.java @@ -27,23 +27,24 @@ import java.util.List; @Service public class ProductServiceImpl implements ProductService { - @Autowired - private ShopProductVariantMapper skuMapper; + private final ShopProductVariantMapper skuMapper; - @Autowired - private ShopProductBaseMapper spumapper; + private final ShopProductBaseMapper spumapper; - @Autowired - private ShopProductSaleAttrMapper productSaleAttrMapper; + private final ShopProductSaleAttrMapper productSaleAttrMapper; - @Autowired - private ShopProductVariantImageMapper imageMapper; + private final ShopProductVariantImageMapper imageMapper; - @Autowired - private ShopProductVariantAttrValueMapper variantAttrValueMapper; + private final ShopProductVariantAttrValueMapper variantAttrValueMapper; - @Autowired - private RedisTemplate redisTemplate; + + public ProductServiceImpl(ShopProductVariantMapper skuMapper, ShopProductBaseMapper spumapper, ShopProductSaleAttrMapper productSaleAttrMapper, ShopProductVariantImageMapper imageMapper, ShopProductVariantAttrValueMapper variantAttrValueMapper, RedisTemplate redisTemplate) { + this.skuMapper = skuMapper; + this.spumapper = spumapper; + this.productSaleAttrMapper = productSaleAttrMapper; + this.imageMapper = imageMapper; + this.variantAttrValueMapper = variantAttrValueMapper; + } /** * 根据sku从数据库获取带图片信息的商品信息