Done ticket GEPAFINBE-153
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user