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.

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