Done ticket GEPFINBE-94

This commit is contained in:
rajesh
2024-11-18 18:55:05 +05:30
parent 8a6cd213b1
commit b591fb1b79
8 changed files with 107 additions and 62 deletions

View File

@@ -7,14 +7,12 @@ import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.entities.*;
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
import net.gepafin.tendermanagement.model.response.*;
@@ -22,6 +20,7 @@ import net.gepafin.tendermanagement.repositories.*;
import net.gepafin.tendermanagement.service.*;
import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.util.Validator;
import org.h2.util.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -93,6 +92,8 @@ public class CallDao {
private S3PathConfig s3PathConfig;
@Autowired
private BeneficiaryPreferredCallRepository beneficiaryPreferredCallRepository;
@Autowired
private Validator validator;
public CallResponse createCallStep1(CreateCallRequestStep1 createCallRequest, UserEntity userEntity) {
@@ -425,15 +426,24 @@ public class CallDao {
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
}
public CallResponse getCallById(UserEntity user, CallEntity callEntity) {
public CallResponse getCallById(HttpServletRequest request,UserEntity user, CallEntity callEntity, Long companyId) {
Long userId = user.getId();
Long callId = callEntity.getId();
BeneficiaryPreferredCallEntity preferredCall = beneficiaryPreferredCallRepository
.findByUserIdAndCallIdInAndIsDeletedFalse(userId, List.of(callId))
.stream()
.findFirst()
.orElse(null);
BeneficiaryPreferredCallEntity preferredCall;
if (companyId != null) {
validator.validateUserWithCompany(request, companyId);
preferredCall = beneficiaryPreferredCallRepository
.findByUserIdAndCallIdAndCompanyIdAndIsDeletedFalse(userId, callId, companyId)
.orElse(null);
} else {
preferredCall = beneficiaryPreferredCallRepository
.findByUserIdAndCallIdInAndIsDeletedFalse(userId, List.of(callId))
.stream()
.findFirst()
.orElse(null);
}
CallResponse callResponse = getCallResponseBean(callEntity);
callResponse.setPreferredCallId(preferredCall != null ? preferredCall.getId() : null);
@@ -646,24 +656,21 @@ public class CallDao {
return createCallResponseBean;
}
public List<CallDetailsResponseBean> getAllCalls(UserEntity user) {
public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,UserEntity user, Long companyId) {
String type = user.getRoleEntity().getRoleType();
List<String> callStatusList = CallStatusEnum.getStatusValues();
if (Boolean.FALSE.equals(ROLE_SUPER_ADMIN.getValue().equals(type))) {
callStatusList = List.of(CallStatusEnum.PUBLISH.getValue());
}
List<CallEntity> calls = callRepository.findByStatusInAndHubId(callStatusList, user.getHub().getId());
List<Long> callIds = calls.stream().map(CallEntity::getId).collect(Collectors.toList());
Map<String, BeneficiaryPreferredCallEntity> preferredCallsMap = getBeneficiaryPreferredCallsForUser(user, callIds);
Map<String, BeneficiaryPreferredCallEntity> preferredCallsMap =
getBeneficiaryPreferredCallsForUser(request,user, callIds, companyId);
return calls.stream()
.map(call -> {
CallDetailsResponseBean responseBean = convertToCallDetailsResponseBean(call);
String key = user.getId() + "_" + call.getId();
BeneficiaryPreferredCallEntity preferredCall = preferredCallsMap.get(key);
Long preferredId = (preferredCall != null && !preferredCall.getIsDeleted()) ? preferredCall.getId() : null;
responseBean.setPreferredCallId(preferredId);
@@ -673,9 +680,27 @@ public class CallDao {
.collect(Collectors.toList());
}
public Map<String, BeneficiaryPreferredCallEntity> getBeneficiaryPreferredCallsForUser(UserEntity user, List<Long> callIds) {
List<BeneficiaryPreferredCallEntity> beneficiaryPreferredCalls = beneficiaryPreferredCallRepository
.findByUserIdAndCallIdInAndIsDeletedFalse(user.getId(), callIds);
public Map<String, BeneficiaryPreferredCallEntity> getBeneficiaryPreferredCallsForUser(HttpServletRequest request, UserEntity user, List<Long> callIds, Long companyId) {
List<BeneficiaryPreferredCallEntity> beneficiaryPreferredCalls;
if (companyId != null) {
validator.validateUserWithCompany(request, companyId);
beneficiaryPreferredCalls = beneficiaryPreferredCallRepository
.findByUserIdAndCallIdInAndCompanyIdAndIsDeletedFalse(user.getId(), callIds, companyId);
} else {
beneficiaryPreferredCalls = beneficiaryPreferredCallRepository
.findByUserIdAndCallIdInAndIsDeletedFalse(user.getId(), callIds);
beneficiaryPreferredCalls = beneficiaryPreferredCalls.stream()
.collect(Collectors.collectingAndThen(
Collectors.toMap(
BeneficiaryPreferredCallEntity::getCallId,
call -> call,
(existing, replacement) -> existing
),
map -> new ArrayList<>(map.values())
));
}
return beneficiaryPreferredCalls.stream()
.collect(Collectors.toMap(