Skip to content

Commit

Permalink
Merge branch 'main' into 251-creazione-codice-183
Browse files Browse the repository at this point in the history
  • Loading branch information
Dario Tagliaferri committed Oct 30, 2024
2 parents b4454cb + 23ba450 commit 78c7437
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 4 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.19.1] - UNRELEASED
## [2.19.1] - 2024-10-30
### Added
- Aggiunto codice 183 giornaliero e ore e minuti per terzo parente disabile

- Aggiunto job che invia agli amministrativi i problemi sui giorni dei dipendenti della sede che
gestiscono

### Changed
- Il codice 98 è ora inseribile anche nei festivi
- Corretto typo nella visualizzazione della pagina Categorie gruppi assenze
Expand Down
22 changes: 22 additions & 0 deletions app/dao/PersonDayInTroubleDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import java.util.List;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import models.Office;
import models.Person;
import models.PersonDay;
import models.PersonDayInTrouble;
import models.enumerate.Troubles;
import models.query.QPersonDay;
import models.query.QPersonDayInTrouble;
import org.joda.time.LocalDate;

Expand Down Expand Up @@ -59,6 +61,7 @@ public List<PersonDayInTrouble> getPersonDayInTroubleInPeriod(

QPersonDayInTrouble pdit = QPersonDayInTrouble.personDayInTrouble;


BooleanBuilder conditions = new BooleanBuilder(pdit.personDay.person.eq(person));
if (begin.isPresent()) {
conditions.and(pdit.personDay.date.goe(begin.get()));
Expand Down Expand Up @@ -87,4 +90,23 @@ public Optional<PersonDayInTrouble> getPersonDayInTroubleByType(PersonDay pd, Tr
.where(pdit.personDay.eq(pd).and(pdit.cause.eq(trouble))).fetchOne();
return Optional.fromNullable(result);
}

/**
* La lista dei trouble per sede.
* @param office la sede di cui si vogliono i trouble
* @param begin la data di inizio da quando si ricerca
* @param end la data di fine in cui si ricerca
* @return la lista dei trouble per sede.
*/
public List<PersonDayInTrouble> getPersonDayInTroubleByOfficeInPeriod(Office office,
LocalDate begin, LocalDate end, Troubles trouble) {
QPersonDayInTrouble pdit = QPersonDayInTrouble.personDayInTrouble;
QPersonDay pd = QPersonDay.personDay;
BooleanBuilder conditions = new BooleanBuilder();
conditions.and(pdit.personDay.date.goe(begin));
conditions.and(pdit.personDay.date.loe(end));
conditions.and(pdit.cause.eq(trouble));
return getQueryFactory().selectFrom(pdit).leftJoin(pdit.personDay, pd)
.where(conditions.and(pd.person.office.eq(office))).fetch();
}
}
94 changes: 94 additions & 0 deletions app/jobs/AlertNoInfoDaysJob.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package jobs;

import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.apache.commons.mail.EmailException;
import org.joda.time.DateTimeConstants;
import org.joda.time.LocalDate;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import dao.OfficeDao;
import dao.PersonDao;
import dao.PersonDayInTroubleDao;
import dao.RoleDao;
import dao.UsersRolesOfficesDao;
import lombok.extern.slf4j.Slf4j;
import manager.PersonDayInTroubleManager;
import models.Office;
import models.Person;
import models.PersonDayInTrouble;
import models.Role;
import models.User;
import models.UsersRolesOffices;
import models.absences.Absence;
import models.enumerate.Troubles;
import play.Play;
import play.jobs.Job;
import play.jobs.On;
import play.jobs.OnApplicationStart;

@SuppressWarnings("rawtypes")
@Slf4j
@On("0 0 7 * * ?") // Ore 7:00
public class AlertNoInfoDaysJob extends Job {

@Inject
static OfficeDao officeDao;
@Inject
static UsersRolesOfficesDao uroDao;
@Inject
static RoleDao roleDao;
@Inject
static PersonDayInTroubleDao personDayInTroubleDao;
@Inject
static PersonDao personDao;
@Inject
static PersonDayInTroubleManager personDayInTroubleManager;

private static final List<Integer> weekEnd = ImmutableList
.of(DateTimeConstants.SATURDAY, DateTimeConstants.SUNDAY);

@Override
public void doJob() throws EmailException {

//in modo da inibire l'esecuzione dei job in base alla configurazione
if (!"true".equals(Play.configuration.getProperty(Bootstrap.JOBS_CONF))) {
log.info("{} interrotto. Disattivato dalla configurazione.", getClass().getName());
return;
}

if (!weekEnd.contains(LocalDate.now().getDayOfWeek())) {
log.debug("Inizia la parte di invio email...");

List<Office> officeList = officeDao.allEnabledOffices();
Map<Office, List<User>> map = Maps.newHashMap();
for (Office o : officeList) {
List<User> userList = uroDao
.getUsersWithRoleOnOffice(roleDao.getRoleByName(Role.PERSONNEL_ADMIN), o);
List<User> list = map.get(o);
if (list == null || list.isEmpty()) {
list = Lists.newArrayList();
}
list.addAll(userList);
map.put(o, list);
}
LocalDate begin = LocalDate.now().minusMonths(1).dayOfMonth().withMinimumValue();
LocalDate end = LocalDate.now().minusDays(1);
log.debug("Inizio a mandare le mail per office...");
for (Map.Entry<Office, List<User>> entry : map.entrySet()) {
log.info("Analizzo la sede di {}", entry.getKey().getName());
List<PersonDayInTrouble> pdList = personDayInTroubleDao.getPersonDayInTroubleByOfficeInPeriod(entry.getKey(),
begin, end, Troubles.NO_ABS_NO_STAMP);
log.info("Trovate {} problemi per la sede {}", pdList.size(), entry.getKey().getName());
if (!pdList.isEmpty()) {
log.info("Invio mail agli amministratori di {}", entry.getKey().getName());
personDayInTroubleManager.sendOfficeTroubleEmailsToAdministrators(pdList, entry.getValue(), entry.getKey());
}
}
}
log.info("Concluso AlertNoInfoDaysJob");
}
}
89 changes: 89 additions & 0 deletions app/manager/PersonDayInTroubleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,29 @@
import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import dao.PersonDayInTroubleDao;
import dao.wrapper.IWrapperContract;
import dao.wrapper.IWrapperFactory;
import dao.wrapper.function.WrapperModelFunctionFactory;
import it.cnr.iit.epas.DateInterval;
import it.cnr.iit.epas.DateUtility;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import manager.configurations.ConfigurationManager;
import manager.configurations.EpasParam;
import models.Contract;
import models.Office;
import models.Person;
import models.PersonDay;
import models.PersonDayInTrouble;
import models.User;
import models.enumerate.Troubles;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
import org.joda.time.LocalDate;
import play.jobs.Job;
Expand Down Expand Up @@ -277,4 +283,87 @@ public void doJob() {
}.now();

}

