#91 base users dashboard
parent
59bc0dbd34
commit
d7c4e6b222
@ -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,97 @@
|
||||
package ru.ulstu.utils.timetable;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import ru.ulstu.utils.timetable.model.Lesson;
|
||||
import ru.ulstu.utils.timetable.model.TimetableResponse;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
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";
|
||||
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() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new Date());
|
||||
return (cal.get(Calendar.WEEK_OF_YEAR) + 1) % 2;
|
||||
}
|
||||
|
||||
private TimetableResponse getTimetableForUser(String userFIO) throws IOException {
|
||||
URL url = new URL(TIMETABLE_URL + "/api/1.0/timetable?filter=" + URLEncoder.encode(userFIO, "UTF-8"));
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
|
||||
BufferedReader in = new BufferedReader(
|
||||
new InputStreamReader(con.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuilder content = new StringBuilder();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
content.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
||||
return new ObjectMapper().readValue(content.toString(), TimetableResponse.class);
|
||||
}
|
||||
|
||||
public Lesson getCurrentLesson(String userFio) throws IOException {
|
||||
TimetableResponse response = getTimetableForUser(userFio);
|
||||
int lessonNumber = getCurrentLessonNumber();
|
||||
if (lessonNumber < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Object> 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,27 @@
|
||||
package ru.ulstu.utils.timetable.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Day {
|
||||
|
||||
private Integer day;
|
||||
private List<List<Object>> lessons = null;
|
||||
|
||||
public Integer getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
public void setDay(Integer day) {
|
||||
this.day = day;
|
||||
}
|
||||
|
||||
public List<List<Object>> getLessons() {
|
||||
return lessons;
|
||||
}
|
||||
|
||||
public void setLessons(List<List<Object>> lessons) {
|
||||
this.lessons = lessons;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package ru.ulstu.utils.timetable.model;
|
||||
|
||||
public class Lesson {
|
||||
private String group;
|
||||
private String nameOfLesson;
|
||||
private String teacher;
|
||||
private String room;
|
||||
|
||||
public Lesson() {
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public String getNameOfLesson() {
|
||||
return nameOfLesson;
|
||||
}
|
||||
|
||||
public String getTeacher() {
|
||||
return teacher;
|
||||
}
|
||||
|
||||
public String getRoom() {
|
||||
return room;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package ru.ulstu.utils.timetable.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Response {
|
||||
|
||||
private List<Week> weeks = null;
|
||||
|
||||
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,16 @@
|
||||
package ru.ulstu.utils.timetable.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Week {
|
||||
|
||||
private List<Day> days = null;
|
||||
|
||||
public List<Day> getDays() {
|
||||
return days;
|
||||
}
|
||||
|
||||
public void setDays(List<Day> days) {
|
||||
this.days = days;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<!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>
|
||||
</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="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>
|
||||
</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