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.

238 lines
11 KiB

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