#93 users activities analytycs

This commit is contained in:
Artem.Arefev 2019-06-11 01:18:49 +04:00
parent 015a1d7fb8
commit cbae48c23e
16 changed files with 159 additions and 72 deletions

View File

@ -0,0 +1,17 @@
package ru.ulstu.activity.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import ru.ulstu.activity.service.ActivityService;
@Controller()
@RequestMapping(value = "/activities")
public class ActivityController {
private ActivityService activityService;
public ActivityController(ActivityService activityService) {
this.activityService = activityService;
}
}

View File

@ -1,7 +1,8 @@
package ru.ulstu.user.model; package ru.ulstu.activity.model;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.user.model.User;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;

View File

@ -1,8 +1,8 @@
package ru.ulstu.user.model; package ru.ulstu.activity.model;
public class ActivityElement { public class ActivityElement {
private int startedCount; private int startedCount = 0;
private int completedCount; private int completedCount = 0;
public ActivityElement() {} public ActivityElement() {}

View File

@ -1,9 +1,9 @@
package ru.ulstu.user.repository; package ru.ulstu.activity.repository;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import ru.ulstu.user.model.Activity; import ru.ulstu.activity.model.Activity;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;

View File

@ -0,0 +1,56 @@
package ru.ulstu.activity.service;
import org.springframework.stereotype.Service;
import ru.ulstu.activity.model.Activity;
import ru.ulstu.activity.model.ActivityElement;
import ru.ulstu.activity.repository.ActivityRepository;
import ru.ulstu.user.model.User;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ActivityService {
private ActivityRepository activityRepository;
public ActivityService(ActivityRepository activityRepository) {
this.activityRepository = activityRepository;
}
public void createActivity(List<User> users, Activity.ActivityState state) {
List<Activity> activities = new ArrayList<>();
for (User user : users) {
activities.add(new Activity(user, state));
}
activityRepository.save(activities);
}
public Map<String, ActivityElement> getUsersActivity(Integer userId, Date dateFrom, Date dateTo) {
List<Activity> activities = activityRepository.getByUserAndDateInterval(userId, dateFrom, dateTo);
Map<String, ActivityElement> dateActivities = new HashMap<>();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
for (Activity activity : activities) {
String dt = formatter.format(activity.getDate());
ActivityElement element;
if (!dateActivities.containsKey(dt)) {
element = new ActivityElement();
} else {
element = dateActivities.get(dt);
}
switch (activity.getActivityState()) {
case TOOK_IN_WORK:
element.incrementStartedCount();
break;
case COMPLETED:
element.incrementCompletedCount();
break;
}
dateActivities.put(dt, element);
}
return dateActivities;
}
}

View File

@ -14,7 +14,7 @@ public class AuthFailureHandler implements AuthenticationFailureHandler {
@Override @Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
AuthenticationException ex) throws IOException { AuthenticationException ex) throws IOException {
if (ex.getClass() == UserBlockedException.class) { if (ex.getCause() instanceof UserBlockedException) {
response.sendRedirect("/users/block"); response.sendRedirect("/users/block");
} }
} }

View File

@ -11,11 +11,11 @@ import ru.ulstu.file.model.FileData;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.project.model.Project; import ru.ulstu.project.model.Project;
import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.Event;
import ru.ulstu.activity.model.Activity;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue; import javax.persistence.DiscriminatorValue;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
@ -27,8 +27,6 @@ import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OrderBy; import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -176,6 +174,17 @@ public class Grant extends BaseEntity implements UserActivity, EventSource {
return getAuthors(); return getAuthors();
} }
public Activity.ActivityState getCommonActivityState() {
switch (this.status) {
case IN_WORK:
return Activity.ActivityState.TOOK_IN_WORK;
case COMPLETED:
return Activity.ActivityState.COMPLETED;
default:
return null;
}
}
public User getLeader() { public User getLeader() {
return leader; return leader;
} }

View File

