|
|
|
@ -52,7 +52,73 @@ public class NewEntryService { |
|
|
|
this.jdbcTemplate = new JdbcTemplate(dataSource); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// old retiment list getting method |
|
|
|
|
|
|
|
// public Map<String, Object> fetchEmplyeeDetails(String fromDate, String toDate, Integer deptId) { |
|
|
|
// Map<String, Object> response = new HashMap<>(); |
|
|
|
// |
|
|
|
// String apiUrl = appconfig.qaqcurl + "serviceId=common_api" |
|
|
|
// + "&jsonResp=Yes" |
|
|
|
// + "&subService=getEmpPenDetDuration" |
|
|
|
// + "&fromDate=" + fromDate |
|
|
|
// + "&toDate=" + toDate |
|
|
|
// + "&deptId=" + deptId; |
|
|
|
// |
|
|
|
// System.out.println("url: " + apiUrl); |
|
|
|
// System.out.println("deptId:" + deptId); |
|
|
|
// try { |
|
|
|
// String rawResponse = restTemplate.getForObject(apiUrl, String.class); |
|
|
|
// System.out.println("Raw Response: " + rawResponse); // Debugging step |
|
|
|
// |
|
|
|
// if (isValidJson(rawResponse)) { |
|
|
|
// JsonNode jsonResponse = objectMapper.readTree(rawResponse); |
|
|
|
// |
|
|
|
// // Extract the "ListResult" array |
|
|
|
// JsonNode details = jsonResponse.path("ListResult"); |
|
|
|
// |
|
|
|
// if (details.isArray() && details.size() > 0) { |
|
|
|
// List<Map<String, String>> list = new ArrayList<>(); |
|
|
|
// for (JsonNode detail : details) { |
|
|
|
// Map<String, String> listResult = new HashMap<>(); |
|
|
|
// |
|
|
|
// listResult.put("RETIREMENT_DATE", getNonNullValue(detail.path("RETIREMENT_DATE"))); |
|
|
|
// listResult.put("DEATH_DATE", getNonNullValue(detail.path("DEATH_DATE"))); |
|
|
|
// listResult.put("COMMUNITY_NAME", getNonNullValue(detail.path("COMMUNITY_NAME"))); |
|
|
|
// listResult.put("GROUP_TYPE", getNonNullValue(detail.path("GROUP_TYPE"))); |
|
|
|
// listResult.put("ID_DEPT", getNonNullValue(detail.path("ID_DEPT"))); |
|
|
|
// listResult.put("EMPLOYEE_CODE", getNonNullValue(detail.path("EMPLOYEE_CODE"))); |
|
|
|
// listResult.put("FUNCTIONARY", getNonNullValue(detail.path("FUNCTIONARY"))); |
|
|
|
// listResult.put("IS_HANDICAPPED", getNonNullValue(detail.path("IS_HANDICAPPED"))); |
|
|
|
// listResult.put("GENDER", getNonNullValue(detail.path("GENDER"))); |
|
|
|
// listResult.put("DATE_OF_BIRTH", getNonNullValue(detail.path("DATE_OF_BIRTH"))); |
|
|
|
// listResult.put("DATE_OF_APPOINTMENT", getNonNullValue(detail.path("DATE_OF_APPOINTMENT"))); |
|
|
|
// listResult.put("DESIGNATION", getNonNullValue(detail.path("DESIGNATION"))); |
|
|
|
// listResult.put("EMPLOYEE_NAME", getNonNullValue(detail.path("EMPLOYEE_NAME"))); |
|
|
|
// listResult.put("DEPARTMENT", getNonNullValue(detail.path("DEPARTMENT"))); |
|
|
|
// list.add(listResult); |
|
|
|
// } |
|
|
|
// // Sort the list by RETIREMENT_DATE in ascending order |
|
|
|
// list.sort(Comparator.comparing(map -> parseDate(((Map<String, String>) map).get("RETIREMENT_DATE")))); |
|
|
|
// |
|
|
|
// response.put("list", list); |
|
|
|
// |
|
|
|
// } else { |
|
|
|
// response.put("list", Collections.emptyList()); |
|
|
|
// } |
|
|
|
// } else { |
|
|
|
// System.err.println("Invalid JSON Response: " + rawResponse); |
|
|
|
// response.put("list", Collections.emptyList()); |
|
|
|
// } |
|
|
|
// |
|
|
|
// } catch (Exception e) { |
|
|
|
// e.printStackTrace(); |
|
|
|
// response.put("list", Collections.emptyList()); |
|
|
|
// } |
|
|
|
// return response; |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// new retirement list getting method with condition |
|
|
|
public Map<String, Object> fetchEmplyeeDetails(String fromDate, String toDate, Integer deptId) { |
|
|
|
Map<String, Object> response = new HashMap<>(); |
|
|
|
|
|
|
|
@ -65,41 +131,48 @@ public class NewEntryService { |
|
|
|
|
|
|
|
System.out.println("url: " + apiUrl); |
|
|
|
System.out.println("deptId:" + deptId); |
|
|
|
|
|
|
|
try { |
|
|
|
String rawResponse = restTemplate.getForObject(apiUrl, String.class); |
|
|
|
System.out.println("Raw Response: " + rawResponse); // Debugging step |
|
|
|
|
|
|
|
if (isValidJson(rawResponse)) { |
|
|
|
JsonNode jsonResponse = objectMapper.readTree(rawResponse); |
|
|
|
|
|
|
|
// Extract the "ListResult" array |
|
|
|
JsonNode details = jsonResponse.path("ListResult"); |
|
|
|
|
|
|
|
if (details.isArray() && details.size() > 0) { |
|
|
|
List<Map<String, String>> list = new ArrayList<>(); |
|
|
|
LocalDate currentDate = LocalDate.now(); // Get today's date |
|
|
|
|
|
|
|
for (JsonNode detail : details) { |
|
|
|
Map<String, String> listResult = new HashMap<>(); |
|
|
|
listResult.put("RETIREMENT_DATE", getNonNullValue(detail.path("RETIREMENT_DATE"))); |
|
|
|
listResult.put("DEATH_DATE", getNonNullValue(detail.path("DEATH_DATE"))); |
|
|
|
listResult.put("COMMUNITY_NAME", getNonNullValue(detail.path("COMMUNITY_NAME"))); |
|
|
|
listResult.put("GROUP_TYPE", getNonNullValue(detail.path("GROUP_TYPE"))); |
|
|
|
listResult.put("ID_DEPT", getNonNullValue(detail.path("ID_DEPT"))); |
|
|
|
listResult.put("EMPLOYEE_CODE", getNonNullValue(detail.path("EMPLOYEE_CODE"))); |
|
|
|
listResult.put("FUNCTIONARY", getNonNullValue(detail.path("FUNCTIONARY"))); |
|
|
|
listResult.put("IS_HANDICAPPED", getNonNullValue(detail.path("IS_HANDICAPPED"))); |
|
|
|
listResult.put("GENDER", getNonNullValue(detail.path("GENDER"))); |
|
|
|
listResult.put("DATE_OF_BIRTH", getNonNullValue(detail.path("DATE_OF_BIRTH"))); |
|
|
|
listResult.put("DATE_OF_APPOINTMENT", getNonNullValue(detail.path("DATE_OF_APPOINTMENT"))); |
|
|
|
listResult.put("DESIGNATION", getNonNullValue(detail.path("DESIGNATION"))); |
|
|
|
listResult.put("EMPLOYEE_NAME", getNonNullValue(detail.path("EMPLOYEE_NAME"))); |
|
|
|
listResult.put("DEPARTMENT", getNonNullValue(detail.path("DEPARTMENT"))); |
|
|
|
list.add(listResult); |
|
|
|
String retirementDateStr = getNonNullValue(detail.path("RETIREMENT_DATE")); |
|
|
|
LocalDate retirementDate = parseDate(retirementDateStr); |
|
|
|
|
|
|
|
// Only add to the list if RETIREMENT_DATE is today or in the future |
|
|
|
if (retirementDate != null && !retirementDate.isBefore(currentDate)) { |
|
|
|
Map<String, String> listResult = new HashMap<>(); |
|
|
|
listResult.put("RETIREMENT_DATE", retirementDateStr); |
|
|
|
listResult.put("DEATH_DATE", getNonNullValue(detail.path("DEATH_DATE"))); |
|
|
|
listResult.put("COMMUNITY_NAME", getNonNullValue(detail.path("COMMUNITY_NAME"))); |
|
|
|
listResult.put("GROUP_TYPE", getNonNullValue(detail.path("GROUP_TYPE"))); |
|
|
|
listResult.put("ID_DEPT", getNonNullValue(detail.path("ID_DEPT"))); |
|
|
|
listResult.put("EMPLOYEE_CODE", getNonNullValue(detail.path("EMPLOYEE_CODE"))); |
|
|
|
listResult.put("FUNCTIONARY", getNonNullValue(detail.path("FUNCTIONARY"))); |
|
|
|
listResult.put("IS_HANDICAPPED", getNonNullValue(detail.path("IS_HANDICAPPED"))); |
|
|
|
listResult.put("GENDER", getNonNullValue(detail.path("GENDER"))); |
|
|
|
listResult.put("DATE_OF_BIRTH", getNonNullValue(detail.path("DATE_OF_BIRTH"))); |
|
|
|
listResult.put("DATE_OF_APPOINTMENT", getNonNullValue(detail.path("DATE_OF_APPOINTMENT"))); |
|
|
|
listResult.put("DESIGNATION", getNonNullValue(detail.path("DESIGNATION"))); |
|
|
|
listResult.put("EMPLOYEE_NAME", getNonNullValue(detail.path("EMPLOYEE_NAME"))); |
|
|
|
listResult.put("DEPARTMENT", getNonNullValue(detail.path("DEPARTMENT"))); |
|
|
|
list.add(listResult); |
|
|
|
} |
|
|
|
} |
|
|
|
// Sort the list by RETIREMENT_DATE in ascending order |
|
|
|
list.sort(Comparator.comparing(map -> parseDate(((Map<String, String>) map).get("RETIREMENT_DATE")))); |
|
|
|
|
|
|
|
response.put("list", list); |
|
|
|
|
|
|
|
// Sort the list by RETIREMENT_DATE in ascending order |
|
|
|
list.sort(Comparator.comparing(map -> parseDate(map.get("RETIREMENT_DATE")))); |
|
|
|
|
|
|
|
response.put("list", list); |
|
|
|
} else { |
|
|
|
response.put("list", Collections.emptyList()); |
|
|
|
} |
|
|
|
@ -107,15 +180,16 @@ public class NewEntryService { |
|
|
|
System.err.println("Invalid JSON Response: " + rawResponse); |
|
|
|
response.put("list", Collections.emptyList()); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
response.put("list", Collections.emptyList()); |
|
|
|
} |
|
|
|
return response; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Object> fetchEmplyeeDetailsbyCode(String empCode) { |
|
|
|
@ -123,7 +197,7 @@ public class NewEntryService { |
|
|
|
|
|
|
|
String apiUrl = appconfig.qaqcurl + "serviceId=common_api" |
|
|
|
+ "&jsonResp=Yes" |
|
|
|
+ "&subService=getEmpPenDet" |
|
|
|
+ "&subService=getEmpWorkDet" |
|
|
|
+ "&empCode=" + empCode; |
|
|
|
|
|
|
|
System.out.println("url: " + apiUrl); |
|
|
|
@ -143,6 +217,7 @@ public class NewEntryService { |
|
|
|
for (JsonNode detail : details) { |
|
|
|
Map<String, String> listResult = new HashMap<>(); |
|
|
|
listResult.put("RETIREMENT_DATE", formatToISODate(getNonNullValue(detail.path("RETIREMENT_DATE")))); |
|
|
|
listResult.put("TO_DATE", parseDate(getNonNullValue(detail.path("TO_DATE"))).toString()); |
|
|
|
listResult.put("DEATH_DATE", getNonNullValue(detail.path("DEATH_DATE"))); |
|
|
|
listResult.put("COMMUNITY_NAME", getNonNullValue(detail.path("COMMUNITY_NAME"))); |
|
|
|
listResult.put("GROUP_TYPE", getNonNullValue(detail.path("GROUP_TYPE"))); |
|
|
|
@ -161,6 +236,7 @@ public class NewEntryService { |
|
|
|
// Sort the list by RETIREMENT_DATE in ascending order |
|
|
|
list.sort(Comparator.comparing(map -> parseDate(((Map<String, String>) map).get("RETIREMENT_DATE")))); |
|
|
|
response.put("list", list); |
|
|
|
System.out.println("listresult: "+list); |
|
|
|
|
|
|
|
} else { |
|
|
|
response.put("list", Collections.emptyList()); |
|
|
|
@ -208,21 +284,49 @@ public class NewEntryService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private LocalDate parseDate(String date) { |
|
|
|
if (date == null || date.isEmpty()) { |
|
|
|
return LocalDate.MIN; // Use a minimum value for invalid or empty dates |
|
|
|
} |
|
|
|
try { |
|
|
|
// Remove time part if present |
|
|
|
if (date.contains(" ")) { |
|
|
|
date = date.split(" ")[0]; // Extract only the date part before space |
|
|
|
} |
|
|
|
|
|
|
|
DateTimeFormatter formatter; |
|
|
|
if (date.matches("\\d{4}-\\d{2}-\\d{2}")) { // yyyy-MM-dd |
|
|
|
formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|
|
|
} else if (date.matches("\\d{2}-\\d{2}-\\d{4}")) { // dd-MM-yyyy |
|
|
|
formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); |
|
|
|
} else { |
|
|
|
System.err.println("Unknown date format: " + date); |
|
|
|
return LocalDate.MIN; |
|
|
|
} |
|
|
|
return LocalDate.parse(date, formatter); |
|
|
|
} catch (DateTimeParseException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
return LocalDate.MIN; // Fallback for invalid dates |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private LocalDate parseDate(String date) { |
|
|
|
if (date == null || date.isEmpty()) { |
|
|
|
return LocalDate.MIN; // Use a minimum value for invalid or empty dates |
|
|
|
} |
|
|
|
try { |
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); // Adjust format as needed |
|
|
|
return LocalDate.parse(date, formatter); |
|
|
|
} catch (DateTimeParseException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
return LocalDate.MIN; // Fallback for invalid dates |
|
|
|
} |
|
|
|
} |
|
|
|
// private LocalDate parseDate(String date) { |
|
|
|
// if (date == null || date.isEmpty()) { |
|
|
|
// return LocalDate.MIN; // Use a minimum value for invalid or empty dates |
|
|
|
// } |
|
|
|
// try { |
|
|
|
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); // Adjust format as needed |
|
|
|
// return LocalDate.parse(date, formatter); |
|
|
|
// } catch (DateTimeParseException e) { |
|
|
|
// e.printStackTrace(); |
|
|
|
// return LocalDate.MIN; // Fallback for invalid dates |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
private boolean isValidJson(String json) { |
|
|
|
|