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.

235 lines
12 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
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. import in.gov.chennaicorporation.gccoffice.configuration.AppConfig;
  13. @Service
  14. @Transactional
  15. public class PensionAuditService {
  16. @Autowired
  17. private JdbcTemplate jdbcTemplate;
  18. private RestTemplate restTemplate;
  19. private ObjectMapper objectMapper;
  20. @Autowired
  21. private AppConfig appconfig;
  22. public PensionAuditService(RestTemplate restTemplate, ObjectMapper objectMapper) {
  23. this.restTemplate = restTemplate;
  24. this.objectMapper = objectMapper;
  25. }
  26. @Autowired
  27. public void setDataSource(@Qualifier("mysqlPensionerDataSource") DataSource dataSource) {
  28. this.jdbcTemplate = new JdbcTemplate(dataSource);
  29. }
  30. @Autowired
  31. public GetFileStatusService getFileStatus;
  32. public List<Map<String, Object>> fetchDetailsForAudit(Integer file_cat) {
  33. String query = "SELECT * " +
  34. "FROM pensioner_details " +
  35. "WHERE file_category=? AND (file_status=1 OR file_status=3) AND is_closed=0";
  36. return jdbcTemplate.queryForList(query,file_cat);
  37. }
  38. public boolean updateEntryDetails(Map<String, Object> requestData) {
  39. // TODO Auto-generated method stub
  40. String empNo = (String) requestData.get("empNo");
  41. String tempId = (String) requestData.get("tempId");
  42. String dateToAudit = (String) requestData.get("dateToAudit");
  43. String filemovedby =(String)requestData.get("filemovedby");
  44. String remarks = (String) requestData.get("remarks");
  45. String dept_Id = (String) requestData.get("deptId");
  46. int deptId = Integer.parseInt(dept_Id);
  47. int filestatus = getFileStatus.getFileStatus4Id();
  48. if (filestatus == 0) {
  49. System.out.println("File status not found. Aborting insertion.");
  50. return false;
  51. }
  52. String file_entry_type="AUDIT_CLEARED";
  53. String updateQuery = "UPDATE pensioner_details SET file_status = ?,file_entry_type=?,file_moved_date=?,remarks=?,updated_date= CURRENT_TIMESTAMP WHERE temp_id = ? LIMIT 1";
  54. int rowsUpdated = jdbcTemplate.update(updateQuery,filestatus,file_entry_type,dateToAudit, remarks,tempId);
  55. System.out.println("Rows inserted in pd:"+rowsUpdated);
  56. if(rowsUpdated>0)
  57. {
  58. // Optional: Insert into file movement history for auditing
  59. String historyQuery = "INSERT INTO file_movement_history (emp_no, file_moved_date, file_status, file_moved_by, remarks,temp_id) VALUES (?,?, ?, ?, ?, ?)";
  60. int rowsUpdated1=jdbcTemplate.update(historyQuery, empNo, dateToAudit, filestatus, filemovedby, remarks,tempId);
  61. System.out.println("Rows inserted in fmh:"+rowsUpdated1);
  62. return true;
  63. }
  64. else {
  65. return false;
  66. }
  67. }
  68. public boolean savehistory(List<Map<String, Object>> emp_details,String filemovedby) {
  69. try {
  70. // Loop through the list of employee details
  71. for (Map<String, Object> emp : emp_details) {
  72. // Extract individual fields from the map
  73. String empNo = emp.get("emp_no").toString();
  74. String empName = emp.get("emp_name").toString();
  75. String deptName = emp.get("dept_name").toString();
  76. String designation = emp.get("designation").toString();
  77. String fileCategoryName = emp.get("file_category_name").toString();
  78. String retirement_date = emp.get("retirement_date").toString();
  79. String retirement_class = emp.get("retirement_class").toString();
  80. String type_of_retirement = emp.get("type_of_retirement").toString();
  81. String fileMovedDate = emp.get("file_moved_date").toString();
  82. String remarks = emp.get("remarks").toString();
  83. int fileStatus = Integer.parseInt(emp.get("file_status").toString());
  84. String fileEntryType = emp.get("file_entry_type").toString();
  85. int file_category = Integer.parseInt(emp.get("file_category").toString());
  86. int dept_id = Integer.parseInt(emp.get("dept_id").toString());
  87. String temp_id = emp.get("temp_id").toString();
  88. // Prepare the insert query
  89. String insertQuery ="INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, type_of_retirement,retirement_date ,retirement_class,file_moved_date, remarks,file_category,file_status,file_entry_type,file_moved_by,dept_id,file_category_name,temp_id) VALUES (?,?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?)";
  90. // Execute the query
  91. int rowsInserted = jdbcTemplate.update(insertQuery, empNo, empName, deptName,designation,type_of_retirement,retirement_date,retirement_class,fileMovedDate,remarks,file_category,fileStatus,fileEntryType,filemovedby,dept_id,fileCategoryName,temp_id);
  92. System.out.println("Rows inserted in pdh:"+rowsInserted);
  93. // Check if the insertion was successful
  94. if (rowsInserted <= 0) {
  95. return false; // Return false if any insertion fails
  96. }
  97. }
  98. return true; // Return true if all insertions succeed
  99. } catch (Exception e) {
  100. e.printStackTrace();
  101. return false; // Return false in case of any exception
  102. }
  103. }
  104. //gis
  105. public List<Map<String, Object>> fetchDetailsForrecivedGis(Integer file_cat) {
  106. String query = "SELECT * FROM pensioner_details WHERE file_category = ? AND file_status = 7";
  107. return jdbcTemplate.queryForList(query,file_cat);
  108. }
  109. public boolean saveFamilyPensionHistory(List<Map<String, Object>> emp_details,String filemovedby) {
  110. try {
  111. // Loop through the list of employee details
  112. for (Map<String, Object> emp : emp_details) {
  113. // Extract individual fields from the map
  114. String empNo = emp.get("emp_no").toString();
  115. String empName = emp.get("emp_name").toString();
  116. String deptName = emp.get("dept_name").toString();
  117. String designation = emp.get("designation").toString();
  118. String fileCategoryName = emp.get("file_category_name").toString();
  119. String pendingDuration=emp.get("pending_duration").toString();
  120. String pendingReason=emp.get("reason_for_pending") != null ? emp.get("reason_for_pending").toString() : null;
  121. String serviceDeath = emp.get("service_death").toString();
  122. String relationshipDeceased = emp.get("relationship_deceased").toString();
  123. String sanctionedGis = emp.get("sanctioned_gis_amount").toString();
  124. String fileMovedDate = emp.get("file_moved_date").toString();
  125. String remarks = emp.get("remarks").toString();
  126. int fileStatus = Integer.parseInt(emp.get("file_status").toString());
  127. String fileEntryType = emp.get("file_entry_type").toString();
  128. int file_category = Integer.parseInt(emp.get("file_category").toString());
  129. int dept_id = Integer.parseInt(emp.get("dept_id").toString());
  130. String temp_id = emp.get("temp_id").toString();
  131. // Prepare the insert query
  132. String insertQuery ="INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, service_death,relationship_deceased ,sanctioned_gis_amount,file_moved_date, remarks,file_category,file_status,file_entry_type,file_moved_by,dept_id,file_category_name,temp_id,pending_duration,reason_for_pending) VALUES (?,?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?)";
  133. // Execute the query
  134. int rowsInserted = jdbcTemplate.update(insertQuery, empNo, empName, deptName,designation,serviceDeath,relationshipDeceased,sanctionedGis,fileMovedDate,remarks,file_category,fileStatus,fileEntryType,filemovedby,dept_id,fileCategoryName,temp_id,pendingDuration,pendingReason);
  135. System.out.println("Rows inserted in pdh:"+rowsInserted);
  136. // Check if the insertion was successful
  137. if (rowsInserted <= 0) {
  138. return false; // Return false if any insertion fails
  139. }
  140. }
  141. return true; // Return true if all insertions succeed
  142. } catch (Exception e) {
  143. e.printStackTrace();
  144. return false; // Return false in case of any exception
  145. }
  146. }
  147. public boolean savePendencyHistory(List<Map<String, Object>> emp_details,String filemovedby) {
  148. try {
  149. // Loop through the list of employee details
  150. for (Map<String, Object> emp : emp_details) {
  151. // Extract individual fields from the map
  152. String empNo = emp.get("emp_no").toString();
  153. String empName = emp.get("emp_name").toString();
  154. String deptName = emp.get("dept_name").toString();
  155. String designation = emp.get("designation").toString();
  156. String retirementClass = emp.get("retirement_class").toString();
  157. String retirementDate=emp.get("retirement_date").toString();
  158. //String fileCategoryName = emp.get("file_category_name").toString();
  159. String pendingDuration=emp.get("pending_duration").toString();
  160. String pendingReason=emp.get("reason_for_pending") != null ? emp.get("reason_for_pending").toString() : null;
  161. String typeOfCategory=emp.get("file_category_name").toString();
  162. String typeOfRetirement=emp.get("type_of_retirement").toString();
  163. String fileMovedDate = emp.get("file_moved_date").toString();
  164. String remarks = emp.get("remarks").toString();
  165. int fileStatus = Integer.parseInt(emp.get("file_status").toString());
  166. String fileEntryType = emp.get("file_entry_type").toString();
  167. int file_category = Integer.parseInt(emp.get("file_category").toString());
  168. int dept_id = Integer.parseInt(emp.get("dept_id").toString());
  169. String temp_id = emp.get("temp_id").toString();
  170. // Prepare the insert query
  171. String insertQuery ="INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation,retirement_class,retirement_date,file_category_name,type_of_retirement,file_moved_date, remarks,file_category,file_status,file_entry_type,file_moved_by,dept_id,temp_id,pending_duration,reason_for_pending) VALUES (?,?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?)";
  172. // Execute the query
  173. int rowsInserted = jdbcTemplate.update(insertQuery, empNo, empName, deptName,designation,retirementClass,retirementDate, typeOfCategory,typeOfRetirement,fileMovedDate,remarks,file_category,fileStatus,fileEntryType,filemovedby,dept_id,temp_id,pendingDuration,pendingReason);
  174. System.out.println("Rows inserted in pdh:"+rowsInserted);
  175. // Check if the insertion was successful
  176. if (rowsInserted <= 0) {
  177. return false; // Return false if any insertion fails
  178. }
  179. }
  180. return true; // Return true if all insertions succeed
  181. } catch (Exception e) {
  182. e.printStackTrace();
  183. return false; // Return false in case of any exception
  184. }
  185. }
  186. }