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.

388 lines
20 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
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 PensionReceivedService {
  16. @Autowired
  17. private JdbcTemplate jdbcTemplate;
  18. private RestTemplate restTemplate;
  19. private ObjectMapper objectMapper;
  20. @Autowired
  21. private AppConfig appconfig;
  22. public PensionReceivedService(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>> fetchReceivedDepartmentEmpfiles(Integer deptId,Integer file_cat) {
  33. String query = "SELECT * " +
  34. "FROM pensioner_details " +
  35. "WHERE dept_id=? AND file_category=? AND (file_status=5 OR file_status=6) AND is_closed=0";
  36. return jdbcTemplate.queryForList(query,deptId,file_cat);
  37. }
  38. public List<Map<String, Object>> fetchZonebenefitsById(String tempId) {
  39. String query = "SELECT * " +
  40. "FROM zone_benefits " +
  41. "WHERE temp_id=?";
  42. return jdbcTemplate.queryForList(query,tempId);
  43. }
  44. public List<Map<String, Object>> fetchPensionbenefitsById(String tempId) {
  45. String query = "SELECT * " +
  46. "FROM pension_benefits " +
  47. "WHERE temp_id=?";
  48. return jdbcTemplate.queryForList(query,tempId);
  49. }
  50. public boolean updateEntryDetails(Map<String, Object> requestData) {
  51. try {
  52. String empNo = (String) requestData.get("empNo");
  53. String tempId = (String) requestData.get("tempId");
  54. String dateToAudit = (String) requestData.get("file_moved_date");
  55. String filemovedby = (String) requestData.get("filemovedby");
  56. String remarks = (String) requestData.get("remarks");
  57. String dept_Id = (String) requestData.get("deptId");
  58. int deptId = (dept_Id != null && !dept_Id.isEmpty()) ? Integer.parseInt(dept_Id) : 0;
  59. int filestatus = getFileStatus.getFileStatus7Id();
  60. if (filestatus == 0) {
  61. System.out.println("File status not found. Aborting insertion.");
  62. return false;
  63. }
  64. String gpf = (String) requestData.get("gpf");
  65. String private_affairs = (String) requestData.get("private_affairs");
  66. String spfgs = (String) requestData.get("spfgs");
  67. String recovery_emp = (String) requestData.get("recovery_emp");
  68. String dcrg = (String) requestData.get("dcrg");
  69. String gpfAmount = requestData.get("gpfAmount") != null ? requestData.get("gpfAmount").toString() : null;
  70. String private_affairs_amount = requestData.get("private_affairs_amount") != null ? requestData.get("private_affairs_amount").toString() : null;
  71. String spfgs_amount = requestData.get("spfgs_amount") != null ? requestData.get("spfgs_amount").toString() : null;
  72. boolean check = checkTempIdInZoneBenefits(tempId);
  73. // Update file_status in pensioner_details
  74. String updateQuery = "UPDATE pensioner_details SET file_status = ?, file_moved_date = ?, remarks = ?, updated_date = CURRENT_TIMESTAMP WHERE temp_id = ?";
  75. int rowsUpdated = jdbcTemplate.update(updateQuery, filestatus, dateToAudit, remarks, tempId);
  76. System.out.println("Rows updated in pensioner_details: " + rowsUpdated);
  77. if (rowsUpdated > 0) {
  78. // Insert into file movement history
  79. String historyQuery = "INSERT INTO file_movement_history (emp_no, file_moved_date, file_status, file_moved_by, remarks, temp_id) VALUES (?, ?, ?, ?, ?, ?)";
  80. int rowsUpdated1 = jdbcTemplate.update(historyQuery, empNo, dateToAudit, filestatus, filemovedby, remarks, tempId);
  81. System.out.println("Rows inserted in file_movement_history: " + rowsUpdated1);
  82. if (rowsUpdated1 > 0) {
  83. if (check) {
  84. // Update zone benefits
  85. String updateQuery1 = "UPDATE zone_benefits SET gpf = ?, gpf_amount = ?, spfgs = ?, spfgs_amount = ?, dcrg = ?, private_affairs = ?, private_affairs_amount = ?, recovery_emp = ?, updated_date = CURRENT_TIMESTAMP WHERE temp_id = ?";
  86. int rowsUpdated3 = jdbcTemplate.update(updateQuery1, gpf, gpfAmount, spfgs, spfgs_amount, dcrg, private_affairs, private_affairs_amount, recovery_emp, tempId);
  87. System.out.println("Rows updated in zone_benefits: " + rowsUpdated3);
  88. } else {
  89. // Insert into zone benefits
  90. String benefitQuery = "INSERT INTO zone_benefits (emp_no, temp_id, gpf, gpf_amount, spfgs, spfgs_amount, dcrg, private_affairs, private_affairs_amount, recovery_emp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  91. int rowsUpdated2 = jdbcTemplate.update(benefitQuery, empNo, tempId, gpf, gpfAmount, spfgs, spfgs_amount, dcrg, private_affairs, private_affairs_amount, recovery_emp);
  92. System.out.println("Rows inserted in zone_benefits: " + rowsUpdated2);
  93. }
  94. return true;
  95. } else {
  96. System.out.println("Failed to insert into file_movement_history");
  97. return false;
  98. }
  99. } else {
  100. System.out.println("Failed to update pensioner_details");
  101. return false;
  102. }
  103. } catch (Exception e) {
  104. System.err.println("Exception in updateEntryDetails: " + e.getMessage());
  105. return false;
  106. }
  107. }
  108. public boolean saveHistory(List<Map<String, Object>> empDetails, List<Map<String, Object>> zoneBenefits, String fileMovedBy) {
  109. try {
  110. // Batch update for employee details
  111. int file_Cat=0;
  112. if (!empDetails.isEmpty()) {
  113. Map<String, Object> firstEmployeeDetails = empDetails.get(0);
  114. Object fileCatObj = firstEmployeeDetails.get("file_category");
  115. if (fileCatObj != null) {
  116. try {
  117. file_Cat = Integer.parseInt(fileCatObj.toString());
  118. System.out.println("Parsed file_category: " + file_Cat);
  119. } catch (NumberFormatException e) {
  120. System.err.println("Failed to parse file_category: " + fileCatObj);
  121. }
  122. } else {
  123. System.out.println("file_category is null in emp_details.");
  124. }
  125. } else {
  126. System.out.println("emp_details is empty.");
  127. }
  128. if(file_Cat==1) {
  129. String empInsertQuery =
  130. "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, type_of_retirement, " +
  131. "retirement_date, retirement_class, file_moved_date, remarks, file_category, file_status, " +
  132. "file_entry_type, file_moved_by, dept_id, file_category_name, temp_id) " +
  133. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  134. jdbcTemplate.batchUpdate(empInsertQuery, empDetails, empDetails.size(), (ps, emp) -> {
  135. ps.setString(1, emp.get("emp_no").toString());
  136. ps.setString(2, emp.get("emp_name").toString());
  137. ps.setString(3, emp.get("dept_name").toString());
  138. ps.setString(4, emp.get("designation").toString());
  139. ps.setString(5, emp.get("type_of_retirement").toString());
  140. ps.setString(6, emp.get("retirement_date").toString());
  141. ps.setString(7, emp.get("retirement_class").toString());
  142. ps.setString(8, emp.get("file_moved_date").toString());
  143. ps.setString(9, emp.get("remarks").toString());
  144. ps.setInt(10, Integer.parseInt(emp.get("file_category").toString()));
  145. ps.setInt(11, Integer.parseInt(emp.get("file_status").toString()));
  146. ps.setString(12, emp.get("file_entry_type").toString());
  147. ps.setString(13, fileMovedBy);
  148. ps.setInt(14, Integer.parseInt(emp.get("dept_id").toString()));
  149. ps.setString(15, emp.get("file_category_name").toString());
  150. ps.setString(16, emp.get("temp_id").toString());
  151. });
  152. System.out.println("rows inserted in pd history for retirement");
  153. }
  154. if(file_Cat==2)
  155. {
  156. String empInsertQuery1 =
  157. "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, service_death, " +
  158. "relationship_deceased, sanctioned_gis_amount, file_moved_date, remarks, file_category, file_status, " +
  159. "file_entry_type, file_moved_by, dept_id, file_category_name, temp_id,pending_duration,reason_for_pending) " +
  160. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)";
  161. jdbcTemplate.batchUpdate(empInsertQuery1, empDetails, empDetails.size(), (ps, emp) -> {
  162. ps.setString(1, emp.get("emp_no").toString());
  163. ps.setString(2, emp.get("emp_name").toString());
  164. ps.setString(3, emp.get("dept_name").toString());
  165. ps.setString(4, emp.get("designation").toString());
  166. ps.setString(5, emp.get("service_death").toString());
  167. ps.setString(6, emp.get("relationship_deceased").toString());
  168. ps.setString(7, emp.get("sanctioned_gis_amount").toString());
  169. ps.setString(8, emp.get("file_moved_date").toString());
  170. ps.setString(9, emp.get("remarks").toString());
  171. ps.setInt(10, Integer.parseInt(emp.get("file_category").toString()));
  172. ps.setInt(11, Integer.parseInt(emp.get("file_status").toString()));
  173. ps.setString(12, emp.get("file_entry_type").toString());
  174. ps.setString(13, fileMovedBy);
  175. ps.setInt(14, Integer.parseInt(emp.get("dept_id").toString()));
  176. ps.setString(15, emp.get("file_category_name").toString());
  177. ps.setString(16, emp.get("temp_id").toString());
  178. ps.setString(17, emp.get("pending_duration").toString());
  179. ps.setString(18, emp.get("reason_for_pending") != null ? emp.get("reason_for_pending").toString() : null);
  180. });
  181. System.out.println("rows inserted in pd history for family Pension");
  182. }
  183. if(file_Cat==3)
  184. {
  185. String empInsertQuery2 =
  186. "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation,type_of_retirement, " +
  187. "file_moved_date, remarks, file_category, file_status, " +
  188. "file_entry_type, file_moved_by, dept_id, file_category_name, temp_id,pending_duration,reason_for_pending,retirement_class,retirement_date) " +
  189. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)";
  190. jdbcTemplate.batchUpdate(empInsertQuery2, empDetails, empDetails.size(), (ps, emp) -> {
  191. ps.setString(1, emp.get("emp_no").toString());
  192. ps.setString(2, emp.get("emp_name").toString());
  193. ps.setString(3, emp.get("dept_name").toString());
  194. ps.setString(4, emp.get("designation").toString());
  195. ps.setString(5, emp.get("type_of_retirement").toString());
  196. ps.setString(6, emp.get("file_moved_date").toString());
  197. ps.setString(7, emp.get("remarks").toString());
  198. ps.setInt(8, Integer.parseInt(emp.get("file_category").toString()));
  199. ps.setInt(9, Integer.parseInt(emp.get("file_status").toString()));
  200. ps.setString(10, emp.get("file_entry_type").toString());
  201. ps.setString(11, fileMovedBy);
  202. ps.setInt(12, Integer.parseInt(emp.get("dept_id").toString()));
  203. ps.setString(13, emp.get("file_category_name").toString());
  204. ps.setString(14, emp.get("temp_id").toString());
  205. ps.setString(15, emp.get("pending_duration").toString());
  206. ps.setString(16, emp.get("reason_for_pending") != null ? emp.get("reason_for_pending").toString() : null);
  207. ps.setString(17, emp.get("retirement_class").toString());
  208. ps.setString(18, emp.get("retirement_date").toString());
  209. });
  210. System.out.println("rows inserted in pd history for pendency");
  211. }
  212. // Batch update for zone benefits
  213. String zoneInsertQuery =
  214. "INSERT INTO zone_benefits_history (emp_no, temp_id, gpf, gpf_amount, spfgs, spfgs_amount, dcrg, " +
  215. "private_affairs, private_affairs_amount, recovery_emp, file_moved_by) " +
  216. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  217. jdbcTemplate.batchUpdate(zoneInsertQuery, zoneBenefits, zoneBenefits.size(), (ps, zone) -> {
  218. ps.setString(1, zone.get("emp_no").toString());
  219. ps.setString(2, zone.get("temp_id").toString());
  220. ps.setString(3, zone.get("gpf").toString());
  221. ps.setString(4, zone.get("gpf_amount") != null ? zone.get("gpf_amount").toString() : null);
  222. ps.setString(5, zone.get("spfgs").toString());
  223. ps.setString(6, zone.get("spfgs_amount") != null ? zone.get("spfgs_amount").toString() : null);
  224. ps.setString(7, zone.get("dcrg").toString());
  225. ps.setString(8, zone.get("private_affairs").toString());
  226. ps.setString(9, zone.get("private_affairs_amount") != null ? zone.get("private_affairs_amount").toString() : null);
  227. ps.setString(10, zone.get("recovery_emp") != null ? zone.get("recovery_emp").toString() : null);
  228. ps.setString(11, fileMovedBy);
  229. });
  230. System.out.println("rows inserted in zone history for family Pension");
  231. return true; // All insertions succeeded
  232. } catch (Exception e) {
  233. e.printStackTrace();
  234. return false; // Return false in case of any exception
  235. }
  236. }
  237. /*
  238. */
  239. public boolean checkTempIdInZoneBenefits(String tempId) {
  240. String query = "SELECT EXISTS (SELECT 1 FROM zone_benefits WHERE temp_id = ?)";
  241. return Boolean.TRUE.equals(jdbcTemplate.queryForObject(query, Boolean.class, tempId));
  242. }
  243. //gis
  244. public boolean updateEntryGisDetails(Map<String, Object> requestData) {
  245. // TODO Auto-generated method stub
  246. String empNo = (String) requestData.get("empNo");
  247. String tempId = (String) requestData.get("tempId");
  248. String dateToAudit = (String) requestData.get("dateToAudit");
  249. String filemovedby =(String)requestData.get("filemovedby");
  250. String remarks = (String) requestData.get("remarks");
  251. String dept_Id = (String) requestData.get("deptId");
  252. String sanctional_gis_date = (String) requestData.get("sanctional_gis_date");
  253. String sanctional_gis_amount = (String) requestData.get("sanctional_gis_amount");
  254. String lic_date = (String) requestData.get("lic_date");
  255. int deptId = Integer.parseInt(dept_Id);
  256. int filestatus = getFileStatus.getFileStatus11Id();
  257. if (filestatus == 0) {
  258. System.out.println("File status not found. Aborting insertion.");
  259. return false;
  260. }
  261. String fileentrytype = "FILE_COMPLETED";
  262. String updateQuery = "UPDATE pensioner_details SET file_status = ?, file_moved_date = ?, remarks = ?, sanctional_gis_date = ?, sanctional_gis_amount = ?, lic_date = ?,file_entry_type=? ,updated_date = CURRENT_TIMESTAMP WHERE temp_id = ? LIMIT 1";
  263. int rowsUpdated = jdbcTemplate.update(updateQuery, filestatus, dateToAudit, remarks, sanctional_gis_date, sanctional_gis_amount, lic_date,fileentrytype ,tempId);
  264. //int rowsUpdated = jdbcTemplate.update(updateQuery,filestatus,dateToAudit, remarks,sanctional_gis_date,sanctional_gis_amount,lic_date,tempId);
  265. System.out.println(dateToAudit);
  266. System.out.println(sanctional_gis_date);
  267. System.out.println(sanctional_gis_amount);
  268. System.out.println(lic_date);
  269. System.out.println("Rows inserted in pd:"+rowsUpdated);
  270. if(rowsUpdated>0)
  271. {
  272. // Optional: Insert into file movement history for auditing
  273. String historyQuery = "INSERT INTO file_movement_history (emp_no, file_moved_date, file_status, file_moved_by, remarks,temp_id) VALUES (?,?, ?, ?, ?, ?)";
  274. int rowsUpdated1=jdbcTemplate.update(historyQuery, empNo, dateToAudit, filestatus, filemovedby, remarks,tempId);
  275. System.out.println("Rows inserted in fmh:"+rowsUpdated1);
  276. return true;
  277. }
  278. else {
  279. return false;
  280. }
  281. }
  282. public boolean savehistoryGis(List<Map<String, Object>> emp_details,String filemovedby) {
  283. try {
  284. // Loop through the list of employee details
  285. for (Map<String, Object> emp : emp_details) {
  286. // Extract individual fields from the map
  287. String empNo = emp.get("emp_no").toString();
  288. String empName = emp.get("emp_name").toString();
  289. String deptName = emp.get("dept_name").toString();
  290. String designation = emp.get("designation").toString();
  291. String fileCategoryName = emp.get("file_category_name").toString();
  292. String fileMovedDate = emp.get("file_moved_date").toString();
  293. String remarks = emp.get("remarks").toString();
  294. int fileStatus = Integer.parseInt(emp.get("file_status").toString());
  295. String fileEntryType = emp.get("file_entry_type").toString();
  296. int file_category = Integer.parseInt(emp.get("file_category").toString());
  297. int dept_id = Integer.parseInt(emp.get("dept_id").toString());
  298. String sanctional_gis_date=emp.get("sanctional_gis_date").toString();
  299. String sanctional_gis_amount=emp.get("sanctional_gis_amount").toString();
  300. String lic_date=emp.get("lic_date").toString();
  301. String temp_id = emp.get("temp_id").toString();
  302. // Prepare the insert query
  303. String insertQuery = "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, file_moved_date, remarks, file_category, file_status, file_entry_type, file_moved_by, dept_id, file_category_name, temp_id, sanctional_gis_date, sanctional_gis_amount, lic_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  304. // Execute the query
  305. int rowsInserted = jdbcTemplate.update(insertQuery, empNo, empName, deptName,designation,fileMovedDate,remarks,file_category,fileStatus,fileEntryType,filemovedby,dept_id,fileCategoryName,temp_id,sanctional_gis_date,sanctional_gis_amount,lic_date);
  306. System.out.println("Rows inserted in pdh:"+rowsInserted);
  307. // Check if the insertion was successful
  308. if (rowsInserted <= 0) {
  309. return false; // Return false if any insertion fails
  310. }
  311. }
  312. return true; // Return true if all insertions succeed
  313. } catch (Exception e) {
  314. e.printStackTrace();
  315. return false; // Return false in case of any exception
  316. }
  317. }
  318. }