Fissato problema nei contratti per previousContract

This commit is contained in:
Giancarlo Panichi 2022-12-01 18:36:28 +01:00
parent 3c01bf39b8
commit 953dc7a23b
5 changed files with 164 additions and 156 deletions

View File

@ -21,6 +21,5 @@ public class EPASContractsDTO implements Serializable {
private String id;
private boolean onCertificate;
private String personId;
private String previousContract;
}

View File

@ -38,7 +38,6 @@ public class EPASContractsMapper {
if (epasContracts.getPerson() != null) {
epasContractsDTO.setPersonId(epasContracts.getPerson().getId());
}
epasContractsDTO.setPreviousContract(epasContracts.getPreviousContract());
return epasContractsDTO;
}
}

View File

@ -20,7 +20,6 @@ public class EPASContracts implements Serializable {
private String id;
private boolean onCertificate;
private EPASPersons person;
private String previousContract;
private EPASWorkingTimeForPerson[] workingTimeTypes;
private String updatedAt;

View File

@ -119,7 +119,7 @@ public class SyncService {
PersOrarioService persOrarioService;
@Autowired
PersOrarioMapper persOrarioMapper;
@Autowired
SIMasterLogService siMasterLogService;
@Autowired
@ -223,8 +223,7 @@ public class SyncService {
writeScheduledData(fluxId, tabsSI, year, month);
siMasterLogService.closeFluxWrites(fluxId, writeTabs());
}
public void executeWritesOrario() throws Exception {
setBWriteTables();
List<TabsSI> tabsSI = tabsSIService.getAllTabsSI();
@ -635,136 +634,13 @@ public class SyncService {
}
if (epasAffiliations != null) {
EPASAffiliations affPresent = null;
for (EPASAffiliations aff : epasAffiliations) {
if (Integer.valueOf(aff.getExternalId()).compareTo(sigp.getId()) == 0) {
affPresent = aff;
break;
}
}
if (affPresent != null) {
List<EPASGroups> epasGroups = epasGroupsService.getList(ISTI_OFFICE_ID);
EPASGroups groupPresent = null;
if (epasGroups != null) {
for (EPASGroups g : epasGroups) {
if (Integer.valueOf(g.getExternalId()).compareTo(sigp.getId()) == 0) {
groupPresent = g;
break;
}
}
if (groupPresent != null) {
EPASPersons epasPerson = null;
try {
epasPerson = epasPersonsService.getByFiscalCode(sigp.getCf());
} catch (Exception e) {
logger.error("Error retrieving person by fiscal code: {}", sigp.getCf());
logger.error(e.getLocalizedMessage(), e);
}
if (epasPerson != null) {
EPASAffiliationsDTO epasAffiliationsDTO = new EPASAffiliationsDTO(
sdfDate.format(sigp.getDal()), sdfDate.format(sigp.getAl()),
groupPresent.getId(), null, String.valueOf(sigp.getPercentuale()),
epasPerson.getId(), String.valueOf(sigp.getId()));
epasAffiliationsService.updateById(affPresent.getId(), epasAffiliationsDTO);
logger.info("EPAS Updated Affilation: {}", epasAffiliationsDTO);
}
}
}
} else {
List<EPASGroups> epasGroups = epasGroupsService.getList(ISTI_OFFICE_ID);
EPASGroups groupPresent = null;
if (epasGroups != null) {
for (EPASGroups g : epasGroups) {
if (Integer.valueOf(g.getExternalId()).compareTo(sigp.getId()) == 0) {
groupPresent = g;
break;
}
}
if (groupPresent != null) {
EPASPersons epasPerson = null;
try {
epasPerson = epasPersonsService.getByFiscalCode(sigp.getCf());
} catch (Exception e) {
logger.error("Error retrieving person by fiscal code: {}", sigp.getCf());
logger.error(e.getLocalizedMessage(), e);
}
if (epasPerson != null) {
EPASAffiliationsDTO epasAffiliationsDTO = new EPASAffiliationsDTO(
sdfDate.format(sigp.getDal()), sdfDate.format(sigp.getAl()),
groupPresent.getId(), null, String.valueOf(sigp.getPercentuale()),
epasPerson.getId(), String.valueOf(sigp.getId()));
EPASAffiliations epasAffiliationNew = epasAffiliationsService
.create(epasAffiliationsDTO);
logger.info("EPAS Created Affilation: {}", epasAffiliationNew);
}
}
}
}
gestisciDipendenteGiaAffiliato(sigp, epasAffiliations);
} else {
List<EPASGroups> epasGroups = epasGroupsService.getList(ISTI_OFFICE_ID);
EPASGroups groupPresent = null;
if (epasGroups != null) {
for (EPASGroups g : epasGroups) {
if (Integer.valueOf(g.getExternalId()).compareTo(sigp.getId()) == 0) {
groupPresent = g;
break;
}
}
if (groupPresent != null) {
EPASPersons epasPerson = null;
try {
epasPerson = epasPersonsService.getByFiscalCode(sigp.getCf());
} catch (Exception e) {
logger.error("Error retrieving person by fiscal code: {}", sigp.getCf());
logger.error(e.getLocalizedMessage(), e);
}
if (epasPerson != null) {
EPASAffiliationsDTO epasAffiliationsDTO = new EPASAffiliationsDTO(
sdfDate.format(sigp.getDal()), sdfDate.format(sigp.getAl()),
groupPresent.getId(), null, String.valueOf(sigp.getPercentuale()),
epasPerson.getId(), String.valueOf(sigp.getId()));
EPASAffiliations epasAffiliationNew = epasAffiliationsService
.create(epasAffiliationsDTO);
logger.info("EPAS Created Affilation: {}", epasAffiliationNew);
}
}
}
gestisciDipendenteNonAffiliato(sigp);
}
} else {
List<EPASAffiliations> epasAffiliations = null;
try {
epasAffiliations = epasAffiliationsService.getByPersonFiscalcode(sigp.getCf());
} catch (Exception e) {
logger.error("Error retrieving Affiliations for fiscal code: {}", sigp.getCf());
logger.error(e.getLocalizedMessage(), e);
}
if (epasAffiliations != null) {
EPASAffiliations affPresent = null;
for (EPASAffiliations aff : epasAffiliations) {
if (Integer.valueOf(aff.getExternalId()).compareTo(sigp.getId()) == 0) {
affPresent = aff;
break;
}
}
if (affPresent != null) {
EPASAffiliationsMapper epasAffiliationsMapper = new EPASAffiliationsMapper();
EPASAffiliationsDTO epasAffiliationsDTO = epasAffiliationsMapper
.epasAffiliationsToEPASAffiliationsDTO(affPresent);
epasAffiliationsDTO.setEndDate(sdfDate.format(sigp.getAl()));
epasAffiliationsService.updateById(affPresent.getId(), epasAffiliationsDTO);
logger.info("EPAS Delete Affilation: {}", epasAffiliationsDTO);
}
}
rimuoviAffiliazione(sigp);
}
}
}
@ -778,6 +654,147 @@ public class SyncService {
}
}
private void rimuoviAffiliazione(SIGruppiPers sigp) {
logger.debug("Rimuovi Affiliazione");
List<EPASAffiliations> epasAffiliations = null;
try {
epasAffiliations = epasAffiliationsService.getByPersonFiscalcode(sigp.getCf());
} catch (Exception e) {
logger.error("Error retrieving Affiliations for fiscal code: {}", sigp.getCf());
logger.error(e.getLocalizedMessage(), e);
}
if (epasAffiliations != null) {
EPASAffiliations affPresent = null;
for (EPASAffiliations aff : epasAffiliations) {
if (aff.getExternalId() != null && !aff.getExternalId().isEmpty()) {
Integer affId = 0;
try {
affId = Integer.valueOf(aff.getExternalId());
} catch (NumberFormatException e) {
logger.error("Invalid aff external id: {} ", aff.getExternalId());
}
if (affId.compareTo(sigp.getId()) == 0) {
affPresent = aff;
break;
}
}
}
if (affPresent != null) {
EPASAffiliationsMapper epasAffiliationsMapper = new EPASAffiliationsMapper();
EPASAffiliationsDTO epasAffiliationsDTO = epasAffiliationsMapper
.epasAffiliationsToEPASAffiliationsDTO(affPresent);
epasAffiliationsDTO.setEndDate(sdfDate.format(sigp.getAl()));
epasAffiliationsService.updateById(affPresent.getId(), epasAffiliationsDTO);
logger.info("EPAS Delete Affilation: {}", epasAffiliationsDTO);
}
}
}
private void gestisciDipendenteNonAffiliato(SIGruppiPers sigp) {
logger.debug("Aggiungi dipendente non affiliato");
List<EPASGroups> epasGroups = epasGroupsService.getList(ISTI_OFFICE_ID);
EPASGroups groupPresent = null;
if (epasGroups != null) {
for (EPASGroups g : epasGroups) {
if (g.getExternalId() != null && !g.getExternalId().isEmpty()) {
Integer gId = 0;
try {
gId = Integer.valueOf(g.getExternalId());
} catch (NumberFormatException e) {
logger.error("Invalid external id: {} ", g.getExternalId());
}
if (gId.compareTo(sigp.getId()) == 0) {
groupPresent = g;
break;
}
}
}
if (groupPresent != null) {
EPASPersons epasPerson = null;
try {
epasPerson = epasPersonsService.getByFiscalCode(sigp.getCf());
} catch (Exception e) {
logger.error("Error retrieving person by fiscal code: {}", sigp.getCf());
logger.error(e.getLocalizedMessage(), e);
}
if (epasPerson != null) {
EPASAffiliationsDTO epasAffiliationsDTO = new EPASAffiliationsDTO(sdfDate.format(sigp.getDal()),
sdfDate.format(sigp.getAl()), groupPresent.getId(), null,
String.valueOf(sigp.getPercentuale()), epasPerson.getId(), String.valueOf(sigp.getId()));
EPASAffiliations epasAffiliationNew = epasAffiliationsService.create(epasAffiliationsDTO);
logger.info("EPAS Created Affilation: {}", epasAffiliationNew);
}
}
}
}
private void gestisciDipendenteGiaAffiliato(SIGruppiPers sigp, List<EPASAffiliations> epasAffiliations) {
logger.debug("Aggiungi dipendente già affiliato");
EPASAffiliations affPresent = null;
for (EPASAffiliations aff : epasAffiliations) {
if (aff.getExternalId() != null && !aff.getExternalId().isEmpty()) {
Integer affId = 0;
try {
affId = Integer.valueOf(aff.getExternalId());
} catch (NumberFormatException e) {
logger.error("Invalid aff external id: {} ", aff.getExternalId());
}
if (affId.compareTo(sigp.getId()) == 0) {
affPresent = aff;
break;
}
}
}
if (affPresent != null) {
List<EPASGroups> epasGroups = epasGroupsService.getList(ISTI_OFFICE_ID);
EPASGroups groupPresent = null;
if (epasGroups != null) {
for (EPASGroups g : epasGroups) {
if (g.getExternalId() != null && !g.getExternalId().isEmpty()) {
Integer gId = 0;
try {
gId = Integer.valueOf(g.getExternalId());
} catch (NumberFormatException e) {
logger.error("Invalid external id: {} ", g.getExternalId());
}
if (gId.compareTo(sigp.getId()) == 0) {
groupPresent = g;
break;
}
}
}
if (groupPresent != null) {
EPASPersons epasPerson = null;
try {
epasPerson = epasPersonsService.getByFiscalCode(sigp.getCf());
} catch (Exception e) {
logger.error("Error retrieving person by fiscal code: {}", sigp.getCf());
logger.error(e.getLocalizedMessage(), e);
}
if (epasPerson != null) {
EPASAffiliationsDTO epasAffiliationsDTO = new EPASAffiliationsDTO(sdfDate.format(sigp.getDal()),
sdfDate.format(sigp.getAl()), groupPresent.getId(), null,
String.valueOf(sigp.getPercentuale()), epasPerson.getId(),
String.valueOf(sigp.getId()));
epasAffiliationsService.updateById(affPresent.getId(), epasAffiliationsDTO);
logger.info("EPAS Updated Affilation: {}", epasAffiliationsDTO);
}
}
}
} else {
gestisciDipendenteNonAffiliato(sigp);
}
}
private String readTabs() {
String readTabs = "";
if (banagrafico) {
@ -901,7 +918,7 @@ public class SyncService {
break;
case "pers_orario":
syncPersOrario(fluxId, tab, year, month, now);
break;
break;
default:
break;
}
@ -909,8 +926,7 @@ public class SyncService {
}
}
}
private void writeOrarioData(Long fluxId, List<TabsSI> tabsSI) {
for (TabsSI tab : tabsSI) {
logger.info("TabSI: {}", tab);
@ -1325,8 +1341,8 @@ public class SyncService {
private void writeAspettativeOnSI(Long fluxId, LocalDateTime now, List<EPASLeaves> epasLeavesList,
LinkedHashMap<String, EPASAbsenceTypes> epasAbsenceTypeMap) {
int count=0;
int count = 0;
// SI
for (EPASLeaves leave : epasLeavesList) {
logger.debug("Writing Leave: {}", leave);
@ -1419,11 +1435,11 @@ public class SyncService {
if (checkSIAspettativeIsUpgradeable(siAspettative)) {
logger.info("Write SIAspettativa: {}", siAspettative);
count=count+1;
count = count + 1;
siAspettativeService.writeNewFlux(fluxId, siAspettative);
}
}
logger.info("Aspettative scritte su SI: {}",count);
logger.info("Aspettative scritte su SI: {}", count);
}
private boolean checkSIAspettativeIsUpgradeable(SIAspettative siAspettative) {
@ -1469,8 +1485,8 @@ public class SyncService {
} else {
logger.info("PersonWorkingTimeDTOList size: {}", epasPersonWorkingTimeDTOList.size());
}
int count=0;
int count = 0;
// SI
for (EPASPersonWorkingTimeDTO pwtDTO : epasPersonWorkingTimeDTOList) {
logger.info("Writing Person Working Time: {}", pwtDTO);
@ -1540,22 +1556,20 @@ public class SyncService {
LocalDateTime dMod = now.truncatedTo(ChronoUnit.SECONDS);
Timestamp dataMod = Timestamp.valueOf(dMod);
SIPersOrario siPersOrario = new SIPersOrario(id, idPersona, pwtDTO.getCf(), startDate, endDate,
pwtDTO.getDescrizione(), pwtDTO.getLun(), pwtDTO.getMar(), pwtDTO.getMer(), pwtDTO.getGio(),
pwtDTO.getVen(), pwtDTO.getSab(), pwtDTO.getPercentuale(), pwtDTO.getTurno(), pwtDTO.getOre_turno(),
pwtDTO.getFestivo(), pwtDTO.getNotturno(), dataMod, SI_FLAG_DEL_FALSE, fluxId);
if (checkSIPersOrarioIsUpgradeable(siPersOrario)) {
logger.info("Write SIPersOrario: {}", siPersOrario);
count=count+1;
count = count + 1;
siPersOrarioService.writeNewFlux(fluxId, siPersOrario);
}
}
logger.info("Personale Orario scritto su SI: {}",count);
logger.info("Personale Orario scritto su SI: {}", count);
logger.info("SIPersOrario Updated");
bpers_orario = true;
tab.setIdFlusso(fluxId);
@ -1563,22 +1577,22 @@ public class SyncService {
tabsSIService.updateTabsSI(tab);
}
private boolean checkSIPersOrarioIsUpgradeable(SIPersOrario siPersOrario) {
boolean upgradeable = false;
try {
Optional<PersOrario> persOrario = persOrarioService.getPersOrarioById(siPersOrario.getId());
if (persOrario.isPresent()) {
PersOrario found = persOrario.get();
logger.debug("Found: {}",found);
logger.debug("Found: {}", found);
PersOrario persOrarioDTO = persOrarioMapper.siPersOrarioToPersOrario(siPersOrario);
logger.debug("PersOrarioDTO: {}",persOrarioDTO);
logger.debug("PersOrarioDTO: {}", persOrarioDTO);
if (!found.same(persOrarioDTO)) {
upgradeable = true;
persOrarioService.updatePersOrario(persOrarioDTO);
}
} else {
logger.debug("Not found PersOrario by id: {}",siPersOrario.getId());
logger.debug("Not found PersOrario by id: {}", siPersOrario.getId());
upgradeable = true;
PersOrario persOrarioDTO = persOrarioMapper.siPersOrarioToPersOrario(siPersOrario);
persOrarioService.createPersOrario(persOrarioDTO);
@ -1591,8 +1605,6 @@ public class SyncService {
}
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) {

View File

@ -72,7 +72,7 @@ public class EPASContractsResourceIT {
private static final String CONTRACT_DEFAUL_ENDDATE = null;
private static final String CONTRACT_DEFAULT_ENDCONTRACT = null;
private static final boolean CONTRACT_DEFAULT_ONCERTIFICATE = true;
private static final String CONTRACT_DEFAULT_PREVIOUSCONTRACT = null;
//private static final String CONTRACT_DEFAULT_PREVIOUSCONTRACT = null;
private static final String CONTRACT_DEFAULT_EXTERNALID = "2496";
private static final String CONTRACT_UPDATE_ENDATE = "2021-12-31";
@ -102,7 +102,6 @@ public class EPASContractsResourceIT {
epasContracts.setEndContract(CONTRACT_DEFAULT_ENDCONTRACT);
epasContracts.setOnCertificate(CONTRACT_DEFAULT_ONCERTIFICATE);
epasContracts.setPerson(createEPASPerson());
epasContracts.setPreviousContract(CONTRACT_DEFAULT_PREVIOUSCONTRACT);
epasContracts.setExternalId(CONTRACT_DEFAULT_EXTERNALID);
return epasContracts;
}