Untitled

mail@pastecode.io avatar
unknown
plain_text
13 days ago
1.4 kB
1
Indexable
Never
package com.capgemini.wsb.fitnesstracker.notification;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;

@Component
@RequiredArgsConstructor
@EnableScheduling
public class TrainingRaportGenerator {
    private final TrainingProvider trainingProvider;
    @Scheduled(cron = "0 0 0 * * 0")
    public void generateRaport() {
        List<Training> trainings = trainingProvider.getTrainings();
        HashMap<String, Integer> trainingCount = new HashMap<>();
        for (Training training : trainings) {
            String trainer = training.getTrainer();
            if (trainingCount.containsKey(trainer)) {
                trainingCount.put(trainer, trainingCount.get(trainer) + 1);
            } else {
                trainingCount.put(trainer, 1);
            }
        }
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("Witaj " + user.getFirstName() + " " + user.getLastName() + "!\n");
            stringBuilder.append("Wykonałeś " + count + " treningów" + "\n");
        stringBuilder();
    }
        emailSender.sendEmail("Tygodniowy raport treningów", raport.toString());
    }
}
Leave a Comment