From ed7707c4d8cf9511250e5ce6fc1f48106c9f7d39 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Wed, 5 Jun 2019 10:53:30 +0400 Subject: [PATCH 1/7] #93 users activity by date --- .../ru/ulstu/paper/service/PaperService.java | 5 ++ .../project/controller/ProjectController.java | 2 + .../ulstu/project/service/ProjectService.java | 6 ++ .../ulstu/user/controller/UserController.java | 10 +++ .../user/controller/UserMvcController.java | 11 +++ .../java/ru/ulstu/user/model/Activity.java | 80 +++++++++++++++++++ .../user/repository/ActivityRepository.java | 19 +++++ .../ru/ulstu/user/service/UserService.java | 41 +++++++++- src/main/resources/application.properties | 6 +- .../db/changelog-20190603_000002-schema.xml | 17 ++++ src/main/resources/db/changelog-master.xml | 1 + .../resources/templates/users/activities.html | 47 +++++++++++ 12 files changed, 240 insertions(+), 5 deletions(-) create mode 100644 src/main/java/ru/ulstu/user/model/Activity.java create mode 100644 src/main/java/ru/ulstu/user/repository/ActivityRepository.java create mode 100644 src/main/resources/db/changelog-20190603_000002-schema.xml create mode 100644 src/main/resources/templates/users/activities.html diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 2393af4..013ce72 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -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(); diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index 88f0c7a..a344f75 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -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; diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index fe8813c..a8444a6 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -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; } diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index c40ed8f..6cabd99 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -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 { public void inviteUser(@RequestParam("email") String email) { userService.inviteUser(email); } + + @GetMapping("/activities") + public Response> 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)); + } } diff --git a/src/main/java/ru/ulstu/user/controller/UserMvcController.java b/src/main/java/ru/ulstu/user/controller/UserMvcController.java index 044bde8..de0592e 100644 --- a/src/main/java/ru/ulstu/user/controller/UserMvcController.java +++ b/src/main/java/ru/ulstu/user/controller/UserMvcController.java @@ -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 { public void getUsersDashboard(ModelMap modelMap) { modelMap.addAllAttributes(userService.getUsersInfo()); } + + @ModelAttribute("allUsers") + public List getAllUsers() { + return userService.findAll(); + } + + @GetMapping("/activities") + public void getActivities() { + } } diff --git a/src/main/java/ru/ulstu/user/model/Activity.java b/src/main/java/ru/ulstu/user/model/Activity.java new file mode 100644 index 0000000..74849dc --- /dev/null +++ b/src/main/java/ru/ulstu/user/model/Activity.java @@ -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; + } +} diff --git a/src/main/java/ru/ulstu/user/repository/ActivityRepository.java b/src/main/java/ru/ulstu/user/repository/ActivityRepository.java new file mode 100644 index 0000000..89b6093 --- /dev/null +++ b/src/main/java/ru/ulstu/user/repository/ActivityRepository.java @@ -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 { +// +// @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 getByUserAndDateInterval(@Param("userId") Integer userId, +// @Param("dateFrom") Date dateFrom, +// @Param("dateTo") Date dateTo); +//} diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 217215b..3056c18 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -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 users) { + List activities = new ArrayList<>(); + for (User user : users) { + activities.add(new Activity(user, Activity.ActivityState.TOOK_IN_WORK)); + } + activityRepository.save(activities); + } + + public void createActivityCompleted(List users) { + List activities = new ArrayList<>(); + for (User user : users) { + activities.add(new Activity(user, Activity.ActivityState.COMPLETED)); + } + activityRepository.save(activities); + } + + public Map getUsersActivity(Integer userId, Date dateFrom, Date dateTo) { + List activities = activityRepository.getByUserAndDateInterval(userId, dateFrom, dateTo); + Map 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; + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f4be778..7bda533 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -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 \ No newline at end of file diff --git a/src/main/resources/db/changelog-20190603_000002-schema.xml b/src/main/resources/db/changelog-20190603_000002-schema.xml new file mode 100644 index 0000000..8ff0184 --- /dev/null +++ b/src/main/resources/db/changelog-20190603_000002-schema.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index c8a6e63..ae5c400 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -49,4 +49,5 @@ + \ No newline at end of file diff --git a/src/main/resources/templates/users/activities.html b/src/main/resources/templates/users/activities.html new file mode 100644 index 0000000..9565a7e --- /dev/null +++ b/src/main/resources/templates/users/activities.html @@ -0,0 +1,47 @@ + + + + + + + + + + + +
+
+
+
+
+

Активность пользователей

