Done ticket GEPAFINBE-104

This commit is contained in:
rajesh
2024-11-26 19:23:12 +05:30
parent e9ce58a96e
commit 6d2374c3e6
24 changed files with 240 additions and 115 deletions

View File

@@ -5,10 +5,14 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import net.gepafin.tendermanagement.entities.*;
import net.gepafin.tendermanagement.enums.DocOtherSourceTypeEnum;
import net.gepafin.tendermanagement.repositories.UserWithCompanyRepository;
import net.gepafin.tendermanagement.service.CompanyService;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.factory.annotation.Autowired;
@@ -18,10 +22,6 @@ import org.springframework.web.multipart.MultipartFile;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.CompanyEntity;
import net.gepafin.tendermanagement.entities.DocumentEntity;
import net.gepafin.tendermanagement.entities.UserCompanyDelegationEntity;
import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.enums.UserCompanyDelegationStatusEnum;
import net.gepafin.tendermanagement.model.request.CompanyDelegationRequest;
import net.gepafin.tendermanagement.model.response.CompanyDelegationResponse;
@@ -67,6 +67,12 @@ public class DelegationDao {
@Autowired
private Validator validator;
@Autowired
private UserWithCompanyRepository userWithCompanyRepository;
@Autowired
private CompanyService companyService;
public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) {
try {
String s3Folder = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.TEMPLATE, 0L, 0L);
@@ -182,8 +188,9 @@ public class DelegationDao {
companyDao.validateCompany(companyId);
companyDao.getUserWithCompany(userEntity.getId(), companyId);
validateFileType(file);
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),companyId);
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
.findByUserIdAndUserWithCompanyIdAndStatus(userEntity.getId(), userWithCompanyEntity.getId(),
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
if (userCompanyDelegationEntity != null) {
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
@@ -191,7 +198,8 @@ public class DelegationDao {
}
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = uploadFileOnAmazonS3ForCompanyDelegation(file);
userCompanyDelegationEntity = new UserCompanyDelegationEntity();
userCompanyDelegationEntity.setCompanyId(companyId);
userCompanyDelegationEntity.setUserWithCompany(userWithCompanyEntity);
userCompanyDelegationEntity.setCompanyId(userWithCompanyEntity.getCompanyId());
userCompanyDelegationEntity.setUserId(userEntity.getId());
if (userEntity.getBeneficiary() != null) {
userCompanyDelegationEntity.setBeneficiaryId(userEntity.getBeneficiary().getId());
@@ -235,8 +243,9 @@ public class DelegationDao {
}
public CompanyDelegationResponse getCompanyDelegation(UserEntity userEntity, Long companyId) {
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),companyId);
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
.findByUserIdAndUserWithCompanyIdAndStatus(userEntity.getId(), userWithCompanyEntity.getId(),
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
companyDao.getUserWithCompany(userEntity.getId(), companyId);
if(userCompanyDelegationEntity == null) {
@@ -247,8 +256,9 @@ public class DelegationDao {
}
public void deleteCompanyDelegation(UserEntity userEntity, Long companyId) {
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),companyId);
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
.findByUserIdAndUserWithCompanyIdAndStatus(userEntity.getId(), userWithCompanyEntity.getId(),
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
companyDao.getUserWithCompany(userEntity.getId(), companyId);
if(userCompanyDelegationEntity == null) {