You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.1 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. package in.gov.chennaicorporation.gccoffice.pensioner.controller;
  2. import java.util.Map;
  3. import java.util.List;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.http.HttpStatus;
  6. import org.springframework.http.ResponseEntity;
  7. import org.springframework.web.bind.annotation.GetMapping;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestParam;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import in.gov.chennaicorporation.gccoffice.pensioner.service.CompletedService;
  12. @RequestMapping("gcc/api/department/completed")
  13. @RestController
  14. public class CompletedApiController {
  15. @Autowired
  16. private CompletedService completedService;
  17. @Autowired
  18. public CompletedApiController(CompletedService completedService) {
  19. this.completedService = completedService;
  20. }
  21. // Combined method to handle both cases (with and without emp_no parameter)
  22. @GetMapping("/cpslist")
  23. public ResponseEntity<?> getCPSList(@RequestParam(value = "emp_no", required = false) String empNo,
  24. @RequestParam(required = false)Integer file_cat,
  25. @RequestParam(required = false)Integer deptId) {
  26. try {
  27. List<Map<String, Object>> cpsList;
  28. // If emp_no is provided, fetch filtered records
  29. if (empNo != null && !empNo.isEmpty()) {
  30. cpsList = completedService.getCPSListByEmpNo(empNo);
  31. } else {
  32. // If emp_no is not provided, fetch all records
  33. cpsList = completedService.getCPSList(file_cat,deptId);
  34. }
  35. // Return response based on the data
  36. if (cpsList.isEmpty()) {
  37. return ResponseEntity.noContent().build(); // No records found
  38. }
  39. return ResponseEntity.ok(cpsList); // Return the records
  40. } catch (Exception e) {
  41. e.printStackTrace();
  42. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  43. .body("Error occurred while fetching completed service records.");
  44. }
  45. }
  46. }