package com.oying.modules.pc.product.rest;
|
|
import com.oying.modules.pc.product.domain.Product;
|
import com.oying.modules.pc.product.domain.dto.ProductInventoryUpdateRequest;
|
import com.oying.modules.pc.product.service.ProductInventoryService;
|
import com.oying.utils.R;
|
import io.swagger.annotations.Api;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.Optional;
|
|
/**
|
* @author lzp
|
* @date 2025-09-10
|
**/
|
@RestController
|
@RequiredArgsConstructor
|
@Api(tags = "εεεΊε")
|
@RequestMapping("/api/pc/product/{productId}/inventory")
|
public class ProductInventoryController {
|
|
private final ProductInventoryService productInventoryService;
|
|
@GetMapping
|
public ResponseEntity<?> getStockInfo(@PathVariable Long productId) {
|
return ResponseEntity.ok(R.success(productInventoryService.getProductById(productId)));
|
}
|
|
@PutMapping
|
public ResponseEntity<?> setStock(@PathVariable Long productId, @RequestBody ProductInventoryUpdateRequest request) {
|
Product product = productInventoryService.setStockQuantity(Optional.ofNullable(request.getProductId()).orElse(productId), request.getQuantity(), request.getVersion());
|
return ResponseEntity.ok(R.success(product));
|
}
|
|
@PostMapping("/increase")
|
public ResponseEntity<?> increaseStock(@PathVariable Long productId, @RequestBody ProductInventoryUpdateRequest request) {
|
Product product = productInventoryService.increaseStock(Optional.ofNullable(request.getProductId()).orElse(productId), request.getAmount());
|
return ResponseEntity.ok(R.success(product));
|
}
|
|
@PostMapping("/decrease")
|
public ResponseEntity<?> decreaseStock(@PathVariable Long productId, @RequestBody ProductInventoryUpdateRequest request) {
|
Product product = productInventoryService.decreaseStock(Optional.ofNullable(request.getProductId()).orElse(productId), request.getAmount());
|
return ResponseEntity.ok(R.success(product));
|
}
|
|
@GetMapping("/sufficient")
|
public ResponseEntity<?> checkStockSufficient(@PathVariable Long productId, @RequestParam Integer requiredAmount) {
|
boolean isSufficient = productInventoryService.isStockSufficient(productId, requiredAmount);
|
return ResponseEntity.ok(R.success(isSufficient));
|
}
|
}
|