@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.Errors; import org.springframework.validation.Errors;
import ru.ulstu.activity.service.ActivityService;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.model.FileDataDto;
@ -26,6 +27,7 @@ import ru.ulstu.user.service.UserService;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
@ -53,6 +55,7 @@ public class GrantService extends BaseService {
private final GrantNotificationService grantNotificationService; private final GrantNotificationService grantNotificationService;
private final KiasService kiasService; private final KiasService kiasService;
private final PingService pingService; private final PingService pingService;
private final ActivityService activityService;
public GrantService(GrantRepository grantRepository, public GrantService(GrantRepository grantRepository,
FileService fileService, FileService fileService,
@ -63,7 +66,8 @@ public class GrantService extends BaseService {
EventService eventService, EventService eventService,
GrantNotificationService grantNotificationService, GrantNotificationService grantNotificationService,
KiasService kiasService, KiasService kiasService,
PingService pingService) { PingService pingService,
ActivityService activityService) {
this.grantRepository = grantRepository; this.grantRepository = grantRepository;
this.kiasService = kiasService; this.kiasService = kiasService;
this.baseRepository = grantRepository; this.baseRepository = grantRepository;
@ -75,6 +79,7 @@ public class GrantService extends BaseService {
this.eventService = eventService; this.eventService = eventService;
this.grantNotificationService = grantNotificationService; this.grantNotificationService = grantNotificationService;
this.pingService = pingService; this.pingService = pingService;
this.activityService = activityService;
} }
public GrantDto getExistGrantById(Integer id) { public GrantDto getExistGrantById(Integer id) {
@ -95,6 +100,7 @@ public class GrantService extends BaseService {
Grant newGrant = copyFromDto(new Grant(), grantDto); Grant newGrant = copyFromDto(new Grant(), grantDto);
newGrant = grantRepository.save(newGrant); newGrant = grantRepository.save(newGrant);
eventService.createFromObject(newGrant, Collections.emptyList(), false, "гранта"); eventService.createFromObject(newGrant, Collections.emptyList(), false, "гранта");
activityService.createActivity(new ArrayList<>(newGrant.getAuthors()), newGrant.getCommonActivityState());
grantNotificationService.sendCreateNotification(newGrant); grantNotificationService.sendCreateNotification(newGrant);
return newGrant; return newGrant;
} }
@ -137,6 +143,7 @@ public class GrantService extends BaseService {
Grant grant = findById(grantDto.getId()); Grant grant = findById(grantDto.getId());
Set<User> oldAuthors = new HashSet<>(grant.getAuthors()); Set<User> oldAuthors = new HashSet<>(grant.getAuthors());
User oldLeader = grant.getLeader(); User oldLeader = grant.getLeader();
Grant.GrantStatus oldStatus = grant.getStatus();
for (FileDataDto file : grantDto.getFiles().stream() for (FileDataDto file : grantDto.getFiles().stream()
.filter(f -> f.isDeleted() && f.getId() != null) .filter(f -> f.isDeleted() && f.getId() != null)
.collect(toList())) { .collect(toList())) {
@ -158,6 +165,9 @@ public class GrantService extends BaseService {
if (grant.getLeader() != oldLeader) { if (grant.getLeader() != oldLeader) {
grantNotificationService.sendLeaderChangeNotification(grant, oldLeader); grantNotificationService.sendLeaderChangeNotification(grant, oldLeader);
} }
if(grant.getStatus() != oldStatus) {
activityService.createActivity(new ArrayList<>(grant.getAuthors()), grant.getCommonActivityState());
}
eventService.updateGrantDeadlines(grant); eventService.updateGrantDeadlines(grant);
return grant.getId(); return grant.getId();
} }

View File

@ -11,6 +11,7 @@ import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileData; import ru.ulstu.file.model.FileData;
import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.Grant;
import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.Event;
import ru.ulstu.activity.model.Activity;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
@ -323,4 +324,15 @@ public class Paper extends BaseEntity implements UserActivity, EventSource {
public int hashCode() { public int hashCode() {
return Objects.hash(super.hashCode(), title, status, type, createDate, updateDate, deadlines, comment, url, locked, events, files, authors, latexText, conferences, grants); return Objects.hash(super.hashCode(), title, status, type, createDate, updateDate, deadlines, comment, url, locked, events, files, authors, latexText, conferences, grants);
} }
public Activity.ActivityState getCommonActivityState() {
switch (this.status) {
case ON_PREPARATION:
return Activity.ActivityState.TOOK_IN_WORK;
case COMPLETED:
return Activity.ActivityState.COMPLETED;
default:
return null;
}
}
} }

View File

@ -3,6 +3,7 @@ package ru.ulstu.paper.service;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import ru.ulstu.activity.service.ActivityService;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.model.FileDataDto;
@ -57,6 +58,7 @@ public class PaperService {
private final EventService eventService; private final EventService eventService;
private final ReferenceRepository referenceRepository; private final ReferenceRepository referenceRepository;
private final PingService pingService; private final PingService pingService;
private final ActivityService activityService;
public PaperService(PaperRepository paperRepository, public PaperService(PaperRepository paperRepository,
ReferenceRepository referenceRepository, ReferenceRepository referenceRepository,
@ -65,7 +67,8 @@ public class PaperService {
UserService userService, UserService userService,
DeadlineService deadlineService, DeadlineService deadlineService,
EventService eventService, EventService eventService,
PingService pingService) { PingService pingService,
ActivityService activityService) {
this.paperRepository = paperRepository; this.paperRepository = paperRepository;
this.referenceRepository = referenceRepository; this.referenceRepository = referenceRepository;
this.fileService = fileService; this.fileService = fileService;
@ -74,6 +77,7 @@ public class PaperService {
this.deadlineService = deadlineService; this.deadlineService = deadlineService;
this.eventService = eventService; this.eventService = eventService;
this.pingService = pingService; this.pingService = pingService;
this.activityService = activityService;
} }
public List<Paper> findAll() { public List<Paper> findAll() {
@ -202,10 +206,7 @@ public class PaperService {
if (paper.getStatus() != oldStatus) { if (paper.getStatus() != oldStatus) {
paperNotificationService.statusChangeNotification(paper, oldStatus); paperNotificationService.statusChangeNotification(paper, oldStatus);
activityService.createActivity(new ArrayList<>(paper.getAuthors()), paper.getCommonActivityState());
if (paper.getStatus() == Paper.PaperStatus.ON_PREPARATION) {
userService.createActivityTookToWork(new ArrayList<>(paper.getAuthors()));
}
} }
return paper.getId(); return paper.getId();
@ -246,7 +247,9 @@ public class PaperService {
paper = paperRepository.save(paper); paper = paperRepository.save(paper);
paperNotificationService.sendCreateNotification(paper); paperNotificationService.sendCreateNotification(paper);
eventService.createFromPaper(paper); eventService.createFromPaper(paper);
activityService.createActivity(new ArrayList<>(paper.getAuthors()), paper.getCommonActivityState());
return paper; return paper;
} }

View File

@ -10,6 +10,7 @@ import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileData; import ru.ulstu.file.model.FileData;
import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.Grant;
import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.Event;
import ru.ulstu.activity.model.Activity;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
@ -106,6 +107,17 @@ public class Project extends BaseEntity implements UserActivity, EventSource {
event.setProject(this); event.setProject(this);
} }
public Activity.ActivityState getCommonActivityState() {
switch (this.status) {
case IN_WORK:
return Activity.ActivityState.TOOK_IN_WORK;
case CLOSED:
return Activity.ActivityState.COMPLETED;
default:
return null;
}
}
public void setTitle(String title) { public void setTitle(String title) {
this.title = title; this.title = title;
} }

View File

@ -3,6 +3,7 @@ package ru.ulstu.project.service;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.util.StringUtils; import org.thymeleaf.util.StringUtils;
import ru.ulstu.activity.service.ActivityService;
import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.model.FileDataDto;
import ru.ulstu.file.service.FileService; import ru.ulstu.file.service.FileService;
@ -17,6 +18,7 @@ import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserService;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -37,14 +39,15 @@ public class ProjectService {
private final EventService eventService; private final EventService eventService;
private final UserService userService; private final UserService userService;
private final PingService pingService; private final PingService pingService;
private final ActivityService activityService;
public ProjectService(ProjectRepository projectRepository, public ProjectService(ProjectRepository projectRepository,
DeadlineService deadlineService, DeadlineService deadlineService,
GrantRepository grantRepository, GrantRepository grantRepository,
FileService fileService, FileService fileService,
EventService eventService, EventService eventService,
UserService userService, UserService userService,
PingService pingService) { PingService pingService,
ActivityService activityService) {
this.projectRepository = projectRepository; this.projectRepository = projectRepository;
this.deadlineService = deadlineService; this.deadlineService = deadlineService;
this.grantRepository = grantRepository; this.grantRepository = grantRepository;
@ -52,6 +55,7 @@ public class ProjectService {
this.eventService = eventService; this.eventService = eventService;
this.userService = userService; this.userService = userService;
this.pingService = pingService; this.pingService = pingService;
this.activityService = activityService;
} }
public List<Project> findAll() { public List<Project> findAll() {
@ -77,15 +81,17 @@ public class ProjectService {
Project newProject = copyFromDto(new Project(), projectDto); Project newProject = copyFromDto(new Project(), projectDto);
newProject = projectRepository.save(newProject); newProject = projectRepository.save(newProject);
eventService.createFromObject(newProject, Collections.emptyList(), false, "проекта"); eventService.createFromObject(newProject, Collections.emptyList(), false, "проекта");
if (projectDto.getStatus() == Project.ProjectStatus.IN_WORK) { activityService.createActivity(new ArrayList<>(newProject.getExecutors()), newProject.getCommonActivityState());
userService.createActivityTookToWork(newProject.getExecutors());
}
return newProject; return newProject;
} }
@Transactional @Transactional
public Project update(ProjectDto projectDto) throws IOException { public Project update(ProjectDto projectDto) throws IOException {
Project project = projectRepository.findOne(projectDto.getId()); Project project = projectRepository.findOne(projectDto.getId());
if (project.getStatus() != projectDto.getStatus()) {
activityService.createActivity(new ArrayList<>(project.getExecutors()), project.getCommonActivityState());
}
projectRepository.save(copyFromDto(project, projectDto)); projectRepository.save(copyFromDto(project, projectDto));
eventService.updateProjectDeadlines(project); eventService.updateProjectDeadlines(project);
for (FileDataDto file : projectDto.getFiles().stream() for (FileDataDto file : projectDto.getFiles().stream()
@ -93,9 +99,6 @@ public class ProjectService {
.collect(toList())) { .collect(toList())) {
fileService.delete(file.getId()); fileService.delete(file.getId());
} }
if (projectDto.getStatus() == Project.ProjectStatus.IN_WORK) {
userService.createActivityTookToWork(project.getExecutors());
}
return project; return project;
} }

View File

@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import ru.ulstu.activity.service.ActivityService;
import ru.ulstu.configuration.Constants; import ru.ulstu.configuration.Constants;
import ru.ulstu.core.model.response.PageableItems; import ru.ulstu.core.model.response.PageableItems;
import ru.ulstu.core.model.response.Response; import ru.ulstu.core.model.response.Response;
@ -20,7 +21,7 @@ import ru.ulstu.odin.controller.OdinController;
import ru.ulstu.odin.model.OdinMetadata; import ru.ulstu.odin.model.OdinMetadata;
import ru.ulstu.odin.model.OdinVoid; import ru.ulstu.odin.model.OdinVoid;
import ru.ulstu.odin.service.OdinService; import ru.ulstu.odin.service.OdinService;
import ru.ulstu.user.model.ActivityElement; import ru.ulstu.activity.model.ActivityElement;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.model.UserListDto; import ru.ulstu.user.model.UserListDto;
@ -59,16 +60,19 @@ public class UserController extends OdinController<UserListDto, UserDto> {
private final UserSessionService userSessionService; private final UserSessionService userSessionService;
private final OdinService<UserRoleDto, UserRoleDto> odinRolesService; private final OdinService<UserRoleDto, UserRoleDto> odinRolesService;
private final OdinService<UserSessionListDto, OdinVoid> odinSessionsService; private final OdinService<UserSessionListDto, OdinVoid> odinSessionsService;
private final ActivityService activityService;
public UserController(UserService userService, public UserController(UserService userService,
UserSessionService userSessionService, UserSessionService userSessionService,
OdinService<UserRoleDto, UserRoleDto> odinRolesService, OdinService<UserRoleDto, UserRoleDto> odinRolesService,
OdinService<UserSessionListDto, OdinVoid> odinSessionsService) { OdinService<UserSessionListDto, OdinVoid> odinSessionsService,
ActivityService activityService) {
super(UserListDto.class, UserDto.class); super(UserListDto.class, UserDto.class);
this.userService = userService; this.userService = userService;
this.userSessionService = userSessionService; this.userSessionService = userSessionService;
this.odinRolesService = odinRolesService; this.odinRolesService = odinRolesService;
this.odinSessionsService = odinSessionsService; this.odinSessionsService = odinSessionsService;
this.activityService = activityService;
} }
@GetMapping(ROLES_URL) @GetMapping(ROLES_URL)
@ -189,6 +193,6 @@ public class UserController extends OdinController<UserListDto, UserDto> {
public Response<Map<String, ActivityElement>> getActivitiesList(@RequestParam("userId") Integer userId, public Response<Map<String, ActivityElement>> getActivitiesList(@RequestParam("userId") Integer userId,
@RequestParam("dateFrom") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateFrom, @RequestParam("dateFrom") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateFrom,
@RequestParam("dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo) { @RequestParam("dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo) {
return new Response<>(userService.getUsersActivity(userId, dateFrom, dateTo)); return new Response<>(activityService.getUsersActivity(userId, dateFrom, dateTo));
} }
} }

View File

@ -34,8 +34,6 @@ import ru.ulstu.user.error.UserNotFoundException;
import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException; import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException;
import ru.ulstu.user.error.UserResetKeyError; import ru.ulstu.user.error.UserResetKeyError;
import ru.ulstu.user.error.UserSendingMailException; import ru.ulstu.user.error.UserSendingMailException;
import ru.ulstu.user.model.Activity;
import ru.ulstu.user.model.ActivityElement;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.model.UserInfoNow; import ru.ulstu.user.model.UserInfoNow;
@ -44,7 +42,7 @@ import ru.ulstu.user.model.UserResetPasswordDto;
import ru.ulstu.user.model.UserRole; import ru.ulstu.user.model.UserRole;
import ru.ulstu.user.model.UserRoleConstants; import ru.ulstu.user.model.UserRoleConstants;
import ru.ulstu.user.model.UserRoleDto; import ru.ulstu.user.model.UserRoleDto;
import ru.ulstu.user.repository.ActivityRepository; import ru.ulstu.activity.repository.ActivityRepository;
import ru.ulstu.user.repository.UserRepository; import ru.ulstu.user.repository.UserRepository;
import ru.ulstu.user.repository.UserRoleRepository; import ru.ulstu.user.repository.UserRoleRepository;
import ru.ulstu.user.util.UserUtils; import ru.ulstu.user.util.UserUtils;
@ -54,9 +52,7 @@ import ru.ulstu.utils.timetable.model.Lesson;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
@ -439,39 +435,4 @@ public class UserService implements UserDetailsService {
userToBlock.setBlocker(getCurrentUser()); userToBlock.setBlocker(getCurrentUser());
userRepository.save(userToBlock); userRepository.save(userToBlock);
} }
public void createActivityTookToWork(List<User> users) {
List<Activity> activities = new ArrayList<>();
for (User user : users) {
activities.add(new Activity(user, Activity.ActivityState.TOOK_IN_WORK));
}
activityRepository.save(activities);
}
public void createActivityCompleted(List<User> users) {
List<Activity> activities = new ArrayList<>();
for (User user : users) {
activities.add(new Activity(user, Activity.ActivityState.COMPLETED));
}
activityRepository.save(activities);
}
public Map<String, ActivityElement> getUsersActivity(Integer userId, Date dateFrom, Date dateTo) {
List<Activity> activities = activityRepository.getByUserAndDateInterval(userId, dateFrom, dateTo);
Map<String, ActivityElement> dateActivities = new HashMap<>();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
for (Activity activity : activities) {
String dt = formatter.format(activity.getDate());
if (!dateActivities.containsKey(dt)) {
dateActivities.put(dt, new ActivityElement(1, 1));
} else {
ActivityElement element = dateActivities.get(dt);
element.incrementCompletedCount();
element.incrementStartedCount();
dateActivities.put(dt, element);
}
}
return dateActivities;
}
} }

View File

@ -18,7 +18,7 @@ logging.level.com.gargoylesoftware.htmlunit=ERROR
# Mail Settings # Mail Settings
spring.mail.host=smtp.yandex.ru spring.mail.host=smtp.yandex.ru
spring.mail.port=465 spring.mail.port=465
spring.mail.username=nio171.ulstu@yandex.ru spring.mail.username=nio17.ulstu@yandex.ru
spring.mail.password=nio17.ulstu.ru spring.mail.password=nio17.ulstu.ru
spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.ssl.enable=true spring.mail.properties.mail.smtp.ssl.enable=true
@ -26,7 +26,7 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact
# JPA Settings # JPA Settings
spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker
spring.datasource.username=postgres spring.datasource.username=postgres
spring.datasource.password=password spring.datasource.password=postgres
spring.datasource.driverclassName=org.postgresql.Driver spring.datasource.driverclassName=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=validate spring.jpa.hibernate.ddl-auto=validate
# Liquibase Settings # Liquibase Settings
@ -37,7 +37,7 @@ liquibase.change-log=classpath:db/changelog-master.xml
# Application Settings # Application Settings
ng-tracker.base-url=http://127.0.0.1:8080 ng-tracker.base-url=http://127.0.0.1:8080
ng-tracker.undead-user-login=admin ng-tracker.undead-user-login=admin
ng-tracker.dev-mode=false ng-tracker.dev-mode=true
ng-tracker.debug_email= ng-tracker.debug_email=
ng-tracker.use-https=false ng-tracker.use-https=false
ng-tracker.check-run=false ng-tracker.check-run=false

View File

@ -9,8 +9,7 @@
<script src="/js/core.js"></script> <script src="/js/core.js"></script>
<script> <script>
google.load('visualization', '1.0', {'packages':['corechart']}); google.load('visualization', '1.0', {'packages':['corechart']});
google.setOnLoadCallback(drawActivitiesChart()); google.setOnLoadCallback(drawActivitiesChart);
</script> </script>
</head> </head>
<body> <body>