Merge pull request #207 from Kitzanos/feature/GEPAFINBE-153
GEPAFINBE-153 (Beneficiary: create stats page )
This commit is contained in:
@@ -408,6 +408,19 @@ public class GepafinConstant {
|
||||
public static final String ASSIGNED_APPLICATION_STATUS_UPDATED_SUCCESSFULLY = "assigned.application.status.updated.successfully";
|
||||
|
||||
public static final String REQUIRED_REQUESTED_AMOUNT_MSG = "validation.required.requested.amount";
|
||||
|
||||
|
||||
public static final String REQUESTED_VS_APPROVED_AMOUNTS="requestedVsApprovedAmount";
|
||||
public static final String MONTH="month";
|
||||
public static final String TOTAL_REQUESTED="totalRequested";
|
||||
public static final String TOTAL_APPROVED="totalApproved";
|
||||
|
||||
public static final String NUMBER_OF_APPLICATION="numberOfApplication";
|
||||
|
||||
|
||||
public static final String COMPANY_ID_NOT_NULL_MSG = "company.id.not.null";
|
||||
public static final String USER_WITH_COMPANY="userWithCompany";
|
||||
|
||||
public static final String FORMULA_AMOUNT_NOT_MATCHED="formula.amount.not.matches.requested.amount";
|
||||
public static final String CRITERIA_TABLE_COLUMNS="criteria_table_columns";
|
||||
|
||||
|
||||
@@ -1419,6 +1419,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();
|
||||
@@ -1429,7 +1432,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
|
||||
|
||||
@@ -1452,10 +1455,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
|
||||
@@ -1479,13 +1482,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<>();
|
||||
|
||||
@@ -1527,16 +1532,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());
|
||||
|
||||
@@ -65,7 +65,7 @@ public class DashboardDao {
|
||||
public SuperAdminWidgetResponseBean getDashboardWidget(UserEntity requestedUserEntity) {
|
||||
SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean();
|
||||
widgetResponseBean.setWidget1(createWidget1(requestedUserEntity));
|
||||
Map<String, Object> widgetBars =getStatistics(requestedUserEntity);
|
||||
Map<String, Object> widgetBars = getStatistics(requestedUserEntity);
|
||||
widgetResponseBean.setWidgetBars(widgetBars);
|
||||
return widgetResponseBean;
|
||||
}
|
||||
@@ -79,8 +79,8 @@ public class DashboardDao {
|
||||
setSubmittedApplications(widget1, requestedUserEntity);
|
||||
setDraftApplications(widget1, requestedUserEntity);
|
||||
setNumberOfCompanies(widget1, requestedUserEntity);
|
||||
setAmountRequested(widget1,requestedUserEntity);
|
||||
setAmountAccepted(widget1,requestedUserEntity);
|
||||
setAmountRequested(widget1, requestedUserEntity);
|
||||
setAmountAccepted(widget1, requestedUserEntity);
|
||||
return widget1;
|
||||
}
|
||||
|
||||
@@ -198,7 +198,8 @@ 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);
|
||||
@@ -256,7 +257,7 @@ public class DashboardDao {
|
||||
responseBean.setEvaluationAverageTime(averageTime != null ? averageTime.setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO);
|
||||
}
|
||||
LocalDate twoDaysLater = LocalDate.now().plusDays(2);
|
||||
List<String> statusList =Arrays.asList( ApplicationEvaluationStatusTypeEnum.OPEN.getValue(), ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());
|
||||
List<String> statusList = Arrays.asList(ApplicationEvaluationStatusTypeEnum.OPEN.getValue(), ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());
|
||||
Long dueApplications = applicationEvaluationRepository.countDueApplicationsBetween(
|
||||
applicationIds,
|
||||
LocalDate.now(),
|
||||
@@ -268,6 +269,7 @@ public class DashboardDao {
|
||||
responseBean.setNumberOfDueApplication(dueApplications);
|
||||
}
|
||||
}
|
||||
|
||||
private AmendmentWidgetResponseBean initializeAmendmentResponseBean() {
|
||||
return AmendmentWidgetResponseBean.builder()
|
||||
.totalAmendments(0L)
|
||||
@@ -283,13 +285,14 @@ public class DashboardDao {
|
||||
AmendmentWidgetResponseBean amendmentWidgetResponseBean = initializeAmendmentResponseBean();
|
||||
|
||||
Long hubId = userEntity.getHub().getId();
|
||||
List<Long> applicationIds = getApplicationIdsForUserOrHub(userEntity,hubId,null);
|
||||
setAmendmentCounts(applicationIds,amendmentWidgetResponseBean, hubId);
|
||||
calculateExpiringRequestsIn48Hours(applicationIds,amendmentWidgetResponseBean, hubId);
|
||||
calculateAverageResponseDays(applicationIds,amendmentWidgetResponseBean,hubId);
|
||||
List<Long> applicationIds = getApplicationIdsForUserOrHub(userEntity, hubId, null);
|
||||
setAmendmentCounts(applicationIds, amendmentWidgetResponseBean, hubId);
|
||||
calculateExpiringRequestsIn48Hours(applicationIds, amendmentWidgetResponseBean, hubId);
|
||||
calculateAverageResponseDays(applicationIds, amendmentWidgetResponseBean, hubId);
|
||||
return amendmentWidgetResponseBean;
|
||||
}
|
||||
public List<Long> getApplicationIdsForUserOrHub(UserEntity userEntity, Long hubId , Long userId) {
|
||||
|
||||
public List<Long> getApplicationIdsForUserOrHub(UserEntity userEntity, Long hubId, Long userId) {
|
||||
if (userId != null) {
|
||||
return assignedApplicationsRepository.findApplicationIdsByUserIdAndIsDeletedFalse(userId);
|
||||
} else if (validator.checkIsPreInstructor()) {
|
||||
@@ -299,7 +302,7 @@ public class DashboardDao {
|
||||
}
|
||||
}
|
||||
|
||||
private void setAmendmentCounts(List<Long> applicationIds,AmendmentWidgetResponseBean responseBean, Long hubId) {
|
||||
private void setAmendmentCounts(List<Long> applicationIds, AmendmentWidgetResponseBean responseBean, Long hubId) {
|
||||
|
||||
Long totalAmendment = applicationAmendmentRequestRepository.countAmendmentsByApplicationIds(applicationIds);
|
||||
if (totalAmendment != null) {
|
||||
@@ -323,7 +326,7 @@ public class DashboardDao {
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateExpiringRequestsIn48Hours(List<Long> applicationIds ,AmendmentWidgetResponseBean responseBean, Long hubId) {
|
||||
private void calculateExpiringRequestsIn48Hours(List<Long> applicationIds, AmendmentWidgetResponseBean responseBean, Long hubId) {
|
||||
|
||||
// Define the statuses to filter
|
||||
List<String> statuses = List.of(
|
||||
@@ -345,7 +348,7 @@ public class DashboardDao {
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateAverageResponseDays(List<Long> applicationIds ,AmendmentWidgetResponseBean responseBean, Long hubId) {
|
||||
private void calculateAverageResponseDays(List<Long> applicationIds, AmendmentWidgetResponseBean responseBean, Long hubId) {
|
||||
|
||||
if (!applicationIds.isEmpty()) {
|
||||
BigDecimal averageResponseDays = applicationAmendmentRequestRepository
|
||||
@@ -359,7 +362,8 @@ public class DashboardDao {
|
||||
responseBean.setAverageResponseDays(BigDecimal.ZERO);
|
||||
}
|
||||
}
|
||||
public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(UserEntity userEntity) {
|
||||
|
||||
public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(UserEntity userEntity) {
|
||||
Long userId = userEntity.getId();
|
||||
Long hubId = userEntity.getHub().getId();
|
||||
|
||||
@@ -367,7 +371,7 @@ public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(
|
||||
List<Long> applicationIds;
|
||||
if (validator.checkIsPreInstructor()) {
|
||||
results = assignedApplicationsRepository.countAssignedApplicationsWithStatus(userId, hubId);
|
||||
applicationIds = assignedApplicationsRepository.findApplicationIdsByUserIdAndHubIdAndIsDeletedFalse(userId,hubId);
|
||||
applicationIds = assignedApplicationsRepository.findApplicationIdsByUserIdAndHubIdAndIsDeletedFalse(userId, hubId);
|
||||
} else {
|
||||
results = assignedApplicationsRepository.countAssignedApplicationsForHub(hubId);
|
||||
applicationIds = assignedApplicationsRepository.findApplicationIdsByHubId(hubId);
|
||||
@@ -389,9 +393,9 @@ public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(
|
||||
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate twoDaysLater = today.plusDays(2);
|
||||
List<String> statusList =Arrays.asList( ApplicationEvaluationStatusTypeEnum.OPEN.getValue(), ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());
|
||||
List<String> statusList = Arrays.asList(ApplicationEvaluationStatusTypeEnum.OPEN.getValue(), ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());
|
||||
Long dueApplications = applicationEvaluationRepository.countDueApplicationsBetween(
|
||||
applicationIds, today, twoDaysLater,statusList
|
||||
applicationIds, today, twoDaysLater, statusList
|
||||
);
|
||||
response.setNumberOfApplicationExpiringIn48Hours(dueApplications != null ? dueApplications : 0L);
|
||||
}
|
||||
@@ -409,7 +413,109 @@ public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(
|
||||
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;
|
||||
}
|
||||
private PreInstructorWidgetResponseBean initializeDashboardPreInstructorResponseBean() {
|
||||
return PreInstructorWidgetResponseBean.builder()
|
||||
.assignedApplication(ApplicationToConsider.builder()
|
||||
|
||||
@@ -149,6 +149,7 @@ public enum UserActionContextEnum {
|
||||
GET_AMENDMENT_DETAILS("GET_AMENDMENT_DETAILS"),
|
||||
GET_DASHBOARD_WIDGET_FOR_PRE_INSTRUCTOR("GET_DASHBOARD_WIDGET_FOR_PRE_INSTRUCTOR"),
|
||||
GET_APPLICATION_DETAILS_FOR_EVALUATION("GET_APPLICATION_DETAILS_FOR_EVALUATION"),
|
||||
GET_STATISTICS_PAGE_FOR_BENEFICIARY("GET_STATISTICS_PAGE_FOR_BENEFICIARY"),
|
||||
|
||||
/** Evaluation criteria action context **/
|
||||
GET_EVALUATION_CRITERIA("GET_EVALUATION_CRITERIA"),
|
||||
|
||||
@@ -10,5 +10,7 @@ public class ApplicationPageableRequestBean {
|
||||
|
||||
private GlobalFilters globalFilters;
|
||||
|
||||
private Integer daysRange;
|
||||
|
||||
private List<ApplicationStatusTypeEnum> status;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.gepafin.tendermanagement.model.response;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class ApplicationWidget {
|
||||
|
||||
private Long submittedApplication;
|
||||
|
||||
private BigDecimal successRate;
|
||||
|
||||
private Long approvedApplication;
|
||||
|
||||
private BigDecimal totalAmountFinanced;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.gepafin.tendermanagement.model.response;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class BeneficiaryStatisticsResponseBean {
|
||||
|
||||
|
||||
private ApplicationWidget applicationWidget;
|
||||
|
||||
private Map<String, Object> applicationWidgetBars;
|
||||
}
|
||||
@@ -94,5 +94,68 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,
|
||||
@Query("SELECT a.id FROM ApplicationEntity a WHERE a.hubId = :hubId AND a.isDeleted = false")
|
||||
List<Long> findApplicationIdsByHubId(@Param("hubId") Long hubId);
|
||||
|
||||
@Query("SELECT CASE WHEN COUNT(CASE WHEN a.submissionDate IS NOT NULL THEN 1 ELSE NULL END) > 0 THEN " +
|
||||
"CAST((SUM(CASE WHEN a.status = 'APPROVED' THEN 1 ELSE 0 END) * 100.0) / " +
|
||||
"COUNT(CASE WHEN a.submissionDate IS NOT NULL THEN 1 ELSE NULL END) AS BigDecimal) " +
|
||||
"ELSE CAST(0 AS BigDecimal) END " +
|
||||
"FROM ApplicationEntity a " +
|
||||
"WHERE a.hubId = :hubId AND a.userId = :userId AND a.userWithCompany.id = :userWithCompanyId " +
|
||||
"AND a.isDeleted = false")
|
||||
BigDecimal findSuccessRateByHubIdAndUserIdAndUserWithCompanyId(
|
||||
@Param("hubId") Long hubId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("userWithCompanyId") Long userWithCompanyId);
|
||||
|
||||
|
||||
@Query("SELECT a.status, COUNT(a.id) FROM ApplicationEntity a WHERE a.isDeleted = false AND a.userId = :userId AND a.userWithCompany.id = :userWithCompanyId AND a.call.hub.id = :hubId GROUP BY a.status")
|
||||
List<Object[]> findApplicationsByStatusAndUserIdAndUserWithCompanyId(@Param("hubId") Long hubId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("userWithCompanyId") Long userWithCompanyId);
|
||||
|
||||
@Query("""
|
||||
SELECT TO_CHAR(a.submissionDate, 'Mon') AS month,
|
||||
SUM(a.amountRequested) AS totalRequested,
|
||||
SUM(a.amountAccepted) AS totalApproved
|
||||
FROM ApplicationEntity a
|
||||
WHERE a.isDeleted = false
|
||||
AND a.status = 'APPROVED'
|
||||
AND a.call.hub.id = :hubId
|
||||
AND a.userId = :userId
|
||||
AND a.userWithCompany.id = :userWithCompanyId
|
||||
GROUP BY TO_CHAR(a.submissionDate, 'Mon'), EXTRACT(YEAR FROM a.submissionDate), EXTRACT(MONTH FROM a.submissionDate)
|
||||
ORDER BY EXTRACT(YEAR FROM a.submissionDate), EXTRACT(MONTH FROM a.submissionDate)
|
||||
""")
|
||||
List<Object[]> findRequestedVsApprovedAmountsPerMonth(
|
||||
@Param("hubId") Long hubId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("userWithCompanyId") Long userWithCompanyId
|
||||
);
|
||||
|
||||
@Query("SELECT COUNT(a) FROM ApplicationEntity a " +
|
||||
"WHERE a.hubId = :hubId " +
|
||||
"AND a.userId = :userId " +
|
||||
"AND a.userWithCompany.id = :userWithCompanyId " +
|
||||
"AND a.isDeleted = false " +
|
||||
"AND a.status IN :statusList " +
|
||||
"AND a.submissionDate IS NOT NULL")
|
||||
Long countSubmittedApplicationsByHubIdAndUserId(
|
||||
@Param("hubId") Long hubId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("userWithCompanyId") Long userWithCompanyId,
|
||||
@Param("statusList") List<String> statusList
|
||||
);
|
||||
|
||||
@Query("SELECT COUNT(a) FROM ApplicationEntity a " +
|
||||
"WHERE a.hubId = :hubId " +
|
||||
"AND a.userId = :userId " +
|
||||
"AND a.userWithCompany.id = :userWithCompanyId " +
|
||||
"AND a.status = :status " +
|
||||
"AND a.isDeleted = false")
|
||||
Long countSubmittedApplicationsByHubIdAndUserIdAndStatus(
|
||||
@Param("hubId") Long hubId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("userWithCompanyId") Long userWithCompanyId,
|
||||
@Param("status") String status);
|
||||
@Query("SELECT SUM(a.amountAccepted) FROM ApplicationEntity a WHERE a.hubId = :hubId AND a.userId = :userId AND a.status = 'APPROVED' AND a.userWithCompany.id = :userWithCompanyId AND a.isDeleted = false")
|
||||
BigDecimal sumAmountRequestedByHubIdAndUserId(@Param("hubId") Long hubId, @Param("userId") Long userId, @Param("userWithCompanyId") Long userWithCompanyId);
|
||||
}
|
||||
|
||||
@@ -18,4 +18,6 @@ public interface DashboardService {
|
||||
public PreInstructorWidgetResponseBean getDashboardWidgetForPreInstructor(HttpServletRequest request,Long userId);
|
||||
public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(HttpServletRequest request);
|
||||
|
||||
public BeneficiaryStatisticsResponseBean getStatisticsPageForBeneficiary(HttpServletRequest request,Long companyId);
|
||||
|
||||
}
|
||||
|
||||
@@ -57,4 +57,11 @@ public class DashboardServiceImpl implements DashboardService {
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
return dashboardDao.getApplicationDetailsForEvaluation(userEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BeneficiaryStatisticsResponseBean getStatisticsPageForBeneficiary(HttpServletRequest request, Long companyId) {
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
CompanyEntity company = validator.validateUserWithCompany(request, companyId);
|
||||
return dashboardDao.getStatisticsPageForBeneficiary(userEntity,company);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public interface DashboardApi {
|
||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN') || hasRole('ROLE_INSTRUCTOR_MANAGER')|| hasRole('ROLE_PRE_INSTRUCTOR')")
|
||||
ResponseEntity<Response<AssignedApplicationWidgetResponseBean>> getApplicationDetailsForEvaluation(HttpServletRequest request);
|
||||
|
||||
@Operation(summary = "Api to get dashboard widget for pre instructor",
|
||||
@Operation(summary = "Api to get Statistics page for beneficiary",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@@ -105,10 +105,25 @@ public interface DashboardApi {
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||
|
||||
@GetMapping(value = "/beneficiary/statistic/company/{companyId}",
|
||||
produces = { "application/json" })
|
||||
ResponseEntity<Response<BeneficiaryStatisticsResponseBean>> getStatisticsPageForBeneficiary(HttpServletRequest request,
|
||||
@Parameter(description = "The company id", required = true) @PathVariable(value = "companyId", required = true) Long companyId);
|
||||
|
||||
|
||||
|
||||
|
||||
@Operation(summary = "Api to get dashboard widget for pre instructor",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||
@GetMapping(value = "/instructor/amendment",
|
||||
produces = { "application/json" })
|
||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN') || hasRole('ROLE_INSTRUCTOR_MANAGER')|| hasRole('ROLE_PRE_INSTRUCTOR')")
|
||||
ResponseEntity<Response<PreInstructorWidgetResponseBean>> getDashboardWidgetForPreInstructor(HttpServletRequest request, @Parameter(description = "The User ID", required = false) @RequestParam(value = "userId",required = false) Long userId);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -93,6 +93,15 @@ public class DashboardApiController implements DashboardApi {
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(widgetResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.DASHBOARD_WIDGET_FETCHED_SUCCESSFULLY)));
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<Response<BeneficiaryStatisticsResponseBean>> getStatisticsPageForBeneficiary(HttpServletRequest request, Long companyId) {
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Get statistics page for beneficiary" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_STATISTICS_PAGE_FOR_BENEFICIARY).build());
|
||||
|
||||
BeneficiaryStatisticsResponseBean widgetResponseBean= dashboardService.getStatisticsPageForBeneficiary(request, companyId);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(widgetResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.DASHBOARD_WIDGET_FETCHED_SUCCESSFULLY)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -368,6 +368,7 @@ either.applicationId.or.assignedApplicationId.must.be.provided=Either applicatio
|
||||
assigned.application.status.updated.successfully=Assigned application status updated successfully.
|
||||
|
||||
validation.required.requested.amount=The Requested Amount configuration should be mandatory.
|
||||
company.id.not.null=Company ID cannot be null.
|
||||
formula.amount.not.matches.requested.amount= The {0} does not matches to calculated amount.
|
||||
|
||||
|
||||
|
||||
@@ -359,5 +359,7 @@ either.applicationId.or.assignedApplicationId.must.be.provided = "<22> necessario
|
||||
assigned.application.status.updated.successfully=Stato dell'applicazione assegnata aggiornato con successo.
|
||||
|
||||
validation.required.requested.amount=La configurazione dell'importo richiesto <20> obbligatoria.
|
||||
company.id.not.null=L'ID dell'azienda non pu? essere nullo.
|
||||
formula.amount.not.matches.requested.amount=Il {0} non corrisponde all'importo calcolato.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user