Bugfix: takes property set into account when collecting comparable reports.
This commit is contained in:
parent
67fc5607e3
commit
0c88c5ed0f
4 changed files with 40 additions and 40 deletions
|
|
@ -73,12 +73,12 @@ public class CalculationJobRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Optional<CalculationJob> getCalculationJobWithJobStateValid(Integer periodId, Integer nodeId, Integer materialId) {
|
public Optional<CalculationJob> getCalculationJobWithJobStateValid(Integer periodId, Integer setId, Integer nodeId, Integer materialId) {
|
||||||
|
|
||||||
/* there should only be one job per period id, node id and material id combination */
|
/* there should only be one job per period id, node id and material id combination */
|
||||||
String query = "SELECT * FROM calculation_job AS cj INNER JOIN premise AS p ON cj.premise_id = p.id WHERE job_state = 'VALID' AND validity_period_id = ? AND p.supplier_node_id = ? AND material_id = ? ORDER BY cj.calculation_date DESC LIMIT 1";
|
String query = "SELECT * FROM calculation_job AS cj INNER JOIN premise AS p ON cj.premise_id = p.id WHERE job_state = 'VALID' AND validity_period_id = ? AND property_set_id = ? AND p.supplier_node_id = ? AND material_id = ? ORDER BY cj.calculation_date DESC LIMIT 1";
|
||||||
|
|
||||||
var job = jdbcTemplate.query(query, new CalculationJobMapper(), periodId, nodeId, materialId);
|
var job = jdbcTemplate.query(query, new CalculationJobMapper(), periodId, setId, nodeId, materialId);
|
||||||
|
|
||||||
if(job.isEmpty())
|
if(job.isEmpty())
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
@ -87,12 +87,12 @@ public class CalculationJobRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Optional<CalculationJob> getCalculationJobWithJobStateValidUserNodeId(Integer periodId, Integer userNodeId, Integer materialId) {
|
public Optional<CalculationJob> getCalculationJobWithJobStateValidUserNodeId(Integer periodId, Integer setId, Integer userNodeId, Integer materialId) {
|
||||||
|
|
||||||
/* there should only be one job per period id, node id and material id combination */
|
/* there should only be one job per period id, node id and material id combination */
|
||||||
String query = "SELECT * FROM calculation_job AS cj INNER JOIN premise AS p ON cj.premise_id = p.id WHERE job_state = 'VALID' AND validity_period_id = ? AND p.user_supplier_node_id = ? AND material_id = ? ORDER BY cj.calculation_date DESC LIMIT 1";
|
String query = "SELECT * FROM calculation_job AS cj INNER JOIN premise AS p ON cj.premise_id = p.id WHERE job_state = 'VALID' AND validity_period_id = ? AND property_set_id = ? AND p.user_supplier_node_id = ? AND material_id = ? ORDER BY cj.calculation_date DESC LIMIT 1";
|
||||||
|
|
||||||
var job = jdbcTemplate.query(query, new CalculationJobMapper(), periodId, userNodeId, materialId);
|
var job = jdbcTemplate.query(query, new CalculationJobMapper(), periodId, setId, userNodeId, materialId);
|
||||||
|
|
||||||
if(job.isEmpty())
|
if(job.isEmpty())
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,7 @@ public class ValidityPeriodRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Optional<ValidityPeriod> getValidPeriodForReportingByMaterialId(Integer materialId, List<Integer> nodeIds, List<Integer> userNodeIds) {
|
public Optional<ValidityTuple> getValidPeriodForReportingByMaterialId(Integer materialId, List<Integer> nodeIds, List<Integer> userNodeIds) {
|
||||||
|
|
||||||
// Check if both lists are empty
|
// Check if both lists are empty
|
||||||
if ((nodeIds == null || nodeIds.isEmpty()) && (userNodeIds == null || userNodeIds.isEmpty())) {
|
if ((nodeIds == null || nodeIds.isEmpty()) && (userNodeIds == null || userNodeIds.isEmpty())) {
|
||||||
|
|
@ -257,30 +257,27 @@ public class ValidityPeriodRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
String validityPeriodSql = """
|
String validityPeriodSql = """
|
||||||
SELECT vp.*
|
SELECT
|
||||||
FROM validity_period vp
|
cj.validity_period_id,
|
||||||
INNER JOIN (
|
cj.property_set_id
|
||||||
SELECT
|
FROM
|
||||||
cj.validity_period_id,
|
premise p
|
||||||
COUNT(DISTINCT COALESCE(p.supplier_node_id, p.user_supplier_node_id)) as node_count
|
INNER JOIN
|
||||||
FROM
|
calculation_job cj ON p.id = cj.premise_id
|
||||||
premise p
|
WHERE
|
||||||
INNER JOIN
|
p.material_id = ?
|
||||||
calculation_job cj ON p.id = cj.premise_id
|
"""
|
||||||
WHERE
|
|
||||||
p.material_id = ?
|
|
||||||
"""
|
|
||||||
+ whereClause + """
|
+ whereClause + """
|
||||||
|
|
||||||
GROUP BY
|
GROUP BY
|
||||||
cj.validity_period_id
|
cj.validity_period_id,
|
||||||
HAVING
|
cj.property_set_id
|
||||||
COUNT(DISTINCT COALESCE(p.supplier_node_id, p.user_supplier_node_id)) = ?
|
HAVING
|
||||||
) matching_periods ON vp.id = matching_periods.validity_period_id
|
COUNT(DISTINCT COALESCE(p.supplier_node_id, p.user_supplier_node_id)) = ?
|
||||||
ORDER BY
|
ORDER BY
|
||||||
vp.start_date DESC
|
(SELECT start_date FROM validity_period WHERE id = cj.validity_period_id) DESC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
""";
|
""";
|
||||||
|
|
||||||
// Build parameters array
|
// Build parameters array
|
||||||
Object[] params = new Object[1 + totalNodeCount + 1];
|
Object[] params = new Object[1 + totalNodeCount + 1];
|
||||||
|
|
@ -299,13 +296,15 @@ public class ValidityPeriodRepository {
|
||||||
|
|
||||||
params[paramIndex] = totalNodeCount;
|
params[paramIndex] = totalNodeCount;
|
||||||
|
|
||||||
var periods = jdbcTemplate.query(validityPeriodSql, new ValidityPeriodMapper(), params);
|
var tuples = jdbcTemplate.query(validityPeriodSql,
|
||||||
|
(rs, cnt) -> new ValidityTuple(rs.getInt("validity_period_id"), rs.getInt("property_set_id")),
|
||||||
|
params);
|
||||||
|
|
||||||
if (periods.isEmpty()) {
|
if (tuples.isEmpty()) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.of(periods.getFirst());
|
return Optional.of(tuples.getFirst());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|
|
||||||
|
|
@ -93,9 +93,9 @@ public class RateApprovalService {
|
||||||
|
|
||||||
if (hasContainerDrafts || hasMatrixDrafts) {
|
if (hasContainerDrafts || hasMatrixDrafts) {
|
||||||
|
|
||||||
if(hasContainerDrafts && !hasMatrixDrafts)
|
if (hasContainerDrafts && !hasMatrixDrafts)
|
||||||
matrixRateRepository.copyCurrentToDraft();
|
matrixRateRepository.copyCurrentToDraft();
|
||||||
else if(!hasContainerDrafts && hasMatrixDrafts)
|
else if (!hasContainerDrafts && hasMatrixDrafts)
|
||||||
containerRateRepository.copyCurrentToDraft();
|
containerRateRepository.copyCurrentToDraft();
|
||||||
|
|
||||||
validityPeriodRepository.applyDraft();
|
validityPeriodRepository.applyDraft();
|
||||||
|
|
|
||||||
|
|
@ -50,15 +50,16 @@ public class ReportingService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ReportDTO> getReport(Integer materialId, List<Integer> nodeIds, List<Integer> userNodeIds) {
|
public List<ReportDTO> getReport(Integer materialId, List<Integer> nodeIds, List<Integer> userNodeIds) {
|
||||||
var period = validityPeriodRepository.getValidPeriodForReportingByMaterialId(materialId, nodeIds, userNodeIds);
|
var tuple = validityPeriodRepository.getValidPeriodForReportingByMaterialId(materialId, nodeIds, userNodeIds);
|
||||||
|
|
||||||
if (period.isEmpty())
|
if (tuple.isEmpty())
|
||||||
throw new IllegalArgumentException("No valid period found");
|
throw new IllegalArgumentException("No valid period found");
|
||||||
|
|
||||||
var periodId = period.get().getId();
|
var periodId = tuple.get().periodId();
|
||||||
|
var setId = tuple.get().propertySetId();
|
||||||
|
|
||||||
var jobs = new ArrayList<>(nodeIds.stream().map(nodeId -> calculationJobRepository.getCalculationJobWithJobStateValid(periodId, nodeId, materialId)).filter(Optional::isPresent).map(Optional::get).toList());
|
var jobs = new ArrayList<>(nodeIds.stream().map(nodeId -> calculationJobRepository.getCalculationJobWithJobStateValid(periodId, setId, nodeId, materialId)).filter(Optional::isPresent).map(Optional::get).toList());
|
||||||
jobs.addAll(userNodeIds.stream().map(nodeId -> calculationJobRepository.getCalculationJobWithJobStateValidUserNodeId(periodId,nodeId ,materialId)).filter(Optional::isPresent).map(Optional::get).toList());
|
jobs.addAll(userNodeIds.stream().map(nodeId -> calculationJobRepository.getCalculationJobWithJobStateValidUserNodeId(periodId, setId,nodeId ,materialId)).filter(Optional::isPresent).map(Optional::get).toList());
|
||||||
|
|
||||||
return jobs.stream().map(reportTransformer::toReportDTO).toList();
|
return jobs.stream().map(reportTransformer::toReportDTO).toList();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue