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.

176 lines
7.4 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
2 years ago
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 if(file_Status == 9) {
  60. //return ResponseEntity.ok("File Moved Department to Complete Pending fields!");
  61. return ResponseEntity.ok("File Moved to Department Partially Completed!");
  62. }
  63. else {
  64. //return ResponseEntity.ok("File Moved Department to Complete Pending fields!");
  65. return ResponseEntity.ok("File Moved to Pension Partially Completed!");
  66. }
  67. } else {
  68. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  69. .body("Failed to save details in history or invalid file_status.");
  70. }
  71. } else {
  72. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to save details for completed.");
  73. }
  74. } catch (Exception e) {
  75. e.printStackTrace();
  76. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  77. .body("Error occurred while saving details.");
  78. }
  79. }
  80. @PostMapping("/updateforretirementpending")
  81. public ResponseEntity<String> updateRetirementEmployeeDetailsPending(@RequestBody Map<String, Object> requestData) {
  82. try {
  83. // Extract request parameters
  84. String tempId = (String) requestData.get("tempId");
  85. String filemovedby = (String) requestData.get("filemovedby");
  86. // Call service method to save the details
  87. boolean isSaved = departmentReceivedService.updateEntryPendingDetails(requestData);
  88. if (isSaved) {
  89. // Fetch employee details
  90. List<Map<String, Object>> emp_details = deptAuditService.fetchEmployeeById(tempId);
  91. System.out.println("emp_details:==:" + emp_details);
  92. // Fetch pension benefits details
  93. List<Map<String, Object>> pension_details = departmentReceivedService.fetchPensionbenefitsById(tempId);
  94. System.out.println("pension_details:==:" + pension_details);
  95. // Save retirement completed history
  96. boolean updated = departmentReceivedService.saveRetirementPendinghistory(emp_details, pension_details, filemovedby);
  97. if(updated)
  98. {
  99. return ResponseEntity.ok("File is Pending!");
  100. }
  101. else {
  102. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to save details in history.");
  103. }
  104. } else {
  105. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to save details for pending.");
  106. }
  107. } catch (Exception e) {
  108. e.printStackTrace();
  109. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  110. .body("Error occurred while saving details.");
  111. }
  112. }
  113. @PostMapping("/updateforretirementreturn")
  114. public ResponseEntity<String> updateRetirementEmployeeDetailsReturn(@RequestBody Map<String, Object> requestData) {
  115. try {
  116. // Extract request parameters
  117. String tempId = (String) requestData.get("tempId");
  118. String filemovedby = (String) requestData.get("filemovedby");
  119. // Call service method to save the details
  120. boolean isSaved = departmentReceivedService.updateEntryReturnDetails(requestData);
  121. if (isSaved) {
  122. // Fetch employee details
  123. List<Map<String, Object>> emp_details = deptAuditService.fetchEmployeeById(tempId);
  124. System.out.println("emp_details:==:" + emp_details);
  125. // Save retirement completed history
  126. boolean updated = departmentReceivedService.saveRetirementreturnhistory(emp_details,filemovedby);
  127. if(updated)
  128. {
  129. return ResponseEntity.ok("File Returned to Department!");
  130. }
  131. else {
  132. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to save details in history.");
  133. }
  134. } else {
  135. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to save details for pending.");
  136. }
  137. } catch (Exception e) {
  138. e.printStackTrace();
  139. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  140. .body("Error occurred while saving details.");
  141. }
  142. }
  143. }