🎨 产品信息维护接口
This commit is contained in:
parent
82fb5300bb
commit
4a34f85799
@ -3,10 +3,7 @@ package com.rymcu.forest.entity;
|
|||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.*;
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@ -19,7 +16,7 @@ import java.util.Date;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table(name = "forest_product")
|
@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 Integer status;
|
||||||
|
|
||||||
private String tags;
|
private String tags;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private String productImgType;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import java.util.Date;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table(name = "forest_product_content")
|
@Table(name = "forest_product_content")
|
||||||
public class ProductContent implements Serializable, Cloneable {
|
public class ProductContent implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 产品表主键
|
* 产品表主键
|
||||||
*/
|
*/
|
||||||
|
@ -22,7 +22,7 @@ public interface ProductMapper extends Mapper<Product> {
|
|||||||
* @param productContentHtml 产品详情 html
|
* @param productContentHtml 产品详情 html
|
||||||
* @return 更新数量
|
* @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<Product> {
|
|||||||
* @return 产品信息
|
* @return 产品信息
|
||||||
*/
|
*/
|
||||||
List<ProductDTO> selectOnlineProducts();
|
List<ProductDTO> 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);
|
||||||
}
|
}
|
||||||
|
@ -16,23 +16,35 @@ import java.util.List;
|
|||||||
public interface ProductService extends Service<Product> {
|
public interface ProductService extends Service<Product> {
|
||||||
/**
|
/**
|
||||||
* 查询产品列表
|
* 查询产品列表
|
||||||
*
|
* @return 产品列表
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
List<ProductDTO> findProducts();
|
List<ProductDTO> findProducts();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取产品详情
|
* 获取产品详情
|
||||||
*
|
*
|
||||||
* @param idProduct
|
* @param idProduct 产品主键
|
||||||
* @param type
|
* @param type 数据类型
|
||||||
* @return
|
* @return 产品详情
|
||||||
*/
|
*/
|
||||||
ProductDTO findProductDTOById(Long idProduct, Integer type);
|
ProductDTO findProductDTOById(Long idProduct, Integer type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取在线商品
|
* 获取在线商品
|
||||||
* @return
|
* @return 产品列表
|
||||||
*/
|
*/
|
||||||
List<ProductDTO> findOnlineProducts();
|
List<ProductDTO> findOnlineProducts();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param product 产品信息
|
||||||
|
* @return 产品信息
|
||||||
|
*/
|
||||||
|
Product postProduct(ProductDTO product);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param idProduct 产品主键
|
||||||
|
* @param status 状态
|
||||||
|
* @return 更新成功状态
|
||||||
|
*/
|
||||||
|
boolean updateStatus(Long idProduct, Integer status);
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,13 @@ import com.rymcu.forest.dto.ProductDTO;
|
|||||||
import com.rymcu.forest.entity.Product;
|
import com.rymcu.forest.entity.Product;
|
||||||
import com.rymcu.forest.mapper.ProductMapper;
|
import com.rymcu.forest.mapper.ProductMapper;
|
||||||
import com.rymcu.forest.service.ProductService;
|
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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,4 +41,45 @@ public class ProductServiceImpl extends AbstractService<Product> implements Prod
|
|||||||
public List<ProductDTO> findOnlineProducts() {
|
public List<ProductDTO> findOnlineProducts() {
|
||||||
return productMapper.selectOnlineProducts();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ public class AdminArticleController {
|
|||||||
|
|
||||||
@PatchMapping("/update-status")
|
@PatchMapping("/update-status")
|
||||||
public GlobalResult<Boolean> updateArticleStatus(@RequestBody ArticleUpdateStatusDTO article) {
|
public GlobalResult<Boolean> updateArticleStatus(@RequestBody ArticleUpdateStatusDTO article) {
|
||||||
Long idArticle = article.getIdArticle();;
|
Long idArticle = article.getIdArticle();
|
||||||
String articleStatus = article.getArticleStatus();
|
String articleStatus = article.getArticleStatus();
|
||||||
String remarks = article.getRemarks();
|
String remarks = article.getRemarks();
|
||||||
return GlobalResultGenerator.genSuccessResult(articleService.updateStatus(idArticle, articleStatus, remarks));
|
return GlobalResultGenerator.genSuccessResult(articleService.updateStatus(idArticle, articleStatus, remarks));
|
||||||
|
@ -2,8 +2,15 @@ package com.rymcu.forest.web.api.product;
|
|||||||
|
|
||||||
import com.rymcu.forest.core.result.GlobalResult;
|
import com.rymcu.forest.core.result.GlobalResult;
|
||||||
import com.rymcu.forest.core.result.GlobalResultGenerator;
|
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.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.service.ProductService;
|
||||||
|
import com.rymcu.forest.util.UserUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@ -22,12 +29,32 @@ public class ProductController {
|
|||||||
@Resource
|
@Resource
|
||||||
private ProductService productService;
|
private ProductService productService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/detail/{idProduct}")
|
@GetMapping("/detail/{idProduct}")
|
||||||
public GlobalResult<ProductDTO> detail(@PathVariable Long idProduct, @RequestParam(defaultValue = "2") Integer type) {
|
public GlobalResult<ProductDTO> detail(@PathVariable Long idProduct, @RequestParam(defaultValue = "2") Integer type) {
|
||||||
ProductDTO dto = productService.findProductDTOById(idProduct, type);
|
ProductDTO dto = productService.findProductDTOById(idProduct, type);
|
||||||
return GlobalResultGenerator.genSuccessResult(dto);
|
return GlobalResultGenerator.genSuccessResult(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/post")
|
||||||
|
public GlobalResult<Product> add(@RequestBody ProductDTO product) {
|
||||||
|
Product newProduct = productService.postProduct(product);
|
||||||
|
return GlobalResultGenerator.genSuccessResult(newProduct);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/post")
|
||||||
|
public GlobalResult<Product> 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<Boolean> updateStatus(@RequestBody Product product) {
|
||||||
|
boolean flag = productService.updateStatus(product.getIdProduct(), product.getStatus());
|
||||||
|
return GlobalResultGenerator.genSuccessResult(flag);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,18 @@
|
|||||||
sysdate(),
|
sysdate(),
|
||||||
sysdate())
|
sysdate())
|
||||||
</insert>
|
</insert>
|
||||||
|
<update id="updateProductContent">
|
||||||
|
update forest_product_content
|
||||||
|
set product_content = #{productContent},
|
||||||
|
product_content_html = #{productContentHtml},
|
||||||
|
updated_time = sysdate()
|
||||||
|
where id_product = #{idProduct}
|
||||||
|
</update>
|
||||||
|
<update id="updateStatus">
|
||||||
|
update forest_product
|
||||||
|
set status = #{status}
|
||||||
|
where id_product = #{idProduct}
|
||||||
|
</update>
|
||||||
<select id="selectProducts" resultMap="DTOResultMap">
|
<select id="selectProducts" resultMap="DTOResultMap">
|
||||||
select id, product_title, product_img_url, tags, product_description, product_price, weights, status
|
select id, product_title, product_img_url, tags, product_description, product_price, weights, status
|
||||||
from forest_product
|
from forest_product
|
||||||
|
Loading…
Reference in New Issue
Block a user