13 changed files with 627 additions and 2 deletions
@ -0,0 +1,80 @@ |
|||
package com.bnyer.img.controller; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.bnyer.common.core.web.controller.BaseController; |
|||
import com.bnyer.common.core.web.domain.AjaxResult; |
|||
import com.bnyer.common.core.web.page.TableDataInfo; |
|||
import com.bnyer.img.domain.Product; |
|||
import com.bnyer.img.dto.ProductDto; |
|||
import com.bnyer.img.dto.ProductPageDto; |
|||
import com.bnyer.img.dto.StatusDto; |
|||
import com.bnyer.img.service.ProductService; |
|||
import com.github.pagehelper.PageHelper; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import io.swagger.annotations.ApiParam; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Api(value = "【图文平台】产品接口",tags = "【图文平台】产品接口") |
|||
@RestController |
|||
@RequestMapping("/img/product") |
|||
@Slf4j |
|||
public class ProductController extends BaseController { |
|||
|
|||
@Autowired |
|||
private ProductService productService; |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="查询产品分页") |
|||
@PostMapping("/page") |
|||
public TableDataInfo pageProduct(@RequestBody @ApiParam("分页对象") ProductPageDto dto){ |
|||
PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); |
|||
List<Product> products = productService.queryPage(dto); |
|||
return getDataTable(products); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="新增产品") |
|||
@PostMapping(value = "/insert") |
|||
public AjaxResult insertProduct(@Validated @RequestBody @ApiParam("产品对象") ProductDto dto){ |
|||
log.debug("【图文平台后台】新增产品参数为:{}", JSON.toJSONString(dto)); |
|||
return AjaxResult.success(productService.insert(dto.extractParam())); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="修改产品") |
|||
@PostMapping(value = "/update") |
|||
public AjaxResult updateProduct(@Validated @RequestBody @ApiParam("产品对象")ProductDto dto){ |
|||
log.debug("【图文平台后台】修改产品参数为:{}", JSON.toJSONString(dto)); |
|||
return AjaxResult.success(productService.update(dto.extractParam())); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="删除产品") |
|||
@DeleteMapping(value = "/delete/{ids}") |
|||
public AjaxResult deleteProduct(@PathVariable @ApiParam("主键ids") List<Long> ids){ |
|||
log.debug("【图文平台后台】删除产品参数为:{}", JSON.toJSONString(ids)); |
|||
return AjaxResult.success(productService.delete(ids)); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="查询产品详情") |
|||
@GetMapping(value = "/details/{id}") |
|||
public AjaxResult detailsProduct(@PathVariable @ApiParam("主键id") Long id){ |
|||
log.debug("【图文平台后台】查询产品详情参数为:{}", id); |
|||
return AjaxResult.success(productService.details(id)); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="变更type显示状态") |
|||
@PostMapping(value = "/changeStatus") |
|||
public AjaxResult changeStatus(@Validated @RequestBody @ApiParam("type状态对象") StatusDto dto){ |
|||
log.debug("【图文平台后台】变更type参数为:{}", JSON.toJSONString(dto)); |
|||
return AjaxResult.success(productService.changeStatus(dto.getId(),dto.getStatus())); |
|||
} |
|||
} |
|||
@ -0,0 +1,104 @@ |
|||
package com.bnyer.img.domain; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
import java.util.Date; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Getter; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.Setter; |
|||
import lombok.ToString; |
|||
|
|||
@ApiModel(value="com-bnyer-img-domain-Product") |
|||
@Getter |
|||
@Setter |
|||
@ToString |
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
@TableName(value = "img_product") |
|||
public class Product extends BaseDomain { |
|||
/** |
|||
* 主键id |
|||
*/ |
|||
@TableId(value = "id", type = IdType.AUTO) |
|||
@ApiModelProperty(value="主键id") |
|||
private Long id; |
|||
|
|||
/** |
|||
* 商品名称 |
|||
*/ |
|||
@TableField(value = "product_name") |
|||
@ApiModelProperty(value="商品名称") |
|||
private String productName; |
|||
|
|||
/** |
|||
* 商品原价 |
|||
*/ |
|||
@TableField(value = "product_origin_price") |
|||
@ApiModelProperty(value="商品原价") |
|||
private BigDecimal productOriginPrice; |
|||
|
|||
/** |
|||
* 商品售价 |
|||
*/ |
|||
@TableField(value = "product_sale_price") |
|||
@ApiModelProperty(value="商品售价") |
|||
private BigDecimal productSalePrice; |
|||
|
|||
/** |
|||
* 折扣 |
|||
*/ |
|||
@TableField(value = "product_discount") |
|||
@ApiModelProperty(value="折扣") |
|||
private String productDiscount; |
|||
|
|||
/** |
|||
* 节省钱数 |
|||
*/ |
|||
@TableField(value = "product_saved_money") |
|||
@ApiModelProperty(value="节省钱数") |
|||
private String productSavedMoney; |
|||
|
|||
/** |
|||
* 库存量 |
|||
*/ |
|||
@TableField(value = "product_num") |
|||
@ApiModelProperty(value="库存量") |
|||
private Integer productNum; |
|||
|
|||
/** |
|||
* 商品描述 |
|||
*/ |
|||
@TableField(value = "product_desc") |
|||
@ApiModelProperty(value="商品描述") |
|||
private String productDesc; |
|||
|
|||
/** |
|||
* 商品图片 |
|||
*/ |
|||
@TableField(value = "product_img") |
|||
@ApiModelProperty(value="商品图片") |
|||
private String productImg; |
|||
|
|||
/** |
|||
* 商品类型(0->直充;1->卡密) |
|||
*/ |
|||
@TableField(value = "product_type") |
|||
@ApiModelProperty(value="商品类型(0->直充;1->卡密)") |
|||
private String productType; |
|||
|
|||
/** |
|||
* 商品使用说明 |
|||
*/ |
|||
@TableField(value = "product_use_desc") |
|||
@ApiModelProperty(value="商品使用说明") |
|||
private String productUseDesc; |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
} |
|||
@ -0,0 +1,80 @@ |
|||
package com.bnyer.img.dto; |
|||
|
|||
import com.bnyer.img.domain.Product; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.NotNull; |
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("产品接收类") |
|||
public class ProductDto implements Serializable { |
|||
|
|||
@ApiModelProperty(value="主键id") |
|||
private Long id; |
|||
|
|||
@NotBlank(message = "商品名称不能为空!") |
|||
@ApiModelProperty(value="商品名称") |
|||
private String productName; |
|||
|
|||
@NotBlank(message = "商品原价不能为空!") |
|||
@ApiModelProperty(value="商品原价") |
|||
private String productOriginPrice; |
|||
|
|||
@NotBlank(message = "商品售价不能为空!") |
|||
@ApiModelProperty(value="商品售价") |
|||
private String productSalePrice; |
|||
|
|||
@NotBlank(message = "折扣不能为空!") |
|||
@ApiModelProperty(value="折扣") |
|||
private String productDiscount; |
|||
|
|||
@NotBlank(message = "节省钱数不能为空!") |
|||
@ApiModelProperty(value="节省钱数") |
|||
private String productSavedMoney; |
|||
|
|||
@NotNull(message = "库存量不能为空!") |
|||
@ApiModelProperty(value="库存量") |
|||
private Integer productNum; |
|||
|
|||
@NotBlank(message = "商品描述不能为空!") |
|||
@ApiModelProperty(value="商品描述") |
|||
private String productDesc; |
|||
|
|||
@NotBlank(message = "商品图片不能为空!") |
|||
@ApiModelProperty(value="商品图片") |
|||
private String productImg; |
|||
|
|||
@NotBlank(message = "商品类型不能为空!") |
|||
@ApiModelProperty(value="商品类型(0->直充;1->卡密)") |
|||
private String productType; |
|||
|
|||
@NotBlank(message = "商品使用说明不能为空!") |
|||
@ApiModelProperty(value="商品使用说明") |
|||
private String productUseDesc; |
|||
|
|||
public Product extractParam(){ |
|||
Product product = new Product(); |
|||
if(this.getId() != null){ |
|||
product.setId(this.getId()); |
|||
} |
|||
product.setProductName(this.getProductName()); |
|||
product.setProductOriginPrice(new BigDecimal(this.getProductOriginPrice())); |
|||
product.setProductSalePrice(new BigDecimal(this.getProductSalePrice())); |
|||
product.setProductDiscount(this.getProductDiscount()); |
|||
product.setProductSavedMoney(this.getProductSavedMoney()); |
|||
product.setProductNum(this.getProductNum()); |
|||
product.setProductDesc(this.getProductDesc()); |
|||
product.setProductImg(this.getProductImg()); |
|||
product.setProductType(this.getProductType()); |
|||
product.setProductUseDesc(this.getProductUseDesc()); |
|||
return product; |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
package com.bnyer.img.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("商品分页接收类") |
|||
public class ProductPageDto extends BasePageDto { |
|||
|
|||
@ApiModelProperty(value="商品名称") |
|||
private String productName; |
|||
|
|||
@ApiModelProperty(value="商品类型(0->直充;1->卡密)") |
|||
private String productType; |
|||
|
|||
@ApiModelProperty(value="是否显示") |
|||
private String isShow; |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
package com.bnyer.img.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.bnyer.img.domain.Product; |
|||
import com.bnyer.img.vo.ProductVo; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Mapper |
|||
public interface ProductMapper extends BaseMapper<Product> { |
|||
|
|||
/** |
|||
* 查询前端产品列表 |
|||
* @return - |
|||
*/ |
|||
List<ProductVo> queryFrontList(); |
|||
|
|||
/** |
|||
* 商品详情 |
|||
* @param id 主键id |
|||
* @return - |
|||
*/ |
|||
ProductVo queryFrontDetails(Long id); |
|||
} |
|||
@ -0,0 +1,66 @@ |
|||
package com.bnyer.img.service; |
|||
|
|||
import com.bnyer.img.domain.Product; |
|||
import com.bnyer.img.dto.ProductPageDto; |
|||
import com.bnyer.img.vo.ProductVo; |
|||
|
|||
import java.util.List; |
|||
|
|||
public interface ProductService { |
|||
|
|||
/** |
|||
* 新增商品 |
|||
* @param product 商品 |
|||
* @return - |
|||
*/ |
|||
int insert(Product product); |
|||
|
|||
/** |
|||
* 编辑商品 |
|||
* @param product 商品 |
|||
* @return - |
|||
*/ |
|||
int update(Product product); |
|||
|
|||
/** |
|||
* 批量删除商品 |
|||
* @param ids 商品ids |
|||
* @return - |
|||
*/ |
|||
int delete(List<Long> ids); |
|||
|
|||
/** |
|||
* 查询商品分页 |
|||
* @param params 分页参数 |
|||
* @return - |
|||
*/ |
|||
List<Product> queryPage(ProductPageDto params); |
|||
|
|||
/** |
|||
* 查询商品详情 |
|||
* @param id 主键id |
|||
* @return - |
|||
*/ |
|||
Product details(Long id); |
|||
|
|||
/** |
|||
* 查询前端商品列表 |
|||
* @return - |
|||
*/ |
|||
List<ProductVo> queryFrontList(); |
|||
|
|||
/** |
|||
* 查询前端盖商品详情 |
|||
* @param id 主键id |
|||
* @return - |
|||
*/ |
|||
ProductVo queryFrontDetails(Long id); |
|||
|
|||
/** |
|||
* 变更显示状态 |
|||
* @param id 主键id |
|||
* @param status 状态 |
|||
* @return - |
|||
*/ |
|||
int changeStatus(Long id,String status); |
|||
} |
|||
@ -0,0 +1,88 @@ |
|||
package com.bnyer.img.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|||
import com.bnyer.common.core.utils.StringUtils; |
|||
import com.bnyer.img.domain.Banner; |
|||
import com.bnyer.img.domain.Product; |
|||
import com.bnyer.img.dto.ProductPageDto; |
|||
import com.bnyer.img.mapper.ProductMapper; |
|||
import com.bnyer.img.service.ProductService; |
|||
import com.bnyer.img.vo.ProductVo; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
@Service |
|||
@Slf4j |
|||
public class ProductServiceImpl implements ProductService { |
|||
|
|||
@Autowired |
|||
private ProductMapper productMapper; |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public int insert(Product product) { |
|||
product.setCreateTime(new Date()); |
|||
product.setUpdateTime(new Date()); |
|||
product.setIsShow("1"); |
|||
return productMapper.insert(product); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public int update(Product product) { |
|||
product.setUpdateTime(new Date()); |
|||
return productMapper.updateById(product); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public int delete(List<Long> ids) { |
|||
return productMapper.deleteBatchIds(ids); |
|||
} |
|||
|
|||
@Override |
|||
public List<Product> queryPage(ProductPageDto params) { |
|||
LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>(); |
|||
if(StringUtils.isNotBlank(params.getProductName())){ |
|||
wrapper.like(Product::getProductName, params.getProductName()); |
|||
} |
|||
if(StringUtils.isNotBlank(params.getProductType())){ |
|||
wrapper.eq(Product::getProductType, params.getProductType()); |
|||
} |
|||
if(StringUtils.isNotBlank(params.getIsShow())){ |
|||
wrapper.eq(Product::getIsShow, params.getIsShow()); |
|||
} |
|||
return productMapper.selectList(wrapper); |
|||
} |
|||
|
|||
@Override |
|||
public Product details(Long id) { |
|||
return productMapper.selectById(id); |
|||
} |
|||
|
|||
@Override |
|||
public List<ProductVo> queryFrontList() { |
|||
return productMapper.queryFrontList(); |
|||
} |
|||
|
|||
@Override |
|||
public ProductVo queryFrontDetails(Long id) { |
|||
return productMapper.queryFrontDetails(id); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public int changeStatus(Long id, String status) { |
|||
LambdaUpdateWrapper<Product> wrapper = new LambdaUpdateWrapper<>(); |
|||
wrapper.eq(Product::getId, id); |
|||
Product product = new Product(); |
|||
product.setIsShow(status); |
|||
return productMapper.update(product,wrapper); |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
package com.bnyer.img.vo; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("banner响应体") |
|||
public class ProductVo implements Serializable { |
|||
@ApiModelProperty(value="主键id") |
|||
private Long id; |
|||
|
|||
@ApiModelProperty(value="商品名称") |
|||
private String productName; |
|||
|
|||
@ApiModelProperty(value="商品原价") |
|||
private BigDecimal productOriginPrice; |
|||
|
|||
@ApiModelProperty(value="商品售价") |
|||
private BigDecimal productSalePrice; |
|||
|
|||
@ApiModelProperty(value="折扣") |
|||
private String productDiscount; |
|||
|
|||
@ApiModelProperty(value="节省钱数") |
|||
private String productSavedMoney; |
|||
|
|||
@ApiModelProperty(value="库存量") |
|||
private Integer productNum; |
|||
|
|||
@ApiModelProperty(value="商品描述") |
|||
private String productDesc; |
|||
|
|||
@ApiModelProperty(value="商品图片") |
|||
private String productImg; |
|||
|
|||
@ApiModelProperty(value="商品类型(0->直充;1->卡密)") |
|||
private String productType; |
|||
|
|||
@ApiModelProperty(value="商品使用说明") |
|||
private String productUseDesc; |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
<?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.bnyer.img.mapper.ProductMapper"> |
|||
<resultMap id="BaseResultMap" type="com.bnyer.img.domain.Product"> |
|||
<!--@mbg.generated--> |
|||
<!--@Table img_product--> |
|||
<id column="id" jdbcType="BIGINT" property="id" /> |
|||
<result column="product_name" jdbcType="VARCHAR" property="productName" /> |
|||
<result column="product_origin_price" jdbcType="DECIMAL" property="productOriginPrice" /> |
|||
<result column="product_sale_price" jdbcType="DECIMAL" property="productSalePrice" /> |
|||
<result column="product_discount" jdbcType="VARCHAR" property="productDiscount" /> |
|||
<result column="product_saved_money" jdbcType="VARCHAR" property="productSavedMoney" /> |
|||
<result column="product_num" jdbcType="INTEGER" property="productNum" /> |
|||
<result column="product_desc" jdbcType="VARCHAR" property="productDesc" /> |
|||
<result column="product_img" jdbcType="VARCHAR" property="productImg" /> |
|||
<result column="product_type" jdbcType="CHAR" property="productType" /> |
|||
<result column="product_use_desc" jdbcType="VARCHAR" property="productUseDesc" /> |
|||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> |
|||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> |
|||
<result column="is_show" jdbcType="CHAR" property="isShow" /> |
|||
<result column="sort" jdbcType="INTEGER" property="sort" /> |
|||
</resultMap> |
|||
<sql id="Base_Column_List"> |
|||
<!--@mbg.generated--> |
|||
id, product_name, product_origin_price, product_sale_price, product_discount, product_saved_money, |
|||
product_num, product_desc, product_img, product_type, product_use_desc, create_time, |
|||
update_time, is_show, sort |
|||
</sql> |
|||
<select id="queryFrontList" resultType="com.bnyer.img.vo.ProductVo"> |
|||
select |
|||
id, product_name, product_origin_price, product_sale_price, product_discount, product_saved_money, |
|||
product_num, product_desc, product_img, product_type, product_use_desc,sort |
|||
from img_product |
|||
where is_show = '1' |
|||
order by sort desc |
|||
</select> |
|||
<select id="queryFrontDetails" resultType="com.bnyer.img.vo.ProductVo"> |
|||
select |
|||
id, product_name, product_origin_price, product_sale_price, product_discount, product_saved_money, |
|||
product_num, product_desc, product_img, product_type, product_use_desc,sort |
|||
from img_product |
|||
where is_show = '1' |
|||
</select> |
|||
</mapper> |
|||
Loading…
Reference in new issue