商品分类及属性接口修改
This commit is contained in:
parent
96fc15e003
commit
424cbe0df5
@ -2,6 +2,7 @@ package com.macro.mall.controller;
|
|||||||
|
|
||||||
import com.macro.mall.dto.CommonResult;
|
import com.macro.mall.dto.CommonResult;
|
||||||
import com.macro.mall.dto.PmsProductAttributeParam;
|
import com.macro.mall.dto.PmsProductAttributeParam;
|
||||||
|
import com.macro.mall.dto.ProductAttrInfo;
|
||||||
import com.macro.mall.model.PmsProductAttribute;
|
import com.macro.mall.model.PmsProductAttribute;
|
||||||
import com.macro.mall.service.PmsProductAttributeService;
|
import com.macro.mall.service.PmsProductAttributeService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@ -83,4 +84,12 @@ public class PmsProductAttributeController {
|
|||||||
return new CommonResult().failed();
|
return new CommonResult().failed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("根据商品分类的id获取商品属性及属性分类")
|
||||||
|
@RequestMapping(value = "/attrInfo/{productCategoryId}",method = RequestMethod.GET)
|
||||||
|
@ResponseBody
|
||||||
|
public Object getAttrInfo(@PathVariable Long productCategoryId){
|
||||||
|
List<ProductAttrInfo> productAttrInfoList = productAttributeService.getProductAttrInfo(productCategoryId);
|
||||||
|
return new CommonResult().success(productAttrInfoList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import java.util.List;
|
|||||||
* Created by macro on 2018/4/26.
|
* Created by macro on 2018/4/26.
|
||||||
*/
|
*/
|
||||||
@Controller
|
@Controller
|
||||||
@Api(tags = "PmsProductCategoryController",description = "商品分类管理")
|
@Api(tags = "PmsProductCategoryController", description = "商品分类管理")
|
||||||
@RequestMapping("/productCategory")
|
@RequestMapping("/productCategory")
|
||||||
public class PmsProductCategoryController {
|
public class PmsProductCategoryController {
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -30,9 +30,9 @@ public class PmsProductCategoryController {
|
|||||||
@ApiOperation("添加产品分类")
|
@ApiOperation("添加产品分类")
|
||||||
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Object create(@Validated @RequestBody PmsProductCategoryParam pmsProductCategoryParam,
|
public Object create(@Validated @RequestBody PmsProductCategoryParam productCategoryParam,
|
||||||
BindingResult result) {
|
BindingResult result) {
|
||||||
int count = productCategoryService.create(pmsProductCategoryParam);
|
int count = productCategoryService.create(productCategoryParam);
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
return new CommonResult().success(count);
|
return new CommonResult().success(count);
|
||||||
} else {
|
} else {
|
||||||
@ -45,9 +45,9 @@ public class PmsProductCategoryController {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Object update(@PathVariable Long id,
|
public Object update(@PathVariable Long id,
|
||||||
@Validated
|
@Validated
|
||||||
@RequestBody PmsProductCategoryParam pmsProductCategoryParam,
|
@RequestBody PmsProductCategoryParam productCategoryParam,
|
||||||
BindingResult result) {
|
BindingResult result) {
|
||||||
int count = productCategoryService.update(id, pmsProductCategoryParam);
|
int count = productCategoryService.update(id, productCategoryParam);
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
return new CommonResult().success(count);
|
return new CommonResult().success(count);
|
||||||
} else {
|
} else {
|
||||||
@ -59,8 +59,8 @@ public class PmsProductCategoryController {
|
|||||||
@RequestMapping(value = "/list/{parentId}", method = RequestMethod.GET)
|
@RequestMapping(value = "/list/{parentId}", method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Object getList(@PathVariable Long parentId,
|
public Object getList(@PathVariable Long parentId,
|
||||||
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
|
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
|
||||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
|
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
|
||||||
List<PmsProductCategory> productCategoryList = productCategoryService.getList(parentId, pageSize, pageNum);
|
List<PmsProductCategory> productCategoryList = productCategoryService.getList(parentId, pageSize, pageNum);
|
||||||
return new CommonResult().pageSuccess(productCategoryList);
|
return new CommonResult().pageSuccess(productCategoryList);
|
||||||
}
|
}
|
||||||
@ -84,4 +84,28 @@ public class PmsProductCategoryController {
|
|||||||
return new CommonResult().failed();
|
return new CommonResult().failed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("修改导航栏显示状态")
|
||||||
|
@RequestMapping(value = "/update/navStatus", method = RequestMethod.POST)
|
||||||
|
@ResponseBody
|
||||||
|
public Object updateNavStatus(@RequestParam("ids") List<Long> 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<Long> ids, @RequestParam("showStatus") Integer showStatus) {
|
||||||
|
int count = productCategoryService.updateShowStatus(ids, showStatus);
|
||||||
|
if (count > 0) {
|
||||||
|
return new CommonResult().success(count);
|
||||||
|
} else {
|
||||||
|
return new CommonResult().failed();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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<ProductAttrInfo> getProductAttrInfo(@Param("id") Long productCategoryId);
|
||||||
|
}
|
@ -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<PmsProductCategoryAttributeRelation> productCategoryAttributeRelationList);
|
||||||
|
}
|
@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
|
|||||||
import org.hibernate.validator.constraints.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
|
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加更新产品分类的参数
|
* 添加更新产品分类的参数
|
||||||
@ -33,6 +34,8 @@ public class PmsProductCategoryParam {
|
|||||||
private String keywords;
|
private String keywords;
|
||||||
@ApiModelProperty("描述")
|
@ApiModelProperty("描述")
|
||||||
private String description;
|
private String description;
|
||||||
|
@ApiModelProperty("产品相关筛选属性集合")
|
||||||
|
private List<Long> productAttributeIdList;
|
||||||
|
|
||||||
public Long getParentId() {
|
public Long getParentId() {
|
||||||
return parentId;
|
return parentId;
|
||||||
@ -105,4 +108,12 @@ public class PmsProductCategoryParam {
|
|||||||
public void setDescription(String description) {
|
public void setDescription(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Long> getProductAttributeIdList() {
|
||||||
|
return productAttributeIdList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProductAttributeIdList(List<Long> productAttributeIdList) {
|
||||||
|
this.productAttributeIdList = productAttributeIdList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.macro.mall.service;
|
package com.macro.mall.service;
|
||||||
|
|
||||||
import com.macro.mall.dto.PmsProductAttributeParam;
|
import com.macro.mall.dto.PmsProductAttributeParam;
|
||||||
|
import com.macro.mall.dto.ProductAttrInfo;
|
||||||
import com.macro.mall.model.PmsProductAttribute;
|
import com.macro.mall.model.PmsProductAttribute;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@ -37,4 +38,6 @@ public interface PmsProductAttributeService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
int delete(List<Long> ids);
|
int delete(List<Long> ids);
|
||||||
|
|
||||||
|
List<ProductAttrInfo> getProductAttrInfo(Long productCategoryId);
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,19 @@ import java.util.List;
|
|||||||
* Created by macro on 2018/4/26.
|
* Created by macro on 2018/4/26.
|
||||||
*/
|
*/
|
||||||
public interface PmsProductCategoryService {
|
public interface PmsProductCategoryService {
|
||||||
|
@Transactional
|
||||||
int create(PmsProductCategoryParam pmsProductCategoryParam);
|
int create(PmsProductCategoryParam pmsProductCategoryParam);
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
int update(Long id, PmsProductCategoryParam pmsProductCategoryParam);
|
int update(Long id, PmsProductCategoryParam pmsProductCategoryParam);
|
||||||
|
|
||||||
List<PmsProductCategory> getList(Long parentId, Integer pageSize, Integer pageNum);
|
List<PmsProductCategory> getList(Long parentId, Integer pageSize, Integer pageNum);
|
||||||
|
|
||||||
int delete(Long id);
|
int delete(Long id);
|
||||||
|
|
||||||
PmsProductCategory getItem(Long id);
|
PmsProductCategory getItem(Long id);
|
||||||
|
|
||||||
|
int updateNavStatus(List<Long> ids, Integer navStatus);
|
||||||
|
|
||||||
|
int updateShowStatus(List<Long> ids, Integer showStatus);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.macro.mall.service.impl;
|
package com.macro.mall.service.impl;
|
||||||
|
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.macro.mall.dao.PmsProductAttributeDao;
|
||||||
import com.macro.mall.dto.PmsProductAttributeParam;
|
import com.macro.mall.dto.PmsProductAttributeParam;
|
||||||
|
import com.macro.mall.dto.ProductAttrInfo;
|
||||||
import com.macro.mall.mapper.PmsProductAttributeCategoryMapper;
|
import com.macro.mall.mapper.PmsProductAttributeCategoryMapper;
|
||||||
import com.macro.mall.mapper.PmsProductAttributeMapper;
|
import com.macro.mall.mapper.PmsProductAttributeMapper;
|
||||||
import com.macro.mall.model.PmsProductAttribute;
|
import com.macro.mall.model.PmsProductAttribute;
|
||||||
@ -24,6 +26,8 @@ public class PmsProductAttributeServiceImpl implements PmsProductAttributeServic
|
|||||||
private PmsProductAttributeMapper productAttributeMapper;
|
private PmsProductAttributeMapper productAttributeMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private PmsProductAttributeCategoryMapper productAttributeCategoryMapper;
|
private PmsProductAttributeCategoryMapper productAttributeCategoryMapper;
|
||||||
|
@Autowired
|
||||||
|
private PmsProductAttributeDao productAttributeDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PmsProductAttribute> getList(Long cid, Integer type, Integer pageSize, Integer pageNum) {
|
public List<PmsProductAttribute> getList(Long cid, Integer type, Integer pageSize, Integer pageNum) {
|
||||||
@ -89,4 +93,9 @@ public class PmsProductAttributeServiceImpl implements PmsProductAttributeServic
|
|||||||
productAttributeCategoryMapper.updateByPrimaryKey(pmsProductAttributeCategory);
|
productAttributeCategoryMapper.updateByPrimaryKey(pmsProductAttributeCategory);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ProductAttrInfo> getProductAttrInfo(Long productCategoryId) {
|
||||||
|
return productAttributeDao.getProductAttrInfo(productCategoryId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
package com.macro.mall.service.impl;
|
package com.macro.mall.service.impl;
|
||||||
|
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.macro.mall.dao.PmsProductCategoryAttributeRelationDao;
|
||||||
import com.macro.mall.dto.PmsProductCategoryParam;
|
import com.macro.mall.dto.PmsProductCategoryParam;
|
||||||
import com.macro.mall.mapper.PmsProductCategoryMapper;
|
import com.macro.mall.mapper.PmsProductCategoryMapper;
|
||||||
import com.macro.mall.mapper.PmsProductMapper;
|
import com.macro.mall.mapper.PmsProductMapper;
|
||||||
import com.macro.mall.model.PmsProduct;
|
import com.macro.mall.model.*;
|
||||||
import com.macro.mall.model.PmsProductCategory;
|
|
||||||
import com.macro.mall.model.PmsProductCategoryExample;
|
|
||||||
import com.macro.mall.model.PmsProductExample;
|
|
||||||
import com.macro.mall.service.PmsProductCategoryService;
|
import com.macro.mall.service.PmsProductCategoryService;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,6 +25,8 @@ public class PmsProductCategoryServiceImpl implements PmsProductCategoryService
|
|||||||
private PmsProductCategoryMapper productCategoryMapper;
|
private PmsProductCategoryMapper productCategoryMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private PmsProductMapper productMapper;
|
private PmsProductMapper productMapper;
|
||||||
|
@Autowired
|
||||||
|
private PmsProductCategoryAttributeRelationDao pmsProductCategoryAttributeRelationDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int create(PmsProductCategoryParam pmsProductCategoryParam) {
|
public int create(PmsProductCategoryParam pmsProductCategoryParam) {
|
||||||
@ -33,7 +35,20 @@ public class PmsProductCategoryServiceImpl implements PmsProductCategoryService
|
|||||||
BeanUtils.copyProperties(pmsProductCategoryParam, productCategory);
|
BeanUtils.copyProperties(pmsProductCategoryParam, productCategory);
|
||||||
//没有父分类时为一级分类
|
//没有父分类时为一级分类
|
||||||
setCategoryLevel(productCategory);
|
setCategoryLevel(productCategory);
|
||||||
return productCategoryMapper.insertSelective(productCategory);
|
int count = productCategoryMapper.insertSelective(productCategory);
|
||||||
|
//创建筛选属性关联
|
||||||
|
List<Long> productAttributeIdList = pmsProductCategoryParam.getProductAttributeIdList();
|
||||||
|
if(!CollectionUtils.isEmpty(productAttributeIdList)){
|
||||||
|
List<PmsProductCategoryAttributeRelation> 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
|
@Override
|
||||||
@ -70,6 +85,24 @@ public class PmsProductCategoryServiceImpl implements PmsProductCategoryService
|
|||||||
return productCategoryMapper.selectByPrimaryKey(id);
|
return productCategoryMapper.selectByPrimaryKey(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateNavStatus(List<Long> 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<Long> 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
|
* 根据分类的parentId设置分类的level
|
||||||
*/
|
*/
|
||||||
|
15
mall-admin/src/main/resources/dao/PmsProductAttributeDao.xml
Normal file
15
mall-admin/src/main/resources/dao/PmsProductAttributeDao.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.macro.mall.dao.PmsProductAttributeDao">
|
||||||
|
<select id="getProductAttrInfo" resultType="com.macro.mall.dto.ProductAttrInfo">
|
||||||
|
SELECT
|
||||||
|
pa.id attributeId,
|
||||||
|
pac.id attributeCategoryId
|
||||||
|
FROM
|
||||||
|
pms_product_category_attribute_relation pcar
|
||||||
|
LEFT JOIN pms_product_attribute pa ON pa.id = pcar.product_attribute_id
|
||||||
|
LEFT JOIN pms_product_attribute_category pac ON pa.product_attribute_category_id = pac.id
|
||||||
|
WHERE
|
||||||
|
pcar.product_category_id = #{id}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.macro.mall.dao.PmsProductCategoryAttributeRelationDao">
|
||||||
|
<!--批量新增回写主键支持-->
|
||||||
|
<insert id="insertList">
|
||||||
|
INSERT INTO pms_product_category_attribute_relation (product_category_id, product_attribute_id) VALUES
|
||||||
|
<foreach collection="list" separator="," item="item" index="index">
|
||||||
|
(#{item.productCategoryId,jdbcType=BIGINT},
|
||||||
|
#{item.productAttributeId,jdbcType=BIGINT})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
Loading…
x
Reference in New Issue
Block a user