feat: add maintenance plan and task controllers
This commit is contained in:
parent
60cb1ba8f3
commit
ab777c748e
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.ether.pms.mdm.controller;
|
||||||
|
|
||||||
|
import com.ether.pms.common.ApiResponse;
|
||||||
|
import com.ether.pms.mdm.entity.MaintenancePlan;
|
||||||
|
import com.ether.pms.mdm.service.MaintenancePlanService;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/ops/maintenance-plans")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MaintenancePlanController {
|
||||||
|
|
||||||
|
private final MaintenancePlanService maintenancePlanService;
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public ApiResponse<MaintenancePlan> createPlan(@Valid @RequestBody MaintenancePlan plan) {
|
||||||
|
MaintenancePlan created = maintenancePlanService.createPlan(plan);
|
||||||
|
return ApiResponse.success(created);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public ApiResponse<List<MaintenancePlan>> getPlans(
|
||||||
|
@RequestParam UUID projectId,
|
||||||
|
@RequestParam(required = false) MaintenancePlan.TriggerType triggerType) {
|
||||||
|
List<MaintenancePlan> plans;
|
||||||
|
if (triggerType != null) {
|
||||||
|
plans = maintenancePlanService.getPlansByTriggerType(triggerType);
|
||||||
|
} else {
|
||||||
|
plans = maintenancePlanService.getActivePlansByProject(projectId);
|
||||||
|
}
|
||||||
|
return ApiResponse.success(plans);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ApiResponse<MaintenancePlan> getPlan(@PathVariable UUID id) {
|
||||||
|
return ApiResponse.success(maintenancePlanService.getPlanById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public ApiResponse<MaintenancePlan> updatePlan(@PathVariable UUID id, @Valid @RequestBody MaintenancePlan plan) {
|
||||||
|
return ApiResponse.success(maintenancePlanService.updatePlan(id, plan));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ApiResponse<Void> deactivatePlan(@PathVariable UUID id) {
|
||||||
|
maintenancePlanService.deactivatePlan(id);
|
||||||
|
return ApiResponse.success(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.ether.pms.mdm.controller;
|
||||||
|
|
||||||
|
import com.ether.pms.common.ApiResponse;
|
||||||
|
import com.ether.pms.mdm.entity.MaintenanceTask;
|
||||||
|
import com.ether.pms.mdm.service.MaintenanceTaskService;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/ops/maintenance-tasks")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MaintenanceTaskController {
|
||||||
|
|
||||||
|
private final MaintenanceTaskService maintenanceTaskService;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public ApiResponse<List<MaintenanceTask>> getTasks(
|
||||||
|
@RequestParam(required = false) UUID projectId,
|
||||||
|
@RequestParam(required = false) UUID assignee,
|
||||||
|
@RequestParam(required = false) MaintenanceTask.Status status,
|
||||||
|
@RequestParam(required = false) UUID equipmentId) {
|
||||||
|
List<MaintenanceTask> tasks;
|
||||||
|
if (equipmentId != null) {
|
||||||
|
tasks = maintenanceTaskService.getTasksByEquipment(equipmentId);
|
||||||
|
} else if (assignee != null) {
|
||||||
|
tasks = maintenanceTaskService.getTasksByAssignee(assignee);
|
||||||
|
} else if (status != null && projectId != null) {
|
||||||
|
tasks = maintenanceTaskService.getTasksByStatus(projectId, status);
|
||||||
|
} else {
|
||||||
|
tasks = maintenanceTaskService.getOverdueTasks();
|
||||||
|
}
|
||||||
|
return ApiResponse.success(tasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ApiResponse<MaintenanceTask> getTask(@PathVariable UUID id) {
|
||||||
|
return ApiResponse.success(maintenanceTaskService.getTaskById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public ApiResponse<MaintenanceTask> createTask(@Valid @RequestBody MaintenanceTask task) {
|
||||||
|
return ApiResponse.success(maintenanceTaskService.createTask(task));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{id}/accept")
|
||||||
|
public ApiResponse<MaintenanceTask> acceptTask(@PathVariable UUID id, @RequestParam UUID userId) {
|
||||||
|
return ApiResponse.success(maintenanceTaskService.acceptTask(id, userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{id}/start")
|
||||||
|
public ApiResponse<MaintenanceTask> startTask(@PathVariable UUID id) {
|
||||||
|
return ApiResponse.success(maintenanceTaskService.startTask(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{id}/complete")
|
||||||
|
public ApiResponse<MaintenanceTask> completeTask(
|
||||||
|
@PathVariable UUID id,
|
||||||
|
@RequestBody CompleteTaskRequest request) {
|
||||||
|
return ApiResponse.success(maintenanceTaskService.completeTask(
|
||||||
|
id, request.getLaborHours(), request.getMaterialsCost(), request.getRemarks()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{id}/cancel")
|
||||||
|
public ApiResponse<Void> cancelTask(@PathVariable UUID id) {
|
||||||
|
maintenanceTaskService.cancelTask(id);
|
||||||
|
return ApiResponse.success(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class CompleteTaskRequest {
|
||||||
|
private BigDecimal laborHours;
|
||||||
|
private BigDecimal materialsCost;
|
||||||
|
private String remarks;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue