Done ticket GEPAFINBE-153

This commit is contained in:
Piyush
2025-02-10 14:56:47 +05:30
parent 58a7247f70
commit e9200c6fb3
14 changed files with 300 additions and 58 deletions

View File

@@ -1404,6 +1404,9 @@ public class ApplicationDao {
public PageableResponseBean<List<ApplicationResponse>> getAllApplicationByPagination(UserEntity userEntity, Long callId, Long companyId, ApplicationPageableRequestBean applicationPageableRequestBean) {
Integer pageNo = null;
Integer pageLimit = null;
UserWithCompanyEntity userWithCompany= userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), companyId).orElse(null);
if (applicationPageableRequestBean.getGlobalFilters() != null) {
pageNo = applicationPageableRequestBean.getGlobalFilters().getPage();
pageLimit = applicationPageableRequestBean.getGlobalFilters().getLimit();
@@ -1414,7 +1417,7 @@ public class ApplicationDao {
if (pageNo == null || pageNo <= 0) {
pageNo = GepafinConstant.DEFAULT_PAGE;
}
Specification<ApplicationEntity> spec = search(callId, companyId, applicationPageableRequestBean, userEntity);
Specification<ApplicationEntity> spec = search(callId,companyId, userWithCompany.getId(), applicationPageableRequestBean, userEntity);
Page<ApplicationEntity> entityPage = applicationRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
// Prepare the response
@@ -1437,10 +1440,10 @@ public class ApplicationDao {
return pageableResponseBean;
}
public Specification<ApplicationEntity> search(Long callId, Long companyId, ApplicationPageableRequestBean applicationPageableRequestBean, UserEntity userEntity) {
public Specification<ApplicationEntity> search(Long callId, Long companyId, Long userWithCompanyId, ApplicationPageableRequestBean applicationPageableRequestBean, UserEntity userEntity) {
return (root, query, criteriaBuilder) -> {
List<Predicate> predicates = getPredicates(applicationPageableRequestBean, criteriaBuilder, root, callId, companyId, userEntity);
List<Predicate> predicates = getPredicates(applicationPageableRequestBean, criteriaBuilder, root, callId,companyId, userWithCompanyId, userEntity);
SortBy sortBy = new SortBy(GepafinConstant.CREATED_DATE, true);
if (applicationPageableRequestBean.getGlobalFilters() != null
@@ -1464,13 +1467,15 @@ public class ApplicationDao {
private List<Predicate> getPredicates(ApplicationPageableRequestBean applicationPageableRequestBean,
CriteriaBuilder criteriaBuilder, Root<ApplicationEntity> root, Long callId, Long companyId, UserEntity userEntity) {
CriteriaBuilder criteriaBuilder, Root<ApplicationEntity> root, Long callId,Long companyId, Long userWithCompanyId, UserEntity userEntity) {
Integer year = null;
String search = null;
Integer daysRange = null;
if (applicationPageableRequestBean.getGlobalFilters() != null) {
year = applicationPageableRequestBean.getGlobalFilters().getYear();
search = applicationPageableRequestBean.getGlobalFilters().getSearch();
daysRange = applicationPageableRequestBean.getDaysRange();
}
List<Predicate> predicates = new ArrayList<>();
@@ -1512,16 +1517,24 @@ public class ApplicationDao {
}
// Optional companyId filter
if (userWithCompanyId != null) {
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.USER_WITH_COMPANY).get(GepafinConstant.ID), userWithCompanyId));
}
if (companyId != null) {
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.COMPANY_ID), companyId));
}
if (daysRange != null && daysRange >= 0) {
LocalDateTime today = LocalDateTime.now();
LocalDateTime pastDate = today.minusDays(daysRange);
predicates.add(criteriaBuilder.between(root.get(GepafinConstant.CREATED_DATE), pastDate, today));
}
predicates.add(criteriaBuilder.isFalse(root.get(GepafinConstant.IS_DELETED)));
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.HUB_ID), userEntity.getHub().getId()));
return predicates;
}
public void checkCallEndDate(CallEntity call) {
LocalDateTime now = DateTimeUtil.DateServerToUTC(LocalDateTime.now());

View File

@@ -61,7 +61,7 @@ public class DashboardDao {
SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean();
widgetResponseBean.setWidget1(createWidget1(requestedUserEntity));
Map<String, Object> widgetBars =getStatistics(requestedUserEntity);
widgetResponseBean.setWidgetBars(widgetBars);
widgetResponseBean.setWidgetBars(widgetBars);
return widgetResponseBean;
}
@@ -193,7 +193,7 @@ public class DashboardDao {
return stats;
}
// public Page<UserActionEntity> getUserAction(UserEntity requestedUserEntity){
// public Page<UserActionEntity> getUserAction(UserEntity requestedUserEntity){
// Pageable pageable = PageRequest.of(0, 20); // Get the first 20 records
// List<String> roles=List.of(RoleStatusEnum.ROLE_PRE_INSTRUCTOR.getValue(),RoleStatusEnum.ROLE_GEPAFIN_OPERATOR.getValue(),RoleStatusEnum.ROLE_INSTRUCTOR_MANAGER.getValue());
// Page<UserActionEntity> userActionEntities=userActionsRepository.findActionsByRoleNamesAndHubId(roles,requestedUserEntity.getHub().getId(),pageable);
@@ -274,16 +274,16 @@ public class DashboardDao {
.build();
}
public AmendmentWidgetResponseBean getAmendmentDetails(UserEntity userEntity) {
AmendmentWidgetResponseBean amendmentWidgetResponseBean = initializeAmendmentResponseBean();
public AmendmentWidgetResponseBean getAmendmentDetails(UserEntity userEntity) {
AmendmentWidgetResponseBean amendmentWidgetResponseBean = initializeAmendmentResponseBean();
Long hubId = userEntity.getHub().getId();
Long hubId = userEntity.getHub().getId();
List<Long> applicationIds = getApplicationIdsForUserOrHub(userEntity,hubId);
setAmendmentCounts(applicationIds,amendmentWidgetResponseBean, hubId);
calculateExpiringRequestsIn48Hours(applicationIds,amendmentWidgetResponseBean, hubId);
calculateAverageResponseDays(applicationIds,amendmentWidgetResponseBean,hubId);
return amendmentWidgetResponseBean;
}
return amendmentWidgetResponseBean;
}
public List<Long> getApplicationIdsForUserOrHub(UserEntity userEntity, Long hubId) {
if (validator.checkIsPreInstructor()) {
return assignedApplicationsRepository.findApplicationIdsByUserIdAndIsDeletedFalse(userEntity.getId());
@@ -294,27 +294,27 @@ public class DashboardDao {
private void setAmendmentCounts(List<Long> applicationIds,AmendmentWidgetResponseBean responseBean, Long hubId) {
Long totalAmendment = applicationAmendmentRequestRepository.countAmendmentsByApplicationIds(applicationIds);
if (totalAmendment != null) {
responseBean.setTotalAmendments(totalAmendment);
}
Long totalAmendment = applicationAmendmentRequestRepository.countAmendmentsByApplicationIds(applicationIds);
if (totalAmendment != null) {
responseBean.setTotalAmendments(totalAmendment);
}
Long awaitingAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus(
applicationIds, ApplicationAmendmentRequestEnum.AWAITING.getValue());
if (awaitingAmendments != null) {
responseBean.setWaitingForResponseAmendments(awaitingAmendments);
}
Long responseRecievedAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus(
applicationIds, ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue());
if (responseRecievedAmendments != null) {
responseBean.setResponseReceivedAmendments(responseRecievedAmendments);
}
Long expiredAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus(
applicationIds, ApplicationAmendmentRequestEnum.EXPIRED.getValue());
if (expiredAmendments != null) {
responseBean.setExpiredAmendments(expiredAmendments);
}
}
Long awaitingAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus(
applicationIds, ApplicationAmendmentRequestEnum.AWAITING.getValue());
if (awaitingAmendments != null) {
responseBean.setWaitingForResponseAmendments(awaitingAmendments);
}
Long responseRecievedAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus(
applicationIds, ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue());
if (responseRecievedAmendments != null) {
responseBean.setResponseReceivedAmendments(responseRecievedAmendments);
}
Long expiredAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus(
applicationIds, ApplicationAmendmentRequestEnum.EXPIRED.getValue());
if (expiredAmendments != null) {
responseBean.setExpiredAmendments(expiredAmendments);
}
}
private void calculateExpiringRequestsIn48Hours(List<Long> applicationIds ,AmendmentWidgetResponseBean responseBean, Long hubId) {
@@ -354,8 +354,8 @@ public class DashboardDao {
}
public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(UserEntity userEntity) {
Long userId = userEntity.getId();
Long hubId = userEntity.getHub().getId();
Long userId = userEntity.getId();
Long hubId = userEntity.getHub().getId();
Object[] results;
List<Long> applicationIds;
@@ -403,7 +403,107 @@ public class DashboardDao {
return response;
}
public static List<String> getStatusList() {
return List.of(
ApplicationStatusTypeEnum.SUBMIT.getValue(),
ApplicationStatusTypeEnum.EVALUATION.getValue(),
ApplicationStatusTypeEnum.APPROVED.getValue(),
ApplicationStatusTypeEnum.REJECTED.getValue(),
ApplicationStatusTypeEnum.SOCCORSO.getValue(),
ApplicationStatusTypeEnum.APPOINTMENT.getValue(),
ApplicationStatusTypeEnum.NDG.getValue(),
ApplicationStatusTypeEnum.ADMISSIBLE.getValue()
);
}
public BeneficiaryStatisticsResponseBean getStatisticsPageForBeneficiary(UserEntity userEntity, CompanyEntity company) {
BeneficiaryStatisticsResponseBean widgetResponseBean = initializeBeneficiaryStatisticsBean();
UserWithCompanyEntity userWithCompanyEntity = companyService.getUserWithCompany(userEntity.getId(), company.getId());
Long hubId = userEntity.getHub().getId();
List<String> statusList = getStatusList();
Long submittedApplication = applicationRepository.countSubmittedApplicationsByHubIdAndUserId(hubId, userEntity.getId(), userWithCompanyEntity.getId(),statusList);
Long approvedApplication = getApplicationCountByStatus(hubId, userEntity.getId(), userWithCompanyEntity.getId(), ApplicationStatusTypeEnum.APPROVED);
BigDecimal successRate = getSuccessRate(hubId, userEntity.getId(), userWithCompanyEntity.getId());
BigDecimal totalAmountRequested = applicationRepository.sumAmountRequestedByHubIdAndUserId(hubId, userEntity.getId(), userWithCompanyEntity.getId());
updateApplicationWidget(widgetResponseBean.getApplicationWidget(), submittedApplication, approvedApplication, successRate,totalAmountRequested);
Map<String, Object> widgetBars = getApplicationStatistics(userEntity,userWithCompanyEntity.getId());
widgetResponseBean.setApplicationWidgetBars(widgetBars);
return widgetResponseBean;
}
private BeneficiaryStatisticsResponseBean initializeBeneficiaryStatisticsBean() {
return BeneficiaryStatisticsResponseBean.builder()
.applicationWidget(ApplicationWidget.builder()
.submittedApplication(0L)
.approvedApplication(0L)
.successRate(BigDecimal.ZERO)
.totalAmountFinanced(BigDecimal.ZERO)
.build())
.build();
}
private Long getApplicationCountByStatus(Long hubId, Long userId, Long userWithCompanyId, ApplicationStatusTypeEnum status) {
return applicationRepository.countSubmittedApplicationsByHubIdAndUserIdAndStatus(hubId, userId, userWithCompanyId, status.getValue());
}
private BigDecimal getSuccessRate(Long hubId, Long userId, Long userWithCompanyId) {
return applicationRepository.findSuccessRateByHubIdAndUserIdAndUserWithCompanyId(hubId, userId, userWithCompanyId);
}
private void updateApplicationWidget(ApplicationWidget applicationWidget, Long submittedApplication, Long approvedApplication, BigDecimal successRate, BigDecimal totalAmountRequested) {
applicationWidget.setSubmittedApplication(submittedApplication != null ? submittedApplication : 0L);
applicationWidget.setApprovedApplication(approvedApplication != null ? approvedApplication : 0L);
applicationWidget.setSuccessRate(successRate != null ? successRate : BigDecimal.ZERO);
applicationWidget.setTotalAmountFinanced(totalAmountRequested != null ? totalAmountRequested : BigDecimal.ZERO);
}
public Map<String, Object> getApplicationStatistics(UserEntity requestedUser,Long userWithCompanyId) {
Map<String, Object> stats = new HashMap<>();
Map<String, Long> statusData = new HashMap<>();
for (ApplicationStatusTypeEnum status : ApplicationStatusTypeEnum.values()) {
statusData.put(status.name(), 0L);
}
// Get applications per status
List<Object[]> applicationsByStatus = applicationRepository.findApplicationsByStatusAndUserIdAndUserWithCompanyId(
requestedUser.getHub().getId(),
requestedUser.getId(),
userWithCompanyId
);
applicationsByStatus.forEach(result -> {
String status = (String) result[0];
Long count = (Long) result[1];
statusData.put(status, count);
});
List<Map<String, Object>> statusList = statusData.entrySet().stream().map(entry -> {
Map<String, Object> statusMap = new HashMap<>();
statusMap.put(GepafinConstant.STATUS, entry.getKey());
statusMap.put(GepafinConstant.NUMBER_OF_APPLICATION, entry.getValue());
return statusMap;
}).collect(Collectors.toList());
stats.put(GepafinConstant.APPLICATION_PER_STATUS, statusList);
// Requested VS Approved Amounts
List<Object[]> requestedVsApprovedAmounts = applicationRepository.findRequestedVsApprovedAmountsPerMonth(
requestedUser.getHub().getId(),
requestedUser.getId(),
userWithCompanyId
);
stats.put(GepafinConstant.REQUESTED_VS_APPROVED_AMOUNTS, requestedVsApprovedAmounts.stream().map(result -> {
Map<String, Object> data = new HashMap<>();
data.put(GepafinConstant.MONTH, result[0]);
data.put(GepafinConstant.TOTAL_REQUESTED, result[1]);
data.put(GepafinConstant.TOTAL_APPROVED, result[2]);
return data;
}).toList());
}
return stats;
}
}