提交 a41633a9 编写于 作者: Z zhh

创建商品功能完善

上级 bc3c5696
......@@ -33,6 +33,8 @@ SpringAOP通用验证失败结果返回 | ✔
CommonResult对通用返回结果进行封装 | ✔
SpringSecurity登录改为Restful形式 | ✔
JWT登录、注册、获取token | ✔
JTA事务处理 |
集成单元测试 | ✔
### 功能完善
......@@ -63,6 +65,22 @@ JWT登录、注册、获取token | ✔
##### 商品管理
###### 添加商品
- 选择商品分类:根据商品分类id查找分类
- 选择品牌:查询全部品牌
- 选择运费模版:查询全部运费模版
- 设置会员价格:查询所有会员等级,传入List<PmsMemberPrice>
- 添加阶梯价格: 参数传入List<PmsProductLadder>
- 设置满减价格: 参数传入List<PmsProductFullReduction>
- 选择商品属性类别:获取所有商品属性分类,根据商品属性分类的id获取规格和参数(type=0->规格;type=1->参数)
- 选择规格并生成库存信息:前端实现
- 添加sku库存信息:参数传入List<PmsSkuStock>
- 设置属性图片:设置到pic和album_pics字段中去
- 添加商品参数:参数传入List<PmsProductAttributeValue>
- 添加自定义商品规格:参数传入List<PmsProductAttributeValue>
- 关联专题:参数传入List<CmsSubjectProductRelation>关系
- 关联优选:参数传入List<CmsPrefrenceAreaProductRelation>关系
#### 促销管理
#### 内容管理
......
此差异已折叠。
<?xml version="1.0" encoding="UTF-8"?>
<?PowerDesigner AppLocale="UTF16" ID="{7BB41C87-EFE8-409A-A86E-B1C3FCE34F8C}" Label="" LastModificationDate="1522747822" Name="mall" Objects="984" Symbols="123" Target="MySQL 5.0" Type="{CDE44E21-9669-11D1-9914-006097355D9B}" signature="PDM_DATA_MODEL_XML" version="16.5.0.3982"?>
<?PowerDesigner AppLocale="UTF16" ID="{7BB41C87-EFE8-409A-A86E-B1C3FCE34F8C}" Label="" LastModificationDate="1524633114" Name="mall" Objects="972" Symbols="123" Target="MySQL 5.0" Type="{CDE44E21-9669-11D1-9914-006097355D9B}" signature="PDM_DATA_MODEL_XML" version="16.5.0.3982"?>
<!-- do not edit this file -->
<Model xmlns:a="attribute" xmlns:c="collection" xmlns:o="object">
......@@ -7562,9 +7562,9 @@ LABL 0 新宋体,8,N</a:FontList>
<a:Code>promotion_type</a:Code>
<a:CreationDate>1522721953</a:CreationDate>
<a:Creator>zhenghong</a:Creator>
<a:ModificationDate>1522722061</a:ModificationDate>
<a:ModificationDate>1524633114</a:ModificationDate>
<a:Modifier>zhenghong</a:Modifier>
<a:Comment>促销类型:0-&gt;使用促销价;1-&gt;使用会员价;2-&gt;使用阶梯价格;3-&gt;使用满减价格</a:Comment>
<a:Comment>促销类型:0-&gt;没有促销使用原价;1-&gt;使用促销价;2-&gt;使用会员价;3-&gt;使用阶梯价格;4-&gt;使用满减价格</a:Comment>
<a:DataType>int(1)</a:DataType>
<a:Length>1</a:Length>
</o:Column>
......
......@@ -8,7 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* 应用启动入口
*/
@SpringBootApplication
@MapperScan("com.macro.mall.mapper")
@MapperScan({"com.macro.mall.mapper","com.macro.mall.dao"})
public class MallAdminApplication {
public static void main(String[] args) {
SpringApplication.run(MallAdminApplication.class, args);
......
package com.macro.mall.controller;
import com.macro.mall.dto.CommonResult;
import com.macro.mall.dto.PmsProductParam;
import com.macro.mall.service.PmsProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* 商品管理Controller
*/
@Controller
@Api(tags = "PmsProductController",description = "商品管理")
@Api(tags = "PmsProductController", description = "商品管理")
@RequestMapping("/product")
public class PmsProductController {
@Autowired
private PmsProductService productService;
@ApiOperation("创建商品")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public Object create(@RequestBody PmsProductParam productParam, BindingResult bindingResult) {
int count = productService.create(productParam);
if (count > 0) {
return new CommonResult().success(count);
} else {
return new CommonResult().failed();
}
}
}
package com.macro.mall.controller;
import com.macro.mall.dto.CommonResult;
import com.macro.mall.model.UmsMemberLevel;
import com.macro.mall.service.UmsMemberLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
/**
* 会员等级管理Controller
*/
@Controller
@Api(tags = "UmsMemberLevelController",description = "会员等级管理")
@RequestMapping("/memberLevel")
public class UmsMemberLevelController {
@Autowired
private UmsMemberLevelService memberLevelService;
@RequestMapping(value = "/list",method = RequestMethod.GET)
@ApiOperation("查询所有会员等级")
@ResponseBody
public Object list(@RequestParam("defaultStatus") Integer defaultStatus){
List<UmsMemberLevel> memberLevelList = memberLevelService.list(defaultStatus);
return new CommonResult().success(memberLevelList);
}
}
package com.macro.mall.dao;
import com.macro.mall.model.PmsMemberPrice;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 自定义会员价格Dao
*/
public interface PmsMemberPriceDao {
int insertList(@Param("list") List<PmsMemberPrice> memberPriceList);
}
package com.macro.mall.dao;
import com.macro.mall.model.PmsProductFullReduction;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 商品自定义满减
*/
public interface PmsProductFullReductionDao {
int insertList(@Param("list") List<PmsProductFullReduction> productFullReductionList);
}
package com.macro.mall.dao;
import com.macro.mall.model.PmsProductLadder;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 自定义会员阶梯价格Dao
*/
public interface PmsProductLadderDao {
int insertList(@Param("list") List<PmsProductLadder> productLadderList);
}
package com.macro.mall.dto;
import com.macro.mall.model.*;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* 创建和修改商品时使用的参数
*/
public class PmsProductParam {
@ApiModelProperty("商品信息")
@NotNull(message = "商品信息不能为空")
private PmsProduct product;
@ApiModelProperty("商品阶梯价格设置")
private List<PmsProductLadder> productLadderList;
@ApiModelProperty("商品满减价格设置")
private List<PmsProductFullReduction> pmsProductFullReductionList;
@ApiModelProperty("商品会员价格设置")
private List<PmsMemberPrice> pmsMemberPriceList;
@ApiModelProperty("商品的sku库存信息")
private List<PmsSkuStock> skuStockList;
@ApiModelProperty("商品参数及自定义规格属性")
private List<PmsProductAttributeValue> pmsProductAttributeValueList;
@ApiModelProperty("专题和商品关系")
private List<CmsSubjectProductRelation> subjectProductRelationList;
@ApiModelProperty("优选专区和商品的关系")
private List<CmsPrefrenceAreaProductRelation> prefrenceAreaProductRelationList;
public PmsProduct getProduct() {
return product;
}
public void setProduct(PmsProduct product) {
this.product = product;
}
public List<PmsProductLadder> getProductLadderList() {
return productLadderList;
}
public void setProductLadderList(List<PmsProductLadder> productLadderList) {
this.productLadderList = productLadderList;
}
public List<PmsProductFullReduction> getPmsProductFullReductionList() {
return pmsProductFullReductionList;
}
public void setPmsProductFullReductionList(List<PmsProductFullReduction> pmsProductFullReductionList) {
this.pmsProductFullReductionList = pmsProductFullReductionList;
}
public List<PmsMemberPrice> getPmsMemberPriceList() {
return pmsMemberPriceList;
}
public void setPmsMemberPriceList(List<PmsMemberPrice> pmsMemberPriceList) {
this.pmsMemberPriceList = pmsMemberPriceList;
}
public List<PmsSkuStock> getSkuStockList() {
return skuStockList;
}
public void setSkuStockList(List<PmsSkuStock> skuStockList) {
this.skuStockList = skuStockList;
}
public List<PmsProductAttributeValue> getPmsProductAttributeValueList() {
return pmsProductAttributeValueList;
}
public void setPmsProductAttributeValueList(List<PmsProductAttributeValue> pmsProductAttributeValueList) {
this.pmsProductAttributeValueList = pmsProductAttributeValueList;
}
public List<CmsSubjectProductRelation> getSubjectProductRelationList() {
return subjectProductRelationList;
}
public void setSubjectProductRelationList(List<CmsSubjectProductRelation> subjectProductRelationList) {
this.subjectProductRelationList = subjectProductRelationList;
}
public List<CmsPrefrenceAreaProductRelation> getPrefrenceAreaProductRelationList() {
return prefrenceAreaProductRelationList;
}
public void setPrefrenceAreaProductRelationList(List<CmsPrefrenceAreaProductRelation> prefrenceAreaProductRelationList) {
this.prefrenceAreaProductRelationList = prefrenceAreaProductRelationList;
}
}
package com.macro.mall.service;
import com.macro.mall.dto.PmsProductParam;
/**
* 商品管理Service
*/
public interface PmsProductService {
/**
* 创建商品
*/
int create(PmsProductParam productParam);
}
package com.macro.mall.service;
import com.macro.mall.model.UmsMemberLevel;
import java.util.List;
/**
* 会员等级管理Service
*/
public interface UmsMemberLevelService {
/**
* 获取所有会员登录
* @param defaultStatus 是否为默认会员
*/
List<UmsMemberLevel> list(Integer defaultStatus);
}
package com.macro.mall.service.impl;
import com.macro.mall.dao.PmsMemberPriceDao;
import com.macro.mall.dao.PmsProductFullReductionDao;
import com.macro.mall.dao.PmsProductLadderDao;
import com.macro.mall.dto.PmsProductParam;
import com.macro.mall.mapper.PmsProductMapper;
import com.macro.mall.model.PmsMemberPrice;
import com.macro.mall.model.PmsProduct;
import com.macro.mall.model.PmsProductFullReduction;
import com.macro.mall.model.PmsProductLadder;
import com.macro.mall.service.PmsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
/**
* 商品管理Service实现类
*/
@Service
public class PmsProductServiceImpl implements PmsProductService{
@Autowired
private PmsProductMapper productMapper;
@Autowired
private PmsMemberPriceDao memberPriceDao;
@Autowired
private PmsProductLadderDao productLadderDao;
@Autowired
private PmsProductFullReductionDao productFullReductionDao;
@Override
public int create(PmsProductParam productParam) {
int count;
//创建商品
PmsProduct product = productParam.getProduct();
product.setId(null);
productMapper.insertSelective(product);
//根据促销类型设置价格:、阶梯价格、满减价格
Long productId = product.getId();
if(product.getPromotionType()==2){
//会员价格
List<PmsMemberPrice> memberPriceList = productParam.getPmsMemberPriceList();
if(!CollectionUtils.isEmpty(memberPriceList)){
for(PmsMemberPrice pmsMemberPrice: memberPriceList){
pmsMemberPrice.setId(null);
pmsMemberPrice.setProductId(productId);
}
memberPriceDao.insertList(memberPriceList);
}
}else if(product.getPromotionType()==3){
//阶梯价格
List<PmsProductLadder> productLadderList = productParam.getProductLadderList();
if(!CollectionUtils.isEmpty(productLadderList)){
for(PmsProductLadder productLadder:productLadderList){
productLadder.setId(null);
productLadder.setProductId(productId);
}
productLadderDao.insertList(productLadderList);
}
}else if(product.getPromotionType()==4){
//满减价格
List<PmsProductFullReduction> productFullReductionList = productParam.getPmsProductFullReductionList();
if(!CollectionUtils.isEmpty(productFullReductionList)){
for (PmsProductFullReduction productFullReduction: productFullReductionList) {
productFullReduction.setId(null);
productFullReduction.setProductId(productId);
}
productFullReductionDao.insertList(productFullReductionList);
}
}
//添加sku库存信息
//添加商品参数
//添加自定义商品规格
//关联专题
//关联优选
count=1;
return count;
}
}
package com.macro.mall.service.impl;
import com.macro.mall.mapper.UmsMemberLevelMapper;
import com.macro.mall.model.UmsMemberLevel;
import com.macro.mall.model.UmsMemberLevelExample;
import com.macro.mall.service.UmsMemberLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 会员等级管理Service实现类
*/
@Service
public class UmsMemberLevelServiceImpl implements UmsMemberLevelService{
@Autowired
private UmsMemberLevelMapper memberLevelMapper;
@Override
public List<UmsMemberLevel> list(Integer defaultStatus) {
UmsMemberLevelExample example = new UmsMemberLevelExample();
example.createCriteria().andDefaultStatusEqualTo(defaultStatus);
return memberLevelMapper.selectByExample(example);
}
}
......@@ -5,7 +5,7 @@ spring.datasource.password=root
#===datasource end===
#===mybatis start===
mybatis.mapper-locations=classpath:mapper/*.xml,classpath*:com/**/mapper/*.xml
mybatis.mapper-locations=classpath:dao/*.xml,classpath*:com/**/mapper/*.xml
#===mybatis end===
#===log start===
......
<?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.PmsMemberPriceDao">
<!--批量新增回写主键支持-->
<insert id="insertList">
INSERT INTO pms_member_price (product_id, member_level_id, member_price) VALUES
<foreach collection="list" separator="," item="item" index="index">
(#{item.productId,jdbcType=BIGINT},
#{item.memberLevelId,jdbcType=BIGINT},
#{item.memberPrice,jdbcType=DECIMAL})
</foreach>
</insert>
</mapper>
\ No newline at end of file
<?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.PmsMemberPriceDao">
<insert id="insertList">
INSERT INTO pms_product_full_reduction (product_id, full_price, reduce_price) VALUES
<foreach collection="list" separator="," item="item" index="index">
(#{item.productId,jdbcType=BIGINT},
#{item.fullPrice,jdbcType=DECIMAL},
#{item.reducePrice,jdbcType=DECIMAL})
</foreach>
</insert>
</mapper>
\ No newline at end of file
<?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.PmsProductLadderDao">
<insert id="insertList">
INSERT INTO pms_product_ladder (product_id, count, discount, price) VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.productId,jdbcType=BIGINT},
#{item.count,jdbcType=INTEGER},
#{item.discount,jdbcType=DECIMAL},
#{item.price,jdbcType=DECIMAL})
</foreach>
</insert>
</mapper>
\ No newline at end of file
package com.macro.mall;
import com.macro.mall.dao.PmsMemberPriceDao;
import com.macro.mall.model.PmsMemberPrice;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
public class PmsDaoTests {
@Autowired
private PmsMemberPriceDao memberPriceDao;
@Test
public void testInsertBatch(){
List<PmsMemberPrice> list = new ArrayList<>();
for(int i=0;i<5;i++){
PmsMemberPrice memberPrice = new PmsMemberPrice();
memberPrice.setProductId(1L);
memberPrice.setMemberLevelId((long) (i+1));
memberPrice.setMemberPrice(new BigDecimal("22"));
list.add(memberPrice);
}
int count = memberPriceDao.insertList(list);
Assert.assertEquals(5,count);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册