Done task GEPAFINBE-6311 Implemented upload application company document flow
This commit is contained in:
@@ -36,6 +36,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -423,15 +424,40 @@ public class NotificationDao {
|
||||
}
|
||||
|
||||
public void sendNotificationToBeneficiaryForDocumentExpiration(CompanyDocumentEntity companyDocumentEntity, NotificationTypeEnum notificationTypeEnum) {
|
||||
|
||||
CompanyEntity companyEntity = companyService.validateCompany(companyDocumentEntity.getCompanyId());
|
||||
Long companyId = companyDocumentEntity.getCompanyId();
|
||||
if (companyId == null) {
|
||||
log.warn("Skipping document expiration notification: companyId is null for document id {}", companyDocumentEntity.getId());
|
||||
return;
|
||||
}
|
||||
CompanyEntity companyEntity = companyService.validateCompany(companyId);
|
||||
List<UserWithCompanyEntity> linkedUsers = userWithCompanyRepository.findByCompanyIdAndIsDeletedFalse(companyId);
|
||||
if (linkedUsers == null || linkedUsers.isEmpty()) {
|
||||
log.warn("Skipping document expiration notification: no users linked to company {} for document id {}", companyId, companyDocumentEntity.getId());
|
||||
return;
|
||||
}
|
||||
Map<String, String> placeHolders = new HashMap<>();
|
||||
placeHolders.put("{{file_name}}", companyDocumentEntity.getFileName());
|
||||
placeHolders.put("{{company_name}}", companyEntity.getCompanyName());
|
||||
placeHolders.put("{{expiration_date}}", companyDocumentEntity.getExpirationDate().toString());
|
||||
NotificationReq notificationReq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, companyDocumentEntity.getUserWithCompany().getUserId(), companyDocumentEntity.getUserWithCompany(),
|
||||
listOf(companyDocumentEntity.getCompanyId()));
|
||||
sendNotification(notificationReq);
|
||||
Map<Long, UserWithCompanyEntity> oneRowPerUser = new LinkedHashMap<>();
|
||||
for (UserWithCompanyEntity uwc : linkedUsers) {
|
||||
if (uwc.getUserId() != null) {
|
||||
oneRowPerUser.putIfAbsent(uwc.getUserId(), uwc);
|
||||
}
|
||||
}
|
||||
if (oneRowPerUser.isEmpty()) {
|
||||
log.warn("Skipping document expiration notification: no user ids on USER_WITH_COMPANY for company {}, document id {}", companyId, companyDocumentEntity.getId());
|
||||
return;
|
||||
}
|
||||
for (UserWithCompanyEntity uwc : oneRowPerUser.values()) {
|
||||
NotificationReq notificationReq = createNotificationReq(
|
||||
notificationTypeEnum.getValue(),
|
||||
placeHolders,
|
||||
uwc.getUserId(),
|
||||
uwc,
|
||||
listOf(companyId));
|
||||
sendNotification(notificationReq);
|
||||
}
|
||||
}
|
||||
|
||||
public PageableResponseBean<List<NotificationResponse>> getNotificationsByUserIdAndCompanyIdByPagination(Long userId, Long companyId, NotificationRequestBean notificationRequestBean) {
|
||||
|
||||
Reference in New Issue
Block a user