商品修改库存
This commit is contained in:
parent
606e4da36c
commit
6ffbef791f
|
|
@ -125,6 +125,17 @@ public class ProductController {
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping
|
||||||
|
@OperationLog("商品-修改库存")
|
||||||
|
@SaStaffCheckPermission("yun_xu_xiu_gai_shang_pin")
|
||||||
|
public CzgResult<Void> updateProductStock(@RequestBody ProductModifyStockParam param) {
|
||||||
|
ValidatorUtil.validateEntity(param, DefaultGroup.class);
|
||||||
|
Long shopId = StpKit.USER.getShopId(0L);
|
||||||
|
param.setShopId(shopId);
|
||||||
|
productService.updateProductStock(param);
|
||||||
|
return CzgResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品-删除
|
* 商品-删除
|
||||||
* @param id 商品ID
|
* @param id 商品ID
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,13 @@ public interface ProductService extends IService<Product> {
|
||||||
*/
|
*/
|
||||||
void updateProduct(ProductDTO dto);
|
void updateProduct(ProductDTO dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改商品库存数量
|
||||||
|
*
|
||||||
|
* @param param 商品id及库存数量
|
||||||
|
*/
|
||||||
|
void updateProductStock(ProductModifyStockParam param);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除商品
|
* 删除商品
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -234,6 +234,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT}, key = "#dto.shopId", allEntries = true)
|
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT}, key = "#dto.shopId", allEntries = true)
|
||||||
public void updateProduct(ProductDTO dto) {
|
public void updateProduct(ProductDTO dto) {
|
||||||
Long shopId = StpKit.USER.getShopId(0L);
|
Long shopId = StpKit.USER.getShopId(0L);
|
||||||
|
|
@ -321,6 +322,52 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||||
productStockFlowService.saveFlow(flow);
|
productStockFlowService.saveFlow(flow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void updateProductStock(ProductModifyStockParam param) {
|
||||||
|
Product entity = super.getById(param.getId());
|
||||||
|
if (entity.getIsStock() == YesNoEnum.NO.value()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!entity.getShopId().equals(param.getShopId())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UpdateChain.of(Product.class)
|
||||||
|
.set(Product::getStockNumber, param.getStockNumber())
|
||||||
|
.set(Product::getShopId, param.getShopId())
|
||||||
|
.eq(Product::getId, param.getId())
|
||||||
|
.update();
|
||||||
|
// 记录商品库存流水
|
||||||
|
ProductStockFlow flow = new ProductStockFlow();
|
||||||
|
Long createUserId = StpKit.USER.getLoginIdAsLong();
|
||||||
|
String createUserName = StpKit.USER.getAccount();
|
||||||
|
flow.setCreateUserId(createUserId);
|
||||||
|
flow.setCreateUserName(createUserName);
|
||||||
|
flow.setShopId(param.getShopId());
|
||||||
|
flow.setProductId(entity.getId());
|
||||||
|
flow.setProductName(entity.getName());
|
||||||
|
flow.setBeforeNumber(NumberUtil.toBigDecimal(entity.getStockNumber()));
|
||||||
|
BigDecimal inOutNumber = NumberUtil.sub(NumberUtil.toBigDecimal(entity.getStockNumber()), flow.getBeforeNumber());
|
||||||
|
// 盘亏
|
||||||
|
if (NumberUtil.isLess(inOutNumber, BigDecimal.ZERO)) {
|
||||||
|
flow.setInOutNumber(inOutNumber);
|
||||||
|
flow.setInOutType(InOutTypeEnum.OUT.value());
|
||||||
|
flow.setInOutItem(InOutItemEnum.LOSS_OUT.value());
|
||||||
|
}
|
||||||
|
// 盘盈
|
||||||
|
if (NumberUtil.isGreater(inOutNumber, BigDecimal.ZERO)) {
|
||||||
|
flow.setInOutNumber(inOutNumber);
|
||||||
|
flow.setInOutType(InOutTypeEnum.IN.value());
|
||||||
|
flow.setInOutItem(InOutItemEnum.WIN_IN.value());
|
||||||
|
}
|
||||||
|
// 盘平
|
||||||
|
if (NumberUtil.equals(inOutNumber, BigDecimal.ZERO)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
flow.setAfterNumber(NumberUtil.toBigDecimal(entity.getStockNumber()));
|
||||||
|
productStockFlowService.saveFlow(flow);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT}, key = "#shopId", allEntries = true)
|
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT}, key = "#shopId", allEntries = true)
|
||||||
public void deleteProduct(Long shopId, Long id) {
|
public void deleteProduct(Long shopId, Long id) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue