商品规格增删改查

This commit is contained in:
bunny 2023-12-16 11:13:55 +08:00
parent 0657d7185c
commit 4ed2a8c62e
5 changed files with 188 additions and 0 deletions

View File

@ -0,0 +1,59 @@
package cn.bunny.controller;
import cn.bunny.common.spzx.model.entity.product.ProductSpec;
import cn.bunny.common.spzx.model.vo.common.Result;
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
import cn.bunny.service.ProductSpecService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Tag(name = "商品规格列表接口")
@RestController
@RequestMapping("/admin/product/productSpec")
public class ProductSpecController {
@Autowired
private ProductSpecService productSpecService;
@Operation(summary = "分页查询商品规格列表", description = "分页查询商品规格列表")
@GetMapping("{page}/{limit}")
public Result lis(@PathVariable("page") Integer page, @PathVariable("limit") Integer limit) {
PageInfo<ProductSpec> pageInfo = productSpecService.findByPage(page, limit);
return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
}
@Operation(summary = "商品规格添加", description = "商品规格添加")
@PostMapping("save")
public Result save(@RequestBody ProductSpec productSpec) {
productSpecService.save(productSpec);
return Result.build(null, ResultCodeEnum.SUCCESS);
}
/**
* 分页查询商品规格列表
*
* @param productSpec 每页数量
* @return 商品规格列表
*/
@Operation(summary = "商品规格修改", description = "商品规格修改")
@PutMapping("updateById")
public Result updateById(@RequestBody ProductSpec productSpec) {
productSpecService.updateById(productSpec);
return Result.build(null, ResultCodeEnum.SUCCESS);
}
/**
* 商品规格删除
*
* @param id id
* @return Result
*/
@Operation(summary = "商品规格删除", description = "商品规格删除")
@DeleteMapping("deleteById/{id}")
public Result deleteById(@PathVariable("id") Integer id) {
productSpecService.deleteById(id);
return Result.build(null, ResultCodeEnum.SUCCESS);
}
}

View File

@ -0,0 +1,21 @@
package cn.bunny.mapper;
import cn.bunny.common.spzx.model.entity.product.ProductSpec;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ProductSpecMapper {
// 分页查询商品规格列表
List<ProductSpec> findByPage();
// 商品规格添加
void save(ProductSpec productSpec);
// 商品规格修改
void updateById(ProductSpec productSpec);
// 商品规格删除
void deleteById(Integer id);
}

View File

@ -0,0 +1,18 @@
package cn.bunny.service;
import cn.bunny.common.spzx.model.entity.product.ProductSpec;
import com.github.pagehelper.PageInfo;
public interface ProductSpecService {
// 分页查询商品规格列表
PageInfo<ProductSpec> findByPage(Integer page, Integer limit);
// 商品规格添加
void save(ProductSpec productSpec);
// 商品规格添加
void updateById(ProductSpec productSpec);
// 商品规格删除
void deleteById(Integer id);
}

View File

@ -0,0 +1,43 @@
package cn.bunny.service.impl;
import cn.bunny.common.spzx.model.entity.product.ProductSpec;
import cn.bunny.mapper.ProductSpecMapper;
import cn.bunny.service.ProductSpecService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ProductSpecServiceImpl implements ProductSpecService {
@Autowired
private ProductSpecMapper productSpecMapper;
// 分页查询商品规格列表
@Override
public PageInfo<ProductSpec> findByPage(Integer page, Integer limit) {
PageHelper.startPage(page, limit);
List<ProductSpec> list = productSpecMapper.findByPage();
return new PageInfo<>(list);
}
// 商品规格添加
@Override
public void save(ProductSpec productSpec) {
productSpecMapper.save(productSpec);
}
// 商品规格修改
@Override
public void updateById(ProductSpec productSpec) {
productSpecMapper.updateById(productSpec);
}
// 商品规格删除
@Override
public void deleteById(Integer id) {
productSpecMapper.deleteById(id);
}
}

View File

@ -0,0 +1,47 @@
<?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="cn.bunny.mapper.ProductSpecMapper">
<resultMap id="productSpecMap" type="cn.bunny.common.spzx.model.entity.product.ProductSpec" autoMapping="true"/>
<!-- 用于select查询公用抽取的列 -->
<sql id="columns">
id,spec_name,spec_value,create_time,update_time,is_deleted
</sql>
<!-- 商品规格添加 -->
<update id="save">
insert into product_spec (id, spec_name, spec_value, create_time, update_time, is_deleted)
values (#{id}, #{specName}, #{specValue}, now(), now(), 0)
</update>
<!-- 商品规格修改 -->
<update id="updateById">
update product_spec set
<if test="specName != null and specName != ''">
spec_name = #{specName},
</if>
<if test="specValue != null and specValue != ''">
spec_value = #{specValue},
</if>
update_time = now()
where
id = #{id}
</update>
<!-- 商品规格删除 -->
<delete id="deleteById">
update product_spec
set update_time = now(),
is_deleted = 1
where id = #{id}
</delete>
<!-- 分页查询商品规格列表 -->
<select id="findByPage" resultType="cn.bunny.common.spzx.model.entity.product.ProductSpec">
select
<include refid="columns"/>
from product_spec
where is_deleted = 0
order by id desc
</select>
</mapper>