Config worksgit add .git add .

This commit is contained in:
Filip Izydorczyk 2020-08-08 00:08:36 +02:00
parent 2f63d05c6c
commit ac0851ae29
3 changed files with 42 additions and 14 deletions

View File

@ -9,6 +9,7 @@ import com.plannaplan.models.FileData;
import com.plannaplan.services.CourseService; import com.plannaplan.services.CourseService;
import com.plannaplan.services.GroupService; import com.plannaplan.services.GroupService;
import com.plannaplan.services.LecturerService; import com.plannaplan.services.LecturerService;
import com.plannaplan.types.GroupType;
import com.plannaplan.types.WeekDay; import com.plannaplan.types.WeekDay;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
@ -78,20 +79,12 @@ public class FileToDatabaseMigrator {
int day = (int) Double.parseDouble(day_cell.toString()); int day = (int) Double.parseDouble(day_cell.toString());
WeekDay group_day = WeekDay.getDay(day); WeekDay group_day = WeekDay.getDay(day);
String room = room_cell.toString(); String room = room_cell.toString();
int time = 480; int time = this.parseTimeToInt(time_cell.toString());
int capacity = (int) Double.parseDouble(capacity_cell.toString()); int capacity = (int) Double.parseDouble(capacity_cell.toString());
Groups group = groupService.find(time, capacity, room); Groups group = groupService.find(time, capacity, room);
if (group == null) {
group = new Groups();
group.setCapacity(capacity);
group.setTime(time);
group.setRoom(room);
}
groupService.save(group);
Course course = this.courseService.getCourseByName(course_name); Course course = this.courseService.getCourseByName(course_name);
if (course == null) { if (course == null) {
@ -112,12 +105,44 @@ public class FileToDatabaseMigrator {
lecturer_surname = surname_cell.toString(); lecturer_surname = surname_cell.toString();
} }
if (lecturerService.getLecturer(lecturer_title, lecturer_name, lecturer_surname) == null) { Lecturer lecturer = lecturerService.getLecturer(lecturer_title, lecturer_name, lecturer_surname);
Lecturer newLecturer = new Lecturer(lecturer_title, lecturer_name, lecturer_surname);
lecturerService.save(newLecturer); if (lecturer == null) {
lecturer = new Lecturer(lecturer_title, lecturer_name, lecturer_surname);
lecturerService.save(lecturer);
}
if (group == null) {
group = new Groups();
group.setCapacity(capacity);
group.setRoom(room);
group.setCourseId(course);
group.setTime(time);
if (capacity >= 50) {
group.setType(GroupType.LECTURE);
} else {
group.setType(GroupType.CLASS);
}
group.setDay(group_day);
group.setLecturer(lecturer);
groupService.save(group);
} }
} }
} }
private Integer parseTimeToInt(String time) {
String times[] = time.split("\\.");
if (times.length == 2) {
return Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]);
}
times = time.split("\\:");
if (times.length == 2) {
return Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]);
}
return 0;
}
} }

View File

@ -9,6 +9,6 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface GroupRepository extends JpaRepository<Groups, Long> { public interface GroupRepository extends JpaRepository<Groups, Long> {
@Query(value = "SELECT * FROM groups WHERE name = :name AND surname = :surname AND title = :title ", nativeQuery = true) @Query(value = "SELECT * FROM groups WHERE time = :time AND room = :room AND capacity = :capacity ", nativeQuery = true)
Groups find(@Param("time") int time, @Param("room") String room, @Param("capacity") int capacity); Groups find(@Param("time") int time, @Param("room") String room, @Param("capacity") int capacity);
} }

View File

@ -11,6 +11,9 @@ public class GroupService {
@Autowired @Autowired
private GroupRepository repo; private GroupRepository repo;
public GroupService() {
}
public Groups find(int time, int capacity, String room) { public Groups find(int time, int capacity, String room) {
return this.repo.find(time, room, capacity); return this.repo.find(time, room, capacity);
} }