Gestita cancellazione della partita se non in uso per ordini lav e acq
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
package it.integry.ems.rules.completing;
|
package it.integry.ems.rules.completing;
|
||||||
|
|
||||||
|
|
||||||
|
import com.microsoft.sqlserver.jdbc.SQLServerException;
|
||||||
import it.integry.ems.rules.completing.dto.DatiPartitaMagDTO;
|
import it.integry.ems.rules.completing.dto.DatiPartitaMagDTO;
|
||||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||||
import it.integry.ems_model.entity.MtbPartitaMag;
|
import it.integry.ems_model.entity.MtbPartitaMag;
|
||||||
|
import it.integry.ems_model.exception.EntityException;
|
||||||
|
import it.integry.ems_model.types.OperationType;
|
||||||
import it.integry.ems_model.utility.UtilityDB;
|
import it.integry.ems_model.utility.UtilityDB;
|
||||||
import it.integry.ems_model.utility.UtilityString;
|
import it.integry.ems_model.utility.UtilityString;
|
||||||
|
|
||||||
@@ -64,4 +67,48 @@ public class PartitaMagRules extends QueryRules {
|
|||||||
ps.close();
|
ps.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean deletePartitaMagIfUnused(Connection conn, MtbPartitaMag mtbPartitaMag) throws Exception {
|
||||||
|
return deletePartitaMagIfUnused(conn, mtbPartitaMag, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean deletePartitaMagIfUnused(Connection conn, MtbPartitaMag mtbPartitaMag, boolean throwException) throws Exception {
|
||||||
|
mtbPartitaMag.setOperation(OperationType.DELETE);
|
||||||
|
|
||||||
|
try {
|
||||||
|
mtbPartitaMag.manageWithParentConnection(conn);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (EntityException e) {
|
||||||
|
if (!throwException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String errorMessage = e.getMessage();
|
||||||
|
|
||||||
|
if (errorMessage.contains("The DELETE statement conflicted with the REFERENCE constraint")) {
|
||||||
|
// Estrai le informazioni dal messaggio di errore
|
||||||
|
String[] errorParts = errorMessage.split("The DELETE statement conflicted with the REFERENCE constraint");
|
||||||
|
|
||||||
|
String constraint = errorParts[1].split("\"")[1]; // Estrai il nome del vincolo
|
||||||
|
String tableName = errorParts[1].split("table \"")[1].split("\"")[0]; // Estrai il nome della tabella
|
||||||
|
|
||||||
|
errorMessage = String.format(
|
||||||
|
"Non puoi eliminare la partita perché esistono riferimenti nella tabella '%s' tramite il vincolo di chiave esterna '%s'.",
|
||||||
|
tableName,
|
||||||
|
constraint
|
||||||
|
);
|
||||||
|
|
||||||
|
throw new Exception(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (!throwException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,16 @@ public class ProductionController {
|
|||||||
return ServiceRestResponse.createPositiveResponse(productionService.mrpCreaOrdineLav(creaOrdineLavDTO));
|
return ServiceRestResponse.createPositiveResponse(productionService.mrpCreaOrdineLav(creaOrdineLavDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/deleteOrdineLav")
|
||||||
|
public ServiceRestResponse deleteOrdineLav(@RequestBody DtbOrdt dtbOrdt) throws Exception {
|
||||||
|
return ServiceRestResponse.createPositiveResponse(productionService.deleteOrdineLav(dtbOrdt));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/deleteOrdineAcq")
|
||||||
|
public ServiceRestResponse deleteOrdineAcq(@RequestBody DtbOrdt dtbOrdt) throws Exception {
|
||||||
|
return ServiceRestResponse.createPositiveResponse(productionService.deleteOrdineAcq(dtbOrdt));
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/mrpCreaOrdiniAcq", method = RequestMethod.POST)
|
@RequestMapping(value = "/mrpCreaOrdiniAcq", method = RequestMethod.POST)
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ServiceRestResponse mrpCreaOrdiniAcq(@RequestBody DtbOrdt dtbOrdt) throws Exception {
|
ServiceRestResponse mrpCreaOrdiniAcq(@RequestBody DtbOrdt dtbOrdt) throws Exception {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import it.integry.ems.exception.PrimaryDatabaseNotPresentException;
|
|||||||
import it.integry.ems.production.dto.*;
|
import it.integry.ems.production.dto.*;
|
||||||
import it.integry.ems.rules.businessLogic.LoadColliService;
|
import it.integry.ems.rules.businessLogic.LoadColliService;
|
||||||
import it.integry.ems.rules.businessLogic.dto.LoadColliDTO;
|
import it.integry.ems.rules.businessLogic.dto.LoadColliDTO;
|
||||||
|
import it.integry.ems.rules.completing.PartitaMagRules;
|
||||||
import it.integry.ems.service.EntityProcessor;
|
import it.integry.ems.service.EntityProcessor;
|
||||||
import it.integry.ems.service.MailService;
|
import it.integry.ems.service.MailService;
|
||||||
import it.integry.ems.service.dto.production.InsertPartitaMagRequestDTO;
|
import it.integry.ems.service.dto.production.InsertPartitaMagRequestDTO;
|
||||||
@@ -776,6 +777,80 @@ public class ProductionService {
|
|||||||
return ordine;
|
return ordine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DtbOrdt deleteOrdineLav(DtbOrdt dtbOrdt) throws Exception {
|
||||||
|
if (ObjectUtils.anyNull(dtbOrdt, dtbOrdt.getGestione(), dtbOrdt.getDataOrd(), dtbOrdt.getNumOrd())) {
|
||||||
|
throw new MissingDataException("Ordine da cancellare incompleto");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
dtbOrdt.setOperation(OperationType.SELECT_OBJECT);
|
||||||
|
|
||||||
|
entityProcessor.processEntity(dtbOrdt, multiDBTransactionManager);
|
||||||
|
|
||||||
|
String codMart = dtbOrdt.getCodProd();
|
||||||
|
String partitaMag = dtbOrdt.getPartitaMag();
|
||||||
|
|
||||||
|
dtbOrdt.setOperation(OperationType.DELETE);
|
||||||
|
|
||||||
|
entityProcessor.processEntity(dtbOrdt, true, multiDBTransactionManager);
|
||||||
|
|
||||||
|
if (!UtilityString.isNullOrEmpty(codMart) && !UtilityString.isNullOrEmpty(partitaMag)) {
|
||||||
|
MtbPartitaMag mtbPartitaMag = new MtbPartitaMag()
|
||||||
|
.setCodMart(codMart)
|
||||||
|
.setPartitaMag(partitaMag);
|
||||||
|
|
||||||
|
PartitaMagRules.deletePartitaMagIfUnused(multiDBTransactionManager.getPrimaryConnection(), mtbPartitaMag, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
multiDBTransactionManager.commitAll();
|
||||||
|
} catch (Exception e) {
|
||||||
|
multiDBTransactionManager.rollbackAll();
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dtbOrdt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DtbOrdt deleteOrdineAcq(DtbOrdt dtbOrdt) throws Exception {
|
||||||
|
if (ObjectUtils.anyNull(dtbOrdt, dtbOrdt.getGestione(), dtbOrdt.getDataOrd(), dtbOrdt.getNumOrd())) {
|
||||||
|
throw new MissingDataException("Ordine da cancellare incompleto");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String sql = Query.format(
|
||||||
|
"SELECT cod_mart, partita_mag\n" +
|
||||||
|
"FROM dtb_ordr\n" +
|
||||||
|
"WHERE gestione = %s\n" +
|
||||||
|
" AND data_ord = %s\n" +
|
||||||
|
" AND num_ord = %s",
|
||||||
|
dtbOrdt.getGestione(),
|
||||||
|
dtbOrdt.getDataOrd(),
|
||||||
|
dtbOrdt.getNumOrd()
|
||||||
|
);
|
||||||
|
|
||||||
|
List<MtbPartitaMag> partiteDaEliminare = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, MtbPartitaMag.class);
|
||||||
|
|
||||||
|
dtbOrdt.setOperation(OperationType.DELETE);
|
||||||
|
|
||||||
|
entityProcessor.processEntity(dtbOrdt, true, multiDBTransactionManager);
|
||||||
|
|
||||||
|
if (partiteDaEliminare != null && !partiteDaEliminare.isEmpty()) {
|
||||||
|
for (MtbPartitaMag mtbPartitaMag : partiteDaEliminare) {
|
||||||
|
PartitaMagRules.deletePartitaMagIfUnused(multiDBTransactionManager.getPrimaryConnection(), mtbPartitaMag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
multiDBTransactionManager.commitAll();
|
||||||
|
} catch (Exception e) {
|
||||||
|
multiDBTransactionManager.rollbackAll();
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dtbOrdt;
|
||||||
|
}
|
||||||
|
|
||||||
public List<EntityBase> chiudiOrdineLavorazione(ChiusuraLavorazioneDTO chiusuraLavorazioneDTO) throws Exception {
|
public List<EntityBase> chiudiOrdineLavorazione(ChiusuraLavorazioneDTO chiusuraLavorazioneDTO) throws Exception {
|
||||||
|
|
||||||
List<EntityBase> entityBaseList = new ArrayList<>();
|
List<EntityBase> entityBaseList = new ArrayList<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user