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.

948 lines
51 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
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
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.text.ParseException;
  3. import java.text.SimpleDateFormat;
  4. import java.time.LocalDate;
  5. import java.time.LocalDateTime;
  6. import java.time.format.DateTimeFormatter;
  7. import java.time.format.DateTimeParseException;
  8. import java.util.ArrayList;
  9. import java.util.Collections;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. import javax.sql.DataSource;
  14. import java.util.Comparator;
  15. import java.util.Date;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.beans.factory.annotation.Qualifier;
  18. import org.springframework.dao.EmptyResultDataAccessException;
  19. import org.springframework.jdbc.core.JdbcTemplate;
  20. import org.springframework.stereotype.Service;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import org.springframework.web.client.RestTemplate;
  23. import com.fasterxml.jackson.databind.JsonNode;
  24. import com.fasterxml.jackson.databind.ObjectMapper;
  25. import in.gov.chennaicorporation.gccoffice.configuration.AppConfig;
  26. @Service
  27. public class NewEntryService {
  28. @Autowired
  29. private JdbcTemplate jdbcTemplate;
  30. private RestTemplate restTemplate;
  31. private ObjectMapper objectMapper;
  32. @Autowired
  33. private AppConfig appconfig;
  34. public NewEntryService(RestTemplate restTemplate, ObjectMapper objectMapper) {
  35. this.restTemplate = restTemplate;
  36. this.objectMapper = objectMapper;
  37. }
  38. @Autowired
  39. public void setDataSource(@Qualifier("mysqlPensionerDataSource") DataSource dataSource) {
  40. this.jdbcTemplate = new JdbcTemplate(dataSource);
  41. }
  42. @Autowired
  43. public GetFileStatusService getFileStatus;
  44. // old retiment list getting method
  45. // public Map<String, Object> fetchEmplyeeDetails(String fromDate, String toDate, Integer deptId) {
  46. // Map<String, Object> response = new HashMap<>();
  47. //
  48. // String apiUrl = appconfig.qaqcurl + "serviceId=common_api"
  49. // + "&jsonResp=Yes"
  50. // + "&subService=getEmpPenDetDuration"
  51. // + "&fromDate=" + fromDate
  52. // + "&toDate=" + toDate
  53. // + "&deptId=" + deptId;
  54. //
  55. // System.out.println("url: " + apiUrl);
  56. // System.out.println("deptId:" + deptId);
  57. // try {
  58. // String rawResponse = restTemplate.getForObject(apiUrl, String.class);
  59. // System.out.println("Raw Response: " + rawResponse); // Debugging step
  60. //
  61. // if (isValidJson(rawResponse)) {
  62. // JsonNode jsonResponse = objectMapper.readTree(rawResponse);
  63. //
  64. // // Extract the "ListResult" array
  65. // JsonNode details = jsonResponse.path("ListResult");
  66. //
  67. // if (details.isArray() && details.size() > 0) {
  68. // List<Map<String, String>> list = new ArrayList<>();
  69. // for (JsonNode detail : details) {
  70. // Map<String, String> listResult = new HashMap<>();
  71. //
  72. // listResult.put("RETIREMENT_DATE", getNonNullValue(detail.path("RETIREMENT_DATE")));
  73. // listResult.put("DEATH_DATE", getNonNullValue(detail.path("DEATH_DATE")));
  74. // listResult.put("COMMUNITY_NAME", getNonNullValue(detail.path("COMMUNITY_NAME")));
  75. // listResult.put("GROUP_TYPE", getNonNullValue(detail.path("GROUP_TYPE")));
  76. // listResult.put("ID_DEPT", getNonNullValue(detail.path("ID_DEPT")));
  77. // listResult.put("EMPLOYEE_CODE", getNonNullValue(detail.path("EMPLOYEE_CODE")));
  78. // listResult.put("FUNCTIONARY", getNonNullValue(detail.path("FUNCTIONARY")));
  79. // listResult.put("IS_HANDICAPPED", getNonNullValue(detail.path("IS_HANDICAPPED")));
  80. // listResult.put("GENDER", getNonNullValue(detail.path("GENDER")));
  81. // listResult.put("DATE_OF_BIRTH", getNonNullValue(detail.path("DATE_OF_BIRTH")));
  82. // listResult.put("DATE_OF_APPOINTMENT", getNonNullValue(detail.path("DATE_OF_APPOINTMENT")));
  83. // listResult.put("DESIGNATION", getNonNullValue(detail.path("DESIGNATION")));
  84. // listResult.put("EMPLOYEE_NAME", getNonNullValue(detail.path("EMPLOYEE_NAME")));
  85. // listResult.put("DEPARTMENT", getNonNullValue(detail.path("DEPARTMENT")));
  86. // list.add(listResult);
  87. // }
  88. // // Sort the list by RETIREMENT_DATE in ascending order
  89. // list.sort(Comparator.comparing(map -> parseDate(((Map<String, String>) map).get("RETIREMENT_DATE"))));
  90. //
  91. // response.put("list", list);
  92. //
  93. // } else {
  94. // response.put("list", Collections.emptyList());
  95. // }
  96. // } else {
  97. // System.err.println("Invalid JSON Response: " + rawResponse);
  98. // response.put("list", Collections.emptyList());
  99. // }
  100. //
  101. // } catch (Exception e) {
  102. // e.printStackTrace();
  103. // response.put("list", Collections.emptyList());
  104. // }
  105. // return response;
  106. // }
  107. // new retirement list getting method with condition
  108. public Map<String, Object> fetchEmplyeeDetails(String fromDate, String toDate, Integer deptId) {
  109. Map<String, Object> response = new HashMap<>();
  110. String apiUrl = appconfig.qaqcurl + "serviceId=common_api"
  111. + "&jsonResp=Yes"
  112. + "&subService=getEmpPenDetDuration"
  113. + "&fromDate=" + fromDate
  114. + "&toDate=" + toDate
  115. + "&deptId=" + deptId;
  116. System.out.println("url: " + apiUrl);
  117. System.out.println("deptId:" + deptId);
  118. try {
  119. String rawResponse = restTemplate.getForObject(apiUrl, String.class);
  120. System.out.println("Raw Response: " + rawResponse); // Debugging step
  121. if (isValidJson(rawResponse)) {
  122. JsonNode jsonResponse = objectMapper.readTree(rawResponse);
  123. JsonNode details = jsonResponse.path("ListResult");
  124. if (details.isArray() && details.size() > 0) {
  125. List<Map<String, String>> list = new ArrayList<>();
  126. LocalDate currentDate = LocalDate.now(); // Get today's date
  127. for (JsonNode detail : details) {
  128. String retirementDateStr = getNonNullValue(detail.path("RETIREMENT_DATE"));
  129. LocalDate retirementDate = parseDate(retirementDateStr);
  130. // Only add to the list if RETIREMENT_DATE is today or in the future
  131. if (retirementDate != null && !retirementDate.isBefore(currentDate)) {
  132. Map<String, String> listResult = new HashMap<>();
  133. listResult.put("RETIREMENT_DATE", retirementDateStr);
  134. listResult.put("DEATH_DATE", getNonNullValue(detail.path("DEATH_DATE")));
  135. listResult.put("COMMUNITY_NAME", getNonNullValue(detail.path("COMMUNITY_NAME")));
  136. listResult.put("GROUP_TYPE", getNonNullValue(detail.path("GROUP_TYPE")));
  137. listResult.put("ID_DEPT", getNonNullValue(detail.path("ID_DEPT")));
  138. listResult.put("EMPLOYEE_CODE", getNonNullValue(detail.path("EMPLOYEE_CODE")));
  139. listResult.put("FUNCTIONARY", getNonNullValue(detail.path("FUNCTIONARY")));
  140. listResult.put("IS_HANDICAPPED", getNonNullValue(detail.path("IS_HANDICAPPED")));
  141. listResult.put("GENDER", getNonNullValue(detail.path("GENDER")));
  142. listResult.put("DATE_OF_BIRTH", getNonNullValue(detail.path("DATE_OF_BIRTH")));
  143. listResult.put("DATE_OF_APPOINTMENT", getNonNullValue(detail.path("DATE_OF_APPOINTMENT")));
  144. listResult.put("DESIGNATION", getNonNullValue(detail.path("DESIGNATION")));
  145. listResult.put("EMPLOYEE_NAME", getNonNullValue(detail.path("EMPLOYEE_NAME")));
  146. listResult.put("DEPARTMENT", getNonNullValue(detail.path("DEPARTMENT")));
  147. list.add(listResult);
  148. }
  149. }
  150. // Sort the list by RETIREMENT_DATE in ascending order
  151. list.sort(Comparator.comparing(map -> parseDate(map.get("RETIREMENT_DATE"))));
  152. response.put("list", list);
  153. } else {
  154. response.put("list", Collections.emptyList());
  155. }
  156. } else {
  157. System.err.println("Invalid JSON Response: " + rawResponse);
  158. response.put("list", Collections.emptyList());
  159. }
  160. } catch (Exception e) {
  161. e.printStackTrace();
  162. response.put("list", Collections.emptyList());
  163. }
  164. return response;
  165. }
  166. public Map<String, Object> fetchEmplyeeDetailsbyCode(String empCode) {
  167. Map<String, Object> response = new HashMap<>();
  168. String apiUrl = appconfig.qaqcurl + "serviceId=common_api"
  169. + "&jsonResp=Yes"
  170. + "&subService=getEmpWorkDet"
  171. + "&empCode=" + empCode;
  172. System.out.println("url: " + apiUrl);
  173. System.out.println("empCode:" + empCode);
  174. try {
  175. String rawResponse = restTemplate.getForObject(apiUrl, String.class);
  176. System.out.println("Raw Response: " + rawResponse); // Debugging step
  177. if (isValidJson(rawResponse)) {
  178. JsonNode jsonResponse = objectMapper.readTree(rawResponse);
  179. // Extract the "ListResult" array
  180. JsonNode details = jsonResponse.path("ListResult");
  181. if (details.isArray() && details.size() > 0) {
  182. List<Map<String, String>> list = new ArrayList<>();
  183. for (JsonNode detail : details) {
  184. Map<String, String> listResult = new HashMap<>();
  185. listResult.put("RETIREMENT_DATE", formatToISODate(getNonNullValue(detail.path("RETIREMENT_DATE"))));
  186. listResult.put("TO_DATE", parseDate(getNonNullValue(detail.path("TO_DATE"))).toString());
  187. listResult.put("DEATH_DATE", getNonNullValue(detail.path("DEATH_DATE")));
  188. listResult.put("COMMUNITY_NAME", getNonNullValue(detail.path("COMMUNITY_NAME")));
  189. listResult.put("GROUP_TYPE", getNonNullValue(detail.path("GROUP_TYPE")));
  190. listResult.put("ID_DEPT", getNonNullValue(detail.path("ID_DEPT")));
  191. listResult.put("EMPLOYEE_CODE", getNonNullValue(detail.path("EMPLOYEE_CODE")));
  192. listResult.put("FUNCTIONARY", getNonNullValue(detail.path("FUNCTIONARY")));
  193. listResult.put("IS_HANDICAPPED", getNonNullValue(detail.path("IS_HANDICAPPED")));
  194. listResult.put("GENDER", getNonNullValue(detail.path("GENDER")));
  195. listResult.put("DATE_OF_BIRTH", getNonNullValue(detail.path("DATE_OF_BIRTH")));
  196. listResult.put("DATE_OF_APPOINTMENT", getNonNullValue(detail.path("DATE_OF_APPOINTMENT")));
  197. listResult.put("DESIGNATION", getNonNullValue(detail.path("DESIGNATION")));
  198. listResult.put("EMPLOYEE_NAME", getNonNullValue(detail.path("EMPLOYEE_NAME")));
  199. listResult.put("DEPARTMENT", getNonNullValue(detail.path("DEPARTMENT")));
  200. list.add(listResult);
  201. }
  202. // Sort the list by RETIREMENT_DATE in ascending order
  203. list.sort(Comparator.comparing(map -> parseDate(((Map<String, String>) map).get("RETIREMENT_DATE"))));
  204. response.put("list", list);
  205. System.out.println("listresult: "+list);
  206. } else {
  207. response.put("list", Collections.emptyList());
  208. }
  209. } else {
  210. System.err.println("Invalid JSON Response: " + rawResponse);
  211. response.put("list", Collections.emptyList());
  212. }
  213. } catch (Exception e) {
  214. e.printStackTrace();
  215. response.put("list", Collections.emptyList());
  216. }
  217. return response;
  218. }
  219. // Utility method to convert DD-MM-YYYY to YYYY-MM-DD
  220. private String formatToISODate(String date) {
  221. if (date == null || date.isEmpty()) {
  222. return "";
  223. }
  224. try {
  225. SimpleDateFormat inputFormat = new SimpleDateFormat("dd-MM-yyyy");
  226. SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
  227. Date parsedDate = inputFormat.parse(date);
  228. return outputFormat.format(parsedDate);
  229. } catch (ParseException e) {
  230. System.err.println("Date parsing error: " + e.getMessage());
  231. return date; // Return original date if parsing fails
  232. }
  233. }
  234. //getting deptId from login
  235. public Integer getloginuserDeptId(int userId) {
  236. String query = "select emp_dept_id from login_details where gcc_login_id = ?";
  237. try {
  238. // Use queryForObject to return a single value
  239. return jdbcTemplate.queryForObject(query, Integer.class, userId);
  240. } catch (EmptyResultDataAccessException e) {
  241. // Log the issue and handle the case when no result is found
  242. System.out.println("No department found for user ID: " + userId);
  243. return null; // Or return a default value if required
  244. }
  245. }
  246. private LocalDate parseDate(String date) {
  247. if (date == null || date.isEmpty()) {
  248. return LocalDate.MIN; // Use a minimum value for invalid or empty dates
  249. }
  250. try {
  251. // Remove time part if present
  252. if (date.contains(" ")) {
  253. date = date.split(" ")[0]; // Extract only the date part before space
  254. }
  255. DateTimeFormatter formatter;
  256. if (date.matches("\\d{4}-\\d{2}-\\d{2}")) { // yyyy-MM-dd
  257. formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  258. } else if (date.matches("\\d{2}-\\d{2}-\\d{4}")) { // dd-MM-yyyy
  259. formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
  260. } else {
  261. System.err.println("Unknown date format: " + date);
  262. return LocalDate.MIN;
  263. }
  264. return LocalDate.parse(date, formatter);
  265. } catch (DateTimeParseException e) {
  266. e.printStackTrace();
  267. return LocalDate.MIN; // Fallback for invalid dates
  268. }
  269. }
  270. // private LocalDate parseDate(String date) {
  271. // if (date == null || date.isEmpty()) {
  272. // return LocalDate.MIN; // Use a minimum value for invalid or empty dates
  273. // }
  274. // try {
  275. // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); // Adjust format as needed
  276. // return LocalDate.parse(date, formatter);
  277. // } catch (DateTimeParseException e) {
  278. // e.printStackTrace();
  279. // return LocalDate.MIN; // Fallback for invalid dates
  280. // }
  281. // }
  282. private boolean isValidJson(String json) {
  283. try {
  284. objectMapper.readTree(json);
  285. return true;
  286. } catch (Exception e) {
  287. return false;
  288. }
  289. }
  290. private String getNonNullValue(JsonNode node) {
  291. //String value = node.isMissingNode() || node.isNull() || node.asText().isEmpty() ? "N/A" : node.asText();
  292. String value = node.isMissingNode() || node.isNull() || node.asText().isEmpty() || node.asText().isBlank() ? "N/A" : node.asText();
  293. //2024-565EAT
  294. return "null".equals(value) ? "N/A" : value; // Check for string "null"
  295. }
  296. public String getDeptNameById(Integer deptId) {
  297. String query = "SELECT dept_name FROM department_master WHERE dept_id=? AND isactive=1 AND isdelete=0";
  298. try {
  299. // Query execution and returning the department name
  300. //return jdbcTemplate.queryForObject(query, new Object[]{deptId}, String.class);
  301. return jdbcTemplate.queryForObject(query, String.class,deptId);
  302. } catch (Exception e) {
  303. // Handle exception if deptId is not found or query fails
  304. e.printStackTrace();
  305. return null;
  306. }
  307. }
  308. @Transactional
  309. public boolean saveRetirementEmployeeDetails(Map<String, Object> requestData) {
  310. try {
  311. String empNo = (String) requestData.get("empNo");
  312. String empName = (String) requestData.get("empName");
  313. String deptName = (String) requestData.get("deptName");
  314. String designation = (String) requestData.get("designation");
  315. String typeOfRetirement = (String) requestData.get("typeOfRetirement");
  316. String retirementdate = (String) requestData.get("retirementdate");
  317. String retirementclass = (String) requestData.get("retirementclass");
  318. String dateToAudit = (String) requestData.get("dateToAudit");
  319. String filemovedby =(String)requestData.get("filemovedby");
  320. String remarks = (String) requestData.get("remarks");
  321. String dept_Id = (String) requestData.get("deptId");
  322. String file_category = (String) requestData.get("filecategory");
  323. // Safely parse integer values
  324. int deptId;
  325. int filecategory;
  326. try {
  327. deptId = Integer.parseInt(dept_Id);
  328. filecategory = Integer.parseInt(file_category);
  329. } catch (NumberFormatException e) {
  330. System.out.println("Invalid number format for deptId or filecategory.");
  331. return false;
  332. }
  333. int filestatus = getFileStatus.getFileStatus1Id();
  334. if (filestatus == 0) {
  335. System.out.println("File status not found. Aborting insertion.");
  336. return false;
  337. }
  338. // Execute a query to fetch the required String based on filecategory
  339. String additionalDataQuery = "SELECT file_name FROM file_category_master WHERE id = ?";
  340. String fc_name = jdbcTemplate.queryForObject(additionalDataQuery,String.class,filecategory);
  341. System.out.println("fc_name==="+fc_name);
  342. String fileentrytype ="NEW";
  343. System.out.println("filemovedby====="+filemovedby);
  344. // Generate the variable (PR + current date + current time)
  345. String currentTimestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("ddMMyyHHmmss"));
  346. String temp_id = "PR" + currentTimestamp;
  347. String query = "INSERT INTO pensioner_details (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,dept_id,file_category_name,temp_id) VALUES (?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?)";
  348. int rowsInserted = jdbcTemplate.update(query, empNo, empName, deptName, designation, typeOfRetirement,retirementdate ,retirementclass,dateToAudit, remarks,filecategory,filestatus,fileentrytype,deptId,fc_name,temp_id);
  349. String query1 = "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 (?,?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?)";
  350. int rowsInsertedHistory = jdbcTemplate.update(query1, empNo, empName, deptName, designation, typeOfRetirement,retirementdate ,retirementclass,dateToAudit, remarks,filecategory,filestatus,fileentrytype,filemovedby,deptId,fc_name,temp_id);
  351. String query2 = "INSERT INTO file_movement_history (emp_no,file_moved_date,file_status,file_moved_by,remarks,temp_id) VALUES (?, ?, ?, ?, ?,?)";
  352. int rowsInsertedFileMovement = jdbcTemplate.update(query2, empNo,dateToAudit,filestatus,filemovedby,remarks,temp_id);
  353. return rowsInserted > 0 && rowsInsertedHistory > 0 && rowsInsertedFileMovement > 0;
  354. } catch (Exception e) {
  355. e.printStackTrace();
  356. return false; // Return false if an exception occurs
  357. }
  358. }
  359. // public List<String> getRegisteredEmps(Integer deptId) {
  360. // String query = "SELECT DISTINCT emp_no FROM pensioner_details WHERE dept_id=? AND file_category <> 5 " +
  361. // "UNION ALL " +
  362. // "SELECT DISTINCT emp_no FROM cps_pensioner_details WHERE dept_id=?";
  363. //
  364. // List<String> emps = jdbcTemplate.queryForList(query, String.class, deptId, deptId);
  365. // System.out.println("emps====" + emps);
  366. //
  367. // return emps;
  368. // }
  369. public List<String> getRegisteredEmps(Integer deptId) {
  370. String query = "SELECT DISTINCT emp_no FROM pensioner_details " +
  371. "WHERE dept_id=? AND (file_category <> 5 OR (file_category = 5 AND file_status != 11)) " +
  372. "UNION ALL " +
  373. "SELECT DISTINCT emp_no FROM cps_pensioner_details WHERE dept_id=?";
  374. List<String> emps = jdbcTemplate.queryForList(query, String.class, deptId, deptId);
  375. System.out.println("emps====" + emps);
  376. return emps;
  377. }
  378. public Integer getRetirementFileCategoryId() {
  379. String query = "SELECT id FROM file_category_master WHERE file_name = 'Retirement'";
  380. try {
  381. return jdbcTemplate.queryForObject(query, Integer.class);
  382. } catch (EmptyResultDataAccessException e) {
  383. return null; // or handle as needed
  384. }
  385. }
  386. public Integer getFamilyPensionFileCategoryId() {
  387. String query = "SELECT id FROM file_category_master WHERE file_name = 'Family Pension'";
  388. try {
  389. return jdbcTemplate.queryForObject(query, Integer.class);
  390. } catch (EmptyResultDataAccessException e) {
  391. return null; // or handle as needed
  392. }
  393. }
  394. public Integer getPendencyFileCategoryId() {
  395. String query = "SELECT id FROM file_category_master WHERE file_name = 'Pendency'";
  396. try {
  397. return jdbcTemplate.queryForObject(query, Integer.class);
  398. } catch (EmptyResultDataAccessException e) {
  399. return null; // or handle as needed
  400. }
  401. }
  402. public Integer getGISFileCategoryId() {
  403. String query = "SELECT id FROM file_category_master WHERE file_name = 'GIS'";
  404. try {
  405. return jdbcTemplate.queryForObject(query, Integer.class);
  406. } catch (EmptyResultDataAccessException e) {
  407. return null; // or handle as needed
  408. }
  409. }
  410. public Integer getPRFileCategoryId() {
  411. String query = "SELECT id FROM file_category_master WHERE file_name = 'Provisional Pension'";
  412. try {
  413. return jdbcTemplate.queryForObject(query, Integer.class);
  414. } catch (EmptyResultDataAccessException e) {
  415. return null; // or handle as needed
  416. }
  417. }
  418. public Integer getCPSFileCategoryId() {
  419. String query = "SELECT id FROM file_category_master WHERE file_name = 'Contributory Pension Scheme'";
  420. try {
  421. return jdbcTemplate.queryForObject(query, Integer.class);
  422. } catch (EmptyResultDataAccessException e) {
  423. return null; // or handle as needed
  424. }
  425. }
  426. @Transactional
  427. public boolean saveFamilyPensionDetails(Map<String, Object> requestData) {
  428. try {
  429. // Extract data from the request body
  430. String empNo = (String) requestData.get("empNo");
  431. String empName = (String) requestData.get("empName");
  432. String deptName = (String) requestData.get("deptName");
  433. String designation = (String) requestData.get("designation");
  434. String sanctionedgis = (String) requestData.get("sanctionedgis");
  435. String serviceDeath =(String) requestData.get("serviceDeath");
  436. String deceased =(String) requestData.get("deceased");
  437. String dateToAudit = (String) requestData.get("dateToAudit");
  438. String remarks = (String) requestData.get("remarks");
  439. String filemovedby =(String)requestData.get("filemovedby");
  440. String pendingDuration = (String) requestData.get("pendingDuration");
  441. String reasonPending = (("yes".equals(pendingDuration) || "no".equals(pendingDuration))
  442. && requestData.get("reasonPending") != null) ? requestData.get("reasonPending").toString() : null;
  443. String dept_Id = (String) requestData.get("deptId");
  444. int deptId = Integer.parseInt(dept_Id);
  445. String file_category = (String) requestData.get("filecategory");
  446. int filecategory = Integer.parseInt(file_category);
  447. // Execute a query to fetch the required String based on filecategory
  448. String additionalDataQuery = "SELECT file_name FROM file_category_master WHERE id = ?";
  449. String fc_name = jdbcTemplate.queryForObject(additionalDataQuery, String.class,filecategory);
  450. System.out.println("fc_name==="+fc_name);
  451. int filestatus = getFileStatus.getFileStatus1Id();
  452. if (filestatus == 0) {
  453. System.out.println("File status not found. Aborting insertion.");
  454. return false;
  455. }
  456. String fileentrytype ="NEW";
  457. int rowsInserted=0;
  458. // Generate the variable (PR + current date + current time)
  459. String currentTimestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("ddMMyyHHmmss"));
  460. String temp_id = "PF" + currentTimestamp;
  461. String query = "INSERT INTO pensioner_details (emp_no, emp_name, dept_name, designation, sanctioned_gis_amount,service_death,relationship_deceased,file_moved_date, remarks,dept_id,file_category,file_status,file_entry_type,file_category_name,temp_id,pending_duration,reason_for_pending) VALUES (?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?)";
  462. rowsInserted = jdbcTemplate.update(query, empNo, empName, deptName, designation, sanctionedgis,serviceDeath ,deceased,dateToAudit, remarks,deptId,filecategory,filestatus,fileentrytype,fc_name,temp_id, pendingDuration,reasonPending);
  463. String query1 = "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, sanctioned_gis_amount,service_death,relationship_deceased,file_moved_date, remarks,dept_id,file_category,file_status,file_entry_type,file_moved_by,file_category_name,temp_id,pending_duration,reason_for_pending) VALUES (?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?,?)";
  464. rowsInserted = jdbcTemplate.update(query1, empNo, empName, deptName, designation, sanctionedgis,serviceDeath ,deceased,dateToAudit, remarks,deptId,filecategory,filestatus,fileentrytype,filemovedby,fc_name,temp_id, pendingDuration,reasonPending);
  465. String query2 = "INSERT INTO file_movement_history (emp_no,file_moved_date,file_status,file_moved_by,remarks,temp_id) VALUES (?, ?, ?, ?, ?,?)";
  466. rowsInserted = jdbcTemplate.update(query2, empNo,dateToAudit,filestatus,filemovedby,remarks,temp_id);
  467. return rowsInserted > 0;
  468. } catch (Exception e) {
  469. e.printStackTrace();
  470. return false; // Return false if an exception occurs
  471. }
  472. }
  473. ///gis saving method service
  474. @Transactional
  475. public boolean savenewEntryDetailsGis(Map<String, Object> requestData) {
  476. try {
  477. String empNo = (String) requestData.get("empNo");
  478. String empName = (String) requestData.get("empName");
  479. String deptName = (String) requestData.get("deptName");
  480. String designation = (String) requestData.get("designation");
  481. String dateToPension = (String) requestData.get("dateToPension");
  482. String filemovedby =(String)requestData.get("filemovedby");
  483. String remarks = (String) requestData.get("remarks");
  484. String serviceDeath =(String) requestData.get("serviceDeath");
  485. String deceased =(String) requestData.get("deceased");
  486. String gisentry = requestData.get("gisentry") != null ?(String) requestData.get("gisentry") : null;
  487. String gisAdvanceamount =requestData.get("gisAdvanceamount") != null ?(String) requestData.get("gisAdvanceamount") : null;
  488. String gisAdvance = requestData.get("gisAdvance") != null ? (String) requestData.get("gisAdvance") : null;
  489. String dept_Id = (String) requestData.get("deptId");
  490. int deptId = Integer.parseInt(dept_Id);
  491. String file_category = (String) requestData.get("filecategory");
  492. int filecategory = Integer.parseInt(file_category);
  493. // Execute a query to fetch the required String based on filecategory
  494. String additionalDataQuery = "SELECT file_name FROM file_category_master WHERE id = ?";
  495. String fc_name = jdbcTemplate.queryForObject(additionalDataQuery, String.class,filecategory);
  496. System.out.println("fc_name==="+fc_name);
  497. int filestatus = getFileStatus.getFileStatus7Id();
  498. if (filestatus == 0) {
  499. System.out.println("File status not found. Aborting insertion.");
  500. return false;
  501. }
  502. String fileentrytype ="NEW";
  503. System.out.println("filemovedby====="+filemovedby);
  504. // Generate the variable (PR + current date + current time)
  505. String currentTimestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("ddMMyyHHmmss"));
  506. String temp_id = "PG" + currentTimestamp;
  507. String query = "INSERT INTO pensioner_details (emp_no, emp_name, dept_name, designation,file_moved_date, remarks,service_death,relationship_deceased,gis_entry,gis_advance_amount,gis_advance ,file_category,file_status,file_entry_type,dept_id,file_category_name,temp_id) VALUES (?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?)";
  508. int rowsInserted = jdbcTemplate.update(query, empNo, empName, deptName, designation, dateToPension, remarks,serviceDeath,deceased,gisentry,gisAdvanceamount,gisAdvance,filecategory,filestatus,fileentrytype,deptId,fc_name,temp_id);
  509. String query1 = "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation,file_moved_date, remarks,service_death,relationship_deceased,gis_entry,gis_advance_amount,gis_advance ,file_category,file_status,file_entry_type,file_moved_by,dept_id,file_category_name,temp_id) VALUES (?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?,?)";
  510. int rowsInsertedHistory = jdbcTemplate.update(query1, empNo, empName, deptName, designation,dateToPension, remarks,serviceDeath,deceased,gisentry,gisAdvanceamount,gisAdvance,filecategory,filestatus,fileentrytype,filemovedby,deptId,fc_name,temp_id);
  511. String query2 = "INSERT INTO file_movement_history (emp_no,file_moved_date,file_status,file_moved_by,remarks,temp_id) VALUES (?, ?, ?, ?, ?,?)";
  512. int rowsInsertedFileMovement = jdbcTemplate.update(query2, empNo,dateToPension,filestatus,filemovedby,remarks,temp_id);
  513. //
  514. return rowsInserted > 0 && rowsInsertedHistory > 0 && rowsInsertedFileMovement > 0;
  515. } catch (Exception e) {
  516. e.printStackTrace();
  517. return false; // Return false if an exception occurs
  518. }
  519. }
  520. //provisional retirement method service
  521. @Transactional
  522. public boolean savenewEntryDetailsProvisionalretirement(Map<String, Object> requestData) {
  523. try {
  524. String empNo = (String) requestData.get("empNo");
  525. String empName = (String) requestData.get("empName");
  526. String deptName = (String) requestData.get("deptName");
  527. String designation = (String) requestData.get("designation");
  528. String typeOfRetirement = (String) requestData.get("typeOfRetirement");
  529. String ReasonofPension = (String) requestData.get("ReasonofPension");
  530. String retirementClass = (String) requestData.get("retirementClass");
  531. String retirementDate = (String) requestData.get("retirementDate");
  532. String pendingDuration = (String) requestData.get("pendingDuration");
  533. String reasonofPending = (String) requestData.get("reasonofPending");
  534. String dp = (String) requestData.get("dp");
  535. String otherReason = (String) requestData.get("otherReason");
  536. String dateToAudit = (String) requestData.get("dateToAudit");
  537. String filemovedby =(String)requestData.get("filemovedby");
  538. String remarks = (String) requestData.get("remarks");
  539. String dept_Id = (String) requestData.get("deptId");
  540. int deptId = Integer.parseInt(dept_Id);
  541. String file_category = (String) requestData.get("filecategory");
  542. int filecategory = Integer.parseInt(file_category);
  543. // Execute a query to fetch the required String based on filecategory
  544. String additionalDataQuery = "SELECT file_name FROM file_category_master WHERE id = ?";
  545. String fc_name = jdbcTemplate.queryForObject(additionalDataQuery, String.class,filecategory);
  546. System.out.println("fc_name==="+fc_name);
  547. int filestatus = getFileStatus.getFileStatus7Id();
  548. if (filestatus == 0) {
  549. System.out.println("File status not found. Aborting insertion.");
  550. return false;
  551. }
  552. String fileentrytype ="NEW";
  553. System.out.println("filemovedby====="+filemovedby);
  554. // Generate the variable (PR + current date + current time)
  555. String currentTimestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("ddMMyyHHmmss"));
  556. String temp_id = "PPR" + currentTimestamp;
  557. String query = "INSERT INTO pensioner_details (emp_no, emp_name, dept_name, designation,type_of_retirement,retirement_class,retirement_date , reason_for_provisional_pension,file_moved_date, pending_duration,reason_for_pending,dp,remarks,file_category,file_status,file_entry_type,dept_id,file_category_name,others_provisional_pension,temp_id) VALUES (?,?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?,?,?)";
  558. int rowsInserted = jdbcTemplate.update(query, empNo, empName, deptName, designation, typeOfRetirement,retirementClass ,retirementDate , ReasonofPension,dateToAudit,pendingDuration,reasonofPending,dp,remarks,filecategory,filestatus,fileentrytype,deptId,fc_name,otherReason,temp_id);
  559. String query1 = "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation,type_of_retirement,retirement_class, retirement_date,reason_for_provisional_pension ,file_moved_date, remarks,pending_duration,reason_for_pending,dp ,file_category,file_status,file_entry_type,file_moved_by,dept_id,file_category_name,others_provisional_pension,temp_id) VALUES (?,?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?,?,?,?)";
  560. int rowsInsertedHistory = jdbcTemplate.update(query1, empNo, empName, deptName, designation,typeOfRetirement,retirementClass,retirementDate ,ReasonofPension,dateToAudit,remarks,pendingDuration,reasonofPending,dp,filecategory,filestatus,fileentrytype,filemovedby,deptId,fc_name,otherReason,temp_id);
  561. String query2 = "INSERT INTO file_movement_history (emp_no,file_moved_date,file_status,file_moved_by,remarks,temp_id) VALUES (?, ?, ?, ?, ?,?)";
  562. int rowsInsertedFileMovement = jdbcTemplate.update(query2, empNo,dateToAudit,filestatus,filemovedby,remarks,temp_id);
  563. //
  564. return rowsInserted > 0 && rowsInsertedHistory > 0 && rowsInsertedFileMovement > 0;
  565. } catch (Exception e) {
  566. e.printStackTrace();
  567. return false; // Return false if an exception occurs
  568. }
  569. }
  570. //cps saving method:
  571. @Transactional
  572. public boolean savenewEntryDetailspensionscheme(Map<String, Object> requestData) {
  573. try {
  574. // Safely extract input values from requestData
  575. String empNo = requestData.get("empNo") != null ? requestData.get("empNo").toString() : null;
  576. String empName = requestData.get("empName") != null ? requestData.get("empName").toString() : null;
  577. String deptName = requestData.get("deptName") != null ? requestData.get("deptName").toString() : null;
  578. String designation = requestData.get("designation") != null ? requestData.get("designation").toString() : null;
  579. String classes = requestData.get("classes") != null ? requestData.get("classes").toString() : null;
  580. String fileMovedBy = requestData.get("fileMovedBy") != null ? requestData.get("fileMovedBy").toString() : null;
  581. String remarks = requestData.get("remarks") != null ? requestData.get("remarks").toString() : null;
  582. String retirementType = requestData.get("retirementType") != null ? requestData.get("retirementType").toString() : null;
  583. String retirementdate = requestData.get("retirementdate") !=null ? requestData.get("retirementdate").toString() : null;
  584. String uac = (String) requestData.get("uac");
  585. String uacDate = "yes".equals(uac) && requestData.get("uacDate") != null ? requestData.get("uacDate").toString() : null;
  586. String pendingDuration = (String) requestData.get("pendingDuration");
  587. String reasonPending = "Yes".equals(pendingDuration) && requestData.get("reasonPending") != null ? requestData.get("reasonPending").toString() : null;
  588. String cps =(String) requestData.get("cps");
  589. String cpsAmount = "yes".equals(cps) && requestData.get("cpsAmount") != null ? requestData.get("cpsAmount").toString() : null;
  590. String elOrLpa = (String)requestData.get("elOrLpa");
  591. String elOrLpaAmount = "yes".equals(elOrLpa) && requestData.get("elOrLpaAmount") != null ? requestData.get("elOrLpaAmount").toString() : null;
  592. String spfgs = (String) requestData.get("spfgs");
  593. String spfgsAmount = "yes".equals(spfgs) && requestData.get("spfgsAmount") != null ? requestData.get("spfgsAmount").toString() : null;
  594. int deptId = requestData.get("deptId") != null ? Integer.parseInt(requestData.get("deptId").toString()) : 0;
  595. // Default static values
  596. String file_category = (String) requestData.get("filecategory");
  597. int filecategory = Integer.parseInt(file_category);
  598. int fileStatus = getFileStatus.getFileStatus11Id();
  599. if (fileStatus == 0) {
  600. System.out.println("File status not found. Aborting insertion.");
  601. return false;
  602. }
  603. String fileEntryType = "FILE_COMPLETED";
  604. // Fetch file_category_name dynamically
  605. String fileCategoryQuery = "SELECT file_name FROM file_category_master WHERE id = ?";
  606. String fileCategoryName = jdbcTemplate.queryForObject(fileCategoryQuery, String.class,filecategory);
  607. // Generate the variable (PR + current date + current time)
  608. String currentTimestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("ddMMyyHHmmss"));
  609. String temp_id = "PC" + currentTimestamp;
  610. // Insert into cps_pensioner_details
  611. String queryDetails = "INSERT INTO cps_pensioner_details " +
  612. "(emp_no, emp_name, dept_name, designation, file_category, retirement_class, retirement_date,type_of_retirement, uac, uac_date, " +
  613. "pending_duration,reason_for_pending ,cps, cps_amount, el_or_lpa, el_or_lpa_amount, spfgs, spfgs_amount, remarks, " +
  614. "file_status, file_entry_type, dept_id, file_category_name,temp_id) " +
  615. "VALUES (?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)";
  616. int rowsInsertedDetails = jdbcTemplate.update(queryDetails,
  617. empNo, empName, deptName, designation, filecategory, classes, retirementdate,retirementType, uac, uacDate,
  618. pendingDuration,reasonPending ,cps, cpsAmount, elOrLpa, elOrLpaAmount, spfgs, spfgsAmount, remarks,
  619. fileStatus, fileEntryType, deptId, fileCategoryName,temp_id);
  620. // Insert into cps_pensioner_details_history
  621. String queryHistory = "INSERT INTO cps_pensioner_details_history " +
  622. "(emp_no, emp_name, dept_name, designation, file_category, retirement_class, retirement_date,type_of_retirement, uac, uac_date, " +
  623. "pending_duration,reason_for_pending ,cps, cps_amount, el_or_lpa, el_or_lpa_amount, spfgs, spfgs_amount, remarks, " +
  624. "file_status, file_entry_type, file_moved_by, dept_id, file_category_name,temp_id) " +
  625. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?)";
  626. int rowsInsertedHistory = jdbcTemplate.update(queryHistory,
  627. empNo, empName, deptName, designation, filecategory, classes, retirementdate,retirementType, uac, uacDate,
  628. pendingDuration, reasonPending,cps, cpsAmount, elOrLpa, elOrLpaAmount, spfgs, spfgsAmount, remarks,
  629. fileStatus, fileEntryType, fileMovedBy, deptId, fileCategoryName,temp_id);
  630. // Current date and time
  631. LocalDateTime fileMovedDate = LocalDateTime.now();
  632. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  633. String formattedFileMovedDate = fileMovedDate.format(formatter);
  634. // Insert into file_movement_history
  635. String queryFileMovement = "INSERT INTO file_movement_history (emp_no, file_status,file_moved_date, file_moved_by, remarks,temp_id) " +
  636. "VALUES (?, ?, ?, ?, ?,?)";
  637. int rowsInsertedFileMovement = jdbcTemplate.update(queryFileMovement, empNo, fileStatus, formattedFileMovedDate, fileMovedBy, remarks,temp_id);
  638. // Return true if all inserts were successful
  639. return rowsInsertedDetails > 0 && rowsInsertedHistory > 0 && rowsInsertedFileMovement > 0;
  640. } catch (Exception e) {
  641. e.printStackTrace();
  642. return false; // Return false if an exception occurs
  643. }
  644. }
  645. //pendency saving method
  646. @Transactional
  647. public boolean savePendencyDetails(Map<String, Object> requestData) {
  648. try {
  649. String empNo = (String) requestData.get("empNo");
  650. String empName = (String) requestData.get("empName");
  651. String deptName = (String) requestData.get("deptName");
  652. String designation = (String) requestData.get("designation");
  653. String retirementclass = (String) requestData.get("retirementclass");
  654. String typeOfRetirement = (String) requestData.get("typeOfRetirement");
  655. String retirementDate = (String) requestData.get("retirementDate");
  656. //String pendencyCategory=(String)requestData.get("pendencyCategory");
  657. String pendencyCategory="Retirement";
  658. String dateToAudit = (String) requestData.get("dateToAudit");
  659. String remarks = (String) requestData.get("remarks");
  660. String filemovedby =(String)requestData.get("filemovedby");
  661. String pendingDuration = (String) requestData.get("pendingDuration");
  662. String reasonPending =requestData.get("reasonPending") != null ? requestData.get("reasonPending").toString() : null;
  663. String dept_Id = (String) requestData.get("deptId");
  664. System.out.println("dept_Id = "+dept_Id);
  665. int deptId = Integer.parseInt(dept_Id);
  666. String file_category = (String) requestData.get("filecategory");
  667. int filecategory = Integer.parseInt(file_category);
  668. int filestatus = getFileStatus.getFileStatus1Id();
  669. if (filestatus == 0) {
  670. System.out.println("File status not found. Aborting insertion.");
  671. return false;
  672. }
  673. String fileentrytype ="NEW";
  674. int rowsInserted = 0;
  675. // Generate the variable (PR + current date + current time)
  676. String currentTimestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("ddMMyyHHmmss"));
  677. String temp_id = "PP" + currentTimestamp;
  678. String query = "INSERT INTO pensioner_details (emp_no, emp_name, dept_name, designation, retirement_class,retirement_date,pending_duration,reason_for_pending,file_moved_date,dept_id,remarks,file_category,file_status,file_entry_type,file_category_name,type_of_retirement,temp_id) VALUES (?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?)";
  679. rowsInserted = jdbcTemplate.update(query, empNo, empName, deptName, designation, retirementclass,retirementDate,pendingDuration,reasonPending,dateToAudit, deptId,remarks,filecategory,filestatus,fileentrytype,pendencyCategory,typeOfRetirement,temp_id);
  680. String query1 = "INSERT INTO pensioner_details_history (emp_no, emp_name, dept_name, designation, retirement_class,retirement_date,pending_duration,reason_for_pending,file_moved_date,dept_id,remarks,file_category,file_status,file_entry_type,file_category_name,type_of_retirement,file_moved_by,temp_id) VALUES (?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?,?)";
  681. rowsInserted = jdbcTemplate.update(query1, empNo, empName, deptName, designation, retirementclass,retirementDate,pendingDuration,reasonPending,dateToAudit, deptId,remarks,filecategory,filestatus,fileentrytype,pendencyCategory,typeOfRetirement,filemovedby,temp_id);
  682. String query2 = "INSERT INTO file_movement_history (emp_no,file_moved_date,file_status,file_moved_by,remarks,temp_id) VALUES (?,?, ?, ?, ?, ?)";
  683. rowsInserted = jdbcTemplate.update(query2, empNo,dateToAudit,filestatus,filemovedby,remarks,temp_id);
  684. return rowsInserted > 0;
  685. } catch (Exception e) {
  686. e.printStackTrace();
  687. return false; // Return false if an exception occurs
  688. }
  689. }
  690. public boolean doesEmployeeExistRPR(String empCode) {
  691. String sql = "SELECT COUNT(*) FROM ( " +
  692. " SELECT emp_no FROM pensioner_details WHERE emp_no = ? AND file_category IN (1,2,3,4,5) " +
  693. " UNION ALL " +
  694. " SELECT emp_no FROM cps_pensioner_details WHERE emp_no = ? AND file_category IN (6) " +
  695. ") AS combined";
  696. // Note: Pass empCode twice since there are two placeholders.
  697. Integer count = jdbcTemplate.queryForObject(sql, Integer.class,empCode,empCode);
  698. return count != null && count > 0;
  699. }
  700. // public boolean doesEmployeeExist(String empCode) {
  701. //
  702. // String sql = "SELECT COUNT(*) FROM ( " +
  703. // " SELECT emp_no FROM pensioner_details WHERE emp_no = ? AND file_category IN (1,3,5) "+
  704. // " UNION ALL " +
  705. // " SELECT emp_no FROM cps_pensioner_details WHERE emp_no = ? AND file_category IN (6) " +
  706. // ") AS combined";
  707. // // Note: Pass empCode twice since there are two placeholders.
  708. // Integer count = jdbcTemplate.queryForObject(sql,Integer.class,empCode,empCode);
  709. // System.out.println("count<<<<<<<<<<<"+count);
  710. // return count != null && count > 0;
  711. // }
  712. //
  713. //
  714. // public boolean doesEmployeeExistgis(String empCode) {
  715. // String sql = "SELECT COUNT(*) FROM ( " +
  716. // " SELECT emp_no FROM pensioner_details WHERE emp_no = ? AND file_category IN (1,2,3,5,6) " +
  717. // " UNION ALL " +
  718. // " SELECT emp_no FROM cps_pensioner_details WHERE emp_no = ? AND file_category IN (6) " +
  719. // ") AS combined";
  720. // // Note: Pass empCode twice since there are two placeholders.
  721. // Integer count = jdbcTemplate.queryForObject(sql, Integer.class,empCode,empCode);
  722. // return count != null && count > 0;
  723. // }
  724. //
  725. //
  726. // public boolean doesEmployeeExistfp(String empCode) {
  727. //
  728. // String sql = "SELECT COUNT(*) FROM ( " +
  729. //
  730. // " SELECT emp_no FROM pensioner_details WHERE emp_no = ? AND file_category IN (1,2,3,5) AND is_closed IN (0)" +
  731. // " UNION ALL " +
  732. //
  733. // " SELECT emp_no FROM cps_pensioner_details WHERE emp_no = ? AND file_category IN (6) " +
  734. // ") AS combined";
  735. //
  736. // // Note: Pass empCode twice since there are two placeholders.
  737. // Integer count = jdbcTemplate.queryForObject(sql, Integer.class,empCode,empCode);
  738. // return count != null && count > 0;
  739. // }
  740. public boolean doesEmployeeExist(String empCode) {
  741. String sql = "SELECT COUNT(*) FROM ( " +
  742. " SELECT emp_no FROM pensioner_details WHERE emp_no = ? AND file_category IN (3,4,5) "+
  743. " UNION ALL " +
  744. " SELECT emp_no FROM pensioner_details WHERE emp_no = ? AND file_category IN (1) AND is_closed=0 "+
  745. " UNION ALL " +
  746. " SELECT emp_no FROM cps_pensioner_details WHERE emp_no = ? AND file_category IN (6) " +
  747. ") AS combined";
  748. // Note: Pass empCode twice since there are two placeholders.
  749. Integer count = jdbcTemplate.queryForObject(sql,Integer.class,empCode,empCode,empCode);
  750. System.out.println("count<<<<<<<<<<<"+count);
  751. return count != null && count > 0;
  752. }
  753. public boolean doesEmployeeExistgis(String empCode) {
  754. String sql = "SELECT COUNT(*) FROM ( " +
  755. " SELECT emp_no FROM pensioner_details WHERE emp_no = ? AND file_category IN (1,2,3,5) " +
  756. " UNION ALL " +
  757. " SELECT emp_no FROM cps_pensioner_details WHERE emp_no = ? AND file_category IN (6) " +
  758. ") AS combined";
  759. // Note: Pass empCode twice since there are two placeholders.
  760. Integer count = jdbcTemplate.queryForObject(sql, Integer.class,empCode,empCode);
  761. return count != null && count > 0;
  762. }
  763. public boolean doesEmployeeExistfp(String empCode) {
  764. String sql = "SELECT COUNT(*) FROM ( " +
  765. " SELECT emp_no FROM pensioner_details WHERE emp_no = ? AND file_category IN (1,2,3,5) AND is_closed IN (0)" +
  766. " UNION ALL " +
  767. " SELECT emp_no FROM cps_pensioner_details WHERE emp_no = ? AND file_category IN (6) " +
  768. ") AS combined";
  769. // Note: Pass empCode twice since there are two placeholders.
  770. Integer count = jdbcTemplate.queryForObject(sql, Integer.class,empCode,empCode);
  771. return count != null && count > 0;
  772. }
  773. }