添加商品属性接口

This commit is contained in:
zhh 2018-04-24 15:01:44 +08:00
parent da20e10fc2
commit 353d731196
6 changed files with 285 additions and 9 deletions

View File

@ -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 | ✔
- 批量删除商品属性
- 分页查询全部商品属性
##### 商品管理
#### 促销管理
#### 内容管理

View File

@ -1,21 +1,85 @@
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();
}
}
}

View File

@ -0,0 +1,130 @@
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;
}
}

View File

@ -1,7 +1,36 @@
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);
}

View File

@ -1,15 +1,58 @@
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);
}
}

View File

@ -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;