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

@@ -405,5 +405,18 @@ public class GepafinConstant {
public static final String ASSIGNED_APPLICATION_STATUS_UPDATED_SUCCESSFULLY = "assigned.application.status.updated.successfully"; 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 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";
} }

View File

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

View File

@@ -61,7 +61,7 @@ public class DashboardDao {
SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean(); SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean();
widgetResponseBean.setWidget1(createWidget1(requestedUserEntity)); widgetResponseBean.setWidget1(createWidget1(requestedUserEntity));
Map<String, Object> widgetBars =getStatistics(requestedUserEntity); Map<String, Object> widgetBars =getStatistics(requestedUserEntity);
widgetResponseBean.setWidgetBars(widgetBars); widgetResponseBean.setWidgetBars(widgetBars);
return widgetResponseBean; return widgetResponseBean;
} }
@@ -193,7 +193,7 @@ public class DashboardDao {
return stats; 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 // 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()); // 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); // Page<UserActionEntity> userActionEntities=userActionsRepository.findActionsByRoleNamesAndHubId(roles,requestedUserEntity.getHub().getId(),pageable);
@@ -274,16 +274,16 @@ public class DashboardDao {
.build(); .build();
} }
public AmendmentWidgetResponseBean getAmendmentDetails(UserEntity userEntity) { public AmendmentWidgetResponseBean getAmendmentDetails(UserEntity userEntity) {
AmendmentWidgetResponseBean amendmentWidgetResponseBean = initializeAmendmentResponseBean(); AmendmentWidgetResponseBean amendmentWidgetResponseBean = initializeAmendmentResponseBean();
Long hubId = userEntity.getHub().getId(); Long hubId = userEntity.getHub().getId();
List<Long> applicationIds = getApplicationIdsForUserOrHub(userEntity,hubId); List<Long> applicationIds = getApplicationIdsForUserOrHub(userEntity,hubId);
setAmendmentCounts(applicationIds,amendmentWidgetResponseBean, hubId); setAmendmentCounts(applicationIds,amendmentWidgetResponseBean, hubId);
calculateExpiringRequestsIn48Hours(applicationIds,amendmentWidgetResponseBean, hubId); calculateExpiringRequestsIn48Hours(applicationIds,amendmentWidgetResponseBean, hubId);
calculateAverageResponseDays(applicationIds,amendmentWidgetResponseBean,hubId); calculateAverageResponseDays(applicationIds,amendmentWidgetResponseBean,hubId);
return amendmentWidgetResponseBean; return amendmentWidgetResponseBean;
} }
public List<Long> getApplicationIdsForUserOrHub(UserEntity userEntity, Long hubId) { public List<Long> getApplicationIdsForUserOrHub(UserEntity userEntity, Long hubId) {
if (validator.checkIsPreInstructor()) { if (validator.checkIsPreInstructor()) {
return assignedApplicationsRepository.findApplicationIdsByUserIdAndIsDeletedFalse(userEntity.getId()); return assignedApplicationsRepository.findApplicationIdsByUserIdAndIsDeletedFalse(userEntity.getId());
@@ -294,27 +294,27 @@ 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); Long totalAmendment = applicationAmendmentRequestRepository.countAmendmentsByApplicationIds(applicationIds);
if (totalAmendment != null) { if (totalAmendment != null) {
responseBean.setTotalAmendments(totalAmendment); responseBean.setTotalAmendments(totalAmendment);
} }
Long awaitingAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus( Long awaitingAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus(
applicationIds, ApplicationAmendmentRequestEnum.AWAITING.getValue()); applicationIds, ApplicationAmendmentRequestEnum.AWAITING.getValue());
if (awaitingAmendments != null) { if (awaitingAmendments != null) {
responseBean.setWaitingForResponseAmendments(awaitingAmendments); responseBean.setWaitingForResponseAmendments(awaitingAmendments);
} }
Long responseRecievedAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus( Long responseRecievedAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus(
applicationIds, ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue()); applicationIds, ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue());
if (responseRecievedAmendments != null) { if (responseRecievedAmendments != null) {
responseBean.setResponseReceivedAmendments(responseRecievedAmendments); responseBean.setResponseReceivedAmendments(responseRecievedAmendments);
} }
Long expiredAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus( Long expiredAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus(
applicationIds, ApplicationAmendmentRequestEnum.EXPIRED.getValue()); applicationIds, ApplicationAmendmentRequestEnum.EXPIRED.getValue());
if (expiredAmendments != null) { if (expiredAmendments != null) {
responseBean.setExpiredAmendments(expiredAmendments); responseBean.setExpiredAmendments(expiredAmendments);
} }
} }
private void calculateExpiringRequestsIn48Hours(List<Long> applicationIds ,AmendmentWidgetResponseBean responseBean, Long hubId) { private void calculateExpiringRequestsIn48Hours(List<Long> applicationIds ,AmendmentWidgetResponseBean responseBean, Long hubId) {
@@ -354,8 +354,8 @@ public class DashboardDao {
} }
public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(UserEntity userEntity) { public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(UserEntity userEntity) {
Long userId = userEntity.getId(); Long userId = userEntity.getId();
Long hubId = userEntity.getHub().getId(); Long hubId = userEntity.getHub().getId();
Object[] results; Object[] results;
List<Long> applicationIds; List<Long> applicationIds;
@@ -403,7 +403,107 @@ public class DashboardDao {
return response; 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;
}
}

View File

@@ -145,6 +145,7 @@ public enum UserActionContextEnum {
GET_APPLICATION_DETAILS("GET_APPLICATION_DETAILS"), GET_APPLICATION_DETAILS("GET_APPLICATION_DETAILS"),
GET_AMENDMENT_DETAILS("GET_AMENDMENT_DETAILS"), GET_AMENDMENT_DETAILS("GET_AMENDMENT_DETAILS"),
GET_APPLICATION_DETAILS_FOR_EVALUATION("GET_APPLICATION_DETAILS_FOR_EVALUATION"), GET_APPLICATION_DETAILS_FOR_EVALUATION("GET_APPLICATION_DETAILS_FOR_EVALUATION"),
GET_STATISTICS_PAGE_FOR_BENEFICIARY("GET_STATISTICS_PAGE_FOR_BENEFICIARY"),
/** Evaluation criteria action context **/ /** Evaluation criteria action context **/
GET_EVALUATION_CRITERIA("GET_EVALUATION_CRITERIA"), GET_EVALUATION_CRITERIA("GET_EVALUATION_CRITERIA"),

View File

@@ -10,5 +10,7 @@ public class ApplicationPageableRequestBean {
private GlobalFilters globalFilters; private GlobalFilters globalFilters;
private Integer daysRange;
private List<ApplicationStatusTypeEnum> status; private List<ApplicationStatusTypeEnum> status;
} }

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -92,5 +92,68 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,
@Query("SELECT a.id FROM ApplicationEntity a WHERE a.hubId = :hubId AND a.isDeleted = false") @Query("SELECT a.id FROM ApplicationEntity a WHERE a.hubId = :hubId AND a.isDeleted = false")
List<Long> findApplicationIdsByHubId(@Param("hubId") Long hubId); 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);
} }

