From 96a9f67a7fa0ecdb12f8789aacf81fab8db2440a Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 22 Jun 2022 08:46:00 +0800 Subject: [PATCH] =?UTF-8?q?:poop:=20=E4=BA=A7=E5=93=81=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/rymcu/forest/dto/ProductDTO.java | 23 ++++++++++++ .../java/com/rymcu/forest/entity/Product.java | 4 ++- .../rymcu/forest/mapper/ProductMapper.java | 17 +++++++++ .../rymcu/forest/service/ProductService.java | 30 ++++++++++++++++ .../service/impl/ProductServiceImpl.java | 36 +++++++++++++++++++ .../web/api/common/CommonApiController.java | 29 ++++++++++++--- .../web/api/product/ProductController.java | 23 ++++++++++++ src/main/java/mapper/ProductMapper.xml | 26 ++++++++++++++ 8 files changed, 182 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/rymcu/forest/dto/ProductDTO.java create mode 100644 src/main/java/com/rymcu/forest/service/ProductService.java create mode 100644 src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java create mode 100644 src/main/java/com/rymcu/forest/web/api/product/ProductController.java diff --git a/src/main/java/com/rymcu/forest/dto/ProductDTO.java b/src/main/java/com/rymcu/forest/dto/ProductDTO.java new file mode 100644 index 0000000..dd8c3cc --- /dev/null +++ b/src/main/java/com/rymcu/forest/dto/ProductDTO.java @@ -0,0 +1,23 @@ +package com.rymcu.forest.dto; + +import com.rymcu.forest.entity.Product; +import lombok.Data; + +/** + * Created on 2022/6/21 9:38. + * + * @author ronger + * @email ronger-x@outlook.com + * @packageName com.rymcu.forest.dto + */ +@Data +public class ProductDTO extends Product { + /** + * 文章内容 + */ + private String productContent; + /** + * 文章内容html + */ + private String productContentHtml; +} diff --git a/src/main/java/com/rymcu/forest/entity/Product.java b/src/main/java/com/rymcu/forest/entity/Product.java index 09dfa6a..fdbcf6c 100644 --- a/src/main/java/com/rymcu/forest/entity/Product.java +++ b/src/main/java/com/rymcu/forest/entity/Product.java @@ -3,6 +3,7 @@ package com.rymcu.forest.entity; import com.alibaba.fastjson.annotation.JSONField; import lombok.Data; +import javax.persistence.Column; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; @@ -24,7 +25,8 @@ public class Product implements Serializable, Cloneable { */ @Id @GeneratedValue(generator = "JDBC") - private Integer id; + @Column(name = "id") + private Integer idProduct; /** * 产品名 */ diff --git a/src/main/java/com/rymcu/forest/mapper/ProductMapper.java b/src/main/java/com/rymcu/forest/mapper/ProductMapper.java index 2386ac0..e03d4ae 100644 --- a/src/main/java/com/rymcu/forest/mapper/ProductMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/ProductMapper.java @@ -1,9 +1,12 @@ package com.rymcu.forest.mapper; import com.rymcu.forest.core.mapper.Mapper; +import com.rymcu.forest.dto.ProductDTO; import com.rymcu.forest.entity.Product; import org.apache.ibatis.annotations.Param; +import java.util.List; + /** * Created on 2022/6/13 21:53. * @@ -19,4 +22,18 @@ public interface ProductMapper extends Mapper { * @return */ Integer insertProductContent(@Param("idProduct") Integer idProduct, @Param("productContent") String productContent, @Param("productContentHtml") String productContentHtml); + + /** + * 查询产品列表 + * @return + */ + List selectProducts(); + + /** + * 获取产品详情 + * @param idProduct + * @param type + * @return + */ + ProductDTO selectProductDTOById(@Param("idProduct") Integer idProduct, @Param("type") Integer type); } diff --git a/src/main/java/com/rymcu/forest/service/ProductService.java b/src/main/java/com/rymcu/forest/service/ProductService.java new file mode 100644 index 0000000..37681d2 --- /dev/null +++ b/src/main/java/com/rymcu/forest/service/ProductService.java @@ -0,0 +1,30 @@ +package com.rymcu.forest.service; + +import com.rymcu.forest.core.service.Service; +import com.rymcu.forest.dto.ProductDTO; +import com.rymcu.forest.entity.Product; + +import java.util.List; + +/** + * Created on 2022/6/21 9:25. + * + * @author ronger + * @email ronger-x@outlook.com + * @packageName com.rymcu.forest.service + */ +public interface ProductService extends Service { + /** + * 查询产品列表 + * @return + */ + List findProducts(); + + /** + * 获取产品详情 + * @param idProduct + * @param type + * @return + */ + ProductDTO findProductDTOById(Integer idProduct, Integer type); +} diff --git a/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java new file mode 100644 index 0000000..3e62b56 --- /dev/null +++ b/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java @@ -0,0 +1,36 @@ +package com.rymcu.forest.service.impl; + +import com.rymcu.forest.core.service.AbstractService; +import com.rymcu.forest.dto.ProductDTO; +import com.rymcu.forest.entity.Product; +import com.rymcu.forest.mapper.ProductMapper; +import com.rymcu.forest.service.ProductService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * Created on 2022/6/21 9:26. + * + * @author ronger + * @email ronger-x@outlook.com + * @packageName com.rymcu.forest.service.impl + */ +@Service +public class ProductServiceImpl extends AbstractService implements ProductService { + + @Resource + private ProductMapper productMapper; + + @Override + public List findProducts() { + return productMapper.selectProducts(); + } + + @Override + public ProductDTO findProductDTOById(Integer idProduct, Integer type) { + ProductDTO productDTO = productMapper.selectProductDTOById(idProduct, type); + return productDTO; + } +} diff --git a/src/main/java/com/rymcu/forest/web/api/common/CommonApiController.java b/src/main/java/com/rymcu/forest/web/api/common/CommonApiController.java index 4d1035d..490a1c8 100644 --- a/src/main/java/com/rymcu/forest/web/api/common/CommonApiController.java +++ b/src/main/java/com/rymcu/forest/web/api/common/CommonApiController.java @@ -8,11 +8,7 @@ import com.rymcu.forest.core.result.GlobalResultMessage; import com.rymcu.forest.core.service.log.annotation.VisitLogger; import com.rymcu.forest.dto.*; import com.rymcu.forest.entity.User; -import com.rymcu.forest.service.ArticleService; -import com.rymcu.forest.service.JavaMailService; -import com.rymcu.forest.service.PortfolioService; -import com.rymcu.forest.service.UserService; -import com.rymcu.forest.util.UserUtils; +import com.rymcu.forest.service.*; import com.rymcu.forest.util.Utils; import org.springframework.web.bind.annotation.*; @@ -37,6 +33,8 @@ public class CommonApiController { private ArticleService articleService; @Resource private PortfolioService portfolioService; + @Resource + private ProductService productService; @GetMapping("/get-email-code") public GlobalResult> getEmailCode(@RequestParam("email") String email) throws MessagingException { @@ -150,4 +148,25 @@ public class CommonApiController { map.put("pagination", pagination); return GlobalResultGenerator.genSuccessResult(map); } + + @GetMapping("/products") + public GlobalResult products(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows) { + PageHelper.startPage(page, rows); + List list = productService.findProducts(); + PageInfo pageInfo = new PageInfo(list); + Map map = new HashMap(2); + map.put("products", pageInfo.getList()); + Map pagination = Utils.getPagination(pageInfo); + map.put("pagination", pagination); + return GlobalResultGenerator.genSuccessResult(map); + } + + @GetMapping("/product/{id}") + @VisitLogger + public GlobalResult> product(@PathVariable Integer id) { + ProductDTO productDTO = productService.findProductDTOById(id, 1); + Map map = new HashMap<>(1); + map.put("product", productDTO); + return GlobalResultGenerator.genSuccessResult(map); + } } diff --git a/src/main/java/com/rymcu/forest/web/api/product/ProductController.java b/src/main/java/com/rymcu/forest/web/api/product/ProductController.java new file mode 100644 index 0000000..6675a1f --- /dev/null +++ b/src/main/java/com/rymcu/forest/web/api/product/ProductController.java @@ -0,0 +1,23 @@ +package com.rymcu.forest.web.api.product; + +import com.rymcu.forest.service.ProductService; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * Created on 2022/6/21 9:30. + * + * @author ronger + * @email ronger-x@outlook.com + * @packageName com.rymcu.forest.web.api.product + */ +@RestController +@RequestMapping("/api/v1/product") +public class ProductController { + + @Resource + private ProductService productService; + +} diff --git a/src/main/java/mapper/ProductMapper.xml b/src/main/java/mapper/ProductMapper.xml index 0f2efe3..438aca3 100644 --- a/src/main/java/mapper/ProductMapper.xml +++ b/src/main/java/mapper/ProductMapper.xml @@ -1,6 +1,14 @@ + + + + + + + + insert into forest_product_content(id_product, product_content, @@ -13,4 +21,22 @@ sysdate(), sysdate()) + + \ No newline at end of file