💩 产品功能代码
This commit is contained in:
parent
9dc4bba198
commit
96a9f67a7f
23
src/main/java/com/rymcu/forest/dto/ProductDTO.java
Normal file
23
src/main/java/com/rymcu/forest/dto/ProductDTO.java
Normal file
@ -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;
|
||||
}
|
@ -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;
|
||||
/**
|
||||
* 产品名
|
||||
*/
|
||||
|
@ -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<Product> {
|
||||
* @return
|
||||
*/
|
||||
Integer insertProductContent(@Param("idProduct") Integer idProduct, @Param("productContent") String productContent, @Param("productContentHtml") String productContentHtml);
|
||||
|
||||
/**
|
||||
* 查询产品列表
|
||||
* @return
|
||||
*/
|
||||
List<ProductDTO> selectProducts();
|
||||
|
||||
/**
|
||||
* 获取产品详情
|
||||
* @param idProduct
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
ProductDTO selectProductDTOById(@Param("idProduct") Integer idProduct, @Param("type") Integer type);
|
||||
}
|
||||
|
30
src/main/java/com/rymcu/forest/service/ProductService.java
Normal file
30
src/main/java/com/rymcu/forest/service/ProductService.java
Normal file
@ -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<Product> {
|
||||
/**
|
||||
* 查询产品列表
|
||||
* @return
|
||||
*/
|
||||
List<ProductDTO> findProducts();
|
||||
|
||||
/**
|
||||
* 获取产品详情
|
||||
* @param idProduct
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
ProductDTO findProductDTOById(Integer idProduct, Integer type);
|
||||
}
|
@ -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<Product> implements ProductService {
|
||||
|
||||
@Resource
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Override
|
||||
public List<ProductDTO> findProducts() {
|
||||
return productMapper.selectProducts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductDTO findProductDTOById(Integer idProduct, Integer type) {
|
||||
ProductDTO productDTO = productMapper.selectProductDTOById(idProduct, type);
|
||||
return productDTO;
|
||||
}
|
||||
}
|
@ -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<Map<String, String>> 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<ProductDTO> list = productService.findProducts();
|
||||
PageInfo<ProductDTO> 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<Map<String, Object>> product(@PathVariable Integer id) {
|
||||
ProductDTO productDTO = productService.findProductDTOById(id, 1);
|
||||
Map<String, Object> map = new HashMap<>(1);
|
||||
map.put("product", productDTO);
|
||||
return GlobalResultGenerator.genSuccessResult(map);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
}
|
@ -1,6 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.rymcu.forest.mapper.ProductMapper">
|
||||
<resultMap id="DTOResultMap" type="com.rymcu.forest.dto.ProductDTO">
|
||||
<id column="id" property="idProduct"></id>
|
||||
<result column="product_title" property="productTitle"></result>
|
||||
<result column="product_img_url" property="productImgUrl"></result>
|
||||
<result column="product_description" property="productDescription"></result>
|
||||
<result column="product_price" property="productPrice"></result>
|
||||
<result column="product_content" property="productContent"></result>
|
||||
</resultMap>
|
||||
<insert id="insertProductContent">
|
||||
insert into forest_product_content(id_product,
|
||||
product_content,
|
||||
@ -13,4 +21,22 @@
|
||||
sysdate(),
|
||||
sysdate())
|
||||
</insert>
|
||||
<select id="selectProducts" resultMap="DTOResultMap">
|
||||
select *
|
||||
from forest_product
|
||||
order by weights
|
||||
</select>
|
||||
<select id="selectProductDTOById" resultMap="DTOResultMap">
|
||||
select id, product_title,
|
||||
<choose>
|
||||
<when test="type == 1">
|
||||
product_content_html as product_content,
|
||||
</when>
|
||||
<otherwise>
|
||||
product_content,
|
||||
</otherwise>
|
||||
</choose>
|
||||
product_img_url from forest_product fp join forest_product_content fpc on fp.id = fpc.id_product
|
||||
where id = #{idProduct}
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user