添加创建产品功能
This commit is contained in:
@@ -3,6 +3,7 @@ package com.macro.mall;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
* 应用启动入口
|
||||
@@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@MapperScan({"com.macro.mall.mapper","com.macro.mall.dao"})
|
||||
@EnableTransactionManagement
|
||||
public class MallAdminApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MallAdminApplication.class, args);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.macro.mall.dao;
|
||||
|
||||
import com.macro.mall.model.CmsPrefrenceAreaProductRelation;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 自定义优选和商品关系操作
|
||||
* Created by macro on 2018/4/26.
|
||||
*/
|
||||
public interface CmsPrefrenceAreaProductRelationDao {
|
||||
int insertList(@Param("list") List<CmsPrefrenceAreaProductRelation> prefrenceAreaProductRelationList);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.macro.mall.dao;
|
||||
|
||||
import com.macro.mall.model.CmsSubjectProductRelation;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 自定义商品和专题关系操作
|
||||
* Created by macro on 2018/4/26.
|
||||
*/
|
||||
public interface CmsSubjectProductRelationDao {
|
||||
int insertList(@Param("list") List<CmsSubjectProductRelation> subjectProductRelationList);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.macro.mall.dao;
|
||||
|
||||
import com.macro.mall.model.PmsProductAttributeValue;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品参数,商品自定义规格属性Dao
|
||||
* Created by macro on 2018/4/26.
|
||||
*/
|
||||
public interface PmsProductAttributeValueDao {
|
||||
int insertList(@Param("list")List<PmsProductAttributeValue> productAttributeValueList);
|
||||
}
|
||||
@@ -17,13 +17,13 @@ public class PmsProductParam {
|
||||
@ApiModelProperty("商品阶梯价格设置")
|
||||
private List<PmsProductLadder> productLadderList;
|
||||
@ApiModelProperty("商品满减价格设置")
|
||||
private List<PmsProductFullReduction> pmsProductFullReductionList;
|
||||
private List<PmsProductFullReduction> productFullReductionList;
|
||||
@ApiModelProperty("商品会员价格设置")
|
||||
private List<PmsMemberPrice> pmsMemberPriceList;
|
||||
private List<PmsMemberPrice> memberPriceList;
|
||||
@ApiModelProperty("商品的sku库存信息")
|
||||
private List<PmsSkuStock> skuStockList;
|
||||
@ApiModelProperty("商品参数及自定义规格属性")
|
||||
private List<PmsProductAttributeValue> pmsProductAttributeValueList;
|
||||
private List<PmsProductAttributeValue> productAttributeValueList;
|
||||
@ApiModelProperty("专题和商品关系")
|
||||
private List<CmsSubjectProductRelation> subjectProductRelationList;
|
||||
@ApiModelProperty("优选专区和商品的关系")
|
||||
@@ -45,20 +45,20 @@ public class PmsProductParam {
|
||||
this.productLadderList = productLadderList;
|
||||
}
|
||||
|
||||
public List<PmsProductFullReduction> getPmsProductFullReductionList() {
|
||||
return pmsProductFullReductionList;
|
||||
public List<PmsProductFullReduction> getProductFullReductionList() {
|
||||
return productFullReductionList;
|
||||
}
|
||||
|
||||
public void setPmsProductFullReductionList(List<PmsProductFullReduction> pmsProductFullReductionList) {
|
||||
this.pmsProductFullReductionList = pmsProductFullReductionList;
|
||||
public void setProductFullReductionList(List<PmsProductFullReduction> productFullReductionList) {
|
||||
this.productFullReductionList = productFullReductionList;
|
||||
}
|
||||
|
||||
public List<PmsMemberPrice> getPmsMemberPriceList() {
|
||||
return pmsMemberPriceList;
|
||||
public List<PmsMemberPrice> getMemberPriceList() {
|
||||
return memberPriceList;
|
||||
}
|
||||
|
||||
public void setPmsMemberPriceList(List<PmsMemberPrice> pmsMemberPriceList) {
|
||||
this.pmsMemberPriceList = pmsMemberPriceList;
|
||||
public void setMemberPriceList(List<PmsMemberPrice> memberPriceList) {
|
||||
this.memberPriceList = memberPriceList;
|
||||
}
|
||||
|
||||
public List<PmsSkuStock> getSkuStockList() {
|
||||
@@ -69,12 +69,12 @@ public class PmsProductParam {
|
||||
this.skuStockList = skuStockList;
|
||||
}
|
||||
|
||||
public List<PmsProductAttributeValue> getPmsProductAttributeValueList() {
|
||||
return pmsProductAttributeValueList;
|
||||
public List<PmsProductAttributeValue> getProductAttributeValueList() {
|
||||
return productAttributeValueList;
|
||||
}
|
||||
|
||||
public void setPmsProductAttributeValueList(List<PmsProductAttributeValue> pmsProductAttributeValueList) {
|
||||
this.pmsProductAttributeValueList = pmsProductAttributeValueList;
|
||||
public void setProductAttributeValueList(List<PmsProductAttributeValue> productAttributeValueList) {
|
||||
this.productAttributeValueList = productAttributeValueList;
|
||||
}
|
||||
|
||||
public List<CmsSubjectProductRelation> getSubjectProductRelationList() {
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.macro.mall.service;
|
||||
|
||||
import com.macro.mall.dto.PmsProductCategoryParam;
|
||||
import com.macro.mall.model.PmsProductCategory;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.macro.mall.service;
|
||||
|
||||
import com.macro.mall.dto.PmsProductParam;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 商品管理Service
|
||||
@@ -10,5 +13,6 @@ public interface PmsProductService {
|
||||
/**
|
||||
* 创建商品
|
||||
*/
|
||||
@Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED)
|
||||
int create(PmsProductParam productParam);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
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.dao.*;
|
||||
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.model.*;
|
||||
import com.macro.mall.service.PmsProductService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品管理Service实现类
|
||||
* Created by macro on 2018/4/26.
|
||||
*/
|
||||
@Service
|
||||
public class PmsProductServiceImpl implements PmsProductService {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PmsProductServiceImpl.class);
|
||||
@Autowired
|
||||
private PmsProductMapper productMapper;
|
||||
@Autowired
|
||||
@@ -29,6 +29,14 @@ public class PmsProductServiceImpl implements PmsProductService {
|
||||
private PmsProductLadderDao productLadderDao;
|
||||
@Autowired
|
||||
private PmsProductFullReductionDao productFullReductionDao;
|
||||
@Autowired
|
||||
private PmsSkuStockDao skuStockDao;
|
||||
@Autowired
|
||||
private PmsProductAttributeValueDao productAttributeValueDao;
|
||||
@Autowired
|
||||
private CmsSubjectProductRelationDao subjectProductRelationDao;
|
||||
@Autowired
|
||||
private CmsPrefrenceAreaProductRelationDao prefrenceAreaProductRelationDao;
|
||||
|
||||
@Override
|
||||
public int create(PmsProductParam productParam) {
|
||||
@@ -40,7 +48,37 @@ public class PmsProductServiceImpl implements PmsProductService {
|
||||
//根据促销类型设置价格:、阶梯价格、满减价格
|
||||
Long productId = product.getId();
|
||||
//会员价格
|
||||
List<PmsMemberPrice> memberPriceList = productParam.getPmsMemberPriceList();
|
||||
relateAndInsertList(memberPriceDao,productParam.getMemberPriceList(),productId);
|
||||
//阶梯价格
|
||||
relateAndInsertList(productLadderDao,productParam.getProductLadderList(),productId);
|
||||
//满减价格
|
||||
relateAndInsertList(productFullReductionDao, productParam.getProductFullReductionList(), productId);
|
||||
//添加sku库存信息
|
||||
relateAndInsertList(skuStockDao, productParam.getSkuStockList(), productId);
|
||||
//添加商品参数,添加自定义商品规格
|
||||
relateAndInsertList(productAttributeValueDao, productParam.getProductAttributeValueList(), productId);
|
||||
//关联专题
|
||||
relateAndInsertList(subjectProductRelationDao, productParam.getSubjectProductRelationList(), productId);
|
||||
//关联优选
|
||||
relateAndInsertList(prefrenceAreaProductRelationDao, productParam.getPrefrenceAreaProductRelationList(), productId);
|
||||
count = 1;
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* 旧版创建
|
||||
*/
|
||||
public int createOld(PmsProductParam productParam) {
|
||||
int count;
|
||||
//创建商品
|
||||
PmsProduct product = productParam.getProduct();
|
||||
product.setId(null);
|
||||
productMapper.insertSelective(product);
|
||||
//根据促销类型设置价格:、阶梯价格、满减价格
|
||||
Long productId = product.getId();
|
||||
//会员价格
|
||||
List<PmsMemberPrice> memberPriceList = productParam.getMemberPriceList();
|
||||
if (!CollectionUtils.isEmpty(memberPriceList)) {
|
||||
for (PmsMemberPrice pmsMemberPrice : memberPriceList) {
|
||||
pmsMemberPrice.setId(null);
|
||||
@@ -58,7 +96,7 @@ public class PmsProductServiceImpl implements PmsProductService {
|
||||
productLadderDao.insertList(productLadderList);
|
||||
}
|
||||
//满减价格
|
||||
List<PmsProductFullReduction> productFullReductionList = productParam.getPmsProductFullReductionList();
|
||||
List<PmsProductFullReduction> productFullReductionList = productParam.getProductFullReductionList();
|
||||
if (!CollectionUtils.isEmpty(productFullReductionList)) {
|
||||
for (PmsProductFullReduction productFullReduction : productFullReductionList) {
|
||||
productFullReduction.setId(null);
|
||||
@@ -67,11 +105,52 @@ public class PmsProductServiceImpl implements PmsProductService {
|
||||
productFullReductionDao.insertList(productFullReductionList);
|
||||
}
|
||||
//添加sku库存信息
|
||||
//添加商品参数
|
||||
//添加自定义商品规格
|
||||
List<PmsSkuStock> skuStockList = productParam.getSkuStockList();
|
||||
if(!CollectionUtils.isEmpty(skuStockList)){
|
||||
for (PmsSkuStock skuStock : skuStockList) {
|
||||
skuStock.setId(null);
|
||||
skuStock.setProductId(productId);
|
||||
}
|
||||
skuStockDao.insertList(skuStockList);
|
||||
}
|
||||
//添加商品参数,添加自定义商品规格
|
||||
List<PmsProductAttributeValue> productAttributeValueList = productParam.getProductAttributeValueList();
|
||||
if(!CollectionUtils.isEmpty(productAttributeValueList)){
|
||||
for (PmsProductAttributeValue productAttributeValue : productAttributeValueList) {
|
||||
productAttributeValue.setId(null);
|
||||
productAttributeValue.setProductId(productId);
|
||||
}
|
||||
productAttributeValueDao.insertList(productAttributeValueList);
|
||||
}
|
||||
//关联专题
|
||||
relateAndInsertList(subjectProductRelationDao, productParam.getSubjectProductRelationList(), productId);
|
||||
//关联优选
|
||||
relateAndInsertList(prefrenceAreaProductRelationDao, productParam.getPrefrenceAreaProductRelationList(), productId);
|
||||
count = 1;
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 建立和插入关系表操作
|
||||
*
|
||||
* @param dao 可以操作的dao
|
||||
* @param dataList 要插入的数据
|
||||
* @param productId 建立关系的id
|
||||
*/
|
||||
private void relateAndInsertList(Object dao, List dataList, Long productId) {
|
||||
try {
|
||||
if (CollectionUtils.isEmpty(dataList)) return;
|
||||
for (Object item : dataList) {
|
||||
Method setId = item.getClass().getMethod("setId", Long.class);
|
||||
setId.invoke(item, (Long) null);
|
||||
Method setProductId = item.getClass().getMethod("setProductId", Long.class);
|
||||
setProductId.invoke(item, productId);
|
||||
}
|
||||
Method insertList = dao.getClass().getMethod("insertList", List.class);
|
||||
insertList.invoke(dao, dataList);
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("创建产品出错:{}",e.getMessage());
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?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.CmsPrefrenceAreaProductRelationDao">
|
||||
<insert id="insertList">
|
||||
insert into cms_prefrence_area_product_relation (prefrence_area_id, product_id) values
|
||||
<foreach collection="list" item="item" separator="," index="index">
|
||||
(#{item.prefrenceAreaId,jdbcType=BIGINT},
|
||||
#{item.productId,jdbcType=BIGINT})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?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.CmsSubjectProductRelationDao">
|
||||
<insert id="insertList">
|
||||
insert into cms_subject_product_relation (subject_id, product_id) values
|
||||
<foreach collection="list" item="item" separator="," index="index">
|
||||
(#{item.subjectId,jdbcType=BIGINT},
|
||||
#{item.productId,jdbcType=BIGINT})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?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.PmsProductAttributeValueDao">
|
||||
<insert id="insertList">
|
||||
insert into pms_product_attribute_value (product_id,product_attribute_id,value) values
|
||||
<foreach collection="list" item="item" index="index" separator=",">
|
||||
(#{item.productId,jdbcType=BIGINT},
|
||||
#{item.productAttributeId,jdbcType=BIGINT},
|
||||
#{item.value,jdbcType=VARCHAR})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?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">
|
||||
<mapper namespace="com.macro.mall.dao.PmsProductFullReductionDao">
|
||||
<insert id="insertList">
|
||||
INSERT INTO pms_product_full_reduction (product_id, full_price, reduce_price) VALUES
|
||||
<foreach collection="list" separator="," item="item" index="index">
|
||||
|
||||
19
mall-admin/src/main/resources/dao/PmsSkuStockDao.xml
Normal file
19
mall-admin/src/main/resources/dao/PmsSkuStockDao.xml
Normal file
@@ -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.PmsSkuStockDao">
|
||||
<insert id="insertList">
|
||||
INSERT INTO pms_sku_stock (product_id, sku_code, price, stock, low_stock, sp1, sp2, sp3, pic, sale) VALUES
|
||||
<foreach collection="list" item="item" index="index" separator=",">
|
||||
(#{item.productId,jdbcType=BIGINT},
|
||||
#{item.skuCode,jdbcType=VARCHAR},
|
||||
#{item.price,jdbcType=DECIMAL},
|
||||
#{item.stock,jdbcType=INTEGER},
|
||||
#{item.lowStock,jdbcType=INTEGER},
|
||||
#{item.sp1,jdbcType=VARCHAR},
|
||||
#{item.sp2,jdbcType=VARCHAR},
|
||||
#{item.sp3,jdbcType=VARCHAR},
|
||||
#{item.pic,jdbcType=VARCHAR},
|
||||
#{item.sale,jdbcType=INTEGER})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user