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.

241 lines
11 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. package in.gov.chennaicorporation.gccoffice.pensioner.service;
  2. import java.util.List;
  3. import java.util.Map;
  4. import javax.sql.DataSource;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.beans.factory.annotation.Qualifier;
  7. import org.springframework.jdbc.core.JdbcTemplate;
  8. import org.springframework.stereotype.Service;
  9. import org.springframework.transaction.annotation.Transactional;
  10. import org.springframework.web.client.RestTemplate;
  11. import com.fasterxml.jackson.databind.ObjectMapper;
  12. @Service
  13. @Transactional
  14. public class ReceivedDeptProvisionalService {
  15. @Autowired
  16. private JdbcTemplate jdbcTemplate;
  17. private RestTemplate restTemplate;
  18. private ObjectMapper objectMapper;
  19. public ReceivedDeptProvisionalService(RestTemplate restTemplate, ObjectMapper objectMapper) {
  20. this.restTemplate = restTemplate;
  21. this.objectMapper = objectMapper;
  22. }
  23. @Autowired
  24. public void setDataSource(@Qualifier("mysqlPensionerDataSource") DataSource dataSource) {
  25. this.jdbcTemplate = new JdbcTemplate(dataSource);
  26. }
  27. @Autowired
  28. public GetFileStatusService getFileStatus;
  29. public List<Map<String, Object>> fetchDetailsProvisionalPension(Integer file_cat) {
  30. String query = "SELECT * " +
  31. "FROM pensioner_details " +
  32. "WHERE file_category=? AND file_status=7";
  33. return jdbcTemplate.queryForList(query,file_cat);
  34. }
  35. public List<Map<String, Object>> fetchDetailsProvisionalDepartment(Integer file_cat) {
  36. String query = "SELECT * " +
  37. "FROM pensioner_details " +
  38. "WHERE file_category=? AND file_status=6";
  39. return jdbcTemplate.queryForList(query,file_cat);
  40. }
  41. //updated entry details
  42. public boolean updateEntryDetailsCompleted(Map<String, Object> requestData) {
  43. // TODO Auto-generated method stub
  44. String empNo = (String) requestData.get("empNo");
  45. String tempId = (String) requestData.get("tempId");
  46. String dateToAudit = (String) requestData.get("dateToAudit");
  47. String filemovedby =(String)requestData.get("filemovedby");
  48. String remarks = (String) requestData.get("remarks");
  49. String dept_Id = (String) requestData.get("deptId");
  50. String pramount = (String) requestData.get("pramount");
  51. String prpercentage = (String) requestData.get("prpercentage");
  52. int deptId = Integer.parseInt(dept_Id);
  53. int filestatus = 11;
  54. String file_entry_type="FILE_COMPLETED";
  55. // Update file_status in pensioner_details
  56. String updateQuery = "UPDATE pensioner_details SET file_status = ?,file_moved_date=?,remarks=?,pr_amount=?,pr_percentage=?,file_entry_type=?,updated_date= CURRENT_TIMESTAMP WHERE temp_id = ? LIMIT 1";
  57. int rowsUpdated = jdbcTemplate.update(updateQuery,filestatus,dateToAudit, remarks,pramount,prpercentage,file_entry_type,tempId);
  58. System.out.println("Rows inserted in pd:"+rowsUpdated);
  59. if(rowsUpdated>0)
  60. {
  61. // Optional: Insert into file movement history for auditing
  62. String historyQuery = "INSERT INTO file_movement_history (emp_no, file_moved_date, file_status, file_moved_by, remarks,temp_id) VALUES (?,?, ?, ?, ?, ?)";
  63. int rowsUpdated1=jdbcTemplate.update(historyQuery, empNo, dateToAudit, filestatus, filemovedby, remarks,tempId);
  64. System.out.println("Rows inserted in fmh:"+rowsUpdated1);
  65. return true;
  66. }
  67. else {
  68. return false;
  69. }
  70. }
  71. // return to department
  72. public boolean updateEntryDetailsReturntoDepartment(Map<String, Object> requestData) {
  73. // TODO Auto-generated method stub
  74. String empNo = (String) requestData.get("empNo");
  75. String tempId = (String) requestData.get("tempId");
  76. String dateToAudit = (String) requestData.get("dateToAudit");
  77. String filemovedby =(String)requestData.get("filemovedby");
  78. String remarks = (String) requestData.get("remarks");
  79. String dept_Id = (String) requestData.get("deptId");
  80. // String pramount = (String) requestData.get("pramount");
  81. // String prpercentage = (String) requestData.get("prpercentage");
  82. int deptId = Integer.parseInt(dept_Id);
  83. int filestatus = 6;
  84. String file_entry_type="FILE_RETURNED";
  85. // Update file_status in pensioner_details
  86. String updateQuery = "UPDATE pensioner_details SET file_status = ?, file_entry_type =?,file_moved_date=?,remarks=?,updated_date= CURRENT_TIMESTAMP WHERE temp_id = ? LIMIT 1";
  87. int rowsUpdated = jdbcTemplate.update(updateQuery,filestatus,file_entry_type,dateToAudit,remarks,tempId);
  88. System.out.println("Rows inserted in pd:"+rowsUpdated);
  89. if(rowsUpdated>0)
  90. {
  91. // Optional: Insert into file movement history for auditing
  92. String historyQuery = "INSERT INTO file_movement_history (emp_no, file_moved_date, file_status, file_moved_by, remarks,temp_id) VALUES (?,?, ?, ?, ?, ?)";
  93. int rowsUpdated1=jdbcTemplate.update(historyQuery, empNo, dateToAudit, filestatus, filemovedby, remarks,tempId);
  94. System.out.println("Rows inserted in fmh:"+rowsUpdated1);
  95. return true;
  96. }
  97. else {
  98. return false;
  99. }
  100. }
  101. // sent to pension
  102. public boolean updateEntryDetailsSenttoPension(Map<String, Object> requestData) {
  103. // TODO Auto-generated method stub
  104. String empNo = (String) requestData.get("empNo");
  105. String tempId = (String) requestData.get("tempId");
  106. String dateToAudit = (String) requestData.get("dateToAudit");
  107. String filemovedby =(String)requestData.get("filemovedby");
  108. String remarks = (String) requestData.get("remarks");
  109. String dept_Id = (String) requestData.get("deptId");
  110. String ReasonofPension = (String) requestData.get("ReasonofPension");
  111. String pendingDuration = (String) requestData.get("pendingDuration");
  112. String reasonofPending = (String) requestData.get("reasonofPending");
  113. String Dp = (String) requestData.get("Dp");
  114. String otherReason = (String) requestData.get("otherReason");
  115. // String pramount = (String) requestData.get("pramount");
  116. // String prpercentage = (String) requestData.get("prpercentage");
  117. int deptId = Integer.parseInt(dept_Id);
  118. int filestatus = 7;
  119. String file_entry_type="FILE_RETURNED";
  120. // Update file_status in pensioner_details
  121. String updateQuery = "UPDATE pensioner_details SET file_status = ?, file_entry_type =?,file_moved_date=?,remarks=?,reason_for_provisional_pension=?,pending_duration=?,reason_for_pending=?,dp=?,others_provisional_pension=?,updated_date= CURRENT_TIMESTAMP WHERE temp_id = ? LIMIT 1";
  122. int rowsUpdated = jdbcTemplate.update(updateQuery,filestatus,file_entry_type,dateToAudit,remarks,ReasonofPension,pendingDuration,reasonofPending,Dp,otherReason ,tempId);
  123. System.out.println("Rows inserted in pd:"+rowsUpdated);
  124. if(rowsUpdated>0)
  125. {
  126. // Optional: Insert into file movement history for auditing
  127. String historyQuery = "INSERT INTO file_movement_history (emp_no, file_moved_date, file_status, file_moved_by, remarks,temp_id) VALUES (?,?, ?, ?, ?, ?)";
  128. int rowsUpdated1=jdbcTemplate.update(historyQuery, empNo, dateToAudit, filestatus, filemovedby, remarks,tempId);
  129. System.out.println("Rows inserted in fmh:"+rowsUpdated1);
  130. return true;
  131. }
  132. else {
  133. return false;
  134. }
  135. }
  136. public boolean savehistory(List<Map<String, Object>> emp_details, String filemovedby) {
  137. try {
  138. // Loop through the list of employee details
  139. for (Map<String, Object> emp : emp_details) {
  140. // Safely extract individual fields from the map with default values
  141. String empNo = emp.get("emp_no").toString();
  142. String empName = emp.get("emp_name").toString();
  143. String deptName = emp.get("dept_name").toString();
  144. String designation = emp.get("designation").toString();
  145. String fileCategoryName = emp.get("file_category_name").toString();
  146. String retirement_class = emp.get("retirement_class").toString();
  147. String type_of_retirement = emp.get("type_of_retirement").toString();
  148. String retirementDate = emp.get("retirement_date").toString();
  149. String ReasonofPension = emp.get("reason_for_provisional_pension").toString();
  150. String pendingDuration = emp.get("pending_duration").toString();
  151. String reasonofPending = emp.get("reason_for_pending") != null ? emp.get("reason_for_pending").toString() : null;
  152. //String Dp = emp.get("dp").toString();
  153. String Dp = emp.get("dp") != null ? emp.get("dp").toString() : "hello";
  154. String otherReason = emp.get("others_provisional_pension") != null ? emp.get("others_provisional_pension").toString() : null;
  155. String fileMovedDate = emp.get("file_moved_date").toString();
  156. String remarks = emp.get("remarks").toString();
  157. String pramount = emp.get("pr_amount") != null && !emp.get("pr_amount").toString().trim().isEmpty() ? emp.get("pr_amount").toString() : null;
  158. String prpercentage = emp.get("pr_percentage") != null && !emp.get("pr_percentage").toString().trim().isEmpty() ? emp.get("pr_percentage").toString() : null;
  159. int fileStatus = Integer.parseInt(emp.get("file_status").toString()); // Default to 0
  160. String fileEntryType = emp.get("file_entry_type").toString();
  161. int file_category = Integer.parseInt(emp.get("file_category").toString()); // Default to 0
  162. int dept_id = Integer.parseInt(emp.get("dept_id").toString()); // Default to 0
  163. String temp_id = emp.get("temp_id").toString();
  164. // Prepare the insert query
  165. String insertQuery = "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, type_of_retirement,retirement_date ,reason_for_provisional_pension, pending_duration, dp, others_provisional_pension, reason_for_pending, retirement_class, file_moved_date, remarks, pr_amount, pr_percentage, file_category, file_status, file_entry_type, file_moved_by, dept_id, file_category_name, temp_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?)";
  166. // Execute the query
  167. int rowsInserted = jdbcTemplate.update(insertQuery, empNo, empName, deptName, designation, type_of_retirement,retirementDate ,ReasonofPension, pendingDuration, Dp, otherReason, reasonofPending, retirement_class, fileMovedDate, remarks, pramount, prpercentage, file_category, fileStatus, fileEntryType, filemovedby, dept_id, fileCategoryName, temp_id);
  168. System.out.println("Rows inserted in pdh: " + rowsInserted);
  169. // Check if the insertion was successful
  170. if (rowsInserted <= 0) {
  171. return false; // Return false if any insertion fails
  172. }
  173. }
  174. return true; // Return true if all insertions succeed
  175. } catch (Exception e) {
  176. e.printStackTrace();
  177. return false; // Return false in case of any exception
  178. }
  179. }
  180. }