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.

172 lines
7.2 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. package in.gov.chennaicorporation.gccoffice.pensioner.controller;
  2. import java.util.List;
  3. import java.util.Map;
  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.PostMapping;
  8. import org.springframework.web.bind.annotation.RequestBody;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import in.gov.chennaicorporation.gccoffice.pensioner.service.DepartmentReceivedService;
  12. import in.gov.chennaicorporation.gccoffice.pensioner.service.DeptAuditService;
  13. @RequestMapping("gcc/api/pension/received")
  14. @RestController
  15. public class DepartmentReceivedApiController {
  16. @Autowired
  17. private DeptAuditService deptAuditService;
  18. @Autowired
  19. private DepartmentReceivedService departmentReceivedService;
  20. @PostMapping("/updateforretirementcompleted")
  21. public ResponseEntity<String> updateRetirementEmployeeDetailsCompleted(@RequestBody Map<String, Object> requestData) {
  22. try {
  23. // Extract request parameters
  24. String tempId = (String) requestData.get("tempId");
  25. String filemovedby = (String) requestData.get("filemovedby");
  26. int file_Status = 0; // Initialize file_status
  27. // Call service method to save the details
  28. boolean isSaved = departmentReceivedService.updateEntryCompletedDetails(requestData);
  29. if (isSaved) {
  30. // Fetch employee details
  31. List<Map<String, Object>> emp_details = deptAuditService.fetchEmployeeById(tempId);
  32. System.out.println("emp_details:==:" + emp_details);
  33. // Fetch pension benefits details
  34. List<Map<String, Object>> pension_details = departmentReceivedService.fetchPensionbenefitsById(tempId);
  35. System.out.println("pension_details:==:" + pension_details);
  36. // Save retirement completed history
  37. boolean updated = departmentReceivedService.saveRetirementCompletedhistory(emp_details, pension_details, filemovedby);
  38. // Retrieve file_status from emp_details
  39. if (!emp_details.isEmpty()) {
  40. Map<String, Object> firstEmployeeDetails = emp_details.get(0);
  41. Object fileStatusObj = firstEmployeeDetails.get("file_status");
  42. if (fileStatusObj != null) {
  43. try {
  44. file_Status = Integer.parseInt(fileStatusObj.toString());
  45. System.out.println("Parsed file_status: " + file_Status);
  46. } catch (NumberFormatException e) {
  47. System.err.println("Failed to parse file_status: " + fileStatusObj);
  48. }
  49. } else {
  50. System.out.println("file_status is null in emp_details.");
  51. }
  52. } else {
  53. System.out.println("emp_details is empty.");
  54. }
  55. // Final response logic
  56. if (updated && file_Status != 0) {
  57. if (file_Status == 11) {
  58. return ResponseEntity.ok("File Completed successfully!");
  59. } else {
  60. //return ResponseEntity.ok("File Moved Department to Complete Pending fields!");
  61. return ResponseEntity.ok("File Moved to Partially Completed!");
  62. }
  63. } else {
  64. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  65. .body("Failed to save details in history or invalid file_status.");
  66. }
  67. } else {
  68. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to save details for completed.");
  69. }
  70. } catch (Exception e) {
  71. e.printStackTrace();
  72. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  73. .body("Error occurred while saving details.");
  74. }
  75. }
  76. @PostMapping("/updateforretirementpending")
  77. public ResponseEntity<String> updateRetirementEmployeeDetailsPending(@RequestBody Map<String, Object> requestData) {
  78. try {
  79. // Extract request parameters
  80. String tempId = (String) requestData.get("tempId");
  81. String filemovedby = (String) requestData.get("filemovedby");
  82. // Call service method to save the details
  83. boolean isSaved = departmentReceivedService.updateEntryPendingDetails(requestData);
  84. if (isSaved) {
  85. // Fetch employee details
  86. List<Map<String, Object>> emp_details = deptAuditService.fetchEmployeeById(tempId);
  87. System.out.println("emp_details:==:" + emp_details);
  88. // Fetch pension benefits details
  89. List<Map<String, Object>> pension_details = departmentReceivedService.fetchPensionbenefitsById(tempId);
  90. System.out.println("pension_details:==:" + pension_details);
  91. // Save retirement completed history
  92. boolean updated = departmentReceivedService.saveRetirementPendinghistory(emp_details, pension_details, filemovedby);
  93. if(updated)
  94. {
  95. return ResponseEntity.ok("File is Pending!");
  96. }
  97. else {
  98. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to save details in history.");
  99. }
  100. } else {
  101. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to save details for pending.");
  102. }
  103. } catch (Exception e) {
  104. e.printStackTrace();
  105. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  106. .body("Error occurred while saving details.");
  107. }
  108. }
  109. @PostMapping("/updateforretirementreturn")
  110. public ResponseEntity<String> updateRetirementEmployeeDetailsReturn(@RequestBody Map<String, Object> requestData) {
  111. try {
  112. // Extract request parameters
  113. String tempId = (String) requestData.get("tempId");
  114. String filemovedby = (String) requestData.get("filemovedby");
  115. // Call service method to save the details
  116. boolean isSaved = departmentReceivedService.updateEntryReturnDetails(requestData);
  117. if (isSaved) {
  118. // Fetch employee details
  119. List<Map<String, Object>> emp_details = deptAuditService.fetchEmployeeById(tempId);
  120. System.out.println("emp_details:==:" + emp_details);
  121. // Save retirement completed history
  122. boolean updated = departmentReceivedService.saveRetirementreturnhistory(emp_details,filemovedby);
  123. if(updated)
  124. {
  125. return ResponseEntity.ok("File Returned to Department!");
  126. }
  127. else {
  128. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to save details in history.");
  129. }
  130. } else {
  131. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to save details for pending.");
  132. }
  133. } catch (Exception e) {
  134. e.printStackTrace();
  135. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  136. .body("Error occurred while saving details.");
  137. }
  138. }
  139. }