diff --git a/mall-admin/src/main/java/com/macro/mall/controller/PmsProductAttributeController.java b/mall-admin/src/main/java/com/macro/mall/controller/PmsProductAttributeController.java index 936bb1a..a4b782e 100644 --- a/mall-admin/src/main/java/com/macro/mall/controller/PmsProductAttributeController.java +++ b/mall-admin/src/main/java/com/macro/mall/controller/PmsProductAttributeController.java @@ -2,6 +2,7 @@ package com.macro.mall.controller; import com.macro.mall.dto.CommonResult; import com.macro.mall.dto.PmsProductAttributeParam; +import com.macro.mall.dto.ProductAttrInfo; import com.macro.mall.model.PmsProductAttribute; import com.macro.mall.service.PmsProductAttributeService; import io.swagger.annotations.Api; @@ -83,4 +84,12 @@ public class PmsProductAttributeController { return new CommonResult().failed(); } } + + @ApiOperation("根据商品分类的id获取商品属性及属性分类") + @RequestMapping(value = "/attrInfo/{productCategoryId}",method = RequestMethod.GET) + @ResponseBody + public Object getAttrInfo(@PathVariable Long productCategoryId){ + List productAttrInfoList = productAttributeService.getProductAttrInfo(productCategoryId); + return new CommonResult().success(productAttrInfoList); + } } diff --git a/mall-admin/src/main/java/com/macro/mall/controller/PmsProductCategoryController.java b/mall-admin/src/main/java/com/macro/mall/controller/PmsProductCategoryController.java index bea4557..a378e8c 100644 --- a/mall-admin/src/main/java/com/macro/mall/controller/PmsProductCategoryController.java +++ b/mall-admin/src/main/java/com/macro/mall/controller/PmsProductCategoryController.java @@ -21,7 +21,7 @@ import java.util.List; * Created by macro on 2018/4/26. */ @Controller -@Api(tags = "PmsProductCategoryController",description = "商品分类管理") +@Api(tags = "PmsProductCategoryController", description = "商品分类管理") @RequestMapping("/productCategory") public class PmsProductCategoryController { @Autowired @@ -30,9 +30,9 @@ public class PmsProductCategoryController { @ApiOperation("添加产品分类") @RequestMapping(value = "/create", method = RequestMethod.POST) @ResponseBody - public Object create(@Validated @RequestBody PmsProductCategoryParam pmsProductCategoryParam, + public Object create(@Validated @RequestBody PmsProductCategoryParam productCategoryParam, BindingResult result) { - int count = productCategoryService.create(pmsProductCategoryParam); + int count = productCategoryService.create(productCategoryParam); if (count > 0) { return new CommonResult().success(count); } else { @@ -45,9 +45,9 @@ public class PmsProductCategoryController { @ResponseBody public Object update(@PathVariable Long id, @Validated - @RequestBody PmsProductCategoryParam pmsProductCategoryParam, + @RequestBody PmsProductCategoryParam productCategoryParam, BindingResult result) { - int count = productCategoryService.update(id, pmsProductCategoryParam); + int count = productCategoryService.update(id, productCategoryParam); if (count > 0) { return new CommonResult().success(count); } else { @@ -59,8 +59,8 @@ public class PmsProductCategoryController { @RequestMapping(value = "/list/{parentId}", method = RequestMethod.GET) @ResponseBody public Object getList(@PathVariable Long parentId, - @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize, - @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) { + @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize, + @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) { List productCategoryList = productCategoryService.getList(parentId, pageSize, pageNum); return new CommonResult().pageSuccess(productCategoryList); } @@ -84,4 +84,28 @@ public class PmsProductCategoryController { return new CommonResult().failed(); } } + + @ApiOperation("修改导航栏显示状态") + @RequestMapping(value = "/update/navStatus", method = RequestMethod.POST) + @ResponseBody + public Object updateNavStatus(@RequestParam("ids") List ids, @RequestParam("navStatus") Integer navStatus) { + int count = productCategoryService.updateNavStatus(ids, navStatus); + if (count > 0) { + return new CommonResult().success(count); + } else { + return new CommonResult().failed(); + } + } + + @ApiOperation("修改显示状态") + @RequestMapping(value = "/update/showStatus", method = RequestMethod.POST) + @ResponseBody + public Object updateShowStatus(@RequestParam("ids") List ids, @RequestParam("showStatus") Integer showStatus) { + int count = productCategoryService.updateShowStatus(ids, showStatus); + if (count > 0) { + return new CommonResult().success(count); + } else { + return new CommonResult().failed(); + } + } } diff --git a/mall-admin/src/main/java/com/macro/mall/dao/PmsProductAttributeDao.java b/mall-admin/src/main/java/com/macro/mall/dao/PmsProductAttributeDao.java new file mode 100644 index 0000000..dc52219 --- /dev/null +++ b/mall-admin/src/main/java/com/macro/mall/dao/PmsProductAttributeDao.java @@ -0,0 +1,14 @@ +package com.macro.mall.dao; + +import com.macro.mall.dto.ProductAttrInfo; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 自定义商品属性Dao + * Created by macro on 2018/5/23. + */ +public interface PmsProductAttributeDao { + List getProductAttrInfo(@Param("id") Long productCategoryId); +} diff --git a/mall-admin/src/main/java/com/macro/mall/dao/PmsProductCategoryAttributeRelationDao.java b/mall-admin/src/main/java/com/macro/mall/dao/PmsProductCategoryAttributeRelationDao.java new file mode 100644 index 0000000..276d8fb --- /dev/null +++ b/mall-admin/src/main/java/com/macro/mall/dao/PmsProductCategoryAttributeRelationDao.java @@ -0,0 +1,14 @@ +package com.macro.mall.dao; + +import com.macro.mall.model.PmsProductCategoryAttributeRelation; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 自定义商品分类和属性关系Dao + * Created by macro on 2018/5/23. + */ +public interface PmsProductCategoryAttributeRelationDao { + int insertList(@Param("list") List productCategoryAttributeRelationList); +} diff --git a/mall-admin/src/main/java/com/macro/mall/dto/PmsProductCategoryParam.java b/mall-admin/src/main/java/com/macro/mall/dto/PmsProductCategoryParam.java index c7c3c6c..12f0ff8 100644 --- a/mall-admin/src/main/java/com/macro/mall/dto/PmsProductCategoryParam.java +++ b/mall-admin/src/main/java/com/macro/mall/dto/PmsProductCategoryParam.java @@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty; import org.hibernate.validator.constraints.NotEmpty; import javax.validation.constraints.Min; +import java.util.List; /** * 添加更新产品分类的参数 @@ -33,6 +34,8 @@ public class PmsProductCategoryParam { private String keywords; @ApiModelProperty("描述") private String description; + @ApiModelProperty("产品相关筛选属性集合") + private List productAttributeIdList; public Long getParentId() { return parentId; @@ -105,4 +108,12 @@ public class PmsProductCategoryParam { public void setDescription(String description) { this.description = description; } + + public List getProductAttributeIdList() { + return productAttributeIdList; + } + + public void setProductAttributeIdList(List productAttributeIdList) { + this.productAttributeIdList = productAttributeIdList; + } } diff --git a/mall-admin/src/main/java/com/macro/mall/dto/ProductAttrInfo.java b/mall-admin/src/main/java/com/macro/mall/dto/ProductAttrInfo.java new file mode 100644 index 0000000..6bed624 --- /dev/null +++ b/mall-admin/src/main/java/com/macro/mall/dto/ProductAttrInfo.java @@ -0,0 +1,27 @@ +package com.macro.mall.dto; + + +/** + * 商品分类对应属性信息 + * Created by macro on 2018/5/23. + */ +public class ProductAttrInfo { + private Long attributeId; + private Long attributeCategoryId; + + public Long getAttributeId() { + return attributeId; + } + + public void setAttributeId(Long attributeId) { + this.attributeId = attributeId; + } + + public Long getAttributeCategoryId() { + return attributeCategoryId; + } + + public void setAttributeCategoryId(Long attributeCategoryId) { + this.attributeCategoryId = attributeCategoryId; + } +} diff --git a/mall-admin/src/main/java/com/macro/mall/service/PmsProductAttributeService.java b/mall-admin/src/main/java/com/macro/mall/service/PmsProductAttributeService.java index c0c34db..c69e3ec 100644 --- a/mall-admin/src/main/java/com/macro/mall/service/PmsProductAttributeService.java +++ b/mall-admin/src/main/java/com/macro/mall/service/PmsProductAttributeService.java @@ -1,6 +1,7 @@ package com.macro.mall.service; import com.macro.mall.dto.PmsProductAttributeParam; +import com.macro.mall.dto.ProductAttrInfo; import com.macro.mall.model.PmsProductAttribute; import org.springframework.transaction.annotation.Transactional; @@ -37,4 +38,6 @@ public interface PmsProductAttributeService { @Transactional int delete(List ids); + + List getProductAttrInfo(Long productCategoryId); } diff --git a/mall-admin/src/main/java/com/macro/mall/service/PmsProductCategoryService.java b/mall-admin/src/main/java/com/macro/mall/service/PmsProductCategoryService.java index 7f235a4..25f6767 100644 --- a/mall-admin/src/main/java/com/macro/mall/service/PmsProductCategoryService.java +++ b/mall-admin/src/main/java/com/macro/mall/service/PmsProductCategoryService.java @@ -13,12 +13,19 @@ import java.util.List; * Created by macro on 2018/4/26. */ public interface PmsProductCategoryService { + @Transactional int create(PmsProductCategoryParam pmsProductCategoryParam); + @Transactional int update(Long id, PmsProductCategoryParam pmsProductCategoryParam); List getList(Long parentId, Integer pageSize, Integer pageNum); int delete(Long id); + PmsProductCategory getItem(Long id); + + int updateNavStatus(List ids, Integer navStatus); + + int updateShowStatus(List ids, Integer showStatus); } diff --git a/mall-admin/src/main/java/com/macro/mall/service/impl/PmsProductAttributeServiceImpl.java b/mall-admin/src/main/java/com/macro/mall/service/impl/PmsProductAttributeServiceImpl.java index 7707039..7024a66 100644 --- a/mall-admin/src/main/java/com/macro/mall/service/impl/PmsProductAttributeServiceImpl.java +++ b/mall-admin/src/main/java/com/macro/mall/service/impl/PmsProductAttributeServiceImpl.java @@ -1,7 +1,9 @@ package com.macro.mall.service.impl; import com.github.pagehelper.PageHelper; +import com.macro.mall.dao.PmsProductAttributeDao; import com.macro.mall.dto.PmsProductAttributeParam; +import com.macro.mall.dto.ProductAttrInfo; import com.macro.mall.mapper.PmsProductAttributeCategoryMapper; import com.macro.mall.mapper.PmsProductAttributeMapper; import com.macro.mall.model.PmsProductAttribute; @@ -24,6 +26,8 @@ public class PmsProductAttributeServiceImpl implements PmsProductAttributeServic private PmsProductAttributeMapper productAttributeMapper; @Autowired private PmsProductAttributeCategoryMapper productAttributeCategoryMapper; + @Autowired + private PmsProductAttributeDao productAttributeDao; @Override public List getList(Long cid, Integer type, Integer pageSize, Integer pageNum) { @@ -89,4 +93,9 @@ public class PmsProductAttributeServiceImpl implements PmsProductAttributeServic productAttributeCategoryMapper.updateByPrimaryKey(pmsProductAttributeCategory); return count; } + + @Override + public List getProductAttrInfo(Long productCategoryId) { + return productAttributeDao.getProductAttrInfo(productCategoryId); + } } diff --git a/mall-admin/src/main/java/com/macro/mall/service/impl/PmsProductCategoryServiceImpl.java b/mall-admin/src/main/java/com/macro/mall/service/impl/PmsProductCategoryServiceImpl.java index 80e9b44..c5839be 100644 --- a/mall-admin/src/main/java/com/macro/mall/service/impl/PmsProductCategoryServiceImpl.java +++ b/mall-admin/src/main/java/com/macro/mall/service/impl/PmsProductCategoryServiceImpl.java @@ -1,18 +1,18 @@ package com.macro.mall.service.impl; import com.github.pagehelper.PageHelper; +import com.macro.mall.dao.PmsProductCategoryAttributeRelationDao; import com.macro.mall.dto.PmsProductCategoryParam; import com.macro.mall.mapper.PmsProductCategoryMapper; import com.macro.mall.mapper.PmsProductMapper; -import com.macro.mall.model.PmsProduct; -import com.macro.mall.model.PmsProductCategory; -import com.macro.mall.model.PmsProductCategoryExample; -import com.macro.mall.model.PmsProductExample; +import com.macro.mall.model.*; import com.macro.mall.service.PmsProductCategoryService; +import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; /** @@ -25,6 +25,8 @@ public class PmsProductCategoryServiceImpl implements PmsProductCategoryService private PmsProductCategoryMapper productCategoryMapper; @Autowired private PmsProductMapper productMapper; + @Autowired + private PmsProductCategoryAttributeRelationDao pmsProductCategoryAttributeRelationDao; @Override public int create(PmsProductCategoryParam pmsProductCategoryParam) { @@ -33,7 +35,20 @@ public class PmsProductCategoryServiceImpl implements PmsProductCategoryService BeanUtils.copyProperties(pmsProductCategoryParam, productCategory); //没有父分类时为一级分类 setCategoryLevel(productCategory); - return productCategoryMapper.insertSelective(productCategory); + int count = productCategoryMapper.insertSelective(productCategory); + //创建筛选属性关联 + List productAttributeIdList = pmsProductCategoryParam.getProductAttributeIdList(); + if(!CollectionUtils.isEmpty(productAttributeIdList)){ + List relationList = new ArrayList<>(); + for (Long productAttrId : productAttributeIdList) { + PmsProductCategoryAttributeRelation relation = new PmsProductCategoryAttributeRelation(); + relation.setProductAttributeId(productAttrId); + relation.setProductCategoryId(productCategory.getId()); + relationList.add(relation); + } + pmsProductCategoryAttributeRelationDao.insertList(relationList); + } + return count; } @Override @@ -70,6 +85,24 @@ public class PmsProductCategoryServiceImpl implements PmsProductCategoryService return productCategoryMapper.selectByPrimaryKey(id); } + @Override + public int updateNavStatus(List ids, Integer navStatus) { + PmsProductCategory productCategory = new PmsProductCategory(); + productCategory.setNavStatus(navStatus); + PmsProductCategoryExample example = new PmsProductCategoryExample(); + example.createCriteria().andIdIn(ids); + return productCategoryMapper.updateByExampleSelective(productCategory, example); + } + + @Override + public int updateShowStatus(List ids, Integer showStatus) { + PmsProductCategory productCategory = new PmsProductCategory(); + productCategory.setShowStatus(showStatus); + PmsProductCategoryExample example = new PmsProductCategoryExample(); + example.createCriteria().andIdIn(ids); + return productCategoryMapper.updateByExampleSelective(productCategory, example); + } + /** * 根据分类的parentId设置分类的level */ diff --git a/mall-admin/src/main/resources/dao/PmsProductAttributeDao.xml b/mall-admin/src/main/resources/dao/PmsProductAttributeDao.xml new file mode 100644 index 0000000..3a4d713 --- /dev/null +++ b/mall-admin/src/main/resources/dao/PmsProductAttributeDao.xml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/mall-admin/src/main/resources/dao/PmsProductCategoryAttributeRelationDao.xml b/mall-admin/src/main/resources/dao/PmsProductCategoryAttributeRelationDao.xml new file mode 100644 index 0000000..e357163 --- /dev/null +++ b/mall-admin/src/main/resources/dao/PmsProductCategoryAttributeRelationDao.xml @@ -0,0 +1,12 @@ + + + + + + INSERT INTO pms_product_category_attribute_relation (product_category_id, product_attribute_id) VALUES + + (#{item.productCategoryId,jdbcType=BIGINT}, + #{item.productAttributeId,jdbcType=BIGINT}) + + + \ No newline at end of file