1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
| package com.org.test.service;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.apache.commons.collections.ListUtils;
import org.apache.log4j.Logger;
import org.hibernate.Hibernate;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.org.test.model.Personne;
import com.org.test.model.SupportGroup;
import com.org.test.model.TargetSite;
import com.org.test.model.Task;
@Service
@Transactional
public class PersonneServiceImpl implements PersonneService {
@Autowired
PersonneRepository personneRepo;
public List<Personne> findAllPersonne() {
return personneRepo.findAll();
}
public boolean isCIROK(String idPersonne) {
return (personneRepo.findById(idPersonne)).getRisk().equals("Low");
}
public List<Object[]> countPersonneByCategory() {
return personneRepo.countAllPersonneByCategory();
}
public List<Object[]> countPersonneByStatus(String category) {
return personneRepo.countAllPersonneByStatus(category);
}
/*
* Get Personne list for the Personne calendar
*/
public List<Personne> getPersonneCalendar(DateTime s, DateTime e) {
List<Personne> listPersonne = personneRepo.findByPlannedStartDateBetweenOrderByPlannedStartDateAsc(s.toDate(), e.toDate());
for (Personne unit : listPersonne){
try {
Hibernate.initialize(unit.getTasks());
Hibernate.initialize(unit.getSupportGroups());
}
catch (Exception ex){
System.err.println(ex.getMessage());
}
}
return listPersonne;
}
/*
* Update the alerts of all Personne over 6 months base on the implemented rules.
*/
public void updateAlertsOnIntervention() {
}
/*
* Update the comment done during the intervention
* @param id
* the id of the Personne
* @param comment
* comment to add
*
* @return the complete comment
*/
public String updateInterventionComment(String id, String comment) {
Personne unit = personneRepo.findById(id);
Date today = new Date();
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
if (unit.getInterventionComment()!=null)
unit.setInterventionComment(unit.getInterventionComment()+"<br/>"+df.format(today)+" : "+comment);
else
unit.setInterventionComment(df.format(today)+" : "+comment);
return unit.getInterventionComment();
}
/*
* Get all Personne between dates.
* @param start
* planned start date boundary
* @param end
* planned end date bounday
*
* @return a list of Personne
*/
public List<Personne> getPersonneBetween(Date start, Date end) {
List<Personne> list = personneRepo.findByStartDateAndEndDate(start, end);
for (Personne c:list){
Hibernate.initialize(c.getImpactedIntervention());
c.setNbTasks();
}
return list;
}
public Personne save(Personne unit) {
Personne unitSaved = personneRepo.findById(unit.getId());
if (unitSaved!=null){
return unitSaved;
}
else {
personneRepo.save(unit);
return unit;
}
}
public List<Personne> getCurrentPersonne(Date start, Date end) {
List<Personne> list = personneRepo.findByStartDateAndEndDate (start, end, start, end);
for (Personne unit : list){
Hibernate.initialize(unit.getImpactedIntervention());
}
return list;
}
@Override
public List<Object[]> getPersonneOnTargetSiteByStatus(List<String> status) {
return personneRepo.currentPersonneTargetSites();
}
} |
Partager