|
@@ -0,0 +1,169 @@
|
|
|
|
|
+package com.etotem.cfc.controller.admin;
|
|
|
|
|
+
|
|
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
|
|
+import com.etotem.cfc.entity.ProductBundleItem;
|
|
|
|
|
+import com.etotem.cfc.service.InventoryService;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+@Tag(name = "管理端-库存管理")
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/api/admin/inventory")
|
|
|
|
|
+public class AdminInventoryController {
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private InventoryService inventoryService;
|
|
|
|
|
+
|
|
|
|
|
+ // ========== 入库单 ==========
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "创建入库单")
|
|
|
|
|
+ @PostMapping("/inbound/create")
|
|
|
|
|
+ public Result<Map<String, Object>> createInbound(@RequestBody Map<String, Object> params,
|
|
|
|
|
+ @RequestAttribute("userId") Long adminId) {
|
|
|
|
|
+ Long supplierId = params.get("supplierId") != null ? Long.valueOf(params.get("supplierId").toString()) : null;
|
|
|
|
|
+ String supplierName = (String) params.get("supplierName");
|
|
|
|
|
+ String remark = (String) params.get("remark");
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ List<Map<String, Object>> items = (List<Map<String, Object>>) params.get("items");
|
|
|
|
|
+ return inventoryService.createInboundOrder(supplierId, supplierName, items, adminId, remark);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "入库单列表")
|
|
|
|
|
+ @PostMapping("/inbound/list")
|
|
|
|
|
+ public Result<Map<String, Object>> listInbound(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ int page = params.get("page") != null ? ((Number) params.get("page")).intValue() : 1;
|
|
|
|
|
+ int size = params.get("size") != null ? ((Number) params.get("size")).intValue() : 20;
|
|
|
|
|
+ String status = (String) params.get("status");
|
|
|
|
|
+ String keyword = (String) params.get("keyword");
|
|
|
|
|
+ return inventoryService.listInboundOrders(page, size, status, keyword);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "入库单详情")
|
|
|
|
|
+ @PostMapping("/inbound/detail")
|
|
|
|
|
+ public Result<Map<String, Object>> detailInbound(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Long id = params.get("id") != null ? Long.valueOf(params.get("id").toString()) : null;
|
|
|
|
|
+ if (id == null) return Result.error("id不能为空");
|
|
|
|
|
+ return inventoryService.detailInboundOrder(id);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "确认入库")
|
|
|
|
|
+ @PostMapping("/inbound/confirm")
|
|
|
|
|
+ public Result<String> confirmInbound(@RequestBody Map<String, Object> params,
|
|
|
|
|
+ @RequestAttribute("userId") Long adminId) {
|
|
|
|
|
+ Long id = params.get("id") != null ? Long.valueOf(params.get("id").toString()) : null;
|
|
|
|
|
+ if (id == null) return Result.error("id不能为空");
|
|
|
|
|
+ return inventoryService.confirmInbound(id, adminId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "取消入库单")
|
|
|
|
|
+ @PostMapping("/inbound/cancel")
|
|
|
|
|
+ public Result<String> cancelInbound(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Long id = params.get("id") != null ? Long.valueOf(params.get("id").toString()) : null;
|
|
|
|
|
+ if (id == null) return Result.error("id不能为空");
|
|
|
|
|
+ return inventoryService.cancelInbound(id);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ========== 库存流水 ==========
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "库存流水列表")
|
|
|
|
|
+ @PostMapping("/transactions/list")
|
|
|
|
|
+ public Result<Map<String, Object>> listTransactions(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ int page = params.get("page") != null ? ((Number) params.get("page")).intValue() : 1;
|
|
|
|
|
+ int size = params.get("size") != null ? ((Number) params.get("size")).intValue() : 20;
|
|
|
|
|
+ Long productId = params.get("productId") != null ? Long.valueOf(params.get("productId").toString()) : null;
|
|
|
|
|
+ Long skuId = params.get("skuId") != null ? Long.valueOf(params.get("skuId").toString()) : null;
|
|
|
|
|
+ String type = (String) params.get("type");
|
|
|
|
|
+ String startDate = (String) params.get("startDate");
|
|
|
|
|
+ String endDate = (String) params.get("endDate");
|
|
|
|
|
+ return inventoryService.listTransactions(page, size, productId, skuId, type, startDate, endDate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ========== 盘点 ==========
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "创建盘点")
|
|
|
|
|
+ @PostMapping("/counting/create")
|
|
|
|
|
+ public Result<String> createCounting(@RequestBody Map<String, Object> params,
|
|
|
|
|
+ @RequestAttribute("userId") Long adminId) {
|
|
|
|
|
+ Long productId = params.get("productId") != null ? Long.valueOf(params.get("productId").toString()) : null;
|
|
|
|
|
+ Long skuId = params.get("skuId") != null ? Long.valueOf(params.get("skuId").toString()) : null;
|
|
|
|
|
+ Integer actualStock = params.get("actualStock") != null ? Integer.valueOf(params.get("actualStock").toString()) : null;
|
|
|
|
|
+ String remark = (String) params.get("remark");
|
|
|
|
|
+ if (productId == null) return Result.error("productId不能为空");
|
|
|
|
|
+ if (actualStock == null) return Result.error("actualStock不能为空");
|
|
|
|
|
+ return inventoryService.createCounting(productId, skuId, actualStock, adminId, remark);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "确认盘点")
|
|
|
|
|
+ @PostMapping("/counting/confirm")
|
|
|
|
|
+ public Result<String> confirmCounting(@RequestBody Map<String, Object> params,
|
|
|
|
|
+ @RequestAttribute("userId") Long adminId) {
|
|
|
|
|
+ Long id = params.get("id") != null ? Long.valueOf(params.get("id").toString()) : null;
|
|
|
|
|
+ if (id == null) return Result.error("id不能为空");
|
|
|
|
|
+ return inventoryService.confirmCounting(id, adminId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "盘点列表")
|
|
|
|
|
+ @PostMapping("/counting/list")
|
|
|
|
|
+ public Result<Map<String, Object>> listCounting(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ int page = params.get("page") != null ? ((Number) params.get("page")).intValue() : 1;
|
|
|
|
|
+ int size = params.get("size") != null ? ((Number) params.get("size")).intValue() : 20;
|
|
|
|
|
+ String status = (String) params.get("status");
|
|
|
|
|
+ return inventoryService.listCountingRecords(page, size, status);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ========== 库存预警 ==========
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "库存预警列表")
|
|
|
|
|
+ @PostMapping("/alert/list")
|
|
|
|
|
+ public Result<List<Map<String, Object>>> listAlerts() {
|
|
|
|
|
+ return inventoryService.listStockAlerts();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ========== 商品库存详情 ==========
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "商品库存详情")
|
|
|
|
|
+ @PostMapping("/product/stock")
|
|
|
|
|
+ public Result<Map<String, Object>> productStock(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Long productId = params.get("productId") != null ? Long.valueOf(params.get("productId").toString()) : null;
|
|
|
|
|
+ if (productId == null) return Result.error("productId不能为空");
|
|
|
|
|
+ return inventoryService.getProductStock(productId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ========== 套餐商品 ==========
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "配置套餐商品组成")
|
|
|
|
|
+ @PostMapping("/bundle/items")
|
|
|
|
|
+ public Result<String> saveBundleItems(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Long bundleProductId = params.get("bundleProductId") != null
|
|
|
|
|
+ ? Long.valueOf(params.get("bundleProductId").toString()) : null;
|
|
|
|
|
+ if (bundleProductId == null) return Result.error("bundleProductId不能为空");
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ List<Map<String, Object>> items = (List<Map<String, Object>>) params.get("items");
|
|
|
|
|
+ return inventoryService.saveBundleItems(bundleProductId, items);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "查询套餐商品组成")
|
|
|
|
|
+ @PostMapping("/bundle/items/list")
|
|
|
|
|
+ public Result<List<ProductBundleItem>> listBundleItems(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Long bundleProductId = params.get("bundleProductId") != null
|
|
|
|
|
+ ? Long.valueOf(params.get("bundleProductId").toString()) : null;
|
|
|
|
|
+ if (bundleProductId == null) return Result.error("bundleProductId不能为空");
|
|
|
|
|
+ return inventoryService.listBundleItems(bundleProductId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "检查套餐库存")
|
|
|
|
|
+ @PostMapping("/bundle/check-stock")
|
|
|
|
|
+ public Result<String> checkBundleStock(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Long bundleProductId = params.get("bundleProductId") != null
|
|
|
|
|
+ ? Long.valueOf(params.get("bundleProductId").toString()) : null;
|
|
|
|
|
+ Integer quantity = params.get("quantity") != null
|
|
|
|
|
+ ? Integer.valueOf(params.get("quantity").toString()) : 1;
|
|
|
|
|
+ if (bundleProductId == null) return Result.error("bundleProductId不能为空");
|
|
|
|
|
+ return inventoryService.checkBundleStock(bundleProductId, quantity);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|