#90 diagrams
This commit is contained in:
parent
59bc0dbd34
commit
49e407f455
@ -2,8 +2,8 @@ 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;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@ -27,13 +27,17 @@ import ru.ulstu.user.model.UserResetPasswordDto;
|
||||
import ru.ulstu.user.model.UserRoleConstants;
|
||||
import ru.ulstu.user.model.UserRoleDto;
|
||||
import ru.ulstu.user.model.UserSessionListDto;
|
||||
import ru.ulstu.user.model.UserWorkloadDto;
|
||||
import ru.ulstu.user.service.UserService;
|
||||
import ru.ulstu.user.service.UserSessionService;
|
||||
import ru.ulstu.user.service.UserWorkloadService;
|
||||
|
||||
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;
|
||||
@ -57,8 +61,10 @@ public class UserController extends OdinController<UserListDto, UserDto> {
|
||||
private final UserSessionService userSessionService;
|
||||
private final OdinService<UserRoleDto, UserRoleDto> odinRolesService;
|
||||
private final OdinService<UserSessionListDto, OdinVoid> odinSessionsService;
|
||||
private final UserWorkloadService userWorkloadService;
|
||||
|
||||
public UserController(UserService userService,
|
||||
UserWorkloadService userWorkloadService,
|
||||
UserSessionService userSessionService,
|
||||
OdinService<UserRoleDto, UserRoleDto> odinRolesService,
|
||||
OdinService<UserSessionListDto, OdinVoid> odinSessionsService) {
|
||||
@ -67,6 +73,7 @@ public class UserController extends OdinController<UserListDto, UserDto> {
|
||||
this.userSessionService = userSessionService;
|
||||
this.odinRolesService = odinRolesService;
|
||||
this.odinSessionsService = odinSessionsService;
|
||||
this.userWorkloadService = userWorkloadService;
|
||||
}
|
||||
|
||||
@GetMapping(ROLES_URL)
|
||||
@ -172,4 +179,22 @@ public class UserController extends OdinController<UserListDto, UserDto> {
|
||||
public void inviteUser(@RequestParam("email") String email) {
|
||||
userService.inviteUser(email);
|
||||
}
|
||||
|
||||
@PostMapping("/setWorkload")
|
||||
public void setWeekHours(@RequestBody UserWorkloadDto workload, HttpServletRequest request) {
|
||||
HttpSession session = request.getSession(false);
|
||||
final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString();
|
||||
User user = userSessionService.getUserBySessionId(sessionId);
|
||||
userWorkloadService.setUserWorkload(user, workload);
|
||||
}
|
||||
|
||||
@GetMapping("/getWorkloads")
|
||||
public Response<List<UserWorkloadDto>> getWorklogs(@RequestParam(name = "dateFrom") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateFrom,
|
||||
@RequestParam(name = "dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo,
|
||||
HttpServletRequest request) {
|
||||
HttpSession session = request.getSession(false);
|
||||
final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString();
|
||||
User user = userSessionService.getUserBySessionId(sessionId);
|
||||
return new Response<>(userWorkloadService.getUserWorkloads(user, dateFrom, dateTo));
|
||||
}
|
||||
}
|
||||
|
68
src/main/java/ru/ulstu/user/model/UserWorkload.java
Normal file
68
src/main/java/ru/ulstu/user/model/UserWorkload.java
Normal file
@ -0,0 +1,68 @@
|
||||
package ru.ulstu.user.model;
|
||||
|
||||
import ru.ulstu.core.model.BaseEntity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Entity
|
||||
@Table(name = "users_workloads")
|
||||
public class UserWorkload extends BaseEntity {
|
||||
|
||||
@Column(name = "hours")
|
||||
private int hours;
|
||||
|
||||
@NotNull
|
||||
@Temporal(value = TemporalType.TIMESTAMP)
|
||||
@Column(name = "date_from")
|
||||
private Date dateFrom;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "date_to")
|
||||
@Temporal(value = TemporalType.TIMESTAMP)
|
||||
private Date dateTo;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "user_id")
|
||||
private User user;
|
||||
|
||||
public int getHours() {
|
||||
return hours;
|
||||
}
|
||||
|
||||
public void setHours(int hours) {
|
||||
this.hours = hours;
|
||||
}
|
||||
|
||||
public Date getDateFrom() {
|
||||
return dateFrom;
|
||||
}
|
||||
|
||||
public void setDateFrom(Date dateFrom) {
|
||||
this.dateFrom = dateFrom;
|
||||
}
|
||||
|
||||
public Date getDateTo() {
|
||||
return dateTo;
|
||||
}
|
||||
|
||||
public void setDateTo(Date dateTo) {
|
||||
this.dateTo = dateTo;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
}
|
48
src/main/java/ru/ulstu/user/model/UserWorkloadDto.java
Normal file
48
src/main/java/ru/ulstu/user/model/UserWorkloadDto.java
Normal file
@ -0,0 +1,48 @@
|
||||
package ru.ulstu.user.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class UserWorkloadDto {
|
||||
private int hours;
|
||||
private Date dateFrom;
|
||||
private Date dateTo;
|
||||
|
||||
public UserWorkloadDto() {
|
||||
}
|
||||
|
||||
public UserWorkloadDto(int hours, Date dateFrom, Date dateTo) {
|
||||
this.hours = hours;
|
||||
this.dateFrom = dateFrom;
|
||||
this.dateTo = dateTo;
|
||||
}
|
||||
|
||||
public UserWorkloadDto(UserWorkload workload) {
|
||||
this.hours = workload.getHours();
|
||||
this.dateFrom = workload.getDateFrom();
|
||||
this.dateTo = workload.getDateTo();
|
||||
}
|
||||
|
||||
public int getHours() {
|
||||
return hours;
|
||||
}
|
||||
|
||||
public void setHours(int hours) {
|
||||
this.hours = hours;
|
||||
}
|
||||
|
||||
public Date getDateFrom() {
|
||||
return dateFrom;
|
||||
}
|
||||
|
||||
public void setDateFrom(Date dateFrom) {
|
||||
this.dateFrom = dateFrom;
|
||||
}
|
||||
|
||||
public Date getDateTo() {
|
||||
return dateTo;
|
||||
}
|
||||
|
||||
public void setDateTo(Date dateTo) {
|
||||
this.dateTo = dateTo;
|
||||
}
|
||||
}
|
@ -0,0 +1,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.User;
|
||||
import ru.ulstu.user.model.UserWorkload;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public interface UserWorkloadRepository extends JpaRepository<UserWorkload, Integer> {
|
||||
List<UserWorkload> findAllByUser(User user);
|
||||
|
||||
@Query("SELECT uw FROM UserWorkload uw WHERE (user = :user) AND (dateFrom >= :dateFrom) AND (dateTo <= :dateTo) ORDER BY uw.dateFrom")
|
||||
List<UserWorkload> findByUserAndInterval(@Param("user") User user, @Param("dateFrom") Date dateFrom, @Param("dateTo") Date dateTo);
|
||||
}
|
48
src/main/java/ru/ulstu/user/service/UserWorkloadService.java
Normal file
48
src/main/java/ru/ulstu/user/service/UserWorkloadService.java
Normal file
@ -0,0 +1,48 @@
|
||||
package ru.ulstu.user.service;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ulstu.configuration.ApplicationProperties;
|
||||
import ru.ulstu.user.model.User;
|
||||
import ru.ulstu.user.model.UserWorkload;
|
||||
import ru.ulstu.user.model.UserWorkloadDto;
|
||||
import ru.ulstu.user.repository.UserWorkloadRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class UserWorkloadService {
|
||||
private final Logger log = LoggerFactory.getLogger(UserWorkloadService.class);
|
||||
private final ApplicationProperties applicationProperties;
|
||||
private final UserWorkloadRepository userWorkloadRepository;
|
||||
|
||||
public UserWorkloadService(UserWorkloadRepository userWorkloadRepository,
|
||||
ApplicationProperties applicationProperties) {
|
||||
this.applicationProperties = applicationProperties;
|
||||
this.userWorkloadRepository = userWorkloadRepository;
|
||||
}
|
||||
|
||||
public void setUserWorkload(User user, UserWorkloadDto userWorkloadDto) {
|
||||
UserWorkload workload = new UserWorkload();
|
||||
|
||||
workload.setHours(userWorkloadDto.getHours());
|
||||
workload.setDateFrom(userWorkloadDto.getDateFrom());
|
||||
workload.setDateTo(userWorkloadDto.getDateTo());
|
||||
workload.setUser(user);
|
||||
|
||||
userWorkloadRepository.save(workload);
|
||||
}
|
||||
|
||||
public List<UserWorkloadDto> getUserWorkloads(User user, Date dateFrom, Date dateTo) {
|
||||
List<UserWorkloadDto> workloadDtos = new ArrayList<>();
|
||||
for (UserWorkload workload : userWorkloadRepository.findByUserAndInterval(user, dateFrom, dateTo)) {
|
||||
workloadDtos.add(new UserWorkloadDto(workload));
|
||||
}
|
||||
return workloadDtos;
|
||||
}
|
||||
}
|
22
src/main/resources/db/changelog-20190521_000000-schema.xml
Normal file
22
src/main/resources/db/changelog-20190521_000000-schema.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?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="20190521_000000-1">
|
||||
<createTable tableName="users_workloads">
|
||||
<column name="id" type="integer">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="version" type="INTEGER"/>
|
||||
<column name="hours" type="integer"/>
|
||||
<column name="date_from" type="timestamp"/>
|
||||
<column name="date_to" type="timestamp"/>
|
||||
<column name="user_id" type="integer"/>
|
||||
</createTable>
|
||||
<addPrimaryKey tableName="users_workloads" columnNames="id" constraintName="users_workloads_pkey"/>
|
||||
<addForeignKeyConstraint baseTableName="users_workloads" baseColumnNames="user_id"
|
||||
constraintName="fk_user__workload" referencedTableName="users"
|
||||
referencedColumnNames="id"/>
|
||||
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
@ -42,4 +42,5 @@
|
||||
<include file="db/changelog-20190507_000000-schema.xml"/>
|
||||
<include file="db/changelog-20190507_000001-schema.xml"/>
|
||||
<include file="db/changelog-20190511_000000-schema.xml"/>
|
||||
<include file="db/changelog-20190521_000000-schema.xml"/>
|
||||
</databaseChangeLog>
|
@ -56,3 +56,55 @@ function inviteUser() {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function setUserWorkload() {
|
||||
$.ajax({
|
||||
url:"/api/1.0/users/setWorkload",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
method: "POST",
|
||||
data: JSON.stringify({
|
||||
"hours": document.getElementById("hours").value,
|
||||
"dateFrom": document.getElementById("dateFrom").value,
|
||||
"dateTo": document.getElementById("dateTo").value,
|
||||
}),
|
||||
success: function() {
|
||||
showFeedbackMessage("Время успешно зарегистрировано", MessageTypesEnum.SUCCESS)
|
||||
},
|
||||
error: function(errorData) {
|
||||
showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function drawChart() {
|
||||
$.ajax({
|
||||
url:"/api/1.0/users/getWorkloads?dateFrom=" + document.getElementById("dateFrom").value + "&dateTo=" + document.getElementById("dateTo").value,
|
||||
contentType: "application/json; charset=utf-8",
|
||||
method: "GET",
|
||||
success: function(response) {
|
||||
if (response.data.length == 0) {
|
||||
return;
|
||||
}
|
||||
array = [['Недели', '']]
|
||||
response.data.forEach(function(element) {
|
||||
dateFrom = new Date(element.dateFrom)
|
||||
dateTo = new Date(element.dateTo)
|
||||
dateStr = dateFrom.getDate() + '.' + (dateFrom.getMonth() + 1) + '.' + dateFrom.getFullYear() + ' - ' +
|
||||
dateTo.getDate() + '.' + (dateTo.getMonth() + 1) + '.' + dateTo.getFullYear();
|
||||
array.push([dateStr, element.hours])
|
||||
})
|
||||
|
||||
var data = google.visualization.arrayToDataTable(array);
|
||||
var options = {
|
||||
title: 'Рабочие часы по неделям',
|
||||
hAxis: {title: 'Неделя'},
|
||||
vAxis: {title: 'Часы'}
|
||||
};
|
||||
var chart = new google.visualization.ColumnChart(document.getElementById('oil'));
|
||||
chart.draw(data, options);
|
||||
},
|
||||
error: function(errorData) {
|
||||
showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -109,6 +109,7 @@
|
||||
<script src="/js/core.js"></script>
|
||||
<script src="/js/config.js"></script>
|
||||
<script src="/js/odin.js"></script>
|
||||
<script src="/js/users.js"></script>
|
||||
<script th:inline="javascript">
|
||||
|
||||
/*<![CDATA[*/
|
||||
|
@ -1,9 +1,19 @@
|
||||
<!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">
|
||||
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="js/users.js"></script>
|
||||
<script src="js/core.js"></script>
|
||||
<script src="https://www.google.com/jsapi"></script>
|
||||
<script>
|
||||
google.load('visualization', '1.0', {'packages':['corechart']});
|
||||
google.setOnLoadCallback(drawChart);
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@ -19,53 +29,97 @@
|
||||
<hr/>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<form id="profile-form" method="post" th:action="@{'/users/profile'}"
|
||||
th:object="${userDto}">
|
||||
<input type="hidden" name="id" th:field="*{id}"/>
|
||||
<div class="form-group">
|
||||
<label for="firstName">Имя:</label>
|
||||
<input class="form-control" id="firstName" type="text"
|
||||
placeholder="Имя"
|
||||
th:field="*{firstName}"/>
|
||||
<p th:if="${#fields.hasErrors('firstName')}" th:errors="*{firstName}"
|
||||
class="alert alert-danger">Incorrect firstName</p>
|
||||
<p class="help-block text-danger"></p>
|
||||
<nav>
|
||||
<div class="nav nav-tabs" id="nav-tab" role="tablist">
|
||||
<a class="nav-item nav-link active" id="nav-main-tab" data-toggle="tab"
|
||||
href="#nav-main" role="tab" aria-controls="nav-main" aria-selected="true">Статья</a>
|
||||
<a class="nav-item nav-link" id="nav-latex-tab" data-toggle="tab"
|
||||
href="#nav-workload" role="tab" aria-controls="nav-workload" aria-selected="false">Загруженность</a>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lastName">Фамилия:</label>
|
||||
<input class="form-control" id="lastName" type="text"
|
||||
placeholder="lastName"
|
||||
th:field="*{lastName}"/>
|
||||
<p th:if="${#fields.hasErrors('lastName')}" th:errors="*{lastName}"
|
||||
class="alert alert-danger">Incorrect lastName</p>
|
||||
<p class="help-block text-danger"></p>
|
||||
</nav>
|
||||
<div class="tab-content" id="nav-tabContent">
|
||||
<div class="tab-pane fade show active" id="nav-main" role="tabpanel"
|
||||
aria-labelledby="nav-main-tab">
|
||||
<form id="profile-form" method="post" th:action="@{'/users/profile'}"
|
||||
th:object="${userDto}">
|
||||
<input type="hidden" name="id" th:field="*{id}"/>
|
||||
<div class="form-group">
|
||||
<label for="firstName">Имя:</label>
|
||||
<input class="form-control" id="firstName" type="text"
|
||||
placeholder="Имя"
|
||||
th:field="*{firstName}"/>
|
||||
<p th:if="${#fields.hasErrors('firstName')}" th:errors="*{firstName}"
|
||||
class="alert alert-danger">Incorrect firstName</p>
|
||||
<p class="help-block text-danger"></p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lastName">Фамилия:</label>
|
||||
<input class="form-control" id="lastName" type="text"
|
||||
placeholder="lastName"
|
||||
th:field="*{lastName}"/>
|
||||
<p th:if="${#fields.hasErrors('lastName')}" th:errors="*{lastName}"
|
||||
class="alert alert-danger">Incorrect lastName</p>
|
||||
<p class="help-block text-danger"></p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">Email:</label>
|
||||
<input class="form-control" id="email" type="text"
|
||||
placeholder="Email"
|
||||
th:field="*{email}"/>
|
||||
<p th:if="${#fields.hasErrors('email')}" th:errors="*{email}"
|
||||
class="alert alert-danger">Incorrect email</p>
|
||||
<p class="help-block text-danger"></p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="login">Логин:</label>
|
||||
<input class="form-control" id="login" type="text"
|
||||
placeholder="Login"
|
||||
th:field="*{login}"/>
|
||||
<p th:if="${#fields.hasErrors('login')}" th:errors="*{login}"
|
||||
class="alert alert-danger">Incorrect email</p>
|
||||
<p class="help-block text-danger"></p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button id="sendMessageButton" name="save"
|
||||
class="btn btn-success text-uppercase"
|
||||
type="submit">
|
||||
Сохранить
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">Email:</label>
|
||||
<input class="form-control" id="email" type="text"
|
||||
placeholder="Email"
|
||||
th:field="*{email}"/>
|
||||
<p th:if="${#fields.hasErrors('email')}" th:errors="*{email}"
|
||||
class="alert alert-danger">Incorrect email</p>
|
||||
<p class="help-block text-danger"></p>
|
||||
<div class="tab-pane fade" id="nav-workload" role="tabpanel"
|
||||
aria-labelledby="nav-profile-tab">
|
||||
<div class="form-group">
|
||||
<label for="hours">Часы:</label>
|
||||
<input class="form-control" id="hours" type="text"
|
||||
placeholder="Количество часов"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="dateFrom">Дата начала недели:</label>
|
||||
<input class="form-control" id="dateFrom" type="date"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="dateTo">Дата окончания недели:</label>
|
||||
<input class="form-control" id="dateTo" type="date"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button id="sendWorkload" name="save"
|
||||
class="btn btn-success text-uppercase"
|
||||
type="button" onclick="setUserWorkload()">
|
||||
Сохранить часы
|
||||
</button>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button id="drawChartBtn" name="save"
|
||||
class="btn btn-success text-uppercase"
|
||||
type="button" onclick="drawChart()">
|
||||
Показать график
|
||||
</button>
|
||||
</div>
|
||||
<div id="oil" style="width: 500px; height: 400px;"></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="login">Логин:</label>
|
||||
<input class="form-control" id="login" type="text"
|
||||
placeholder="Login"
|
||||
th:field="*{login}"/>
|
||||
<p th:if="${#fields.hasErrors('login')}" th:errors="*{login}"
|
||||
class="alert alert-danger">Incorrect email</p>
|
||||
<p class="help-block text-danger"></p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button id="sendMessageButton" name="save"
|
||||
class="btn btn-success text-uppercase"
|
||||
type="submit">
|
||||
Сохранить
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user