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.

299 lines
15 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. import in.gov.chennaicorporation.gccoffice.configuration.AppConfig;
  13. @Service
  14. public class DeptAuditService {
  15. @Autowired
  16. private JdbcTemplate jdbcTemplate;
  17. private RestTemplate restTemplate;
  18. private ObjectMapper objectMapper;
  19. @Autowired
  20. private AppConfig appconfig;
  21. public DeptAuditService(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>> fetchEmployeeDetailsByTable(Integer deptId,Integer file_cat) {
  30. String query = "SELECT * " +
  31. "FROM pensioner_details " +
  32. "WHERE dept_id=? AND file_category=? AND (file_status=1 OR file_status=3) AND is_closed=0";
  33. return jdbcTemplate.queryForList(query,deptId,file_cat);
  34. }
  35. public List<Map<String, Object>> fetchEmployeeById(String tempId) {
  36. String query = "SELECT * " +
  37. "FROM pensioner_details " +
  38. "WHERE temp_id=?";
  39. return jdbcTemplate.queryForList(query,tempId);
  40. }
  41. public List<Map<String, Object>> fetchEmployeeByIdCps(String tempId) {
  42. String query = "SELECT * " +
  43. "FROM cps_pensioner_details " +
  44. "WHERE temp_id=?";
  45. return jdbcTemplate.queryForList(query,tempId);
  46. }
  47. public List<Map<String, Object>> fetchDetailsWithZoneBenefitsById(String tempId) {
  48. String query = "SELECT pd.*, zb.gpf, zb.gpf_amount, zb.spfgs, zb.spfgs_amount, zb.dcrg, " +
  49. "zb.private_affairs, zb.private_affairs_amount, zb.recovery_emp " +
  50. "FROM pensioner_details pd " +
  51. "LEFT JOIN zone_benefits zb ON pd.temp_id = zb.temp_id " +
  52. "WHERE pd.temp_id = ?";
  53. return jdbcTemplate.queryForList(query, tempId);
  54. }//
  55. public List<Map<String, Object>> fetchFilePendingBenefits(String tempId) {
  56. String query = "SELECT pd.*, zb.gpf, zb.gpf_amount, zb.spfgs, zb.spfgs_amount, zb.dcrg, " +
  57. "zb.private_affairs, zb.private_affairs_amount, zb.recovery_emp,pb.file_pending " +
  58. "FROM pensioner_details pd " +
  59. "LEFT JOIN zone_benefits zb ON pd.temp_id = zb.temp_id " +
  60. "LEFT JOIN pension_benefits pb ON pd.temp_id = pb.temp_id " +
  61. "WHERE pd.temp_id = ?";
  62. return jdbcTemplate.queryForList(query, tempId);
  63. }
  64. public List<Map<String, Object>> fetchPartialCompleted(String tempId) {
  65. String query = "SELECT pd.*, zb.gpf, zb.gpf_amount, zb.spfgs, zb.spfgs_amount, zb.dcrg, " +
  66. "zb.private_affairs, zb.private_affairs_amount, zb.recovery_emp,pb.file_pending," +
  67. "pb.pension_number,pb.ledger_number,pb.benefit_pension,pb.benefit_pension_amount,pb.benefit_dcrg,pb.benefit_dcrg_amount,pb.benefit_commutation,pb.benefit_commutation_amount " +
  68. "FROM pensioner_details pd " +
  69. "LEFT JOIN zone_benefits zb ON pd.temp_id = zb.temp_id " +
  70. "LEFT JOIN pension_benefits pb ON pd.temp_id = pb.temp_id " +
  71. "WHERE pd.temp_id = ?";
  72. return jdbcTemplate.queryForList(query, tempId);
  73. }
  74. public List<Map<String, Object>> fetchFileMovementHistory(String tempId) {
  75. // Query to fetch file movement history
  76. String query = "SELECT fh.file_moved_date AS fileMovedDateHistory, " +
  77. "fm.file_status AS fileStatusHistory, " +
  78. "fh.remarks AS remarksHistory " +
  79. "FROM file_movement_history fh " +
  80. "JOIN file_status_master fm ON fh.file_status = fm.id " +
  81. "WHERE fh.temp_id = ?";
  82. return jdbcTemplate.queryForList(query,tempId);
  83. }
  84. @Transactional
  85. public boolean updateEntryDetails(Map<String, Object> requestData) {
  86. // TODO Auto-generated method stub
  87. String empNo = (String) requestData.get("empNo");
  88. String tempId = (String) requestData.get("tempId");
  89. String dateToAudit = (String) requestData.get("dateToAudit");
  90. String filemovedby =(String)requestData.get("filemovedby");
  91. String remarks = (String) requestData.get("remarks");
  92. String dept_Id = (String) requestData.get("deptId");
  93. int deptId = Integer.parseInt(dept_Id);
  94. int filestatus = 2;
  95. String file_entry_type="AUDIT_RETURNED";
  96. // Update file_status in pensioner_details
  97. String updateQuery = "UPDATE pensioner_details SET file_status = ?, file_entry_type =?,file_moved_date=?,remarks=?,updated_date= CURRENT_TIMESTAMP WHERE temp_id = ? LIMIT 1";
  98. int rowsUpdated = jdbcTemplate.update(updateQuery,filestatus,file_entry_type,dateToAudit, remarks,tempId);
  99. System.out.println("Rows inserted in pd:"+rowsUpdated);
  100. if(rowsUpdated>0)
  101. {
  102. // Optional: Insert into file movement history for auditing
  103. String historyQuery = "INSERT INTO file_movement_history (emp_no, file_moved_date, file_status, file_moved_by, remarks,temp_id) VALUES (?,?, ?, ?, ?, ?)";
  104. int rowsUpdated1=jdbcTemplate.update(historyQuery, empNo, dateToAudit, filestatus, filemovedby, remarks,tempId);
  105. System.out.println("Rows inserted in fmh:"+rowsUpdated1);
  106. return true;
  107. }
  108. else {
  109. return false;
  110. }
  111. }
  112. @Transactional
  113. public boolean savehistory(List<Map<String, Object>> emp_details,String filemovedby) {
  114. try {
  115. // Loop through the list of employee details
  116. for (Map<String, Object> emp : emp_details) {
  117. // Extract individual fields from the map
  118. String empNo = emp.get("emp_no").toString();
  119. String empName = emp.get("emp_name").toString();
  120. String deptName = emp.get("dept_name").toString();
  121. String designation = emp.get("designation").toString();
  122. String fileCategoryName = emp.get("file_category_name").toString();
  123. String retirement_date = emp.get("retirement_date").toString();
  124. String retirement_class = emp.get("retirement_class").toString();
  125. String type_of_retirement = emp.get("type_of_retirement").toString();
  126. String fileMovedDate = emp.get("file_moved_date").toString();
  127. String remarks = emp.get("remarks").toString();
  128. int fileStatus = Integer.parseInt(emp.get("file_status").toString());
  129. String fileEntryType = emp.get("file_entry_type").toString();
  130. int file_category = Integer.parseInt(emp.get("file_category").toString());
  131. int dept_id = Integer.parseInt(emp.get("dept_id").toString());
  132. String temp_id = emp.get("temp_id").toString();
  133. // Prepare the insert query
  134. 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 (?,?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?)";
  135. // Execute the query
  136. 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);
  137. System.out.println("Rows inserted in pdh:"+rowsInserted);
  138. // Check if the insertion was successful
  139. if (rowsInserted <= 0) {
  140. return false; // Return false if any insertion fails
  141. }
  142. }
  143. return true; // Return true if all insertions succeed
  144. } catch (Exception e) {
  145. e.printStackTrace();
  146. return false; // Return false in case of any exception
  147. }
  148. }
  149. //save the updatedfamilypension details
  150. @Transactional
  151. public boolean saveFamilyPensionHistory(List<Map<String, Object>> emp_details,String filemovedby) {
  152. try {
  153. // Loop through the list of employee details
  154. for (Map<String, Object> emp : emp_details) {
  155. // Extract individual fields from the map
  156. String empNo = emp.get("emp_no").toString();
  157. String empName = emp.get("emp_name").toString();
  158. String deptName = emp.get("dept_name").toString();
  159. String designation = emp.get("designation").toString();
  160. String fileCategoryName = emp.get("file_category_name").toString();
  161. String pendingDuration=emp.get("pending_duration").toString();
  162. String pendingReason=emp.get("reason_for_pending") != null ? emp.get("reason_for_pending").toString() : null;
  163. String serviceDeath = emp.get("service_death").toString();
  164. String relationshipDeceased = emp.get("relationship_deceased").toString();
  165. String sanctionedGis = emp.get("sanctioned_gis_amount").toString();
  166. String fileMovedDate = emp.get("file_moved_date").toString();
  167. String remarks = emp.get("remarks").toString();
  168. int fileStatus = Integer.parseInt(emp.get("file_status").toString());
  169. String fileEntryType = emp.get("file_entry_type").toString();
  170. int file_category = Integer.parseInt(emp.get("file_category").toString());
  171. int dept_id = Integer.parseInt(emp.get("dept_id").toString());
  172. String temp_id = emp.get("temp_id").toString();
  173. // Prepare the insert query
  174. 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 (?,?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?)";
  175. // Execute the query
  176. 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);
  177. System.out.println("Rows inserted in pdh:"+rowsInserted);
  178. // Check if the insertion was successful
  179. if (rowsInserted <= 0) {
  180. return false; // Return false if any insertion fails
  181. }
  182. }
  183. return true; // Return true if all insertions succeed
  184. } catch (Exception e) {
  185. e.printStackTrace();
  186. return false; // Return false in case of any exception
  187. }
  188. }
  189. //save the pendency details
  190. @Transactional
  191. public boolean savePendencyHistory(List<Map<String, Object>> emp_details,String filemovedby) {
  192. try {
  193. // Loop through the list of employee details
  194. for (Map<String, Object> emp : emp_details) {
  195. // Extract individual fields from the map
  196. String empNo = emp.get("emp_no").toString();
  197. String empName = emp.get("emp_name").toString();
  198. String deptName = emp.get("dept_name").toString();
  199. String designation = emp.get("designation").toString();
  200. String retirementClass = emp.get("retirement_class").toString();
  201. String retirementDate=emp.get("retirement_date").toString();
  202. //String fileCategoryName = emp.get("file_category_name").toString();
  203. String pendingDuration=emp.get("pending_duration").toString();
  204. String pendingReason=emp.get("reason_for_pending") != null ? emp.get("reason_for_pending").toString() : null;
  205. String typeOfCategory=emp.get("file_category_name").toString();
  206. String typeOfRetirement=emp.get("type_of_retirement").toString();
  207. String fileMovedDate = emp.get("file_moved_date").toString();
  208. String remarks = emp.get("remarks").toString();
  209. int fileStatus = Integer.parseInt(emp.get("file_status").toString());
  210. String fileEntryType = emp.get("file_entry_type").toString();
  211. int file_category = Integer.parseInt(emp.get("file_category").toString());
  212. int dept_id = Integer.parseInt(emp.get("dept_id").toString());
  213. String temp_id = emp.get("temp_id").toString();
  214. // Prepare the insert query
  215. 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 (?,?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?)";
  216. // Execute the query
  217. 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);
  218. System.out.println("Rows inserted in pdh:"+rowsInserted);
  219. // Check if the insertion was successful
  220. if (rowsInserted <= 0) {
  221. return false; // Return false if any insertion fails
  222. }
  223. }
  224. return true; // Return true if all insertions succeed
  225. } catch (Exception e) {
  226. e.printStackTrace();
  227. return false; // Return false in case of any exception
  228. }
  229. }
  230. }