From 96e36b89891d32c5b469a80d5ac77771151f235e Mon Sep 17 00:00:00 2001 From: ronger Date: Sat, 3 Feb 2024 11:16:51 +0800 Subject: [PATCH 1/4] =?UTF-8?q?:art:=20=E4=BA=A7=E5=93=81=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=A2=9E=E5=8A=A0=E6=A0=87=E7=AD=BE=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/rymcu/forest/dto/ProductDTO.java | 2 ++ src/main/java/com/rymcu/forest/entity/Product.java | 2 ++ .../com/rymcu/forest/service/impl/ProductServiceImpl.java | 3 +-- src/main/java/mapper/ProductMapper.xml | 5 +++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/rymcu/forest/dto/ProductDTO.java b/src/main/java/com/rymcu/forest/dto/ProductDTO.java index dd8c3cc..7123d04 100644 --- a/src/main/java/com/rymcu/forest/dto/ProductDTO.java +++ b/src/main/java/com/rymcu/forest/dto/ProductDTO.java @@ -2,6 +2,7 @@ package com.rymcu.forest.dto; import com.rymcu.forest.entity.Product; import lombok.Data; +import lombok.EqualsAndHashCode; /** * Created on 2022/6/21 9:38. @@ -11,6 +12,7 @@ import lombok.Data; * @packageName com.rymcu.forest.dto */ @Data +@EqualsAndHashCode(callSuper=false) public class ProductDTO extends Product { /** * 文章内容 diff --git a/src/main/java/com/rymcu/forest/entity/Product.java b/src/main/java/com/rymcu/forest/entity/Product.java index b5e312d..0686465 100644 --- a/src/main/java/com/rymcu/forest/entity/Product.java +++ b/src/main/java/com/rymcu/forest/entity/Product.java @@ -57,4 +57,6 @@ public class Product implements Serializable, Cloneable { */ @JSONField(format = "yyyy-MM-dd HH:mm:ss") private Date updatedTime; + + private String tags; } diff --git a/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java index 3e62b56..b6ddaa6 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java @@ -30,7 +30,6 @@ public class ProductServiceImpl extends AbstractService implements Prod @Override public ProductDTO findProductDTOById(Integer idProduct, Integer type) { - ProductDTO productDTO = productMapper.selectProductDTOById(idProduct, type); - return productDTO; + return productMapper.selectProductDTOById(idProduct, type); } } diff --git a/src/main/java/mapper/ProductMapper.xml b/src/main/java/mapper/ProductMapper.xml index 438aca3..3a8230f 100644 --- a/src/main/java/mapper/ProductMapper.xml +++ b/src/main/java/mapper/ProductMapper.xml @@ -8,6 +8,7 @@ + insert into forest_product_content(id_product, @@ -27,7 +28,7 @@ order by weights - \ No newline at end of file + From 20610745710775ebe9d7e2da6d8decdcbdc04182 Mon Sep 17 00:00:00 2001 From: ronger Date: Fri, 16 Feb 2024 14:23:03 +0800 Subject: [PATCH 2/4] =?UTF-8?q?:art:=20=E4=BA=A7=E5=93=81=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=BC=96=E8=BE=91=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/rymcu/forest/mapper/ProductMapper.java | 2 +- .../com/rymcu/forest/service/ProductService.java | 2 +- .../forest/service/impl/ProductServiceImpl.java | 2 +- .../forest/web/api/product/ProductController.java | 14 ++++++++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/rymcu/forest/mapper/ProductMapper.java b/src/main/java/com/rymcu/forest/mapper/ProductMapper.java index 4fb8757..173657a 100644 --- a/src/main/java/com/rymcu/forest/mapper/ProductMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/ProductMapper.java @@ -38,5 +38,5 @@ public interface ProductMapper extends Mapper { * @param type * @return */ - ProductDTO selectProductDTOById(@Param("idProduct") Integer idProduct, @Param("type") Integer type); + ProductDTO selectProductDTOById(@Param("idProduct") Long 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 index 3851c37..fa14811 100644 --- a/src/main/java/com/rymcu/forest/service/ProductService.java +++ b/src/main/java/com/rymcu/forest/service/ProductService.java @@ -28,5 +28,5 @@ public interface ProductService extends Service { * @param type * @return */ - ProductDTO findProductDTOById(Integer idProduct, Integer type); + ProductDTO findProductDTOById(Long 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 index b6ddaa6..35f53b5 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java @@ -29,7 +29,7 @@ public class ProductServiceImpl extends AbstractService implements Prod } @Override - public ProductDTO findProductDTOById(Integer idProduct, Integer type) { + public ProductDTO findProductDTOById(Long idProduct, Integer type) { return productMapper.selectProductDTOById(idProduct, type); } } 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 index 6675a1f..c3229ae 100644 --- a/src/main/java/com/rymcu/forest/web/api/product/ProductController.java +++ b/src/main/java/com/rymcu/forest/web/api/product/ProductController.java @@ -1,8 +1,10 @@ package com.rymcu.forest.web.api.product; +import com.rymcu.forest.core.result.GlobalResult; +import com.rymcu.forest.core.result.GlobalResultGenerator; +import com.rymcu.forest.dto.ProductDTO; import com.rymcu.forest.service.ProductService; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -20,4 +22,12 @@ public class ProductController { @Resource private ProductService productService; + + + @GetMapping("/detail/{idProduct}") + public GlobalResult detail(@PathVariable Long idProduct, @RequestParam(defaultValue = "2") Integer type) { + ProductDTO dto = productService.findProductDTOById(idProduct, type); + return GlobalResultGenerator.genSuccessResult(dto); + } + } From 82fb5300bb6f2e77c7575b0306aea2c216b8d5f2 Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 28 Feb 2024 09:10:50 +0800 Subject: [PATCH 3/4] =?UTF-8?q?:art:=20=E4=BA=A7=E5=93=81=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/rymcu/forest/entity/Product.java | 2 ++ .../rymcu/forest/mapper/ProductMapper.java | 22 ++++++++++++------- .../rymcu/forest/service/ProductService.java | 6 +++++ .../service/impl/ProductServiceImpl.java | 5 +++++ .../web/api/common/CommonApiController.java | 4 ++-- src/main/java/mapper/ProductMapper.xml | 12 ++++++++-- 6 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/rymcu/forest/entity/Product.java b/src/main/java/com/rymcu/forest/entity/Product.java index 0686465..d6fcded 100644 --- a/src/main/java/com/rymcu/forest/entity/Product.java +++ b/src/main/java/com/rymcu/forest/entity/Product.java @@ -58,5 +58,7 @@ public class Product implements Serializable, Cloneable { @JSONField(format = "yyyy-MM-dd HH:mm:ss") private Date updatedTime; + private Integer status; + private String tags; } diff --git a/src/main/java/com/rymcu/forest/mapper/ProductMapper.java b/src/main/java/com/rymcu/forest/mapper/ProductMapper.java index 173657a..ef57bd0 100644 --- a/src/main/java/com/rymcu/forest/mapper/ProductMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/ProductMapper.java @@ -17,26 +17,32 @@ public interface ProductMapper extends Mapper { /** * 保存产品详情 * - * @param idProduct - * @param productContent - * @param productContentHtml - * @return + * @param idProduct 产品主键 + * @param productContent 产品详情 markdown + * @param productContentHtml 产品详情 html + * @return 更新数量 */ Integer insertProductContent(@Param("idProduct") Integer idProduct, @Param("productContent") String productContent, @Param("productContentHtml") String productContentHtml); /** * 查询产品列表 * - * @return + * @return 产品列表 */ List selectProducts(); /** * 获取产品详情 * - * @param idProduct - * @param type - * @return + * @param idProduct 产品 ID + * @param type 获取类型 + * @return 产品信息 */ ProductDTO selectProductDTOById(@Param("idProduct") Long idProduct, @Param("type") Integer type); + + /** + * 获取在线产品 + * @return 产品信息 + */ + List selectOnlineProducts(); } diff --git a/src/main/java/com/rymcu/forest/service/ProductService.java b/src/main/java/com/rymcu/forest/service/ProductService.java index fa14811..1cf4d47 100644 --- a/src/main/java/com/rymcu/forest/service/ProductService.java +++ b/src/main/java/com/rymcu/forest/service/ProductService.java @@ -29,4 +29,10 @@ public interface ProductService extends Service { * @return */ ProductDTO findProductDTOById(Long idProduct, Integer type); + + /** + * 获取在线商品 + * @return + */ + List findOnlineProducts(); } diff --git a/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java index 35f53b5..64c8cf8 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java @@ -32,4 +32,9 @@ public class ProductServiceImpl extends AbstractService implements Prod public ProductDTO findProductDTOById(Long idProduct, Integer type) { return productMapper.selectProductDTOById(idProduct, type); } + + @Override + public List findOnlineProducts() { + return productMapper.selectOnlineProducts(); + } } 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 8d7c562..5a3bdd9 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 @@ -141,14 +141,14 @@ public class CommonApiController { @GetMapping("/products") public GlobalResult> products(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows) { PageHelper.startPage(page, rows); - List list = productService.findProducts(); + List list = productService.findOnlineProducts(); PageInfo pageInfo = new PageInfo<>(list); return GlobalResultGenerator.genSuccessResult(pageInfo); } @GetMapping("/product/{id}") @VisitLogger - public GlobalResult product(@PathVariable Integer id) { + public GlobalResult product(@PathVariable Long id) { ProductDTO productDTO = productService.findProductDTOById(id, 1); return GlobalResultGenerator.genSuccessResult(productDTO); } diff --git a/src/main/java/mapper/ProductMapper.xml b/src/main/java/mapper/ProductMapper.xml index 3a8230f..2c07b6b 100644 --- a/src/main/java/mapper/ProductMapper.xml +++ b/src/main/java/mapper/ProductMapper.xml @@ -8,6 +8,8 @@ + + @@ -23,12 +25,12 @@ sysdate()) + From 4a34f8579969c2a4595f3b29b2ea533cb183971b Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 28 Feb 2024 09:43:32 +0800 Subject: [PATCH 4/4] =?UTF-8?q?:art:=20=E4=BA=A7=E5=93=81=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=BB=B4=E6=8A=A4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/rymcu/forest/entity/Product.java | 10 ++--- .../rymcu/forest/entity/ProductContent.java | 2 +- .../rymcu/forest/mapper/ProductMapper.java | 19 +++++++- .../rymcu/forest/service/ProductService.java | 24 +++++++--- .../service/impl/ProductServiceImpl.java | 45 +++++++++++++++++++ .../web/api/admin/AdminArticleController.java | 2 +- .../web/api/product/ProductController.java | 31 ++++++++++++- src/main/java/mapper/ProductMapper.xml | 12 +++++ 8 files changed, 129 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/rymcu/forest/entity/Product.java b/src/main/java/com/rymcu/forest/entity/Product.java index d6fcded..1f2e63d 100644 --- a/src/main/java/com/rymcu/forest/entity/Product.java +++ b/src/main/java/com/rymcu/forest/entity/Product.java @@ -3,10 +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; +import javax.persistence.*; import java.io.Serializable; import java.util.Date; @@ -19,7 +16,7 @@ import java.util.Date; */ @Data @Table(name = "forest_product") -public class Product implements Serializable, Cloneable { +public class Product implements Serializable { /** * 主键 */ @@ -61,4 +58,7 @@ public class Product implements Serializable, Cloneable { private Integer status; private String tags; + + @Transient + private String productImgType; } diff --git a/src/main/java/com/rymcu/forest/entity/ProductContent.java b/src/main/java/com/rymcu/forest/entity/ProductContent.java index 8559ecb..701e874 100644 --- a/src/main/java/com/rymcu/forest/entity/ProductContent.java +++ b/src/main/java/com/rymcu/forest/entity/ProductContent.java @@ -16,7 +16,7 @@ import java.util.Date; */ @Data @Table(name = "forest_product_content") -public class ProductContent implements Serializable, Cloneable { +public class ProductContent implements Serializable { /** * 产品表主键 */ diff --git a/src/main/java/com/rymcu/forest/mapper/ProductMapper.java b/src/main/java/com/rymcu/forest/mapper/ProductMapper.java index ef57bd0..bb77426 100644 --- a/src/main/java/com/rymcu/forest/mapper/ProductMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/ProductMapper.java @@ -22,7 +22,7 @@ public interface ProductMapper extends Mapper { * @param productContentHtml 产品详情 html * @return 更新数量 */ - Integer insertProductContent(@Param("idProduct") Integer idProduct, @Param("productContent") String productContent, @Param("productContentHtml") String productContentHtml); + Integer insertProductContent(@Param("idProduct") Long idProduct, @Param("productContent") String productContent, @Param("productContentHtml") String productContentHtml); /** * 查询产品列表 @@ -45,4 +45,21 @@ public interface ProductMapper extends Mapper { * @return 产品信息 */ List selectOnlineProducts(); + + /** + * 保存产品详情 + * + * @param idProduct 产品主键 + * @param productContent 产品详情 markdown + * @param productContentHtml 产品详情 html + * @return 更新数量 + */ + Integer updateProductContent(@Param("idProduct") Long idProduct, @Param("productContent") String productContent, @Param("productContentHtml") String productContentHtml); + + /** + * @param idProduct 产品主键 + * @param status 状态 + * @return 更新成功状态 + */ + int updateStatus(@Param("idProduct") Long idProduct, @Param("status") Integer status); } diff --git a/src/main/java/com/rymcu/forest/service/ProductService.java b/src/main/java/com/rymcu/forest/service/ProductService.java index 1cf4d47..d9d3a88 100644 --- a/src/main/java/com/rymcu/forest/service/ProductService.java +++ b/src/main/java/com/rymcu/forest/service/ProductService.java @@ -16,23 +16,35 @@ import java.util.List; public interface ProductService extends Service { /** * 查询产品列表 - * - * @return + * @return 产品列表 */ List findProducts(); /** * 获取产品详情 * - * @param idProduct - * @param type - * @return + * @param idProduct 产品主键 + * @param type 数据类型 + * @return 产品详情 */ ProductDTO findProductDTOById(Long idProduct, Integer type); /** * 获取在线商品 - * @return + * @return 产品列表 */ List findOnlineProducts(); + + /** + * @param product 产品信息 + * @return 产品信息 + */ + Product postProduct(ProductDTO product); + + /** + * @param idProduct 产品主键 + * @param status 状态 + * @return 更新成功状态 + */ + boolean updateStatus(Long idProduct, Integer status); } diff --git a/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java index 64c8cf8..789cf93 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ProductServiceImpl.java @@ -5,9 +5,13 @@ 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 com.rymcu.forest.util.BeanCopierUtil; +import com.rymcu.forest.web.api.common.UploadController; +import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.Date; import java.util.List; /** @@ -37,4 +41,45 @@ public class ProductServiceImpl extends AbstractService implements Prod public List findOnlineProducts() { return productMapper.selectOnlineProducts(); } + + /** + * @param product 产品信息 + * @return 产品信息 + */ + @Override + public Product postProduct(ProductDTO product) { + boolean isUpdate = product.getIdProduct() > 0; + if (StringUtils.isNotBlank(product.getProductImgType())) { + String headImgUrl = UploadController.uploadBase64File(product.getProductImgUrl(), 0); + product.setProductImgUrl(headImgUrl); + } + Product newProduct; + if (isUpdate) { + newProduct = productMapper.selectByPrimaryKey(product.getIdProduct()); + newProduct.setProductImgUrl(product.getProductImgUrl()); + newProduct.setProductTitle(product.getProductTitle()); + newProduct.setProductPrice(product.getProductPrice()); + newProduct.setProductDescription(product.getProductDescription()); + productMapper.updateByPrimaryKeySelective(newProduct); + // 更新产品详情 + productMapper.updateProductContent(newProduct.getIdProduct(), product.getProductContent(), product.getProductContentHtml()); + } else { + newProduct = new Product(); + BeanCopierUtil.convert(product, newProduct); + newProduct.setCreatedTime(new Date()); + // 创建产品详情 + productMapper.insertProductContent(newProduct.getIdProduct(), product.getProductContent(), product.getProductContentHtml()); + } + return newProduct; + } + + /** + * @param idProduct 产品主键 + * @param status 状态 + * @return 更新成功状态 + */ + @Override + public boolean updateStatus(Long idProduct, Integer status) { + return productMapper.updateStatus(idProduct, status) > 0; + } } diff --git a/src/main/java/com/rymcu/forest/web/api/admin/AdminArticleController.java b/src/main/java/com/rymcu/forest/web/api/admin/AdminArticleController.java index e56de0b..ab5c89e 100644 --- a/src/main/java/com/rymcu/forest/web/api/admin/AdminArticleController.java +++ b/src/main/java/com/rymcu/forest/web/api/admin/AdminArticleController.java @@ -34,7 +34,7 @@ public class AdminArticleController { @PatchMapping("/update-status") public GlobalResult updateArticleStatus(@RequestBody ArticleUpdateStatusDTO article) { - Long idArticle = article.getIdArticle();; + Long idArticle = article.getIdArticle(); String articleStatus = article.getArticleStatus(); String remarks = article.getRemarks(); return GlobalResultGenerator.genSuccessResult(articleService.updateStatus(idArticle, articleStatus, remarks)); 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 index c3229ae..7873aea 100644 --- a/src/main/java/com/rymcu/forest/web/api/product/ProductController.java +++ b/src/main/java/com/rymcu/forest/web/api/product/ProductController.java @@ -2,8 +2,15 @@ package com.rymcu.forest.web.api.product; import com.rymcu.forest.core.result.GlobalResult; import com.rymcu.forest.core.result.GlobalResultGenerator; +import com.rymcu.forest.core.service.security.annotation.AuthorshipInterceptor; +import com.rymcu.forest.core.service.security.annotation.SecurityInterceptor; import com.rymcu.forest.dto.ProductDTO; +import com.rymcu.forest.entity.Product; +import com.rymcu.forest.entity.Product; +import com.rymcu.forest.entity.User; +import com.rymcu.forest.enumerate.Module; import com.rymcu.forest.service.ProductService; +import com.rymcu.forest.util.UserUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -22,12 +29,32 @@ public class ProductController { @Resource private ProductService productService; - - @GetMapping("/detail/{idProduct}") public GlobalResult detail(@PathVariable Long idProduct, @RequestParam(defaultValue = "2") Integer type) { ProductDTO dto = productService.findProductDTOById(idProduct, type); return GlobalResultGenerator.genSuccessResult(dto); } + @PostMapping("/post") + public GlobalResult add(@RequestBody ProductDTO product) { + Product newProduct = productService.postProduct(product); + return GlobalResultGenerator.genSuccessResult(newProduct); + } + + @PutMapping("/post") + public GlobalResult update(@RequestBody ProductDTO product) { + if (product.getIdProduct() == null || product.getIdProduct() == 0) { + throw new IllegalArgumentException("产品主键参数异常!"); + } + Product oldProduct = productService.postProduct(product); + return GlobalResultGenerator.genSuccessResult(oldProduct); + } + + + @PatchMapping("/update-status") + public GlobalResult updateStatus(@RequestBody Product product) { + boolean flag = productService.updateStatus(product.getIdProduct(), product.getStatus()); + return GlobalResultGenerator.genSuccessResult(flag); + } + } diff --git a/src/main/java/mapper/ProductMapper.xml b/src/main/java/mapper/ProductMapper.xml index 2c07b6b..ddf51f6 100644 --- a/src/main/java/mapper/ProductMapper.xml +++ b/src/main/java/mapper/ProductMapper.xml @@ -24,6 +24,18 @@ sysdate(), sysdate()) + + update forest_product_content + set product_content = #{productContent}, + product_content_html = #{productContentHtml}, + updated_time = sysdate() + where id_product = #{idProduct} + + + update forest_product + set status = #{status} + where id_product = #{idProduct} +