商品管理完成

This commit is contained in:
bunny 2023-12-16 20:54:10 +08:00
parent 0546776bdf
commit dabed9ca7d
10 changed files with 176 additions and 62 deletions

View File

@ -4,27 +4,17 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="94fab532-0084-41f1-bb0f-d2d2811915a7" name="Changes" comment="商品管理查询分页">
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/controller/ProductUntilController.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductDetailMapper.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductSkuMapper.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductUntilMapper.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/ProductUntilService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/impl/ProductUntilServiceImpl.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductDetailMapper.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductSkuMapper.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductUntilMapper.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
<list default="true" id="94fab532-0084-41f1-bb0f-d2d2811915a7" name="Changes" comment="商品管理添加删除">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/controller/ProductController.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/controller/ProductController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/controller/ProductSpecController.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/controller/ProductSpecController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductDetailMapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductDetailMapper.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductMapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductMapper.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductSpecMapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductSpecMapper.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductSkuMapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductSkuMapper.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/ProductService.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/ProductService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/ProductSpecService.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/ProductSpecService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/impl/ProductServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/impl/ProductServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/impl/ProductSpecServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/impl/ProductSpecServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductDetailMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductDetailMapper.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductMapper.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductSpecMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductSpecMapper.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductSkuMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductSkuMapper.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -88,6 +78,9 @@
]
}
}]]></component>
<component name="ReactorSettings">
<option name="notificationShown" value="true" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="G:\File\Java\spzx-parent\spzx-manager\src\main\resources\mapper" />
@ -122,7 +115,7 @@
<option name="presentableId" value="Default" />
<updated>1702710124940</updated>
<workItem from="1702710126987" duration="661000" />
<workItem from="1702713203759" duration="7512000" />
<workItem from="1702713203759" duration="13045000" />
</task>
<task id="LOCAL-00001" summary="商品管理查询分页">
<option name="closed" value="true" />
@ -132,7 +125,15 @@
<option name="project" value="LOCAL" />
<updated>1702714985398</updated>
</task>
<option name="localTasksCounter" value="2" />
<task id="LOCAL-00002" summary="商品管理添加删除">
<option name="closed" value="true" />
<created>1702725562779</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1702725562779</updated>
</task>
<option name="localTasksCounter" value="3" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -140,7 +141,8 @@
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="商品管理查询分页" />
<option name="LAST_COMMIT_MESSAGE" value="商品管理查询分页" />
<MESSAGE value="商品管理添加删除" />
<option name="LAST_COMMIT_MESSAGE" value="商品管理添加删除" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
@ -156,5 +158,10 @@
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
<watches-manager>
<configuration name="SpringBootApplicationConfigurationType">
<watch expression="product" />
</configuration>
</watches-manager>
</component>
</project>

View File

