#112 ping activity
parent
a35bcfce1b
commit
e680aa30c4
@ -0,0 +1,35 @@
|
||||
package ru.ulstu.ping.model;
|
||||
|
||||
import ru.ulstu.user.model.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PingInfo {
|
||||
private User user;
|
||||
private List<Ping> pings = new ArrayList<>();
|
||||
|
||||
public PingInfo(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public List<Ping> getPings() {
|
||||
return pings;
|
||||
}
|
||||
|
||||
public void setPings(List<Ping> pings) {
|
||||
this.pings = pings;
|
||||
}
|
||||
|
||||
public void addPing(Ping ping) {
|
||||
this.pings.add(ping);
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package ru.ulstu.ping.service;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.core.model.UserActivity;
|
||||
import ru.ulstu.ping.model.Ping;
|
||||
import ru.ulstu.ping.model.PingInfo;
|
||||
import ru.ulstu.ping.repository.PingRepository;
|
||||
import ru.ulstu.user.model.User;
|
||||
import ru.ulstu.user.service.MailService;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
public class PingScheduler {
|
||||
private final Logger log = LoggerFactory.getLogger(PingScheduler.class);
|
||||
private final PingRepository pingRepository;
|
||||
private final MailService mailService;
|
||||
private final static String PING_MAIL_SUBJECT = "Ping статистика";
|
||||
|
||||
public PingScheduler(PingRepository pingRepository, MailService mailService) {
|
||||
this.pingRepository = pingRepository;
|
||||
this.mailService = mailService;
|
||||
}
|
||||
|
||||
|
||||
@Scheduled(cron = "0 0 * * 1 ?")
|
||||
public void sendPingsInfo() {
|
||||
log.debug("Scheduler.sendPingsInfo started");
|
||||
|
||||
List<PingInfo> pingInfos = new ArrayList<>();
|
||||
|
||||
for (Ping ping : pingRepository.findByDate(java.sql.Date.valueOf(LocalDate.now().minusWeeks(1)))) {
|
||||
UserActivity pingActivity = ping.getActivity();
|
||||
Set<User> users = pingActivity.getActivityUsers();
|
||||
|
||||
for (User user : users) {
|
||||
PingInfo userPing = pingInfos.stream().filter(u -> u.getUser() == user).findFirst().orElse(null);
|
||||
if (userPing == null) {
|
||||
userPing = new PingInfo(user);
|
||||
pingInfos.add(userPing);
|
||||
}
|
||||
userPing.addPing(ping);
|
||||
}
|
||||
}
|
||||
|
||||
for (PingInfo pingInfo : pingInfos) {
|
||||
mailService.sendEmailFromTemplate(ImmutableMap.of("pings", pingInfo.getPings()),
|
||||
pingInfo.getUser(), "pingsInfoWeekEmail", PING_MAIL_SUBJECT);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
package ru.ulstu.user.model;
|
||||
|
||||
import ru.ulstu.ping.model.Ping;
|
||||
|
||||
public class DiagramElement {
|
||||
private User user;
|
||||
private int conferences = 0;
|
||||
private int projects = 0;
|
||||
private int grants = 0;
|
||||
private int papers = 0;
|
||||
|
||||
public DiagramElement() {
|
||||
}
|
||||
|
||||
public DiagramElement(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public int getConferences() {
|
||||
return conferences;
|
||||
}
|
||||
|
||||
public void setConferences(int conferences) {
|
||||
this.conferences = conferences;
|
||||
}
|
||||
|
||||
public int getProjects() {
|
||||
return projects;
|
||||
}
|
||||
|
||||
public void setProjects(int projects) {
|
||||
this.projects = projects;
|
||||
}
|
||||
|
||||
public int getGrants() {
|
||||
return grants;
|
||||
}
|
||||
|
||||
public void setGrants(int grants) {
|
||||
this.grants = grants;
|
||||
}
|
||||
|
||||
public int getPapers() {
|
||||
return papers;
|
||||
}
|
||||
|
||||
public void setPapers(int papers) {
|
||||
this.papers = papers;
|
||||
}
|
||||
|
||||
public void incrementPapers(int value) {
|
||||
this.papers ++;
|
||||
}
|
||||
|
||||
public void incrementProjects(int value) {
|
||||
this.projects ++;
|
||||
}
|
||||
|
||||
public void incrementConferences(int value) {
|
||||
this.conferences ++;
|
||||
}
|
||||
|
||||
public void incrementGrants(int value) {
|
||||
this.grants ++;
|
||||
}
|
||||
|
||||
public void incrementActivity(Ping ping) {
|
||||
if (ping.getConference() != null) {
|
||||
this.conferences ++;
|
||||
} else if(ping.getPaper() != null) {
|
||||
this.papers ++;
|
||||
} else if(ping.getProject() != null) {
|
||||
this.projects ++;
|
||||
} else if(ping.getGrant() != null) {
|
||||
this.grants ++;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue