diff --git a/product/pom.xml b/product/pom.xml
index eb58b3c4c..58be06e12 100644
--- a/product/pom.xml
+++ b/product/pom.xml
@@ -13,7 +13,6 @@
pom
product-application
- product-service
product-service-api
diff --git a/product/product-application/pom.xml b/product/product-application/pom.xml
index ce024bf19..4fea6cd86 100644
--- a/product/product-application/pom.xml
+++ b/product/product-application/pom.xml
@@ -11,6 +11,10 @@
product-rest
+
+ 1.3.0.Final
+
+
cn.iocoder.mall
@@ -60,6 +64,46 @@
2.12.0
+
+ org.mapstruct
+ mapstruct
+ ${org.mapstruct.version}
+
+
+
+
+ io.springfox
+ springfox-swagger2
+ 2.9.2
+
+
+ io.springfox
+ springfox-swagger-ui
+ 2.9.2
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.5.1
+
+ 1.8
+ 1.8
+
+
+ org.mapstruct
+ mapstruct-processor
+ ${org.mapstruct.version}
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/ProductApplication.java b/product/product-application/src/main/java/cn/iocoder/mall/product/ProductApplication.java
new file mode 100644
index 000000000..fba29b9a4
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/ProductApplication.java
@@ -0,0 +1,13 @@
+package cn.iocoder.mall.product;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class ProductApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(ProductApplication.class, args);
+ }
+
+}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/ProductRestApplication.java b/product/product-application/src/main/java/cn/iocoder/mall/product/ProductRestApplication.java
deleted file mode 100644
index c192eb487..000000000
--- a/product/product-application/src/main/java/cn/iocoder/mall/product/ProductRestApplication.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package cn.iocoder.mall.product;
-
-import org.mybatis.spring.annotation.MapperScan;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.context.ConfigurableApplicationContext;
-
-import javax.sql.DataSource;
-
-@SpringBootApplication
-@MapperScan("cn.iocoder.mall.product.dao") // 扫描对应的 Mapper 接口
-public class ProductRestApplication {
-
- public static void main(String[] args) {
- ConfigurableApplicationContext ctx = SpringApplication.run(ProductRestApplication.class, args);
- DataSource ds = ctx.getBean(DataSource.class);
- System.out.println(ds);
- }
-
-}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/bo/ProductCategoryBO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/bo/ProductCategoryBO.java
new file mode 100644
index 000000000..29fa1d023
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/bo/ProductCategoryBO.java
@@ -0,0 +1,70 @@
+package cn.iocoder.mall.product.bo;
+
+/**
+ * 商品分类 BO
+ */
+public class ProductCategoryBO {
+
+ /**
+ * 分类编号
+ */
+ private Integer id;
+ /**
+ * 父分类编号
+ *
+ * 如果不存在父级,则 pid = 0 。
+ */
+ private Integer pid;
+ /**
+ * 名称
+ */
+ private String name;
+ /**
+ * 分类图片
+ */
+ private String picUrl;
+ /**
+ * 排序值
+ */
+ private Integer sort;
+
+ 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 getPicUrl() {
+ return picUrl;
+ }
+
+ public void setPicUrl(String picUrl) {
+ this.picUrl = picUrl;
+ }
+
+ public Integer getSort() {
+ return sort;
+ }
+
+ public void setSort(Integer sort) {
+ this.sort = sort;
+ }
+}
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/config/DatabaseConfiguration.java b/product/product-application/src/main/java/cn/iocoder/mall/product/config/DatabaseConfiguration.java
new file mode 100644
index 000000000..b1020e51a
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/config/DatabaseConfiguration.java
@@ -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
+
+}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/config/GlobalExceptionHandler.java b/product/product-application/src/main/java/cn/iocoder/mall/product/config/GlobalExceptionHandler.java
new file mode 100644
index 000000000..1a8063b30
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/config/GlobalExceptionHandler.java
@@ -0,0 +1,36 @@
+package cn.iocoder.mall.product.config;
+
+import cn.iocoder.mall.product.constants.ErrorCodeEnum;
+import cn.iocoder.mall.product.exception.ServiceException;
+import cn.iocoder.mall.product.vo.RestResult;
+import org.springframework.web.bind.MissingServletRequestParameterException;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+
+@ControllerAdvice
+public class GlobalExceptionHandler {
+
+ @ResponseBody
+ @ExceptionHandler(value = ServiceException.class)
+ public RestResult serviceExceptionHandler(HttpServletRequest req, Exception e) {
+ ServiceException ex = (ServiceException) e;
+ return RestResult.error(ex.getCode(), ex.getMessage());
+ }
+
+ @ResponseBody
+ @ExceptionHandler(value = Exception.class)
+ public RestResult resultExceptionHandler(HttpServletRequest req, Exception e) {
+ // TODO 异常日志
+ e.printStackTrace();
+ // TODO 翻译不同的异常
+ if (e instanceof MissingServletRequestParameterException) {
+ return RestResult.error(ErrorCodeEnum.MISSING_REQUEST_PARAM_ERROR.getCode(), ErrorCodeEnum.MISSING_REQUEST_PARAM_ERROR.getMessage());
+ }
+ // 返回
+ return RestResult.error(ErrorCodeEnum.SYS_ERROR.getCode(), ErrorCodeEnum.SYS_ERROR.getMessage());
+ }
+
+}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/config/GlobalResponseBodyAdvice.java b/product/product-application/src/main/java/cn/iocoder/mall/product/config/GlobalResponseBodyAdvice.java
new file mode 100644
index 000000000..1ce33e816
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/config/GlobalResponseBodyAdvice.java
@@ -0,0 +1,26 @@
+package cn.iocoder.mall.product.config;
+
+import cn.iocoder.mall.product.vo.RestResult;
+import org.springframework.core.MethodParameter;
+import org.springframework.http.MediaType;
+import org.springframework.http.server.ServerHttpRequest;
+import org.springframework.http.server.ServerHttpResponse;
+import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
+
+//@ControllerAdvice
+public class GlobalResponseBodyAdvice implements ResponseBodyAdvice {
+
+ @Override
+ public boolean supports(MethodParameter returnType, Class converterType) {
+ return true; // TODO 芋艿,未来,这里可以剔除掉一些,需要特殊返回的接口
+ }
+
+ @Override
+ public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
+ if (body instanceof RestResult) {
+ return body;
+ }
+ return RestResult.ok(body);
+ }
+
+}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/config/MVCConfiguration.java b/product/product-application/src/main/java/cn/iocoder/mall/product/config/MVCConfiguration.java
new file mode 100644
index 000000000..0015f58cc
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/config/MVCConfiguration.java
@@ -0,0 +1,23 @@
+package cn.iocoder.mall.product.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@EnableWebMvc
+@Configuration
+public class MVCConfiguration implements WebMvcConfigurer {
+
+// @Autowired
+// private SecurityInterceptor securityInterceptor;
+
+// @Reference
+// private OAuth2Service oauth2Service;
+
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+// registry.addInterceptor(securityInterceptor);
+ }
+
+}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/config/SwaggerConfiguration.java b/product/product-application/src/main/java/cn/iocoder/mall/product/config/SwaggerConfiguration.java
new file mode 100644
index 000000000..1a518f1ac
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/config/SwaggerConfiguration.java
@@ -0,0 +1,36 @@
+package cn.iocoder.mall.product.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.ApiInfoBuilder;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+@Configuration
+@EnableSwagger2
+public class SwaggerConfiguration {
+
+ @Bean
+ public Docket createRestApi() {
+ return new Docket(DocumentationType.SWAGGER_2)
+ .apiInfo(apiInfo())
+ .select()
+ .apis(RequestHandlerSelectors.basePackage("cn.iocoder.mall.product.controller"))
+ .paths(PathSelectors.any())
+ .build();
+ }
+
+ private ApiInfo apiInfo() {
+ return new ApiInfoBuilder()
+ .title("商品子系统")
+ .description("商品子系统")
+ .termsOfServiceUrl("http://www.iocoder.cn")
+ .version("1.0.0")
+ .build();
+ }
+
+}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/constants/ErrorCodeEnum.java b/product/product-application/src/main/java/cn/iocoder/mall/product/constants/ErrorCodeEnum.java
new file mode 100644
index 000000000..ab28001f5
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/constants/ErrorCodeEnum.java
@@ -0,0 +1,32 @@
+package cn.iocoder.mall.product.constants;
+
+/**
+ * 错误码枚举类
+ *
+ * 系统级异常,使用 2-001-000-000 段
+ */
+public enum ErrorCodeEnum {
+
+ SYS_ERROR(2001001000, "服务端发生异常"),
+ MISSING_REQUEST_PARAM_ERROR(2001001001, "参数缺失"),
+
+ ;
+
+ private final int code;
+ private final String message;
+
+ ErrorCodeEnum(int code, String message) {
+ this.code = code;
+ this.message = message;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+ ;
+
+}
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/controller/user/ProductCategoryController.java b/product/product-application/src/main/java/cn/iocoder/mall/product/controller/user/ProductCategoryController.java
index d9c087e15..1067df369 100644
--- a/product/product-application/src/main/java/cn/iocoder/mall/product/controller/user/ProductCategoryController.java
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/controller/user/ProductCategoryController.java
@@ -1,22 +1,34 @@
package cn.iocoder.mall.product.controller.user;
+import cn.iocoder.mall.product.convert.ProductCategoryConvert;
+import cn.iocoder.mall.product.service.ProductCategoryService;
import cn.iocoder.mall.product.vo.ProductCategoryVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
-import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("user/product/category")
+@Api("商品分类")
public class ProductCategoryController {
- // TODO 获得父编号为 id 的分类们 后面,使用 swagger 注释
+ @Autowired
+ private ProductCategoryService productCategoryService;
+
@GetMapping
- public List list(@RequestParam("id") Integer id) {
- return new ArrayList<>();
+ @ApiOperation("获得指定编号下的子分类的数组")
+ @ApiImplicitParam(name = "pid", value = "指定分类编号", required = true)
+ public List list(@RequestParam("pid") Integer pid) {
+ return ProductCategoryConvert.INSTANCE.convertToVO(
+ productCategoryService.getListByPid(pid)
+ );
}
}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/convert/ProductCategoryConvert.java b/product/product-application/src/main/java/cn/iocoder/mall/product/convert/ProductCategoryConvert.java
new file mode 100644
index 000000000..0e4abb009
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/convert/ProductCategoryConvert.java
@@ -0,0 +1,27 @@
+package cn.iocoder.mall.product.convert;
+
+import cn.iocoder.mall.product.bo.ProductCategoryBO;
+import cn.iocoder.mall.product.dataobject.ProductCategoryDO;
+import cn.iocoder.mall.product.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({})
+ ProductCategoryBO convertToBO(ProductCategoryDO category);
+
+ List convertToBO(List categoryList);
+
+ @Mappings({})
+ ProductCategoryVO convertToVO(ProductCategoryBO category);
+
+ List convertToVO(List categoryList);
+
+}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/convert/ProductSpuConvert.java b/product/product-application/src/main/java/cn/iocoder/mall/product/convert/ProductSpuConvert.java
new file mode 100644
index 000000000..b0599c2f7
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/convert/ProductSpuConvert.java
@@ -0,0 +1,17 @@
+package cn.iocoder.mall.product.convert;
+
+import cn.iocoder.mall.product.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);
+
+}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/dao/ProductCategoryMapper.java b/product/product-application/src/main/java/cn/iocoder/mall/product/dao/ProductCategoryMapper.java
new file mode 100644
index 000000000..e1c5a3988
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/dao/ProductCategoryMapper.java
@@ -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 selectListByPidAndStatusOrderBySort(@Param("pid") Integer pid,
+ @Param("status") Integer status);
+
+}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/dataobject/ProductCategoryDO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/dataobject/ProductCategoryDO.java
index 4b944551c..47690acbb 100644
--- a/product/product-application/src/main/java/cn/iocoder/mall/product/dataobject/ProductCategoryDO.java
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/dataobject/ProductCategoryDO.java
@@ -7,6 +7,8 @@ import java.util.Date;
*/
public class ProductCategoryDO {
+ public static final Integer STATUS_ENABLE = 1;
+
/**
* 分类编号
*/
@@ -28,7 +30,7 @@ public class ProductCategoryDO {
/**
* 分类图片
*/
- private String picURL;
+ private String picUrl;
/**
* 排序值
*/
@@ -49,4 +51,76 @@ public class ProductCategoryDO {
*/
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;
+ }
+
+}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/exception/ServiceException.java b/product/product-application/src/main/java/cn/iocoder/mall/product/exception/ServiceException.java
new file mode 100644
index 000000000..695acccab
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/exception/ServiceException.java
@@ -0,0 +1,46 @@
+package cn.iocoder.mall.product.exception;
+
+/**
+ * 服务异常
+ *
+ * 参考 https://www.kancloud.cn/onebase/ob/484204 文章
+ *
+ * 一共 10 位,分成四段
+ *
+ * 第一段,1 位,类型
+ * 1 - 业务级别异常
+ * 2 - 系统级别异常
+ * 第二段,3 位,系统类型
+ * 001 - 用户系统
+ * 002 - 商品系统
+ * 003 - 订单系统
+ * 004 - 支付系统
+ * 005 - 优惠劵系统
+ * ... - ...
+ * 第三段,3 位,模块
+ * 不限制规则。
+ * 一般建议,每个系统里面,可能有多个模块,可以再去做分段。以用户系统为例子:
+ * 001 - OAuth2 模块
+ * 002 - User 模块
+ * 003 - MobileCode 模块
+ * 第四段,3 位,错误码
+ * 不限制规则。
+ * 一般建议,每个模块自增。
+ */
+public class ServiceException extends RuntimeException {
+
+ /**
+ * 错误码
+ */
+ private final Integer code;
+
+ public ServiceException(Integer code, String message) {
+ super(message);
+ this.code = code;
+ }
+
+ public Integer getCode() {
+ return code;
+ }
+
+}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/service/ProductCategoryService.java b/product/product-application/src/main/java/cn/iocoder/mall/product/service/ProductCategoryService.java
new file mode 100644
index 000000000..110c76ad1
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/service/ProductCategoryService.java
@@ -0,0 +1,24 @@
+package cn.iocoder.mall.product.service;
+
+import cn.iocoder.mall.product.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
+public class ProductCategoryService {
+
+ @Autowired
+ private ProductCategoryMapper productCategoryMapper;
+
+ public List getListByPid(Integer pid) {
+ List categoryList = productCategoryMapper.selectListByPidAndStatusOrderBySort(pid, ProductCategoryDO.STATUS_ENABLE);
+ return ProductCategoryConvert.INSTANCE.convertToBO(categoryList);
+ }
+
+}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/service/ProductSpuService.java b/product/product-application/src/main/java/cn/iocoder/mall/product/service/ProductSpuService.java
index 387ce4082..e08b5e068 100644
--- a/product/product-application/src/main/java/cn/iocoder/mall/product/service/ProductSpuService.java
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/service/ProductSpuService.java
@@ -1,6 +1,7 @@
package cn.iocoder.mall.product.service;
import cn.iocoder.mall.product.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;
@@ -15,9 +16,8 @@ public class ProductSpuService implements cn.iocoder.mall.product.service.api.Pr
public ProductSpuBO getProductSpu(Integer id) {
ProductSpuDO productSpuDO = productSpuDAO.selectById(id);
- ProductSpuBO productSpuBO = new ProductSpuBO(); // TODO 芋艿,后面改下
- productSpuBO.setId(productSpuDO.getId());
- return productSpuBO;
+ // 转换成 BO
+ return ProductSpuConvert.INSTANCE.convert(productSpuDO);
}
}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/vo/ProductCategoryVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/vo/ProductCategoryVO.java
index d6e1fbf0c..457517a34 100644
--- a/product/product-application/src/main/java/cn/iocoder/mall/product/vo/ProductCategoryVO.java
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/vo/ProductCategoryVO.java
@@ -1,4 +1,40 @@
package cn.iocoder.mall.product.vo;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel("商品分类")
public class ProductCategoryVO {
+
+ @ApiModelProperty(value = "分类编号", required = true, example = "1")
+ private Integer id;
+ @ApiModelProperty(value = "分类名", required = true, example = "手机")
+ private String name;
+ @ApiModelProperty(value = "分类图片", notes = "一般情况下,只有根分类才有图片", example = "http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg")
+ private String picUrl;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPicUrl() {
+ return picUrl;
+ }
+
+ public void setPicUrl(String picUrl) {
+ this.picUrl = picUrl;
+ }
+
}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/vo/RestResult.java b/product/product-application/src/main/java/cn/iocoder/mall/product/vo/RestResult.java
new file mode 100644
index 000000000..8f02472b1
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/vo/RestResult.java
@@ -0,0 +1,56 @@
+package cn.iocoder.mall.product.vo;
+
+public class RestResult {
+
+ /**
+ * 错误码
+ */
+ private Integer code;
+ /**
+ * 错误提示
+ */
+ private String message;
+ /**
+ * 返回数据
+ */
+ private Object data;
+
+ public static RestResult error(Integer code, String message) {
+ RestResult result = new RestResult();
+ result.code = code;
+ result.message = message;
+ return result;
+ }
+
+ public static RestResult ok(Object data) {
+ RestResult result = new RestResult();
+ result.code = 0;
+ result.data = data;
+ result.message = "";
+ return result;
+ }
+
+ public Integer getCode() {
+ return code;
+ }
+
+ public void setCode(Integer code) {
+ this.code = code;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+}
\ No newline at end of file
diff --git a/product/product-application/src/main/resources/mybatis/mapper/ProductCategoryMapper.xml b/product/product-application/src/main/resources/mybatis/mapper/ProductCategoryMapper.xml
index f3c090623..52f26f49e 100644
--- a/product/product-application/src/main/resources/mybatis/mapper/ProductCategoryMapper.xml
+++ b/product/product-application/src/main/resources/mybatis/mapper/ProductCategoryMapper.xml
@@ -1,12 +1,15 @@
-
-
-
+
+
+
-
\ No newline at end of file
+
+
diff --git a/product/product-application/src/main/resources/mybatis/mapper/ProductSkuMapper.xml b/product/product-application/src/main/resources/mybatis/mapper/ProductSkuMapper.xml
new file mode 100644
index 000000000..f3c090623
--- /dev/null
+++ b/product/product-application/src/main/resources/mybatis/mapper/ProductSkuMapper.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+ SELECT
+ id
+ FROM product_spu
+ WHERE id = #{id}
+
+
+
\ No newline at end of file