商品系统项目结构整理

This commit is contained in:
YunaiV
2019-03-03 18:04:06 +08:00
parent eddec34e5d
commit 359d6766f3
38 changed files with 200 additions and 73 deletions

View File

@@ -0,0 +1,14 @@
package cn.iocoder.mall.product.config;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@MapperScan("cn.iocoder.mall.product.dao") // 扫描对应的 Mapper 接口
@EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理。为什么使用 proxyTargetClass 参数,参见 https://blog.csdn.net/huang_550/article/details/76492600
public class DatabaseConfiguration {
// 数据源,使用 HikariCP
}

View File

@@ -0,0 +1,21 @@
package cn.iocoder.mall.product.convert;
import cn.iocoder.mall.product.api.bo.ProductCategoryBO;
import cn.iocoder.mall.product.dataobject.ProductCategoryDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface ProductCategoryConvert {
ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class);
@Mappings({})
ProductCategoryBO convertToBO(ProductCategoryDO category);
List<ProductCategoryBO> convertToBO(List<ProductCategoryDO> categoryList);
}

View File

@@ -0,0 +1,17 @@
package cn.iocoder.mall.product.convert;
import cn.iocoder.mall.product.api.bo.ProductSpuBO;
import cn.iocoder.mall.product.dataobject.ProductSpuDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper
public interface ProductSpuConvert {
ProductSpuConvert INSTANCE = Mappers.getMapper(ProductSpuConvert.class);
@Mappings({})
ProductSpuBO convert(ProductSpuDO spu);
}

View File

@@ -0,0 +1,15 @@
package cn.iocoder.mall.product.dao;
import cn.iocoder.mall.product.dataobject.ProductCategoryDO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ProductCategoryMapper {
List<ProductCategoryDO> selectListByPidAndStatusOrderBySort(@Param("pid") Integer pid,
@Param("status") Integer status);
}

View File

@@ -0,0 +1,11 @@
package cn.iocoder.mall.product.dao;
import cn.iocoder.mall.product.dataobject.ProductSpuDO;
import org.springframework.stereotype.Repository;
@Repository
public interface ProductSpuMapper {
ProductSpuDO selectById(Integer id);
}

View File

@@ -0,0 +1,34 @@
package cn.iocoder.mall.product.dataobject;
import java.util.Date;
/**
* Product 规格
*/
public class ProductAttrDO {
/**
* 规格编号
*/
private Integer id;
/**
* 名称
*/
private String name;
/**
* 创建时间
*/
private Date createTime;
/**
* 最后更新时间
*/
private Date updateTime;
/**
* 状态
*
* 1-正常
* 2-删除
*/
private Integer status;
}

View File

@@ -0,0 +1,38 @@
package cn.iocoder.mall.product.dataobject;
import java.util.Date;
/**
* Product 规格值
*/
public class ProductAttrValueDO {
/**
* 规格值编号
*/
private Integer id;
/**
* 规格编号
*/
private Integer attrId;
/**
* 规格值
*/
private String name;
/**
* 创建时间
*/
private Date createTime;
/**
* 最后更新时间
*/
private Date updateTime;
/**
* 状态
*
* 1-正常
* 2-删除
*/
private Integer status;
}

View File

@@ -0,0 +1,126 @@
package cn.iocoder.mall.product.dataobject;
import java.util.Date;
/**
* 商品分类
*/
public class ProductCategoryDO {
public static final Integer STATUS_ENABLE = 1;
/**
* 分类编号
*/
private Integer id;
/**
* 父分类编号
*
* 如果不存在父级,则 pid = 0 。
*/
private Integer pid;
/**
* 名称
*/
private String name;
/**
* 描述
*/
private String description;
/**
* 分类图片
*/
private String picUrl;
/**
* 排序值
*/
private Integer sort;
/**
* 创建时间
*/
private Date createTime;
/**
* 最后更新时间
*/
private Date updateTime;
/**
* 状态
*
* 1-正常
* 2-删除
*/
private Integer status;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getPid() {
return pid;
}
public void setPid(Integer pid) {
this.pid = pid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPicUrl() {
return picUrl;
}
public void setPicUrl(String picUrl) {
this.picUrl = picUrl;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}

View File

@@ -0,0 +1,59 @@
package cn.iocoder.mall.product.dataobject;
import java.util.Date;
/**
* 商品 SKU
*/
public class ProductSkuDO {
/**
* sku 编号
*/
private Integer id;
/**
* 商品编号
*/
private Integer itemId;
// TODO 店铺编号
/**
* 状态
*
* 1-正常
* 2-删除
*/
private Integer status;
/**
* 图片地址
*/
private String picURL;
/**
* 规格值({@link ProductAttrDO})数组
*
* 数组,以逗号分隔
*/
private String attrs;
/**
* 价格,单位分
*/
private Integer price;
/**
* 商品在付款减库存的状态下该Sku上未付款的订单数量
*/
private Integer withHoldQuantity;
/**
* 销量
*/
private Integer soldNum;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}

View File

@@ -0,0 +1,82 @@
package cn.iocoder.mall.product.dataobject;
import java.util.Date;
/**
* 商品 SPU
*/
public class ProductSpuDO {
// ========== 基础字段 =========
/**
* SPU 编号
*/
private Integer id;
// TODO 店铺编号
/**
* 创建时间
*/
private Date createTime;
/**
* 最后更新时间
*/
private Date updateTime;
/**
* 状态
*
* 1-正常
* 2-删除
*/
private Integer status;
// ========== 基本信息 =========
/**
* SPU 名字
*/
private String name;
/**
* SPU 描述
*/
private String descrption;
/**
* 分类编号
*/
private Integer cid;
/**
* 商品主图地址
*
* 数组,以逗号分隔
*
* 建议尺寸800*800像素你可以拖拽图片调整顺序最多上传15张
*/
private String picURLs;
// TODO 价格库存
// TODO 运费信息
// ========== 其他信息 =========
/**
* 是否上架商品(是否可见)。
*
* true 为已上架
* false 为已下架
*/
private Boolean visible;
/**
* 排序字段
*/
private Integer order;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}

View File

@@ -0,0 +1,38 @@
package cn.iocoder.mall.product.dataobject;
import java.util.Date;
/**
* Product 库存
*/
public class ProductStockDO {
/**
* 编号,自增
*/
private Integer id;
/**
* SKU 编号
*/
private Integer skuId;
/**
* 库存数
*/
private Integer quantity;
/**
* 创建时间
*/
private Date createTime;
/**
* 最后更新时间
*/
private Date updateTime;
/**
* 状态
*
* 1-正常
* 2-删除
*/
private Integer status;
}

View File

@@ -0,0 +1 @@
package cn.iocoder.mall.product;

View File

@@ -0,0 +1,26 @@
package cn.iocoder.mall.product.service;
import cn.iocoder.mall.product.api.ProductCategoryService;
import cn.iocoder.mall.product.api.bo.ProductCategoryBO;
import cn.iocoder.mall.product.convert.ProductCategoryConvert;
import cn.iocoder.mall.product.dao.ProductCategoryMapper;
import cn.iocoder.mall.product.dataobject.ProductCategoryDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示
@com.alibaba.dubbo.config.annotation.Service(validation = "true")
public class ProductCategoryServiceImpl implements ProductCategoryService {
@Autowired
private ProductCategoryMapper productCategoryMapper;
@Override
public List<ProductCategoryBO> getListByPid(Integer pid) {
List<ProductCategoryDO> categoryList = productCategoryMapper.selectListByPidAndStatusOrderBySort(pid, ProductCategoryDO.STATUS_ENABLE);
return ProductCategoryConvert.INSTANCE.convertToBO(categoryList);
}
}

View File

@@ -0,0 +1,25 @@
package cn.iocoder.mall.product.service;
import cn.iocoder.mall.product.api.ProductSpuService;
import cn.iocoder.mall.product.api.bo.ProductSpuBO;
import cn.iocoder.mall.product.convert.ProductSpuConvert;
import cn.iocoder.mall.product.dao.ProductSpuMapper;
import cn.iocoder.mall.product.dataobject.ProductSpuDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示
@com.alibaba.dubbo.config.annotation.Service
public class ProductSpuServiceImpl implements ProductSpuService {
@Autowired
private ProductSpuMapper productSpuDAO;
@Override
public ProductSpuBO getProductSpu(Integer id) {
ProductSpuDO productSpuDO = productSpuDAO.selectById(id);
// 转换成 BO
return ProductSpuConvert.INSTANCE.convert(productSpuDO);
}
}

View File

@@ -0,0 +1,25 @@
spring:
# datasource
datasource:
url: jdbc:mysql://127.0.0.1:33061/mall_product?useSSL=false
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
# mybatis
mybatis:
config-location: classpath:mybatis-config.xml
mapper-locations: classpath:mapper/*.xml
type-aliases-package: cn.iocoder.mall.product.dataobject
# dubbo
dubbo:
application:
name: product-service
registry:
address: zookeeper://127.0.0.1:2181
protocol:
port: -1
name: dubbo
scan:
base-packages: cn.iocoder.mall.product.service

View File

@@ -0,0 +1,15 @@
<?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="cn.iocoder.mall.product.dao.ProductCategoryMapper">
<select id="selectListByPidAndStatusOrderBySort" resultType="ProductCategoryDO">
SELECT
id, name, pic_url, sort
FROM product_category
WHERE pid = #{pid}
AND status = #{status}
ORDER BY sort ASC
</select>
</mapper>

View File

@@ -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="cn.iocoder.mall.product.dao.ProductSpuMapper">
<select id="selectById" parameterType="Integer" resultType="ProductSpuDO">
SELECT
id
FROM product_spu
WHERE id = #{id}
</select>
</mapper>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 使用驼峰命名法转换字段。 -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<typeAliases>
<typeAlias alias="Integer" type="java.lang.Integer"/>
<typeAlias alias="Long" type="java.lang.Long"/>
<typeAlias alias="HashMap" type="java.util.HashMap"/>
<typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap"/>
<typeAlias alias="ArrayList" type="java.util.ArrayList"/>
<typeAlias alias="LinkedList" type="java.util.LinkedList"/>
</typeAliases>
</configuration>