View File

@@ -1,11 +1,7 @@
package net.gepafin.tendermanagement.service; package net.gepafin.tendermanagement.service;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.model.response.AmendmentWidgetResponseBean; import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.model.response.ApplicationWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.AssignedApplicationWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
public interface DashboardService { public interface DashboardService {
@@ -16,4 +12,6 @@ public interface DashboardService {
public AmendmentWidgetResponseBean getAmendmentDetails(HttpServletRequest request); public AmendmentWidgetResponseBean getAmendmentDetails(HttpServletRequest request);
public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(HttpServletRequest request); public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(HttpServletRequest request);
public BeneficiaryStatisticsResponseBean getStatisticsPageForBeneficiary(HttpServletRequest request,Long companyId);
} }

View File

@@ -4,11 +4,7 @@ import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.dao.DashboardDao; import net.gepafin.tendermanagement.dao.DashboardDao;
import net.gepafin.tendermanagement.entities.CompanyEntity; import net.gepafin.tendermanagement.entities.CompanyEntity;
import net.gepafin.tendermanagement.entities.UserEntity; import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.model.response.AmendmentWidgetResponseBean; import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.model.response.ApplicationWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.AssignedApplicationWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
import net.gepafin.tendermanagement.service.DashboardService; import net.gepafin.tendermanagement.service.DashboardService;
import net.gepafin.tendermanagement.util.Validator; import net.gepafin.tendermanagement.util.Validator;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -52,4 +48,11 @@ public class DashboardServiceImpl implements DashboardService {
UserEntity userEntity = validator.validateUser(request); UserEntity userEntity = validator.validateUser(request);
return dashboardDao.getApplicationDetailsForEvaluation(userEntity); 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);
}
} }

