#93 users activity by date
This commit is contained in:
parent
ea0b8fbaad
commit
ed7707c4d8
@ -21,6 +21,7 @@ import ru.ulstu.user.service.UserService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
@ -197,6 +198,10 @@ public class PaperService {
|
||||
|
||||
if (paper.getStatus() != oldStatus) {
|
||||
paperNotificationService.statusChangeNotification(paper, oldStatus);
|
||||
|
||||
if (paper.getStatus() == Paper.PaperStatus.ON_PREPARATION) {
|
||||
userService.createActivityTookToWork(new ArrayList<>(paper.getUsers()));
|
||||
}
|
||||
}
|
||||
|
||||
return paper.getId();
|
||||
|
@ -13,6 +13,8 @@ import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.project.model.Project;
|
||||
import ru.ulstu.project.model.ProjectDto;
|
||||
import ru.ulstu.project.service.ProjectService;
|
||||
import ru.ulstu.user.error.UserNotActivatedException;
|
||||
import ru.ulstu.user.error.UserNotFoundException;
|
||||
import ru.ulstu.user.model.User;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
|
@ -64,6 +64,9 @@ public class ProjectService {
|
||||
public Project create(ProjectDto projectDto) throws IOException {
|
||||
Project newProject = copyFromDto(new Project(), projectDto);
|
||||
newProject = projectRepository.save(newProject);
|
||||
if (projectDto.getStatus() == Project.ProjectStatus.IN_WORK) {
|
||||
userService.createActivityTookToWork(newProject.getExecutors());
|
||||
}
|
||||
return newProject;
|
||||
}
|
||||
|
||||
@ -74,6 +77,9 @@ public class ProjectService {
|
||||
fileService.deleteFile(project.getApplication());
|
||||
}
|
||||
projectRepository.save(copyFromDto(project, projectDto));
|
||||
if (projectDto.getStatus() == Project.ProjectStatus.IN_WORK) {
|
||||
userService.createActivityTookToWork(project.getExecutors());
|
||||
}
|
||||
return project;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package ru.ulstu.user.controller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
@ -34,6 +35,8 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static ru.ulstu.user.controller.UserController.URL;
|
||||
@ -171,4 +174,11 @@ public class UserController extends OdinController<UserListDto, UserDto> {
|
||||
public void inviteUser(@RequestParam("email") String email) {
|
||||
userService.inviteUser(email);
|
||||
}
|
||||
|
||||
@GetMapping("/activities")
|
||||
public Response<Map<Date, Integer>> getActivitiesList(@RequestParam("userId") Integer userId,
|
||||
@RequestParam("dateFrom") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateFrom,
|
||||
@RequestParam("dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo) {
|
||||
return new Response<>(userService.getUsersActivity(userId, dateFrom, dateTo));
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import ru.ulstu.configuration.Constants;
|
||||
@ -17,6 +18,7 @@ import ru.ulstu.user.service.UserSessionService;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/users")
|
||||
@ -53,4 +55,13 @@ public class UserMvcController extends OdinController<UserListDto, UserDto> {
|
||||
public void getUsersDashboard(ModelMap modelMap) {
|
||||
modelMap.addAllAttributes(userService.getUsersInfo());
|
||||
}
|
||||
|
||||
@ModelAttribute("allUsers")
|
||||
public List<User> getAllUsers() {
|
||||
return userService.findAll();
|
||||
}
|
||||
|
||||
@GetMapping("/activities")
|
||||
public void getActivities() {
|
||||
}
|
||||
}
|
||||
|
80
src/main/java/ru/ulstu/user/model/Activity.java
Normal file
80
src/main/java/ru/ulstu/user/model/Activity.java
Normal file
@ -0,0 +1,80 @@
|
||||
package ru.ulstu.user.model;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import ru.ulstu.core.model.BaseEntity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
@Table(name = "activity")
|
||||
public class Activity extends BaseEntity {
|
||||
|
||||
public enum ActivityState {
|
||||
TOOK_IN_WORK("Взято в работу"),
|
||||
COMPLETED("Выполнено");
|
||||
|
||||
private String statusName;
|
||||
|
||||
ActivityState(String statusName) {
|
||||
this.statusName = statusName;
|
||||
}
|
||||
|
||||
public String getStatusName() {
|
||||
return this.statusName;
|
||||
}
|
||||
}
|
||||
|
||||
@ManyToOne()
|
||||
@JoinColumn(name = "user_id")
|
||||
private User user;
|
||||
|
||||
@Temporal(value = TemporalType.TIMESTAMP)
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date date;
|
||||
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
@Column(name = "state")
|
||||
private ActivityState activityState;
|
||||
|
||||
public Activity(User user, ActivityState activityState) {
|
||||
this.user = user;
|
||||
this.date = new Date();
|
||||
this.activityState = activityState;
|
||||
}
|
||||
|
||||
public Activity() {
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public ActivityState getActivityState() {
|
||||
return activityState;
|
||||
}
|
||||
|
||||
public void setActivityState(ActivityState activityState) {
|
||||
this.activityState = activityState;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package ru.ulstu.user.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
//import ru.ulstu.user.model.Activity;
|
||||
//
|
||||
//import java.util.Date;
|
||||
//import java.util.List;
|
||||
//
|
||||
//public interface ActivityRepository extends JpaRepository<Activity, Integer> {
|
||||
//
|
||||
// @Query("SELECT a FROM Activity a WHERE (:userId IS NULL OR a.user.id = :userId) " +
|
||||
// "AND (CAST(:dateFrom AS date) IS NULL OR :dateFrom < a.date) " +
|
||||
// "AND (CAST(:dateTo AS date) IS NULL OR :dateTo > a.date)")
|
||||
// List<Activity> getByUserAndDateInterval(@Param("userId") Integer userId,
|
||||
// @Param("dateFrom") Date dateFrom,
|
||||
// @Param("dateTo") Date dateTo);
|
||||
//}
|
@ -30,6 +30,7 @@ import ru.ulstu.user.error.UserNotFoundException;
|
||||
import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException;
|
||||
import ru.ulstu.user.error.UserResetKeyError;
|
||||
import ru.ulstu.user.error.UserSendingMailException;
|
||||
import ru.ulstu.user.model.Activity;
|
||||
import ru.ulstu.user.model.User;
|
||||
import ru.ulstu.user.model.UserDto;
|
||||
import ru.ulstu.user.model.UserInfoNow;
|
||||
@ -38,6 +39,7 @@ import ru.ulstu.user.model.UserResetPasswordDto;
|
||||
import ru.ulstu.user.model.UserRole;
|
||||
import ru.ulstu.user.model.UserRoleConstants;
|
||||
import ru.ulstu.user.model.UserRoleDto;
|
||||
import ru.ulstu.user.repository.ActivityRepository;
|
||||
import ru.ulstu.user.repository.UserRepository;
|
||||
import ru.ulstu.user.repository.UserRoleRepository;
|
||||
import ru.ulstu.user.util.UserUtils;
|
||||
@ -48,9 +50,11 @@ import ru.ulstu.utils.timetable.model.Lesson;
|
||||
import javax.mail.MessagingException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@ -73,6 +77,7 @@ public class UserService implements UserDetailsService {
|
||||
private final TimetableService timetableService;
|
||||
private final ConferenceService conferenceService;
|
||||
private final UserSessionService userSessionService;
|
||||
private final ActivityRepository activityRepository;
|
||||
|
||||
public UserService(UserRepository userRepository,
|
||||
PasswordEncoder passwordEncoder,
|
||||
@ -81,7 +86,8 @@ public class UserService implements UserDetailsService {
|
||||
MailService mailService,
|
||||
ApplicationProperties applicationProperties,
|
||||
@Lazy ConferenceService conferenceRepository,
|
||||
@Lazy UserSessionService userSessionService) throws ParseException {
|
||||
@Lazy UserSessionService userSessionService,
|
||||
ActivityRepository activityRepository) throws ParseException {
|
||||
this.userRepository = userRepository;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
this.userRoleRepository = userRoleRepository;
|
||||
@ -91,6 +97,7 @@ public class UserService implements UserDetailsService {
|
||||
this.conferenceService = conferenceRepository;
|
||||
this.timetableService = new TimetableService();
|
||||
this.userSessionService = userSessionService;
|
||||
this.activityRepository = activityRepository;
|
||||
}
|
||||
|
||||
private User getUserByEmail(String email) {
|
||||
@ -252,7 +259,7 @@ public class UserService implements UserDetailsService {
|
||||
mailService.sendChangePasswordMail(user);
|
||||
}
|
||||
|
||||
public boolean requestUserPasswordReset(String email) {
|
||||
public boolean requestUserPasswordReset(String email) {
|
||||
User user = userRepository.findOneByEmailIgnoreCase(email);
|
||||
if (user == null) {
|
||||
throw new UserNotFoundException(email);
|
||||
@ -389,4 +396,34 @@ public class UserService implements UserDetailsService {
|
||||
}
|
||||
return ImmutableMap.of("users", usersInfoNow, "error", err);
|
||||
}
|
||||
|
||||
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<Date, Integer> getUsersActivity(Integer userId, Date dateFrom, Date dateTo) {
|
||||
List<Activity> activities = activityRepository.getByUserAndDateInterval(userId, dateFrom, dateTo);
|
||||
Map<Date, Integer> dateActivities = new HashMap<>();
|
||||
|
||||
for (Activity activity : activities) {
|
||||
if (!dateActivities.containsKey(activity.getDate())) {
|
||||
dateActivities.put(activity.getDate(), 1);
|
||||
} else {
|
||||
dateActivities.put(activity.getDate(), dateActivities.get(activity.getDate()) + 1);
|
||||
}
|
||||
}
|
||||
return dateActivities;
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ logging.level.ru.ulstu=DEBUG
|
||||
# Mail Settings
|
||||
spring.mail.host=smtp.yandex.ru
|
||||
spring.mail.port=465
|
||||
spring.mail.username=nio17.ulstu@yandex.ru
|
||||
spring.mail.username=nio171.ulstu@yandex.ru
|
||||
spring.mail.password=nio17.ulstu.ru
|
||||
spring.mail.properties.mail.smtp.auth=true
|
||||
spring.mail.properties.mail.smtp.ssl.enable=true
|
||||
@ -24,7 +24,7 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact
|
||||
# JPA Settings
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker
|
||||
spring.datasource.username=postgres
|
||||
spring.datasource.password=postgres
|
||||
spring.datasource.password=password
|
||||
spring.datasource.driverclassName=org.postgresql.Driver
|
||||
spring.jpa.hibernate.ddl-auto=validate
|
||||
# Liquibase Settings
|
||||
@ -34,7 +34,7 @@ liquibase.change-log=classpath:db/changelog-master.xml
|
||||
# Application Settings
|
||||
ng-tracker.base-url=http://127.0.0.1:8080
|
||||
ng-tracker.undead-user-login=admin
|
||||
ng-tracker.dev-mode=true
|
||||
ng-tracker.dev-mode=false
|
||||
ng-tracker.debug_email=
|
||||
ng-tracker.use-https=false
|
||||
ng-tracker.check-run=false
|
17
src/main/resources/db/changelog-20190603_000002-schema.xml
Normal file
17
src/main/resources/db/changelog-20190603_000002-schema.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||
<changeSet author="arefyev" id="20190603_000000-3">
|
||||
<createTable tableName="activity">
|
||||
<column name="id" type="integer"/>
|
||||
<column name="user_id" type="integer"/>
|
||||
<column name="version" type="integer"/>
|
||||
<column name="date" type="timestamp"/>
|
||||
<column name="state" type="varchar(255)"/>
|
||||
</createTable>
|
||||
<addForeignKeyConstraint baseTableName="activity" baseColumnNames="user_id"
|
||||
constraintName="fk_activity_user" referencedTableName="users"
|
||||
referencedColumnNames="id"/>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
@ -49,4 +49,5 @@
|
||||
<include file="db/changelog-20190523_000000-schema.xml"/>
|
||||
<include file="db/changelog-20190528_000000-schema.xml"/>
|
||||
<include file="db/changelog-20190528_000002-schema.xml"/>
|
||||
<include file="db/changelog-20190603_000002-schema.xml"/>
|
||||
</databaseChangeLog>
|
47
src/main/resources/templates/users/activities.html
Normal file
47
src/main/resources/templates/users/activities.html
Normal file
@ -0,0 +1,47 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
|
||||
<head>
|
||||
<link rel="stylesheet" href="../css/grant.css"/>
|
||||
<script src="https://www.google.com/jsapi"></script>
|
||||
<script src="/js/users.js"></script>
|
||||
<script src="/js/core.js"></script>
|
||||
<script>
|
||||
google.load('visualization', '1.0', {'packages':['corechart']});
|
||||
google.setOnLoadCallback(drawChart);
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container" layout:fragment="content">
|
||||
<section id="ewrq">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-12 text-center">
|
||||
<h2 class="section-heading text-uppercase">Активность пользователей</h2>
|
||||
</div>
|
||||
<div id="air" style="width: 500px; height: 400px;" class="col-md-9 col-sm-12"></div>
|
||||
<div class="col-md-3 col-sm-12">
|
||||
<div class="filter">
|
||||
<h5>Фильтр:</h5>
|
||||
<select class="form-control" id="author"
|
||||
onchange="drawActivitiesChart();">
|
||||
<option value="">Все авторы</option>
|
||||
<option th:each="user: ${allUsers}" th:value="${user.id}"
|
||||
th:text="${user.lastName}">lastName
|
||||
</option>
|
||||
</select>
|
||||
<br/>
|
||||
<input type="date" id="dateFrom"/>
|
||||
<input type="date" id="dateTo"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user