feat: add spare part management controller
This commit is contained in:
parent
799e358d0f
commit
9e89932600
|
|
@ -0,0 +1,114 @@
|
|||
package com.ether.pms.mdm.controller;
|
||||
|
||||
import com.ether.pms.common.ApiResponse;
|
||||
import com.ether.pms.mdm.entity.SparePart;
|
||||
import com.ether.pms.mdm.entity.SparePartCategory;
|
||||
import com.ether.pms.mdm.entity.SparePartRecord;
|
||||
import com.ether.pms.mdm.service.SparePartService;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/ops/spare-parts")
|
||||
@RequiredArgsConstructor
|
||||
public class SparePartController {
|
||||
|
||||
private final SparePartService sparePartService;
|
||||
|
||||
// ==================== 分类管理 ====================
|
||||
|
||||
@GetMapping("/categories")
|
||||
public ApiResponse<List<SparePartCategory>> getCategories() {
|
||||
return ApiResponse.success(sparePartService.getCategories());
|
||||
}
|
||||
|
||||
@PostMapping("/categories")
|
||||
public ApiResponse<SparePartCategory> createCategory(@Valid @RequestBody SparePartCategory category) {
|
||||
return ApiResponse.success(sparePartService.createCategory(category));
|
||||
}
|
||||
|
||||
// ==================== 备件管理 ====================
|
||||
|
||||
@GetMapping
|
||||
public ApiResponse<List<SparePart>> getSpareParts(
|
||||
@RequestParam UUID projectId,
|
||||
@RequestParam(required = false) UUID categoryId) {
|
||||
List<SparePart> spareParts;
|
||||
if (categoryId != null) {
|
||||
spareParts = sparePartService.getSparePartsByCategory(categoryId);
|
||||
} else {
|
||||
spareParts = sparePartService.getSparePartsByProject(projectId);
|
||||
}
|
||||
return ApiResponse.success(spareParts);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ApiResponse<SparePart> getSparePart(@PathVariable UUID id) {
|
||||
return ApiResponse.success(sparePartService.getSparePartById(id));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ApiResponse<SparePart> createSparePart(@Valid @RequestBody SparePart sparePart) {
|
||||
return ApiResponse.success(sparePartService.createSparePart(sparePart));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ApiResponse<SparePart> updateSparePart(@PathVariable UUID id, @Valid @RequestBody SparePart sparePart) {
|
||||
return ApiResponse.success(sparePartService.updateSparePart(id, sparePart));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResponse<Void> deleteSparePart(@PathVariable UUID id) {
|
||||
sparePartService.deleteSparePart(id);
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
|
||||
@GetMapping("/low-stock")
|
||||
public ApiResponse<List<SparePart>> getLowStockParts(@RequestParam UUID projectId) {
|
||||
return ApiResponse.success(sparePartService.getLowStockParts(projectId));
|
||||
}
|
||||
|
||||
// ==================== 库存操作 ====================
|
||||
|
||||
@PostMapping("/in-stock")
|
||||
public ApiResponse<SparePartRecord> inStock(@RequestBody StockRequest request) {
|
||||
SparePartRecord record = sparePartService.inStock(
|
||||
request.getSparePartId(), request.getQuantity(), request.getRecordedBy(), request.getRemarks());
|
||||
return ApiResponse.success(record);
|
||||
}
|
||||
|
||||
@PostMapping("/out-stock")
|
||||
public ApiResponse<SparePartRecord> outStock(@RequestBody OutStockRequest request) {
|
||||
SparePartRecord record = sparePartService.outStock(
|
||||
request.getSparePartId(), request.getQuantity(),
|
||||
request.getRelatedOrderId(), request.getRecordedBy(), request.getRemarks());
|
||||
return ApiResponse.success(record);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/records")
|
||||
public ApiResponse<List<SparePartRecord>> getSparePartRecords(@PathVariable UUID id) {
|
||||
return ApiResponse.success(sparePartService.getSparePartRecords(id));
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class StockRequest {
|
||||
private UUID sparePartId;
|
||||
private Integer quantity;
|
||||
private UUID recordedBy;
|
||||
private String remarks;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class OutStockRequest {
|
||||
private UUID sparePartId;
|
||||
private Integer quantity;
|
||||
private UUID relatedOrderId;
|
||||
private UUID recordedBy;
|
||||
private String remarks;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue