merged with dev
commit
a405267092
@ -0,0 +1,50 @@
|
||||
package ru.ulstu.user.model;
|
||||
|
||||
import ru.ulstu.conference.model.Conference;
|
||||
import ru.ulstu.utils.timetable.model.Lesson;
|
||||
|
||||
public class UserInfoNow {
|
||||
private Lesson lesson;
|
||||
private Conference conference;
|
||||
private User user;
|
||||
private boolean isOnline;
|
||||
|
||||
public UserInfoNow(Lesson lesson, Conference conference, User user, boolean isOnline) {
|
||||
this.lesson = lesson;
|
||||
this.conference = conference;
|
||||
this.user = user;
|
||||
this.isOnline = isOnline;
|
||||
}
|
||||
|
||||
public Lesson getLesson() {
|
||||
return lesson;
|
||||
}
|
||||
|
||||
public void setLesson(Lesson lesson) {
|
||||
this.lesson = lesson;
|
||||
}
|
||||
|
||||
public Conference getConference() {
|
||||
return conference;
|
||||
}
|
||||
|
||||
public void setConference(Conference conference) {
|
||||
this.conference = conference;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return isOnline;
|
||||
}
|
||||
|
||||
public void setOnline(boolean online) {
|
||||
isOnline = online;
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package ru.ulstu.utils.timetable;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import ru.ulstu.core.util.DateUtils;
|
||||
import ru.ulstu.utils.timetable.errors.TimetableClientException;
|
||||
import ru.ulstu.utils.timetable.model.Lesson;
|
||||
import ru.ulstu.utils.timetable.model.TimetableResponse;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class TimetableService {
|
||||
private static final String TIMETABLE_URL = "http://timetable.athene.tech/api/1.0/timetable?filter=%s";
|
||||
private SimpleDateFormat lessonTimeFormat = new SimpleDateFormat("hh:mm");
|
||||
|
||||
private long[] lessonsStarts = new long[] {
|
||||
lessonTimeFormat.parse("8:00:00").getTime(),
|
||||
lessonTimeFormat.parse("9:40:00").getTime(),
|
||||
lessonTimeFormat.parse("11:30:00").getTime(),
|
||||
lessonTimeFormat.parse("13:10:00").getTime(),
|
||||
lessonTimeFormat.parse("14:50:00").getTime(),
|
||||
lessonTimeFormat.parse("16:30:00").getTime(),
|
||||
lessonTimeFormat.parse("18:10:00").getTime(),
|
||||
};
|
||||
|
||||
public TimetableService() throws ParseException {
|
||||
}
|
||||
|
||||
private int getCurrentDay() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
int day = calendar.get(Calendar.DAY_OF_WEEK);
|
||||
return (day + 5) % 7;
|
||||
}
|
||||
|
||||
private int getCurrentLessonNumber() {
|
||||
long lessonDuration = 90 * 60000;
|
||||
Date now = new Date();
|
||||
long timeNow = now.getTime() % (24 * 60 * 60 * 1000L);
|
||||
|
||||
for (int i = 0; i < lessonsStarts.length; i++) {
|
||||
if (timeNow > lessonsStarts[i] && timeNow < lessonsStarts[i] + lessonDuration) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int getCurrentWeek() {
|
||||
Date currentDate = Calendar.getInstance().getTime();
|
||||
currentDate = DateUtils.clearTime(currentDate);
|
||||
|
||||
Calendar firstJan = Calendar.getInstance();
|
||||
firstJan.set(Calendar.MONTH, 0);
|
||||
firstJan.set(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
return (int) Math.round(Math.ceil((((currentDate.getTime() - firstJan.getTime().getTime()) / 86400000)
|
||||
+ DateUtils.addDays(firstJan.getTime(), 1).getTime() / 7) % 2));
|
||||
}
|
||||
|
||||
private TimetableResponse getTimetableForUser(String userFIO) throws RestClientException {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
return restTemplate.getForObject(String.format(TIMETABLE_URL, userFIO), TimetableResponse.class);
|
||||
}
|
||||
|
||||
public Lesson getCurrentLesson(String userFio) {
|
||||
TimetableResponse response;
|
||||
try {
|
||||
response = getTimetableForUser(userFio);
|
||||
} catch (RestClientException e) {
|
||||
e.printStackTrace();
|
||||
throw new TimetableClientException(userFio);
|
||||
}
|
||||
|
||||
int lessonNumber = getCurrentLessonNumber();
|
||||
if (lessonNumber < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Lesson> lessons = response
|
||||
.getResponse()
|
||||
.getWeeks()
|
||||
.get(getCurrentWeek())
|
||||
.getDays()
|
||||
.get(getCurrentDay())
|
||||
.getLessons()
|
||||
.get(lessonNumber);
|
||||
|
||||
if (lessons.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
return new ObjectMapper().convertValue(lessons.get(0), Lesson.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package ru.ulstu.utils.timetable.errors;
|
||||
|
||||
public class TimetableClientException extends RuntimeException {
|
||||
public TimetableClientException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package ru.ulstu.utils.timetable.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Day {
|
||||
|
||||
private Integer day;
|
||||
private List<List<Lesson>> lessons = new ArrayList<>();
|
||||
|
||||
public Integer getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
public void setDay(Integer day) {
|
||||
this.day = day;
|
||||
}
|
||||
|
||||
public List<List<Lesson>> getLessons() {
|
||||
return lessons;
|
||||
}
|
||||
|
||||
public void setLessons(List<List<Lesson>> lessons) {
|
||||
this.lessons = lessons;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package ru.ulstu.utils.timetable.model;
|
||||
|
||||
public class Lesson {
|
||||
private String group;
|
||||
private String nameOfLesson;
|
||||
private String teacher;
|
||||
private String room;
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public String getNameOfLesson() {
|
||||
return nameOfLesson;
|
||||
}
|
||||
|
||||
public String getTeacher() {
|
||||
return teacher;
|
||||
}
|
||||
|
||||
public String getRoom() {
|
||||
return room;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package ru.ulstu.utils.timetable.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Response {
|
||||
|
||||
private List<Week> weeks = new ArrayList<>();
|
||||
|
||||
public List<Week> getWeeks() {
|
||||
return weeks;
|
||||
}
|
||||
|
||||
public void setWeeks(List<Week> weeks) {
|
||||
this.weeks = weeks;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package ru.ulstu.utils.timetable.model;
|
||||
|
||||
public class TimetableResponse {
|
||||
private Response response;
|
||||
private String error;
|
||||
|
||||
public Response getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
public void setResponse(Response response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(String error) {
|
||||
this.error = error;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package ru.ulstu.utils.timetable.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Week implements Serializable {
|
||||
|
||||
private List<Day> days = new ArrayList<>();
|
||||
|
||||
public List<Day> getDays() {
|
||||
return days;
|
||||
}
|
||||
|
||||
public void setDays(List<Day> days) {
|
||||
this.days = days;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?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="anton" id="20190506_000000-1">
|
||||
<addColumn tableName="deadline">
|
||||
<column name="executor" type="varchar(255)"/>
|
||||
</addColumn>
|
||||
<addColumn tableName="deadline">
|
||||
<column name="done" type="boolean"/>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
@ -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="anton" id="20190506_000000-2">
|
||||
<createTable tableName="project_executors">
|
||||
<column name="project_id" type="integer"/>
|
||||
<column name="executors_id" type="integer"/>
|
||||
</createTable>
|
||||
<addForeignKeyConstraint baseTableName="project_executors" baseColumnNames="project_id"
|
||||
constraintName="fk_project_project_executors" referencedTableName="project"
|
||||
referencedColumnNames="id"/>
|
||||
<addForeignKeyConstraint baseTableName="project_executors" baseColumnNames="executors_id"
|
||||
constraintName="fk_user_project_executors" referencedTableName="users"
|
||||
referencedColumnNames="id"/>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
@ -0,0 +1,14 @@
|
||||
<?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="anton" id="20190517_000001-1">
|
||||
<modifyDataType tableName="deadline"
|
||||
columnName="executor"
|
||||
newDataType="integer"
|
||||
schemaName="public"/>
|
||||
<addForeignKeyConstraint baseTableName="deadline" baseColumnNames="executor"
|
||||
constraintName="fk_deadline_executor" referencedTableName="users"
|
||||
referencedColumnNames="id"/>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
@ -0,0 +1,11 @@
|
||||
<?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="anton" id="20190528_000000-1">
|
||||
<renameColumn tableName="deadline"
|
||||
columnDataType="integer"
|
||||
newColumnName="executors"
|
||||
oldColumnName="executor"/>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
@ -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="anton" id="20190528_000000-3">
|
||||
<createTable tableName="deadline_executors">
|
||||
<column name="deadline_id" type="integer"/>
|
||||
<column name="executors_id" type="integer"/>
|
||||
</createTable>
|
||||
<addForeignKeyConstraint baseTableName="deadline_executors" baseColumnNames="deadline_id"
|
||||
constraintName="fk_deadline_deadline_executors" referencedTableName="deadline"
|
||||
referencedColumnNames="id"/>
|
||||
<addForeignKeyConstraint baseTableName="deadline_executors" baseColumnNames="executors_id"
|
||||
constraintName="fk_user_deadline_executors" referencedTableName="users"
|
||||
referencedColumnNames="id"/>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
@ -0,0 +1,5 @@
|
||||
.div-deadline-done {
|
||||
width: 60%;
|
||||
height: 100%;
|
||||
float: right;
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<!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">
|
||||
<head>
|
||||
<script src="/js/core.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container" layout:fragment="content">
|
||||
<section id="services">
|
||||
<div class="container">
|
||||
<div class="col-lg-12 text-center">
|
||||
<h2 class="section-heading text-uppercase">Пользователи</h2>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<h2 th:text="${error}">teste</h2>
|
||||
</div>
|
||||
<div class="row justify-content-center" id="dashboard">
|
||||
<th:block th:each="user : ${users}">
|
||||
<div th:replace="users/fragments/userDashboardFragment :: userDashboard(user=${user})"/>
|
||||
</th:block>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<script th:inline="javascript">
|
||||
/*<![CDATA[*/
|
||||
$(document).ready(function () {
|
||||
var error = /*[[${error}]]*/
|
||||
showFeedbackMessage(error, MessageTypesEnum.WARNING)
|
||||
});
|
||||
/*]]>*/
|
||||
</script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,18 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head th:fragment="headerfiles">
|
||||
<meta charset="UTF-8"/>
|
||||
</head>
|
||||
<body>
|
||||
<div th:fragment="userDashboard (user)" class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
|
||||
<div class="row">
|
||||
<div class="col col-10">
|
||||
<b><p th:text="${user.user.lastName} + ' ' + ${user.user.firstName} + ' ' + ${user.user.patronymic}"></p></b>
|
||||
<i><p th:if="${user.conference != null}" th:text="'Сейчас на конференции ' + ${user.conference.title}"></p></i>
|
||||
<i><p th:if="${user.lesson != null}" th:text="'Сейчас на паре ' + ${user.lesson.nameOfLesson} + ' в аудитории ' + ${user.lesson.room}"></p></i>
|
||||
<p th:if="${user.isOnline()}">Онлайн</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue