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
353d7311
Commit
353d7311
authored
Apr 24, 2018
by
zhh
Browse files
添加商品属性接口
parent
da20e10f
Changes
6
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
353d7311
...
...
@@ -14,7 +14,7 @@ Thymeleaf | 模板引擎
Swagger-UI | 文档生产工具
Hibernator-Validator | 验证框架
Vue | 前端框架
AdminLte
| 前端模版
Element
| 前端模版
### 框架搭建
功能 | 完成
...
...
@@ -31,16 +31,20 @@ crud操作demo | ✔
SpringAOP通用日志处理 | ✔
SpringAOP通用验证失败结果返回 | ✔
CommonResult对通用返回结果进行封装 | ✔
SpringSecurity登录改为Restful形式 |
SpringSecurity登录改为Restful形式 |
✔
JWT登录、注册、获取token | ✔
### 功能完善
#### 后台登录功能
#### 后台登录功能(完成)
-
后台用户注册功能
-
后台用户登录后获取token
-
刷新token功能
#### 商品管理
##### 商品属性分类管理
##### 商品属性分类管理
(完成)
-
添加商品属性分类(名称)
-
分页查询全部商品属性分类
...
...
@@ -48,7 +52,7 @@ JWT登录、注册、获取token | ✔
-
修改单个属性分类名称
-
查询单个属性分类信息
##### 商品属性管理
##### 商品属性管理
(完成)
-
根据分类查询属性列表或参数列表(分页,支持类型)
-
添加商品属性
...
...
@@ -57,6 +61,8 @@ JWT登录、注册、获取token | ✔
-
批量删除商品属性
-
分页查询全部商品属性
##### 商品管理
#### 促销管理
#### 内容管理
...
...
mall-admin/src/main/java/com/macro/mall/controller/PmsProductAttributeController.java
View file @
353d7311
package
com.macro.mall.controller
;
import
com.macro.mall.dto.CommonResult
;
import
com.macro.mall.dto.PmsProductAttributeParam
;
import
com.macro.mall.model.PmsProductAttribute
;
import
com.macro.mall.service.PmsProductAttributeService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
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.RequestMapping
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
* 商品属性管理Controller
*/
@Controller
@Api
(
tags
=
"PmsProductAttributeController"
,
description
=
"商品属性管理"
)
@Api
(
tags
=
"PmsProductAttributeController"
,
description
=
"商品属性管理"
)
@RequestMapping
(
"/productAttribute"
)
public
class
PmsProductAttributeController
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
PmsProductAttributeController
.
class
);
@Autowired
private
PmsProductAttributeService
productAttributeService
;
@ApiOperation
(
"根据分类查询属性列表或参数列表"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"type"
,
value
=
"0表示属性,1表示参数"
,
required
=
true
,
paramType
=
"query"
,
dataType
=
"integer"
)})
@RequestMapping
(
value
=
"/list/{cid}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
getList
(
@PathVariable
Long
cid
,
@RequestParam
(
value
=
"type"
)
Integer
type
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"5"
)
Integer
pageSize
,
@RequestParam
(
value
=
"pageNum"
,
defaultValue
=
"1"
)
Integer
pageNum
)
{
List
<
PmsProductAttribute
>
productAttributeList
=
productAttributeService
.
getList
(
cid
,
type
,
pageSize
,
pageNum
);
return
new
CommonResult
().
pageSuccess
(
productAttributeList
);
}
@ApiOperation
(
"添加商品属性信息"
)
@RequestMapping
(
value
=
"/create"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
create
(
@RequestBody
PmsProductAttributeParam
productAttributeParam
,
BindingResult
bindingResult
)
{
int
count
=
productAttributeService
.
create
(
productAttributeParam
);
if
(
count
>
0
)
{
return
new
CommonResult
().
success
(
count
);
}
else
{
return
new
CommonResult
().
failed
();
}
}
@ApiOperation
(
"修改商品属性信息"
)
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
update
(
@PathVariable
Long
id
,
@RequestBody
PmsProductAttributeParam
productAttributeParam
,
BindingResult
bindingResult
){
int
count
=
productAttributeService
.
update
(
id
,
productAttributeParam
);
if
(
count
>
0
)
{
return
new
CommonResult
().
success
(
count
);
}
else
{
return
new
CommonResult
().
failed
();
}
}
@ApiOperation
(
"查询单个商品属性"
)
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
getItem
(
@PathVariable
Long
id
){
PmsProductAttribute
productAttribute
=
productAttributeService
.
getItem
(
id
);
return
new
CommonResult
().
success
(
productAttribute
);
}
@ApiOperation
(
"批量删除商品属性"
)
@RequestMapping
(
value
=
"/delete"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
delete
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
){
int
count
=
productAttributeService
.
delete
(
ids
);
if
(
count
>
0
)
{
return
new
CommonResult
().
success
(
count
);
}
else
{
return
new
CommonResult
().
failed
();
}
}
}
mall-admin/src/main/java/com/macro/mall/dto/PmsProductAttributeParam.java
0 → 100644
View file @
353d7311
package
com.macro.mall.dto
;
import
com.macro.mall.validator.FlagValidator
;
import
io.swagger.annotations.ApiModelProperty
;
import
org.hibernate.validator.constraints.NotEmpty
;
/**
* 商品属性参数
*/
public
class
PmsProductAttributeParam
{
@ApiModelProperty
(
"属性分类ID"
)
@NotEmpty
(
message
=
"属性分类不能为空"
)
private
Long
productAttributeCategoryId
;
@ApiModelProperty
(
"属性名称"
)
@NotEmpty
(
message
=
"属性名称不能为空"
)
private
String
name
;
@ApiModelProperty
(
"属性选择类型:0->唯一;1->单选;2->多选"
)
@FlagValidator
({
"0"
,
"1"
,
"2"
})
private
Integer
selectType
;
@ApiModelProperty
(
"属性录入方式:0->手工录入;1->从列表中选取"
)
@FlagValidator
({
"0"
,
"1"
})
private
Integer
inputType
;
@ApiModelProperty
(
"可选值列表,以逗号隔开"
)
private
String
inputList
;
private
Integer
sort
;
@ApiModelProperty
(
"分类筛选样式:0->普通;1->颜色"
)
@FlagValidator
({
"0"
,
"1"
})
private
Integer
filterType
;
@ApiModelProperty
(
"检索类型;0->不需要进行检索;1->关键字检索;2->范围检索"
)
@FlagValidator
({
"0"
,
"1"
,
"2"
})
private
Integer
searchType
;
@ApiModelProperty
(
"相同属性产品是否关联;0->不关联;1->关联"
)
@FlagValidator
({
"0"
,
"1"
})
private
Integer
relatedStatus
;
@ApiModelProperty
(
"是否支持手动新增;0->不支持;1->支持"
)
@FlagValidator
({
"0"
,
"1"
})
private
Integer
handAddStatus
;
@ApiModelProperty
(
"属性的类型;0->规格;1->参数"
)
@FlagValidator
({
"0"
,
"1"
})
private
Integer
type
;
public
Long
getProductAttributeCategoryId
()
{
return
productAttributeCategoryId
;
}
public
void
setProductAttributeCategoryId
(
Long
productAttributeCategoryId
)
{
this
.
productAttributeCategoryId
=
productAttributeCategoryId
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
Integer
getSelectType
()
{
return
selectType
;
}
public
void
setSelectType
(
Integer
selectType
)
{
this
.
selectType
=
selectType
;
}
public
Integer
getInputType
()
{
return
inputType
;
}
public
void
setInputType
(
Integer
inputType
)
{
this
.
inputType
=
inputType
;
}
public
String
getInputList
()
{
return
inputList
;
}
public
void
setInputList
(
String
inputList
)
{
this
.
inputList
=
inputList
;
}
public
Integer
getSort
()
{
return
sort
;
}
public
void
setSort
(
Integer
sort
)
{
this
.
sort
=
sort
;
}
public
Integer
getFilterType
()
{
return
filterType
;
}
public
void
setFilterType
(
Integer
filterType
)
{
this
.
filterType
=
filterType
;
}
public
Integer
getSearchType
()
{
return
searchType
;
}
public
void
setSearchType
(
Integer
searchType
)
{
this
.
searchType
=
searchType
;
}
public
Integer
getRelatedStatus
()
{
return
relatedStatus
;
}
public
void
setRelatedStatus
(
Integer
relatedStatus
)
{
this
.
relatedStatus
=
relatedStatus
;
}
public
Integer
getHandAddStatus
()
{
return
handAddStatus
;
}
public
void
setHandAddStatus
(
Integer
handAddStatus
)
{
this
.
handAddStatus
=
handAddStatus
;
}
public
Integer
getType
()
{
return
type
;
}
public
void
setType
(
Integer
type
)
{
this
.
type
=
type
;
}
}
mall-admin/src/main/java/com/macro/mall/service/PmsProductAttributeService.java
View file @
353d7311
package
com.macro.mall.service
;
import
com.macro.mall.dto.PmsProductAttributeParam
;
import
com.macro.mall.model.PmsProductAttribute
;
import
java.util.List
;
/**
* 商品属性Service
*/
public
interface
PmsProductAttributeService
{
/**
* 根据分类分页获取商品属性
* @param cid 分类id
* @param type 0->属性;2->参数
* @return
*/
List
<
PmsProductAttribute
>
getList
(
Long
cid
,
Integer
type
,
Integer
pageSize
,
Integer
pageNum
);
/**
* 添加商品属性
*/
int
create
(
PmsProductAttributeParam
pmsProductAttributeParam
);
/**
* 修改商品属性
*/
int
update
(
Long
id
,
PmsProductAttributeParam
productAttributeParam
);
/**
* 获取单个商品属性信息
*/
PmsProductAttribute
getItem
(
Long
id
);
int
delete
(
List
<
Long
>
ids
);
}
mall-admin/src/main/java/com/macro/mall/service/impl/PmsProductAttributeServiceImpl.java
View file @
353d7311
package
com.macro.mall.service.impl
;
import
com.github.pagehelper.PageHelper
;
import
com.macro.mall.dto.PmsProductAttributeParam
;
import
com.macro.mall.mapper.PmsProductAttributeMapper
;
import
com.macro.mall.model.PmsProductAttribute
;
import
com.macro.mall.model.PmsProductAttributeExample
;
import
com.macro.mall.service.PmsProductAttributeService
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* 商品属性Service实现类
*/
@Service
public
class
PmsProductAttributeServiceImpl
implements
PmsProductAttributeService
{
public
class
PmsProductAttributeServiceImpl
implements
PmsProductAttributeService
{
@Autowired
private
PmsProductAttributeMapper
productAttributeMapper
;
@Override
public
List
<
PmsProductAttribute
>
getList
(
Long
cid
,
Integer
type
,
Integer
pageSize
,
Integer
pageNum
)
{
PageHelper
.
startPage
(
pageNum
,
pageSize
);
PmsProductAttributeExample
example
=
new
PmsProductAttributeExample
();
example
.
setOrderByClause
(
"sort desc"
);
example
.
createCriteria
().
andProductAttributeCategoryIdEqualTo
(
cid
).
andTypeEqualTo
(
type
);
return
productAttributeMapper
.
selectByExample
(
example
);
}
@Override
public
int
create
(
PmsProductAttributeParam
pmsProductAttributeParam
)
{
PmsProductAttribute
pmsProductAttribute
=
new
PmsProductAttribute
();
BeanUtils
.
copyProperties
(
pmsProductAttributeParam
,
pmsProductAttribute
);
return
productAttributeMapper
.
insertSelective
(
pmsProductAttribute
);
}
@Override
public
int
update
(
Long
id
,
PmsProductAttributeParam
productAttributeParam
)
{
PmsProductAttribute
pmsProductAttribute
=
new
PmsProductAttribute
();
pmsProductAttribute
.
setId
(
id
);
BeanUtils
.
copyProperties
(
productAttributeParam
,
pmsProductAttribute
);
return
productAttributeMapper
.
updateByPrimaryKeySelective
(
pmsProductAttribute
);
}
@Override
public
PmsProductAttribute
getItem
(
Long
id
)
{
return
productAttributeMapper
.
selectByPrimaryKey
(
id
);
}
@Override
public
int
delete
(
List
<
Long
>
ids
)
{
PmsProductAttributeExample
example
=
new
PmsProductAttributeExample
();
example
.
createCriteria
().
andIdIn
(
ids
);
return
productAttributeMapper
.
deleteByExample
(
example
);
}
}
mall-admin/src/main/java/com/macro/mall/validator/FlagValidatorClass.java
View file @
353d7311
...
...
@@ -16,6 +16,10 @@ public class FlagValidatorClass implements ConstraintValidator<FlagValidator,Int
@Override
public
boolean
isValid
(
Integer
value
,
ConstraintValidatorContext
constraintValidatorContext
)
{
boolean
isValid
=
false
;
if
(
value
==
null
){
//当状态为空时使用默认值
return
true
;
}
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++){
if
(
values
[
i
].
equals
(
String
.
valueOf
(
value
))){
isValid
=
true
;
...
...
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