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.

197 lines
7.5 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.dao.EmptyResultDataAccessException;
  8. import org.springframework.jdbc.core.JdbcTemplate;
  9. import org.springframework.stereotype.Service;
  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. public class FileClosingService {
  15. @Autowired
  16. private JdbcTemplate jdbcTemplate;
  17. private RestTemplate restTemplate;
  18. private ObjectMapper objectMapper;
  19. @Autowired
  20. private AppConfig appconfig;
  21. public FileClosingService(RestTemplate restTemplate, ObjectMapper objectMapper) {
  22. this.restTemplate = restTemplate;
  23. this.objectMapper = objectMapper;
  24. }
  25. @Autowired
  26. public void setDataSource(@Qualifier("mysqlPensionerDataSource") DataSource dataSource) {
  27. this.jdbcTemplate = new JdbcTemplate(dataSource);
  28. }
  29. @Autowired
  30. public GetFileStatusService getFileStatus;
  31. public List<Map<String, Object>> fetchEmployeeByTempId(String tempId) {
  32. System.out.println("inside");
  33. String sql = "SELECT * " +
  34. "FROM pensioner_details pd " +
  35. "where pd.file_category=1 and pd.file_status < 11 and pd.temp_id = ? and pd.is_closed=0 " ;
  36. System.out.println("outside");
  37. System.out.println(sql);
  38. return jdbcTemplate.queryForList(sql,tempId);
  39. }
  40. public String getTempId(String empCode,Integer deptId,Integer file_cat) {
  41. String query = "SELECT temp_id FROM pensioner_details WHERE emp_no = ? AND file_category = ? AND dept_id = ?";
  42. try {
  43. return jdbcTemplate.queryForObject(query, String.class,empCode,file_cat,deptId);
  44. } catch (EmptyResultDataAccessException e) {
  45. return null; // or handle as needed
  46. }
  47. }
  48. public List<Map<String, Object>> fetchEmployeeById(String tempId) {
  49. String sql = "SELECT pd.*, zb.gpf, zb.gpf_amount, zb.spfgs, zb.spfgs_amount, zb.dcrg, " +
  50. "zb.private_affairs, zb.private_affairs_amount, zb.recovery_emp, " +
  51. "pb.file_pending, pb.pension_number, pb.ledger_number, pb.benefit_pension, " +
  52. "pb.benefit_pension_amount, pb.benefit_dcrg, pb.benefit_dcrg_amount " +
  53. "FROM pensioner_details pd " +
  54. "LEFT JOIN zone_benefits zb ON pd.temp_id = zb.temp_id " +
  55. "LEFT JOIN pension_benefits pb ON pd.temp_id = pb.temp_id "+
  56. "where pd.temp_id = ? ";
  57. return jdbcTemplate.queryForList(sql,tempId);
  58. }
  59. public boolean updateEntryDetails(Map<String, Object> requestData) {
  60. System.out.println("requestdata"+requestData);
  61. // TODO Auto-generated method stub
  62. String empNo = (String) requestData.get("empNo");
  63. String tempId = (String) requestData.get("tempId");
  64. String dateToAudit = (String) requestData.get("dateToAudit");
  65. String filemovedby =(String)requestData.get("filemovedby");
  66. String serviceDeath =(String)requestData.get("serviceDeath");
  67. String remarks = (String) requestData.get("remarks");
  68. String dept_Id = (String) requestData.get("deptId");
  69. int deptId = Integer.parseInt(dept_Id);
  70. int filestatus=12;
  71. // Update file_status in pensioner_details
  72. String updateQuery = "update pensioner_details set service_death=?,file_moved_date=?,remarks=?,updated_date= CURRENT_TIMESTAMP,is_closed=1 WHERE temp_id = ? LIMIT 1";
  73. int rowsUpdated = jdbcTemplate.update(updateQuery,serviceDeath,dateToAudit, remarks,tempId);
  74. System.out.println("Rows inserted in pd:"+rowsUpdated);
  75. if(rowsUpdated>0)
  76. {
  77. // Optional: Insert into file movement history for auditing
  78. String historyQuery = "INSERT INTO file_movement_history (emp_no, file_moved_date, file_status, file_moved_by, remarks,temp_id) VALUES (?,?, ?, ?, ?, ?)";
  79. int rowsUpdated1=jdbcTemplate.update(historyQuery, empNo, dateToAudit, filestatus, filemovedby, remarks,tempId);
  80. System.out.println("Rows inserted in fmh:"+rowsUpdated1);
  81. return true;
  82. }
  83. else {
  84. return false;
  85. }
  86. }
  87. // save fileclosing details
  88. public boolean saveclosinghistory(List<Map<String, Object>> emp_details,String filemovedby) {
  89. try {
  90. // Loop through the list of employee details
  91. for (Map<String, Object> emp : emp_details) {
  92. // Extract individual fields from the map
  93. String empNo = emp.get("emp_no").toString();
  94. String empName = emp.get("emp_name").toString();
  95. String deptName = emp.get("dept_name").toString();
  96. String designation = emp.get("designation").toString();
  97. String serviceDeath=emp.get("service_death").toString();
  98. String fileCategoryName = emp.get("file_category_name").toString();
  99. String retirement_date = emp.get("retirement_date").toString();
  100. String retirement_class = emp.get("retirement_class").toString();
  101. String type_of_retirement = emp.get("type_of_retirement").toString();
  102. String fileMovedDate = emp.get("file_moved_date").toString();
  103. String remarks = emp.get("remarks").toString();
  104. int fileStatus = Integer.parseInt(emp.get("file_status").toString());
  105. String fileEntryType = emp.get("file_entry_type").toString();
  106. int file_category = Integer.parseInt(emp.get("file_category").toString());
  107. int dept_id = Integer.parseInt(emp.get("dept_id").toString());
  108. String temp_id = emp.get("temp_id").toString();
  109. // Prepare the insert query
  110. String insertQuery ="INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, service_death,file_moved_date, remarks,file_category,file_status,file_entry_type,file_moved_by,dept_id,file_category_name,temp_id) VALUES (?,?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?)";
  111. // Execute the query
  112. int rowsInserted = jdbcTemplate.update(insertQuery, empNo, empName, deptName,designation,serviceDeath,fileMovedDate,remarks,file_category,fileStatus,fileEntryType,filemovedby,dept_id,fileCategoryName,temp_id);
  113. System.out.println("Rows inserted in pdh:"+rowsInserted);
  114. // Check if the insertion was successful
  115. if (rowsInserted <= 0) {
  116. return false; // Return false if any insertion fails
  117. }
  118. }
  119. return true; // Return true if all insertions succeed
  120. } catch (Exception e) {
  121. e.printStackTrace();
  122. return false; // Return false in case of any exception
  123. }
  124. }
  125. //closed list
  126. public List<Map<String, Object>> fetchClosingEmployee() {
  127. System.out.println("inside");
  128. String sql = "SELECT * " +
  129. "FROM pensioner_details pd " +
  130. "where pd.file_category=1 and pd.file_status < 11 and pd.is_closed=1 ";
  131. return jdbcTemplate.queryForList(sql);
  132. }
  133. }