Skip to content

Commit 24880db

Browse files
Fabienfabiengo
authored andcommitted
feat(bo): allow operators to display their daily treated files count
1 parent f7597a2 commit 24880db

File tree

6 files changed

+104
-1
lines changed

6 files changed

+104
-1
lines changed

dossierfacile-bo/src/main/java/fr/gouv/bo/configuration/WebSecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
6969
.hasRole("ADMIN")
7070
.antMatchers("/bo/tenant/{tenantId}/processFile")
7171
.hasAnyRole("ADMIN", "OPERATOR", "PARTNER")
72-
.antMatchers("/bo/**", "/bo", "/documents/**")
72+
.antMatchers("/bo/**", "/bo", "/documents/**", "/bo/dashboard")
7373
.hasAnyRole("ADMIN", "OPERATOR")
7474
.anyRequest()
7575
.authenticated()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package fr.gouv.bo.controller;
2+
3+
import fr.dossierfacile.common.entity.BOUser;
4+
import fr.gouv.bo.dto.EmailDTO;
5+
import fr.gouv.bo.service.LogService;
6+
import fr.gouv.bo.service.UserService;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.stereotype.Controller;
9+
import org.springframework.ui.Model;
10+
import org.springframework.web.bind.annotation.GetMapping;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
13+
import java.security.Principal;
14+
import java.util.List;
15+
16+
@Controller
17+
@RequestMapping(value = "/bo/dashboard")
18+
public class BODashboardController {
19+
public final String EMAIL = "email";
20+
@Autowired
21+
private LogService logService;
22+
@Autowired
23+
private UserService userService;
24+
25+
@GetMapping("")
26+
public String myDashboard(Model model, Principal principal) {
27+
if (principal == null) {
28+
return "redirect:/login";
29+
}
30+
BOUser operator = userService.findUserByEmail(principal.getName());
31+
List<Object[]> listTreatedCountByDay = logService.listLastTreatedFilesByOperator(operator.getId());
32+
33+
model.addAttribute("operator", operator);
34+
model.addAttribute("listTreatedCountByDay", listTreatedCountByDay);
35+
36+
model.addAttribute(EMAIL, new EmailDTO());
37+
return "bo/dashboard";
38+
}
39+
}

dossierfacile-bo/src/main/java/fr/gouv/bo/repository/BoLogRepository.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.springframework.data.domain.Page;
55
import org.springframework.data.domain.Pageable;
66
import org.springframework.data.jpa.repository.JpaRepository;
7+
import org.springframework.data.jpa.repository.Query;
8+
import org.springframework.data.repository.query.Param;
79

810
import java.util.List;
911

@@ -14,4 +16,14 @@ public interface BoLogRepository extends JpaRepository<Log, Long> {
1416
Page<Log> findAll(Pageable pageable);
1517

1618
Page<Log> findAllByTenantId(Long tenantId, Pageable pageable);
19+
20+
@Query(value = """
21+
SELECT DATE(creation_date) AS creation_date, COUNT(*) AS record_count
22+
FROM tenant_log
23+
WHERE operator_id = :operatorId
24+
AND ( log_type = 'ACCOUNT_VALIDATED' OR log_type = 'ACCOUNT_DENIED' )
25+
AND creation_date BETWEEN CURRENT_DATE - :minusDays AND CURRENT_DATE + 1
26+
GROUP BY DATE(creation_date)
27+
""", nativeQuery = true)
28+
List<Object[]> countTreatedFromXDaysGroupByDate(@Param("operatorId") Long operatorId, @Param("minusDays") int minusDays);
1729
}

dossierfacile-bo/src/main/java/fr/gouv/bo/service/LogService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ public void saveByLog(Log log) {
3434
logRepository.save(log);
3535
}
3636

37+
public List<Object[]> listLastTreatedFilesByOperator(Long operatorId){
38+
return logRepository.countTreatedFromXDaysGroupByDate(operatorId, 3);
39+
}
40+
3741
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<html lang="fr"
3+
xmlns:th="http://www.thymeleaf.org"
4+
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
5+
layout:decorator="bo/layout-bo">
6+
<head>
7+
<title>DossierFacile</title>
8+
</head>
9+
<body>
10+
<div layout:fragment="content" th:remove="tag">
11+
<div class="container">
12+
<h2>Info Opérateur</h2>
13+
<table class="table table-striped table-bordered table-hover">
14+
<tr>
15+
<td>Id</td>
16+
<td th:text="${operator.id}"></td>
17+
</tr>
18+
<tr>
19+
<td>Email</td>
20+
<td th:text="${operator.email}"></td>
21+
</tr>
22+
</table>
23+
</div>
24+
<div class="container">
25+
<h2>Les derniers dossiers traités</h2>
26+
<div class="table-responsive">
27+
<table class="table table-striped table-bordered table-hover">
28+
<thead>
29+
<tr>
30+
<th>Date</th>
31+
<th>Nombre de dossiers traités</th>
32+
</tr>
33+
</thead>
34+
<tbody>
35+
36+
<tr th:each="row : ${listTreatedCountByDay}">
37+
<td th:utext="${row[0]}"></td>
38+
<td th:utext="${row[1]}"></td>
39+
</tbody>
40+
</table>
41+
</div>
42+
</div>
43+
</div>
44+
45+
</body>
46+
</html>

dossierfacile-bo/src/main/resources/templates/include/fixed-header-bo.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<a class="" th:href="@{/}">
77
<img src="/assets/images/logo.png" alt="" class="logo animated slideInLeft"/>
88
</a>
9+
<a sec:authorize="hasRole('ROLE_ADMIN') or hasRole('ROLE_OPERATOR')" th:href="@{/bo/dashboard}"
10+
class="profile fixed-header-link" th:text="Dashboard"></a>
911
</div>
1012
<div class="col-md-4">
1113
<div class="row" style="margin-right: 225px;margin-left: 0;">

0 commit comments

Comments
 (0)