Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
mall
Commits
8e48c839
Commit
8e48c839
authored
May 24, 2018
by
zhh
Browse files
商品分类修改完善
parent
424cbe0d
Changes
7
Hide whitespace changes
Inline
Side-by-side
mall-admin/src/main/java/com/macro/mall/controller/PmsProductAttributeCategoryController.java
View file @
8e48c839
package
com.macro.mall.controller
;
import
com.macro.mall.dto.CommonResult
;
import
com.macro.mall.dto.PmsProductAttributeCategoryItem
;
import
com.macro.mall.model.PmsProductAttributeCategory
;
import
com.macro.mall.service.PmsProductAttributeCategoryService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -18,7 +17,7 @@ import java.util.List;
* Created by macro on 2018/4/26.
*/
@Controller
@Api
(
tags
=
"PmsProductAttributeCategoryController"
,
description
=
"商品属性分类管理"
)
@Api
(
tags
=
"PmsProductAttributeCategoryController"
,
description
=
"商品属性分类管理"
)
@RequestMapping
(
"/productAttribute/category"
)
public
class
PmsProductAttributeCategoryController
{
@Autowired
...
...
@@ -71,8 +70,16 @@ public class PmsProductAttributeCategoryController {
@ApiOperation
(
"分页获取所有商品属性分类"
)
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
getList
(
@RequestParam
(
defaultValue
=
"5"
)
Integer
pageSize
,
@RequestParam
(
defaultValue
=
"1"
)
Integer
pageNum
)
{
List
<
PmsProductAttributeCategory
>
productAttributeCategoryList
=
productAttributeCategoryService
.
getList
(
pageSize
,
pageNum
);
public
Object
getList
(
@RequestParam
(
defaultValue
=
"5"
)
Integer
pageSize
,
@RequestParam
(
defaultValue
=
"1"
)
Integer
pageNum
)
{
List
<
PmsProductAttributeCategory
>
productAttributeCategoryList
=
productAttributeCategoryService
.
getList
(
pageSize
,
pageNum
);
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
);
}
}
mall-admin/src/main/java/com/macro/mall/dao/PmsProductAttributeCategoryDao.java
0 → 100644
View file @
8e48c839
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
();
}
mall-admin/src/main/java/com/macro/mall/dto/PmsProductAttributeCategoryItem.java
0 → 100644
View file @
8e48c839
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
;
}
}
mall-admin/src/main/java/com/macro/mall/service/PmsProductAttributeCategoryService.java
View file @
8e48c839
package
com.macro.mall.service
;
import
com.macro.mall.dto.PmsProductAttributeCategoryItem
;
import
com.macro.mall.model.PmsProductAttributeCategory
;
import
java.util.List
;
...
...
@@ -18,4 +19,6 @@ public interface PmsProductAttributeCategoryService {
PmsProductAttributeCategory
getItem
(
Long
id
);
List
<
PmsProductAttributeCategory
>
getList
(
Integer
pageSize
,
Integer
pageNum
);
List
<
PmsProductAttributeCategoryItem
>
getListWithAttr
();
}
mall-admin/src/main/java/com/macro/mall/service/impl/PmsProductAttributeCategoryServiceImpl.java
View file @
8e48c839
package
com.macro.mall.service.impl
;
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.model.PmsProductAttributeCategory
;
import
com.macro.mall.model.PmsProductAttributeCategoryExample
;
...
...
@@ -18,6 +20,8 @@ import java.util.List;
public
class
PmsProductAttributeCategoryServiceImpl
implements
PmsProductAttributeCategoryService
{
@Autowired
private
PmsProductAttributeCategoryMapper
productAttributeCategoryMapper
;
@Autowired
private
PmsProductAttributeCategoryDao
productAttributeCategoryDao
;
@Override
public
int
create
(
String
name
)
{
...
...
@@ -49,4 +53,9 @@ public class PmsProductAttributeCategoryServiceImpl implements PmsProductAttribu
PageHelper
.
startPage
(
pageNum
,
pageSize
);
return
productAttributeCategoryMapper
.
selectByExample
(
new
PmsProductAttributeCategoryExample
());
}
@Override
public
List
<
PmsProductAttributeCategoryItem
>
getListWithAttr
()
{
return
productAttributeCategoryDao
.
getListWithAttr
();
}
}
mall-admin/src/main/java/com/macro/mall/service/impl/PmsProductCategoryServiceImpl.java
View file @
8e48c839
...
...
@@ -3,6 +3,7 @@ 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.PmsProductCategoryAttributeRelationMapper
;
import
com.macro.mall.mapper.PmsProductCategoryMapper
;
import
com.macro.mall.mapper.PmsProductMapper
;
import
com.macro.mall.model.*
;
...
...
@@ -26,8 +27,9 @@ public class PmsProductCategoryServiceImpl implements PmsProductCategoryService
@Autowired
private
PmsProductMapper
productMapper
;
@Autowired
private
PmsProductCategoryAttributeRelationDao
pmsProductCategoryAttributeRelationDao
;
private
PmsProductCategoryAttributeRelationDao
productCategoryAttributeRelationDao
;
@Autowired
private
PmsProductCategoryAttributeRelationMapper
productCategoryAttributeRelationMapper
;
@Override
public
int
create
(
PmsProductCategoryParam
pmsProductCategoryParam
)
{
PmsProductCategory
productCategory
=
new
PmsProductCategory
();
...
...
@@ -39,18 +41,27 @@ public class PmsProductCategoryServiceImpl implements PmsProductCategoryService
//创建筛选属性关联
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
);
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
<>();
for
(
Long
productAttrId
:
productAttributeIdList
)
{
PmsProductCategoryAttributeRelation
relation
=
new
PmsProductCategoryAttributeRelation
();
relation
.
setProductAttributeId
(
productAttrId
);
relation
.
setProductCategoryId
(
productCategoryId
);
relationList
.
add
(
relation
);
}
productCategoryAttributeRelationDao
.
insertList
(
relationList
);
}
@Override
public
int
update
(
Long
id
,
PmsProductCategoryParam
pmsProductCategoryParam
)
{
PmsProductCategory
productCategory
=
new
PmsProductCategory
();
...
...
@@ -63,6 +74,17 @@ public class PmsProductCategoryServiceImpl implements PmsProductCategoryService
PmsProductExample
example
=
new
PmsProductExample
();
example
.
createCriteria
().
andProductCategoryIdEqualTo
(
id
);
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
);
}
...
...
mall-admin/src/main/resources/dao/PmsProductAttributeCategoryDao.xml
0 → 100644
View file @
8e48c839
<?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>
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment