Ого, вау сделал отчет

This commit is contained in:
ArtemEmelyanov 2023-05-15 20:09:55 +04:00
parent 58280603ce
commit a47d810d48
5 changed files with 79 additions and 33 deletions

Binary file not shown.

View File

@ -2,6 +2,7 @@
<div class="container mt-4">
<h1 class="text-center mb-4">Group Table</h1>
<button class="btn btn-primary mr-2" @click="openModal('create')">Добавить</button>
<button class="btn btn-primary mr-2" @click="openReport()">Отчет</button>
<table class="table table-striped">
<thead>
<tr>
@ -36,6 +37,41 @@
</tbody>
</table>
</div>
<!--Форма для отчета -->
<div class="modal" tabindex="-1" id="openReport">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Отчет</h5>
</div>
<div class="modal-body">
<form>
<table class="table table-striped">
<thead>
<tr>
<th>Группа</th>
<th>Студенты</th>
</tr>
</thead>
<tbody>
<tr v-for="[key, value] in Object.entries(getAllInfo)" :key="key">
<td>{{ key }}</td>
<td>
<ul>
<li v-for="book in value" :key="book">{{ book }}</li>
</ul>
</td>
</tr>
</tbody>
</table>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="editModal" @click="closeReport()">Закрыть</button>
</div>
</div>
</div>
</div>
<!--Форма для привязки предмета и групп -->
<div class="modal" tabindex="-1" id="openModalForAddSubjects">
<div class="modal-dialog">
@ -206,6 +242,7 @@ export default {
created() {
this.getGroups();
this.getSubjects();
this.getAll();
},
data() {
return{
@ -219,9 +256,20 @@ export default {
groupId: undefined,
selectedSubjects: [],
subjectsInGroup: [],
getAllInfo: new Object() ,
}
},
methods: {
getAll(){
axios.get(this.URL + "group/getAll")
.then(response => {
this.getAllInfo = response.data;
console.log(response.data);
})
.catch(error => {
console.log(error);
});
},
getSubjectsInGroup(id){
axios.get(this.URL + `group/${id}/getAllSubjects`)
.then(response => {
@ -314,6 +362,12 @@ export default {
CloseModalForAddStudents() {
document.getElementById("ModalForAddStudents").style.display = "none";
},
openReport() {
document.getElementById("openReport").style.display = "block";
},
closeReport() {
document.getElementById("openReport").style.display = "none";
},
saveStudents(id) {
axios.post(this.URL + `group/${id}/addStudents`, this.selectedStudents)
.then(() => {

View File

@ -10,6 +10,7 @@ import ru.IP_LabWorks.IP.University.Model.Subject;
import ru.IP_LabWorks.IP.University.Service.GroupService;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/group")
@ -79,11 +80,8 @@ public class GroupController {
public void addSubjectToGroup(@PathVariable Long id, @RequestBody @Valid List<Long> subjectIds){
groupService.addSubjectToGroup(id, subjectIds);
}
// @PostMapping("/{id}/student")
// public StudentDTO setStudentToGroup(@PathVariable Long id,
// @RequestParam("studentId") Long studentId) {
// return new StudentDTO(groupService.addStudentToGroup(id, studentId));
// }
@GetMapping("/getAll")
public Map<String, List<String>> getAll(){
return groupService.getAll();
}
}

View File

@ -1,7 +1,15 @@
package ru.IP_LabWorks.IP.University.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import ru.IP_LabWorks.IP.University.Model.Group;
import java.util.List;
public interface GroupRepository extends JpaRepository<Group, Long> {
@Query("select g.name as group, s.name as students " +
"from Group g " +
"join g.students s " +
"group by g.id, g.name, s.name")
List<Object[]> getAll();
}

View File

@ -12,7 +12,9 @@ import ru.IP_LabWorks.IP.University.Service.NotFoundException.GroupNotFoundExcep
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
public class GroupService {
@ -126,30 +128,14 @@ public class GroupService {
groupRepository.save(currentGroup);
}
/* @Transactional
public Group addStudentToGroup(Long groupId, Long studentId) {
Group group = findGroup(groupId);
Student student = studentService.findStudent(studentId);
if (group == null || student == null) {
throw new EntityNotFoundException("Group or Student not found");
}
group.setStudent(student);
return group;
}*/
//
// @Transactional
// public void removeStudentFromGroup(Long groupId, Long studentId) {
// Group group = findGroup(groupId);
// Student student = em.find(Student.class, studentId);
// group.getStudents().remove(student);
// }
//
// @Transactional(readOnly = true)
// public List<Student> findStudentsInGroup(Long groupId) {
// Group group = findGroup(groupId);
// if (group == null) {
// throw new EntityNotFoundException("Group not found");
// }
// return group.getStudents();
// }
@Transactional
public Map<String, List<String>> getAll(){
return groupRepository.getAll().stream()
.collect(
Collectors.groupingBy(
o -> (String) o[0],
Collectors.mapping( o -> (String) o[1], Collectors.toList() )
)
);
}
}