1.上下架售罄接口

This commit is contained in:
2024-08-12 14:25:14 +08:00
parent 6de1857e3c
commit 923ee6f1cb
6 changed files with 115 additions and 1 deletions

View File

@@ -1,13 +1,17 @@
package com.chaozhanggui.system.cashierservice.controller;
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStatusDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStockDTO;
import com.chaozhanggui.system.cashierservice.service.ProductService;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.Map;
@CrossOrigin(origins = "*")
@@ -21,6 +25,23 @@ public class ProductController {
private ProductService productService;
@PutMapping("/productStatus")
public Result productStatus(
@Valid @RequestBody ProductStatusDTO productStatusDTO
) {
productService.updateState(productStatusDTO);
return Result.success(CodeEnum.SUCCESS);
}
@PutMapping("/productStock")
public Result productStock(
@Valid @RequestBody ProductStockDTO productStockDTO
) {
productService.updateStock(productStockDTO);
return Result.success(CodeEnum.SUCCESS);
}
@GetMapping(value = "queryCommodityInfo")
public Result queryCommodityInfo(
@RequestHeader("token") String token,

View File

@@ -5,6 +5,7 @@ import com.chaozhanggui.system.cashierservice.entity.TbProductWithBLOBs;
import com.chaozhanggui.system.cashierservice.entity.po.ProConsSkuInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;
@@ -53,4 +54,24 @@ public interface TbProductMapper {
@Update("update tb_product set stock_number=stock_number-#{num} WHERE id=#{id}")
int decrStockUnCheck(String id, int num);
@Select("select * from tb_product product where product.id=#{productId} and product.shop_id=#{shopId} and product.is_del=0")
TbProduct selectByShopIdAndId(@Param("productId") Integer productId, @Param("shopId") Integer shopId);
@Update("update tb_product_sku set is_grounding=#{isGrounding} where product_id=#{productId}")
int updateGroundingByProId(@Param("productId") Integer productId, @Param("isGrounding") int isGrounding);
@Update("update tb_product_sku set is_grounding=#{status} where id=#{skuId}")
int updateGrounding(@Param("skuId") Integer skuId, @Param("status") int status);
@Update("update tb_product set is_pause_sale=#{state} where id=#{id} and shop_id=#{shopId}")
int pauseSale(@Param("id") Integer id, @Param("shopId") Integer shopId, @Param("state") Integer state);
@Update("update tb_product_sku set is_pause_sale=#{state} where product_id=#{id} and shop_id=#{shopId}")
int pauseSkuSale(@Param("id") Integer proId, @Param("shopId") Integer shopId, @Param("state") Integer state);
@Update("update tb_product set stock_number=#{stock} where id=#{productId} and shop_id=#{shopId}")
int updateStock(@Param("shopId") Integer shopId, @Param("productId") Integer productId, @Param("stock") Integer stock);
}

View File

@@ -55,5 +55,11 @@ public interface TbProductSkuMapper {
List<TbProductSku> selectByProductCheckGrounding(@Param("id") Integer id);
@Select("select * from tb_product_sku where is_grounding=1 and is_del=0 and product_id=#{id}")
List<TbProductSku> selectGroundingByProId(Integer id);
List<TbProductSku> selectGroundingByProId(@Param("id") Integer id);
@Update("update tb_product_sku set is_pause_sale=#{state} where id=#{skuId} and shop_id=#{shopId}")
int pauseSale(@Param("skuId") Integer skuId, @Param("shopId") Integer shopId, @Param("state") Integer state);
@Update("update tb_product_sku set stock_number=#{stock} where product_id=#{skuId} and shop_id=#{shopId}")
int updateStock(@Param("skuId") Integer skuId, @Param("shopId") Integer shopId, @Param("stock") Integer stock);
}

View File

@@ -0,0 +1,22 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotNull;
@Data
public class ProductStatusDTO {
@NotNull
private Integer productId;
@NotNull
private Integer shopId;
@NotNull
@Range(min = 0, max = 1)
private Integer state;
// 0上下架 1售罄
@Range(min = 0, max = 1)
@NotNull
private Integer type;
}

View File

@@ -0,0 +1,18 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
@Data
public class ProductStockDTO {
@NotNull
private Integer shopId;
@NotNull
private Integer productId;
@NotNull
@Min(0)
private Integer stock;
}

View File

@@ -7,6 +7,8 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStatusDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStockDTO;
import com.chaozhanggui.system.cashierservice.entity.vo.ShopCategoryVo;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.interceptor.LimitSubmitAspect;
@@ -222,4 +224,28 @@ public class ProductService {
}
}
}
public void updateState(ProductStatusDTO productStatusDTO) {
TbProduct product = tbProductMapper.selectByShopIdAndId(productStatusDTO.getProductId(), productStatusDTO.getShopId());
if (productStatusDTO.getType().equals(0)) {
tbProductMapper.updateGroundingByProId(product.getId(), productStatusDTO.getState());
}else {
tbProductMapper.pauseSale(productStatusDTO.getProductId(), productStatusDTO.getShopId(), productStatusDTO.getState());
tbProductMapper.pauseSkuSale(productStatusDTO.getProductId(), productStatusDTO.getShopId(), productStatusDTO.getState());
}
}
public void updateStock(ProductStockDTO productStockDTO) {
TbProduct product = tbProductMapper.selectByShopIdAndId(productStockDTO.getProductId(), productStockDTO.getShopId());
if (product == null) {
throw new MsgException("商品不存在");
}
if (product.getIsDistribute() != 1 && product.getTypeEnum().equals("sku")) {
throw new MsgException("多规格非共享商品暂不支持修改库存");
}else {
tbProductSkuMapper.updateStock(productStockDTO.getProductId(), productStockDTO.getShopId(), productStockDTO.getStock());
}
}
}