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