商品分类修改完善
This commit is contained in:
parent
424cbe0df5
commit
8e48c839ff
@ -1,12 +1,11 @@
|
|||||||
package com.macro.mall.controller;
|
package com.macro.mall.controller;
|
||||||
|
|
||||||
import com.macro.mall.dto.CommonResult;
|
import com.macro.mall.dto.CommonResult;
|
||||||
|
import com.macro.mall.dto.PmsProductAttributeCategoryItem;
|
||||||
import com.macro.mall.model.PmsProductAttributeCategory;
|
import com.macro.mall.model.PmsProductAttributeCategory;
|
||||||
import com.macro.mall.service.PmsProductAttributeCategoryService;
|
import com.macro.mall.service.PmsProductAttributeCategoryService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -75,4 +74,12 @@ public class PmsProductAttributeCategoryController {
|
|||||||
List<PmsProductAttributeCategory> productAttributeCategoryList = productAttributeCategoryService.getList(pageSize, pageNum);
|
List<PmsProductAttributeCategory> productAttributeCategoryList = productAttributeCategoryService.getList(pageSize, pageNum);
|
||||||
return new CommonResult().pageSuccess(productAttributeCategoryList);
|
return new CommonResult().pageSuccess(productAttributeCategoryList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("获取所有商品属性分类及其下属性")
|
||||||
|
@RequestMapping(value = "/list/withAttr", method = RequestMethod.GET)
|
||||||
|
@ResponseBody
|
||||||
|
public Object getListWithAttr() {
|
||||||
|
List<PmsProductAttributeCategoryItem> productAttributeCategoryResultList = productAttributeCategoryService.getListWithAttr();
|
||||||
|
return new CommonResult().success(productAttributeCategoryResultList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.macro.mall.dao;
|
||||||
|
|
||||||
|
import com.macro.mall.dto.PmsProductAttributeCategoryItem;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义商品属性分类Dao
|
||||||
|
* Created by macro on 2018/5/24.
|
||||||
|
*/
|
||||||
|
public interface PmsProductAttributeCategoryDao {
|
||||||
|
List<PmsProductAttributeCategoryItem> getListWithAttr();
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.macro.mall.dto;
|
||||||
|
|
||||||
|
import com.macro.mall.model.PmsProductAttribute;
|
||||||
|
import com.macro.mall.model.PmsProductAttributeCategory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 包含有分类下属性的dto
|
||||||
|
* Created by macro on 2018/5/24.
|
||||||
|
*/
|
||||||
|
public class PmsProductAttributeCategoryItem extends PmsProductAttributeCategory {
|
||||||
|
private List<PmsProductAttribute> productAttributeList;
|
||||||
|
|
||||||
|
public List<PmsProductAttribute> getProductAttributeList() {
|
||||||
|
return productAttributeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProductAttributeList(List<PmsProductAttribute> productAttributeList) {
|
||||||
|
this.productAttributeList = productAttributeList;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.macro.mall.service;
|
package com.macro.mall.service;
|
||||||
|
|
||||||
|
import com.macro.mall.dto.PmsProductAttributeCategoryItem;
|
||||||
import com.macro.mall.model.PmsProductAttributeCategory;
|
import com.macro.mall.model.PmsProductAttributeCategory;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -18,4 +19,6 @@ public interface PmsProductAttributeCategoryService {
|
|||||||
PmsProductAttributeCategory getItem(Long id);
|
PmsProductAttributeCategory getItem(Long id);
|
||||||
|
|
||||||
List<PmsProductAttributeCategory> getList(Integer pageSize, Integer pageNum);
|
List<PmsProductAttributeCategory> getList(Integer pageSize, Integer pageNum);
|
||||||
|
|
||||||
|
List<PmsProductAttributeCategoryItem> getListWithAttr();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
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.PmsProductAttributeCategoryDao;
|
||||||
|
import com.macro.mall.dto.PmsProductAttributeCategoryItem;
|
||||||
import com.macro.mall.mapper.PmsProductAttributeCategoryMapper;
|
import com.macro.mall.mapper.PmsProductAttributeCategoryMapper;
|
||||||
import com.macro.mall.model.PmsProductAttributeCategory;
|
import com.macro.mall.model.PmsProductAttributeCategory;
|
||||||
import com.macro.mall.model.PmsProductAttributeCategoryExample;
|
import com.macro.mall.model.PmsProductAttributeCategoryExample;
|
||||||
@ -18,6 +20,8 @@ import java.util.List;
|
|||||||
public class PmsProductAttributeCategoryServiceImpl implements PmsProductAttributeCategoryService {
|
public class PmsProductAttributeCategoryServiceImpl implements PmsProductAttributeCategoryService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private PmsProductAttributeCategoryMapper productAttributeCategoryMapper;
|
private PmsProductAttributeCategoryMapper productAttributeCategoryMapper;
|
||||||
|
@Autowired
|
||||||
|
private PmsProductAttributeCategoryDao productAttributeCategoryDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int create(String name) {
|
public int create(String name) {
|
||||||
@ -49,4 +53,9 @@ public class PmsProductAttributeCategoryServiceImpl implements PmsProductAttribu
|
|||||||
PageHelper.startPage(pageNum,pageSize);
|
PageHelper.startPage(pageNum,pageSize);
|
||||||
return productAttributeCategoryMapper.selectByExample(new PmsProductAttributeCategoryExample());
|
return productAttributeCategoryMapper.selectByExample(new PmsProductAttributeCategoryExample());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PmsProductAttributeCategoryItem> getListWithAttr() {
|
||||||
|
return productAttributeCategoryDao.getListWithAttr();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ 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.dao.PmsProductCategoryAttributeRelationDao;
|
||||||
import com.macro.mall.dto.PmsProductCategoryParam;
|
import com.macro.mall.dto.PmsProductCategoryParam;
|
||||||
|
import com.macro.mall.mapper.PmsProductCategoryAttributeRelationMapper;
|
||||||
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.*;
|
import com.macro.mall.model.*;
|
||||||
@ -26,8 +27,9 @@ public class PmsProductCategoryServiceImpl implements PmsProductCategoryService
|
|||||||
@Autowired
|
@Autowired
|
||||||
private PmsProductMapper productMapper;
|
private PmsProductMapper productMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private PmsProductCategoryAttributeRelationDao pmsProductCategoryAttributeRelationDao;
|
private PmsProductCategoryAttributeRelationDao productCategoryAttributeRelationDao;
|
||||||
|
@Autowired
|
||||||
|
private PmsProductCategoryAttributeRelationMapper productCategoryAttributeRelationMapper;
|
||||||
@Override
|
@Override
|
||||||
public int create(PmsProductCategoryParam pmsProductCategoryParam) {
|
public int create(PmsProductCategoryParam pmsProductCategoryParam) {
|
||||||
PmsProductCategory productCategory = new PmsProductCategory();
|
PmsProductCategory productCategory = new PmsProductCategory();
|
||||||
@ -39,16 +41,25 @@ public class PmsProductCategoryServiceImpl implements PmsProductCategoryService
|
|||||||
//创建筛选属性关联
|
//创建筛选属性关联
|
||||||
List<Long> productAttributeIdList = pmsProductCategoryParam.getProductAttributeIdList();
|
List<Long> productAttributeIdList = pmsProductCategoryParam.getProductAttributeIdList();
|
||||||
if(!CollectionUtils.isEmpty(productAttributeIdList)){
|
if(!CollectionUtils.isEmpty(productAttributeIdList)){
|
||||||
|
insertRelationList(productCategory.getId(), productAttributeIdList);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量插入商品分类与筛选属性关系表
|
||||||
|
* @param productCategoryId 商品分类id
|
||||||
|
* @param productAttributeIdList 相关商品筛选属性id集合
|
||||||
|
*/
|
||||||
|
private void insertRelationList(Long productCategoryId, List<Long> productAttributeIdList) {
|
||||||
List<PmsProductCategoryAttributeRelation> relationList = new ArrayList<>();
|
List<PmsProductCategoryAttributeRelation> relationList = new ArrayList<>();
|
||||||
for (Long productAttrId : productAttributeIdList) {
|
for (Long productAttrId : productAttributeIdList) {
|
||||||
PmsProductCategoryAttributeRelation relation = new PmsProductCategoryAttributeRelation();
|
PmsProductCategoryAttributeRelation relation = new PmsProductCategoryAttributeRelation();
|
||||||
relation.setProductAttributeId(productAttrId);
|
relation.setProductAttributeId(productAttrId);
|
||||||
relation.setProductCategoryId(productCategory.getId());
|
relation.setProductCategoryId(productCategoryId);
|
||||||
relationList.add(relation);
|
relationList.add(relation);
|
||||||
}
|
}
|
||||||
pmsProductCategoryAttributeRelationDao.insertList(relationList);
|
productCategoryAttributeRelationDao.insertList(relationList);
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -63,6 +74,17 @@ public class PmsProductCategoryServiceImpl implements PmsProductCategoryService
|
|||||||
PmsProductExample example = new PmsProductExample();
|
PmsProductExample example = new PmsProductExample();
|
||||||
example.createCriteria().andProductCategoryIdEqualTo(id);
|
example.createCriteria().andProductCategoryIdEqualTo(id);
|
||||||
productMapper.updateByExampleSelective(product,example);
|
productMapper.updateByExampleSelective(product,example);
|
||||||
|
//同时更新筛选属性的信息
|
||||||
|
if(!CollectionUtils.isEmpty(pmsProductCategoryParam.getProductAttributeIdList())){
|
||||||
|
PmsProductCategoryAttributeRelationExample relationExample = new PmsProductCategoryAttributeRelationExample();
|
||||||
|
relationExample.createCriteria().andProductCategoryIdEqualTo(id);
|
||||||
|
productCategoryAttributeRelationMapper.deleteByExample(relationExample);
|
||||||
|
insertRelationList(id,pmsProductCategoryParam.getProductAttributeIdList());
|
||||||
|
}else{
|
||||||
|
PmsProductCategoryAttributeRelationExample relationExample = new PmsProductCategoryAttributeRelationExample();
|
||||||
|
relationExample.createCriteria().andProductCategoryIdEqualTo(id);
|
||||||
|
productCategoryAttributeRelationMapper.deleteByExample(relationExample);
|
||||||
|
}
|
||||||
return productCategoryMapper.updateByPrimaryKeySelective(productCategory);
|
return productCategoryMapper.updateByPrimaryKeySelective(productCategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
<?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.PmsProductAttributeCategoryDao">
|
||||||
|
<resultMap id="getListWithAttrMap" type="com.macro.mall.dto.PmsProductAttributeCategoryItem" extends="com.macro.mall.mapper.PmsProductAttributeCategoryMapper.BaseResultMap">
|
||||||
|
<collection property="productAttributeList" columnPrefix="attr_" resultMap="com.macro.mall.mapper.PmsProductAttributeMapper.BaseResultMap">
|
||||||
|
</collection>
|
||||||
|
</resultMap>
|
||||||
|
<select id="getListWithAttr" resultMap="getListWithAttrMap">
|
||||||
|
SELECT
|
||||||
|
pac.id,
|
||||||
|
pac.name,
|
||||||
|
pa.id attr_id,
|
||||||
|
pa.name attr_name
|
||||||
|
FROM
|
||||||
|
pms_product_attribute_category pac
|
||||||
|
LEFT JOIN pms_product_attribute pa ON pac.id = pa.product_attribute_category_id
|
||||||
|
AND pa.type=1;
|
||||||
|
</select>
|
||||||
|
</mapper>
|
Loading…
x
Reference in New Issue
Block a user