Aggiunta rendicontazione singolo cartellino

This commit is contained in:
Giancarlo Panichi 2022-08-04 19:06:40 +02:00
parent c58e496f15
commit 44c3fc8fa5
9 changed files with 270 additions and 109 deletions

View File

@ -175,7 +175,7 @@ public class SyncService {
writeData(fluxId, tabsSI, year, month);
siMasterLogService.closeFluxWrites(fluxId, writeTabs());
}
public void executeWritesOrario() throws Exception {
setBWriteTables();
List<TabsSI> tabsSI = tabsSIService.getAllTabsSI();
@ -194,6 +194,15 @@ public class SyncService {
}
public void executeWritesSingleTimeCards(String year, String month, String fc) throws Exception {
setBWriteTables();
List<TabsSI> tabsSI = tabsSIService.getAllTabsSI();
Long fluxId = siMasterLogService.startFluxWrites();
writeSingleTimeCardsData(fluxId, tabsSI, year, month,fc);
siMasterLogService.closeFluxWrites(fluxId, writeTabs());
}
public void executeWriteOffSiteWorks(String year, String month) throws Exception {
setBWriteTables();
List<TabsSI> tabsSI = tabsSIService.getAllTabsSI();
@ -203,7 +212,6 @@ public class SyncService {
}
private void readData(List<TabsSI> tabsSI) {
// TabsSI posizioniTab = null;
// TabsSI prorogheTab = null;
@ -918,6 +926,51 @@ public class SyncService {
}
}
private void writeSingleTimeCardsData(Long fluxId, List<TabsSI> tabsSI, String year, String month, String fc)
throws Exception {
logger.info("Report {}-{}", year, month);
logger.info("FiscalCode: {}", fc);
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":
syncSingleCartellino(fluxId, tab, year, month, now, fc);
break;
// case "cartellini_rendicontazioni":
// syncCartelliniRendicontazioni(fluxId, tab, year, month, now,
// timeCardsReporting);
// break;
// case "lavoro_fuori_sede":
// syncLavoroFuoriSede(fluxId,tab);
// break;
// case "aspettative":
// syncAspettative(fluxId,tab);
// break;
default:
break;
}
}
}
}
private void writeOffSiteWorksData(Long fluxId, List<TabsSI> tabsSI, String year, String month) throws Exception {
logger.info("Report {}-{}", year, month);
LocalDateTime now = LocalDateTime.now();
@ -1179,6 +1232,70 @@ public class SyncService {
}
private void syncSingleCartellino(Long fluxId, TabsSI tab, String year, String month, LocalDateTime now, String fc)
throws Exception {
if (tab.getIdFlusso() == null || tab.getIdFlusso().longValue() == 0) {
logger.error("Invalid Id Flusso for tab: {}", tab);
return;
}
logger.info("Reference: {}-{}", year, month);
// Set Update DateTime
Timestamp dataMod = Timestamp.valueOf(now);
// logger.info("Persons Validated: {}",
// epasValidates.getValidatedPersons().length);
// checkFiscalCode(epasValidates.getValidatedPersons());
EPASPersons person = epasPersonsService.getByFiscalCode(fc);
if (person == null) {
logger.error("Error retrieving person by fiscal code: {}", fc);
String error = "Error retrieving person by fiscal code: " + fc;
throw new Exception(error);
}
logger.info("Writing TimeCard for Person: {}", person);
if (person.getFiscalCode() == null || person.getFiscalCode().isEmpty()) {
logger.error("Invalid FiscalCode: {}", person.getFiscalCode());
String error = "Invalid FiscalCode: " + person.getFiscalCode();
throw new Exception(error);
} else {
logger.info("FiscalCode: {}", person.getFiscalCode());
}
EPASTimeCards epasTimeCards = epasTimeCardsService.getTimeCardByPersonFiscalCode(person.getFiscalCode(), year,
month);
EPASPersons epasPerson = epasTimeCards.getPerson();
Integer personId = Integer.valueOf(epasPerson.getId());
for (EPASPersonDays epasPersonDay : epasTimeCards.getPersonDays()) {
Long id = Long.valueOf(epasPersonDay.getId());
StringBuilder motivo = new StringBuilder();
extractMotivoInfo(epasPersonDay, motivo);
java.sql.Date date = null;
try {
date = java.sql.Date.valueOf(epasPersonDay.getDate());
} catch (Exception e) {
logger.error("Invalid date format: {}", epasPersonDay.getDate());
break;
}
SICartellini siCartellini = new SICartellini(id, personId, epasPerson.getFiscalCode(), date,
motivo.toString(), epasPersonDay.getTimeAtWork(), epasPersonDay.getDifference(), dataMod, "0",
fluxId);
siCartelliniService.writeNewFlux(fluxId, siCartellini);
}
logger.info("SICartellino Updated");
bcartellini = true;
tab.setIdFlusso(fluxId);
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);

View File

@ -138,6 +138,17 @@ public class ExceptionTranslator implements ProblemHandling, SecurityAdviceTrait
return create(ex, problem, request);
}
@ExceptionHandler(value = Exception.class)
public ResponseEntity<Problem> handleException(Exception ex, NativeWebRequest request) {
Problem problem = Problem.builder()
.withStatus(Status.INTERNAL_SERVER_ERROR)
.with(MESSAGE_KEY, ex.getLocalizedMessage())
.build();
return create(ex,problem,request);
}
@Override
public ProblemBuilder prepare(final Throwable throwable, final StatusType status, final URI type) {

View File

@ -1,12 +1,8 @@
package it.cnr.isti.epasmed.web.rest.sync;
import java.net.URISyntaxException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
@ -47,25 +43,20 @@ public class SyncResource {
*
* @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with
* status {@code 400 (Bad Request)} if there is a error.
* @throws Exception
*
*
*/
@GetMapping("/sync/reads")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<Object> syncReads() throws URISyntaxException {
public ResponseEntity<Void> syncReads() throws Exception {
logger.info("REST request syncReads()");
ResponseEntity<Object> res;
try {
syncService.executeReads();
logger.info("Sincronizzazione delle Letture eseguita correttamente.");
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName,
"Sincronizzazione delle letture eseguita corretamente.", "")).build();
} catch (Throwable e) {
logger.error("Errore nella sincronizzazione delle letture: {}", e.getLocalizedMessage(), e);
res=new ResponseEntity<Object>(
e.getLocalizedMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
}
ResponseEntity<Void> res;
syncService.executeReads();
logger.info("Sincronizzazione delle Letture eseguita correttamente.");
res = ResponseEntity.noContent().headers(
HeaderUtil.createAlert(applicationName, "Sincronizzazione delle letture eseguita corretamente.", ""))
.build();
return res;
}
@ -76,27 +67,22 @@ public class SyncResource {
* @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.
* @throws Exception
*
*
*/
@GetMapping("/sync/writes")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<Object> syncWrites(@RequestParam("year") String year, @RequestParam("month") String month)
throws URISyntaxException {
public ResponseEntity<Void> syncWrites(@RequestParam("year") String year, @RequestParam("month") String month)
throws Exception {
logger.info("REST request syncWrites");
ResponseEntity<Object> res;
try {
syncService.executeWrites(year, month);
String msg = "Rendicontazione eseguita correttamente.";
logger.info(msg);
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
ResponseEntity<Void> res;
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 rendicontazione: {}", e.getLocalizedMessage(), e);
res=new ResponseEntity<Object>(
e.getLocalizedMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
}
return res;
}
@ -107,32 +93,29 @@ public class SyncResource {
* @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.
* @throws Exception
*
*
*/
@GetMapping("/sync/test")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<Object> syncTest(@RequestParam("year") String year, @RequestParam("month") String month)
throws URISyntaxException {
public ResponseEntity<Void> syncTest(@RequestParam("year") String year, @RequestParam("month") String month)
throws Exception {
logger.info("REST request syncTest");
ResponseEntity<Object> res;
try {
logger.info("Selezionato {} - {} ", year, month);
String msg = "Test eseguito correttamente.";
logger.info(msg);
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
//throw new Exception("Some errors in server!");
ResponseEntity<Void> res;
logger.info("Selezionato {} - {} ", year, month);
String msg = "Test eseguito correttamente.";
logger.info(msg);
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
// throw new Exception("Some errors in server!");
// } catch (Throwable e) {
// logger.error("Errore nella sincronizzazione delle letture: {}",
// e.getLocalizedMessage(), e);
// res = new ResponseEntity<Object>(e.getLocalizedMessage(), new HttpHeaders(),
// HttpStatus.INTERNAL_SERVER_ERROR);
// }
} catch (Throwable e) {
logger.error("Errore nel test: {}", e.getLocalizedMessage(), e);
//res = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).
// headers(HeaderUtil.createFailureAlert(applicationName, false, "Test", "Test", errore)).body(errore);
//res = ResponseEntity.noContent()
//.headers(HeaderUtil.createFailureAlert(applicationName, false, null, null, errore)).build();
res=new ResponseEntity<Object>(
e.getLocalizedMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
}
return res;
}
@ -142,25 +125,19 @@ public class SyncResource {
*
* @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with
* status {@code 400 (Bad Request)} if there is a error.
* @throws Exception
*
*
*/
@GetMapping("/sync/writesOrario")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<Object> syncWritesOrario() throws URISyntaxException {
public ResponseEntity<Void> syncWritesOrario() throws Exception {
logger.info("REST request syncWritesOrario)");
ResponseEntity<Object> 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=new ResponseEntity<Object>(
e.getLocalizedMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
}
ResponseEntity<Void> res;
syncService.executeWritesOrario();
String msg = "Rendicontazione dell'orario eseguita correttamente.";
logger.info(msg);
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
return res;
}
@ -172,28 +149,51 @@ public class SyncResource {
* @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.
* @throws Exception
*
*
*/
@GetMapping("/sync/writesTimeCards")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<Object> syncWritesTimeCards(@RequestParam("year") String year,
@RequestParam("month") String month) throws URISyntaxException {
public ResponseEntity<Void> syncWritesTimeCards(@RequestParam("year") String year,
@RequestParam("month") String month) throws Exception {
logger.info("REST request syncWritesTimeCards)");
ResponseEntity<Object> res;
try {
syncService.executeWritesTimeCards(year, month);
String msg = "Rendicontazione dei cartellini eseguita correttamente.";
logger.info(msg);
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
} catch (Throwable e) {
logger.error("Errore nella rendicontazione dei cartellini: {}", e.getLocalizedMessage(), e);
res=new ResponseEntity<Object>(
e.getLocalizedMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
}
ResponseEntity<Void> res;
syncService.executeWritesTimeCards(year, month);
String msg = "Rendicontazione dei cartellini eseguita correttamente.";
logger.info(msg);
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
return res;
}
/**
* {@code GET /sync/writesSingleTimeCards} : Reports SingleTimeCards from ePAS in
* SistemaInformativo.
*
* @param year the year.
* @param month the month.
* @param fiscalCode the fiscal code
* @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with
* status {@code 400 (Bad Request)} if there is a error.
* @throws Exception
*
*
*/
@GetMapping("/sync/writesSingleTimeCards")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<Void> syncSingleWritesTimeCards(@RequestParam("year") String year,
@RequestParam("month") String month, @RequestParam("fiscalCode") String fc) throws Exception {
logger.info("REST request syncSingleWritesTimeCards)");
ResponseEntity<Void> res;
syncService.executeWritesSingleTimeCards(year, month,fc);
String msg = "Rendicontazione del cartellino eseguita correttamente.";
logger.info(msg);
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
return res;
}
/**
* {@code GET /sync/writesOffSiteWorks} : Reports Off Site Works from ePAS in
@ -203,26 +203,21 @@ public class SyncResource {
* @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.
* @throws Exception
*
*
*/
@GetMapping("/sync/writesOffSiteWorks")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<Object> syncWritesOffSiteWorks(@RequestParam("year") String year,
@RequestParam("month") String month) throws URISyntaxException {
public ResponseEntity<Void> syncWritesOffSiteWorks(@RequestParam("year") String year,
@RequestParam("month") String month) throws Exception {
logger.info("REST request syncWritesOffSiteWorks)");
ResponseEntity<Object> 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();
ResponseEntity<Void> res;
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=new ResponseEntity<Object>(
e.getLocalizedMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
}
return res;
}

View File

@ -5,16 +5,15 @@
<jhi-alert></jhi-alert>
<p>Rendicontazione da ePAS a Sistema Informativo.</p>
<div class="page-min-height">
<form>
<div class="form-group">
<label for="annoRendicontazione">Anno</label>
<input type="number" class="form-control"
id="annoRendicontazione" name="annoRendicontazione" min="2000"
max="3000" [(ngModel)]="year">
<!-- <small id="rendicontaHelp" class="form-text text-muted">Inserire
il mese da rendicontare.</small> -->
max="3000" [(ngModel)]="year" required>
<!-- -->
</div>
<div class="form-group">
<label for="meseRendicontazione">Mese</label>

View File

@ -16,7 +16,7 @@ export class RendicontazioneComponent implements OnInit {
constructor(private rendicontazioneService: RendicontazioneService) {
const date: Date = new Date();
this.year = date.getFullYear();
this.month = date.getMonth();
this.month = date.getMonth() + 1;
}
ngOnInit(): void {}
@ -45,13 +45,13 @@ export class RendicontazioneComponent implements OnInit {
private onSuccess(): void {
this.isLoading = false;
// eslint-disable-next-line no-console
console.log('Successo');
console.log('Success');
}
private onError(error: HttpErrorResponse): void {
this.isLoading = false;
// eslint-disable-next-line no-console
console.log('Errore Riscontrato');
console.log('Error');
// eslint-disable-next-line no-console
console.log(error);
}

View File

@ -2,17 +2,49 @@
<h2 id="logs-page-heading">Sync</h2>
<jhi-alert-error></jhi-alert-error>
<jhi-alert></jhi-alert>
<p>Sync Sistema Informativo ed ePAS.</p>
<div class="page-min-height">
<form>
<div class="form-group">
<label for="annoRendicontazione">Anno</label>
<input type="number" class="form-control"
id="annoRendicontazione" name="annoRendicontazione" min="2000"
max="3000" [(ngModel)]="year" required>
<!-- -->
</div>
<div class="form-group">
<label for="meseRendicontazione">Mese</label>
<select id="meseRendicontazione" name="meseRendicontazione"
class="form-select form-control"
aria-label="Mese" [(ngModel)]="month" required>
<option value="1">Gennaio</option>
<option value="2">Febbraio</option>
<option value="3">Marzo</option>
<option value="4">Aprile</option>
<option value="5">Maggio</option>
<option value="6">Giugno</option>
<option value="7">Luglio</option>
<option value="8">Agosto</option>
<option value="9">Settembre</option>
<option value="10">Ottobre</option>
<option value="10">Novembre</option>
<option value="12">Dicembre</option>
</select>
</div>
<button class="btn btn-primary" type="button" [disabled]="isLoading"
(click)="sync('reads')">Reads</button>
(click)="sync('test')">Test</button>
<button class="btn btn-primary" type="button" [disabled]="isLoading"
(click)="sync('writes')">Writes</button>
(click)="sync('reads')">Leggi</button>
<button class="btn btn-primary" type="button" [disabled]="isLoading"
(click)="sync('writesOrario')">Scrivi Orario</button>
<button class="btn btn-primary" type="button" [disabled]="isLoading"
(click)="sync('writesTimeCards')">Scrivi Cartellini</button>
<button class="btn btn-primary" type="button" [disabled]="isLoading"
(click)="sync('writesOffSiteWorks')">Scrivi Lavoro Fuori Sede</button>
</form>
<div *ngIf="isLoading" class="d-flex justify-content-center">

View File

@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core';
// import { NgbDate } from '@ng-bootstrap/ng-bootstrap';
import { HttpErrorResponse } from '@angular/common/http';
import { SyncType } from './sync.model';
import { SyncService } from './sync.service';
@ -37,19 +38,25 @@ export class SyncComponent implements OnInit {
return;
}
// this.syncService.sync(syncType, this.year,this.month).subscribe(
// () => this.onSuccess(),
// () => this.onError()
// );
this.syncService.sync(syncType, this.year, this.month).subscribe(
() => this.onSuccess(),
error => this.onError(error)
);
}
private onSuccess(): void {
this.isLoading = false;
// eslint-disable-next-line no-console
console.log('Success');
}
private onError(): void {
private onError(error: HttpErrorResponse): void {
this.isLoading = false;
}
// eslint-disable-next-line no-console
console.log('Error');
// eslint-disable-next-line no-console
console.log(error);
//
//
}
}

View File

@ -1 +1 @@
export type SyncType = 'reads' | 'writes';
export type SyncType = 'test' | 'reads' | 'writesOrario' | 'writesTimeCards' | 'writesOffSiteWorks';

View File

@ -9,7 +9,7 @@
<meta name="theme-color" content="#000000">
<link rel="icon" href="favicon.ico" />
<link rel="manifest" href="manifest.webapp" />
<link rel="stylesheet" href="content/css/loading.css">
<!-- <link rel="stylesheet" href="content/css/loading.css"> -->
<!-- jhipster-needle-add-resources-to-root - JHipster will add new resources here -->
</head>
<body>