varie per importazione movimenti di rossogargano
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
package it.integry.ems.migration.model;
|
||||||
|
|
||||||
|
import it.integry.ems.migration._base.BaseMigration;
|
||||||
|
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||||
|
|
||||||
|
public class Migration_20241025173251 extends BaseMigration implements MigrationModelInterface {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void up() throws Exception {
|
||||||
|
if (isHistoryDB())
|
||||||
|
return;
|
||||||
|
|
||||||
|
executeStatement("ALTER TABLE ctb_movt ADD rif_import varchar(40)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void down() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -220,20 +220,8 @@ public class EmsServices {
|
|||||||
boolean anyError = checkForErrorsAndAddToResponse(entityImporter, tmpResult, result, gestName, format, fileContent, file.getName(), anomaliaIsError, headless);
|
boolean anyError = checkForErrorsAndAddToResponse(entityImporter, tmpResult, result, gestName, format, fileContent, file.getName(), anomaliaIsError, headless);
|
||||||
|
|
||||||
/* 22/01/2018 MARCO: Se la procedura di import va a buon fine, il file viene spostato nella cartella Imported a prescindere dalla presenza o meno di anomalie. */
|
/* 22/01/2018 MARCO: Se la procedura di import va a buon fine, il file viene spostato nella cartella Imported a prescindere dalla presenza o meno di anomalie. */
|
||||||
if (!anyError && file != null && !anomaliaIsError) {
|
if (!anyError && file != null && !anomaliaIsError)
|
||||||
String absolutePath = setupGest.getImportSetup(multiDBTransactionManager.getPrimaryConnection(), type, format, "PATH_FILE_IMPORTED");
|
moveFileImported(type, format, file, entityImporter, tmpResult);
|
||||||
if (!UtilityString.isNullOrEmpty(absolutePath)) {
|
|
||||||
String fileNameDest = entityImporter.renameFile(file.getName(), tmpResult);
|
|
||||||
File destFile = new File(absolutePath + File.separator + fileNameDest);
|
|
||||||
if (destFile.exists()) {
|
|
||||||
destFile.delete();
|
|
||||||
}
|
|
||||||
if (!UtilityFile.directoryExists(absolutePath)) {
|
|
||||||
UtilityFile.directoryCreate(absolutePath);
|
|
||||||
}
|
|
||||||
FileUtils.moveFile(file, destFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (headless) {
|
if (headless) {
|
||||||
@@ -286,7 +274,13 @@ public class EmsServices {
|
|||||||
List<EntityBase> tmpResult = (List<EntityBase>) entityImporter.doImport();
|
List<EntityBase> tmpResult = (List<EntityBase>) entityImporter.doImport();
|
||||||
response.getAnomalie().addAll(entityImporter.getAnomalie());
|
response.getAnomalie().addAll(entityImporter.getAnomalie());
|
||||||
|
|
||||||
checkForErrorsAndAddToResponse(entityImporter, tmpResult, result, gestName, format, fileContent, fileName, anomaliaIsError, headless);
|
boolean anyError = checkForErrorsAndAddToResponse(entityImporter, tmpResult, result, gestName, format, fileContent, fileName, anomaliaIsError, headless);
|
||||||
|
|
||||||
|
if (!anyError && fileContent != null && !anomaliaIsError){
|
||||||
|
File file = new File(fileName);
|
||||||
|
FileUtils.writeByteArrayToFile(file, fileContent);
|
||||||
|
moveFileImported(type, format, file, entityImporter, tmpResult);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (headless) {
|
if (headless) {
|
||||||
@@ -315,6 +309,21 @@ public class EmsServices {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void moveFileImported(String type, String format, File file, IEntityImporter entityImporter, List<EntityBase> tmpResult) throws Exception {
|
||||||
|
String absolutePath = setupGest.getImportSetup(multiDBTransactionManager.getPrimaryConnection(), type, format, "PATH_FILE_IMPORTED");
|
||||||
|
if (!UtilityString.isNullOrEmpty(absolutePath)) {
|
||||||
|
String fileNameDest = entityImporter.renameFile(file.getName(), tmpResult);
|
||||||
|
File destFile = new File(absolutePath + File.separator + fileNameDest);
|
||||||
|
if (destFile.exists()) {
|
||||||
|
destFile.delete();
|
||||||
|
}
|
||||||
|
if (!UtilityFile.directoryExists(absolutePath)) {
|
||||||
|
UtilityFile.directoryCreate(absolutePath);
|
||||||
|
}
|
||||||
|
FileUtils.moveFile(file, destFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Procedura di impostazione parametri Entity Importer
|
* Procedura di impostazione parametri Entity Importer
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -118,6 +118,9 @@ public class CtbMovt extends EntityBase {
|
|||||||
@SqlField(value = "data_comp_iva")
|
@SqlField(value = "data_comp_iva")
|
||||||
private Date dataCompIva;
|
private Date dataCompIva;
|
||||||
|
|
||||||
|
@SqlField(value = "rif_import", maxLength = 40)
|
||||||
|
private String rifImport;
|
||||||
|
|
||||||
@JsonProperty(value = "flag_scorporo")
|
@JsonProperty(value = "flag_scorporo")
|
||||||
private String flagScorporo;
|
private String flagScorporo;
|
||||||
|
|
||||||
@@ -581,6 +584,15 @@ public class CtbMovt extends EntityBase {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRifImport() {
|
||||||
|
return rifImport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CtbMovt setRifImport(String rifImport) {
|
||||||
|
this.rifImport = rifImport;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public List<CtbMovi> getCtbMovi() {
|
public List<CtbMovi> getCtbMovi() {
|
||||||
return ctbMovi;
|
return ctbMovi;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -3,9 +3,14 @@ package it.integry.ems.contabil.Import;
|
|||||||
import it.integry.ems.Import.base.BaseEntityImporter;
|
import it.integry.ems.Import.base.BaseEntityImporter;
|
||||||
import it.integry.ems.Import.base.IEntityImporter;
|
import it.integry.ems.Import.base.IEntityImporter;
|
||||||
import it.integry.ems.contabil.Import.service.ContabilImportService;
|
import it.integry.ems.contabil.Import.service.ContabilImportService;
|
||||||
|
import it.integry.ems.document.Import.DocumentiImporter;
|
||||||
import it.integry.ems_model.base.EntityBase;
|
import it.integry.ems_model.base.EntityBase;
|
||||||
|
import it.integry.ems_model.entity.CtbMovt;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class ContabilImporter extends BaseEntityImporter<List<EntityBase>> implements IEntityImporter<List<EntityBase>> {
|
public class ContabilImporter extends BaseEntityImporter<List<EntityBase>> implements IEntityImporter<List<EntityBase>> {
|
||||||
|
|
||||||
@@ -64,4 +69,26 @@ public class ContabilImporter extends BaseEntityImporter<List<EntityBase>> imple
|
|||||||
return this.text;
|
return this.text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String renameFile(String orginalFileName, List<EntityBase> entities) throws Exception {
|
||||||
|
{
|
||||||
|
ContabilImporter.Format enumFormat = ContabilImporter.Format.fromString(super.format);
|
||||||
|
String fileNameDest = null;
|
||||||
|
if (enumFormat != null) {
|
||||||
|
switch (enumFormat) {
|
||||||
|
case DOCFINANCE:
|
||||||
|
String rifImport = entities.stream()
|
||||||
|
.filter(x -> x instanceof CtbMovt).findFirst().map(x -> ((CtbMovt) x).getRifImport()).orElse(null);
|
||||||
|
fileNameDest = rifImport + ".txt";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fileNameDest = super.renameFile(orginalFileName, entities);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileNameDest;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -497,6 +497,11 @@ public class MovimentiContabiliDocfinanceDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static CtbMovt fromMovimenti(MovimentiContabiliDocfinanceDTO mov){
|
public static CtbMovt fromMovimenti(MovimentiContabiliDocfinanceDTO mov){
|
||||||
return new CtbMovt().setDataCmov(mov.getDataOperazione()).setCodCcau(mov.getCausaleCoge()).setDescrizioneCaus(String.valueOf(mov.hashCode()));
|
return new CtbMovt()
|
||||||
|
.setDataCmov(mov.getDataOperazione())
|
||||||
|
.setCodCcau(mov.getCausaleCoge())
|
||||||
|
.setDescrizioneCaus(String.valueOf(mov.hashCode()))
|
||||||
|
.setNumDoc(Integer.valueOf(mov.getMovimento()))
|
||||||
|
.setRifImport(mov.getAnnoCoge() + "_" + mov.getNumeroRitornoCoge());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -582,13 +582,26 @@ public class ContabilImportService {
|
|||||||
TxtMapper<MovimentiContabiliDocfinanceDTO> txtMapper = new TxtMapper<MovimentiContabiliDocfinanceDTO>()
|
TxtMapper<MovimentiContabiliDocfinanceDTO> txtMapper = new TxtMapper<MovimentiContabiliDocfinanceDTO>()
|
||||||
.setFieldsSplitChar("");
|
.setFieldsSplitChar("");
|
||||||
List<MovimentiContabiliDocfinanceDTO> deserialize = txtMapper.deserialize(lines, MovimentiContabiliDocfinanceDTO.class);
|
List<MovimentiContabiliDocfinanceDTO> deserialize = txtMapper.deserialize(lines, MovimentiContabiliDocfinanceDTO.class);
|
||||||
|
|
||||||
|
|
||||||
|
String sql =
|
||||||
|
Query.format(
|
||||||
|
"SELECT CAST(count(*) as bit ) FROM ctb_movt WHERE rif_import = %s",
|
||||||
|
deserialize.get(0).getAnnoCoge() + "_" + deserialize.get(0).getNumeroRitornoCoge()
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if ( UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql))
|
||||||
|
throw new Exception("Impossibile importare questo file, movimenti già importati");
|
||||||
|
|
||||||
|
|
||||||
Map<CtbMovt, List<MovimentiContabiliDocfinanceDTO>> movimenti = deserialize.stream().collect(Collectors.groupingBy(MovimentiContabiliDocfinanceDTO::fromMovimenti));
|
Map<CtbMovt, List<MovimentiContabiliDocfinanceDTO>> movimenti = deserialize.stream().collect(Collectors.groupingBy(MovimentiContabiliDocfinanceDTO::fromMovimenti));
|
||||||
|
|
||||||
List<CtbMovt> ctbMovtList = new ArrayList<>();
|
List<CtbMovt> ctbMovtList = new ArrayList<>();
|
||||||
for (CtbMovt ctbMovt : movimenti.keySet()) {
|
for (CtbMovt ctbMovt : movimenti.keySet()) {
|
||||||
|
|
||||||
String codCcau = ctbMovt.getCodCcau();
|
String codCcau = ctbMovt.getCodCcau();
|
||||||
String sql = Query.format("SELECT CAST(COUNT(*) AS BIT) FROM ctb_caus WHERE cod_ccau = %s", codCcau);
|
sql = Query.format("SELECT CAST(COUNT(*) AS BIT) FROM ctb_caus WHERE cod_ccau = %s", codCcau);
|
||||||
boolean codCcauExists = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
boolean codCcauExists = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
||||||
|
|
||||||
if (!codCcauExists) {
|
if (!codCcauExists) {
|
||||||
@@ -674,7 +687,6 @@ public class ContabilImportService {
|
|||||||
if (listAnomalie.isEmpty() || listAnomalie.stream().noneMatch(AnomalieDTO::isError)){
|
if (listAnomalie.isEmpty() || listAnomalie.stream().noneMatch(AnomalieDTO::isError)){
|
||||||
return entityProcessor.processEntityList(ctbMovtList, true);
|
return entityProcessor.processEntityList(ctbMovtList, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user