|
|
@@ -1,64 +1,75 @@
|
|
|
package com.oms.controller;
|
|
|
|
|
|
+import com.oms.common.ApiResponse;
|
|
|
import com.oms.dto.TicketDTO;
|
|
|
import com.oms.entity.Ticket;
|
|
|
import com.oms.service.TicketService;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/crm/tickets")
|
|
|
+@RequiredArgsConstructor
|
|
|
public class TicketController {
|
|
|
|
|
|
- @Autowired
|
|
|
- private TicketService ticketService;
|
|
|
+ private final TicketService ticketService;
|
|
|
|
|
|
@GetMapping
|
|
|
- public ResponseEntity<Map<String, List<?>>> getTickets(
|
|
|
+ public ApiResponse<List<Ticket>> getTickets(
|
|
|
@RequestParam(required = false) String status,
|
|
|
@RequestParam(required = false) String priority) {
|
|
|
- List<Ticket> items = ticketService.listTickets(status, priority);
|
|
|
- return ResponseEntity.ok(Map.of("items", items));
|
|
|
+ return ApiResponse.success(ticketService.listTickets(status, priority));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/{id}")
|
|
|
- public ResponseEntity<Ticket> getTicket(@PathVariable Long id) {
|
|
|
+ public ApiResponse<Ticket> getTicket(@PathVariable Long id) {
|
|
|
Ticket ticket = ticketService.getTicket(id);
|
|
|
- return ticket != null ? ResponseEntity.ok(ticket) : ResponseEntity.notFound().build();
|
|
|
+ if (ticket == null) {
|
|
|
+ return ApiResponse.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ return ApiResponse.success(ticket);
|
|
|
}
|
|
|
|
|
|
@PostMapping
|
|
|
- public ResponseEntity<Ticket> createTicket(@RequestBody TicketDTO dto) {
|
|
|
- Ticket ticket = ticketService.createTicket(dto);
|
|
|
- return ResponseEntity.ok(ticket);
|
|
|
+ public ApiResponse<Ticket> createTicket(@RequestBody TicketDTO dto) {
|
|
|
+ return ApiResponse.success(ticketService.createTicket(dto));
|
|
|
}
|
|
|
|
|
|
@PutMapping("/{id}")
|
|
|
- public ResponseEntity<Ticket> updateTicket(@PathVariable Long id, @RequestBody TicketDTO dto) {
|
|
|
+ public ApiResponse<Ticket> updateTicket(@PathVariable Long id, @RequestBody TicketDTO dto) {
|
|
|
Ticket ticket = ticketService.updateTicket(id, dto);
|
|
|
- return ticket != null ? ResponseEntity.ok(ticket) : ResponseEntity.notFound().build();
|
|
|
+ if (ticket == null) {
|
|
|
+ return ApiResponse.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ return ApiResponse.success(ticket);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/{id}/assign")
|
|
|
- public ResponseEntity<Ticket> assignTicket(@PathVariable Long id, @RequestBody Map<String, Object> body) {
|
|
|
+ public ApiResponse<Ticket> assignTicket(@PathVariable Long id, @RequestBody Map<String, Object> body) {
|
|
|
Long assignedTo = Long.valueOf(body.get("assignedTo").toString());
|
|
|
String assignedName = body.get("assignedName").toString();
|
|
|
Ticket ticket = ticketService.assignTicket(id, assignedTo, assignedName);
|
|
|
- return ticket != null ? ResponseEntity.ok(ticket) : ResponseEntity.notFound().build();
|
|
|
+ if (ticket == null) {
|
|
|
+ return ApiResponse.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ return ApiResponse.success(ticket);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/{id}/resolve")
|
|
|
- public ResponseEntity<Ticket> resolveTicket(@PathVariable Long id, @RequestBody Map<String, String> body) {
|
|
|
+ public ApiResponse<Ticket> resolveTicket(@PathVariable Long id, @RequestBody Map<String, String> body) {
|
|
|
Ticket ticket = ticketService.resolveTicket(id, body.get("resolution"));
|
|
|
- return ticket != null ? ResponseEntity.ok(ticket) : ResponseEntity.notFound().build();
|
|
|
+ if (ticket == null) {
|
|
|
+ return ApiResponse.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ return ApiResponse.success(ticket);
|
|
|
}
|
|
|
|
|
|
@DeleteMapping("/{id}")
|
|
|
- public ResponseEntity<Void> deleteTicket(@PathVariable Long id) {
|
|
|
+ public ApiResponse<Void> deleteTicket(@PathVariable Long id) {
|
|
|
ticketService.deleteTicket(id);
|
|
|
- return ResponseEntity.ok().build();
|
|
|
+ return ApiResponse.success();
|
|
|
}
|
|
|
}
|