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.

692 lines
37 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
2 years ago
2 years ago
​
2 years ago
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
​
2 years ago
​
2 years ago
2 years ago
​
2 years ago
2 years ago
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
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.dao.DataAccessException;
  8. import org.springframework.jdbc.core.JdbcTemplate;
  9. import org.springframework.stereotype.Service;
  10. import org.springframework.transaction.annotation.Transactional;
  11. import org.springframework.web.client.RestTemplate;
  12. import com.fasterxml.jackson.databind.ObjectMapper;
  13. import in.gov.chennaicorporation.gccoffice.configuration.AppConfig;
  14. @Service
  15. public class DepartmentReceivedService {
  16. @Autowired
  17. private JdbcTemplate jdbcTemplate;
  18. private RestTemplate restTemplate;
  19. private ObjectMapper objectMapper;
  20. @Autowired
  21. private AppConfig appconfig;
  22. public DepartmentReceivedService(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>> fetchPensionReceivedEmpfiles(Integer file_cat) {
  33. String query = "SELECT * " +
  34. "FROM pensioner_details " +
  35. "WHERE file_category=? AND (file_status=7 OR file_status=8) AND is_closed=0";
  36. return jdbcTemplate.queryForList(query,file_cat);
  37. }
  38. public List<Map<String, Object>> fetchPensionbenefitsById(String tempId) {
  39. String query = "SELECT * " +
  40. "FROM pension_benefits " +
  41. "WHERE temp_id=?";
  42. return jdbcTemplate.queryForList(query,tempId);
  43. }
  44. @Transactional
  45. public boolean updateEntryCompletedDetails(Map<String, Object> requestData) {
  46. try {
  47. String empNo = (String) requestData.get("empNo");
  48. String tempId = (String) requestData.get("tempId");
  49. String dateToAudit = (String) requestData.get("dateToAudit");
  50. String filemovedby = (String) requestData.get("filemovedby");
  51. String remarks = (String) requestData.get("remarks");
  52. String dept_Id = (String) requestData.get("deptId");
  53. String file_pending = (String) requestData.get("file_pending");
  54. String pension_number = (String) requestData.get("pension_number");
  55. String ledger_number = (String) requestData.get("ledger_number");
  56. String benefit_pension = (String) requestData.get("benefit_pension");
  57. String benefit_dcrg = requestData.get("benefit_dcrg") != null ? requestData.get("benefit_dcrg").toString() : null;
  58. String benefit_commutation = (String) requestData.get("benefit_commutation");
  59. String benefit_pension_amount = (String) requestData.get("benefit_pension_amount")!= null ? requestData.get("benefit_pension_amount").toString() : null;
  60. String benefit_dcrg_amount = requestData.get("benefit_dcrg_amount") != null ? requestData.get("benefit_dcrg_amount").toString() : null;
  61. String benefit_commutation_amount = (String) requestData.get("benefit_commutation_amount") != null ? requestData.get("benefit_commutation_amount").toString() : null;
  62. int deptId = Integer.parseInt(dept_Id);
  63. int filestatus=0;
  64. String file_entry_type="";
  65. boolean check = checkTempPresent(tempId);
  66. if (check) {
  67. String updateQuery1 = "UPDATE pension_benefits SET file_pending = ?, pension_number = ?, ledger_number = ?, benefit_pension = ?, benefit_pension_amount = ?, benefit_dcrg = ?, benefit_dcrg_amount = ?, benefit_commutation = ?, benefit_commutation_amount = ?, updated_date = CURRENT_TIMESTAMP WHERE temp_id = ?";
  68. int rowsUpdated3 = jdbcTemplate.update(updateQuery1, file_pending, pension_number, ledger_number, benefit_pension, benefit_pension_amount, benefit_dcrg, benefit_dcrg_amount, benefit_commutation, benefit_commutation_amount, tempId);
  69. } else {
  70. String benefitQuery = "INSERT INTO pension_benefits (emp_no, temp_id, file_pending, pension_number, ledger_number, benefit_pension, benefit_pension_amount, benefit_dcrg, benefit_dcrg_amount, benefit_commutation, benefit_commutation_amount) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  71. int rowsUpdated2 = jdbcTemplate.update(benefitQuery, empNo, tempId, file_pending, pension_number, ledger_number, benefit_pension, benefit_pension_amount, benefit_dcrg, benefit_dcrg_amount, benefit_commutation, benefit_commutation_amount);
  72. }
  73. if ("yes".equalsIgnoreCase(benefit_dcrg)) {
  74. filestatus = CheckFieldsInDept(tempId) ? (CheckFieldsInPensioner(tempId) ? getFileStatus.getFileStatus11Id() : getFileStatus.getFileStatus10Id() ) : getFileStatus.getFileStatus9Id();
  75. file_entry_type="FILE_COMPLETED";
  76. }
  77. else if("no".equalsIgnoreCase(benefit_dcrg) || "no".equalsIgnoreCase(benefit_pension)){
  78. filestatus = getFileStatus.getFileStatus10Id();
  79. file_entry_type="PENSION_PARTIAL";
  80. }
  81. else if(benefit_dcrg==null)
  82. {
  83. filestatus = getFileStatus.getFileStatus9Id();
  84. file_entry_type="DEPARTMENT_PARTIAL";
  85. }
  86. //getFileStatus.getFileStatus2Id();
  87. if (filestatus == 0) {
  88. System.out.println("File status not found. Aborting insertion.");
  89. return false;
  90. }
  91. String updateQuery = "UPDATE pensioner_details SET file_entry_type=?,file_status = ?, file_moved_date = ?, remarks = ?, updated_date = CURRENT_TIMESTAMP WHERE temp_id = ? LIMIT 1";
  92. int rowsUpdated = jdbcTemplate.update(updateQuery,file_entry_type, filestatus, dateToAudit, remarks, tempId);
  93. if (rowsUpdated > 0) {
  94. String historyQuery = "INSERT INTO file_movement_history (emp_no, file_moved_date, file_status, file_moved_by, remarks, temp_id) VALUES (?, ?, ?, ?, ?, ?)";
  95. int rowsUpdated1 = jdbcTemplate.update(historyQuery, empNo, dateToAudit, filestatus, filemovedby, remarks, tempId);
  96. if (rowsUpdated1 > 0) {
  97. return true;
  98. }
  99. }
  100. return false;
  101. } catch (NumberFormatException e) {
  102. System.err.println("Error parsing department ID: " + e.getMessage());
  103. return false;
  104. } catch (DataAccessException e) {
  105. System.err.println("Database operation failed: " + e.getMessage());
  106. return false;
  107. } catch (Exception e) {
  108. System.err.println("Unexpected error: " + e.getMessage());
  109. return false;
  110. }
  111. }
  112. private boolean checkTempPresent(String tempId) {
  113. String query = "SELECT EXISTS (SELECT 1 FROM pension_benefits WHERE temp_id = ?)";
  114. return Boolean.TRUE.equals(jdbcTemplate.queryForObject(query, Boolean.class, tempId));
  115. }
  116. private boolean CheckFieldsInDept(String tempId) {
  117. // Define the SQL query
  118. String sql = "SELECT CASE " +
  119. "WHEN (gpf = 'yes' OR gpf = '90') AND spfgs = 'yes' AND private_affairs = 'yes' AND dcrg = 'yes' THEN true " +
  120. "ELSE false END AS allYes " +
  121. "FROM zone_benefits " +
  122. "WHERE temp_id = ?";
  123. try {
  124. // Use queryForObject to get a single boolean result
  125. Boolean result = jdbcTemplate.queryForObject(sql, Boolean.class, tempId);
  126. return result != null && result; // Return the result if not null
  127. } catch (Exception e) {
  128. e.printStackTrace(); // Log the exception if needed
  129. }
  130. return false; // Return false if an exception occurs
  131. }
  132. private boolean CheckFieldsInPensioner(String tempId) {
  133. // Define the SQL query
  134. String sql = "SELECT CASE " +
  135. "WHEN benefit_pension = 'yes' AND benefit_dcrg = 'yes' THEN true " +
  136. "ELSE false END AS allYes " +
  137. "FROM pension_benefits " +
  138. "WHERE temp_id = ?";
  139. try {
  140. // Use queryForObject to get a single boolean result
  141. Boolean result = jdbcTemplate.queryForObject(sql, Boolean.class, tempId);
  142. return result != null && result; // Return the result if not null
  143. } catch (Exception e) {
  144. e.printStackTrace(); // Log the exception if needed
  145. }
  146. return false; // Return false if an exception occurs
  147. }
  148. @Transactional
  149. public boolean saveRetirementCompletedhistory(List<Map<String, Object>> emp_details,List<Map<String, Object>> pension_details,String filemovedby) {
  150. try {
  151. int file_Cat=0;
  152. if (!emp_details.isEmpty()) {
  153. Map<String, Object> firstEmployeeDetails = emp_details.get(0);
  154. Object fileCatObj = firstEmployeeDetails.get("file_category");
  155. if (fileCatObj != null) {
  156. try {
  157. file_Cat = Integer.parseInt(fileCatObj.toString());
  158. System.out.println("Parsed file_category: " + file_Cat);
  159. } catch (NumberFormatException e) {
  160. System.err.println("Failed to parse file_category: " + fileCatObj);
  161. }
  162. } else {
  163. System.out.println("file_category is null in emp_details.");
  164. }
  165. } else {
  166. System.out.println("emp_details is empty.");
  167. }
  168. // Batch update for employee details
  169. if(file_Cat==1) {
  170. String empInsertQuery =
  171. "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, type_of_retirement, " +
  172. "retirement_date, retirement_class, file_moved_date, remarks, file_category, file_status, " +
  173. "file_entry_type, file_moved_by, dept_id, file_category_name, temp_id) " +
  174. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  175. jdbcTemplate.batchUpdate(empInsertQuery, emp_details, emp_details.size(), (ps, emp) -> {
  176. ps.setString(1, emp.get("emp_no").toString());
  177. ps.setString(2, emp.get("emp_name").toString());
  178. ps.setString(3, emp.get("dept_name").toString());
  179. ps.setString(4, emp.get("designation").toString());
  180. ps.setString(5, emp.get("type_of_retirement").toString());
  181. ps.setString(6, emp.get("retirement_date").toString());
  182. ps.setString(7, emp.get("retirement_class").toString());
  183. ps.setString(8, emp.get("file_moved_date").toString());
  184. ps.setString(9, emp.get("remarks").toString());
  185. ps.setInt(10, Integer.parseInt(emp.get("file_category").toString()));
  186. ps.setInt(11, Integer.parseInt(emp.get("file_status").toString()));
  187. ps.setString(12, emp.get("file_entry_type").toString());
  188. ps.setString(13, filemovedby);
  189. ps.setInt(14, Integer.parseInt(emp.get("dept_id").toString()));
  190. ps.setString(15, emp.get("file_category_name").toString());
  191. ps.setString(16, emp.get("temp_id").toString());
  192. });
  193. }
  194. if(file_Cat==2)
  195. {
  196. String empInsertQuery1 =
  197. "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, service_death, " +
  198. "relationship_deceased, sanctioned_gis_amount, file_moved_date, remarks, file_category, file_status, " +
  199. "file_entry_type, file_moved_by, dept_id, file_category_name, temp_id,pending_duration,reason_for_pending) " +
  200. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)";
  201. jdbcTemplate.batchUpdate(empInsertQuery1, emp_details, emp_details.size(), (ps, emp) -> {
  202. ps.setString(1, emp.get("emp_no").toString());
  203. ps.setString(2, emp.get("emp_name").toString());
  204. ps.setString(3, emp.get("dept_name").toString());
  205. ps.setString(4, emp.get("designation").toString());
  206. ps.setString(5, emp.get("service_death").toString());
  207. ps.setString(6, emp.get("relationship_deceased").toString());
  208. ps.setString(7, emp.get("sanctioned_gis_amount").toString());
  209. ps.setString(8, emp.get("file_moved_date").toString());
  210. ps.setString(9, emp.get("remarks").toString());
  211. ps.setInt(10, Integer.parseInt(emp.get("file_category").toString()));
  212. ps.setInt(11, Integer.parseInt(emp.get("file_status").toString()));
  213. ps.setString(12, emp.get("file_entry_type").toString());
  214. ps.setString(13, filemovedby);
  215. ps.setInt(14, Integer.parseInt(emp.get("dept_id").toString()));
  216. ps.setString(15, emp.get("file_category_name").toString());
  217. ps.setString(16, emp.get("temp_id").toString());
  218. ps.setString(17, emp.get("pending_duration").toString());
  219. ps.setString(18, emp.get("reason_for_pending") != null ? emp.get("reason_for_pending").toString() : null);
  220. });
  221. System.out.println("rows inserted in pd history for family Pension");
  222. }
  223. if(file_Cat==3)
  224. {
  225. String empInsertQuery2 =
  226. "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation,type_of_retirement, " +
  227. "file_moved_date, remarks, file_category, file_status, " +
  228. "file_entry_type, file_moved_by, dept_id, file_category_name, temp_id,pending_duration,reason_for_pending,retirement_class,retirement_date) " +
  229. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)";
  230. jdbcTemplate.batchUpdate(empInsertQuery2, emp_details, emp_details.size(), (ps, emp) -> {
  231. ps.setString(1, emp.get("emp_no").toString());
  232. ps.setString(2, emp.get("emp_name").toString());
  233. ps.setString(3, emp.get("dept_name").toString());
  234. ps.setString(4, emp.get("designation").toString());
  235. ps.setString(5, emp.get("type_of_retirement").toString());
  236. ps.setString(6, emp.get("file_moved_date").toString());
  237. ps.setString(7, emp.get("remarks").toString());
  238. ps.setInt(8, Integer.parseInt(emp.get("file_category").toString()));
  239. ps.setInt(9, Integer.parseInt(emp.get("file_status").toString()));
  240. ps.setString(10, emp.get("file_entry_type").toString());
  241. ps.setString(11, filemovedby);
  242. ps.setInt(12, Integer.parseInt(emp.get("dept_id").toString()));
  243. ps.setString(13, emp.get("file_category_name").toString());
  244. ps.setString(14, emp.get("temp_id").toString());
  245. ps.setString(15, emp.get("pending_duration").toString());
  246. ps.setString(16, emp.get("reason_for_pending") != null ? emp.get("reason_for_pending").toString() : null);
  247. ps.setString(17, emp.get("retirement_class").toString());
  248. ps.setString(18, emp.get("retirement_date").toString());
  249. });
  250. System.out.println("rows inserted in pd history for pending");
  251. }
  252. String pensionInsertQuery =
  253. "INSERT INTO pension_benefits_history (emp_no,temp_id,file_pending,pension_number,ledger_number,benefit_pension,benefit_pension_amount,benefit_dcrg,benefit_dcrg_amount,benefit_commutation,benefit_commutation_amount,file_moved_by) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
  254. jdbcTemplate.batchUpdate(pensionInsertQuery, pension_details, pension_details.size(), (ps, pension) -> {
  255. ps.setString(1, pension.get("emp_no").toString());
  256. ps.setString(2, pension.get("temp_id").toString());
  257. ps.setString(3, pension.get("file_pending").toString());
  258. ps.setString(4, pension.get("pension_number").toString());
  259. ps.setString(5, pension.get("ledger_number").toString());
  260. ps.setString(6, pension.get("benefit_pension").toString());
  261. ps.setString(7, pension.get("benefit_pension_amount") != null ? pension.get("benefit_pension_amount").toString() : null);
  262. ps.setString(8, pension.get("benefit_dcrg") != null ? pension.get("benefit_dcrg").toString() : null);
  263. ps.setString(9, pension.get("benefit_dcrg_amount") != null ? pension.get("benefit_dcrg_amount").toString() : null);
  264. ps.setString(10, pension.get("benefit_commutation").toString());
  265. ps.setString(11, pension.get("benefit_commutation_amount") != null ? pension.get("benefit_commutation_amount").toString() : null);
  266. ps.setString(12, filemovedby);
  267. });
  268. System.out.println("rows inserted in pension history for family Pension");
  269. return true; // Return true if all insertions succeed
  270. } catch (Exception e) {
  271. e.printStackTrace();
  272. return false; // Return false in case of any exception
  273. }
  274. }
  275. @Transactional
  276. public boolean updateEntryPendingDetails(Map<String, Object> requestData) {
  277. // TODO Auto-generated method stub
  278. String empNo = (String) requestData.get("empNo");
  279. String tempId = (String) requestData.get("tempId");
  280. String dateToAudit = (String) requestData.get("dateToAudit");
  281. String filemovedby =(String)requestData.get("filemovedby");
  282. String remarks = (String) requestData.get("remarks");
  283. String dept_Id = (String) requestData.get("deptId");
  284. String file_pending = (String) requestData.get("file_pending");
  285. int deptId = Integer.parseInt(dept_Id);
  286. int filestatus = getFileStatus.getFileStatus8Id();
  287. if (filestatus == 0) {
  288. System.out.println("File status not found. Aborting insertion.");
  289. return false;
  290. }
  291. String file_entry_type="FILE_PENDING";
  292. String updateQuery = "UPDATE pensioner_details SET file_status = ?,file_entry_type=?,file_moved_date=?,remarks=?,updated_date= CURRENT_TIMESTAMP WHERE temp_id = ? LIMIT 1";
  293. int rowsUpdated = jdbcTemplate.update(updateQuery,filestatus,file_entry_type,dateToAudit, remarks,tempId);
  294. System.out.println("Rows inserted in pd:"+rowsUpdated);
  295. if(rowsUpdated>0)
  296. {
  297. // Optional: Insert into file movement history for auditing
  298. String historyQuery = "INSERT INTO file_movement_history (emp_no, file_moved_date, file_status, file_moved_by, remarks,temp_id) VALUES (?,?, ?, ?, ?, ?)";
  299. int rowsUpdated1=jdbcTemplate.update(historyQuery, empNo, dateToAudit, filestatus, filemovedby, remarks,tempId);
  300. System.out.println("Rows inserted in fmh:"+rowsUpdated1);
  301. if(rowsUpdated1>0)
  302. {
  303. // Insert into zone benefits
  304. String benefitQuery="INSERT INTO pension_benefits (emp_no,temp_id,file_pending) VALUES (?,?,?)";
  305. int rowsUpdated2=jdbcTemplate.update(benefitQuery,empNo,tempId,file_pending);
  306. System.out.println("Rows inserted in pb1:"+rowsUpdated2);
  307. return true;
  308. }
  309. else
  310. {
  311. return false;
  312. }
  313. }
  314. else {
  315. return false;
  316. }
  317. }
  318. @Transactional
  319. public boolean saveRetirementPendinghistory(List<Map<String, Object>> emp_details,List<Map<String, Object>> pension_details,String filemovedby) {
  320. try {
  321. int file_Cat=0;
  322. if (!emp_details.isEmpty()) {
  323. Map<String, Object> firstEmployeeDetails = emp_details.get(0);
  324. Object fileCatObj = firstEmployeeDetails.get("file_category");
  325. if (fileCatObj != null) {
  326. try {
  327. file_Cat = Integer.parseInt(fileCatObj.toString());
  328. System.out.println("Parsed file_category: " + file_Cat);
  329. } catch (NumberFormatException e) {
  330. System.err.println("Failed to parse file_category: " + fileCatObj);
  331. }
  332. } else {
  333. System.out.println("file_category is null in emp_details.");
  334. }
  335. } else {
  336. System.out.println("emp_details is empty.");
  337. }
  338. // Batch update for employee details
  339. if(file_Cat==1) {
  340. String empInsertQuery =
  341. "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, type_of_retirement, " +
  342. "retirement_date, retirement_class, file_moved_date, remarks, file_category, file_status, " +
  343. "file_entry_type, file_moved_by, dept_id, file_category_name, temp_id) " +
  344. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  345. jdbcTemplate.batchUpdate(empInsertQuery, emp_details, emp_details.size(), (ps, emp) -> {
  346. ps.setString(1, emp.get("emp_no").toString());
  347. ps.setString(2, emp.get("emp_name").toString());
  348. ps.setString(3, emp.get("dept_name").toString());
  349. ps.setString(4, emp.get("designation").toString());
  350. ps.setString(5, emp.get("type_of_retirement").toString());
  351. ps.setString(6, emp.get("retirement_date").toString());
  352. ps.setString(7, emp.get("retirement_class").toString());
  353. ps.setString(8, emp.get("file_moved_date").toString());
  354. ps.setString(9, emp.get("remarks").toString());
  355. ps.setInt(10, Integer.parseInt(emp.get("file_category").toString()));
  356. ps.setInt(11, Integer.parseInt(emp.get("file_status").toString()));
  357. ps.setString(12, emp.get("file_entry_type").toString());
  358. ps.setString(13, filemovedby);
  359. ps.setInt(14, Integer.parseInt(emp.get("dept_id").toString()));
  360. ps.setString(15, emp.get("file_category_name").toString());
  361. ps.setString(16, emp.get("temp_id").toString());
  362. });
  363. }
  364. if(file_Cat==2)
  365. {
  366. String empInsertQuery1 =
  367. "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, service_death, " +
  368. "relationship_deceased, sanctioned_gis_amount, file_moved_date, remarks, file_category, file_status, " +
  369. "file_entry_type, file_moved_by, dept_id, file_category_name, temp_id,pending_duration,reason_for_pending) " +
  370. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)";
  371. jdbcTemplate.batchUpdate(empInsertQuery1, emp_details, emp_details.size(), (ps, emp) -> {
  372. ps.setString(1, emp.get("emp_no").toString());
  373. ps.setString(2, emp.get("emp_name").toString());
  374. ps.setString(3, emp.get("dept_name").toString());
  375. ps.setString(4, emp.get("designation").toString());
  376. ps.setString(5, emp.get("service_death").toString());
  377. ps.setString(6, emp.get("relationship_deceased").toString());
  378. ps.setString(7, emp.get("sanctioned_gis_amount").toString());
  379. ps.setString(8, emp.get("file_moved_date").toString());
  380. ps.setString(9, emp.get("remarks").toString());
  381. ps.setInt(10, Integer.parseInt(emp.get("file_category").toString()));
  382. ps.setInt(11, Integer.parseInt(emp.get("file_status").toString()));
  383. ps.setString(12, emp.get("file_entry_type").toString());
  384. ps.setString(13, filemovedby);
  385. ps.setInt(14, Integer.parseInt(emp.get("dept_id").toString()));
  386. ps.setString(15, emp.get("file_category_name").toString());
  387. ps.setString(16, emp.get("temp_id").toString());
  388. ps.setString(17, emp.get("pending_duration").toString());
  389. ps.setString(18, emp.get("reason_for_pending") != null ? emp.get("reason_for_pending").toString() : null);
  390. });
  391. System.out.println("rows inserted in pd history for family Pension");
  392. }
  393. if(file_Cat==3)
  394. {
  395. String empInsertQuery2 =
  396. "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation,type_of_retirement, " +
  397. "file_moved_date, remarks, file_category, file_status, " +
  398. "file_entry_type, file_moved_by, dept_id, file_category_name, temp_id,pending_duration,reason_for_pending) " +
  399. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  400. jdbcTemplate.batchUpdate(empInsertQuery2, emp_details, emp_details.size(), (ps, emp) -> {
  401. ps.setString(1, emp.get("emp_no").toString());
  402. ps.setString(2, emp.get("emp_name").toString());
  403. ps.setString(3, emp.get("dept_name").toString());
  404. ps.setString(4, emp.get("designation").toString());
  405. ps.setString(5, emp.get("type_of_retirement").toString());
  406. ps.setString(6, emp.get("file_moved_date").toString());
  407. ps.setString(7, emp.get("remarks").toString());
  408. ps.setInt(8, Integer.parseInt(emp.get("file_category").toString()));
  409. ps.setInt(9, Integer.parseInt(emp.get("file_status").toString()));
  410. ps.setString(10, emp.get("file_entry_type").toString());
  411. ps.setString(11, filemovedby);
  412. ps.setInt(12, Integer.parseInt(emp.get("dept_id").toString()));
  413. ps.setString(13, emp.get("file_category_name").toString());
  414. ps.setString(14, emp.get("temp_id").toString());
  415. ps.setString(15, emp.get("pending_duration").toString());
  416. ps.setString(16, emp.get("reason_for_pending") != null ? emp.get("reason_for_pending").toString() : null);
  417. });
  418. System.out.println("rows inserted in pd history for pending");
  419. }
  420. String pensionInsertQuery =
  421. "INSERT INTO pension_benefits_history (emp_no,temp_id,file_pending,file_moved_by) VALUES (?,?,?,?)";
  422. jdbcTemplate.batchUpdate(pensionInsertQuery, pension_details, pension_details.size(), (ps, pension) -> {
  423. ps.setString(1, pension.get("emp_no").toString());
  424. ps.setString(2, pension.get("temp_id").toString());
  425. ps.setString(3, pension.get("file_pending").toString());
  426. ps.setString(4, filemovedby);
  427. });
  428. System.out.println("rows inserted in pension history for family Pension");
  429. return true; // Return true if all insertions succeed
  430. } catch (Exception e) {
  431. e.printStackTrace();
  432. return false; // Return false in case of any exception
  433. }
  434. }
  435. @Transactional
  436. public boolean updateEntryReturnDetails(Map<String, Object> requestData) {
  437. // TODO Auto-generated method stub
  438. String empNo = (String) requestData.get("empNo");
  439. String tempId = (String) requestData.get("tempId");
  440. String dateToAudit = (String) requestData.get("dateToAudit");
  441. String filemovedby =(String)requestData.get("filemovedby");
  442. String remarks = (String) requestData.get("remarks");
  443. String dept_Id = (String) requestData.get("deptId");
  444. String file_entry_type="FILE_RETURNED";
  445. int deptId = Integer.parseInt(dept_Id);
  446. int filestatus = getFileStatus.getFileStatus6Id();
  447. if (filestatus == 0) {
  448. System.out.println("File status not found. Aborting insertion.");
  449. return false;
  450. }
  451. String updateQuery = "UPDATE pensioner_details SET file_status = ?,file_entry_type=?,file_moved_date=?,remarks=?,updated_date= CURRENT_TIMESTAMP WHERE temp_id = ? LIMIT 1";
  452. int rowsUpdated = jdbcTemplate.update(updateQuery,filestatus,file_entry_type,dateToAudit, remarks,tempId);
  453. System.out.println("Rows inserted in pd:"+rowsUpdated);
  454. if(rowsUpdated>0)
  455. {
  456. // Optional: Insert into file movement history for auditing
  457. String historyQuery = "INSERT INTO file_movement_history (emp_no, file_moved_date, file_status, file_moved_by, remarks,temp_id) VALUES (?,?, ?, ?, ?, ?)";
  458. int rowsUpdated1=jdbcTemplate.update(historyQuery, empNo, dateToAudit, filestatus, filemovedby, remarks,tempId);
  459. System.out.println("Rows inserted in fmh:"+rowsUpdated1);
  460. return true;
  461. }
  462. else {
  463. return false;
  464. }
  465. }
  466. @Transactional
  467. public boolean saveRetirementreturnhistory(List<Map<String, Object>> emp_details,String filemovedby) {
  468. try {
  469. int file_Cat=0;
  470. if (!emp_details.isEmpty()) {
  471. Map<String, Object> firstEmployeeDetails = emp_details.get(0);
  472. Object fileCatObj = firstEmployeeDetails.get("file_category");
  473. if (fileCatObj != null) {
  474. try {
  475. file_Cat = Integer.parseInt(fileCatObj.toString());
  476. System.out.println("Parsed file_category: " + file_Cat);
  477. } catch (NumberFormatException e) {
  478. System.err.println("Failed to parse file_category: " + fileCatObj);
  479. }
  480. } else {
  481. System.out.println("file_category is null in emp_details.");
  482. }
  483. } else {
  484. System.out.println("emp_details is empty.");
  485. }
  486. // Batch update for employee details
  487. if(file_Cat==1) {
  488. String empInsertQuery =
  489. "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, type_of_retirement, " +
  490. "retirement_date, retirement_class, file_moved_date, remarks, file_category, file_status, " +
  491. "file_entry_type, file_moved_by, dept_id, file_category_name, temp_id) " +
  492. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  493. jdbcTemplate.batchUpdate(empInsertQuery, emp_details, emp_details.size(), (ps, emp) -> {
  494. ps.setString(1, emp.get("emp_no").toString());
  495. ps.setString(2, emp.get("emp_name").toString());
  496. ps.setString(3, emp.get("dept_name").toString());
  497. ps.setString(4, emp.get("designation").toString());
  498. ps.setString(5, emp.get("type_of_retirement").toString());
  499. ps.setString(6, emp.get("retirement_date").toString());
  500. ps.setString(7, emp.get("retirement_class").toString());
  501. ps.setString(8, emp.get("file_moved_date").toString());
  502. ps.setString(9, emp.get("remarks").toString());
  503. ps.setInt(10, Integer.parseInt(emp.get("file_category").toString()));
  504. ps.setInt(11, Integer.parseInt(emp.get("file_status").toString()));
  505. ps.setString(12, emp.get("file_entry_type").toString());
  506. ps.setString(13, filemovedby);
  507. ps.setInt(14, Integer.parseInt(emp.get("dept_id").toString()));
  508. ps.setString(15, emp.get("file_category_name").toString());
  509. ps.setString(16, emp.get("temp_id").toString());
  510. });
  511. }
  512. if(file_Cat==2)
  513. {
  514. String empInsertQuery1 =
  515. "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, service_death, " +
  516. "relationship_deceased, sanctioned_gis_amount, file_moved_date, remarks, file_category, file_status, " +
  517. "file_entry_type, file_moved_by, dept_id, file_category_name, temp_id,pending_duration,reason_for_pending) " +
  518. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)";
  519. jdbcTemplate.batchUpdate(empInsertQuery1, emp_details, emp_details.size(), (ps, emp) -> {
  520. ps.setString(1, emp.get("emp_no").toString());
  521. ps.setString(2, emp.get("emp_name").toString());
  522. ps.setString(3, emp.get("dept_name").toString());
  523. ps.setString(4, emp.get("designation").toString());
  524. ps.setString(5, emp.get("service_death").toString());
  525. ps.setString(6, emp.get("relationship_deceased").toString());
  526. ps.setString(7, emp.get("sanctioned_gis_amount").toString());
  527. ps.setString(8, emp.get("file_moved_date").toString());
  528. ps.setString(9, emp.get("remarks").toString());
  529. ps.setInt(10, Integer.parseInt(emp.get("file_category").toString()));
  530. ps.setInt(11, Integer.parseInt(emp.get("file_status").toString()));
  531. ps.setString(12, emp.get("file_entry_type").toString());
  532. ps.setString(13, filemovedby);
  533. ps.setInt(14, Integer.parseInt(emp.get("dept_id").toString()));
  534. ps.setString(15, emp.get("file_category_name").toString());
  535. ps.setString(16, emp.get("temp_id").toString());
  536. ps.setString(17, emp.get("pending_duration").toString());
  537. ps.setString(18, emp.get("reason_for_pending") != null ? emp.get("reason_for_pending").toString() : null);
  538. });
  539. System.out.println("rows inserted in pd history for family Pension");
  540. }
  541. if(file_Cat==3)
  542. {
  543. String empInsertQuery2 =
  544. "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation,type_of_retirement, " +
  545. "file_moved_date, remarks, file_category, file_status, " +
  546. "file_entry_type, file_moved_by, dept_id, file_category_name, temp_id,pending_duration,reason_for_pending) " +
  547. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  548. jdbcTemplate.batchUpdate(empInsertQuery2, emp_details, emp_details.size(), (ps, emp) -> {
  549. ps.setString(1, emp.get("emp_no").toString());
  550. ps.setString(2, emp.get("emp_name").toString());
  551. ps.setString(3, emp.get("dept_name").toString());
  552. ps.setString(4, emp.get("designation").toString());
  553. ps.setString(5, emp.get("type_of_retirement").toString());
  554. ps.setString(6, emp.get("file_moved_date").toString());
  555. ps.setString(7, emp.get("remarks").toString());
  556. ps.setInt(8, Integer.parseInt(emp.get("file_category").toString()));
  557. ps.setInt(9, Integer.parseInt(emp.get("file_status").toString()));
  558. ps.setString(10, emp.get("file_entry_type").toString());
  559. ps.setString(11, filemovedby);
  560. ps.setInt(12, Integer.parseInt(emp.get("dept_id").toString()));
  561. ps.setString(13, emp.get("file_category_name").toString());
  562. ps.setString(14, emp.get("temp_id").toString());
  563. ps.setString(15, emp.get("pending_duration").toString());
  564. ps.setString(16, emp.get("reason_for_pending") != null ? emp.get("reason_for_pending").toString() : null);
  565. });
  566. System.out.println("rows inserted in pd history for pending");
  567. }
  568. return true; // Return true if all insertions succeed
  569. } catch (Exception e) {
  570. e.printStackTrace();
  571. return false; // Return false in case of any exception
  572. }
  573. }
  574. }