@ -7,6 +7,7 @@ import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
import cn.bunny.service.ProductService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -20,21 +21,44 @@ public class ProductController {
@Autowired
private ProductService productService;
@Operation(summary = "保存修改数据",description = "保存修改数据")
@PostMapping("updateById")
@Operation(summary = "商品上下架", description = "商品上下架")
@GetMapping("/updateStatus/{id}/{status}")
public Result updateStatus(@PathVariable("id") Long id,
@PathVariable("status") Integer status) {
productService.updateStatus(id, status);
return Result.build(null, ResultCodeEnum.SUCCESS);
}
@Operation(summary = "审核商品", description = "审核商品")
@GetMapping("/updateAuditStatus/{id}/{auditStatus}")
public Result updateAuditStatus(@PathVariable("id") Long id,
@PathVariable("auditStatus") Integer auditStatus) {
productService.updateAuditStatus(id, auditStatus);
return Result.build(null, ResultCodeEnum.SUCCESS);
}
@Operation(summary = "删除数据", description = "删除数据")
@DeleteMapping("deleteById/{id}")
public Result deleteById(@Parameter(name = "id", description = "商品id", required = true) Long id) {
productService.deleteById(id);
return Result.build(null, ResultCodeEnum.SUCCESS);
}
@Operation(summary = "保存修改数据", description = "保存修改数据")
@PutMapping("updateById")
public Result updateById(@RequestBody Product product) {
productService.updateById(product);
return Result.build(null, ResultCodeEnum.SUCCESS);
}
@Operation(summary = "根据id查询商品信息",description = "根据id查询商品信息")
@Operation(summary = "根据id查询商品信息", description = "根据id查询商品信息")
@GetMapping("getById/{id}")
public Result getById(@PathVariable("id") Long id) {
Product product = productService.getById(id);
return Result.build(product, ResultCodeEnum.SUCCESS);
return Result.build(product , ResultCodeEnum.SUCCESS) ;
}
@Operation(summary = "保存商品数据接口",description = "保存商品数据接口")
@Operation(summary = "保存商品数据接口", description = "保存商品数据接口")
@PostMapping("save")
public Result save(@RequestBody Product product) {
productService.save(product);

View File

@ -12,4 +12,7 @@ public interface ProductDetailMapper {
// 修改product_details表
void updateById(ProductDetails productDetails);
// 删除product_details数据
void deleteById(Long id);
}

View File

@ -19,4 +19,10 @@ public interface ProductMapper {
// 修改product表
void updateProduct(Product product);
// 删除product数据
void deleteById(Long id);
// 审核商品
void updateById(Product product);
}

View File

@ -14,4 +14,7 @@ public interface ProductSkuMapper {
// 修改product_sku表
void updateById(ProductSku productSku);
// 删除product_sku数据
void deleteByProductId(Long id);
}

View File

@ -18,4 +18,13 @@ public interface ProductService {
// 保存修改数据
void updateById(Product product);
// 删除数据
void deleteById(Long id);
// 审核商品
void updateAuditStatus(Long id, Integer auditStatus);
// 商品上下架
void updateStatus(Long id, Integer status);
}

View File

@ -62,18 +62,19 @@ public class ProductServiceImpl implements ProductService {
// 根据id查询商品信息
@Override
public Product getById(Long id) {
// 1. 根据id查询商品基本信息
// 根据id查询商品数据
Product product = productMapper.findProductById(id);
// 2. 根据id查询商品sku信息列表 productsku
// 根据商品的id查询sku数据
List<ProductSku> productSkuList = productSkuMapper.findProductSkuByProductId(id);
product.setProductSkuList(productSkuList);
// 3. 根据id查询商品详情信息 productdetails
ProductDetails productDetails = productDetailMapper.findProductDetailsById(id);
String imageUrls = productDetails.getImageUrls();
product.setDetailsImageUrls(imageUrls);
// 根据商品的id查询商品详情数据
ProductDetails productDetails = productDetailMapper.findProductDetailsById(product.getId());
if (productDetails != null) product.setDetailsImageUrls(productDetails.getImageUrls());
// 返回数据
return product;
}
@ -91,8 +92,51 @@ public class ProductServiceImpl implements ProductService {
// 修改product_details表
String detailsImageUrls = product.getDetailsImageUrls();
ProductDetails productDetails= productDetailMapper.findProductDetailsById(product.getId());
ProductDetails productDetails = productDetailMapper.findProductDetailsById(product.getId());
productDetails.setImageUrls(detailsImageUrls);
productDetailMapper.updateById(productDetails);
}
// 删除数据
@Override
public void deleteById(Long id) {
// 1. 删除product数据
productMapper.deleteById(id);
// 2. 删除product_sku数据
productSkuMapper.deleteByProductId(id);
// 3. 删除product_details数据
productDetailMapper.deleteById(id);
}
// 审核商品
@Override
public void updateAuditStatus(Long id, Integer auditStatus) {
Product product = new Product();
product.setId(id);
if (auditStatus == 1) {
product.setAuditStatus(1);
product.setAuditMessage("审核通过");
} else {
product.setAuditStatus(-1);
product.setAuditMessage("审核不通过");
}
productMapper.updateById(product);
}
// 商品上下架
@Override
public void updateStatus(Long id, Integer status) {
Product product = new Product();
product.setId(id);
if (status == 1) {
product.setStatus(1);
} else {
product.setStatus(-1);
}
productMapper.updateById(product);
}
}

View File

@ -1,6 +1,9 @@
<?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.ProductDetailMapper">
<resultMap id="productDetailsMap" type="cn.bunny.common.spzx.model.entity.product.ProductDetails" autoMapping="true"/>
<!-- 用于select查询公用抽取的列 -->
<sql id="columns">
id,product_id,image_urls,create_time,update_time,is_deleted
@ -33,12 +36,18 @@
id = #{id}
</update>
<!-- 删除product_details数据 -->
<update id="deleteById">
update product_details
set is_deleted=1
where id = #{id}
</update>
<!-- 根据id查询商品信息 -->
<select id="findProductDetailsById" resultType="cn.bunny.common.spzx.model.entity.product.ProductDetails">
select
<include refid="columns"/>
<select id="findProductDetailsById" resultMap="productDetailsMap">
select <include refid="columns" />
from product_details
where
product_id = #{productId} and is_deleted=0
product_id = #{productId}
</select>
</mapper>

View File

@ -76,6 +76,25 @@
id = #{id}
</update>
<!-- 删除product数据 -->
<update id="deleteById">
update product
set is_deleted=1
where id = #{id}
</update>
<!-- 审核商品 -->
<update id="updateById">
update product set
<if test="status != null and status !=''">
status = #{status}
</if>
<if test="auditStatus != null and auditStatus != ''">
audit_status = #{auditStatus}
</if>
where id = #{id}
</update>
<!-- 查询分页 -->
<select id="findByPage" resultType="cn.bunny.common.spzx.model.entity.product.Product">
select
@ -93,31 +112,17 @@
</select>
<!-- 1. 根据id查询商品基本信息 -->
<select id="findProductById" resultType="cn.bunny.common.spzx.model.entity.product.Product">
select p.id,
p.name,
p.brand_id,
p.category1_id,
p.category2_id,
p.category3_id,
p.unit_name,
p.slider_urls,
p.spec_value,
p.status,
p.audit_status,
p.audit_message,
p.create_time,
p.update_time,
p.is_deleted,
b.name brandName,
c1.name category1Name,
c2.name category2Name,
c3.name category3Name
<select id="findProductById" resultMap="productMap">
select
p.id, p.name , p.brand_id , p.category1_id , p.category2_id , p.category3_id, p.unit_name,
p.slider_urls , p.spec_value , p.status , p.audit_status , p.audit_message , p.create_time , p.update_time , p.is_deleted ,
b.name brandName , c1.name category1Name , c2.name category2Name , c2.name category3Name
from product p
LEFT JOIN brand b on b.id = p.brand_id
LEFT JOIN category c1 on c1.id = p.category1_id
LEFT JOIN category c2 on c2.id = p.category2_id
LEFT JOIN category c3 on c3.id = p.category3_id
where p.id = #{id}
where
p.id = #{id}
</select>
</mapper>

View File

@ -2,10 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.bunny.mapper.ProductSkuMapper">
<!-- 用于select查询公用抽取的列 -->
<sql id="columns">
id,sku_code,sku_name,product_id,thumb_img,sale_price,market_price,cost_price,stock_num,sku_spec,weight,volume,status,create_time,update_time,is_deleted
</sql>
<resultMap id="productSkuMap" type="cn.bunny.common.spzx.model.entity.product.ProductSku" autoMapping="true"/>
<insert id="save" useGeneratedKeys="true" keyProperty="id">
insert into product_sku (id,
@ -88,9 +85,16 @@
id = #{id}
</update>
<!-- 删除product_sku数据 -->
<update id="deleteByProductId">
update product_sku
set is_deleted=1
where id = #{id}
</update>
<!-- 根据id查询商品信息 -->
<select id="findProductSkuByProductId" resultType="cn.bunny.common.spzx.model.entity.product.ProductSku">
select <include refid="columns" />
<select id="findProductSkuByProductId" resultMap="productSkuMap">
select *
from product_sku
where product_id = #{productId}
and is_deleted = 0