/**
* Metodo che invia le mail agli amministratori del personale delle varie sedi per informare
* sui giorni con problemi dei dipendenti della loro sede.
* @param daysInTrouble la lista dei giorni con problemi
* @param administrators la lista degli amministratori di una sede
* @param office la sede di riferimento
* @throws EmailException
*/
public void sendOfficeTroubleEmailsToAdministrators(List<PersonDayInTrouble> daysInTrouble,
List<User> administrators, Office office) throws EmailException {
Map<Person, List<String>> map = createTroubleMap(daysInTrouble);
String message = createMessageForAdministrator(map);
for (User user : administrators) {

SimpleEmail simpleEmail = new SimpleEmail();
simpleEmail.setSubject("ePas Controllo timbrature per Amministratori");

simpleEmail.setMsg(message);
if (user == null || user.getPerson() == null) {
log.info("Trovato utente senza persona associata: {}", user.getUsername());
continue;
}
if (user.getPerson().getEmail() == null) {
continue;
}
simpleEmail.addTo(user.getPerson().getEmail());
try {
Mail.send(simpleEmail);
} catch (Exception ex) {
log.error("Fallito invio email all'amministratore {} della sede {} per {}",
user.getPerson().getFullname(), office.getName(), ex);
}

log.info("Inviata mail a {} per segnalare i problemi dei dipendenti della sede {}",
user.getPerson(), user.getPerson().getOffice());
}

}

/**
* Metodo privato che genera la mappa Persona-lista di stringhe contenente le giornate in cui
* il dipendente ha un trouble.
* @param daysInTrouble la lista di trouble
* @return la mappa persona-lista di stringhe contenente le giornate in cui i dipendenti
* hanno un trouble.
*/
private Map<Person, List<String>> createTroubleMap(List<PersonDayInTrouble> daysInTrouble) {
final String dateFormatter = "dd/MM/YYYY";
Map<Person, List<String>> map = Maps.newHashMap();
for (PersonDayInTrouble pdit : daysInTrouble) {
List<String> list = map.get(pdit.getPersonDay().getPerson());
if (list == null || list.isEmpty()) {
list = Lists.newArrayList();
}
list.add(pdit.getPersonDay().getDate().toString(dateFormatter));
map.put(pdit.getPersonDay().getPerson(), list);
}
return map;
}

/**
* Metodo che crea il messaggio da mandare agli amministratori.
* @param map la mappa contenente per ogni persona la lista di date in cui ci sono problemi
* @return il messaggio da mandare agli amministratori del personale.
*/
private String createMessageForAdministrator(Map<Person, List<String>> map) {
final StringBuilder message = new StringBuilder()
.append(String.format("Qui di seguito i dipendenti che presentano giorni con problemi "
+ "e le date in cui sono stati riscontrati: \r\n"));
for (Map.Entry<Person, List<String>> entry : map.entrySet()) {
message.append(String.format("\r\n %s nei giorni: ", entry.getKey().getFullname()));
for (String s : entry.getValue()) {
message.append(String.format("%s - ", s));
}
}

message.append("\r\nLa preghiamo di verificare con i dipendenti i giorni in oggetto.\r\n")
.append("\r\nSaluti,\r\n")
.append("Il team di ePAS");

return message.toString();
}
}
4 changes: 2 additions & 2 deletions publiccode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

publiccodeYmlVersion: '0.2'
name: epas
releaseDate: '2024-10-15'
releaseDate: '2024-10-30'
url: 'https://github.com/consiglionazionaledellericerche/epas'
applicationSuite: epas
softwareVersion: 2.19.0
softwareVersion: 2.19.1
developmentStatus: stable
softwareType: standalone/web
platforms:
Expand Down

0 comments on commit 78c7437

Please sign in to comment.