商品系统项目结构整理

pull/1/head
YunaiV 2019-03-03 18:04:06 +08:00
parent eddec34e5d
commit 359d6766f3
38 changed files with 200 additions and 73 deletions

View File

@ -14,6 +14,7 @@
<modules> <modules>
<module>product-application</module> <module>product-application</module>
<module>product-service-api</module> <module>product-service-api</module>
<module>product-service-impl</module>
</modules> </modules>

View File

@ -9,13 +9,18 @@
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>product-rest</artifactId> <artifactId>product-application</artifactId>
<properties> <properties>
<org.mapstruct.version>1.3.0.Final</org.mapstruct.version> <org.mapstruct.version>1.3.0.Final</org.mapstruct.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>common-framework</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>cn.iocoder.mall</groupId> <groupId>cn.iocoder.mall</groupId>
<artifactId>product-service-api</artifactId> <artifactId>product-service-api</artifactId>
@ -23,7 +28,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.iocoder.mall</groupId> <groupId>cn.iocoder.mall</groupId>
<artifactId>common-framework</artifactId> <artifactId>product-service-impl</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>

View File

@ -3,7 +3,7 @@ package cn.iocoder.mall.product;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.product"})
public class ProductApplication { public class ProductApplication {
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.config; package cn.iocoder.mall.product.application.config;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.config; package cn.iocoder.mall.product.application.config;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -19,7 +19,7 @@ public class SwaggerConfiguration {
return new Docket(DocumentationType.SWAGGER_2) return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo()) .apiInfo(apiInfo())
.select() .select()
.apis(RequestHandlerSelectors.basePackage("cn.iocoder.mall.product.controller")) .apis(RequestHandlerSelectors.basePackage("cn.iocoder.mall.product.application.controller"))
.paths(PathSelectors.any()) .paths(PathSelectors.any())
.build(); .build();
} }

View File

@ -1,12 +1,13 @@
package cn.iocoder.mall.product.controller.user; package cn.iocoder.mall.product.application.controller.users;
import cn.iocoder.mall.product.convert.ProductCategoryConvert; import cn.iocoder.mall.product.api.ProductCategoryService;
import cn.iocoder.mall.product.service.ProductCategoryService; import cn.iocoder.mall.product.api.bo.ProductCategoryBO;
import cn.iocoder.mall.product.vo.ProductCategoryVO; import cn.iocoder.mall.product.application.convert.ProductCategoryConvert;
import cn.iocoder.mall.product.application.vo.ProductCategoryVO;
import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@ -19,16 +20,15 @@ import java.util.List;
@Api("商品分类") @Api("商品分类")
public class ProductCategoryController { public class ProductCategoryController {
@Autowired @Reference(validation = "true")
private ProductCategoryService productCategoryService; private ProductCategoryService productCategoryService;
@GetMapping @GetMapping
@ApiOperation("获得指定编号下的子分类的数组") @ApiOperation("获得指定编号下的子分类的数组")
@ApiImplicitParam(name = "pid", value = "指定分类编号", required = true, example = "0") @ApiImplicitParam(name = "pid", value = "指定分类编号", required = true, example = "0")
public List<ProductCategoryVO> list(@RequestParam("pid") Integer pid) { public List<ProductCategoryVO> list(@RequestParam("pid") Integer pid) {
return ProductCategoryConvert.INSTANCE.convertToVO( List<ProductCategoryBO> result = productCategoryService.getListByPid(pid);
productCategoryService.getListByPid(pid) return ProductCategoryConvert.INSTANCE.convertToVO(result);
);
} }
} }

View File

