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.

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