This commit is contained in:
Tim
2025-06-17 08:37:47 +02:00
parent 3a07af2d78
commit e0ef5d25a6
4 changed files with 16 additions and 3 deletions

View File

@@ -23,6 +23,8 @@ public interface ArticleService {
Article save(Article article);
Article update(Article article);
double getRating(Long id);
double getRating(UUID uuid);

View File

@@ -69,6 +69,12 @@ public class ArticleServiceImpl implements ArticleService {
return articleRepository.save(article);
}
@Override
@Transactional
public Article update(Article article) {
return articleRepository.save(article);
}
@Override
public double getRating(Long id) {
return reviewRepository.streamReviewsByArticleId(id)

View File

@@ -12,10 +12,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import java.util.function.BinaryOperator;
import java.util.function.Function;
@@ -84,7 +82,14 @@ public class StatisticsServiceImpl implements StatisticsService {
articleService.findAll().forEach(article -> {
int percent = (int) Math.floor(((1.0d * article.getStock() / article.getStockExpected()) * 100) / 10) * 10;
log.info("Stock percent: {} {}", article.getUuid(), percent);
log.info("Cat: {}", article.getCategory());
for (ArticleCategory value : ArticleCategory.values()) {
if (article.getCategory().equalsIgnoreCase(value.loc)) {
log.info("Fixing Article Category {} to {}", article.getCategory(), value.loc);
article.setCategory(value.loc);
articleService.update(article);
break;
}
}
map.get(article.getCategory()).putIfAbsent(percent, 0);
map.get(article.getCategory()).computeIfPresent(percent, (k,v) -> ++v);
});