@ -1,9 +1,9 @@
package cn.iocoder.mall.product.controller.user; package cn.iocoder.mall.product.application.controller.users;
import cn.iocoder.mall.product.bo.ProductSpuBO; import cn.iocoder.mall.product.api.ProductSpuService;
import cn.iocoder.mall.product.service.ProductSpuService; import cn.iocoder.mall.product.api.bo.ProductSpuBO;
import cn.iocoder.mall.product.vo.ProductSpuListVO; import cn.iocoder.mall.product.application.vo.ProductSpuListVO;
import org.springframework.beans.factory.annotation.Autowired; import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("user/product/spu") @RequestMapping("user/product/spu")
public class ProductSpuController { public class ProductSpuController {
@Autowired @Reference(validation = "true")
private ProductSpuService productSpuService; private ProductSpuService productSpuService;
// TODO 详情 // TODO 详情

View File

@ -0,0 +1,22 @@
package cn.iocoder.mall.product.application.convert;
import cn.iocoder.mall.product.api.bo.ProductCategoryBO;
import cn.iocoder.mall.product.application.vo.ProductCategoryVO;
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({})
ProductCategoryVO convertToVO(ProductCategoryBO category);
List<ProductCategoryVO> convertToVO(List<ProductCategoryBO> categoryList);
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.vo; package cn.iocoder.mall.product.application.vo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.vo; package cn.iocoder.mall.product.application.vo;
import java.util.List; import java.util.List;

View File

@ -0,0 +1,4 @@
package cn.iocoder.mall.product.application.vo;
public class ProductSpuVO {
}

View File

@ -1,4 +0,0 @@
package cn.iocoder.mall.product.vo;
public class ProductSpuVO {
}

View File

@ -1,32 +1,9 @@
spring: spring:
application: application:
name: product-application name: product-application
# 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
# server # server
server: server:
port: 8081 port: 18081
servlet:
# mybatis context-path: /product-api/
mybatis:
config-location: classpath:mybatis-config.xml
mapper-locations: classpath:mapper/*.xml
type-aliases-package: cn.iocoder.mall.product.dataobject
# dubbo
dubbo:
registry:
address: zookeeper://127.0.0.1:2181
protocol:
port: -1
name: dubbo
scan:
base-packages: cn.iocoder.mall.product.service
demo:
service:
version: 1.0.0

View File

@ -0,0 +1,11 @@
package cn.iocoder.mall.product.api;
import cn.iocoder.mall.product.api.bo.ProductCategoryBO;
import java.util.List;
public interface ProductCategoryService {
List<ProductCategoryBO> getListByPid(Integer pid);
}

View File

@ -0,0 +1,9 @@
package cn.iocoder.mall.product.api;
import cn.iocoder.mall.product.api.bo.ProductSpuBO;
public interface ProductSpuService {
ProductSpuBO getProductSpu(Integer id);
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.bo; package cn.iocoder.mall.product.api.bo;
/** /**
* BO * BO

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.bo; package cn.iocoder.mall.product.api.bo;
public class ProductSkuBO { public class ProductSkuBO {

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.bo; package cn.iocoder.mall.product.api.bo;
public class ProductSpuBO { public class ProductSpuBO {

View File

@ -1,4 +0,0 @@
package cn.iocoder.mall.product.service.api;
public interface ProductSpuService {
}

View File

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>product</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>product-service-impl</artifactId>
<properties>
<org.mapstruct.version>1.3.0.Final</org.mapstruct.version>
</properties>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>product-service-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.0.1-jre</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 提供给 mapstruct 使用 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source> <!-- or higher, depending on your project -->
<target>1.8</target> <!-- or higher, depending on your project -->
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,8 +1,7 @@
package cn.iocoder.mall.product.convert; package cn.iocoder.mall.product.convert;
import cn.iocoder.mall.product.bo.ProductCategoryBO; import cn.iocoder.mall.product.api.bo.ProductCategoryBO;
import cn.iocoder.mall.product.dataobject.ProductCategoryDO; import cn.iocoder.mall.product.dataobject.ProductCategoryDO;
import cn.iocoder.mall.product.vo.ProductCategoryVO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mappings; import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
@ -19,9 +18,4 @@ public interface ProductCategoryConvert {
List<ProductCategoryBO> convertToBO(List<ProductCategoryDO> categoryList); List<ProductCategoryBO> convertToBO(List<ProductCategoryDO> categoryList);
@Mappings({})
ProductCategoryVO convertToVO(ProductCategoryBO category);
List<ProductCategoryVO> convertToVO(List<ProductCategoryBO> categoryList);
} }

View File

@ -1,6 +1,6 @@
package cn.iocoder.mall.product.convert; package cn.iocoder.mall.product.convert;
import cn.iocoder.mall.product.bo.ProductSpuBO; import cn.iocoder.mall.product.api.bo.ProductSpuBO;
import cn.iocoder.mall.product.dataobject.ProductSpuDO; import cn.iocoder.mall.product.dataobject.ProductSpuDO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mappings; import org.mapstruct.Mappings;

View File

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

View File

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

View File

@ -1,6 +1,7 @@
package cn.iocoder.mall.product.service; package cn.iocoder.mall.product.service;
import cn.iocoder.mall.product.bo.ProductSpuBO; 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.convert.ProductSpuConvert;
import cn.iocoder.mall.product.dao.ProductSpuMapper; import cn.iocoder.mall.product.dao.ProductSpuMapper;
import cn.iocoder.mall.product.dataobject.ProductSpuDO; import cn.iocoder.mall.product.dataobject.ProductSpuDO;
@ -9,11 +10,12 @@ import org.springframework.stereotype.Service;
@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示 @Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示
@com.alibaba.dubbo.config.annotation.Service @com.alibaba.dubbo.config.annotation.Service
public class ProductSpuService implements cn.iocoder.mall.product.service.api.ProductSpuService { public class ProductSpuServiceImpl implements ProductSpuService {
@Autowired @Autowired
private ProductSpuMapper productSpuDAO; private ProductSpuMapper productSpuDAO;
@Override
public ProductSpuBO getProductSpu(Integer id) { public ProductSpuBO getProductSpu(Integer id) {
ProductSpuDO productSpuDO = productSpuDAO.selectById(id); ProductSpuDO productSpuDO = productSpuDAO.selectById(id);
// 转换成 BO // 转换成 BO

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