|
|
|
|
@@ -63,6 +63,7 @@ import java.math.BigDecimal;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
|
|
import java.text.MessageFormat;
|
|
|
|
|
import java.text.NumberFormat;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
@@ -218,6 +219,9 @@ public class ApplicationDao {
|
|
|
|
|
@Autowired
|
|
|
|
|
private EvaluationCriteriaRepository evaluationCriteriaRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CallRepository callRepository;
|
|
|
|
|
|
|
|
|
|
public final Random random = new Random();
|
|
|
|
|
|
|
|
|
|
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) {
|
|
|
|
|
@@ -594,11 +598,9 @@ public class ApplicationDao {
|
|
|
|
|
String fieldType = content.getName();
|
|
|
|
|
|
|
|
|
|
// Define handlers for different (fieldType + settingName) combinations
|
|
|
|
|
Map<String, Runnable> handlers = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
// Add handler for isRequestedAmount
|
|
|
|
|
if ("numberinput".equals(fieldType) && Boolean.TRUE.equals(settingMap.get("isRequestedAmount"))) {
|
|
|
|
|
handlers.put("isRequestedAmount", () -> {
|
|
|
|
|
try {
|
|
|
|
|
BigDecimal amountRequested = new BigDecimal(fieldValue.toString());
|
|
|
|
|
applicationFormEntity.getApplication().setAmountRequested(amountRequested);
|
|
|
|
|
@@ -607,19 +609,20 @@ public class ApplicationDao {
|
|
|
|
|
log.error("Invalid number format for requested amount: {}", fieldValue, e);
|
|
|
|
|
throw new IllegalArgumentException("Field value is not a valid number: " + fieldValue, e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add handler for isPecEmail
|
|
|
|
|
if ("textinput".equals(fieldType) && Boolean.TRUE.equals(settingMap.get("isPecEmail"))) {
|
|
|
|
|
handlers.put("isPecEmail", () -> {
|
|
|
|
|
applicationFormEntity.getApplication().setPecEmail(fieldValue.toString());
|
|
|
|
|
log.info("Set PEC to {} for Application ID: {}", fieldValue, applicationFormEntity.getApplication().getId());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("textinput".equals(fieldType) && Boolean.TRUE.equals(settingMap.get("isPIVA"))) {
|
|
|
|
|
applicationFormEntity.getApplication().setVatNumber(fieldValue.toString());
|
|
|
|
|
log.info("Set PEC to {} for Application ID: {}", fieldValue, applicationFormEntity.getApplication().getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run all applicable handlers
|
|
|
|
|
handlers.values().forEach(Runnable::run);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -2422,8 +2425,9 @@ public class ApplicationDao {
|
|
|
|
|
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(GepafinConstant.RINALDO_EMAIL),emailLogRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte[] downloadRankingCsv(Long callId) {
|
|
|
|
|
CallEntity callEntity = callService.validateCall(callId);
|
|
|
|
|
public byte[] downloadRankingCsv(Long callId,UserEntity userEntity) {
|
|
|
|
|
|
|
|
|
|
CallEntity callEntity = validator.validateUserWithCall(userEntity,callId);
|
|
|
|
|
|
|
|
|
|
List<ApplicationEntity> applications =
|
|
|
|
|
applicationRepository.findByCallIdAndIsDeletedFalseAndStatusIn(
|
|
|
|
|
@@ -2435,10 +2439,11 @@ public class ApplicationDao {
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
List<String> dynamicLabels = new ArrayList<>(); // Maintain insertion order, allow duplicates only once
|
|
|
|
|
Map<Long, Map<String, BigDecimal>> appLabelScoresMap = new HashMap<>();
|
|
|
|
|
Map<Long, Map<String, String>> appLabelScoresMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
Map<Long, ApplicationEntity> applicationMap = new HashMap<>();
|
|
|
|
|
Map<Long, BigDecimal> appTotalScoreMap = new HashMap<>();
|
|
|
|
|
Map<Long, String> appTotalScoreMap = new HashMap<>();
|
|
|
|
|
Map<Long, String> appInstructorMap = new HashMap<>(); // New map to store instructor name per app
|
|
|
|
|
|
|
|
|
|
for (ApplicationEntity app : applications) {
|
|
|
|
|
Long appId = app.getId();
|
|
|
|
|
@@ -2447,8 +2452,19 @@ public class ApplicationDao {
|
|
|
|
|
ApplicationEvaluationEntity evaluation =
|
|
|
|
|
applicationEvaluationRepository.findByApplicationId(appId);
|
|
|
|
|
|
|
|
|
|
if (evaluation != null && evaluation.getAssignedApplicationsEntity() != null) {
|
|
|
|
|
Long userId = evaluation.getAssignedApplicationsEntity().getUserId();
|
|
|
|
|
if (userId != null) {
|
|
|
|
|
userRepository.findById(userId).ifPresent(user -> {
|
|
|
|
|
String firstName = user.getFirstName() != null ? user.getFirstName() : "";
|
|
|
|
|
String lastName = user.getLastName() != null ? user.getLastName() : "";
|
|
|
|
|
appInstructorMap.put(appId, firstName + " " + lastName);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BigDecimal totalScore = applicationEvaluationDao.calculateTotalScore(evaluation.getCriteria());
|
|
|
|
|
appTotalScoreMap.put(appId, totalScore);
|
|
|
|
|
appTotalScoreMap.put(appId, Utils.convertToItalianFormatWithOnlyDecimalValue(String.valueOf(totalScore)));
|
|
|
|
|
|
|
|
|
|
List<CriteriaResponse> criteriaList =
|
|
|
|
|
evaluation.getCriteria() != null ?
|
|
|
|
|
@@ -2457,7 +2473,7 @@ public class ApplicationDao {
|
|
|
|
|
|
|
|
|
|
List<CriteriaResponse> dbCriteriaList = applicationEvaluationDao.getCriteriaResponse(appId);
|
|
|
|
|
|
|
|
|
|
Map<String, BigDecimal> scoreByLabel = new HashMap<>();
|
|
|
|
|
Map<String, String> scoreByLabel = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
for (CriteriaResponse criteria : criteriaList) {
|
|
|
|
|
Optional<CriteriaResponse> matchedDb = dbCriteriaList.stream()
|
|
|
|
|
@@ -2469,8 +2485,9 @@ public class ApplicationDao {
|
|
|
|
|
if (!dynamicLabels.contains(label)) {
|
|
|
|
|
dynamicLabels.add(label);
|
|
|
|
|
}
|
|
|
|
|
String criteriaScore= String.valueOf(criteria.getScore() != null ? criteria.getScore() : BigDecimal.ZERO);
|
|
|
|
|
|
|
|
|
|
scoreByLabel.put(label, criteria.getScore() != null ? criteria.getScore() : BigDecimal.ZERO);
|
|
|
|
|
scoreByLabel.put(label, Utils.convertToItalianFormatWithOnlyDecimalValue(criteriaScore));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
appLabelScoresMap.put(appId, scoreByLabel);
|
|
|
|
|
@@ -2478,7 +2495,7 @@ public class ApplicationDao {
|
|
|
|
|
|
|
|
|
|
// Build headers dynamically
|
|
|
|
|
List<String> headers = new ArrayList<>(List.of(
|
|
|
|
|
"ApplicationID", "VatNumber", "Company Name", "Protocol", "Requested Amount", "Status", "Total Score"
|
|
|
|
|
"ApplicationID","Application VatNumber", "VatNumber", "Company Name", "Protocol", "Requested Amount", "Status","Instructor Name","Application PEC","Company PEC","Total Score"
|
|
|
|
|
));
|
|
|
|
|
headers.addAll(dynamicLabels);
|
|
|
|
|
|
|
|
|
|
@@ -2492,17 +2509,22 @@ public class ApplicationDao {
|
|
|
|
|
|
|
|
|
|
List<Object> row = new ArrayList<>();
|
|
|
|
|
row.add(appId);
|
|
|
|
|
row.add(app.getVatNumber());
|
|
|
|
|
row.add(company.getVatNumber());
|
|
|
|
|
row.add(company.getCompanyName());
|
|
|
|
|
row.add(protocolEntity != null ? protocolEntity.getProtocolNumber() : 0L);
|
|
|
|
|
row.add(app.getAmountRequested());
|
|
|
|
|
String formattedAmount=Utils.convertToItalianFormatWithOnlyDecimalValue(String.valueOf(app.getAmountRequested()));
|
|
|
|
|
row.add(formattedAmount);
|
|
|
|
|
row.add(app.getStatus());
|
|
|
|
|
row.add(appInstructorMap.getOrDefault(appId, ""));
|
|
|
|
|
row.add(app.getPecEmail());
|
|
|
|
|
row.add(company.getPec());
|
|
|
|
|
row.add(appTotalScoreMap.get(appId));
|
|
|
|
|
|
|
|
|
|
Map<String, BigDecimal> scores = appLabelScoresMap.getOrDefault(appId, Collections.emptyMap());
|
|
|
|
|
Map<String, String> scores = appLabelScoresMap.getOrDefault(appId, Collections.emptyMap());
|
|
|
|
|
|
|
|
|
|
for (String label : dynamicLabels) {
|
|
|
|
|
row.add(scores.getOrDefault(label, BigDecimal.ZERO));
|
|
|
|
|
row.add(scores.getOrDefault(label, ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rows.add(row);
|
|
|
|
|
@@ -2512,7 +2534,9 @@ public class ApplicationDao {
|
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
|
|
try (OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
|
|
|
|
|
CSVPrinter csvPrinter = new CSVPrinter(writer,
|
|
|
|
|
CSVFormat.DEFAULT.withHeader(headers.toArray(new String[0])))) {
|
|
|
|
|
CSVFormat.DEFAULT
|
|
|
|
|
.withDelimiter(';')
|
|
|
|
|
.withHeader(headers.toArray(new String[0])))) {
|
|
|
|
|
|
|
|
|
|
for (List<Object> row : rows) {
|
|
|
|
|
csvPrinter.printRecord(row);
|
|
|
|
|
|