Aggiornata sincronizzazione

This commit is contained in:
Giancarlo Panichi 2022-08-02 20:12:50 +02:00
parent c81a54f25b
commit 1ffb8c4a82
16 changed files with 573 additions and 97 deletions

View File

@ -15,6 +15,7 @@ import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import it.cnr.isti.epasmed.config.ApplicationProperties;
import it.cnr.isti.epasmed.epas.model.EPASOffSiteWorks;
import it.cnr.isti.epasmed.epas.model.EPASPersonDays;
@Component
@ -79,20 +80,21 @@ public class EPASOffSiteWorksClient {
return listEPASPersonDays;
}
public List<EPASPersonDays> getListByOfficeCodeId(String id, String year, String month) {
public List<EPASOffSiteWorks> getListByOfficeCodeId(String id, String year, String month) {
log.info("Retrieving Off Site Works List by office code id: {}", id);
Map<String, String> uriVariables = new HashMap<>();
uriVariables.put("sedeId", id);
uriVariables.put("year", year);
uriVariables.put("month", month);
ResponseEntity<List<EPASPersonDays>> responseEntity = rt.exchange(appProps.getDatasourceEpasRest().getRestUrl()
+ "/v3/personDays/offSiteWorkByPersonAndMonth?sedeId={sedeId}&year={year}&month={month}",
HttpMethod.GET, null, new ParameterizedTypeReference<List<EPASPersonDays>>() {
ResponseEntity<List<EPASOffSiteWorks>> responseEntity = rt.exchange(appProps.getDatasourceEpasRest().getRestUrl()
+ "/v3/personDays/offSiteWorkByOfficeAndMonth?sedeId={sedeId}&year={year}&month={month}",
HttpMethod.GET, null, new ParameterizedTypeReference<List<EPASOffSiteWorks>>() {
}, uriVariables);
List<EPASPersonDays> listEPASPersonDays = responseEntity.getBody();
log.info("Retrieved Off Site Works List: {}", listEPASPersonDays);
return listEPASPersonDays;
List<EPASOffSiteWorks> listEPASOffSiteWorks = responseEntity.getBody();
log.info("Retrieved Off Site Works List: {}", listEPASOffSiteWorks);
return listEPASOffSiteWorks;
}
}

View File

@ -0,0 +1,28 @@
package it.cnr.isti.epasmed.epas.model;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class EPASOffSiteWorks implements Serializable {
private static final long serialVersionUID = 1L;
private EPASAbsences[] absences;
private String date;
private Integer difference;
private String id;
private Boolean isHoliday;
private Boolean isTicketAvailable;
private EPASPersons person;
private Integer progressive;
private EPASStampings[] stampings;
private Integer timeAtWork;
}

View File

@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import it.cnr.isti.epasmed.epas.client.EPASOffSiteWorksClient;
import it.cnr.isti.epasmed.epas.model.EPASOffSiteWorks;
import it.cnr.isti.epasmed.epas.model.EPASPersonDays;
@Service
@ -26,7 +27,7 @@ public class EPASOffSiteWorksService {
return epasOffSiteWorksClient.getListByPersonEmail(email, year, month);
}
public List<EPASPersonDays> getListByOfficeCodeId(String id, String year, String month) {
public List<EPASOffSiteWorks> getListByOfficeCodeId(String id, String year, String month) {
return epasOffSiteWorksClient.getListByOfficeCodeId(id, year, month);
}

View File

@ -0,0 +1,27 @@
package it.cnr.isti.epasmed.sistemainformativo.model;
import java.io.Serializable;
import java.sql.Timestamp;
import java.sql.Date;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SILavoroFuoriSede implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private Integer idpersona;
private String cf;
private Date giorno;
private String luogo;
private String motivo;
private String way;
private Timestamp data_mod;
private String flag_del;
private Long id_flusso;
}

View File

@ -0,0 +1,38 @@
package it.cnr.isti.epasmed.sistemainformativo.repository;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import it.cnr.isti.epasmed.sistemainformativo.model.SILavoroFuoriSede;
@Repository
public class SILavoroFuoriSedeRepository {
private static final Logger logger = LoggerFactory.getLogger(SILavoroFuoriSedeRepository.class);
private JdbcTemplate jdbcTemplate;
//
public SILavoroFuoriSedeRepository(final @Qualifier("sistemaInformativoDataSource") DataSource dataSource) {
super();
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
public void writeNewFlux(Long fluxId, SILavoroFuoriSede siLavoroFuoriSede) {
jdbcTemplate.update("INSERT INTO epas_lavoro_fuori_sede (id,idpersona,cf,"
+ "giorno,luogo,motivo,way,data_mod,flag_del,id_flusso) "
+ "VALUES (?,?,?,?,?,?,?,?,?,?)",
siLavoroFuoriSede.getId(),siLavoroFuoriSede.getIdpersona(),siLavoroFuoriSede.getCf(),
siLavoroFuoriSede.getGiorno(),siLavoroFuoriSede.getLuogo(),siLavoroFuoriSede.getMotivo(),
siLavoroFuoriSede.getWay(),siLavoroFuoriSede.getData_mod(),siLavoroFuoriSede.getFlag_del(),fluxId);
logger.debug("Writed SILavoroFuoriSede: {}",siLavoroFuoriSede);
}
}

View File

@ -34,7 +34,7 @@ public class SIMasterLogRepository {
public void startFluxReads() {
logger.info("Iniziato Flusso in lettura");
jdbcTemplate.update("INSERT INTO master_log (codice_flusso, tabelle, operazione, data_inizio_oper) "
+ "VALUES ('epas','anagrafico,mail,telefoni,gruppi','L',current_timestamp)");
+ "VALUES ('epas','anagrafico,mail,telefoni,gruppi,gruppo_pers','L',current_timestamp)");
logger.info("Flusso in lettura aperto");
}
@ -75,8 +75,8 @@ public class SIMasterLogRepository {
public Long startFluxWrites() throws Exception {
logger.info("Iniziato Flusso in scrittura");
jdbcTemplate.update("INSERT INTO master_log (codice_flusso, tabelle, operazione, data_inizio_oper)"
+ " VALUES ('epas','epas_cartellini, epas_cartellini_rendicontazioni, epas_festivita,"
+ " epas_orario, epas_pers_orario,"
+ " VALUES ('epas','epas_cartellini, epas_cartellini_rendicontazioni,"
+ " epas_orario,"
+ " epas_lavoro_fuori_sede',"
+ " 'S',current_timestamp)");
logger.info("Flusso in scrittura aperto");

View File

@ -0,0 +1,35 @@
package it.cnr.isti.epasmed.sistemainformativo.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import it.cnr.isti.epasmed.sistemainformativo.model.SILavoroFuoriSede;
import it.cnr.isti.epasmed.sistemainformativo.repository.SILavoroFuoriSedeRepository;
/**
* Service class for managing Lavoro Fuori Sede.
*/
@Service
@Transactional("sistemaInformativoTransactionManager")
public class SILavoroFuoriSedeService {
private final Logger log = LoggerFactory.getLogger(getClass());
private final SILavoroFuoriSedeRepository siLavoroFuoriSedeRepository;
public SILavoroFuoriSedeService(SILavoroFuoriSedeRepository siLavoroFuoriSedeRepository) {
super();
this.siLavoroFuoriSedeRepository = siLavoroFuoriSedeRepository;
}
public void writeNewFlux(Long fluxId, SILavoroFuoriSede siLavoroFuoriSede) {
log.debug("Write SILavoroFuoriSede Flux = {}",fluxId);
siLavoroFuoriSedeRepository.writeNewFlux(fluxId,siLavoroFuoriSede);
}
}

View File

@ -6,6 +6,7 @@ import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -31,6 +32,7 @@ import it.cnr.isti.epasmed.epas.mapper.EPASPersonsMapper;
import it.cnr.isti.epasmed.epas.model.EPASAbsences;
import it.cnr.isti.epasmed.epas.model.EPASAffiliations;
import it.cnr.isti.epasmed.epas.model.EPASGroups;
import it.cnr.isti.epasmed.epas.model.EPASOffSiteWorks;
import it.cnr.isti.epasmed.epas.model.EPASPersonDays;
import it.cnr.isti.epasmed.epas.model.EPASPersons;
import it.cnr.isti.epasmed.epas.model.EPASStampings;
@ -39,6 +41,7 @@ import it.cnr.isti.epasmed.epas.model.EPASValidates;
import it.cnr.isti.epasmed.epas.model.EPASWorkingTimeTypes;
import it.cnr.isti.epasmed.epas.service.EPASAffiliationsService;
import it.cnr.isti.epasmed.epas.service.EPASGroupsService;
import it.cnr.isti.epasmed.epas.service.EPASOffSiteWorksService;
import it.cnr.isti.epasmed.epas.service.EPASPersonsService;
import it.cnr.isti.epasmed.epas.service.EPASTimeCardsService;
import it.cnr.isti.epasmed.epas.service.EPASValidatesService;
@ -51,6 +54,7 @@ import it.cnr.isti.epasmed.sistemainformativo.model.SICartelliniRendicontazioni;
import it.cnr.isti.epasmed.sistemainformativo.model.SIEmail;
import it.cnr.isti.epasmed.sistemainformativo.model.SIGruppi;
import it.cnr.isti.epasmed.sistemainformativo.model.SIGruppiPers;
import it.cnr.isti.epasmed.sistemainformativo.model.SILavoroFuoriSede;
import it.cnr.isti.epasmed.sistemainformativo.model.SIOrario;
import it.cnr.isti.epasmed.sistemainformativo.model.SITelefoni;
import it.cnr.isti.epasmed.sistemainformativo.service.SIAnagraficoService;
@ -59,6 +63,7 @@ import it.cnr.isti.epasmed.sistemainformativo.service.SICartelliniService;
import it.cnr.isti.epasmed.sistemainformativo.service.SIEmailService;
import it.cnr.isti.epasmed.sistemainformativo.service.SIGruppiPersService;
import it.cnr.isti.epasmed.sistemainformativo.service.SIGruppiService;
import it.cnr.isti.epasmed.sistemainformativo.service.SILavoroFuoriSedeService;
import it.cnr.isti.epasmed.sistemainformativo.service.SIMasterLogService;
import it.cnr.isti.epasmed.sistemainformativo.service.SIOrarioService;
import it.cnr.isti.epasmed.sistemainformativo.service.SITelefoniService;
@ -103,6 +108,8 @@ public class SyncService {
SICartelliniRendicontazioniService siCartelliniRendicontazioniService;
@Autowired
SIOrarioService siOrarioService;
@Autowired
SILavoroFuoriSedeService siLavoroFuoriSedeService;
@Autowired
EPASPersonsService epasPersonsService;
@ -114,11 +121,12 @@ public class SyncService {
EPASAffiliationsService epasAffiliationsService;
@Autowired
EPASWorkingTimeTypesService epasWorkingTimeTypesService;
@Autowired
EPASTimeCardsService epasTimeCardsService;
@Autowired
EPASValidatesService epasValidatesService;
@Autowired
EPASOffSiteWorksService epasOffSiteWorksService;
private boolean banagrafico;
private boolean bemail;
@ -134,15 +142,25 @@ public class SyncService {
private boolean blavoro_fuori_sede;
private boolean baspettative;
public void executeReads() throws Exception {
private void setBReadTables() {
banagrafico = false;
bemail = false;
btelefoni = false;
bgruppi = false;
bgruppo_pers = false;
// bposizioni = false;
// bproroghe = false;
}
private void setBWriteTables() {
bcartellini = false;
bcartellini_rendicontazioni = false;
borario = false;
bpers_orario = false;
blavoro_fuori_sede = false;
// baspettative=false;
}
public void executeReads() throws Exception {
setBReadTables();
List<TabsSI> tabsSI = tabsSIService.getAllTabsSI();
siMasterLogService.startFluxReads();
readData(tabsSI);
@ -150,36 +168,42 @@ public class SyncService {
}
public void executeWrites() throws Exception {
borario = false;
bcartellini = false;
bcartellini_rendicontazioni = false;
bpers_orario = false;
blavoro_fuori_sede = false;
baspettative = false;
public void executeWrites(String year, String month) throws Exception {
setBWriteTables();
List<TabsSI> tabsSI = tabsSIService.getAllTabsSI();
Long fluxId = siMasterLogService.startFluxWrites();
writeData(fluxId, tabsSI);
writeData(fluxId, tabsSI, year, month);
siMasterLogService.closeFluxWrites(fluxId, writeTabs());
}
public void executeWritesOrario() throws Exception {
setBWriteTables();
List<TabsSI> tabsSI = tabsSIService.getAllTabsSI();
Long fluxId = siMasterLogService.startFluxWrites();
writeOrarioData(fluxId, tabsSI);
siMasterLogService.closeFluxWrites(fluxId, writeTabs());
}
public void executeTimeCardsWrites() throws Exception {
borario = false;
bcartellini = false;
bcartellini_rendicontazioni = false;
bpers_orario = false;
blavoro_fuori_sede = false;
baspettative = false;
public void executeWritesTimeCards(String year, String month) throws Exception {
setBWriteTables();
List<TabsSI> tabsSI = tabsSIService.getAllTabsSI();
Long fluxId = siMasterLogService.startFluxWrites();
writeTimeCardsData(fluxId, tabsSI);
writeTimeCardsData(fluxId, tabsSI, year, month);
siMasterLogService.closeFluxWrites(fluxId, writeTabs());
}
public void executeWriteOffSiteWorks(String year, String month) throws Exception {
setBWriteTables();
List<TabsSI> tabsSI = tabsSIService.getAllTabsSI();
Long fluxId = siMasterLogService.startFluxWrites();
writeOffSiteWorksData(fluxId, tabsSI, year, month);
siMasterLogService.closeFluxWrites(fluxId, writeTabs());
}
private void readData(List<TabsSI> tabsSI) {
// TabsSI posizioniTab = null;
// TabsSI prorogheTab = null;
@ -780,8 +804,7 @@ public class SyncService {
return writeTabs;
}
private void writeData(Long fluxId, List<TabsSI> tabsSI) {
private void writeOrarioData(Long fluxId, List<TabsSI> tabsSI) {
for (TabsSI tab : tabsSI) {
logger.info("TabSI: {}", tab);
if (tab.getOperazioni() != null && !tab.getOperazioni().isEmpty()
@ -816,7 +839,11 @@ public class SyncService {
}
}
private void writeTimeCardsData(Long fluxId, List<TabsSI> tabsSI) throws Exception {
private void writeData(Long fluxId, List<TabsSI> tabsSI, String year, String month) throws Exception {
logger.info("Report {}-{}", year, month);
LocalDateTime now = LocalDateTime.now();
checkValidMonthToSend(year, month);
TimeCardsReporting timeCardsReporting = createTimeCardReporting(fluxId, year, month, now);
for (TabsSI tab : tabsSI) {
logger.info("TabSI: {}", tab);
@ -836,7 +863,46 @@ public class SyncService {
case "cartellini":
break;
case "cartellini_rendicontazioni":
syncCartelliniRendicontazioni(fluxId, tab);
syncCartelliniRendicontazioni(fluxId, tab, year, month, now, timeCardsReporting);
break;
case "lavoro_fuori_sede":
syncLavoroFuoriSede(fluxId, tab, year, month, now);
break;
// case "aspettative":
// syncAspettative(fluxId,tab);
// break;
default:
break;
}
}
}
}
private void writeTimeCardsData(Long fluxId, List<TabsSI> tabsSI, String year, String month) throws Exception {
logger.info("Report {}-{}", year, month);
LocalDateTime now = LocalDateTime.now();
checkValidMonthToSend(year, month);
TimeCardsReporting timeCardsReporting = createTimeCardReporting(fluxId, year, month, now);
for (TabsSI tab : tabsSI) {
logger.info("TabSI: {}", tab);
if (tab.getOperazioni() != null && !tab.getOperazioni().isEmpty()
&& tab.getOperazioni().compareTo("W") == 0) {
if (tab.getNome() == null || tab.getNome().isEmpty()) {
continue;
}
switch (tab.getNome()) {
// case "orario":
// syncOrario(fluxId, tab);
// break;
// case "pers_orario":
// syncPersOrario(fluxId,tab);
// break;
case "cartellini":
break;
case "cartellini_rendicontazioni":
syncCartelliniRendicontazioni(fluxId, tab, year, month, now, timeCardsReporting);
break;
// case "lavoro_fuori_sede":
// syncLavoroFuoriSede(fluxId,tab);
@ -852,6 +918,45 @@ public class SyncService {
}
}
private void writeOffSiteWorksData(Long fluxId, List<TabsSI> tabsSI, String year, String month) throws Exception {
logger.info("Report {}-{}", year, month);
LocalDateTime now = LocalDateTime.now();
checkValidMonthToSend(year, month);
for (TabsSI tab : tabsSI) {
logger.info("TabSI: {}", tab);
if (tab.getOperazioni() != null && !tab.getOperazioni().isEmpty()
&& tab.getOperazioni().compareTo("W") == 0) {
if (tab.getNome() == null || tab.getNome().isEmpty()) {
continue;
}
switch (tab.getNome()) {
// case "orario":
// syncOrario(fluxId, tab);
// break;
// case "pers_orario":
// syncPersOrario(fluxId,tab);
// break;
// case "cartellini":
// break;
// case "cartellini_rendicontazioni":
// syncCartelliniRendicontazioni(fluxId, tab);
// break;
case "lavoro_fuori_sede":
syncLavoroFuoriSede(fluxId, tab, year, month, now);
break;
// case "aspettative":
// syncAspettative(fluxId,tab);
// break;
default:
break;
}
}
}
}
private void syncOrario(Long fluxId, TabsSI tab) {
if (tab.getIdFlusso() == null || tab.getIdFlusso().longValue() == 0) {
logger.error("Invalid Id Flusso for tab: {}", tab);
@ -894,50 +999,130 @@ public class SyncService {
}
}
private void syncCartelliniRendicontazioni(Long fluxId, TabsSI tab) throws Exception {
private void syncLavoroFuoriSede(Long fluxId, TabsSI tab, String year, String month, LocalDateTime now)
throws Exception {
if (tab.getIdFlusso() == null || tab.getIdFlusso().longValue() == 0) {
logger.error("Invalid Id Flusso for tab: {}", tab);
return;
}
Optional<TimeCardsReporting> lastTcR = timeCardsReportingService.getLastTimeCardsReporting();
if (!lastTcR.isPresent()) {
logger.error("Invalid TimeCardsReporting start point: {}", tab);
logger.info("Reference: {}-{}", year, month);
List<EPASOffSiteWorks> epasOffSiteWorksList = epasOffSiteWorksService.getListByOfficeCodeId(ISTI_OFFICE_CODEID,
year, month);
if (epasOffSiteWorksList == null || epasOffSiteWorksList.isEmpty()) {
logger.info("OffSiteWorks not found for: {} - {} ", year, month);
return;
}
Integer year = lastTcR.get().getYear();
Integer month = lastTcR.get().getMonth();
YearMonth nextMonthToSent = YearMonth.of(year, month);
nextMonthToSent = nextMonthToSent.plusMonths(1);
// "2021-02-03T09:49:05.231072"
DateTimeFormatter formatter = new DateTimeFormatterBuilder().parseCaseInsensitive()
.append(DateTimeFormatter.ISO_LOCAL_DATE_TIME).optionalStart().appendPattern(".SSSSSS").optionalEnd()
.optionalStart().appendZoneOrOffsetId().optionalEnd().toFormatter();
String yearRef = String.valueOf(nextMonthToSent.getYear());
String monthRef = String.valueOf(nextMonthToSent.getMonthValue());
// SI
for (EPASOffSiteWorks offSiteWorks : epasOffSiteWorksList) {
logger.info("Writing OffSiteWorks: {}", offSiteWorks);
if (offSiteWorks == null || offSiteWorks.getPerson() == null) {
logger.error("Invalid Off Site Works: {}", offSiteWorks);
continue;
}
logger.info("Reference: {} - {} ", yearRef, monthRef);
if (offSiteWorks.getPerson().getFiscalCode() == null
|| offSiteWorks.getPerson().getFiscalCode().isEmpty()) {
logger.error("Invalid FiscalCode: {}", offSiteWorks.getPerson().getFiscalCode());
continue;
} else {
logger.info("FiscalCode: {}", offSiteWorks.getPerson().getFiscalCode());
}
EPASValidates epasValidates = epasValidatesService.getValidatesByOfficeCodeId(ISTI_OFFICE_CODEID, yearRef,
monthRef);
Integer idPersona = 0;
try {
idPersona = Integer.valueOf(offSiteWorks.getPerson().getId());
} catch (NumberFormatException e) {
logger.error("Invalid Person Id: {}", offSiteWorks.getPerson().getId());
continue;
}
logger.info("Date: {}", offSiteWorks.getDate());
java.sql.Date date = null;
try {
date = java.sql.Date.valueOf(offSiteWorks.getDate());
} catch (Exception e) {
logger.error("Invalid date format: {}", offSiteWorks.getDate());
continue;
}
for (EPASStampings epasStamping : offSiteWorks.getStampings()) {
if (epasStamping == null) {
logger.error("Invalid Stamping: {}", epasStamping);
continue;
}
if (epasStamping.getStampType() != null && !epasStamping.getStampType().isEmpty()
&& epasStamping.getStampType().compareTo("lavoroFuoriSede") == 0) {
logger.debug("Stamping Type: {}", epasStamping.getStampType());
Long id = 0L;
try {
id = Long.valueOf(epasStamping.getId());
} catch (NumberFormatException e) {
logger.error("Invalid id for stamping: {}", e.getLocalizedMessage(), e);
continue;
}
logger.debug("Stamping Data: {}", epasStamping.getDate());
Timestamp dataMod;
try {
LocalDateTime dMod = LocalDateTime.parse(epasStamping.getDate(), formatter);
dataMod = Timestamp.valueOf(dMod);
} catch (IllegalArgumentException | DateTimeParseException e) {
logger.error("Invalid stamping data format: {}", e.getLocalizedMessage(), e);
continue;
}
logger.debug("DataMod: {}", dataMod);
SILavoroFuoriSede siLavoroFuoriSede = new SILavoroFuoriSede(id, idPersona,
offSiteWorks.getPerson().getFiscalCode(), date, epasStamping.getPlace(),
epasStamping.getReason(), epasStamping.getWay(), dataMod, SI_FLAG_DEL_FALSE, fluxId);
siLavoroFuoriSedeService.writeNewFlux(fluxId, siLavoroFuoriSede);
}
}
}
logger.info("SILavoroFuoriSede Updated");
blavoro_fuori_sede = true;
tab.setIdFlusso(fluxId);
tab.setLastUpdate(now);
tabsSIService.updateTabsSI(tab);
}
private void syncCartelliniRendicontazioni(Long fluxId, TabsSI tab, String year, String month, LocalDateTime now,
TimeCardsReporting timeCardsReporting) throws Exception {
if (tab.getIdFlusso() == null || tab.getIdFlusso().longValue() == 0) {
logger.error("Invalid Id Flusso for tab: {}", tab);
return;
}
logger.info("Reference: {}-{}", year, month);
EPASValidates epasValidates = epasValidatesService.getValidatesByOfficeCodeId(ISTI_OFFICE_CODEID, year, month);
// if (!epasValidates.getAllCertificationsValidated()) {
// logger.info("No month closed on EPAS: {}", nextMonthToSent);
// return;
// }
logger.info("Certifications Validated: {}", nextMonthToSent);
// Set Update DateTime
LocalDateTime now = LocalDateTime.now();
Timestamp dataMod = Timestamp.valueOf(now);
// EPASMed
TimeCardsReporting timeCardsReporting = new TimeCardsReporting();
timeCardsReporting.setYear(nextMonthToSent.getYear());
timeCardsReporting.setMonth(nextMonthToSent.getMonthValue());
timeCardsReporting.setIdFlusso(fluxId);
timeCardsReporting.setLastUpdate(now);
timeCardsReporting = timeCardsReportingService.createTimeCardsReporting(timeCardsReporting);
logger.info("Persons Validated: {}", epasValidates.getValidatedPersons().length);
checkFiscalCode(epasValidates.getValidatedPersons());
@ -952,7 +1137,7 @@ public class SyncService {
}
EPASTimeCards epasTimeCards = epasTimeCardsService.getTimeCardByPersonFiscalCode(person.getFiscalCode(),
yearRef, monthRef);
year, month);
EPASPersons epasPerson = epasTimeCards.getPerson();
Integer personId = Integer.valueOf(epasPerson.getId());
@ -981,19 +1166,61 @@ public class SyncService {
logger.info("SICartellini Updated");
SICartelliniRendicontazioni siCartelliniRendicontazioni = new SICartelliniRendicontazioni(
timeCardsReporting.getId(), timeCardsReporting.getYear(), timeCardsReporting.getMonth(),
Timestamp.valueOf(timeCardsReporting.getLastUpdate()), SI_FLAG_DEL_FALSE, fluxId);
timeCardsReporting.getId(), timeCardsReporting.getYear(), timeCardsReporting.getMonth(), dataMod,
SI_FLAG_DEL_FALSE, fluxId);
siCartelliniRendicontazioniService.writeNewFlux(fluxId, siCartelliniRendicontazioni);
logger.info("SICartelliniRendicontazioni Updated");
bcartellini_rendicontazioni = true;
bcartellini = true;
bcartellini_rendicontazioni = true;
tab.setIdFlusso(fluxId);
tab.setLastUpdate(timeCardsReporting.getLastUpdate());
tab.setLastUpdate(now);
tabsSIService.updateTabsSI(tab);
}
private TimeCardsReporting createTimeCardReporting(Long fluxId, String year, String month, LocalDateTime now) {
Integer iYear = Integer.parseInt(year);
Integer iMonth = Integer.parseInt(month);
// EPASMed
TimeCardsReporting timeCardsReporting = new TimeCardsReporting();
timeCardsReporting.setYear(iYear);
timeCardsReporting.setMonth(iMonth);
timeCardsReporting.setIdFlusso(fluxId);
timeCardsReporting.setLastUpdate(now);
timeCardsReporting = timeCardsReportingService.createTimeCardsReporting(timeCardsReporting);
return timeCardsReporting;
}
private void checkValidMonthToSend(String year, String month) throws Exception {
Integer iYear = Integer.valueOf(year);
Integer iMonth = Integer.valueOf(month);
YearMonth selectedMonth = YearMonth.of(iYear, iMonth);
YearMonth nextMonthToSent = nextMonthToSend();
if (selectedMonth.compareTo(nextMonthToSent) != 0) {
String error = "Attenzione il mese richiesto non è valido per la rendicontazione.";
logger.error(error);
throw new Exception(error);
}
}
private YearMonth nextMonthToSend() throws Exception {
Optional<TimeCardsReporting> lastTcR = timeCardsReportingService.getLastTimeCardsReporting();
if (!lastTcR.isPresent()) {
String error = "Invalid TimeCardsReporting start point, no value found.";
logger.error(error);
throw new Exception(error);
}
Integer latestY = lastTcR.get().getYear();
Integer latestM = lastTcR.get().getMonth();
YearMonth nextMonthToSent = YearMonth.of(latestY, latestM);
nextMonthToSent = nextMonthToSent.plusMonths(1);
return nextMonthToSent;
}
private void checkFiscalCode(EPASPersons[] validatedPersons) throws Exception {
if (validatedPersons != null && validatedPersons.length > 0) {
ArrayList<String> personsWithInvalidFiscalCode = new ArrayList<>();
@ -1031,9 +1258,8 @@ public class SyncService {
boolean foundLavoroFuoriSede = false;
boolean foundMotiviDiServizio = false;
for (EPASStampings epasStamping : epasPersonDay.getStampings()) {
if (epasStamping.getStampType()!=null&&
!epasStamping.getStampType().isEmpty()) {
switch(epasStamping.getStampType()) {
if (epasStamping.getStampType() != null && !epasStamping.getStampType().isEmpty()) {
switch (epasStamping.getStampType()) {
case "lavoroFuoriSede":
foundLavoroFuoriSede = true;
break;

View File

@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController;
import io.github.jhipster.web.util.HeaderUtil;
import io.github.jhipster.web.util.ResponseUtil;
import it.cnr.isti.epasmed.epas.model.EPASOffSiteWorks;
import it.cnr.isti.epasmed.epas.model.EPASPersonDays;
import it.cnr.isti.epasmed.epas.service.EPASOffSiteWorksService;
@ -87,10 +88,10 @@ public class EPASOffSiteWorksResource {
* the EPAS Off Site Works List, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/offsiteworks/byOffice")
public ResponseEntity<List<EPASPersonDays>> getOffSiteWorksByOffice(@RequestParam("codeId") String id,
public ResponseEntity<List<EPASOffSiteWorks>> getOffSiteWorksByOffice(@RequestParam("codeId") String id,
@RequestParam("year") String year, @RequestParam("month") String month) {
log.info("REST request to get ePAS Off Site Works list: officeCodeId={}, year={}, month={}", id,year,month);
List<EPASPersonDays> epasOffSiteWorksList = epasOffSiteWorksService.getListByOfficeCodeId(id, year, month);
List<EPASOffSiteWorks> epasOffSiteWorksList = epasOffSiteWorksService.getListByOfficeCodeId(id, year, month);
return ResponseUtil.wrapOrNotFound(Optional.of(epasOffSiteWorksList));
}

View File

@ -9,6 +9,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.github.jhipster.web.util.HeaderUtil;
@ -66,10 +67,14 @@ public class SyncResource {
return res;
}
/**
* {@code GET /sync/writes} : Retrieve new flux from ePAS and
* {@code GET /sync/writes} : Report from ePAS and
* update SistemaInformativo.
*
* @param year the year.
* @param month the month.
* @return the {@link ResponseEntity} with status {@code 201 (Executed)}
* or with status {@code 400 (Bad Request)} if there is a error.
*
@ -77,20 +82,51 @@ public class SyncResource {
*/
@GetMapping("/sync/writes")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<Void> syncWrites() throws URISyntaxException {
logger.info("REST request syncWrites)");
public ResponseEntity<Void> syncWrites(@RequestParam("year") String year,
@RequestParam("month") String month) throws URISyntaxException {
logger.info("REST request syncWrites");
ResponseEntity<Void> res;
try {
syncService.executeWrites();
String msg="Sincronizzazione delle scritture eseguita correttamente.";
syncService.executeWrites(year,month);
String msg="Rendicontazione eseguita correttamente.";
logger.info(msg);
res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName,
msg,"")).build();
} catch (Throwable e) {
logger.error("Errore nella sincronizzazione delle scritture: {}", e.getLocalizedMessage(), e);
logger.error("Errore nella rendicontazione: {}", e.getLocalizedMessage(), e);
res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName,
"Errore nella sincronizzazione delle scritture: {}", e.getLocalizedMessage())).build();
"Errore nella rendicontazione: {}", e.getLocalizedMessage())).build();
}
return res;
}
/**
* {@code GET /sync/writesOrario} : Report Orario from ePAS and
* update SistemaInformativo.
*
* @return the {@link ResponseEntity} with status {@code 201 (Executed)}
* or with status {@code 400 (Bad Request)} if there is a error.
*
*/
@GetMapping("/sync/writesOrario")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<Void> syncWritesOrario() throws URISyntaxException {
logger.info("REST request syncWritesOrario)");
ResponseEntity<Void> res;
try {
syncService.executeWritesOrario();
String msg="Rendicontazione dell'orario eseguita correttamente.";
logger.info(msg);
res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName,
msg,"")).build();
} catch (Throwable e) {
logger.error("Errore nella rendicontazione dell'orario: {}", e.getLocalizedMessage(), e);
res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName,
"Errore nella rendicontazione dell'orario: {}", e.getLocalizedMessage())).build();
}
return res;
}
@ -100,6 +136,8 @@ public class SyncResource {
* {@code GET /sync/writesTimeCards} : Reports TimeCards from ePAS
* in SistemaInformativo.
*
* @param year the year.
* @param month the month.
* @return the {@link ResponseEntity} with status {@code 201 (Executed)}
* or with status {@code 400 (Bad Request)} if there is a error.
*
@ -107,11 +145,12 @@ public class SyncResource {
*/
@GetMapping("/sync/writesTimeCards")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<Void> syncTimeCardsWrites() throws URISyntaxException {
logger.info("REST request syncWrites)");
public ResponseEntity<Void> syncWritesTimeCards(@RequestParam("year") String year,
@RequestParam("month") String month) throws URISyntaxException {
logger.info("REST request syncWritesTimeCards)");
ResponseEntity<Void> res;
try {
syncService.executeTimeCardsWrites();
syncService.executeWritesTimeCards(year,month);
String msg="Rendicontazione dei cartellini eseguita correttamente.";
logger.info(msg);
res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName,
@ -125,4 +164,36 @@ public class SyncResource {
return res;
}
/**
* {@code GET /sync/writesOffSiteWorks} : Reports Off Site Works from ePAS
* in SistemaInformativo.
*
* @param year the year.
* @param month the month.
* @return the {@link ResponseEntity} with status {@code 201 (Executed)}
* or with status {@code 400 (Bad Request)} if there is a error.
*
*/
@GetMapping("/sync/writesOffSiteWorks")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<Void> syncWritesOffSiteWorks(@RequestParam("year") String year,
@RequestParam("month") String month) throws URISyntaxException {
logger.info("REST request syncWritesOffSiteWorks)");
ResponseEntity<Void> res;
try {
syncService.executeWriteOffSiteWorks(year,month);
String msg="Rendicontazione del lavoro fuori sede eseguita correttamente.";
logger.info(msg);
res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName,
msg,"")).build();
} catch (Throwable e) {
logger.error("Errore nella rendicontazione del lavoro fuori sede: {}", e.getLocalizedMessage(), e);
res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName,
"Errore nella rendicontazione del lavoro fuori sede: {}", e.getLocalizedMessage())).build();
}
return res;
}
}

View File

@ -7,7 +7,11 @@
<p>Sync Sistema Informativo ed ePAS.</p>
<div class="d-grid gap-2 d-md-block">
<ngb-datepicker (navigate)="dateNavigate($event)"
[showWeekdays]="false" class="datepicker-only-month-select"></ngb-datepicker>
<button class="btn btn-primary" type="button" [disabled]="isLoading"
(click)="sync('reads')">Reads</button>
<button class="btn btn-primary" type="button" [disabled]="isLoading"

View File

@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { NgbDatepickerNavigateEvent } from '@ng-bootstrap/ng-bootstrap';
import { SyncType } from './sync.model';
import { SyncService } from './sync.service';
@ -9,19 +10,36 @@ import { SyncService } from './sync.service';
})
export class SyncComponent implements OnInit {
syncT: SyncType | null = null;
year: number;
month: number;
isLoading = false; // hidden by default
constructor(private syncService: SyncService) {}
constructor(private syncService: SyncService) {
const date: Date = new Date();
this.year = date.getFullYear();
this.month = date.getMonth();
}
ngOnInit(): void {}
sync(syncType: SyncType): void {
this.isLoading = true;
this.syncT = syncType;
this.syncService.sync(syncType).subscribe(
() => this.onSuccess(),
() => this.onError()
);
if (this.year == null || this.year <= 0) {
// eslint-disable-next-line no-console
console.log('Select the year');
return;
}
if (this.month == null || this.month <= 0) {
// eslint-disable-next-line no-console
console.log('Select the month');
return;
}
// this.syncService.sync(syncType, this.year,this.month).subscribe(
// () => this.onSuccess(),
// () => this.onError()
// );
}
private onSuccess(): void {
@ -32,5 +50,16 @@ export class SyncComponent implements OnInit {
this.isLoading = false;
}
dateNavigate($event: NgbDatepickerNavigateEvent): void {
this.year = $event.next.year;
this.month = $event.next.month;
// eslint-disable-next-line no-console
console.log(this.year);
// eslint-disable-next-line no-console
console.log(this.month);
// old value is contained in $event.current
}
//
}

View File

@ -9,7 +9,7 @@ import { SyncType } from './sync.model';
export class SyncService {
constructor(private http: HttpClient) {}
sync(syncType: SyncType): Observable<{}> {
return this.http.get(SERVER_API_URL + 'api/sync/' + syncType);
sync(syncType: SyncType, year: number, month: number): Observable<{}> {
return this.http.get(SERVER_API_URL + 'api/sync/' + syncType + '?year=' + year + '&month=' + month);
}
}

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>epasmed</title>
<title>ePASMed</title>
<meta name="description" content="Description for epasmed">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">

View File

@ -24,7 +24,7 @@ import it.cnr.isti.epasmed.security.AuthoritiesConstants;
@AutoConfigureMockMvc
@WithMockUser(authorities = AuthoritiesConstants.ADMIN)
@SpringBootTest(classes = EpasmedApp.class)
@EnabledIf("false")
@EnabledIf("true")
public class EPASOffSiteWorksResourceIT {
private final Logger log = LoggerFactory.getLogger(getClass());

View File

@ -24,10 +24,12 @@ import it.cnr.isti.epasmed.security.AuthoritiesConstants;
@AutoConfigureMockMvc
@WithMockUser(authorities = AuthoritiesConstants.ADMIN)
@SpringBootTest(classes = EpasmedApp.class)
@EnabledIf("false")
@EnabledIf("true")
public class SyncResourceIT {
private final Logger log = LoggerFactory.getLogger(getClass());
private static final String YEAR="2022";
private static final String MONTH="6";
@Autowired
@ -54,13 +56,25 @@ public class SyncResourceIT {
@Test
public void syncWrites() throws Exception {
restSyncMockMvc.perform(get("/api/sync/writes"))
restSyncMockMvc.perform(get("/api/sync/writes?year="+YEAR+"&month="+MONTH))
.andExpect(status().is2xxSuccessful());
}
@Test
public void syncTimeCardsWrites() throws Exception {
restSyncMockMvc.perform(get("/api/sync/writesTimeCards"))
public void syncWritesOrario() throws Exception {
restSyncMockMvc.perform(get("/api/sync/writesOrario"))
.andExpect(status().is2xxSuccessful());
}
@Test
public void syncWritesTimeCards() throws Exception {
restSyncMockMvc.perform(get("/api/sync/writesTimeCards?year="+YEAR+"&month="+MONTH))
.andExpect(status().is2xxSuccessful());
}
@Test
public void syncWritesOffSiteWorks() throws Exception {
restSyncMockMvc.perform(get("/api/sync/writesOffSiteWorks?year="+YEAR+"&month="+MONTH))
.andExpect(status().is2xxSuccessful());
}