+
+
+
+
+
Фильтр:
+ +
+ + +
+
+
+
+ +
+
+ + -- 2.34.1 From 2adaf7740a47f2cf58e8c5367e5bb93042afd825 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Wed, 5 Jun 2019 10:55:12 +0400 Subject: [PATCH 2/7] #93 removed comment --- .../user/repository/ActivityRepository.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/ulstu/user/repository/ActivityRepository.java b/src/main/java/ru/ulstu/user/repository/ActivityRepository.java index 89b6093..cc0ec4e 100644 --- a/src/main/java/ru/ulstu/user/repository/ActivityRepository.java +++ b/src/main/java/ru/ulstu/user/repository/ActivityRepository.java @@ -3,17 +3,17 @@ 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 { -// -// @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 getByUserAndDateInterval(@Param("userId") Integer userId, -// @Param("dateFrom") Date dateFrom, -// @Param("dateTo") Date dateTo); -//} +import ru.ulstu.user.model.Activity; + +import java.util.Date; +import java.util.List; + +public interface ActivityRepository extends JpaRepository { + + @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 getByUserAndDateInterval(@Param("userId") Integer userId, + @Param("dateFrom") Date dateFrom, + @Param("dateTo") Date dateTo); +} -- 2.34.1 From 44e3fc2c6e69c3b50bf394e6f1c9467f78423a34 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Wed, 5 Jun 2019 11:25:33 +0400 Subject: [PATCH 3/7] #93 fixes --- .../ulstu/user/controller/UserController.java | 2 +- .../ru/ulstu/user/service/UserService.java | 14 ++++---- src/main/resources/public/js/users.js | 34 +++++++++++++++++++ .../resources/templates/users/activities.html | 4 +-- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index 6cabd99..d18df00 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -176,7 +176,7 @@ public class UserController extends OdinController { } @GetMapping("/activities") - public Response> getActivitiesList(@RequestParam("userId") Integer userId, + public Response> 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)); diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 3056c18..1990194 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -49,6 +49,7 @@ import ru.ulstu.utils.timetable.model.Lesson; import javax.mail.MessagingException; import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; @@ -413,15 +414,16 @@ public class UserService implements UserDetailsService { activityRepository.save(activities); } - public Map getUsersActivity(Integer userId, Date dateFrom, Date dateTo) { + public Map getUsersActivity(Integer userId, Date dateFrom, Date dateTo) { List activities = activityRepository.getByUserAndDateInterval(userId, dateFrom, dateTo); - Map dateActivities = new HashMap<>(); - + Map dateActivities = new HashMap<>(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); for (Activity activity : activities) { - if (!dateActivities.containsKey(activity.getDate())) { - dateActivities.put(activity.getDate(), 1); + String dt = formatter.format(activity.getDate()); + if (!dateActivities.containsKey(dt)) { + dateActivities.put(dt, 1); } else { - dateActivities.put(activity.getDate(), dateActivities.get(activity.getDate()) + 1); + dateActivities.put(dt, dateActivities.get(dt) + 1); } } return dateActivities; diff --git a/src/main/resources/public/js/users.js b/src/main/resources/public/js/users.js index e31d3ad..2d1244f 100644 --- a/src/main/resources/public/js/users.js +++ b/src/main/resources/public/js/users.js @@ -124,4 +124,38 @@ function resetPassword() { function isEmailValid(email) { re = /\S+@\S+\.\S+/; return re.test(email) +} + +function drawActivitiesChart() { + userId = $('#author :selected').val() + dateFrom = $('#dateFrom').val() + dateTo = $('#dateTo').val() + + $.ajax({ + url:`/api/1.0/users/activities?userId=${userId}&dateFrom=${dateFrom}&dateTo=${dateTo}`, + contentType: "application/json; charset=utf-8", + method: "GET", + success: function(response) { + if (response.data.length == 0) { + return; + } + array = [['Активности', 'Количество']] + + Object.keys(response.data).forEach(function(key) { + console.table('Key : ' + key + ', Value : ' + response.data[key]) + array.push([key, response.data[key]]) + }) + var data = google.visualization.arrayToDataTable(array); + var options = { + title: 'Активности', + is3D: true, + pieResidueSliceLabel: 'Остальное' + }; + var chart = new google.visualization.ColumnChart(document.getElementById('air')); + chart.draw(data, options); + }, + error: function(errorData) { + showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) + } + }) } \ No newline at end of file diff --git a/src/main/resources/templates/users/activities.html b/src/main/resources/templates/users/activities.html index 9565a7e..9527b95 100644 --- a/src/main/resources/templates/users/activities.html +++ b/src/main/resources/templates/users/activities.html @@ -34,8 +34,8 @@
- - + + -- 2.34.1 From 9bec1d080da32ae450dcf8bb13beafba9693d170 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Wed, 5 Jun 2019 11:55:51 +0400 Subject: [PATCH 4/7] #93 completed count --- .../ulstu/user/controller/UserController.java | 7 ++-- .../ru/ulstu/user/model/ActivityElement.java | 37 +++++++++++++++++++ .../ru/ulstu/user/service/UserService.java | 13 +++++-- src/main/resources/public/js/users.js | 5 ++- .../resources/templates/users/activities.html | 2 +- 5 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 src/main/java/ru/ulstu/user/model/ActivityElement.java diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index d18df00..9770ed1 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -21,6 +21,7 @@ import ru.ulstu.odin.controller.OdinController; import ru.ulstu.odin.model.OdinMetadata; import ru.ulstu.odin.model.OdinVoid; import ru.ulstu.odin.service.OdinService; +import ru.ulstu.user.model.ActivityElement; import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserListDto; @@ -176,9 +177,9 @@ public class UserController extends OdinController { } @GetMapping("/activities") - public Response> getActivitiesList(@RequestParam("userId") Integer userId, - @RequestParam("dateFrom") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateFrom, - @RequestParam("dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo) { + public Response> 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)); } } diff --git a/src/main/java/ru/ulstu/user/model/ActivityElement.java b/src/main/java/ru/ulstu/user/model/ActivityElement.java new file mode 100644 index 0000000..f1e42b6 --- /dev/null +++ b/src/main/java/ru/ulstu/user/model/ActivityElement.java @@ -0,0 +1,37 @@ +package ru.ulstu.user.model; + +public class ActivityElement { + private int startedCount; + private int completedCount; + + public ActivityElement() {} + + public ActivityElement(int startedCount, int completedCount) { + this.startedCount = startedCount; + this.completedCount = completedCount; + } + + public int getStartedCount() { + return startedCount; + } + + public void setStartedCount(int startedCount) { + this.startedCount = startedCount; + } + + public int getCompletedCount() { + return completedCount; + } + + public void setCompletedCount(int completedCount) { + this.completedCount = completedCount; + } + + public void incrementStartedCount() { + this.startedCount ++; + } + + public void incrementCompletedCount() { + this.completedCount ++; + } +} diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 1990194..0004268 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -31,6 +31,7 @@ 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.ActivityElement; import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserInfoNow; @@ -414,16 +415,20 @@ public class UserService implements UserDetailsService { activityRepository.save(activities); } - public Map getUsersActivity(Integer userId, Date dateFrom, Date dateTo) { + public Map getUsersActivity(Integer userId, Date dateFrom, Date dateTo) { List activities = activityRepository.getByUserAndDateInterval(userId, dateFrom, dateTo); - Map dateActivities = new HashMap<>(); + Map 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, 1); + dateActivities.put(dt, new ActivityElement(1, 1)); + } else { - dateActivities.put(dt, dateActivities.get(dt) + 1); + ActivityElement element = dateActivities.get(dt); + element.incrementCompletedCount(); + element.incrementStartedCount(); + dateActivities.put(dt, element); } } return dateActivities; diff --git a/src/main/resources/public/js/users.js b/src/main/resources/public/js/users.js index 2d1244f..82fb9fe 100644 --- a/src/main/resources/public/js/users.js +++ b/src/main/resources/public/js/users.js @@ -139,11 +139,12 @@ function drawActivitiesChart() { if (response.data.length == 0) { return; } - array = [['Активности', 'Количество']] + kk = response.data; + array = [['Активности', 'Количество начатых', 'Количество законченных']] Object.keys(response.data).forEach(function(key) { console.table('Key : ' + key + ', Value : ' + response.data[key]) - array.push([key, response.data[key]]) + array.push([key, response.data[key]['startedCount'], response.data[key]['completedCount']]) }) var data = google.visualization.arrayToDataTable(array); var options = { diff --git a/src/main/resources/templates/users/activities.html b/src/main/resources/templates/users/activities.html index 9527b95..f5c8e1d 100644 --- a/src/main/resources/templates/users/activities.html +++ b/src/main/resources/templates/users/activities.html @@ -9,7 +9,7 @@ -- 2.34.1 From a28b3ea57b6d4870bcdbde1d0d66400fbd548e93 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Fri, 7 Jun 2019 12:46:27 +0400 Subject: [PATCH 5/7] #93 resolve stashed conflicts --- .../java/ru/ulstu/conference/model/Conference.java | 8 ++++++++ src/main/java/ru/ulstu/grant/model/Grant.java | 11 +++++++++++ .../ru/ulstu/grant/repository/GrantRepository.java | 9 +++++++++ .../java/ru/ulstu/grant/service/GrantService.java | 4 ++++ .../ru/ulstu/paper/repository/PaperRepository.java | 8 ++++++++ .../java/ru/ulstu/paper/service/PaperService.java | 5 +++++ src/main/java/ru/ulstu/project/model/Project.java | 12 ++++++++++++ .../ulstu/project/repository/ProjectRepository.java | 13 +++++++++++++ .../ru/ulstu/project/service/ProjectService.java | 6 ++++++ .../java/ru/ulstu/user/service/UserService.java | 6 ++++++ 10 files changed, 82 insertions(+) diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 4df1a1f..8915fcf 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -67,6 +67,14 @@ public class Conference extends BaseEntity { @Fetch(FetchMode.SUBSELECT) private List users = new ArrayList<>(); + @Column(name = "create_date") + @Temporal(TemporalType.TIMESTAMP) + private Date createDate = new Date(); + + @Column(name = "update_date") + @Temporal(TemporalType.TIMESTAMP) + private Date updateDate = new Date(); + public String getTitle() { return title; } diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index 369568f..88949e7 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -13,6 +13,7 @@ import ru.ulstu.timeline.model.Event; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -24,6 +25,8 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.Comparator; @@ -98,6 +101,14 @@ public class Grant extends BaseEntity implements UserContainer { @JoinColumn(name = "grant_id") private List events = new ArrayList<>(); + @Column(name = "create_date") + @Temporal(TemporalType.TIMESTAMP) + private Date createDate = new Date(); + + @Column(name = "update_date") + @Temporal(TemporalType.TIMESTAMP) + private Date updateDate = new Date(); + public GrantStatus getStatus() { return status; } diff --git a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java index 876a8c1..9e66ac9 100644 --- a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java +++ b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java @@ -4,8 +4,10 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import ru.ulstu.grant.model.Grant; +import ru.ulstu.user.model.User; import ru.ulstu.name.BaseRepository; +import java.util.Date; import java.util.List; public interface GrantRepository extends JpaRepository, BaseRepository { @@ -20,4 +22,11 @@ public interface GrantRepository extends JpaRepository, BaseRepo @Query("SELECT g FROM Grant g WHERE (g.status <> 'SKIPPED') AND (g.status <> 'COMPLETED')") List findAllActive(); + + @Query("SELECT g FROM Grant g WHERE (:user IS NULL OR user MEMBER OF g.authors) AND (:status IS NULL OR :status = p.status) " + + " AND (:dateFrom IS NULL OR :dateFrom < p.updateDate) AND (:dateTo IS NULL OR :dateTo > p.updateDate)") + List findByAuthorHasAndStatus(@Param("user") User user, + @Param("status") Grant.GrantStatus status, + @Param("dateFrom") Date dateFrom, + @Param("dateTo") Date dateTo); } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 3243ace..385d939 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -334,4 +334,8 @@ public class GrantService extends BaseService { private List findAllActive() { return grantRepository.findAllActive(); } + + public List getByUserAndStatusAndInterval(User user, Grant.GrantStatus status, Date dateFrom, Date dateTo) { + return grantRepository.findByAuthorHasAndStatus(user, status, dateFrom, dateTo); + } } diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java index 42d3703..f4cd800 100644 --- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.repository.query.Param; import ru.ulstu.paper.model.Paper; import ru.ulstu.user.model.User; +import java.util.Date; import java.util.List; public interface PaperRepository extends JpaRepository { @@ -24,4 +25,11 @@ public interface PaperRepository extends JpaRepository { List findByConferencesIsNullAndStatusNot(Paper.PaperStatus status); List findByIdNotInAndConferencesIsNullAndStatusNot(List paperIds, Paper.PaperStatus status); + + @Query("SELECT p FROM Paper g WHERE (:user IS NULL OR user MEMBER OF p.authors) AND (:status IS NULL OR :status = p.status) " + + "AND (:dateFrom IS NULL OR :dateFrom < p.updateDate) AND (:dateTo IS NULL OR :dateTo > p.updateDate)") + List findByAuthorHasAndStatus(@Param("user") User user, + @Param("status") Paper.PaperStatus status, + @Param("dateFrom") Date dateFrom, + @Param("dateTo") Date dateTo); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 013ce72..aa00e54 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -7,6 +7,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.service.FileService; +import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.AutoCompleteData; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; @@ -391,4 +392,8 @@ public class PaperService { autoCompleteData.setPublishers(referenceRepository.findDistinctPublishers()); return autoCompleteData; } + + public List getByUserAndStatusAndInterval(User user, Paper.PaperStatus status, Date dateFrom, Date dateTo) { + return paperRepository.findByAuthorHasAndStatus(user, status, dateFrom, dateTo); + } } diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index 3d11583..a404eb4 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -9,6 +9,7 @@ import ru.ulstu.grant.model.Grant; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -17,9 +18,12 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.HashSet; +import java.util.Date; import java.util.List; import java.util.Set; @@ -72,6 +76,14 @@ public class Project extends BaseEntity implements UserContainer { @ManyToMany(fetch = FetchType.LAZY) private List executors = new ArrayList<>(); + @Column(name = "create_date") + @Temporal(TemporalType.TIMESTAMP) + private Date createDate = new Date(); + + @Column(name = "update_date") + @Temporal(TemporalType.TIMESTAMP) + private Date updateDate = new Date(); + public String getTitle() { return title; } diff --git a/src/main/java/ru/ulstu/project/repository/ProjectRepository.java b/src/main/java/ru/ulstu/project/repository/ProjectRepository.java index 6a78075..63ab6c7 100644 --- a/src/main/java/ru/ulstu/project/repository/ProjectRepository.java +++ b/src/main/java/ru/ulstu/project/repository/ProjectRepository.java @@ -1,8 +1,21 @@ package ru.ulstu.project.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.paper.model.Paper; import ru.ulstu.project.model.Project; +import ru.ulstu.user.model.User; + +import java.util.Date; +import java.util.List; public interface ProjectRepository extends JpaRepository { + @Query("SELECT p FROM Project p WHERE (:user IS NULL OR user MEMBER OF p.authors) AND (:status IS NULL OR :status = p.status) " + + "AND (:dateFrom IS NULL OR :dateFrom < p.updateDate) AND (:dateTo IS NULL OR :dateTo > p.updateDate)") + List findByAuthorHasAndStatus(@Param("user") User user, + @Param("status") Project.ProjectStatus status, + @Param("dateFrom") Date dateFrom, + @Param("dateTo") Date dateTo); } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index a8444a6..78e9f99 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -11,9 +11,11 @@ import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.repository.ProjectRepository; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; +import ru.ulstu.user.model.User; import java.io.IOException; import java.util.Arrays; +import java.util.Date; import java.util.List; import static org.springframework.util.ObjectUtils.isEmpty; @@ -126,6 +128,10 @@ public class ProjectService { return projectRepository.findOne(id); } + public List getByUserAndStatusAndInterval(User user, Project.ProjectStatus status, Date dateFrom, Date dateTo) { + return projectRepository.findByAuthorHasAndStatus(user, status, dateFrom, dateTo); + } + public List getProjectExecutors(ProjectDto projectDto) { List users = userService.findAll(); return users; diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 0004268..db75aec 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -20,6 +20,12 @@ import ru.ulstu.core.error.EntityIdIsNullException; import ru.ulstu.core.jpa.OffsetablePageRequest; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.response.PageableItems; +import ru.ulstu.grant.model.Grant; +import ru.ulstu.grant.service.GrantService; +import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.service.PaperService; +import ru.ulstu.project.model.Project; +import ru.ulstu.project.service.ProjectService; import ru.ulstu.user.error.UserActivationError; import ru.ulstu.user.error.UserEmailExistsException; import ru.ulstu.user.error.UserIdExistsException; -- 2.34.1 From cbae48c23ea937972dbaddba9a025c04390b4918 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Tue, 11 Jun 2019 01:18:49 +0400 Subject: [PATCH 6/7] #93 users activities analytycs --- .../controller/ActivityController.java | 17 ++++++ .../{user => activity}/model/Activity.java | 3 +- .../model/ActivityElement.java | 6 +- .../repository/ActivityRepository.java | 4 +- .../activity/service/ActivityService.java | 56 +++++++++++++++++++ .../ulstu/core/model/AuthFailureHandler.java | 2 +- src/main/java/ru/ulstu/grant/model/Grant.java | 15 ++++- .../ru/ulstu/grant/service/GrantService.java | 12 +++- src/main/java/ru/ulstu/paper/model/Paper.java | 12 ++++ .../ru/ulstu/paper/service/PaperService.java | 13 +++-- .../java/ru/ulstu/project/model/Project.java | 12 ++++ .../ulstu/project/service/ProjectService.java | 19 ++++--- .../ulstu/user/controller/UserController.java | 10 +++- .../ru/ulstu/user/service/UserService.java | 41 +------------- src/main/resources/application.properties | 6 +- .../resources/templates/users/activities.html | 3 +- 16 files changed, 159 insertions(+), 72 deletions(-) create mode 100644 src/main/java/ru/ulstu/activity/controller/ActivityController.java rename src/main/java/ru/ulstu/{user => activity}/model/Activity.java (96%) rename src/main/java/ru/ulstu/{user => activity}/model/ActivityElement.java (87%) rename src/main/java/ru/ulstu/{user => activity}/repository/ActivityRepository.java (90%) create mode 100644 src/main/java/ru/ulstu/activity/service/ActivityService.java diff --git a/src/main/java/ru/ulstu/activity/controller/ActivityController.java b/src/main/java/ru/ulstu/activity/controller/ActivityController.java new file mode 100644 index 0000000..3aaf43e --- /dev/null +++ b/src/main/java/ru/ulstu/activity/controller/ActivityController.java @@ -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; + } + + +} diff --git a/src/main/java/ru/ulstu/user/model/Activity.java b/src/main/java/ru/ulstu/activity/model/Activity.java similarity index 96% rename from src/main/java/ru/ulstu/user/model/Activity.java rename to src/main/java/ru/ulstu/activity/model/Activity.java index 74849dc..3c5e3e0 100644 --- a/src/main/java/ru/ulstu/user/model/Activity.java +++ b/src/main/java/ru/ulstu/activity/model/Activity.java @@ -1,7 +1,8 @@ -package ru.ulstu.user.model; +package ru.ulstu.activity.model; import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.user.model.User; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/src/main/java/ru/ulstu/user/model/ActivityElement.java b/src/main/java/ru/ulstu/activity/model/ActivityElement.java similarity index 87% rename from src/main/java/ru/ulstu/user/model/ActivityElement.java rename to src/main/java/ru/ulstu/activity/model/ActivityElement.java index f1e42b6..4e4c716 100644 --- a/src/main/java/ru/ulstu/user/model/ActivityElement.java +++ b/src/main/java/ru/ulstu/activity/model/ActivityElement.java @@ -1,8 +1,8 @@ -package ru.ulstu.user.model; +package ru.ulstu.activity.model; public class ActivityElement { - private int startedCount; - private int completedCount; + private int startedCount = 0; + private int completedCount = 0; public ActivityElement() {} diff --git a/src/main/java/ru/ulstu/user/repository/ActivityRepository.java b/src/main/java/ru/ulstu/activity/repository/ActivityRepository.java similarity index 90% rename from src/main/java/ru/ulstu/user/repository/ActivityRepository.java rename to src/main/java/ru/ulstu/activity/repository/ActivityRepository.java index cc0ec4e..993b339 100644 --- a/src/main/java/ru/ulstu/user/repository/ActivityRepository.java +++ b/src/main/java/ru/ulstu/activity/repository/ActivityRepository.java @@ -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.Query; 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.List; diff --git a/src/main/java/ru/ulstu/activity/service/ActivityService.java b/src/main/java/ru/ulstu/activity/service/ActivityService.java new file mode 100644 index 0000000..980d272 --- /dev/null +++ b/src/main/java/ru/ulstu/activity/service/ActivityService.java @@ -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 users, Activity.ActivityState state) { + List activities = new ArrayList<>(); + for (User user : users) { + activities.add(new Activity(user, state)); + } + activityRepository.save(activities); + } + + public Map getUsersActivity(Integer userId, Date dateFrom, Date dateTo) { + List activities = activityRepository.getByUserAndDateInterval(userId, dateFrom, dateTo); + Map 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; + } +} diff --git a/src/main/java/ru/ulstu/core/model/AuthFailureHandler.java b/src/main/java/ru/ulstu/core/model/AuthFailureHandler.java index 8b6bd9d..e878622 100644 --- a/src/main/java/ru/ulstu/core/model/AuthFailureHandler.java +++ b/src/main/java/ru/ulstu/core/model/AuthFailureHandler.java @@ -14,7 +14,7 @@ public class AuthFailureHandler implements AuthenticationFailureHandler { @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException ex) throws IOException { - if (ex.getClass() == UserBlockedException.class) { + if (ex.getCause() instanceof UserBlockedException) { response.sendRedirect("/users/block"); } } diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index 3a50a75..a275b19 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -11,11 +11,11 @@ import ru.ulstu.file.model.FileData; import ru.ulstu.paper.model.Paper; import ru.ulstu.project.model.Project; import ru.ulstu.timeline.model.Event; +import ru.ulstu.activity.model.Activity; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; import javax.persistence.DiscriminatorValue; -import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -27,8 +27,6 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.Collections; @@ -176,6 +174,17 @@ public class Grant extends BaseEntity implements UserActivity, EventSource { 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() { return leader; } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 99387c7..dbb2a44 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.Errors; +import ru.ulstu.activity.service.ActivityService; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.model.FileDataDto; @@ -26,6 +27,7 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.text.ParseException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Date; @@ -53,6 +55,7 @@ public class GrantService extends BaseService { private final GrantNotificationService grantNotificationService; private final KiasService kiasService; private final PingService pingService; + private final ActivityService activityService; public GrantService(GrantRepository grantRepository, FileService fileService, @@ -63,7 +66,8 @@ public class GrantService extends BaseService { EventService eventService, GrantNotificationService grantNotificationService, KiasService kiasService, - PingService pingService) { + PingService pingService, + ActivityService activityService) { this.grantRepository = grantRepository; this.kiasService = kiasService; this.baseRepository = grantRepository; @@ -75,6 +79,7 @@ public class GrantService extends BaseService { this.eventService = eventService; this.grantNotificationService = grantNotificationService; this.pingService = pingService; + this.activityService = activityService; } public GrantDto getExistGrantById(Integer id) { @@ -95,6 +100,7 @@ public class GrantService extends BaseService { Grant newGrant = copyFromDto(new Grant(), grantDto); newGrant = grantRepository.save(newGrant); eventService.createFromObject(newGrant, Collections.emptyList(), false, "гранта"); + activityService.createActivity(new ArrayList<>(newGrant.getAuthors()), newGrant.getCommonActivityState()); grantNotificationService.sendCreateNotification(newGrant); return newGrant; } @@ -137,6 +143,7 @@ public class GrantService extends BaseService { Grant grant = findById(grantDto.getId()); Set oldAuthors = new HashSet<>(grant.getAuthors()); User oldLeader = grant.getLeader(); + Grant.GrantStatus oldStatus = grant.getStatus(); for (FileDataDto file : grantDto.getFiles().stream() .filter(f -> f.isDeleted() && f.getId() != null) .collect(toList())) { @@ -158,6 +165,9 @@ public class GrantService extends BaseService { if (grant.getLeader() != oldLeader) { grantNotificationService.sendLeaderChangeNotification(grant, oldLeader); } + if(grant.getStatus() != oldStatus) { + activityService.createActivity(new ArrayList<>(grant.getAuthors()), grant.getCommonActivityState()); + } eventService.updateGrantDeadlines(grant); return grant.getId(); } diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 32a1e5e..ccf3289 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -11,6 +11,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.grant.model.Grant; import ru.ulstu.timeline.model.Event; +import ru.ulstu.activity.model.Activity; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; @@ -323,4 +324,15 @@ public class Paper extends BaseEntity implements UserActivity, EventSource { public int hashCode() { 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; + } + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 0275000..18fb76f 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -3,6 +3,7 @@ package ru.ulstu.paper.service; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.activity.service.ActivityService; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.model.FileDataDto; @@ -57,6 +58,7 @@ public class PaperService { private final EventService eventService; private final ReferenceRepository referenceRepository; private final PingService pingService; + private final ActivityService activityService; public PaperService(PaperRepository paperRepository, ReferenceRepository referenceRepository, @@ -65,7 +67,8 @@ public class PaperService { UserService userService, DeadlineService deadlineService, EventService eventService, - PingService pingService) { + PingService pingService, + ActivityService activityService) { this.paperRepository = paperRepository; this.referenceRepository = referenceRepository; this.fileService = fileService; @@ -74,6 +77,7 @@ public class PaperService { this.deadlineService = deadlineService; this.eventService = eventService; this.pingService = pingService; + this.activityService = activityService; } public List findAll() { @@ -202,10 +206,7 @@ public class PaperService { if (paper.getStatus() != oldStatus) { paperNotificationService.statusChangeNotification(paper, oldStatus); - - if (paper.getStatus() == Paper.PaperStatus.ON_PREPARATION) { - userService.createActivityTookToWork(new ArrayList<>(paper.getAuthors())); - } + activityService.createActivity(new ArrayList<>(paper.getAuthors()), paper.getCommonActivityState()); } return paper.getId(); @@ -246,7 +247,9 @@ public class PaperService { paper = paperRepository.save(paper); paperNotificationService.sendCreateNotification(paper); + eventService.createFromPaper(paper); + activityService.createActivity(new ArrayList<>(paper.getAuthors()), paper.getCommonActivityState()); return paper; } diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index 6c60052..224c91e 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -10,6 +10,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.grant.model.Grant; import ru.ulstu.timeline.model.Event; +import ru.ulstu.activity.model.Activity; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; @@ -106,6 +107,17 @@ public class Project extends BaseEntity implements UserActivity, EventSource { 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) { this.title = title; } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index 2c5d91c..92340c7 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -3,6 +3,7 @@ package ru.ulstu.project.service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.util.StringUtils; +import ru.ulstu.activity.service.ActivityService; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.service.FileService; @@ -17,6 +18,7 @@ import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -37,14 +39,15 @@ public class ProjectService { private final EventService eventService; private final UserService userService; private final PingService pingService; - + private final ActivityService activityService; public ProjectService(ProjectRepository projectRepository, DeadlineService deadlineService, GrantRepository grantRepository, FileService fileService, EventService eventService, UserService userService, - PingService pingService) { + PingService pingService, + ActivityService activityService) { this.projectRepository = projectRepository; this.deadlineService = deadlineService; this.grantRepository = grantRepository; @@ -52,6 +55,7 @@ public class ProjectService { this.eventService = eventService; this.userService = userService; this.pingService = pingService; + this.activityService = activityService; } public List findAll() { @@ -77,15 +81,17 @@ public class ProjectService { Project newProject = copyFromDto(new Project(), projectDto); newProject = projectRepository.save(newProject); eventService.createFromObject(newProject, Collections.emptyList(), false, "проекта"); - if (projectDto.getStatus() == Project.ProjectStatus.IN_WORK) { - userService.createActivityTookToWork(newProject.getExecutors()); - } + activityService.createActivity(new ArrayList<>(newProject.getExecutors()), newProject.getCommonActivityState()); + return newProject; } @Transactional public Project update(ProjectDto projectDto) throws IOException { Project project = projectRepository.findOne(projectDto.getId()); + if (project.getStatus() != projectDto.getStatus()) { + activityService.createActivity(new ArrayList<>(project.getExecutors()), project.getCommonActivityState()); + } projectRepository.save(copyFromDto(project, projectDto)); eventService.updateProjectDeadlines(project); for (FileDataDto file : projectDto.getFiles().stream() @@ -93,9 +99,6 @@ public class ProjectService { .collect(toList())) { fileService.delete(file.getId()); } - if (projectDto.getStatus() == Project.ProjectStatus.IN_WORK) { - userService.createActivityTookToWork(project.getExecutors()); - } return project; } diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index 0592417..2fdec8e 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import ru.ulstu.activity.service.ActivityService; import ru.ulstu.configuration.Constants; import ru.ulstu.core.model.response.PageableItems; 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.OdinVoid; 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.UserDto; import ru.ulstu.user.model.UserListDto; @@ -59,16 +60,19 @@ public class UserController extends OdinController { private final UserSessionService userSessionService; private final OdinService odinRolesService; private final OdinService odinSessionsService; + private final ActivityService activityService; public UserController(UserService userService, UserSessionService userSessionService, OdinService odinRolesService, - OdinService odinSessionsService) { + OdinService odinSessionsService, + ActivityService activityService) { super(UserListDto.class, UserDto.class); this.userService = userService; this.userSessionService = userSessionService; this.odinRolesService = odinRolesService; this.odinSessionsService = odinSessionsService; + this.activityService = activityService; } @GetMapping(ROLES_URL) @@ -189,6 +193,6 @@ public class UserController extends OdinController { public Response> 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)); + return new Response<>(activityService.getUsersActivity(userId, dateFrom, dateTo)); } } diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 1f28afc..0145182 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -34,8 +34,6 @@ 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.ActivityElement; import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; 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.UserRoleConstants; 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.UserRoleRepository; import ru.ulstu.user.util.UserUtils; @@ -54,9 +52,7 @@ import ru.ulstu.utils.timetable.model.Lesson; import javax.mail.MessagingException; import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -439,39 +435,4 @@ public class UserService implements UserDetailsService { userToBlock.setBlocker(getCurrentUser()); userRepository.save(userToBlock); } - - public void createActivityTookToWork(List users) { - List activities = new ArrayList<>(); - for (User user : users) { - activities.add(new Activity(user, Activity.ActivityState.TOOK_IN_WORK)); - } - activityRepository.save(activities); - } - - public void createActivityCompleted(List users) { - List activities = new ArrayList<>(); - for (User user : users) { - activities.add(new Activity(user, Activity.ActivityState.COMPLETED)); - } - activityRepository.save(activities); - } - - public Map getUsersActivity(Integer userId, Date dateFrom, Date dateTo) { - List activities = activityRepository.getByUserAndDateInterval(userId, dateFrom, dateTo); - Map 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; - } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b95d006..7b30ec0 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -18,7 +18,7 @@ logging.level.com.gargoylesoftware.htmlunit=ERROR # Mail Settings spring.mail.host=smtp.yandex.ru 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.properties.mail.smtp.auth=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 spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker spring.datasource.username=postgres -spring.datasource.password=password +spring.datasource.password=postgres spring.datasource.driverclassName=org.postgresql.Driver spring.jpa.hibernate.ddl-auto=validate # Liquibase Settings @@ -37,7 +37,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=false +ng-tracker.dev-mode=true ng-tracker.debug_email= ng-tracker.use-https=false ng-tracker.check-run=false diff --git a/src/main/resources/templates/users/activities.html b/src/main/resources/templates/users/activities.html index f5c8e1d..33fc831 100644 --- a/src/main/resources/templates/users/activities.html +++ b/src/main/resources/templates/users/activities.html @@ -9,8 +9,7 @@ -- 2.34.1 From e81ee4d36b45f0ed42e62372222fb4f70820de3f Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Tue, 11 Jun 2019 01:20:34 +0400 Subject: [PATCH 7/7] #93 codestyle --- src/main/java/ru/ulstu/activity/model/ActivityElement.java | 7 ++++--- src/main/java/ru/ulstu/grant/service/GrantService.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/activity/model/ActivityElement.java b/src/main/java/ru/ulstu/activity/model/ActivityElement.java index 4e4c716..17fecce 100644 --- a/src/main/java/ru/ulstu/activity/model/ActivityElement.java +++ b/src/main/java/ru/ulstu/activity/model/ActivityElement.java @@ -4,7 +4,8 @@ public class ActivityElement { private int startedCount = 0; private int completedCount = 0; - public ActivityElement() {} + public ActivityElement() { + } public ActivityElement(int startedCount, int completedCount) { this.startedCount = startedCount; @@ -28,10 +29,10 @@ public class ActivityElement { } public void incrementStartedCount() { - this.startedCount ++; + this.startedCount++; } public void incrementCompletedCount() { - this.completedCount ++; + this.completedCount++; } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index dbb2a44..1892629 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -165,7 +165,7 @@ public class GrantService extends BaseService { if (grant.getLeader() != oldLeader) { grantNotificationService.sendLeaderChangeNotification(grant, oldLeader); } - if(grant.getStatus() != oldStatus) { + if (grant.getStatus() != oldStatus) { activityService.createActivity(new ArrayList<>(grant.getAuthors()), grant.getCommonActivityState()); } eventService.updateGrantDeadlines(grant); -- 2.34.1