View File

@@ -6,11 +6,7 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.model.response.AmendmentWidgetResponseBean; import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.model.response.ApplicationWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.AssignedApplicationWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
import net.gepafin.tendermanagement.model.util.Response; import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants; import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
@@ -90,5 +86,17 @@ public interface DashboardApi {
produces = { "application/json" }) produces = { "application/json" })
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN') || hasRole('ROLE_INSTRUCTOR_MANAGER')|| hasRole('ROLE_PRE_INSTRUCTOR')") @PreAuthorize("hasRole('ROLE_SUPER_ADMIN') || hasRole('ROLE_INSTRUCTOR_MANAGER')|| hasRole('ROLE_PRE_INSTRUCTOR')")
ResponseEntity<Response<AssignedApplicationWidgetResponseBean>> getApplicationDetailsForEvaluation(HttpServletRequest request); ResponseEntity<Response<AssignedApplicationWidgetResponseBean>> getApplicationDetailsForEvaluation(HttpServletRequest request);
@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 = {
@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 = "/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);
} }

View File

@@ -6,11 +6,7 @@ import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.enums.UserActionContextEnum; import net.gepafin.tendermanagement.enums.UserActionContextEnum;
import net.gepafin.tendermanagement.enums.UserActionLogsEnum; import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
import net.gepafin.tendermanagement.model.request.UserActionRequest; import net.gepafin.tendermanagement.model.request.UserActionRequest;
import net.gepafin.tendermanagement.model.response.AmendmentWidgetResponseBean; import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.model.response.ApplicationWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.AssignedApplicationWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
import net.gepafin.tendermanagement.model.util.Response; import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.service.DashboardService; import net.gepafin.tendermanagement.service.DashboardService;
import net.gepafin.tendermanagement.util.LoggingUtil; import net.gepafin.tendermanagement.util.LoggingUtil;
@@ -83,6 +79,15 @@ public class DashboardApiController implements DashboardApi {
return ResponseEntity.status(HttpStatus.CREATED) return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<>(widgetResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.DASHBOARD_WIDGET_FETCHED_SUCCESSFULLY))); .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)));
}
} }

View File

@@ -365,5 +365,5 @@ evaluation.form.not.found=Evaluation form not found.
assigned.application.status.updated.successfully=Assigned application status updated successfully. assigned.application.status.updated.successfully=Assigned application status updated successfully.
validation.required.requested.amount=The Requested Amount configuration should be mandatory. validation.required.requested.amount=The Requested Amount configuration should be mandatory.
company.id.not.null=Company ID cannot be null.

View File

@@ -356,6 +356,6 @@ evaluation.form.not.found=Modulo di valutazione non trovato.
assigned.application.status.updated.successfully=Stato dell'applicazione assegnata aggiornato con successo. assigned.application.status.updated.successfully=Stato dell'applicazione assegnata aggiornato con successo.
validation.required.requested.amount=La configurazione dell'importo richiesto è obbligatoria. validation.required.requested.amount=La configurazione dell'importo richiesto è obbligatoria.
company.id.not.null=L'ID dell'azienda non pu? essere nullo.