Code for dashbaord API
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package net.gepafin.tendermanagement.dao;
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserActionEntity;
|
||||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
||||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||||
@@ -9,15 +10,18 @@ import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
|||||||
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
|
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.response.Widget1;
|
import net.gepafin.tendermanagement.model.response.Widget1;
|
||||||
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
|
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
|
||||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
import net.gepafin.tendermanagement.repositories.CallRepository;
|
|
||||||
import net.gepafin.tendermanagement.repositories.CompanyRepository;
|
|
||||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
|
||||||
import net.gepafin.tendermanagement.service.CompanyService;
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class DashboardDao {
|
public class DashboardDao {
|
||||||
@@ -37,11 +41,15 @@ public class DashboardDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CompanyService companyService;
|
private CompanyService companyService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserActionsRepository userActionsRepository;
|
||||||
|
|
||||||
public SuperAdminWidgetResponseBean getDashboardWidget(UserEntity requestedUserEntity) {
|
public SuperAdminWidgetResponseBean getDashboardWidget(UserEntity requestedUserEntity) {
|
||||||
SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean();
|
SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean();
|
||||||
widgetResponseBean.setWidget1(createWidget1(requestedUserEntity));
|
widgetResponseBean.setWidget1(createWidget1(requestedUserEntity));
|
||||||
// List<Object[]> widgetBars = callRepository.findApplicationsPerCall();
|
Map<String, Object> widgetBars =getStatistics(requestedUserEntity);
|
||||||
// widgetResponseBean.setWidgetBars(widgetBars);
|
widgetResponseBean.setWidgetBars(widgetBars);
|
||||||
|
widgetResponseBean.setUserActionWidgetList(getUserAction(requestedUserEntity));
|
||||||
return widgetResponseBean;
|
return widgetResponseBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +62,8 @@ public class DashboardDao {
|
|||||||
setSubmittedApplications(widget1, requestedUserEntity);
|
setSubmittedApplications(widget1, requestedUserEntity);
|
||||||
setDraftApplications(widget1, requestedUserEntity);
|
setDraftApplications(widget1, requestedUserEntity);
|
||||||
setNumberOfCompanies(widget1, requestedUserEntity);
|
setNumberOfCompanies(widget1, requestedUserEntity);
|
||||||
|
setAmountRequested(widget1,requestedUserEntity);
|
||||||
|
setAmountAccepted(widget1,requestedUserEntity);
|
||||||
return widget1;
|
return widget1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +80,20 @@ public class DashboardDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setAmountRequested(Widget1 widget1, UserEntity requestedUserEntity) {
|
||||||
|
BigDecimal amountRequested = callRepository.findTotalAmountOfPublishedCalls(requestedUserEntity.getHub().getId());
|
||||||
|
if (amountRequested != null) {
|
||||||
|
widget1.setAmountRequested(amountRequested);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setAmountAccepted(Widget1 widget1, UserEntity requestedUserEntity) {
|
||||||
|
BigDecimal amountAccepted = applicationRepository.findTotalApprovedApplicationAmount(requestedUserEntity.getHub().getId());
|
||||||
|
if (amountAccepted != null) {
|
||||||
|
widget1.setAmountAccepted(amountAccepted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setRegisteredUsers(Widget1 widget1, UserEntity requestedUserEntity) {
|
private void setRegisteredUsers(Widget1 widget1, UserEntity requestedUserEntity) {
|
||||||
Long activeUsers = userRepository.countByStatusAndRoleEntityRoleTypeAndHubId(UserStatusEnum.ACTIVE.getValue(),
|
Long activeUsers = userRepository.countByStatusAndRoleEntityRoleTypeAndHubId(UserStatusEnum.ACTIVE.getValue(),
|
||||||
RoleStatusEnum.ROLE_BENEFICIARY.getValue(), requestedUserEntity.getHub().getId());
|
RoleStatusEnum.ROLE_BENEFICIARY.getValue(), requestedUserEntity.getHub().getId());
|
||||||
@@ -121,4 +144,34 @@ public class DashboardDao {
|
|||||||
}
|
}
|
||||||
return beneficiaryWidgetResponseBean;
|
return beneficiaryWidgetResponseBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getStatistics(UserEntity requestedUser) {
|
||||||
|
Map<String, Object> stats = new HashMap<>();
|
||||||
|
|
||||||
|
// Get applications per call
|
||||||
|
List<Object[]> applicationsPerCall = applicationRepository.findApplicationsPerCallWithName(requestedUser.getHub().getId());
|
||||||
|
stats.put("APPLICATION_PER_CALL", applicationsPerCall.stream().map(result -> {
|
||||||
|
Map<String, Object> callData = new HashMap<>();
|
||||||
|
callData.put("CALL", result[0]); // Call name
|
||||||
|
callData.put("APPLICATIONS", result[1]); // Application count
|
||||||
|
return callData;
|
||||||
|
}).toList());
|
||||||
|
|
||||||
|
// Get applications grouped by status
|
||||||
|
List<Object[]> applicationsByStatus = applicationRepository.findApplicationsByStatus(requestedUser.getHub().getId());
|
||||||
|
stats.put("APPLICATION_STATUSES", applicationsByStatus.stream().map(result -> {
|
||||||
|
Map<String, Object> statusData = new HashMap<>();
|
||||||
|
statusData.put("STATUS", result[0]); // Application status
|
||||||
|
statusData.put("COUNT", result[1]); // Count of applications
|
||||||
|
return statusData;
|
||||||
|
}).toList());
|
||||||
|
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
return userActionEntities;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
package net.gepafin.tendermanagement.model.response;
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserActionEntity;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class SuperAdminWidgetResponseBean {
|
public class SuperAdminWidgetResponseBean {
|
||||||
|
|
||||||
private Widget1 widget1;
|
private Widget1 widget1;
|
||||||
|
|
||||||
// private List<Object[]> widgetBars;
|
private Map<String, Object> widgetBars;
|
||||||
|
|
||||||
|
Page<UserActionEntity> userActionWidgetList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,4 +23,8 @@ public class Widget1 {
|
|||||||
|
|
||||||
private BigDecimal totalActiveFinancing;
|
private BigDecimal totalActiveFinancing;
|
||||||
|
|
||||||
|
private BigDecimal amountRequested;
|
||||||
|
|
||||||
|
private BigDecimal amountAccepted;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Query;
|
|||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -24,7 +25,6 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,
|
|||||||
|
|
||||||
public Optional<ApplicationEntity> findByIdAndUserIdAndIsDeletedFalse(Long id,Long userId);
|
public Optional<ApplicationEntity> findByIdAndUserIdAndIsDeletedFalse(Long id,Long userId);
|
||||||
|
|
||||||
Optional<ApplicationEntity> findByUserIdAndUserWithCompanyIdAndCallIdAndIsDeletedFalse(Long userId, Long userWithCompanyId, Long callId);
|
|
||||||
|
|
||||||
public Optional<ApplicationEntity> findByIdAndUserIdAndCallIdAndIsDeletedFalse(Long applicationId, Long userId,
|
public Optional<ApplicationEntity> findByIdAndUserIdAndCallIdAndIsDeletedFalse(Long applicationId, Long userId,
|
||||||
Long callId);
|
Long callId);
|
||||||
@@ -44,4 +44,15 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,
|
|||||||
|
|
||||||
@Query("SELECT a.call.id FROM ApplicationEntity a WHERE a.id = :id AND a.isDeleted = false")
|
@Query("SELECT a.call.id FROM ApplicationEntity a WHERE a.id = :id AND a.isDeleted = false")
|
||||||
Long findCallIdById(@Param("id") Long id);
|
Long findCallIdById(@Param("id") Long id);
|
||||||
|
|
||||||
|
@Query("SELECT a.call.name, COUNT(a.id) FROM ApplicationEntity a WHERE a.isDeleted = false AND a.call.hub.id = :hubId GROUP BY a.call.name")
|
||||||
|
List<Object[]> findApplicationsPerCallWithName(@Param("hubId") Long hubId);
|
||||||
|
|
||||||
|
// Count Applications by Status by Hub ID
|
||||||
|
@Query("SELECT a.status, COUNT(a.id) FROM ApplicationEntity a WHERE a.isDeleted = false AND a.call.hub.id = :hubId GROUP BY a.status")
|
||||||
|
List<Object[]> findApplicationsByStatus(@Param("hubId") Long hubId);
|
||||||
|
|
||||||
|
// Total Amount of Approved Applications by Hub ID
|
||||||
|
@Query("SELECT SUM(a.call.amount) FROM ApplicationEntity a WHERE a.status = 'APPROVED' AND a.isDeleted = false AND a.call.hub.id = :hubId")
|
||||||
|
BigDecimal findTotalApprovedApplicationAmount(@Param("hubId") Long hubId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,4 +47,9 @@ public interface CallRepository extends JpaRepository<CallEntity, Long> {
|
|||||||
BigDecimal findTotalAmountOfPublishedCallsAndHubId(@Param("hubId") Long hubId);
|
BigDecimal findTotalAmountOfPublishedCallsAndHubId(@Param("hubId") Long hubId);
|
||||||
@Query("SELECT c FROM CallEntity c WHERE c.id IN :ids AND c.status IN :status")
|
@Query("SELECT c FROM CallEntity c WHERE c.id IN :ids AND c.status IN :status")
|
||||||
List<CallEntity> findByIdInAndStatusIn(@Param("ids") List<Long> ids, @Param("status") List<String> status);
|
List<CallEntity> findByIdInAndStatusIn(@Param("ids") List<Long> ids, @Param("status") List<String> status);
|
||||||
|
|
||||||
|
@Query("SELECT SUM(c.amount) FROM CallEntity c WHERE c.hub.id = :hubId AND c.status = 'PUBLISH'")
|
||||||
|
BigDecimal findTotalAmountOfPublishedCalls(@Param("hubId") Long hubId);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,38 @@
|
|||||||
package net.gepafin.tendermanagement.repositories;
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.entities.UserActionEntity;
|
import net.gepafin.tendermanagement.entities.UserActionEntity;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface UserActionsRepository extends JpaRepository<UserActionEntity, Long> {
|
public interface UserActionsRepository extends JpaRepository<UserActionEntity, Long> {
|
||||||
UserActionEntity findUserActionById(Long id);
|
UserActionEntity findUserActionById(Long id);
|
||||||
|
|
||||||
|
//
|
||||||
|
// @Query("SELECT ua FROM UserActionEntity ua " +
|
||||||
|
// "JOIN ua.user u " +
|
||||||
|
// "WHERE u.roleEntity.roleType IN :roleNames " +
|
||||||
|
// "AND ua.hub.id = :hubId " +
|
||||||
|
// "AND ua.isDeleted = false")
|
||||||
|
// Page<UserActionEntity> findActionsByRoleNamesAndHubId(
|
||||||
|
// @Param("roleNames") List<String> roleNames,
|
||||||
|
// @Param("hubId") Long hubId, Pageable pageable);
|
||||||
|
|
||||||
|
@Query("SELECT ua FROM UserActionEntity ua " +
|
||||||
|
"JOIN UserEntity u ON ua.userId = u.id " + // Join on userId field
|
||||||
|
"JOIN u.roleEntity r " + // Join the RoleEntity via the UserEntity
|
||||||
|
"WHERE r.roleType IN :roleNames " + // Filter by role name
|
||||||
|
"AND ua.hubId = :hubId " + // Filter by hubId
|
||||||
|
"AND ua.isDeleted = false")
|
||||||
|
Page<UserActionEntity> findActionsByRoleNamesAndHubId(
|
||||||
|
@Param("roleNames") List<String> roleNames,
|
||||||
|
@Param("hubId") Long hubId,
|
||||||
|
Pageable pageable);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2065,4 +2065,12 @@
|
|||||||
</insert>
|
</insert>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="08-01-2025_NK_075410" author="Nisha kashyap">
|
||||||
|
<addColumn tableName="application">
|
||||||
|
<column name="amountRequested" type="numeric"></column>
|
||||||
|
<column name="amountAccepted" type="numeric"></column>
|
||||||
|
<column name="dateAccepted" type="TIMESTAMP WITHOUT TIME ZONE"></column>
|
||||||
|
<column name="dateRejected" type="TIMESTAMP WITHOUT TIME ZONE"></column>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
|||||||
Reference in New Issue
Block a user